Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Relocate geth genesis, state parsers to common, blockchain respectively #2300

Merged
merged 13 commits into from Sep 22, 2022

Conversation

g11tech
Copy link
Contributor

@g11tech g11tech commented Sep 21, 2022

Relocate geth genesis, state parsers to common, blockchain respectively

Partially addresses #1708 as parseGethGenesisState can set these objects

  • code
  • storage

Nonces still need to be checked

Note (from @holgerd77): this also fixes a severe bug in the Blockchain.create() method.

@codecov
Copy link

codecov bot commented Sep 21, 2022

Codecov Report

Merging #2300 (9b80d91) into master (5ca079f) will increase coverage by 0.07%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 92.82% <ø> (ø)
blockchain 89.40% <100.00%> (+0.93%) ⬆️
client 86.96% <ø> (-0.03%) ⬇️
common 98.45% <100.00%> (+0.36%) ⬆️
devp2p 92.37% <ø> (-0.09%) ⬇️
ethash ∅ <ø> (∅)
evm 79.23% <ø> (ø)
rlp ?
statemanager 88.43% <ø> (ø)
trie 90.36% <ø> (ø)
tx 97.98% <ø> (ø)
util 91.67% <ø> (ø)
vm 85.31% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@g11tech g11tech marked this pull request as draft September 21, 2022 10:54
})
// You either have genesis block hash or calculate it from using the geth state via `blockchain` module
// const genesisBlockHash = ...
common.setForkHashes(genesisBlockHash)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Gajinder,
this looks already pretty great all over the place! 😄

Just for context/understanding: are fork hashes generally not included in genesis.json files? 🤔 Or is this just an "emergency mode" addition in case they are not included but normally they are?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @holgerd77 , thanks ❤️ the geth genesis doesn't has any forkHashes, so yes this would need to be set explicitly for custom chains based out of geth configs, and also can work as the fallback as you mentioned 👍

@holgerd77
Copy link
Member

Can you add at least one test in Common directly using the new functionality?

Also just to mention: when I suggested this I thought about adding a new static constructor like Common.fromGethConfig() or the like. If this has no logic hickups I would still find this a bit more elegant, but I can also life with the current solution. Also to mention that I guess we can still always additionally add such a constructor afterwards in addition to the existing helper function (that might generally be good to have both ways/options for flexibility).

Just some thoughts, if you also think this is a good idea to streamline things feel free to additionally add such a constructor if this doesn't collide with option types or the like. If you don't then just leave for now.

@g11tech
Copy link
Contributor Author

g11tech commented Sep 21, 2022

Can you add at least one test in Common directly using the new functionality?

Also just to mention: when I suggested this I thought about adding a new static constructor like Common.fromGethConfig() or the like. If this has no logic hickups I would still find this a bit more elegant, but I can also life with the current solution. Also to mention that I guess we can still always additionally add such a constructor afterwards in addition to the existing helper function (that might generally be good to have both ways/options for flexibility).

Just some thoughts, if you also think this is a good idea to streamline things feel free to additionally add such a constructor if this doesn't collide with option types or the like. If you don't then just leave for now.

sounds good @holgerd77 🙂 will update 👍 and add some tests as well

@g11tech
Copy link
Contributor Author

g11tech commented Sep 21, 2022

added a test for kiln genesis's block root match (sourced from an old geth build), seems to be not matching 🤔 , currently debugging for fix

@@ -36,7 +36,7 @@ export async function genesisStateRoot(genesisState: GenesisState) {
account.codeHash = Buffer.from(keccak256(toBuffer(code)))
}
if (storage !== undefined) {
const storageTrie = new Trie()
const storageTrie = new Trie({ useKeyHashing: true })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. The v6 final release clean-up bugs keep trickling in (still on a very modest level though).

Great find! 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea it took quite a digging to find this one 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following up the call-path here,so this is actually not such a "mild" bug being triggered directly in Blockchain.create() in certain circumstances, right? 🤔 "Only" in genesis storage scenarios, but anyhow. Guess some bugfix releases are really getting closer to be realized/done at some point.

Copy link
Contributor Author

@g11tech g11tech Sep 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes in genesis storage scenarios only! thats why i digged around and used kiln genesis (since i wanted to incorporate a little complex genesis and luckily found this bug) and corresponding genesis block ( had to find an old geth build to get it 😅 )

@g11tech
Copy link
Contributor Author

g11tech commented Sep 22, 2022

@holgerd77 PR should be good to merge 🙏

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks really really great, we have been waiting for such a functionality/constructor for quite some time, @ryanio would/will love this as well 🙂, quite some pre-work being done to enable this and this will really ease (expand on) use cases for the other libraries (easily instantiate a Block from a custom chain where you only have a genesis.json file and the block RPC e.g., these kind of things).

So, great! Will merge.

'kiln genesis hash matches'
)
})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests. 👍

// post calculating it via `blockchain`)
common.setForkHashes(genesisHash)
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. 👍


tape('[Utils/Parse]', (t) => {
t.test('should parse geth params file', async (t) => {
const json = require(`../../client/test/testdata/geth-genesis/testnet.json`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Won't make it a blocker here but this is a bit dangerous.

So if someone reorganizes test data in client, this will (at least locally) remain unnoticed when someone is working "client only" and running the client tests and the like. Will break on CI then so somewhat ok, but nevertheless we should generally avoid and in doubt rather take over.

At some point we might also want to consolidate testdata a bit more (or at least discuss), and do a dedicated directory testdata on packages folder level or the like and in turn keep the test data a bit more curated and high quality level. Just some thoughts for now though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants