fix: BlockNumberAddress related doc and namings (#6732)

This commit is contained in:
makcandrov
2024-02-22 14:25:22 +04:00
committed by GitHub
parent a4c034903b
commit ca98261d43
4 changed files with 15 additions and 15 deletions

View File

@ -114,7 +114,7 @@ impl<DB: Database, D: BodyDownloader> Stage<DB> for BodyStage<D> {
let mut ommers_cursor = tx.cursor_write::<tables::BlockOmmers>()?; let mut ommers_cursor = tx.cursor_write::<tables::BlockOmmers>()?;
let mut withdrawals_cursor = tx.cursor_write::<tables::BlockWithdrawals>()?; let mut withdrawals_cursor = tx.cursor_write::<tables::BlockWithdrawals>()?;
// 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(); 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"); debug!(target: "sync::stages::bodies", stage_progress = from_block, target = to_block, start_tx_id = next_tx_num, "Commencing sync");

View File

@ -621,24 +621,24 @@ mod tests {
fn insert_storage_entry<TX: DbTxMut>( fn insert_storage_entry<TX: DbTxMut>(
&self, &self,
tx: &TX, tx: &TX,
tid_address: BlockNumberAddress, bn_address: BlockNumberAddress,
entry: StorageEntry, entry: StorageEntry,
hash: bool, hash: bool,
) -> Result<(), reth_db::DatabaseError> { ) -> Result<(), reth_db::DatabaseError> {
let mut storage_cursor = tx.cursor_dup_write::<tables::PlainStorageState>()?; let mut storage_cursor = tx.cursor_dup_write::<tables::PlainStorageState>()?;
let prev_entry = 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 => { Some(e) if e.key == entry.key => {
tx.delete::<tables::PlainStorageState>(tid_address.address(), Some(e)) tx.delete::<tables::PlainStorageState>(bn_address.address(), Some(e))
.expect("failed to delete entry"); .expect("failed to delete entry");
e e
} }
_ => StorageEntry { key: entry.key, value: U256::from(0) }, _ => StorageEntry { key: entry.key, value: U256::from(0) },
}; };
tx.put::<tables::PlainStorageState>(tid_address.address(), entry)?; tx.put::<tables::PlainStorageState>(bn_address.address(), entry)?;
if hash { 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 }; let hashed_entry = StorageEntry { key: keccak256(entry.key), value: entry.value };
if let Some(e) = tx if let Some(e) = tx
@ -653,7 +653,7 @@ mod tests {
tx.put::<tables::HashedStorage>(hashed_address, hashed_entry)?; tx.put::<tables::HashedStorage>(hashed_address, hashed_entry)?;
} }
tx.put::<tables::StorageChangeSet>(tid_address, prev_entry)?; tx.put::<tables::StorageChangeSet>(bn_address, prev_entry)?;
Ok(()) Ok(())
} }

View File

@ -572,14 +572,14 @@ mod tests {
let mut rev_changeset_walker = let mut rev_changeset_walker =
storage_changesets_cursor.walk_back(None).unwrap(); 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() rev_changeset_walker.next().transpose().unwrap()
{ {
if tid_address.block_number() < target_block { if bn_address.block_number() < target_block {
break break
} }
tree.entry(keccak256(tid_address.address())) tree.entry(keccak256(bn_address.address()))
.or_default() .or_default()
.insert(keccak256(entry.key), entry.value); .insert(keccak256(entry.key), entry.value);
} }

View File

@ -73,7 +73,7 @@ impl BlockNumberAddress {
(*range.start(), Address::ZERO).into()..(*range.end() + 1, Address::ZERO).into() (*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 { pub fn block_number(&self) -> BlockNumber {
self.0 .0 self.0 .0
} }
@ -99,12 +99,12 @@ impl Encode for BlockNumberAddress {
type Encoded = [u8; 28]; type Encoded = [u8; 28];
fn encode(self) -> Self::Encoded { fn encode(self) -> Self::Encoded {
let tx = self.0 .0; let block_number = self.0 .0;
let address = self.0 .1; let address = self.0 .1;
let mut buf = [0u8; 28]; 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[8..].copy_from_slice(address.as_slice());
buf buf
} }
@ -129,7 +129,7 @@ mod tests {
use std::str::FromStr; use std::str::FromStr;
#[test] #[test]
fn test_tx_number_address() { fn test_block_number_address() {
let num = 1u64; let num = 1u64;
let hash = Address::from_str("ba5e000000000000000000000000000000000000").unwrap(); let hash = Address::from_str("ba5e000000000000000000000000000000000000").unwrap();
let key = BlockNumberAddress((num, hash)); let key = BlockNumberAddress((num, hash));
@ -146,7 +146,7 @@ mod tests {
} }
#[test] #[test]
fn test_tx_number_address_rand() { fn test_block_number_address_rand() {
let mut bytes = [0u8; 28]; let mut bytes = [0u8; 28];
thread_rng().fill(bytes.as_mut_slice()); thread_rng().fill(bytes.as_mut_slice());
let key = BlockNumberAddress::arbitrary(&mut Unstructured::new(&bytes)).unwrap(); let key = BlockNumberAddress::arbitrary(&mut Unstructured::new(&bytes)).unwrap();