5

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?

3

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

  • Thanks. Helpful info. The Node example is the one I've been following. Unfortunately, the layout of Geth's database is not the same as that one, and the Go links are indeed out of date. Does give an idea though of where to go looking for the current schema. – mgalka Sep 2 '17 at 18:03
1

You could also read data via a localhost IPC api, which is much faster than the RPC http endpoint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.