Skip to content

Commit

Permalink
fix: scale withdrawals amount to gwei
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare committed Jul 9, 2024
1 parent 4a1b42a commit 7145da6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions trace_decoder/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
OtherBlockData, TrieRootHash, TxnIdx, EMPTY_ACCOUNT_BYTES_RLPED,
ZERO_STORAGE_SLOT_VAL_RLPED,
},
utils::{hash, optional_field, optional_field_hex, update_val_if_some},
utils::{eth_to_gwei, hash, optional_field, optional_field_hex, update_val_if_some},
};

/// Stores the result of parsing tries. Returns a [TraceParsingError] upon
Expand Down Expand Up @@ -617,7 +617,7 @@ impl ProcessedBlockTrace {
})?;
let mut acc_data = account_from_rlped_bytes(acc_bytes)?;

acc_data.balance += amt;
acc_data.balance += eth_to_gwei(amt);

state
.insert(h_addr_nibs, rlp::encode(&acc_data).to_vec())
Expand Down Expand Up @@ -721,7 +721,7 @@ impl StateTrieWrites {
}
};

update_val_if_some(&mut state_node.balance, self.balance);
update_val_i_some(&mut state_node.balance, self.balance);
update_val_if_some(&mut state_node.nonce, self.nonce);
update_val_if_some(&mut state_node.storage_root, storage_root_hash_change);
update_val_if_some(&mut state_node.code_hash, self.code_hash);
Expand Down
7 changes: 6 additions & 1 deletion trace_decoder/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ethereum_types::H256;
use ethereum_types::{H256, U256};
use keccak_hash::keccak;
use log::trace;
use mpt_trie::{
Expand All @@ -8,6 +8,11 @@ use mpt_trie::{

use crate::types::HashedStorageAddr;

pub(crate) fn eth_to_gwei(eth: U256) -> U256 {
// 1 ether = 10^9 gwei.
eth * U256::from(10).pow(9.into())
}

pub(crate) fn hash(bytes: &[u8]) -> H256 {
H256::from(keccak(bytes).0)
}
Expand Down

0 comments on commit 7145da6

Please sign in to comment.