From ca98261d43d40cb2332567fac2bb944fe38e9131 Mon Sep 17 00:00:00 2001 From: makcandrov Date: Thu, 22 Feb 2024 14:25:22 +0400 Subject: [PATCH] fix: `BlockNumberAddress` related doc and namings (#6732) --- crates/stages/src/stages/bodies.rs | 2 +- crates/stages/src/stages/hashing_storage.rs | 12 ++++++------ crates/stages/src/stages/merkle.rs | 6 +++--- crates/storage/db/src/tables/models/accounts.rs | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/stages/src/stages/bodies.rs b/crates/stages/src/stages/bodies.rs index 56001595cf..1eb913bf53 100644 --- a/crates/stages/src/stages/bodies.rs +++ b/crates/stages/src/stages/bodies.rs @@ -114,7 +114,7 @@ impl Stage for BodyStage { let mut ommers_cursor = tx.cursor_write::()?; let mut withdrawals_cursor = tx.cursor_write::()?; - // Get id for the next tx_num of zero if there are no transactions. + // Get id for the next tx_num or zero if there are no transactions. let mut next_tx_num = tx_cursor.last()?.map(|(id, _)| id + 1).unwrap_or_default(); debug!(target: "sync::stages::bodies", stage_progress = from_block, target = to_block, start_tx_id = next_tx_num, "Commencing sync"); diff --git a/crates/stages/src/stages/hashing_storage.rs b/crates/stages/src/stages/hashing_storage.rs index 1e30337389..f3a20ce155 100644 --- a/crates/stages/src/stages/hashing_storage.rs +++ b/crates/stages/src/stages/hashing_storage.rs @@ -621,24 +621,24 @@ mod tests { fn insert_storage_entry( &self, tx: &TX, - tid_address: BlockNumberAddress, + bn_address: BlockNumberAddress, entry: StorageEntry, hash: bool, ) -> Result<(), reth_db::DatabaseError> { let mut storage_cursor = tx.cursor_dup_write::()?; let prev_entry = - match storage_cursor.seek_by_key_subkey(tid_address.address(), entry.key)? { + match storage_cursor.seek_by_key_subkey(bn_address.address(), entry.key)? { Some(e) if e.key == entry.key => { - tx.delete::(tid_address.address(), Some(e)) + tx.delete::(bn_address.address(), Some(e)) .expect("failed to delete entry"); e } _ => StorageEntry { key: entry.key, value: U256::from(0) }, }; - tx.put::(tid_address.address(), entry)?; + tx.put::(bn_address.address(), entry)?; if hash { - let hashed_address = keccak256(tid_address.address()); + let hashed_address = keccak256(bn_address.address()); let hashed_entry = StorageEntry { key: keccak256(entry.key), value: entry.value }; if let Some(e) = tx @@ -653,7 +653,7 @@ mod tests { tx.put::(hashed_address, hashed_entry)?; } - tx.put::(tid_address, prev_entry)?; + tx.put::(bn_address, prev_entry)?; Ok(()) } diff --git a/crates/stages/src/stages/merkle.rs b/crates/stages/src/stages/merkle.rs index de94cf9d3d..bb3345c4b2 100644 --- a/crates/stages/src/stages/merkle.rs +++ b/crates/stages/src/stages/merkle.rs @@ -572,14 +572,14 @@ mod tests { let mut rev_changeset_walker = storage_changesets_cursor.walk_back(None).unwrap(); - while let Some((tid_address, entry)) = + while let Some((bn_address, entry)) = rev_changeset_walker.next().transpose().unwrap() { - if tid_address.block_number() < target_block { + if bn_address.block_number() < target_block { break } - tree.entry(keccak256(tid_address.address())) + tree.entry(keccak256(bn_address.address())) .or_default() .insert(keccak256(entry.key), entry.value); } diff --git a/crates/storage/db/src/tables/models/accounts.rs b/crates/storage/db/src/tables/models/accounts.rs index 77ef1c5576..767f321d90 100644 --- a/crates/storage/db/src/tables/models/accounts.rs +++ b/crates/storage/db/src/tables/models/accounts.rs @@ -73,7 +73,7 @@ impl BlockNumberAddress { (*range.start(), Address::ZERO).into()..(*range.end() + 1, Address::ZERO).into() } - /// Return the transition id + /// Return the block number pub fn block_number(&self) -> BlockNumber { self.0 .0 } @@ -99,12 +99,12 @@ impl Encode for BlockNumberAddress { type Encoded = [u8; 28]; fn encode(self) -> Self::Encoded { - let tx = self.0 .0; + let block_number = self.0 .0; let address = self.0 .1; let mut buf = [0u8; 28]; - buf[..8].copy_from_slice(&tx.to_be_bytes()); + buf[..8].copy_from_slice(&block_number.to_be_bytes()); buf[8..].copy_from_slice(address.as_slice()); buf } @@ -129,7 +129,7 @@ mod tests { use std::str::FromStr; #[test] - fn test_tx_number_address() { + fn test_block_number_address() { let num = 1u64; let hash = Address::from_str("ba5e000000000000000000000000000000000000").unwrap(); let key = BlockNumberAddress((num, hash)); @@ -146,7 +146,7 @@ mod tests { } #[test] - fn test_tx_number_address_rand() { + fn test_block_number_address_rand() { let mut bytes = [0u8; 28]; thread_rng().fill(bytes.as_mut_slice()); let key = BlockNumberAddress::arbitrary(&mut Unstructured::new(&bytes)).unwrap();