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): full sync #1312

Merged
merged 285 commits into from
Nov 28, 2024
Merged

feat(l1): full sync #1312

merged 285 commits into from
Nov 28, 2024

Conversation

fmoletta
Copy link
Contributor

@fmoletta fmoletta commented Nov 27, 2024

Motivation
Support syncing via fullsync

Description

  • Implement full sync
  • Trigger full sync in fork choice update
  • Implement communication between backend and peers in p2p crate via channels that allow to send and receive messages from the peer data on the kademlia table to the peer's active connection listen loop. This way backend processes, such as syncing, can make requests and receive responses from a chosen peer

Leftover work: #1317 #1318

Status:
Succesfully passes ethereum/sync test suite when removing V3-specifc fork choice & payload checks (see commit c6d6767)

This PR shares the same basis as snap-sync #1209

Closes: None, but is a good basis for snap sync

fmoletta and others added 30 commits October 25, 2024 15:21
…ethereum_rust into trie_iter_plus_listen_loop
@fmoletta fmoletta marked this pull request as ready for review November 27, 2024 19:32
@fmoletta fmoletta requested a review from a team as a code owner November 27, 2024 19:32
@@ -117,6 +115,11 @@ async fn main() {
.get_one::<String>("datadir")
.map_or(set_datadir(DEFAULT_DATADIR), |datadir| set_datadir(datadir));

let snap_sync = is_snap_sync(&matches);
if snap_sync {
info!("snap-sync not available, defaulting to full-sync");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Full sync will only work for a network with a post-merge genesis, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the sync itself here is no check specifically preventing it from happening, we would get an error when trying to execute pre-merge blocks as we don't support them.

/// Only performs full-sync but will also be in charge of snap-sync in the future
#[derive(Debug)]
pub struct SyncManager {
// true: syncmode = snap, false = syncmode = full
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: wouldn't it be clearer to have an enum instead of a bool?

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 thought making an enum for only two choices was a bit overkill. Maybe we could change the name to snap_enabled so we can "disable" it after the first sync

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually find an enum fitting for this situation, having a bool can lead to wonder what false/true means (plus the enum has type checking which warns when you're not using some varint), but this is not something critical.


/// Starts a sync cycle, updating the state with all blocks between the current head and the sync head
/// TODO: only uses full sync, should also process snap sync once implemented
pub async fn start_sync(&mut self, mut current_head: H256, sync_head: H256, store: Store) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

so, if I understand this right, current_head is older than sync_head?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think eventually we will have to go backwards for syncing, but let's discuss it. Anyway this is great for a first version.

}
}

/// Creates a dummy SyncManager for tests where syncing is not needed
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we put this behind the test feature flag?

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 would like to, but test feature flag gating doesn't work well across crates

};
return serde_json::to_value(fork_choice_response)
.map_err(|error| RpcErr::Internal(error.to_string()));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

awesome work!

Copy link
Collaborator

@mpaulucci mpaulucci left a comment

Choose a reason for hiding this comment

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

🎉

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.

Left some comments, overall looks good, I like the Syncer approach 🚀 .

cmd/ethrex/cli.rs Show resolved Hide resolved
crates/networking/p2p/kademlia.rs Outdated Show resolved Hide resolved
crates/networking/p2p/kademlia.rs Show resolved Hide resolved
crates/networking/p2p/kademlia.rs Show resolved Hide resolved
crates/networking/p2p/kademlia.rs Outdated Show resolved Hide resolved
crates/networking/p2p/sync.rs Show resolved Hide resolved
crates/networking/p2p/sync.rs Show resolved Hide resolved
crates/networking/p2p/sync.rs Show resolved Hide resolved
crates/networking/p2p/sync.rs Show resolved Hide resolved
crates/networking/rpc/engine/fork_choice.rs Show resolved Hide resolved
@fmoletta fmoletta added this pull request to the merge queue Nov 28, 2024
Merged via the queue into main with commit 9a2f8e0 Nov 28, 2024
15 checks passed
@fmoletta fmoletta deleted the full-sync branch November 28, 2024 21:17
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.

4 participants