From 8077cafbb9271ec7a0f29999ec3fb72d07424793 Mon Sep 17 00:00:00 2001 From: ananas-block Date: Wed, 26 Jun 2024 23:19:34 +0100 Subject: [PATCH] reduced indexed changelog proof size to NET_TREE_HEIGHT without canopy --- .../src/nullifier/address_queue_nullifier.rs | 13 +- merkle-tree/concurrent/src/lib.rs | 2 +- merkle-tree/indexed/src/changelog.rs | 3 +- merkle-tree/indexed/src/copy.rs | 34 +-- merkle-tree/indexed/src/lib.rs | 137 ++-------- merkle-tree/indexed/src/zero_copy.rs | 42 +-- merkle-tree/indexed/tests/tests.rs | 240 +++++------------- .../initialize_address_merkle_tree.rs | 5 +- .../src/processor/initialize_address_queue.rs | 1 - .../account-compression/src/state/address.rs | 8 +- .../system/src/invoke/verify_state_proof.rs | 9 +- .../tests/address_merkle_tree_tests.rs | 1 + test-programs/e2e-test/tests/test.rs | 2 +- test-utils/src/address_tree_rollover.rs | 26 +- test-utils/src/assert_address_merkle_tree.rs | 17 +- test-utils/src/indexer/test_indexer.rs | 2 +- test-utils/src/lib.rs | 4 +- test-utils/src/test_forester.rs | 39 +-- test-utils/src/transaction_params.rs | 2 +- 19 files changed, 187 insertions(+), 400 deletions(-) diff --git a/forester/src/nullifier/address_queue_nullifier.rs b/forester/src/nullifier/address_queue_nullifier.rs index 766bb6243d..f09914dab8 100644 --- a/forester/src/nullifier/address_queue_nullifier.rs +++ b/forester/src/nullifier/address_queue_nullifier.rs @@ -29,7 +29,7 @@ pub async fn empty_address_queue( loop { let merkle_tree = - get_indexed_merkle_tree::( + get_indexed_merkle_tree::( rpc, address_merkle_tree_pubkey, ) @@ -97,11 +97,12 @@ pub async fn get_changelog_indices( merkle_tree_pubkey: &Pubkey, client: &mut R, ) -> Result<(usize, usize), ForesterError> { - let merkle_tree = get_indexed_merkle_tree::( - client, - *merkle_tree_pubkey, - ) - .await; + let merkle_tree = + get_indexed_merkle_tree::( + client, + *merkle_tree_pubkey, + ) + .await; let changelog_index = merkle_tree.changelog_index(); let indexed_changelog_index = merkle_tree.indexed_changelog_index(); Ok((changelog_index, indexed_changelog_index)) diff --git a/merkle-tree/concurrent/src/lib.rs b/merkle-tree/concurrent/src/lib.rs index ca7047dcb4..0b610c6d14 100644 --- a/merkle-tree/concurrent/src/lib.rs +++ b/merkle-tree/concurrent/src/lib.rs @@ -442,7 +442,7 @@ where return Err(ConcurrentMerkleTreeError::CannotUpdateEmpty); } - if self.canopy_depth > 0 && proof.len() != self.height { + if self.canopy_depth > 0 { self.update_proof_from_canopy(leaf_index, proof)?; } if changelog_index != self.changelog_index() { diff --git a/merkle-tree/indexed/src/changelog.rs b/merkle-tree/indexed/src/changelog.rs index 5a3259f050..d2515d431a 100644 --- a/merkle-tree/indexed/src/changelog.rs +++ b/merkle-tree/indexed/src/changelog.rs @@ -1,5 +1,6 @@ use light_concurrent_merkle_tree::event::RawIndexedElement; +/// NET_HEIGHT = HEIGHT - CANOPY_DEPTH #[derive(Clone, Debug, PartialEq, Eq)] pub struct IndexedChangelogEntry where @@ -8,7 +9,7 @@ where /// Element that was a subject to the change. pub element: RawIndexedElement, /// Merkle proof of that operation. - pub proof: [[u8; 32]; NET_HEIGHT], // TODO: add const generic HEIGHT - CANOPY_DEPTH + pub proof: [[u8; 32]; NET_HEIGHT], /// Index of a changelog entry in `ConcurrentMerkleTree` corresponding to /// the same operation. pub changelog_index: usize, diff --git a/merkle-tree/indexed/src/copy.rs b/merkle-tree/indexed/src/copy.rs index 21fe1f16df..f5c1f7b8ce 100644 --- a/merkle-tree/indexed/src/copy.rs +++ b/merkle-tree/indexed/src/copy.rs @@ -11,7 +11,9 @@ use num_traits::{CheckedAdd, CheckedSub, ToBytes, Unsigned}; use crate::{errors::IndexedMerkleTreeError, IndexedMerkleTree}; #[derive(Debug)] -pub struct IndexedMerkleTreeCopy(IndexedMerkleTree) +pub struct IndexedMerkleTreeCopy( + IndexedMerkleTree, +) where H: Hasher, I: CheckedAdd @@ -25,7 +27,8 @@ where + Unsigned, usize: From; -impl IndexedMerkleTreeCopy +impl + IndexedMerkleTreeCopy where H: Hasher, I: CheckedAdd @@ -53,7 +56,7 @@ where let indexed_changelog_metadata: CyclicBoundedVecMetadata = unsafe { read_value_at(bytes, &mut offset) }; - let expected_size = IndexedMerkleTree::::size_in_account( + let expected_size = IndexedMerkleTree::::size_in_account( merkle_tree.height, merkle_tree.changelog.capacity(), merkle_tree.roots.capacity(), @@ -65,13 +68,8 @@ where ConcurrentMerkleTreeError::BufferSize(expected_size, bytes.len()), )); } - println!("pre offset {} ", offset); - let indexed_changelog = unsafe { read_cyclic_bounded_vec_at(bytes, &mut offset, &indexed_changelog_metadata) }; - println!("pre offset {} ", offset); - println!("meta data {:?}", indexed_changelog_metadata); - println!("bytes len {}", bytes.len()); Ok(Self(IndexedMerkleTree { merkle_tree, @@ -81,7 +79,8 @@ where } } -impl Deref for IndexedMerkleTreeCopy +impl Deref + for IndexedMerkleTreeCopy where H: Hasher, I: CheckedAdd @@ -95,7 +94,7 @@ where + Unsigned, usize: From, { - type Target = IndexedMerkleTree; + type Target = IndexedMerkleTree; fn deref(&self) -> &Self::Target { &self.0 @@ -120,8 +119,9 @@ mod test { const CANOPY_DEPTH: usize, const INDEXED_CHANGELOG_SIZE: usize, const OPERATIONS: usize, + const NET_HEIGHT: usize, >() { - let mut mt_1 = IndexedMerkleTree::::new( + let mut mt_1 = IndexedMerkleTree::::new( HEIGHT, CHANGELOG_SIZE, ROOTS, @@ -133,7 +133,7 @@ mod test { let mut bytes = vec![ 0u8; - IndexedMerkleTree::::size_in_account( + IndexedMerkleTree::::size_in_account( HEIGHT, CHANGELOG_SIZE, ROOTS, @@ -144,7 +144,7 @@ mod test { { let mut mt_2 = - IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_init( + IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_init( &mut bytes, HEIGHT, CANOPY_DEPTH, @@ -163,7 +163,7 @@ mod test { for _ in 0..OPERATIONS { // Reload the tree from bytes on each iteration. let mut mt_2 = - IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_mut( + IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_mut( &mut bytes, ) .unwrap(); @@ -177,7 +177,8 @@ mod test { // Read a copy of that Merkle tree. let mt_2 = - IndexedMerkleTreeCopy::::from_bytes_copy(&bytes).unwrap(); + IndexedMerkleTreeCopy::::from_bytes_copy(&bytes) + .unwrap(); assert_eq!(mt_1, *mt_2); } @@ -189,7 +190,7 @@ mod test { const ROOTS: usize = 2400; const CANOPY_DEPTH: usize = 10; const INDEXED_CHANGELOG_SIZE: usize = 256; - + const NET_HEIGHT: usize = 16; const OPERATIONS: usize = 1024; from_bytes_copy::< @@ -199,6 +200,7 @@ mod test { CANOPY_DEPTH, INDEXED_CHANGELOG_SIZE, OPERATIONS, + NET_HEIGHT, >() } } diff --git a/merkle-tree/indexed/src/lib.rs b/merkle-tree/indexed/src/lib.rs index 336547b0dc..e443ff3b9b 100644 --- a/merkle-tree/indexed/src/lib.rs +++ b/merkle-tree/indexed/src/lib.rs @@ -29,10 +29,10 @@ use crate::errors::IndexedMerkleTreeError; pub const HIGHEST_ADDRESS_PLUS_ONE: &str = "452312848583266388373324160190187140051835877600158453279131187530910662655"; -// , const NET_HEIGHT: usize + #[derive(Debug)] #[repr(C)] -pub struct IndexedMerkleTree +pub struct IndexedMerkleTree where H: Hasher, I: CheckedAdd @@ -47,17 +47,17 @@ where usize: From, { pub merkle_tree: ConcurrentMerkleTree, - pub indexed_changelog: CyclicBoundedVec>, + pub indexed_changelog: CyclicBoundedVec>, _index: PhantomData, } -pub type IndexedMerkleTree22 = IndexedMerkleTree; -pub type IndexedMerkleTree26 = IndexedMerkleTree; -pub type IndexedMerkleTree32 = IndexedMerkleTree; -pub type IndexedMerkleTree40 = IndexedMerkleTree; +pub type IndexedMerkleTree22 = IndexedMerkleTree; +pub type IndexedMerkleTree26 = IndexedMerkleTree; +pub type IndexedMerkleTree32 = IndexedMerkleTree; +pub type IndexedMerkleTree40 = IndexedMerkleTree; -impl IndexedMerkleTree +impl IndexedMerkleTree where H: Hasher, I: CheckedAdd @@ -96,7 +96,7 @@ where // indexed_changelog (metadata) + mem::size_of::() // indexed_changelog - + mem::size_of::>() * indexed_changelog_size + + mem::size_of::>() * indexed_changelog_size } pub fn new( @@ -135,20 +135,12 @@ where next_value: [0_u8; 32], index: I::zero(), }; - #[cfg(target_os = "solana")] - { - use solana_program::msg; - msg!("height: {}", self.height); - msg!("canopy_depth: {}", self.merkle_tree.canopy_depth); - msg!("height - canopy_depth: {}", self.height); - } let changelog_entry = IndexedChangelogEntry { element, - proof: H::zero_bytes()[..self.height].try_into().unwrap(), + proof: H::zero_bytes()[..NET_HEIGHT].try_into().unwrap(), changelog_index: 0, }; self.indexed_changelog.push(changelog_entry); - Ok(()) } @@ -187,16 +179,16 @@ where )?; // Emit changelog for low element. - // let proof = BoundedVec::from_slice(&); let low_element = RawIndexedElement { value: bigint_to_be_bytes_array::<32>(&element_bundle.new_low_element.value)?, next_index: element_bundle.new_low_element.next_index, next_value: bigint_to_be_bytes_array::<32>(&element_bundle.new_element.value)?, index: element_bundle.new_low_element.index, }; + let low_element_changelog_entry = IndexedChangelogEntry { element: low_element, - proof: H::zero_bytes()[..self.height].try_into().unwrap(), + proof: H::zero_bytes()[..NET_HEIGHT].try_into().unwrap(), changelog_index, }; self.indexed_changelog.push(low_element_changelog_entry); @@ -216,9 +208,10 @@ where }; let new_element_changelog_entry = IndexedChangelogEntry { element: new_element, - proof: proof.to_array()?, + proof: proof.as_slice()[..NET_HEIGHT].try_into().unwrap(), changelog_index, }; + self.indexed_changelog.push(new_element_changelog_entry); Ok(()) @@ -261,29 +254,12 @@ where low_element_next_value: &mut BigUint, low_leaf_proof: &mut BoundedVec<[u8; 32]>, ) -> Result<(), IndexedMerkleTreeError> { - #[cfg(target_os = "solana")] - { - solana_program::msg!("patch_elements_and_proof"); - solana_program::msg!("new_element: {:?}", new_element); - solana_program::msg!("low_element: {:?}", low_element); - solana_program::msg!("low_element_next_value: {:?}", low_element_next_value); - solana_program::msg!("indexed_changelog_index: {:?}", indexed_changelog_index); - // for (i, entry) in self.indexed_changelog.iter().enumerate() { - // solana_program::msg!("entry {}: {:?}", i, entry.element); - - // if i == 7 { - // break; - // } - // } - } let next_indexed_changelog_indices: Vec = self .indexed_changelog .iter_from(indexed_changelog_index)? .skip(1) .enumerate() .filter_map(|(index, changelog_entry)| { - // #[cfg(target_os = "solana")] - // solana_program::msg!("changelog_entry: {:?}", changelog_entry); if changelog_entry.element.index == low_element.index { Some((indexed_changelog_index + 1 + index) % self.indexed_changelog.len()) } else { @@ -291,18 +267,12 @@ where } }) .collect(); - #[cfg(target_os = "solana")] - solana_program::msg!( - "next_indexed_changelog_indices: {:?}", - next_indexed_changelog_indices - ); let mut new_low_element = None; for next_indexed_changelog_index in next_indexed_changelog_indices { let changelog_entry = &mut self.indexed_changelog[next_indexed_changelog_index]; - // #[cfg(target_os = "solana")] - // solana_program::msg!("patching with: changelog_entry: {:?}", changelog_entry); + let next_element_value = BigUint::from_bytes_be(&changelog_entry.element.next_value); if next_element_value < new_element.value { // If the next element is lower than the current element, it means @@ -327,70 +297,25 @@ where // Patch the next value. *low_element_next_value = BigUint::from_bytes_be(&changelog_entry.element.next_value); // Patch the proof. - // low_leaf_proof.clone_from(&BoundedVec::from_slice(&changelog_entry.proof[0..len])); for i in 0..low_leaf_proof.len() { low_leaf_proof[i] = changelog_entry.proof[i]; } - #[cfg(target_os = "solana")] - solana_program::msg!("low_leaf_proof len: {:?}", low_leaf_proof.len()); } // If we found a new low element. if let Some((new_low_element_changelog_index, new_low_element)) = new_low_element { let new_low_element_changelog_entry = &self.indexed_changelog[new_low_element_changelog_index]; - // #[cfg(target_os = "solana")] - // solana_program::msg!( - // "new_low_element_changelog_entry: {:?}", - // new_low_element_changelog_entry - // ); *changelog_index = new_low_element_changelog_entry.changelog_index; *low_element = IndexedElement { index: new_low_element_changelog_entry.element.index, value: new_low_element.clone(), next_index: new_low_element_changelog_entry.element.next_index, }; - #[cfg(target_os = "solana")] - solana_program::msg!("low_leaf_proof len: {:?}", low_leaf_proof.len()); - #[cfg(target_os = "solana")] - { - // solana_program::msg!( - // "new_low_element_changelog_entry len: {:?}", - // new_low_element_changelog_entry.proof.len() - // ); - // solana_program::msg!( - // "new_low_element_changelog_entry proof: {:?}", - // new_low_element_changelog_entry.proof - // ); - // solana_program::msg!( - // "new_low_element_changelog_entry element: {:?}", - // new_low_element_changelog_entry.element - // ); - } - #[cfg(not(target_os = "solana"))] - { - println!( - "new_low_element_changelog_entry len: {:?}", - new_low_element_changelog_entry.proof.len() - ); - println!( - "new_low_element_changelog_entry proof: {:?}", - new_low_element_changelog_entry.proof - ); - println!( - "new_low_element_changelog_entry element: {:?}", - new_low_element_changelog_entry.element - ); - } - // low_leaf_proof.clone_from(&BoundedVec::from_slice( - // &new_low_element_changelog_entry.proof[0..len], - // )); for i in 0..low_leaf_proof.len() { low_leaf_proof[i] = new_low_element_changelog_entry.proof[i]; } - #[cfg(target_os = "solana")] - solana_program::msg!("low_leaf_proof len: {:?}", low_leaf_proof.len()); new_element.next_index = low_element.next_index; // Start the patching process from scratch for the new low element. @@ -416,10 +341,6 @@ where mut low_element_next_value: BigUint, low_leaf_proof: &mut BoundedVec<[u8; 32]>, ) -> Result, IndexedMerkleTreeError> { - #[cfg(target_os = "solana")] - { - solana_program::msg!("low leaf proof capacity {:?}", low_leaf_proof.capacity()); - } self.patch_elements_and_proof( indexed_changelog_index, &mut changelog_index, @@ -428,10 +349,6 @@ where &mut low_element_next_value, low_leaf_proof, )?; - #[cfg(target_os = "solana")] - { - solana_program::msg!("low leaf proof capacity {:?}", low_leaf_proof.capacity()); - } // Check that the value of `new_element` belongs to the range // of `old_low_element`. if low_element.next_index == I::zero() { @@ -485,7 +402,7 @@ where }; let low_element_changelog_entry = IndexedChangelogEntry { element: new_low_element, - proof: low_leaf_proof.to_array()?, + proof: low_leaf_proof.as_slice()[..NET_HEIGHT].try_into().unwrap(), changelog_index: new_changelog_index, }; @@ -502,16 +419,7 @@ where let mut proof = BoundedVec::with_capacity(self.height); let new_leaf = new_element.hash::(&low_element_next_value)?; let (new_changelog_index, _) = self.merkle_tree.append_with_proof(&new_leaf, &mut proof)?; - #[cfg(target_os = "solana")] - { - solana_program::msg!(" appeneded with proof"); - solana_program::msg!("proof: {:?}", proof); - } - #[cfg(not(target_os = "solana"))] - { - println!(" appeneded with proof"); - println!("proof: {:?}", proof); - } + // Prepare raw new element to save in changelog. let raw_new_element = RawIndexedElement { value: bigint_to_be_bytes_array::<32>(&new_element.value).unwrap(), @@ -523,7 +431,7 @@ where // Emit changelog entry for new element. let new_element_changelog_entry = IndexedChangelogEntry { element: raw_new_element, - proof: proof.to_array()?, + proof: proof.as_slice()[..NET_HEIGHT].try_into().unwrap(), changelog_index: new_changelog_index, }; self.indexed_changelog.push(new_element_changelog_entry); @@ -539,7 +447,8 @@ where } } -impl Deref for IndexedMerkleTree +impl Deref + for IndexedMerkleTree where H: Hasher, I: CheckedAdd @@ -560,7 +469,8 @@ where } } -impl DerefMut for IndexedMerkleTree +impl DerefMut + for IndexedMerkleTree where H: Hasher, I: CheckedAdd @@ -579,7 +489,8 @@ where } } -impl PartialEq for IndexedMerkleTree +impl PartialEq + for IndexedMerkleTree where H: Hasher, I: CheckedAdd diff --git a/merkle-tree/indexed/src/zero_copy.rs b/merkle-tree/indexed/src/zero_copy.rs index 7d7d73e7cb..f408487ab7 100644 --- a/merkle-tree/indexed/src/zero_copy.rs +++ b/merkle-tree/indexed/src/zero_copy.rs @@ -18,7 +18,7 @@ use num_traits::{CheckedAdd, CheckedSub, ToBytes, Unsigned}; use crate::{errors::IndexedMerkleTreeError, IndexedMerkleTree}; #[derive(Debug)] -pub struct IndexedMerkleTreeZeroCopy<'a, H, I, const HEIGHT: usize> +pub struct IndexedMerkleTreeZeroCopy<'a, H, I, const HEIGHT: usize, const NET_HEIGHT: usize> where H: Hasher, I: CheckedAdd @@ -32,13 +32,14 @@ where + Unsigned, usize: From, { - pub merkle_tree: mem::ManuallyDrop>, + pub merkle_tree: mem::ManuallyDrop>, // The purpose of this field is ensuring that the wrapper does not outlive // the buffer. _bytes: &'a [u8], } -impl<'a, H, I, const HEIGHT: usize> IndexedMerkleTreeZeroCopy<'a, H, I, HEIGHT> +impl<'a, H, I, const HEIGHT: usize, const NET_HEIGHT: usize> + IndexedMerkleTreeZeroCopy<'a, H, I, HEIGHT, NET_HEIGHT> where H: Hasher, I: CheckedAdd @@ -61,7 +62,7 @@ where let indexed_changelog_metadata: *mut CyclicBoundedVecMetadata = unsafe { read_ptr_at(bytes, &mut offset) }; - let expected_size = IndexedMerkleTree::::size_in_account( + let expected_size = IndexedMerkleTree::::size_in_account( merkle_tree.height, merkle_tree.changelog.capacity(), merkle_tree.roots.capacity(), @@ -96,7 +97,8 @@ where } } -impl<'a, H, I, const HEIGHT: usize> Deref for IndexedMerkleTreeZeroCopy<'a, H, I, HEIGHT> +impl<'a, H, I, const HEIGHT: usize, const NET_HEIGHT: usize> Deref + for IndexedMerkleTreeZeroCopy<'a, H, I, HEIGHT, NET_HEIGHT> where H: Hasher, I: CheckedAdd @@ -110,7 +112,7 @@ where + Unsigned, usize: From, { - type Target = IndexedMerkleTree; + type Target = IndexedMerkleTree; fn deref(&self) -> &Self::Target { &self.merkle_tree @@ -118,8 +120,8 @@ where } #[derive(Debug)] -pub struct IndexedMerkleTreeZeroCopyMut<'a, H, I, const HEIGHT: usize>( - IndexedMerkleTreeZeroCopy<'a, H, I, HEIGHT>, +pub struct IndexedMerkleTreeZeroCopyMut<'a, H, I, const HEIGHT: usize, const NET_HEIGHT: usize>( + IndexedMerkleTreeZeroCopy<'a, H, I, HEIGHT, NET_HEIGHT>, ) where H: Hasher, @@ -134,7 +136,8 @@ where + Unsigned, usize: From; -impl<'a, H, I, const HEIGHT: usize> IndexedMerkleTreeZeroCopyMut<'a, H, I, HEIGHT> +impl<'a, H, I, const HEIGHT: usize, const NET_HEIGHT: usize> + IndexedMerkleTreeZeroCopyMut<'a, H, I, HEIGHT, NET_HEIGHT> where H: Hasher, I: CheckedAdd @@ -170,7 +173,7 @@ where roots_capacity, )?; - let expected_size = IndexedMerkleTree::::size_in_account( + let expected_size = IndexedMerkleTree::::size_in_account( height, changelog_capacity, roots_capacity, @@ -201,7 +204,8 @@ where } } -impl<'a, H, I, const HEIGHT: usize> Deref for IndexedMerkleTreeZeroCopyMut<'a, H, I, HEIGHT> +impl<'a, H, I, const HEIGHT: usize, const NET_HEIGHT: usize> Deref + for IndexedMerkleTreeZeroCopyMut<'a, H, I, HEIGHT, NET_HEIGHT> where H: Hasher, I: CheckedAdd @@ -215,14 +219,15 @@ where + Unsigned, usize: From, { - type Target = IndexedMerkleTree; + type Target = IndexedMerkleTree; fn deref(&self) -> &Self::Target { &self.0.merkle_tree } } -impl<'a, H, I, const HEIGHT: usize> DerefMut for IndexedMerkleTreeZeroCopyMut<'a, H, I, HEIGHT> +impl<'a, H, I, const HEIGHT: usize, const NET_HEIGHT: usize> DerefMut + for IndexedMerkleTreeZeroCopyMut<'a, H, I, HEIGHT, NET_HEIGHT> where H: Hasher, I: CheckedAdd @@ -252,13 +257,14 @@ mod test { fn from_bytes_zero_copy< const HEIGHT: usize, + const NET_HEIGHT: usize, const CHANGELOG_SIZE: usize, const ROOTS: usize, const CANOPY_DEPTH: usize, const INDEXED_CHANGELOG_SIZE: usize, const OPERATIONS: usize, >() { - let mut mt_1 = IndexedMerkleTree::::new( + let mut mt_1 = IndexedMerkleTree::::new( HEIGHT, CHANGELOG_SIZE, ROOTS, @@ -270,7 +276,7 @@ mod test { let mut bytes = vec![ 0u8; - IndexedMerkleTree::::size_in_account( + IndexedMerkleTree::::size_in_account( HEIGHT, CHANGELOG_SIZE, ROOTS, @@ -281,7 +287,7 @@ mod test { { let mut mt_2 = - IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_init( + IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_init( &mut bytes, HEIGHT, CANOPY_DEPTH, @@ -300,7 +306,7 @@ mod test { for _ in 0..OPERATIONS { // Reload the tree from bytes on each iteration. let mut mt_2 = - IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_mut( + IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_mut( &mut bytes, ) .unwrap(); @@ -316,6 +322,7 @@ mod test { #[test] fn test_from_bytes_zero_copy_26_1400_2400_10_256_1024() { const HEIGHT: usize = 26; + const NET_HEIGHT: usize = 16; const CHANGELOG_SIZE: usize = 1400; const ROOTS: usize = 2400; const CANOPY_DEPTH: usize = 10; @@ -325,6 +332,7 @@ mod test { from_bytes_zero_copy::< HEIGHT, + NET_HEIGHT, CHANGELOG_SIZE, ROOTS, CANOPY_DEPTH, diff --git a/merkle-tree/indexed/tests/tests.rs b/merkle-tree/indexed/tests/tests.rs index 4dc4180e08..3a346f7ae7 100644 --- a/merkle-tree/indexed/tests/tests.rs +++ b/merkle-tree/indexed/tests/tests.rs @@ -22,6 +22,7 @@ const MERKLE_TREE_CHANGELOG: usize = 256; const MERKLE_TREE_ROOTS: usize = 1024; const MERKLE_TREE_CANOPY: usize = 0; const MERKLE_TREE_INDEXED_CHANGELOG: usize = 64; +const NET_HEIGHT: usize = MERKLE_TREE_HEIGHT - MERKLE_TREE_CANOPY; const QUEUE_ELEMENTS: usize = 1024; @@ -58,7 +59,7 @@ enum RelayerUpdateError { fn program_update( // PDAs queue: &mut RefMut<'_, IndexedArray>, - merkle_tree: &mut RefMut<'_, IndexedMerkleTree>, + merkle_tree: &mut RefMut<'_, IndexedMerkleTree>, // Instruction data changelog_index: u16, indexed_changelog_index: u16, @@ -100,7 +101,7 @@ where fn relayer_update( // PDAs queue: &mut RefMut<'_, IndexedArray>, - merkle_tree: &mut RefMut<'_, IndexedMerkleTree>, + merkle_tree: &mut RefMut<'_, IndexedMerkleTree>, ) -> Result<(), RelayerUpdateError> where H: Hasher, @@ -267,16 +268,17 @@ where // On-chain PDAs. let onchain_queue: RefCell> = RefCell::new(IndexedArray::default()); - let onchain_tree: RefCell> = RefCell::new( - IndexedMerkleTree::new( - MERKLE_TREE_HEIGHT, - MERKLE_TREE_CHANGELOG, - MERKLE_TREE_ROOTS, - MERKLE_TREE_CANOPY, - MERKLE_TREE_INDEXED_CHANGELOG, - ) - .unwrap(), - ); + let onchain_tree: RefCell> = + RefCell::new( + IndexedMerkleTree::new( + MERKLE_TREE_HEIGHT, + MERKLE_TREE_CHANGELOG, + MERKLE_TREE_ROOTS, + MERKLE_TREE_CANOPY, + MERKLE_TREE_INDEXED_CHANGELOG, + ) + .unwrap(), + ); onchain_tree.borrow_mut().init().unwrap(); // Insert a pair of nullifiers. @@ -325,16 +327,17 @@ where // On-chain PDAs. let onchain_queue: RefCell> = RefCell::new(IndexedArray::default()); - let onchain_tree: RefCell> = RefCell::new( - IndexedMerkleTree::new( - MERKLE_TREE_HEIGHT, - MERKLE_TREE_CHANGELOG, - MERKLE_TREE_ROOTS, - MERKLE_TREE_CANOPY, - MERKLE_TREE_INDEXED_CHANGELOG, - ) - .unwrap(), - ); + let onchain_tree: RefCell> = + RefCell::new( + IndexedMerkleTree::new( + MERKLE_TREE_HEIGHT, + MERKLE_TREE_CHANGELOG, + MERKLE_TREE_ROOTS, + MERKLE_TREE_CANOPY, + MERKLE_TREE_INDEXED_CHANGELOG, + ) + .unwrap(), + ); onchain_tree.borrow_mut().init().unwrap(); // Insert a pair of nulifiers. @@ -400,16 +403,17 @@ where // On-chain PDAs. let onchain_queue: RefCell> = RefCell::new(IndexedArray::default()); - let onchain_tree: RefCell> = RefCell::new( - IndexedMerkleTree::new( - MERKLE_TREE_HEIGHT, - MERKLE_TREE_CHANGELOG, - MERKLE_TREE_ROOTS, - MERKLE_TREE_CANOPY, - MERKLE_TREE_INDEXED_CHANGELOG, - ) - .unwrap(), - ); + let onchain_tree: RefCell> = + RefCell::new( + IndexedMerkleTree::new( + MERKLE_TREE_HEIGHT, + MERKLE_TREE_CHANGELOG, + MERKLE_TREE_ROOTS, + MERKLE_TREE_CANOPY, + MERKLE_TREE_INDEXED_CHANGELOG, + ) + .unwrap(), + ); onchain_tree.borrow_mut().init().unwrap(); // Local artifacts. @@ -856,8 +860,10 @@ fn functional_changelog_test_1() { let address_1 = 30_u32.to_biguint().unwrap(); let address_2 = 10_u32.to_biguint().unwrap(); let address_3 = 11_u32.to_biguint().unwrap(); - - perform_change_log_test::(&[address_1, address_2, address_3]); + const HEIGHT: usize = 10; + perform_change_log_test::(&[ + address_1, address_2, address_3, + ]); } /// Performs conflicting Merkle tree updates where: @@ -872,8 +878,9 @@ fn functional_changelog_test_1() { fn functional_changelog_test_2() { let address_1 = 10_u32.to_biguint().unwrap(); let address_2 = 30_u32.to_biguint().unwrap(); + const HEIGHT: usize = 10; - perform_change_log_test::(&[address_1, address_2]); + perform_change_log_test::(&[address_1, address_2]); } /// Performs conflicting Merkle tree updates where: @@ -893,8 +900,11 @@ fn functional_changelog_test_3() { let address_1 = 30_u32.to_biguint().unwrap(); let address_2 = 10_u32.to_biguint().unwrap(); let address_3 = 20_u32.to_biguint().unwrap(); + const HEIGHT: usize = 10; - perform_change_log_test::(&[address_1, address_2, address_3]); + perform_change_log_test::(&[ + address_1, address_2, address_3, + ]); } /// Performs conflicting Merkle tree updates where two parties try to insert @@ -902,8 +912,12 @@ fn functional_changelog_test_3() { #[test] fn functional_changelog_test_double_spend() { let address = 10_u32.to_biguint().unwrap(); + const HEIGHT: usize = 10; - perform_change_log_test::(&[address.clone(), address.clone()]); + perform_change_log_test::(&[ + address.clone(), + address.clone(), + ]); } #[test] @@ -914,6 +928,7 @@ fn functional_changelog_test_random_8_512_512_0_512() { const CANOPY: usize = 0; const INDEXED_CHANGELOG: usize = 512; const N_OPERATIONS: usize = (1 << HEIGHT) / 2; + const NET_HEIGHT: usize = HEIGHT - CANOPY; functional_changelog_test_random::< false, @@ -923,6 +938,7 @@ fn functional_changelog_test_random_8_512_512_0_512() { CANOPY, INDEXED_CHANGELOG, N_OPERATIONS, + NET_HEIGHT, >() } @@ -937,6 +953,7 @@ fn functional_changelog_test_random_wrap_around_8_128_512_0_512() { const CANOPY: usize = 0; const INDEXED_CHANGELOG: usize = 128; const N_OPERATIONS: usize = (1 << HEIGHT) / 2; + const NET_HEIGHT: usize = HEIGHT - CANOPY; for _ in 0..100 { functional_changelog_test_random::< true, @@ -946,6 +963,7 @@ fn functional_changelog_test_random_wrap_around_8_128_512_0_512() { CANOPY, INDEXED_CHANGELOG, N_OPERATIONS, + NET_HEIGHT, >() } } @@ -961,6 +979,7 @@ fn functional_changelog_test_random< const CANOPY: usize, const INDEXED_CHANGELOG: usize, const N_OPERATIONS: usize, + const NET_HEIGHT: usize, >() { let mut rng = thread_rng(); @@ -973,6 +992,7 @@ fn functional_changelog_test_random< ROOTS, CANOPY, INDEXED_CHANGELOG, + NET_HEIGHT, >(&leaves); } @@ -1004,6 +1024,7 @@ fn perform_change_log_test< const ROOTS: usize, const CANOPY: usize, const INDEXED_CHANGELOG: usize, + const NET_HEIGHT: usize, >( addresses: &[BigUint], ) { @@ -1013,14 +1034,15 @@ fn perform_change_log_test< relayer_indexed_array.init().unwrap(); let mut relayer_merkle_tree = reference::IndexedMerkleTree::::new(HEIGHT, CANOPY).unwrap(); - let mut onchain_indexed_merkle_tree = IndexedMerkleTree::::new( - HEIGHT, - CHANGELOG, - ROOTS, - CANOPY, - INDEXED_CHANGELOG, - ) - .unwrap(); + let mut onchain_indexed_merkle_tree = + IndexedMerkleTree::::new( + HEIGHT, + CHANGELOG, + ROOTS, + CANOPY, + INDEXED_CHANGELOG, + ) + .unwrap(); onchain_indexed_merkle_tree.init().unwrap(); onchain_indexed_merkle_tree.add_highest_element().unwrap(); relayer_merkle_tree.init().unwrap(); @@ -1108,132 +1130,4 @@ fn perform_change_log_test< } } } - let mut bytes = vec![ - 0u8; - IndexedMerkleTree::::size_in_account( - HEIGHT, 1400, ROOTS, 10, 256 - ) - ]; -} - -fn perform_change_log_test_2< - const DOUBLE_SPEND: bool, - const WRAP_AROUND: bool, - const HEIGHT: usize, - const CHANGELOG: usize, - const ROOTS: usize, - const CANOPY: usize, - const INDEXED_CHANGELOG: usize, ->( - addresses: &[BigUint], -) { - // Initialize the trees and indexed array. - let mut relayer_indexed_array = - IndexedArray::::default(); - relayer_indexed_array.init().unwrap(); - let mut relayer_merkle_tree = - reference::IndexedMerkleTree::::new(HEIGHT, CANOPY).unwrap(); - let mut onchain_indexed_merkle_tree = IndexedMerkleTree::::new( - HEIGHT, - CHANGELOG, - ROOTS, - CANOPY, - INDEXED_CHANGELOG, - ) - .unwrap(); - onchain_indexed_merkle_tree.init().unwrap(); - onchain_indexed_merkle_tree.add_highest_element().unwrap(); - relayer_merkle_tree.init().unwrap(); - assert_eq!( - relayer_merkle_tree.root(), - onchain_indexed_merkle_tree.root(), - "environment setup failed relayer and onchain indexed Merkle tree roots are inconsistent" - ); - - // Perform updates for each actor, where every of them is using the same - // changelog indices, generating a conflict which needs to be solved by - // patching from changelog. - let mut indexed_arrays = vec![relayer_indexed_array.clone(); addresses.len()]; - let changelog_index = onchain_indexed_merkle_tree.changelog_index(); - let indexed_changelog_index = onchain_indexed_merkle_tree.indexed_changelog_index(); - for (i, (address, indexed_array)) in addresses.iter().zip(indexed_arrays.iter_mut()).enumerate() - { - let (old_low_address, old_low_address_next_value) = indexed_array - .find_low_element_for_nonexistent(&address) - .unwrap(); - let address_bundle = indexed_array - .new_element_with_low_element_index(old_low_address.index, address) - .unwrap(); - - let mut low_element_proof = relayer_merkle_tree - .get_proof_of_leaf(old_low_address.index, false) - .unwrap(); - - if DOUBLE_SPEND && i > 0 { - let res = onchain_indexed_merkle_tree.update( - changelog_index, - indexed_changelog_index, - address_bundle.new_element, - old_low_address, - old_low_address_next_value, - &mut low_element_proof, - ); - assert!(matches!( - res, - Err(IndexedMerkleTreeError::NewElementGreaterOrEqualToNextElement) - )); - } else if WRAP_AROUND && (i + 1) * 2 > INDEXED_CHANGELOG { - // After a wrap-around of the indexed changelog, we expect leaf - // updates to break immediately. - let res = onchain_indexed_merkle_tree.update( - changelog_index, - indexed_changelog_index, - address_bundle.new_element.clone(), - old_low_address.clone(), - old_low_address_next_value, - &mut low_element_proof, - ); - println!("changelog_index {:?}", changelog_index); - println!("indexed_changelog_index {:?}", indexed_changelog_index); - println!( - "address_bundle new_element_next_value{:?}", - address_bundle.new_element_next_value - ); - println!( - "address_bundle new_element {:?}", - address_bundle.new_element - ); - - println!("old_low_address {:?}", old_low_address); - println!("res {:?}", res); - assert!(matches!( - res, - Err(IndexedMerkleTreeError::ConcurrentMerkleTree( - ConcurrentMerkleTreeError::CannotUpdateLeaf - )) - )); - } else { - onchain_indexed_merkle_tree - .update( - changelog_index, - indexed_changelog_index, - address_bundle.new_element, - old_low_address, - old_low_address_next_value, - &mut low_element_proof, - ) - .unwrap(); - } - } -} - -/// -#[test] -fn debug_changelog() { - let address = 10_u32.to_biguint().unwrap(); - - perform_change_log_test_2::(&[ - address.clone(), - address.clone(), - ]); } diff --git a/programs/account-compression/src/processor/initialize_address_merkle_tree.rs b/programs/account-compression/src/processor/initialize_address_merkle_tree.rs index 9c86551077..46825bb9d1 100644 --- a/programs/account-compression/src/processor/initialize_address_merkle_tree.rs +++ b/programs/account-compression/src/processor/initialize_address_merkle_tree.rs @@ -48,8 +48,9 @@ pub fn process_initialize_address_merkle_tree( roots_size as usize, address_changelog_size as usize, )?; + msg!("Initialized address merkle tree"); merkle_tree.init().map_err(ProgramError::from)?; - + msg!("inited"); // Initialize the address merkle tree with the bn254 Fr field size - 1 // This is the highest value that you can poseidon hash with poseidon syscalls. // Initializing the indexed Merkle tree enables non-inclusion proofs without handling the first case specifically. @@ -57,5 +58,7 @@ pub fn process_initialize_address_merkle_tree( merkle_tree .add_highest_element() .map_err(ProgramError::from)?; + msg!("added_highest_element"); + Ok(()) } diff --git a/programs/account-compression/src/processor/initialize_address_queue.rs b/programs/account-compression/src/processor/initialize_address_queue.rs index 9375a0c109..fdb9b63842 100644 --- a/programs/account-compression/src/processor/initialize_address_queue.rs +++ b/programs/account-compression/src/processor/initialize_address_queue.rs @@ -36,7 +36,6 @@ pub fn process_initialize_address_queue<'info>( } else { 0 }; - msg!(" addres squeue rollover_fee: {}", rollover_fee); address_queue.init( AccessMetadata::new(owner, program_owner), RolloverMetadata::new( diff --git a/programs/account-compression/src/state/address.rs b/programs/account-compression/src/state/address.rs index cc24e0f0d4..0015702d86 100644 --- a/programs/account-compression/src/state/address.rs +++ b/programs/account-compression/src/state/address.rs @@ -38,7 +38,7 @@ impl AddressMerkleTreeAccount { indexed_changelog_size: usize, ) -> usize { 8 + mem::size_of::() - + IndexedMerkleTree::::size_in_account( + + IndexedMerkleTree::::size_in_account( height, changelog_size, roots_size, @@ -60,7 +60,7 @@ impl AddressMerkleTreeAccount { pub fn address_merkle_tree_from_bytes_zero_copy( data: &[u8], -) -> Result> { +) -> Result> { let data = &data[8 + mem::size_of::()..]; let merkle_tree = IndexedMerkleTreeZeroCopy::from_bytes_zero_copy(data).map_err(ProgramError::from)?; @@ -74,7 +74,7 @@ pub fn address_merkle_tree_from_bytes_zero_copy_init( changelog_capacity: usize, roots_capacity: usize, indexed_changelog_capacity: usize, -) -> Result> { +) -> Result> { let data = &mut data[8 + mem::size_of::()..]; let merkle_tree = IndexedMerkleTreeZeroCopyMut::from_bytes_zero_copy_init( data, @@ -90,7 +90,7 @@ pub fn address_merkle_tree_from_bytes_zero_copy_init( pub fn address_merkle_tree_from_bytes_zero_copy_mut( data: &mut [u8], -) -> Result> { +) -> Result> { let data = &mut data[8 + mem::size_of::()..]; let merkle_tree = IndexedMerkleTreeZeroCopyMut::from_bytes_zero_copy_mut(data).map_err(ProgramError::from)?; diff --git a/programs/system/src/invoke/verify_state_proof.rs b/programs/system/src/invoke/verify_state_proof.rs index 9c6b6304c2..31a35d8eb0 100644 --- a/programs/system/src/invoke/verify_state_proof.rs +++ b/programs/system/src/invoke/verify_state_proof.rs @@ -69,10 +69,11 @@ pub fn fetch_roots_address_merkle_tree< .to_account_info(); let merkle_tree = merkle_tree.try_borrow_data()?; check_discriminator::(&merkle_tree)?; - let merkle_tree = IndexedMerkleTreeZeroCopy::::from_bytes_zero_copy( - &merkle_tree[8 + mem::size_of::()..], - ) - .map_err(ProgramError::from)?; + let merkle_tree = + IndexedMerkleTreeZeroCopy::::from_bytes_zero_copy( + &merkle_tree[8 + mem::size_of::()..], + ) + .map_err(ProgramError::from)?; let fetched_roots = &merkle_tree.roots; roots[j] = fetched_roots[index_mt_account.address_merkle_tree_root_index as usize]; diff --git a/test-programs/account-compression-test/tests/address_merkle_tree_tests.rs b/test-programs/account-compression-test/tests/address_merkle_tree_tests.rs index cd51d1c6c6..1268c92887 100644 --- a/test-programs/account-compression-test/tests/address_merkle_tree_tests.rs +++ b/test-programs/account-compression-test/tests/address_merkle_tree_tests.rs @@ -514,6 +514,7 @@ async fn update_address_merkle_tree_failing_tests(merkle_tree_config: &AddressMe Poseidon, usize, 26, + 16, >(&mut context, address_merkle_tree_pubkey) .await; let changelog_index = address_merkle_tree.changelog_index(); diff --git a/test-programs/e2e-test/tests/test.rs b/test-programs/e2e-test/tests/test.rs index 855f73452c..38c85e27bb 100644 --- a/test-programs/e2e-test/tests/test.rs +++ b/test-programs/e2e-test/tests/test.rs @@ -32,7 +32,7 @@ async fn test_10000_all() { KeypairActionConfig::all_default(), GeneralActionConfig::default(), 10000, - Some(17695267035445945231), + None, ) .await; env.execute_rounds().await; diff --git a/test-utils/src/address_tree_rollover.rs b/test-utils/src/address_tree_rollover.rs index c360bba74d..c6c55de027 100644 --- a/test-utils/src/address_tree_rollover.rs +++ b/test-utils/src/address_tree_rollover.rs @@ -36,7 +36,7 @@ pub async fn set_address_merkle_tree_next_index( ) { let mut merkle_tree = rpc.get_account(*merkle_tree_pubkey).await.unwrap().unwrap(); let merkle_tree_deserialized = - &mut IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_mut( + &mut IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_mut( &mut merkle_tree.data[8 + std::mem::size_of::()..], ) .unwrap(); @@ -48,7 +48,7 @@ pub async fn set_address_merkle_tree_next_index( rpc.set_account(merkle_tree_pubkey, &account_share_data); let mut merkle_tree = rpc.get_account(*merkle_tree_pubkey).await.unwrap().unwrap(); let merkle_tree_deserialized = - IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_mut( + IndexedMerkleTreeZeroCopyMut::::from_bytes_zero_copy_mut( &mut merkle_tree.data[8 + std::mem::size_of::()..], ) .unwrap(); @@ -185,16 +185,18 @@ pub async fn assert_rolled_over_address_merkle_tree_and_queue( drop(new_loaded_mt_account); drop(old_loaded_mt_account); - let struct_old = get_indexed_merkle_tree::( - rpc, - old_mt_account.key(), - ) - .await; - let struct_new = get_indexed_merkle_tree::( - rpc, - new_mt_account.key(), - ) - .await; + let struct_old = + get_indexed_merkle_tree::( + rpc, + old_mt_account.key(), + ) + .await; + let struct_new = + get_indexed_merkle_tree::( + rpc, + new_mt_account.key(), + ) + .await; assert_rolledover_merkle_trees(&struct_old.merkle_tree, &struct_new.merkle_tree); { diff --git a/test-utils/src/assert_address_merkle_tree.rs b/test-utils/src/assert_address_merkle_tree.rs index fc1005dc57..dd1fa13965 100644 --- a/test-utils/src/assert_address_merkle_tree.rs +++ b/test-utils/src/assert_address_merkle_tree.rs @@ -15,7 +15,7 @@ pub async fn assert_address_merkle_tree_initialized( expected_next_index: usize, expected_rightmost_leaf: &[u8; 32], owner_pubkey: &Pubkey, - expected_indexed_changelog_length: usize, + _expected_indexed_changelog_length: usize, ) { let merkle_tree = AccountZeroCopy::::new( rpc, @@ -81,6 +81,7 @@ pub async fn assert_address_merkle_tree_initialized( Poseidon, usize, 26, + 16, >(rpc, *merkle_tree_pubkey) .await; @@ -116,17 +117,5 @@ pub async fn assert_address_merkle_tree_initialized( expected_roots_length.saturating_sub(1) ); assert_eq!(&merkle_tree.rightmost_leaf(), expected_rightmost_leaf); - - // assert_eq!( - // merkle_tree.changelog.len(), - // expected_indexed_changelog_length - // ); - // assert_eq!( - // merkle_tree.changelog.capacity(), - // expected_indexed_changelog_length - // ); - // for i in merkle_tree.changelog.iter() { - // println!("changelog: {:?}", i); - // } - // panic!() + // TODO: complete asserts } diff --git a/test-utils/src/indexer/test_indexer.rs b/test-utils/src/indexer/test_indexer.rs index 954d43109d..df169cd8c5 100644 --- a/test-utils/src/indexer/test_indexer.rs +++ b/test-utils/src/indexer/test_indexer.rs @@ -707,7 +707,7 @@ impl TestIndexer( + get_indexed_merkle_tree::( rpc, address_merkle_tree_pubkeys[i], ) diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index e53dae0549..d476494d1c 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -96,10 +96,10 @@ where // TODO: do discriminator check /// Fetches the fiven account, then copies and serializes it as an /// `IndexedMerkleTree`. -pub async fn get_indexed_merkle_tree( +pub async fn get_indexed_merkle_tree( rpc: &mut R, pubkey: Pubkey, -) -> IndexedMerkleTreeCopy +) -> IndexedMerkleTreeCopy where R: RpcConnection, H: Hasher, diff --git a/test-utils/src/test_forester.rs b/test-utils/src/test_forester.rs index db359952c7..b927a563f7 100644 --- a/test-utils/src/test_forester.rs +++ b/test-utils/src/test_forester.rs @@ -263,7 +263,7 @@ pub async fn empty_address_queue_test = Vec::new(); let address_merkle_tree = - get_indexed_merkle_tree::( + get_indexed_merkle_tree::( rpc, address_merkle_tree_pubkey, ) @@ -282,7 +282,7 @@ pub async fn empty_address_queue_test( + get_indexed_merkle_tree::( rpc, address_merkle_tree_pubkey, ) @@ -292,7 +292,7 @@ pub async fn empty_address_queue_test(rpc, address_queue_pubkey).await }; let address = address_queue.first_no_seq().unwrap(); - println!("address: {:?}", address); + if address.is_none() { break; } @@ -309,9 +309,6 @@ pub async fn empty_address_queue_test( + get_indexed_merkle_tree::( rpc, address_merkle_tree_pubkey, ) .await; - let account = rpc - .get_account(address_merkle_tree_pubkey) - .await - .unwrap() - .unwrap(); - let account_data = account.data.clone(); - println!("account data len {:?}", account_data.len()); - println!( - "std::mem::size_of::() {:?}", - std::mem::size_of::() - ); - let merkle_tree = IndexedMerkleTreeCopy::::from_bytes_copy( - &account_data[8 + std::mem::size_of::()..], - ) - .unwrap(); - // println!( - // "merkle_tree.indexed_changelog_index(): {:?}", - // merkle_tree.indexed_changelog_index() - // ); - // println!("merkle_tree[0]: {:?}", merkle_tree.indexed_changelog[0]); - // println!("merkle_tree[1]: {:?}", merkle_tree.indexed_changelog[1]); - // println!("merkle_tree[2]: {:?}", merkle_tree.indexed_changelog[2]); - // println!("merkle_tree[3]: {:?}", merkle_tree.indexed_changelog[3]); + let (old_low_address, old_low_address_next_value) = relayer_indexing_array .find_low_element_for_nonexistent(&address.value_biguint()) .unwrap(); @@ -530,7 +505,7 @@ pub async fn update_merkle_tree( Some(changelog_index) => changelog_index, None => { let address_merkle_tree = - get_indexed_merkle_tree::( + get_indexed_merkle_tree::( rpc, address_merkle_tree_pubkey, ) @@ -543,7 +518,7 @@ pub async fn update_merkle_tree( Some(indexed_changelog_index) => indexed_changelog_index, None => { let address_merkle_tree = - get_indexed_merkle_tree::( + get_indexed_merkle_tree::( rpc, address_merkle_tree_pubkey, ) diff --git a/test-utils/src/transaction_params.rs b/test-utils/src/transaction_params.rs index b70069f575..ea7ee14445 100644 --- a/test-utils/src/transaction_params.rs +++ b/test-utils/src/transaction_params.rs @@ -21,7 +21,7 @@ impl Default for FeeConfig { Self { // rollover fee plus additonal lamports for the cpi account state_merkle_tree_rollover: 185, - address_queue_rollover: 211, + address_queue_rollover: 202, network_fee: 5000, address_network_fee: 5000, solana_network_fee: 5000,