Skip to content

Commit

Permalink
fix: scale withdrawals amount to gwei (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare authored Jul 10, 2024
1 parent 8d5f15b commit 43a984d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 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 @@ -563,8 +563,13 @@ impl ProcessedBlockTrace {
fn add_withdrawals_to_txns(
txn_ir: &mut [GenerationInputs],
final_trie_state: &mut PartialTrieState,
withdrawals: Vec<(Address, U256)>,
mut withdrawals: Vec<(Address, U256)>,
) -> TraceParsingResult<()> {
// Scale withdrawals amounts.
for (_addr, amt) in withdrawals.iter_mut() {
*amt = eth_to_gwei(*amt)
}

let withdrawals_with_hashed_addrs_iter = || {
withdrawals
.iter()
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 43a984d

Please sign in to comment.