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

Add statefulVerkleStateManager #3628

Merged
merged 44 commits into from
Sep 10, 2024
Merged

Add statefulVerkleStateManager #3628

merged 44 commits into from
Sep 10, 2024

Conversation

acolytec3
Copy link
Contributor

Implements a stateful version of the statemanager interface that uses a verkle trie as a backend.

@acolytec3
Copy link
Contributor Author

Note, this still has extraneous commits that already exist on master in it (from the kaustinen7 readiness PR). Will purge those out and clean up the commit trie at some point here soon.

@acolytec3 acolytec3 force-pushed the statefulVerkleStateManager branch from 94edd6c to adad631 Compare September 3, 2024 10:27
this._caches?.account?.del(address)
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Don't want to get yourself too much on the nerve with this refactoring/DRY stuff (but maybe a bit 😂), but maybe you can put such code parts like the putAccount() directly in a src/helpers/verkle.ts file or similar with an adjusted function signature putAccount(self/this: SM, address: Address, account?: Account): Promise<void> taking the code from the stateless verkle SM directly over so that these kind of code parts just never reach this file?

Then we directly have a unified version and do not need to post-DRY this and this should not be significantly ore work (just run the statless tests from statelessVerkleStateManager.spec.ts along)!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I'm not 100% sure what you mean since the implementations are not the same. The stateless SM puts things in an in memory map via direct this._state[verkleKey] = serializedBytes and the stateful implementation uses await this.trie.put(stem, suffixes, values) to "put" data. The thing I could do differently is to have encodeVerkleLeafBasicData accept an account rather than the various fields and that would de-dup a few lines of code.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, yeah, nevermind, you are right, haven't looked/though closely enough. I think I am generally still latently unsatisfied that we always copy over 2/3 of code which is redundant/the same.

Maybe we can also tackle this in a more fine-grained way. We could e.g. centralize the generic DEBUG strings and re-use, things like that (for sure not in this PR).

So don't let me distract you here! 🙂 I will nevertheless not give up on the topic, maybe open some more low-reaching small issues on this after this PR got merged.

Comment on lines 212 to 221
await this._trie.put(
chunkStems[stem],
chunkSuffixes.slice(
128 + (256 * stem - 1),
codeChunks.length <= 128 + 256 * stem ? codeChunks.length : 128 + 256 * stem,
),
codeChunks.slice(
128 + (256 * stem - 1),
codeChunks.length <= 128 + 256 * stem ? codeChunks.length : 128 + 256 * stem,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

To slightly improve clarity, I would define chunkId = stem - 1 and then use that for the 2 instances where we use stem - 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where are you seeing this? In the code below here, it's not stem - 1 but (VERKLE_NODE_WIDTH * stem) - 1 since these arrays are zero-indexed. I'm not referencing a specific chunkId but a section of the overall array of chunks corresponding to the stem we're putting them under.

await this._trie.put(
chunkStems[stem],
chunkSuffixes.slice(
128 + (256 * stem - 1),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use the constants for these values for 2 reasons:

  • If the spec change, we can easily just update the constant.
  • It makes the meaning of these numbers obvious (e.g. CODE_OFFSET, VERKLE_NODE_WIDTH, etc.)

Copy link

codecov bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 69.73294% with 102 lines in your changes missing coverage. Please review.

Project coverage is 38.78%. Comparing base (4470cc3) to head (b97e813).
Report is 40 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 66.20% <ø> (-7.25%) ⬇️
blockchain 84.92% <ø> (?)
client ?
common 89.68% <ø> (?)
devp2p 0.00% <ø> (?)
evm 65.49% <ø> (?)
genesis 0.00% <ø> (?)
statemanager 67.12% <69.73%> (?)
trie 51.92% <ø> (?)
tx ?
wallet ?

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

@holgerd77
Copy link
Member

🙂 🎉

@acolytec3 acolytec3 merged commit 2f3316d into master Sep 10, 2024
38 checks passed
@acolytec3 acolytec3 deleted the statefulVerkleStateManager branch September 10, 2024 13:39
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.

3 participants