Kaynağa Gözat

[message-buffer 9/X] - Rename "accumulator" to message (#777)

* refactor(message-buffer): rename accumulator-input to message-buffer

refactor any names with accumulator to message

* refactor(message-buffer): change accumulator seed to message
swimricky 2 yıl önce
ebeveyn
işleme
6a5b1c434a
33 değiştirilmiş dosya ile 160 ekleme ve 176 silme
  1. 7 7
      .pre-commit-config.yaml
  2. 0 7
      accumulator_updater/programs/accumulator_updater/src/state/mod.rs
  3. 0 0
      message_buffer/.gitignore
  4. 0 0
      message_buffer/.prettierignore
  5. 1 1
      message_buffer/Anchor.toml
  6. 9 9
      message_buffer/Cargo.lock
  7. 0 0
      message_buffer/Cargo.toml
  8. 0 0
      message_buffer/NOTES.md
  9. 0 0
      message_buffer/migrations/deploy.ts
  10. 0 0
      message_buffer/package.json
  11. 3 3
      message_buffer/programs/message_buffer/Cargo.toml
  12. 0 0
      message_buffer/programs/message_buffer/Xargo.toml
  13. 0 0
      message_buffer/programs/message_buffer/src/instructions/mod.rs
  14. 8 8
      message_buffer/programs/message_buffer/src/instructions/put_all.rs
  15. 8 9
      message_buffer/programs/message_buffer/src/lib.rs
  16. 1 1
      message_buffer/programs/message_buffer/src/macros.rs
  17. 35 40
      message_buffer/programs/message_buffer/src/state/message_buffer.rs
  18. 7 0
      message_buffer/programs/message_buffer/src/state/mod.rs
  19. 1 1
      message_buffer/programs/message_buffer/src/state/whitelist.rs
  20. 1 1
      message_buffer/programs/mock-cpi-caller/Cargo.toml
  21. 0 0
      message_buffer/programs/mock-cpi-caller/Xargo.toml
  22. 12 12
      message_buffer/programs/mock-cpi-caller/src/instructions/add_price.rs
  23. 0 0
      message_buffer/programs/mock-cpi-caller/src/instructions/cpi_max_test.rs
  24. 0 0
      message_buffer/programs/mock-cpi-caller/src/instructions/mod.rs
  25. 11 11
      message_buffer/programs/mock-cpi-caller/src/instructions/update_price.rs
  26. 1 1
      message_buffer/programs/mock-cpi-caller/src/lib.rs
  27. 0 0
      message_buffer/programs/mock-cpi-caller/src/message.rs
  28. 0 0
      message_buffer/programs/mock-cpi-caller/src/message/price.rs
  29. 0 0
      message_buffer/programs/mock-cpi-caller/src/state/mod.rs
  30. 0 0
      message_buffer/programs/mock-cpi-caller/src/state/price.rs
  31. 55 65
      message_buffer/tests/message_buffer.ts
  32. 0 0
      message_buffer/tsconfig.json
  33. 0 0
      message_buffer/yarn.lock

+ 7 - 7
.pre-commit-config.yaml

@@ -65,17 +65,17 @@ repos:
         entry: cargo +nightly fmt --manifest-path ./hermes/Cargo.toml --all -- --config-path rustfmt.toml
         pass_filenames: false
         files: hermes
-      # Hooks for accumulator updater contract
-      - id: cargo-fmt-accumulator-updater
-        name: Cargo format for accumulator updater contract
+      # Hooks for message buffer contract
+      - id: cargo-fmt-message-buffer
+        name: Cargo format for message buffer contract
         language: "rust"
-        entry: cargo +nightly fmt --manifest-path ./accumulator_updater/Cargo.toml --all -- --config-path rustfmt.toml
+        entry: cargo +nightly fmt --manifest-path ./message_buffer/Cargo.toml --all -- --config-path rustfmt.toml
         pass_filenames: false
         files: accumulator_updater
-      - id: cargo-clippy-accumulator-updater
-        name: Cargo clippy for accumulator-updater contract
+      - id: cargo-clippy-message-buffer
+        name: Cargo clippy for message buffer contract
         language: "rust"
-        entry: cargo +nightly clippy --manifest-path ./accumulator_updater/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
+        entry: cargo +nightly clippy --manifest-path ./message_buffer/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
         pass_filenames: false
         files: accumulator_updater
       # Hooks for solana receiver contract

+ 0 - 7
accumulator_updater/programs/accumulator_updater/src/state/mod.rs

@@ -1,7 +0,0 @@
-pub use {
-    accumulator_input::*,
-    whitelist::*,
-};
-
-mod accumulator_input;
-mod whitelist;

+ 0 - 0
accumulator_updater/.gitignore → message_buffer/.gitignore


+ 0 - 0
accumulator_updater/.prettierignore → message_buffer/.prettierignore


+ 1 - 1
accumulator_updater/Anchor.toml → message_buffer/Anchor.toml

@@ -2,7 +2,7 @@
 seeds = true
 skip-lint = false
 [programs.localnet]
-accumulator_updater = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
+message_buffer = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 mock_cpi_caller = "Dg5PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
 
 [registry]

+ 9 - 9
accumulator_updater/Cargo.lock → message_buffer/Cargo.lock

@@ -2,14 +2,6 @@
 # It is not intended for manual editing.
 version = 3
 
-[[package]]
-name = "accumulator_updater"
-version = "0.1.0"
-dependencies = [
- "anchor-lang",
- "bytemuck",
-]
-
 [[package]]
 name = "ahash"
 version = "0.7.6"
@@ -893,13 +885,21 @@ dependencies = [
  "autocfg",
 ]
 
+[[package]]
+name = "message_buffer"
+version = "0.1.0"
+dependencies = [
+ "anchor-lang",
+ "bytemuck",
+]
+
 [[package]]
 name = "mock-cpi-caller"
 version = "0.1.0"
 dependencies = [
- "accumulator_updater",
  "anchor-lang",
  "bytemuck",
+ "message_buffer",
 ]
 
 [[package]]

+ 0 - 0
accumulator_updater/Cargo.toml → message_buffer/Cargo.toml


+ 0 - 0
accumulator_updater/NOTES.md → message_buffer/NOTES.md


+ 0 - 0
accumulator_updater/migrations/deploy.ts → message_buffer/migrations/deploy.ts


+ 0 - 0
accumulator_updater/package.json → message_buffer/package.json


+ 3 - 3
accumulator_updater/programs/accumulator_updater/Cargo.toml → message_buffer/programs/message_buffer/Cargo.toml

@@ -1,12 +1,12 @@
 [package]
-name = "accumulator_updater"
+name = "message_buffer"
 version = "0.1.0"
-description = "Accumulator Updater Pythnet Program"
+description = "Message Buffer Pythnet Program"
 edition = "2021"
 
 [lib]
 crate-type = ["cdylib", "lib"]
-name = "accumulator_updater"
+name = "message_buffer"
 
 [features]
 no-entrypoint = []

+ 0 - 0
accumulator_updater/programs/accumulator_updater/Xargo.toml → message_buffer/programs/message_buffer/Xargo.toml


+ 0 - 0
accumulator_updater/programs/accumulator_updater/src/instructions/mod.rs → message_buffer/programs/message_buffer/src/instructions/mod.rs


+ 8 - 8
accumulator_updater/programs/accumulator_updater/src/instructions/put_all.rs → message_buffer/programs/message_buffer/src/instructions/put_all.rs

@@ -13,7 +13,7 @@ use {
 };
 
 
-pub const ACCUMULATOR: &str = "accumulator";
+pub const MESSAGE: &str = "message";
 pub const FUND: &str = "fund";
 
 
@@ -26,7 +26,7 @@ pub fn put_all<'info>(
     let accumulator_input_ai = ctx
         .remaining_accounts
         .first()
-        .ok_or(AccumulatorUpdaterError::AccumulatorInputNotProvided)?;
+        .ok_or(AccumulatorUpdaterError::MessageBufferNotProvided)?;
 
     let loader;
 
@@ -35,7 +35,7 @@ pub fn put_all<'info>(
             let (pda, bump) = Pubkey::find_program_address(
                 &[
                     cpi_caller_auth.as_ref(),
-                    ACCUMULATOR.as_bytes(),
+                    MESSAGE.as_bytes(),
                     base_account_key.as_ref(),
                 ],
                 &crate::ID,
@@ -43,7 +43,7 @@ pub fn put_all<'info>(
             require_keys_eq!(accumulator_input_ai.key(), pda);
             let signer_seeds = [
                 cpi_caller_auth.as_ref(),
-                ACCUMULATOR.as_bytes(),
+                MESSAGE.as_bytes(),
                 base_account_key.as_ref(),
                 &[bump],
             ];
@@ -54,20 +54,20 @@ pub fn put_all<'info>(
             let fund_signer_seeds = [FUND.as_bytes(), &[fund_pda_bump]];
             PutAll::create_account(
                 accumulator_input_ai,
-                8 + AccumulatorInput::INIT_SPACE,
+                8 + MessageBuffer::INIT_SPACE,
                 &ctx.accounts.fund,
                 &[signer_seeds.as_slice(), fund_signer_seeds.as_slice()],
                 &ctx.accounts.system_program,
             )?;
-            loader = AccountLoader::<AccumulatorInput>::try_from_unchecked(
+            loader = AccountLoader::<MessageBuffer>::try_from_unchecked(
                 &crate::ID,
                 accumulator_input_ai,
             )?;
             let mut accumulator_input = loader.load_init()?;
-            accumulator_input.header = AccumulatorHeader::new(bump);
+            accumulator_input.header = BufferHeader::new(bump);
             accumulator_input
         } else {
-            loader = AccountLoader::<AccumulatorInput>::try_from(accumulator_input_ai)?;
+            loader = AccountLoader::<MessageBuffer>::try_from(accumulator_input_ai)?;
             let mut accumulator_input = loader.load_mut()?;
             accumulator_input.header.set_version();
             accumulator_input

+ 8 - 9
accumulator_updater/programs/accumulator_updater/src/lib.rs → message_buffer/programs/message_buffer/src/lib.rs

@@ -12,7 +12,7 @@ use {
 declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
 
 #[program]
-pub mod accumulator_updater {
+pub mod message_buffer {
     use super::*;
 
 
@@ -54,12 +54,13 @@ pub mod accumulator_updater {
 
     /// Insert messages/inputs for the Accumulator. All inputs derived from the
     /// `base_account_key` will go into the same PDA. The PDA is derived with
-    /// seeds = [cpi_caller, b"accumulator", base_account_key]
+    /// seeds = [cpi_caller_auth, b"accumulator", base_account_key]
     ///
     ///
     ///
     /// * `base_account_key`    - Pubkey of the original account the
-    ///                           AccumulatorInput is derived from
+    ///                           `MessageBuffer` is derived from
+    ///                           (e.g. pyth price account)
     /// * `messages`            - Vec of vec of bytes, each representing a message
     ///                           to be hashed and accumulated
     ///
@@ -92,7 +93,7 @@ pub struct Initialize<'info> {
     #[account(
         init,
         payer = payer,
-        seeds = [b"accumulator".as_ref(), b"whitelist".as_ref()],
+        seeds = [b"message".as_ref(), b"whitelist".as_ref()],
         bump,
         space = 8 + Whitelist::INIT_SPACE
     )]
@@ -109,7 +110,7 @@ pub struct UpdateWhitelist<'info> {
     pub authority: Signer<'info>,
     #[account(
         mut,
-        seeds = [b"accumulator".as_ref(), b"whitelist".as_ref()],
+        seeds = [b"message".as_ref(), b"whitelist".as_ref()],
         bump = whitelist.bump,
         has_one = authority
     )]
@@ -137,10 +138,8 @@ pub enum AccumulatorUpdaterError {
     InvalidPDA,
     #[msg("Update data exceeds current length")]
     CurrentDataLengthExceeded,
-    #[msg("Accumulator Input not writable")]
-    AccumulatorInputNotWritable,
-    #[msg("Accumulator Input not provided")]
-    AccumulatorInputNotProvided,
+    #[msg("Message Buffer not provided")]
+    MessageBufferNotProvided,
     #[msg("Fund Bump not found")]
     FundBumpNotFound,
 }

+ 1 - 1
accumulator_updater/programs/accumulator_updater/src/macros.rs → message_buffer/programs/message_buffer/src/macros.rs

@@ -3,7 +3,7 @@ macro_rules! accumulator_input_seeds {
     ($accumulator_input:expr, $cpi_caller_pid:expr, $base_account:expr) => {
         &[
             $cpi_caller_pid.as_ref(),
-            b"accumulator".as_ref(),
+            b"message".as_ref(),
             $base_account.as_ref(),
             &[$accumulator_input.header.bump],
         ]

+ 35 - 40
accumulator_updater/programs/accumulator_updater/src/state/accumulator_input.rs → message_buffer/programs/message_buffer/src/state/message_buffer.rs

@@ -7,7 +7,7 @@ use {
 };
 
 
-/// `AccumulatorInput` is an arbitrary set of bytes
+/// `MessageBuffer` is an arbitrary set of bytes
 /// that will be included in the AccumulatorSysvar
 ///
 ///
@@ -17,8 +17,8 @@ use {
 /// TODO: implement custom serialization & set alignment
 #[account(zero_copy)]
 #[derive(Debug, InitSpace)]
-pub struct AccumulatorInput {
-    pub header:   AccumulatorHeader,
+pub struct MessageBuffer {
+    pub header:   BufferHeader,
     // 10KB - 8 (discriminator) - 514 (header)
     // TODO: do we want to initialize this to the max size?
     //   - will lead to more data being passed around for validators
@@ -30,7 +30,7 @@ pub struct AccumulatorInput {
 // - what other fields are needed?
 #[zero_copy]
 #[derive(InitSpace, Debug)]
-pub struct AccumulatorHeader {
+pub struct BufferHeader {
     pub bump:        u8, // 1
     pub version:     u8, // 1
     // byte offset of accounts where data starts
@@ -44,11 +44,11 @@ pub struct AccumulatorHeader {
 }
 
 
-impl AccumulatorHeader {
+impl BufferHeader {
     // HEADER_LEN allows for append-only forward-compatibility for the header.
     // this is the number of bytes from the beginning of the account_info.data
     // to the start of the `AccumulatorInput` data.
-    pub const HEADER_LEN: u16 = 8 + AccumulatorHeader::INIT_SPACE as u16;
+    pub const HEADER_LEN: u16 = 8 + BufferHeader::INIT_SPACE as u16;
 
     pub const CURRENT_VERSION: u8 = 1;
 
@@ -65,9 +65,9 @@ impl AccumulatorHeader {
         self.version = Self::CURRENT_VERSION;
     }
 }
-impl AccumulatorInput {
+impl MessageBuffer {
     pub fn new(bump: u8) -> Self {
-        let header = AccumulatorHeader::new(bump);
+        let header = BufferHeader::new(bump);
         Self {
             header,
             messages: [0u8; 9_718],
@@ -146,15 +146,10 @@ mod test {
 
     #[test]
     fn test_sizes_and_alignments() {
-        let (header_idx_size, header_idx_align) = (
-            size_of::<AccumulatorHeader>(),
-            align_of::<AccumulatorHeader>(),
-        );
+        let (header_idx_size, header_idx_align) =
+            (size_of::<BufferHeader>(), align_of::<BufferHeader>());
 
-        let (input_size, input_align) = (
-            size_of::<AccumulatorInput>(),
-            align_of::<AccumulatorInput>(),
-        );
+        let (input_size, input_align) = (size_of::<MessageBuffer>(), align_of::<MessageBuffer>());
 
         assert_eq!(header_idx_size, 514);
         assert_eq!(header_idx_align, 2);
@@ -167,7 +162,7 @@ mod test {
         let data = vec![vec![12, 34], vec![56, 78, 90]];
         let data_bytes: Vec<Vec<u8>> = data.into_iter().map(data_bytes).collect();
 
-        let accumulator_input = &mut AccumulatorInput::new(0);
+        let accumulator_input = &mut MessageBuffer::new(0);
 
         let (num_msgs, num_bytes) = accumulator_input.put_all(&data_bytes);
         assert_eq!(num_msgs, 2);
@@ -178,7 +173,7 @@ mod test {
         assert_eq!(accumulator_input.header.end_offsets[1], 5);
 
 
-        let accumulator_input_bytes = bytes_of(accumulator_input);
+        let message_buffer_bytes = bytes_of(accumulator_input);
 
         // The header_len field represents the size of all data prior to the message bytes.
         // This includes the account discriminator, which is not part of the header struct.
@@ -195,9 +190,9 @@ mod test {
         let mut data_iter = data_bytes.iter();
         for offset in iter {
             let end_offset = header_len + *offset as usize;
-            let accumulator_input_data = &accumulator_input_bytes[start..end_offset];
+            let message_buffer_data = &message_buffer_bytes[start..end_offset];
             let expected_data = data_iter.next().unwrap();
-            assert_eq!(accumulator_input_data, expected_data.as_slice());
+            assert_eq!(message_buffer_data, expected_data.as_slice());
             start = end_offset;
         }
     }
@@ -207,23 +202,23 @@ mod test {
         let data = vec![vec![0u8; 9_718 - 2], vec![0u8], vec![0u8; 2]];
 
         let data_bytes: Vec<Vec<u8>> = data.into_iter().map(data_bytes).collect();
-        let accumulator_input = &mut AccumulatorInput::new(0);
-        let (num_msgs, num_bytes) = accumulator_input.put_all(&data_bytes);
+        let message_buffer = &mut MessageBuffer::new(0);
+        let (num_msgs, num_bytes) = message_buffer.put_all(&data_bytes);
         assert_eq!(num_msgs, 2);
         assert_eq!(
             num_bytes,
             data_bytes[0..2].iter().map(|x| x.len()).sum::<usize>() as u16
         );
 
-        let accumulator_input_bytes = bytes_of(accumulator_input);
+        let message_buffer_bytes = bytes_of(message_buffer);
 
         // The header_len field represents the size of all data prior to the message bytes.
         // This includes the account discriminator, which is not part of the header struct.
         // Subtract the size of the discriminator (8 bytes) to compensate
-        let header_len = accumulator_input.header.header_len as usize - 8;
+        let header_len = message_buffer.header.header_len as usize - 8;
 
 
-        let iter = accumulator_input
+        let iter = message_buffer
             .header
             .end_offsets
             .iter()
@@ -232,13 +227,13 @@ mod test {
         let mut data_iter = data_bytes.iter();
         for offset in iter {
             let end_offset = header_len + *offset as usize;
-            let accumulator_input_data = &accumulator_input_bytes[start..end_offset];
+            let message_buffer_data = &message_buffer_bytes[start..end_offset];
             let expected_data = data_iter.next().unwrap();
-            assert_eq!(accumulator_input_data, expected_data.as_slice());
+            assert_eq!(message_buffer_data, expected_data.as_slice());
             start = end_offset;
         }
 
-        assert_eq!(accumulator_input.header.end_offsets[2], 0);
+        assert_eq!(message_buffer.header.end_offsets[2], 0);
     }
 
     #[test]
@@ -252,22 +247,22 @@ mod test {
         ];
 
         let data_bytes: Vec<Vec<u8>> = data.into_iter().map(data_bytes).collect();
-        let accumulator_input = &mut AccumulatorInput::new(0);
-        let (num_msgs, num_bytes) = accumulator_input.put_all(&data_bytes);
+        let message_buffer = &mut MessageBuffer::new(0);
+        let (num_msgs, num_bytes) = message_buffer.put_all(&data_bytes);
         assert_eq!(num_msgs, 3);
         assert_eq!(
             num_bytes,
             data_bytes[0..3].iter().map(|x| x.len()).sum::<usize>() as u16
         );
 
-        let accumulator_input_bytes = bytes_of(accumulator_input);
+        let message_buffer_bytes = bytes_of(message_buffer);
 
         // *note* minus 8 here since no account discriminator when using
         // `bytes_of`directly on accumulator_input
-        let header_len = accumulator_input.header.header_len as usize - 8;
+        let header_len = message_buffer.header.header_len as usize - 8;
 
 
-        let iter = accumulator_input
+        let iter = message_buffer
             .header
             .end_offsets
             .iter()
@@ -276,16 +271,16 @@ mod test {
         let mut data_iter = data_bytes.iter();
         for offset in iter {
             let end_offset = header_len + *offset as usize;
-            let accumulator_input_data = &accumulator_input_bytes[start..end_offset];
+            let message_buffer_data = &message_buffer_bytes[start..end_offset];
             let expected_data = data_iter.next().unwrap();
-            assert_eq!(accumulator_input_data, expected_data.as_slice());
+            assert_eq!(message_buffer_data, expected_data.as_slice());
             start = end_offset;
         }
 
-        assert_eq!(accumulator_input.header.end_offsets[0], 9_715);
-        assert_eq!(accumulator_input.header.end_offsets[1], 9_716);
-        assert_eq!(accumulator_input.header.end_offsets[2], 9_717);
-        assert_eq!(accumulator_input.header.end_offsets[3], 0);
-        assert_eq!(accumulator_input.header.end_offsets[4], 0);
+        assert_eq!(message_buffer.header.end_offsets[0], 9_715);
+        assert_eq!(message_buffer.header.end_offsets[1], 9_716);
+        assert_eq!(message_buffer.header.end_offsets[2], 9_717);
+        assert_eq!(message_buffer.header.end_offsets[3], 0);
+        assert_eq!(message_buffer.header.end_offsets[4], 0);
     }
 }

+ 7 - 0
message_buffer/programs/message_buffer/src/state/mod.rs

@@ -0,0 +1,7 @@
+pub use {
+    self::message_buffer::*,
+    whitelist::*,
+};
+
+mod message_buffer;
+mod whitelist;

+ 1 - 1
accumulator_updater/programs/accumulator_updater/src/state/whitelist.rs → message_buffer/programs/message_buffer/src/state/whitelist.rs

@@ -38,7 +38,7 @@ impl Whitelist {
 #[derive(Accounts)]
 pub struct WhitelistVerifier<'info> {
     #[account(
-        seeds = [b"accumulator".as_ref(), b"whitelist".as_ref()],
+        seeds = [b"message".as_ref(), b"whitelist".as_ref()],
         bump = whitelist.bump,
     )]
     // Using a Box to move account from stack to heap

+ 1 - 1
accumulator_updater/programs/mock-cpi-caller/Cargo.toml → message_buffer/programs/mock-cpi-caller/Cargo.toml

@@ -17,6 +17,6 @@ default = []
 
 [dependencies]
 anchor-lang = "0.27.0"
-accumulator_updater = { path = "../accumulator_updater", features = ["cpi"] }
+message_buffer = { path = "../message_buffer", features = ["cpi"] }
 # needed for the new #[account(zero_copy)] in anchor 0.27.0
 bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"]}

+ 0 - 0
accumulator_updater/programs/mock-cpi-caller/Xargo.toml → message_buffer/programs/mock-cpi-caller/Xargo.toml


+ 12 - 12
accumulator_updater/programs/mock-cpi-caller/src/instructions/add_price.rs → message_buffer/programs/mock-cpi-caller/src/instructions/add_price.rs

@@ -18,11 +18,11 @@ use {
             PythAccountType,
         },
     },
-    accumulator_updater::program::AccumulatorUpdater as AccumulatorUpdaterProgram,
     anchor_lang::{
         prelude::*,
         system_program,
     },
+    message_buffer::program::MessageBuffer as MessageBufferProgram,
 };
 
 pub fn add_price<'info>(
@@ -74,7 +74,7 @@ impl<'info> AddPrice<'info> {
                 .collect::<Vec<_>>(),
         );
         let create_inputs_ix = anchor_lang::solana_program::instruction::Instruction {
-            program_id: ctx.accounts.accumulator_program.key(),
+            program_id: ctx.accounts.message_buffer_program.key(),
             accounts,
             data: (
                 //anchor ix discriminator/identifier
@@ -91,7 +91,7 @@ impl<'info> AddPrice<'info> {
         // that won't be available in the oracle program
         let (_, bump) = Pubkey::find_program_address(
             &[
-                ctx.accounts.accumulator_program.key().as_ref(),
+                ctx.accounts.message_buffer_program.key().as_ref(),
                 CPI.as_bytes(),
             ],
             &crate::ID,
@@ -100,7 +100,7 @@ impl<'info> AddPrice<'info> {
             &create_inputs_ix,
             account_infos,
             &[&[
-                ctx.accounts.accumulator_program.key().as_ref(),
+                ctx.accounts.message_buffer_program.key().as_ref(),
                 CPI.as_bytes(),
                 &[bump],
             ]],
@@ -128,24 +128,24 @@ pub struct AddPrice<'info> {
         bump,
         space = 8 + PriceAccount::INIT_SPACE
     )]
-    pub pyth_price_account:    AccountLoader<'info, PriceAccount>,
+    pub pyth_price_account:     AccountLoader<'info, PriceAccount>,
     #[account(mut)]
-    pub payer:                 Signer<'info>,
+    pub payer:                  Signer<'info>,
     #[account(mut)]
-    pub fund:                  SystemAccount<'info>,
+    pub fund:                   SystemAccount<'info>,
     /// also needed for accumulator_updater
-    pub system_program:        Program<'info, System>,
+    pub system_program:         Program<'info, System>,
     /// CHECK: whitelist
-    pub accumulator_whitelist: UncheckedAccount<'info>,
+    pub accumulator_whitelist:  UncheckedAccount<'info>,
     /// PDA representing this program's authority
     /// to call the accumulator program
     #[account(
-        seeds = [accumulator_program.key().as_ref(), b"cpi".as_ref()],
+        seeds = [message_buffer_program.key().as_ref(), b"cpi".as_ref()],
         owner = system_program::System::id(),
         bump,
     )]
-    pub auth:                  SystemAccount<'info>,
-    pub accumulator_program:   Program<'info, AccumulatorUpdaterProgram>,
+    pub auth:                   SystemAccount<'info>,
+    pub message_buffer_program: Program<'info, MessageBufferProgram>,
     // Remaining Accounts
     // should all be new uninitialized accounts
 }

+ 0 - 0
accumulator_updater/programs/mock-cpi-caller/src/instructions/cpi_max_test.rs → message_buffer/programs/mock-cpi-caller/src/instructions/cpi_max_test.rs


+ 0 - 0
accumulator_updater/programs/mock-cpi-caller/src/instructions/mod.rs → message_buffer/programs/mock-cpi-caller/src/instructions/mod.rs


+ 11 - 11
accumulator_updater/programs/mock-cpi-caller/src/instructions/update_price.rs → message_buffer/programs/mock-cpi-caller/src/instructions/update_price.rs

@@ -14,11 +14,11 @@ use {
         },
         state::PriceAccount,
     },
-    accumulator_updater::program::AccumulatorUpdater as AccumulatorUpdaterProgram,
     anchor_lang::{
         prelude::*,
         system_program,
     },
+    message_buffer::program::MessageBuffer as MessageBufferProgram,
 };
 
 #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, PartialEq, Eq)]
@@ -41,20 +41,20 @@ pub struct UpdatePrice<'info> {
     ],
     bump,
     )]
-    pub pyth_price_account:    AccountLoader<'info, PriceAccount>,
+    pub pyth_price_account:     AccountLoader<'info, PriceAccount>,
     #[account(mut)]
-    pub fund:                  SystemAccount<'info>,
+    pub fund:                   SystemAccount<'info>,
     /// Needed for accumulator_updater
-    pub system_program:        Program<'info, System>,
+    pub system_program:         Program<'info, System>,
     /// CHECK: whitelist
-    pub accumulator_whitelist: UncheckedAccount<'info>,
+    pub accumulator_whitelist:  UncheckedAccount<'info>,
     #[account(
-        seeds = [accumulator_program.key().as_ref(), b"cpi".as_ref()],
+        seeds = [message_buffer_program.key().as_ref(), b"cpi".as_ref()],
         owner = system_program::System::id(),
         bump,
     )]
-    pub auth:                  SystemAccount<'info>,
-    pub accumulator_program:   Program<'info, AccumulatorUpdaterProgram>,
+    pub auth:                   SystemAccount<'info>,
+    pub message_buffer_program: Program<'info, MessageBufferProgram>,
 }
 
 /// Updates the mock pyth price account and calls accumulator-updater
@@ -102,7 +102,7 @@ impl<'info> UpdatePrice<'info> {
                 .collect::<Vec<_>>(),
         );
         let update_inputs_ix = anchor_lang::solana_program::instruction::Instruction {
-            program_id: ctx.accounts.accumulator_program.key(),
+            program_id: ctx.accounts.message_buffer_program.key(),
             accounts,
             data: (
                 //anchor ix discriminator/identifier
@@ -119,7 +119,7 @@ impl<'info> UpdatePrice<'info> {
         // that won't be available in the oracle program
         let (_, bump) = Pubkey::find_program_address(
             &[
-                ctx.accounts.accumulator_program.key().as_ref(),
+                ctx.accounts.message_buffer_program.key().as_ref(),
                 CPI.as_bytes(),
             ],
             &crate::ID,
@@ -128,7 +128,7 @@ impl<'info> UpdatePrice<'info> {
             &update_inputs_ix,
             account_infos,
             &[&[
-                ctx.accounts.accumulator_program.key().as_ref(),
+                ctx.accounts.message_buffer_program.key().as_ref(),
                 CPI.as_bytes(),
                 &[bump],
             ]],

+ 1 - 1
accumulator_updater/programs/mock-cpi-caller/src/lib.rs → message_buffer/programs/mock-cpi-caller/src/lib.rs

@@ -49,7 +49,7 @@ mod test {
 
     #[test]
     fn ix_discriminator() {
-        let a = &(accumulator_updater::instruction::PutAll {
+        let a = &(message_buffer::instruction::PutAll {
             base_account_key: anchor_lang::prelude::Pubkey::default(),
             messages:         vec![],
         }

+ 0 - 0
accumulator_updater/programs/mock-cpi-caller/src/message.rs → message_buffer/programs/mock-cpi-caller/src/message.rs


+ 0 - 0
accumulator_updater/programs/mock-cpi-caller/src/message/price.rs → message_buffer/programs/mock-cpi-caller/src/message/price.rs


+ 0 - 0
accumulator_updater/programs/mock-cpi-caller/src/state/mod.rs → message_buffer/programs/mock-cpi-caller/src/state/mod.rs


+ 0 - 0
accumulator_updater/programs/mock-cpi-caller/src/state/price.rs → message_buffer/programs/mock-cpi-caller/src/state/price.rs


+ 55 - 65
accumulator_updater/tests/accumulator_updater.ts → message_buffer/tests/message_buffer.ts

@@ -1,6 +1,6 @@
 import * as anchor from "@coral-xyz/anchor";
 import { IdlTypes, Program, BorshAccountsCoder } from "@coral-xyz/anchor";
-import { AccumulatorUpdater } from "../target/types/accumulator_updater";
+import { MessageBuffer } from "../target/types/message_buffer";
 import { MockCpiCaller } from "../target/types/mock_cpi_caller";
 import lumina from "@lumina-dev/test";
 import { assert } from "chai";
@@ -11,17 +11,17 @@ import bs58 from "bs58";
 // transactions in this test -  https://lumina.fyi/debug
 lumina();
 
-const accumulatorUpdaterProgram = anchor.workspace
-  .AccumulatorUpdater as Program<AccumulatorUpdater>;
+const messageBufferProgram = anchor.workspace
+  .MessageBuffer as Program<MessageBuffer>;
 const mockCpiProg = anchor.workspace.MockCpiCaller as Program<MockCpiCaller>;
 let whitelistAuthority = anchor.web3.Keypair.generate();
 const [mockCpiCallerAuth] = anchor.web3.PublicKey.findProgramAddressSync(
-  [accumulatorUpdaterProgram.programId.toBuffer(), Buffer.from("cpi")],
+  [messageBufferProgram.programId.toBuffer(), Buffer.from("cpi")],
   mockCpiProg.programId
 );
 const [fundPda] = anchor.web3.PublicKey.findProgramAddressSync(
   [Buffer.from("fund")],
-  accumulatorUpdaterProgram.programId
+  messageBufferProgram.programId
 );
 
 const pythPriceAccountId = new anchor.BN(1);
@@ -40,14 +40,10 @@ const [pythPriceAccountPk] = anchor.web3.PublicKey.findProgramAddressSync(
   ],
   mockCpiProg.programId
 );
-
+const MESSAGE = Buffer.from("message");
 const [accumulatorPdaKey] = anchor.web3.PublicKey.findProgramAddressSync(
-  [
-    mockCpiCallerAuth.toBuffer(),
-    Buffer.from("accumulator"),
-    pythPriceAccountPk.toBuffer(),
-  ],
-  accumulatorUpdaterProgram.programId
+  [mockCpiCallerAuth.toBuffer(), MESSAGE, pythPriceAccountPk.toBuffer()],
+  messageBufferProgram.programId
 );
 
 let fundBalance = 100 * anchor.web3.LAMPORTS_PER_SOL;
@@ -58,8 +54,8 @@ describe("accumulator_updater", () => {
 
   const [whitelistPubkey, whitelistBump] =
     anchor.web3.PublicKey.findProgramAddressSync(
-      [Buffer.from("accumulator"), Buffer.from("whitelist")],
-      accumulatorUpdaterProgram.programId
+      [MESSAGE, Buffer.from("whitelist")],
+      messageBufferProgram.programId
     );
 
   before("transfer lamports to the fund", async () => {
@@ -68,13 +64,13 @@ describe("accumulator_updater", () => {
 
   it("Is initialized!", async () => {
     // Add your test here.
-    const tx = await accumulatorUpdaterProgram.methods
+    const tx = await messageBufferProgram.methods
       .initialize(whitelistAuthority.publicKey)
       .accounts({})
       .rpc();
     console.log("Your transaction signature", tx);
 
-    const whitelist = await accumulatorUpdaterProgram.account.whitelist.fetch(
+    const whitelist = await messageBufferProgram.account.whitelist.fetch(
       whitelistPubkey
     );
     assert.strictEqual(whitelist.bump, whitelistBump);
@@ -84,14 +80,14 @@ describe("accumulator_updater", () => {
 
   it("Sets allowed programs to the whitelist", async () => {
     const allowedProgramAuthorities = [mockCpiCallerAuth];
-    await accumulatorUpdaterProgram.methods
+    await messageBufferProgram.methods
       .setAllowedPrograms(allowedProgramAuthorities)
       .accounts({
         authority: whitelistAuthority.publicKey,
       })
       .signers([whitelistAuthority])
       .rpc();
-    const whitelist = await accumulatorUpdaterProgram.account.whitelist.fetch(
+    const whitelist = await messageBufferProgram.account.whitelist.fetch(
       whitelistPubkey
     );
     console.info(`whitelist after add: ${JSON.stringify(whitelist)}`);
@@ -106,7 +102,7 @@ describe("accumulator_updater", () => {
 
   it("Updates the whitelist authority", async () => {
     const newWhitelistAuthority = anchor.web3.Keypair.generate();
-    await accumulatorUpdaterProgram.methods
+    await messageBufferProgram.methods
       .updateWhitelistAuthority(newWhitelistAuthority.publicKey)
       .accounts({
         authority: whitelistAuthority.publicKey,
@@ -114,7 +110,7 @@ describe("accumulator_updater", () => {
       .signers([whitelistAuthority])
       .rpc();
 
-    const whitelist = await accumulatorUpdaterProgram.account.whitelist.fetch(
+    const whitelist = await messageBufferProgram.account.whitelist.fetch(
       whitelistPubkey
     );
     assert.isTrue(whitelist.authority.equals(newWhitelistAuthority.publicKey));
@@ -130,7 +126,7 @@ describe("accumulator_updater", () => {
         systemProgram: anchor.web3.SystemProgram.programId,
         auth: mockCpiCallerAuth,
         accumulatorWhitelist: whitelistPubkey,
-        accumulatorProgram: accumulatorUpdaterProgram.programId,
+        messageBufferProgram: messageBufferProgram.programId,
       })
       .pubkeys();
 
@@ -187,12 +183,10 @@ describe("accumulator_updater", () => {
       mockCpiCallerAddPriceTxPubkeys.pythPriceAccount
     );
 
-    const accumulatorInput =
-      await accumulatorUpdaterProgram.account.accumulatorInput.fetch(
-        accumulatorPdaKey
-      );
+    const messageBuffer =
+      await messageBufferProgram.account.messageBuffer.fetch(accumulatorPdaKey);
 
-    const accumulatorPriceMessages = parseAccumulatorInput(accumulatorInput);
+    const accumulatorPriceMessages = parseMessageBuffer(messageBuffer);
 
     console.log(
       `accumulatorPriceMessages: ${JSON.stringify(
@@ -207,31 +201,38 @@ describe("accumulator_updater", () => {
       assert.isTrue(pm.priceExpo.eq(addPriceParams.priceExpo));
     });
 
+    const fundBalanceAfter = await provider.connection.getBalance(fundPda);
+    assert.isTrue(fundBalance > fundBalanceAfter);
+  });
+
+  it("Fetches MessageBuffer using getProgramAccounts with discriminator", async () => {
     let discriminator =
-      BorshAccountsCoder.accountDiscriminator("AccumulatorInput");
-    let accumulatorInputDiscriminator = bs58.encode(discriminator);
+      BorshAccountsCoder.accountDiscriminator("MessageBuffer");
+    let messageBufferDiscriminator = bs58.encode(discriminator);
 
     // fetch using `getProgramAccounts` and memcmp filter
-    const accumulatorAccounts = await provider.connection.getProgramAccounts(
-      accumulatorUpdaterProgram.programId,
+    const messageBufferAccounts = await provider.connection.getProgramAccounts(
+      messageBufferProgram.programId,
       {
         filters: [
           {
             memcmp: {
               offset: 0,
-              bytes: accumulatorInputDiscriminator,
+              bytes: messageBufferDiscriminator,
             },
           },
         ],
       }
     );
+    const msgBufferAcctKeys = messageBufferAccounts.map((ai) =>
+      ai.pubkey.toString()
+    );
+    console.log(
+      `messageBufferAccounts: ${JSON.stringify(msgBufferAcctKeys, null, 2)}`
+    );
 
-    accumulatorAccounts
-      .map((a) => a.toString())
-      .includes(accumulatorPdaKey.toString());
-
-    const fundBalanceAfter = await provider.connection.getBalance(fundPda);
-    assert.isTrue(fundBalance > fundBalanceAfter);
+    assert.isTrue(messageBufferAccounts.length === 1);
+    msgBufferAcctKeys.includes(accumulatorPdaKey.toString());
   });
 
   it("Mock CPI Program - UpdatePrice", async () => {
@@ -253,7 +254,7 @@ describe("accumulator_updater", () => {
         pythPriceAccount: pythPriceAccountPk,
         auth: mockCpiCallerAuth,
         accumulatorWhitelist: whitelistPubkey,
-        accumulatorProgram: accumulatorUpdaterProgram.programId,
+        messageBufferProgram: messageBufferProgram.programId,
       })
       .remainingAccounts([accumulatorPdaMeta])
       .preInstructions([
@@ -270,12 +271,11 @@ describe("accumulator_updater", () => {
     assert.isTrue(pythPriceAccount.priceExpo.eq(updatePriceParams.priceExpo));
     assert.isTrue(pythPriceAccount.ema.eq(updatePriceParams.ema));
     assert.isTrue(pythPriceAccount.emaExpo.eq(updatePriceParams.emaExpo));
-    const accumulatorInput =
-      await accumulatorUpdaterProgram.account.accumulatorInput.fetch(
+    const messageBuffer =
+      await messageBufferProgram.account.messageBuffer.fetch(
         accumulatorPdaMeta.pubkey
       );
-    const updatedAccumulatorPriceMessages =
-      parseAccumulatorInput(accumulatorInput);
+    const updatedAccumulatorPriceMessages = parseMessageBuffer(messageBuffer);
 
     console.log(
       `updatedAccumulatorPriceMessages: ${JSON.stringify(
@@ -316,7 +316,7 @@ describe("accumulator_updater", () => {
           pythPriceAccount: pythPriceAccountPk,
           auth: mockCpiCallerAuth,
           accumulatorWhitelist: whitelistPubkey,
-          accumulatorProgram: accumulatorUpdaterProgram.programId,
+          messageBufferProgram: messageBufferProgram.programId,
         })
         .remainingAccounts([accumulatorPdaMeta])
         .preInstructions([
@@ -333,12 +333,11 @@ describe("accumulator_updater", () => {
       assert.isTrue(pythPriceAccount.priceExpo.eq(updatePriceParams.priceExpo));
       assert.isTrue(pythPriceAccount.ema.eq(updatePriceParams.ema));
       assert.isTrue(pythPriceAccount.emaExpo.eq(updatePriceParams.emaExpo));
-      const accumulatorInput =
-        await accumulatorUpdaterProgram.account.accumulatorInput.fetch(
+      const messageBuffer =
+        await messageBufferProgram.account.messageBuffer.fetch(
           accumulatorPdaMeta.pubkey
         );
-      const updatedAccumulatorPriceMessages =
-        parseAccumulatorInput(accumulatorInput);
+      const updatedAccumulatorPriceMessages = parseMessageBuffer(messageBuffer);
 
       console.log(
         `updatedAccumulatorPriceMessages: ${JSON.stringify(
@@ -382,7 +381,7 @@ describe("accumulator_updater", () => {
             pythPriceAccount: pythPriceAccountPk,
             auth: mockCpiCallerAuth,
             accumulatorWhitelist: whitelistPubkey,
-            accumulatorProgram: accumulatorUpdaterProgram.programId,
+            messageBufferProgram: messageBufferProgram.programId,
           })
           .remainingAccounts([accumulatorPdaMeta])
           .preInstructions([
@@ -404,12 +403,8 @@ export const getAccumulatorPdaMeta = (
   pythAccount: anchor.web3.PublicKey
 ): AccountMeta => {
   const accumulatorPdaKey = anchor.web3.PublicKey.findProgramAddressSync(
-    [
-      cpiCallerAuth.toBuffer(),
-      Buffer.from("accumulator"),
-      pythAccount.toBuffer(),
-    ],
-    accumulatorUpdaterProgram.programId
+    [cpiCallerAuth.toBuffer(), MESSAGE, pythAccount.toBuffer()],
+    messageBufferProgram.programId
   )[0];
   return {
     pubkey: accumulatorPdaKey,
@@ -418,15 +413,15 @@ export const getAccumulatorPdaMeta = (
   };
 };
 
-type AccumulatorInputHeader = IdlTypes<AccumulatorUpdater>["AccumulatorHeader"];
+type BufferHeader = IdlTypes<MessageBuffer>["BufferHeader"];
 
-// Parses AccumulatorInput.data into a PriceAccount or PriceOnly object based on the
+// Parses MessageBuffer.data into a PriceAccount or PriceOnly object based on the
 // accountType and accountSchema.
-function parseAccumulatorInput({
+function parseMessageBuffer({
   header,
   messages,
 }: {
-  header: AccumulatorInputHeader;
+  header: BufferHeader;
   messages: number[];
 }): AccumulatorPriceMessage[] {
   const accumulatorMessages = [];
@@ -464,12 +459,12 @@ type MessageHeader = {
   size: number;
 };
 
-type Message = {
+type MessageBuffer = {
   header: MessageHeader;
   data: Buffer;
 };
 
-function parseMessageBytes(data: Buffer): Message {
+function parseMessageBytes(data: Buffer): MessageBuffer {
   let offset = 0;
 
   const schema = data.readInt8(offset);
@@ -527,8 +522,3 @@ function parseCompactPriceMessage(data: Uint8Array): CompactPriceMessage {
     priceExpo: new anchor.BN(data.subarray(16, 24), "be"),
   };
 }
-
-interface AccumulatorInput<T> {
-  header: AccumulatorInputHeader;
-  account: T;
-}

+ 0 - 0
accumulator_updater/tsconfig.json → message_buffer/tsconfig.json


+ 0 - 0
accumulator_updater/yarn.lock → message_buffer/yarn.lock