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: scale withdrawals amount to gwei #371

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading