6

I know that chaindata folder (on Mac OS X) stores the state as key/value database. But how is a block stored? Are transactions also stored as key/value pairs? If yes, how to identify which files belong to transactions and which files belong to state? I have a bunch of levelDB files 'ldb' under chaindata and I have no idea how to probe them, say using python levelDB bindings.

This question does ask a bit about the blockchain, however the answer does not particularly refer to how blocks are stored.

EDIT: I am concerned with low-level representation of transactions and blocks and how they are stored on disk. I understand that they are in RLP format from ethereum wiki. What exactly I am looking for is which files belong to blocks (and transactions) and which don't.

Ram
  • 91
  • 1
  • 4
  • afaik the leveldb files contain RLP-encoded (see https://github.com/ethereum/wiki/wiki/RLP) data. Probably a look at the ethereum client (the python one is supposed to be most readable) helps to answer your question. – didi_X8 Oct 23 '16 at 01:44
  • My question is which files to read? I am assuming that all ldb files are key value files, so how to know which files are block related and which ones are state related? – Ram Oct 23 '16 at 03:25
  • check this http://ethereum.stackexchange.com/questions/5999/format-of-leveldb-files-in-nodes-directory-trouble-pulling-contents-with-python – Badr Bellaj Oct 23 '16 at 22:41
  • May be this can help you out https://ethereum.stackexchange.com/questions/28976/leveldb-in-geth-key-and-values/33445#33445 – Vishal Sharma Dec 29 '17 at 10:52

1 Answers1

1

The easiest way is to use the official NodeJS library, write a few lines of JavaScript to scan all of the blocks, and optionally all transactions in each block. Start at block 0 and keep scanning until it returns null.

You can do that with far less code than it would take to read/parse, and it would have the added benefit of never needing an upgrade just because the underlying db changed.

Ross Perkins
  • 776
  • 6
  • 11
  • I am concerned with low-level representation of transactions and blocks and how they are stored on disk. I understand their RLP format from ethereum wiki. Are you suggesting that each ldb file contains both block/transaction information and state information? – Ram Oct 23 '16 at 13:30
  • I'm suggesting that there is no reason you need to read the files at all. The API will let you inspect all of the data in a consistent manner whether you use eth, geth or some future sever that uses an entirely different local db schema. Forget there are files. Access the db via the API. – Ross Perkins Oct 23 '16 at 21:50