[Ethereum] How to access Geth’s state trie

go-ethereumleveldbstate-trieweb3js

Using Geth, how can I extract a snapshot of the network state for a given block?

My Geth node runs a full sync (~300 gb) which means the state trie should already be saved down. I've tried accessing the leveldb database directly, but it's mixed together with the blockchain in the chaindata folder so it's not clear what the structure is.

I've also tried using the web3 dumpBlock method, which works in theory, but it takes way too long to be practically usable (hours).

Is there an another API method that can access the state trie faster?
Any documentation on how the database in the chaindata folder is organized?

Best Answer

Doing this using web3 over RPC will take forever, as you've found. Reading the .ldb files is the way to go, and is something that's come up in similar questions before.

I don't know of any working, up-to-date, .ldb parser, though there must be some in existence, so I'll defer to other more knowledgeable answers you might get.


In the meantime...

See: LDB files reading, which attempts to point the OP in the direction of parts of Geth's state trie (Go) API, with a view to writing a parser from scratch. (There's also an old Go parser, here, though it's likely out of date.)

To get a better understanding of how the database is laid out, have a read of Exploring Ethereum's state trie With Node.js. The example code is quite old, but can be made to work with a few tweaks.

Also related, though with no clear answer: How to parse blocks with Python?

Also related, specifically to the RPL encoding within the .ldb files: Format of LevelDB files in nodes directory? Trouble pulling contents with python leveldb API

Related Topic