fix(rpc): commit call state in trace call many (#3437)

This commit is contained in:
Matthias Seitz
2023-06-27 20:37:23 +02:00
committed by GitHub
parent c3dda470de
commit 1b13616fd4

View File

@ -193,7 +193,9 @@ where
let mut results = Vec::with_capacity(calls.len());
let mut db = SubState::new(State::new(state));
for (call, trace_types) in calls {
let mut calls = calls.into_iter().peekable();
while let Some((call, trace_types)) = calls.next() {
let env = prepare_call_env(
cfg.clone(),
block_env.clone(),
@ -204,12 +206,30 @@ where
let config = tracing_config(&trace_types);
let mut inspector = TracingInspector::new(config);
let (res, _) = inspect(&mut db, env, &mut inspector)?;
let trace_res = inspector.into_parity_builder().into_trace_results_with_state(
res,
&trace_types,
&db,
)?;
let ResultAndState { result, state } = res;
let mut trace_res =
inspector.into_parity_builder().into_trace_results(result, &trace_types);
// If statediffs were requested, populate them with the account balance and
// nonce from pre-state
if let Some(ref mut state_diff) = trace_res.state_diff {
populate_account_balance_nonce_diffs(
state_diff,
&db,
state.iter().map(|(addr, acc)| (*addr, acc.info.clone())),
)?;
}
results.push(trace_res);
// need to apply the state changes of this call before executing the
// next call
if calls.peek().is_some() {
// need to apply the state changes of this call before executing
// the next call
db.commit(state)
}
}
Ok(results)
@ -403,6 +423,9 @@ where
move |tx_info, inspector, res, state, db| {
let mut full_trace =
inspector.into_parity_builder().into_trace_results(res, &trace_types);
// If statediffs were requested, populate them with the account balance and nonce
// from pre-state
if let Some(ref mut state_diff) = full_trace.state_diff {
populate_account_balance_nonce_diffs(
state_diff,