Skip to content

Commit 2d37b02

Browse files
committed
Tracing should use state root from the last block
1 parent 708632b commit 2d37b02

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/rpc/serves.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,10 @@ impl<P: 'static + Patch + Send> DebugRPC for MinerDebugRPC<P> {
580580

581581
let transaction = state.get_transaction_by_hash(hash.0)?;
582582
let block = state.get_block_by_hash(state.get_transaction_block_hash_by_hash(hash.0)?)?;
583+
let last_block = state.get_block_by_number(if block.header.number == U256::zero() { 0 } else { block.header.number.as_usize() - 1 });
583584
let last_hashes = state.get_last_256_block_hashes_by_number(block.header.number.as_usize());
584585

585-
let mut stateful: MemoryStateful<'static> = state.stateful_at(block.header.state_root);
586+
let mut stateful: MemoryStateful<'static> = state.stateful_at(last_block.header.state_root);
586587
for other_transaction in &block.transactions {
587588
if other_transaction != &transaction {
588589
let valid = stateful.to_valid::<P>(transaction.clone())?;
@@ -608,9 +609,10 @@ impl<P: 'static + Patch + Send> DebugRPC for MinerDebugRPC<P> {
608609
let config = config.unwrap_or(RPCTraceConfig::default());
609610
let state = self.state.lock().unwrap();
610611
let block: Block = UntrustedRlp::new(&block_rlp.0).as_val()?;
612+
let last_block = state.get_block_by_number(if block.header.number == U256::zero() { 0 } else { block.header.number.as_usize() - 1 });
611613
let last_hashes = state.get_last_256_block_hashes_by_number(block.header.number.as_usize());
612614

613-
let mut stateful: MemoryStateful<'static> = state.stateful_at(block.header.state_root);
615+
let mut stateful: MemoryStateful<'static> = state.stateful_at(last_block.header.state_root);
614616
let mut steps = Vec::new();
615617
for transaction in block.transactions.clone() {
616618
let (mut local_steps, vm) = replay_transaction::<P>(&stateful, transaction,
@@ -636,9 +638,10 @@ impl<P: 'static + Patch + Send> DebugRPC for MinerDebugRPC<P> {
636638
return Err(Error::NotFound);
637639
}
638640
let block: Block = state.get_block_by_number(number);
641+
let last_block = state.get_block_by_number(if block.header.number == U256::zero() { 0 } else { block.header.number.as_usize() - 1 });
639642
let last_hashes = state.get_last_256_block_hashes_by_number(block.header.number.as_usize());
640643

641-
let mut stateful: MemoryStateful<'static> = state.stateful_at(block.header.state_root);
644+
let mut stateful: MemoryStateful<'static> = state.stateful_at(last_block.header.state_root);
642645
let mut steps = Vec::new();
643646
for transaction in block.transactions.clone() {
644647
let (mut local_steps, vm) = replay_transaction::<P>(&stateful, transaction,
@@ -661,9 +664,10 @@ impl<P: 'static + Patch + Send> DebugRPC for MinerDebugRPC<P> {
661664
let config = config.unwrap_or(RPCTraceConfig::default());
662665
let state = self.state.lock().unwrap();
663666
let block: Block = state.get_block_by_hash(hash.0)?;
667+
let last_block = state.get_block_by_number(if block.header.number == U256::zero() { 0 } else { block.header.number.as_usize() - 1 });
664668
let last_hashes = state.get_last_256_block_hashes_by_number(block.header.number.as_usize());
665669

666-
let mut stateful: MemoryStateful<'static> = state.stateful_at(block.header.state_root);
670+
let mut stateful: MemoryStateful<'static> = state.stateful_at(last_block.header.state_root);
667671
let mut steps = Vec::new();
668672
for transaction in block.transactions.clone() {
669673
let (mut local_steps, vm) = replay_transaction::<P>(&stateful, transaction,
@@ -693,9 +697,10 @@ impl<P: 'static + Patch + Send> DebugRPC for MinerDebugRPC<P> {
693697

694698
let state = self.state.lock().unwrap();
695699
let block: Block = UntrustedRlp::new(&buffer).as_val()?;
700+
let last_block = state.get_block_by_number(if block.header.number == U256::zero() { 0 } else { block.header.number.as_usize() - 1 });
696701
let last_hashes = state.get_last_256_block_hashes_by_number(block.header.number.as_usize());
697702

698-
let mut stateful: MemoryStateful<'static> = state.stateful_at(block.header.state_root);
703+
let mut stateful: MemoryStateful<'static> = state.stateful_at(last_block.header.state_root);
699704
let mut steps = Vec::new();
700705
for transaction in block.transactions.clone() {
701706
let (mut local_steps, vm) = replay_transaction::<P>(&stateful, transaction,

0 commit comments

Comments
 (0)