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

feat(l1): implement TrieIterator + GetAccountRange snap request handling logic #960

Merged
merged 73 commits into from
Oct 31, 2024

Conversation

fmoletta
Copy link
Contributor

@fmoletta fmoletta commented Oct 23, 2024

Motivation
Handling snap capability message GetAccountRange

Description

  • Add functionality to iterate the Trie (TrieIterator)
  • Add functionality to iterate over all accounts in the state (Store::iter_accounts)
  • Add logic to handle GetAccountRange snap request
  • Fix slim encoding of AccountState
  • Remove unneeded trait RLPEncodeSlim

Notes

  • We don't have the listen loop implemented so this PR only adds the standalone logic for handling the request and creating a response, we still need to plug it in to the main loop.
  • We are not able to run the hive test suite due to missing listen loop + old blocks being used by the test suite. I instead copied the state from a Geth execution (loading genesis + importing chain) and used that state to replicate hive tests as unit tests. These tests could be removed once we fix those two problems

Partially addresses #184

@fmoletta fmoletta changed the title feat(l1): implement TrieIterator + GetAccountRange snap request handling [WIP] feat(l1): implement TrieIterator + GetAccountRange snap request handling logic Oct 24, 2024
@fmoletta fmoletta changed the base branch from 840-rlpx-listen-loop to main October 29, 2024 17:52
@fmoletta fmoletta changed the base branch from main to 840-rlpx-listen-loop October 29, 2024 17:53
Base automatically changed from 840-rlpx-listen-loop to main October 29, 2024 18:47
@fmoletta fmoletta marked this pull request as ready for review October 29, 2024 21:22
@fmoletta fmoletta requested a review from a team as a code owner October 29, 2024 21:22
@@ -38,6 +46,14 @@ impl Message {
Message::Ping(msg) => msg.encode(buf),
Message::Pong(msg) => msg.encode(buf),
Message::Status(msg) => msg.encode(buf),
Message::GetAccountRange(msg) => {
0x21_u8.encode(buf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is quite manual. Would be nice to refactor code so that a message is associated to a message id (probably out of scope of this PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could add a method code to the Message enum and use it for encoding/decoding so that we onlty write the code number once in the codebase

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like a good solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ill create an issue for it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that the msg_id is encoded within the RLPxMessage::encode(..) for the other Message types like PingMessage, HelloMessage. Would it not work if we move 0x21_u8.encode(buf) into the RLPxMessage::encode(..) method of snap::GetAccountRange?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are discussing moving the encoding of the code number to the encoding of the Message enum for the other messages too. The code number is already being decoded on the enum's decode Message so encoding it on the enum's decode method would keep encoding/decoding simmetrical for all involved structs

@@ -50,6 +66,8 @@ impl Display for Message {
Message::Ping(_) => "p2p:Ping".fmt(f),
Message::Pong(_) => "p2p:Pong".fmt(f),
Message::Status(_) => "eth:Status".fmt(f),
Message::GetAccountRange(_) => "snap::GetAccountRange".fmt(f),
Copy link
Contributor

@ElFantasma ElFantasma Oct 31, 2024

Choose a reason for hiding this comment

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

single colons (:) to be homogeneous with the rest of the representations.

Maybe we should use / for all instead 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Contributor

@fkrause98 fkrause98 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@ElFantasma ElFantasma left a comment

Choose a reason for hiding this comment

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

Nice work!

@fmoletta fmoletta added this pull request to the merge queue Oct 31, 2024
Merged via the queue into main with commit 236c1a1 Oct 31, 2024
13 checks passed
@fmoletta fmoletta deleted the trie_iter branch October 31, 2024 17:57
h3lio5 pushed a commit to h3lio5/lambda_ethereum_rust that referenced this pull request Oct 31, 2024
…andling logic (lambdaclass#960)

**Motivation**
Handling snap capability message `GetAccountRange`

<!-- Why does this pull request exist? What are its goals? -->

**Description**
* Add functionality to iterate the Trie (TrieIterator)
* Add functionality to iterate over all accounts in the state
(Store::iter_accounts)
* Add logic to handle `GetAccountRange` snap request
* Fix slim encoding of `AccountState`
* Remove unneeded trait `RLPEncodeSlim`

**Notes**
* ~We don't have the listen loop implemented so this PR only adds the
standalone logic for handling the request and creating a response, we
still need to plug it in to the main loop.~
* ~We are not able to run the hive test suite due to missing listen loop
+ old blocks being used by the test suite. I instead copied the state
from a Geth execution (loading genesis + importing chain) and used that
state to replicate hive tests as unit tests. These tests could be
removed once we fix those two problems~

<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 -->
Partially addresses lambdaclass#184

---------

Co-authored-by: Esteban Dimitroff Hodi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants