Skip to content

Commit

Permalink
chore: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19-cw committed Aug 8, 2024
1 parent ae7a23f commit 9cc8ba0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/eth/rpc/rpc_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ where
}

/// Decode an RPC parameter encoded in RLP.
///
/// https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp
pub fn parse_rpc_rlp<T: Decodable>(value: &[u8]) -> Result<T, StratusError> {
match rlp::decode::<T>(value) {
Ok(trx) => Ok(trx),
Expand Down
17 changes: 6 additions & 11 deletions src/eth/storage/rocks/rocks_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,13 @@ impl RocksStorageState {
block_number: BlockNumber,
batch: &mut WriteBatch,
) -> Result<()> {
let accounts = self.accounts.clone();
let accounts_history = self.accounts_history.clone();
let account_slots = self.account_slots.clone();
let account_slots_history = self.account_slots_history.clone();

let mut account_changes = Vec::new();
let mut account_history_changes = Vec::new();

for change in changes {
if change.is_account_modified() {
let address: AddressRocksdb = change.address.into();
let mut account_info_entry = accounts.get_or_insert_with(address, AccountRocksdb::default)?;
let mut account_info_entry = self.accounts.get_or_insert_with(address, AccountRocksdb::default)?;

if let Some(nonce) = change.nonce.clone().take_modified() {
account_info_entry.nonce = nonce.into();
Expand All @@ -209,8 +204,8 @@ impl RocksStorageState {
}
}

accounts.prepare_batch_insertion(account_changes, batch)?;
accounts_history.prepare_batch_insertion(account_history_changes, batch)?;
self.accounts.prepare_batch_insertion(account_changes, batch)?;
self.accounts_history.prepare_batch_insertion(account_history_changes, batch)?;

let mut slot_changes = Vec::new();
let mut slot_history_changes = Vec::new();
Expand All @@ -225,8 +220,8 @@ impl RocksStorageState {
}
}
}
account_slots.prepare_batch_insertion(slot_changes, batch)?;
account_slots_history.prepare_batch_insertion(slot_history_changes, batch)?;
self.account_slots.prepare_batch_insertion(slot_changes, batch)?;
self.account_slots_history.prepare_batch_insertion(slot_history_changes, batch)?;

Ok(())
}
Expand Down Expand Up @@ -379,7 +374,7 @@ impl RocksStorageState {

let mut txs_batch = vec![];
let mut logs_batch = vec![];
for transaction in block.transactions.clone() {
for transaction in block.transactions.iter().cloned() {
txs_batch.push((transaction.input.hash.into(), transaction.block_number.into()));
for log in transaction.logs {
logs_batch.push(((transaction.input.hash.into(), log.log_index.into()), transaction.block_number.into()));
Expand Down

0 comments on commit 9cc8ba0

Please sign in to comment.