Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix truncated hex in anvil dump_state #8216

Merged
merged 9 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/anvil/src/eth/backend/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub trait Db:
}

/// Sets the balance of the given address
fn set_storage_at(&mut self, address: Address, slot: U256, val: U256) -> DatabaseResult<()>;
fn set_storage_at(&mut self, address: Address, slot: B256, val: B256) -> DatabaseResult<()>;

/// inserts a blockhash for the given number
fn insert_block_hash(&mut self, number: U256, hash: B256);
Expand Down Expand Up @@ -179,8 +179,8 @@ impl<T: DatabaseRef<Error = DatabaseError> + Send + Sync + Clone + fmt::Debug> D
self.insert_account_info(address, account)
}

fn set_storage_at(&mut self, address: Address, slot: U256, val: U256) -> DatabaseResult<()> {
self.insert_account_storage(address, slot, val)
fn set_storage_at(&mut self, address: Address, slot: B256, val: B256) -> DatabaseResult<()> {
self.insert_account_storage(address, slot.into(), val.into())
}

fn insert_block_hash(&mut self, number: U256, hash: B256) {
Expand Down Expand Up @@ -348,7 +348,7 @@ pub struct SerializableAccountRecord {
pub nonce: u64,
pub balance: U256,
pub code: Bytes,
pub storage: BTreeMap<U256, U256>,
pub storage: BTreeMap<B256, B256>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also how the regular genesis account is formatted with hash -> hash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see an example of genesis.json storage field:

      "storage": {
        "0x0000000000000000000000000000000000000000000000000000000000000001": "0x02",
        "0x0000000000000000000000000000000000000000000000000000000000000002": "0x04",
        "0x29ecdbdf95c7f6ceec92d6150c697aa14abeb0f8595dd58d808842ea237d8494": "0x01",
        "0x6aa118c6537572d8b515a9f9154be55a3377a8de7991cd23bf6e5ceb368688e3": "0x01",
        ...
      }

The type is pub storage: BTreeMap<B256, U256>, but it doesnt resolve the issue:
#8179

}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl GenesisConfig {
db.insert_account(addr, self.genesis_to_account_info(&acc));
// insert all storage values
for (k, v) in storage.unwrap_or_default().iter() {
db.set_storage_at(addr, U256::from_be_bytes(k.0), U256::from_be_bytes(v.0))?;
db.set_storage_at(addr, B256::from(k.0), B256::from(v.0))?;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/eth/backend/mem/fork_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Db for ForkedDatabase {
self.database_mut().insert_account(address, account)
}

fn set_storage_at(&mut self, address: Address, slot: U256, val: U256) -> DatabaseResult<()> {
fn set_storage_at(&mut self, address: Address, slot: B256, val: B256) -> DatabaseResult<()> {
// this ensures the account is loaded first
let _ = Database::basic(self, address)?;
self.database_mut().set_storage_at(address, slot, val)
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Db for ForkedDatabase {
nonce: v.info.nonce,
balance: v.info.balance,
code: code.original_bytes(),
storage: v.storage.into_iter().collect(),
storage: v.storage.into_iter().map(|(k, v)| (k.into(), v.into())).collect(),
},
))
})
Expand Down
Loading