Skip to content

Conversation

gballet
Copy link
Member

@gballet gballet commented Mar 31, 2025

This is an implementation of the state conversion process described in EIP-7612.

What this PR does:

  • It creates a special type of "facade pattern" tree, called TransitionTree, that is in charge of abstracting which one of the underlying trees (the "base" MPT tree or the "overlay" verkle tree) values should be read from/written to.
  • At the end of the block execution, a tree-sweeping process goes over the snapshot and converts N "leaves" (either a single slot or a full account header + code). In order to resume where the previous block stopped, a TransitionState structure is maintained in the db, keyed by the pre-state root of the block. This helps recovering these pointers in case the process is ran multiple times (e.g. block production, followed by insertion).

@gballet gballet added the verkle label Mar 31, 2025
@gballet gballet force-pushed the stateless-transition branch from 5f4b22f to 16cb4fa Compare March 31, 2025 15:50
go.mod Outdated
Copy link
Member Author

Choose a reason for hiding this comment

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

This is due to a bug being found in 0.2.2 that breaks the Holesky shadowfork. I will revert this in a further PR, when I have time to perform a deeper investigation of the bug. v0.2.2 is a db-size optimization and has no functional impact.

Comment on lines 72 to 116
Copy link
Member Author

Choose a reason for hiding this comment

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

@rjl493456442 these are helper functions to handle the transition. In my own branch, this is the most convenient way to access them. But maybe they could be moved to a verkle-specific TrieDB if it's cleaner ... what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's contrary to the spec

Suggested change
// TODO also insert value into overlay

Copy link
Member Author

Choose a reason for hiding this comment

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

Same thing as above

Suggested change
// TODO also insert value into overlay

Copy link
Member Author

Choose a reason for hiding this comment

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

note to self: remove that if it's no longer needed

@gballet gballet force-pushed the stateless-transition branch 2 times, most recently from 8e8d10a to b9884bf Compare April 2, 2025 13:08
Copy link
Member Author

@gballet gballet left a comment

Choose a reason for hiding this comment

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

I pushed a second commit in order to explore the idea I mentioned earlier, which is to move as much of the transition management code to the TransitionTrie itself. The code is still incomplete and doesn't compile, but reading my messages will help explain some aspects of it - and hopefully we can converge towards a working and reliable design.

Comment on lines 74 to 117
Copy link
Member Author

Choose a reason for hiding this comment

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

These are helper functions managing the conversion pointers (current slot being considered, current account, as well as methods to save and restore the state from the db).

In the source branch, these are stored in the unique disk database. Having to partially rewrite the code means that we can consider other methods. For instance, I am exploring the possibility to store the pointers in the MPT or verkle DB (if it's not present there, it means that the transition hasn't started) - and I am thinking it'd be better if the transition tree were the one deciding where the data is - I have a hunch this might simplify the design.

Activation of the forks would still be explicit (no way to work around that anyway, we need a header for chainConfig.IsVerkle()) but the interface would be that of the tree.

Comment on lines 209 to 168
Copy link
Member Author

Choose a reason for hiding this comment

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

These could be moved to the TransitionTree, if it makes the interface/diff simpler (see previous comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

The question of how this gets initialized is still open. I have a hunch we could simply create it no matter what, and keep it empty as long as the transition hasn't happened.

I'm not a 100% clear on how this would work in a fully-verkle tesnet, but I guess that in this case, we could have an empty MPT db with just the info that the transition has completed and therefore, that there is no need to go through it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gary: pass verkle db as parameter

Copy link
Member Author

Choose a reason for hiding this comment

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

and initialize both DBs at the beginning so that we support verkle at genesis networks

Copy link
Member Author

Choose a reason for hiding this comment

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

note that this method doesn't currently exist, I'm proposing that we move it from (*state.Database).LoadTransitionState) and keep it inside the tree somehow.

Copy link
Member Author

Choose a reason for hiding this comment

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

so as a follow-up to the message above, this would be NewTransitionTree(mptr, vktr, false, ts)

Copy link
Member Author

Choose a reason for hiding this comment

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

Not present in this PR yet, but the call to StartVerkleTransition could be called at the start ofProcess, since the state should not be needed beforehand.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note to self: this is also where the pointers would be saved at the db. And the equivalent "start / save" would have to be added to the miner for block production.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gary: read the pointers directly from ethdb.KeyValueStore

Copy link
Member Author

Choose a reason for hiding this comment

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

and store it in the cachingdb, no lock should be needed

Copy link
Member Author

Choose a reason for hiding this comment

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

Gary: the cache itself has an internal lock, this should not be necessary

@gballet gballet force-pushed the stateless-transition branch from 500abed to 7942e52 Compare April 3, 2025 18:45
rjl493456442 added a commit that referenced this pull request Aug 5, 2025
…art 1) (#31634)

This is the first part of #31532 

It maintains a series of conversion maker which are to be updated by the
conversion code (in a follow-up PR, this is a breakdown of a larger PR
to make things easier to review). They can be used in this way:

- During the conversion, by storing the conversion markers when the
block has been processed. This is meant to be written in a function that
isn't currently present, hence [this
TODO](https://github.com/ethereum/go-ethereum/pull/31634/files#diff-89272f61e115723833d498a0acbe59fa2286e3dc7276a676a7f7816f21e248b7R384).

Part of  #31583

---------

Signed-off-by: Guillaume Ballet <[email protected]>
Co-authored-by: Gary Rong <[email protected]>
@gballet gballet closed this Aug 12, 2025
gballet added a commit to gballet/go-ethereum that referenced this pull request Sep 11, 2025
…art 1) (ethereum#31634)

This is the first part of ethereum#31532 

It maintains a series of conversion maker which are to be updated by the
conversion code (in a follow-up PR, this is a breakdown of a larger PR
to make things easier to review). They can be used in this way:

- During the conversion, by storing the conversion markers when the
block has been processed. This is meant to be written in a function that
isn't currently present, hence [this
TODO](https://github.com/ethereum/go-ethereum/pull/31634/files#diff-89272f61e115723833d498a0acbe59fa2286e3dc7276a676a7f7816f21e248b7R384).

Part of  ethereum#31583

---------

Signed-off-by: Guillaume Ballet <[email protected]>
Co-authored-by: Gary Rong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant