research icon indicating copy to clipboard operation
research copied to clipboard

How do we query intermediate contract state?

Open Zerim opened this issue 6 years ago • 3 comments

I.e. between transactions rather than just between blocks.

Zerim avatar Apr 18 '18 15:04 Zerim

Looks like this can be done through a combination of inspecting the transaction receipt for a particular transaction, and accessing LevelDB directly. Each transaction receipt stores a root property which, according to this answer, is the root hash of the intermediate state tree after that particular transaction was executed.

We can use this root hash as a key and access values from the LevelDB database through the db_getHex JSON RPC API, though this interface will be deprecated in the future and would be very slow.

Alternately we could access the LevelDB database directly. This answer offers some suggestions on how this can be approached. Most promising is to piggyback off of the existing ethdb package in Geth or the equivalent rust module in Parity's ethereum client.

Zerim avatar May 01 '18 02:05 Zerim

Update: It looks like that after the Byzantium fork, transaction receipts no longer contain a root property and nodes no longer calculate an intermediate state tree. This has to do with preparations for sharding and parallelizing transaction processing.

For full rationale see EIP#98

Zerim avatar May 11 '18 02:05 Zerim

Don't have time to dig into this now, but we should explore using trace mode and a custom tracer.

See: https://github.com/ethereum/go-ethereum/wiki/Tracing:-Introduction

And: https://ethereum.stackexchange.com/questions/40191/how-to-install-a-custom-tracer-in-geth

Zerim avatar May 11 '18 02:05 Zerim