graphprotocol / research

Research, proposals, papers, and specs
48 stars 9 forks source link

How do we query intermediate contract state? #6

Open Zerim opened 6 years ago

Zerim commented 6 years ago

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

Zerim commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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