ethereumjs-monorepo icon indicating copy to clipboard operation
ethereumjs-monorepo copied to clipboard

Make ethereumjs-blockchain compatible again with the latest Geth leveldb database format

Open BigMurry opened this issue 4 years ago • 9 comments

I'm trying to use ethereumjs-blockchain to read the raw levedb data created by geth, but I failed to do so. And I also try to use the dbManager to read the levedb data, failed again. My steps are:

  1. sync some the blockchain data by using geth --goerli --datadir <my data dir>
  2. write code to read the level db data.
const level = require('level');
const DbManager = require('ethereumjs-blockchain/dist/dbManager').default;

async function run () {
  const db = level('path to the geth chaindata');
  const dbManager = new DbManager(db);
  const block = await dbManager.getBlock(5); // successful when blockNumber = 0
  return block;
 }
// get the error: Error [NotFoundError]: Key not found in database [hn]

My question is if this package is compatible with the leveldb data created by geth or I missed something?

BigMurry avatar May 12 '20 11:05 BigMurry

Hi @BigMurry, there is an example stated on the ethereumjs-blockchain package README page for connecting to a Geth DB, did you try? This likely hasn't been run for a while though.

If you are do please post the version you are using (master or some release?) together with the output you are (or are not 😄) getting here.

holgerd77 avatar May 12 '20 14:05 holgerd77

Hi @holgerd77 , thanks for the quick reply. I just tried the example, and the out put is:

Done.

nothing else. I've run geth --goerli to get some .ldb files in the chaindata folder, but the example code didn't log any thing.


ethereumjs-blockchain: 4.0.3 geth: Geth/v1.9.14-unstable-82f9ed49-20200508/linux-amd64/go1.14.2

BigMurry avatar May 13 '20 06:05 BigMurry

I think it may caused by the ancient blob storage feature introduced by Geth from 1.9.x.

BigMurry avatar May 14 '20 04:05 BigMurry

Sounds like this would need some further investigation. I've changed the title to reflect this and added some fitting labels. This would also also be a good grasp for external help, so I added help wanted and good first issue labels as well.

holgerd77 avatar May 20 '20 06:05 holgerd77

This is probably because Goerli is a PoA chain which we do not support (i.e. the blocks are invalid, because we think it is a PoW chain).

Linking #689

jochem-brouwer avatar Oct 28 '20 22:10 jochem-brouwer

I am not sure what's the status here and if it's still realistic to read the raw Geth leveldb database or if the format has changed substantially (e.g. with the latest snap sync changes?) and we should change on the example instead (or just remove for now).

Needs some investigation.

holgerd77 avatar Jun 15 '21 11:06 holgerd77

This would still need some investigation.

holgerd77 avatar Jan 13 '22 19:01 holgerd77

It may be unreasonable for us to stay compatible with the geth leveldb format depending on how often it is changed or updated, what happens with a flat db layout strategy, etc. I assume there would be many changes over time.

If this is the case we should reword blockchain/README.md so it doesn't read The following is an example to iterate through an existing Geth DB (needs `level` to be installed separately). but rather something else, or at least specify the geth versions we know it works.

Maybe we can ask for some thoughts from the geth team, if it doesn't change that often, then maybe it is worth it to do the work to remain compatible, if there is a strong use case of people using this feature to work on geth dbs.

ryanio avatar Jan 13 '22 20:01 ryanio

Maybe there could be an abstracted storage layer, so people can build and share custom implementations.

wong2 avatar Sep 05 '22 06:09 wong2

We do have custom db wrappers implemented for v7. Methinks we can close this and people can implement their own wrappers to allow this sort of thing to work.

acolytec3 avatar May 22 '23 16:05 acolytec3