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): snap sync overhaul #1763

Open
wants to merge 202 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 200 commits
Commits
Show all changes
202 commits
Select commit Hold shift + click to select a range
0ee0d81
Set peer capabilities when starting connection
fmoletta Dec 19, 2024
3e35cec
get_peer: Make it random + filter by cap
fmoletta Dec 19, 2024
b3dcdc3
Fixes
fmoletta Dec 19, 2024
75e32b1
Clippy
fmoletta Dec 19, 2024
30fec69
fmt
fmoletta Dec 19, 2024
3ba67f4
Add holesky genesis + bootnodes
fmoletta Jan 2, 2025
d9dd1ee
Push files
fmoletta Jan 2, 2025
b0cd4ee
Fix rem by zero
fmoletta Jan 3, 2025
dd3dd6b
Apply suggestion
fmoletta Jan 8, 2025
c48ba08
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 8, 2025
ab60c84
Add show_peer_stats method
fmoletta Jan 8, 2025
9f4ebc8
fmt
fmoletta Jan 8, 2025
18fcab5
Move holesky bootnodes to a json file
fmoletta Jan 8, 2025
83c4b3b
Push file
fmoletta Jan 8, 2025
a263ae6
Clippy
fmoletta Jan 8, 2025
9f75073
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 8, 2025
b221394
Aquire receiver lock before sending request
fmoletta Jan 8, 2025
ba76e4e
Add bootnodes & genesis
fmoletta Jan 8, 2025
926a364
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 8, 2025
c1edda8
Fix Deserialize for BootNode
fmoletta Jan 8, 2025
673db47
Merge branch 'show-peer-stats' into sepolia-debug
fmoletta Jan 8, 2025
6b14d7b
Merge branch 'fix-potential-request-overlap' into sepolia-debug
fmoletta Jan 8, 2025
e8fa564
Mute handle_message errors + show peer stats upon peer request
fmoletta Jan 8, 2025
f6e2e2d
Disable ForkId check
fmoletta Jan 8, 2025
0ab0070
Omit unknown caps
fmoletta Jan 8, 2025
dd1b575
Make sync louder
fmoletta Jan 8, 2025
8433e9a
Mute payload tracing
fmoletta Jan 8, 2025
dff2d56
Fix
fmoletta Jan 8, 2025
a8e0e6c
Debug
fmoletta Jan 8, 2025
d97b736
Debug
fmoletta Jan 8, 2025
296fd6d
Show disconnect reason in HandshakeError
fmoletta Jan 8, 2025
0c24974
clippy
fmoletta Jan 8, 2025
847e8bb
fmt
fmoletta Jan 9, 2025
4fcb6f3
Debug
fmoletta Jan 9, 2025
c5af640
Debug
fmoletta Jan 9, 2025
356dfb3
Debug
fmoletta Jan 9, 2025
3c15f29
Debug
fmoletta Jan 9, 2025
dce4ea9
Debug
fmoletta Jan 9, 2025
f850101
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 9, 2025
fe5ea94
Remove diff
fmoletta Jan 9, 2025
1aba97e
Debug
fmoletta Jan 9, 2025
e2e7d5b
Debug
fmoletta Jan 9, 2025
d8a6051
Merge branch 'inform-mid-handshake-disconnect' into sepolia-debug
fmoletta Jan 9, 2025
bfd1862
Debug
fmoletta Jan 9, 2025
104de49
Try to cartch duplicate connection attempt error
fmoletta Jan 9, 2025
184562a
Try to cartch duplicate connection attempt error
fmoletta Jan 9, 2025
2232c02
Try to cartch duplicate connection attempt error
fmoletta Jan 9, 2025
d1c24d9
Dont initiate a second connection when revalidating peer
fmoletta Jan 9, 2025
74ea3b3
Keep track of snap state
fmoletta Jan 9, 2025
0e6396c
Merge branch 'track-snap-state' into sepolia-debug
fmoletta Jan 9, 2025
519b9da
Keep track of snap state
fmoletta Jan 10, 2025
8972955
Keep track of snap state
fmoletta Jan 10, 2025
9b0bf77
Debug
fmoletta Jan 10, 2025
4020234
Debug
fmoletta Jan 10, 2025
75ed3ca
Debug
fmoletta Jan 10, 2025
d3cb204
Disregard bodies
fmoletta Jan 10, 2025
fc7249e
Download only bodies past pivot
fmoletta Jan 10, 2025
b38351a
Mute revalidation'
fmoletta Jan 10, 2025
8b10f5d
Debug
fmoletta Jan 10, 2025
16116c4
Debug
fmoletta Jan 10, 2025
c72de56
Do not switch to full sync on aborted sync
fmoletta Jan 13, 2025
c3ec08e
Debug
fmoletta Jan 13, 2025
62db683
Debug
fmoletta Jan 13, 2025
9008b1b
Debug
fmoletta Jan 13, 2025
de2f849
Debug
fmoletta Jan 13, 2025
d092b12
Mute connection errors
fmoletta Jan 14, 2025
f4cd209
Use current SyncStatus when applying a fork choice update
fmoletta Jan 14, 2025
40e4cc5
Use current SyncStatus when applying a new payload
fmoletta Jan 14, 2025
25785f3
Debug
fmoletta Jan 14, 2025
eb8cce5
Debug
fmoletta Jan 14, 2025
84f5de6
Debug
fmoletta Jan 14, 2025
b3074bb
Debug
fmoletta Jan 14, 2025
d55d22f
Debug
fmoletta Jan 14, 2025
ce488ba
Debug
fmoletta Jan 14, 2025
90571fe
[REVERT ME] disable receipt fetching
fmoletta Jan 14, 2025
a7b195f
Execute blocks after pivot
fmoletta Jan 14, 2025
a53cfaa
Trace verify range
fmoletta Jan 14, 2025
81fd7f0
Revert "Trace verify range"
fmoletta Jan 14, 2025
f3ac721
Trace verify range
fmoletta Jan 14, 2025
1d6548e
Trace verify range
fmoletta Jan 14, 2025
a8aba12
Trace verify range
fmoletta Jan 14, 2025
b5b4a24
Trace verify range
fmoletta Jan 14, 2025
024c13b
Trace verify range
fmoletta Jan 14, 2025
3a77d93
Trace verify range
fmoletta Jan 14, 2025
bb97334
Trace verify range
fmoletta Jan 14, 2025
f768099
Trace verify range
fmoletta Jan 14, 2025
26855e4
Trace verify range
fmoletta Jan 14, 2025
d915aac
Trace verify range
fmoletta Jan 14, 2025
7512ad4
Fix validate storage range logic
fmoletta Jan 14, 2025
075ce35
Fix retry counter when fetching account ranges
fmoletta Jan 14, 2025
94338ae
Only activate full sync after succesful snap sync
fmoletta Jan 14, 2025
231867f
Restore comment
fmoletta Jan 14, 2025
c523bca
Merge branch 'fix-retry-handling-sync' into sepolia-debug
fmoletta Jan 14, 2025
be6464a
Clean verify range tracing
fmoletta Jan 14, 2025
132aecc
Clean verify range tracing
fmoletta Jan 14, 2025
f6e75e6
Clean verify range tracing
fmoletta Jan 14, 2025
b5e5c88
Adjust numbers + silence mac failure
fmoletta Jan 14, 2025
27e01f5
Simplify logic (aka no longer care about bodies and receipts before t…
fmoletta Jan 14, 2025
4ce3e0c
Use current SyncStatus when applying a fork choice update
fmoletta Jan 14, 2025
fc81ab2
Use current SyncStatus when applying a new payload
fmoletta Jan 14, 2025
730bb5e
Mute non-sync logs
fmoletta Jan 15, 2025
fbde9ff
Merge branch 'main' into track-snap-state-simplified
fmoletta Jan 15, 2025
7145b92
Fix
fmoletta Jan 15, 2025
9c03b78
Fix
fmoletta Jan 15, 2025
36f26ee
Mute non-sync logs
fmoletta Jan 15, 2025
fb4fb3e
Periodically show peer stats
fmoletta Jan 15, 2025
824f623
Periodically show peer stats
fmoletta Jan 15, 2025
de73c29
Add comment
fmoletta Jan 15, 2025
b80d447
Fix typo + move call to appropiate context
fmoletta Jan 15, 2025
d5a37c4
Revert "Periodically show peer stats"
fmoletta Jan 15, 2025
f87052a
Merge branch 'periodically-show-peer-stats' into sepolia-debug
fmoletta Jan 15, 2025
7399f89
Trace storage bottlenecks
fmoletta Jan 15, 2025
d9654bd
Trace storage bottlenecks
fmoletta Jan 15, 2025
9b3900a
Abort early if stale pivot on storage fetcher
fmoletta Jan 15, 2025
20f9f47
Adjust batch sizes
fmoletta Jan 15, 2025
3db8c76
Handle large storage batch
fmoletta Jan 15, 2025
6c6753f
Trace Handle large storage batch
fmoletta Jan 15, 2025
b67da8e
Fix
fmoletta Jan 15, 2025
a0ef349
Fix
fmoletta Jan 15, 2025
d580dc2
Update
fmoletta Jan 16, 2025
283529a
Update
fmoletta Jan 16, 2025
f8de62b
Update
fmoletta Jan 16, 2025
f387ff9
Merge branch 'track-snap-state-simplified' into sepolia-debug
fmoletta Jan 16, 2025
d163535
Store state trie checkpoint
fmoletta Jan 16, 2025
9c7b395
Use checkpoints in state trie download
fmoletta Jan 16, 2025
e0d3fa7
Debug
fmoletta Jan 16, 2025
495bbbe
Debug
fmoletta Jan 16, 2025
ec548e3
Debug
fmoletta Jan 16, 2025
b38fe36
Fix
fmoletta Jan 16, 2025
340ce4e
Add storage handling of pending healing lists
fmoletta Jan 16, 2025
3dc9b13
Revert "Add storage handling of pending healing lists"
fmoletta Jan 16, 2025
6c40cc5
Allow healing restart
fmoletta Jan 16, 2025
85de436
Allow healing restart
fmoletta Jan 16, 2025
ad22712
Allow healing restart
fmoletta Jan 16, 2025
f999957
Fix
fmoletta Jan 16, 2025
dc14663
Fix
fmoletta Jan 16, 2025
2f9bfae
Healing: Dont write nodes only leaf values, may be slower but we wont…
fmoletta Jan 17, 2025
6aec5b4
Remove noise
fmoletta Jan 17, 2025
abc85d5
Fix
fmoletta Jan 17, 2025
5f2bdd8
Soft reset
fmoletta Jan 17, 2025
6cf2dd8
Soft reset
fmoletta Jan 17, 2025
0111892
(test) try increasing response bytes
fmoletta Jan 17, 2025
c3120d3
Unify batch sizes
fmoletta Jan 17, 2025
e7542d2
(test) try increasing batch size
fmoletta Jan 17, 2025
69ed322
Dont overwrite pending storages
fmoletta Jan 17, 2025
868d35a
Dont overwrite pending storages
fmoletta Jan 17, 2025
93d2f91
Remove soft reset
fmoletta Jan 17, 2025
8f90a1f
Dont overwrite pending storages
fmoletta Jan 17, 2025
bf74c47
Remove soft reset
fmoletta Jan 17, 2025
3723b88
Show completion percentage during state sync
fmoletta Jan 17, 2025
4bf453e
Debug
fmoletta Jan 17, 2025
75f2182
Show completion percentage during state sync
fmoletta Jan 17, 2025
1f267e9
Show progress: detatch task + show estimated time to finish
fmoletta Jan 17, 2025
691d651
Spawn multiple tasks for storage fetcher
fmoletta Jan 17, 2025
59fcde2
Trace storage tasks
fmoletta Jan 17, 2025
0bd9f53
Fix bit logic
fmoletta Jan 17, 2025
4746e9e
Fix tracing
fmoletta Jan 17, 2025
91162b7
Update bytes limit for peer requests
fmoletta Jan 20, 2025
87485db
Remove internal StalePivot error
fmoletta Jan 20, 2025
ccec4cc
Handle edge case: sync head not found
fmoletta Jan 20, 2025
0e4bd69
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 20, 2025
e282079
Remove debug code
fmoletta Jan 20, 2025
c92627d
Debug
fmoletta Jan 20, 2025
b3531b7
Remove debug code
fmoletta Jan 20, 2025
181d5fd
Mute connection errors
fmoletta Jan 20, 2025
cffb582
Clean branch
fmoletta Jan 20, 2025
2bc5078
Tone down sync tracing
fmoletta Jan 20, 2025
f53634d
Tone down sync tracing
fmoletta Jan 21, 2025
a151033
fmt + replace debug with error return
fmoletta Jan 21, 2025
d84c034
Add debug message on removed unwrap
fmoletta Jan 21, 2025
199f25a
Clearly point out hacky fixes
fmoletta Jan 21, 2025
55ad834
Update redb impl
fmoletta Jan 21, 2025
77875f5
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 21, 2025
9fa4328
Fix
fmoletta Jan 21, 2025
f7b0ee9
Fix
fmoletta Jan 21, 2025
ae0f9e2
restore tracing
fmoletta Jan 21, 2025
7d956ef
Doc new storage methods
fmoletta Jan 21, 2025
fd5791e
Fix potential unwrap
fmoletta Jan 21, 2025
5eaac44
Fix conditional
fmoletta Jan 21, 2025
707b760
Fix logic
fmoletta Jan 21, 2025
9cd6acc
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 21, 2025
0a1bc34
clippy
fmoletta Jan 21, 2025
18347d0
clippy
fmoletta Jan 21, 2025
3094fc5
Fix logic
fmoletta Jan 22, 2025
ae46ef5
Simplify pivot selection + fix post-pivot exec
fmoletta Jan 22, 2025
f1e8c44
Switch to full-sync if we have very few blocks between syc head and l…
fmoletta Jan 22, 2025
c7d4e95
Remove debug line
fmoletta Jan 22, 2025
e38c1a6
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 22, 2025
d7dec4e
Filter out storages without paths left to fetch
fmoletta Jan 22, 2025
f0c544c
fmt
fmoletta Jan 22, 2025
ba68348
Fix issue link
fmoletta Jan 22, 2025
6afac6b
Amend diffs
fmoletta Jan 22, 2025
a93e847
Prioritize reaching leaves on state trie heal + increase batch size f…
fmoletta Jan 22, 2025
d4e299d
Fix
fmoletta Jan 22, 2025
3ead985
Cleaning
fmoletta Jan 22, 2025
e08cc0a
Fix cherry pick conflicts
fmoletta Jan 22, 2025
d5782ab
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 22, 2025
13c0a1d
Fix leftover conflicts
fmoletta Jan 22, 2025
adc4df7
Use saturating sub
fmoletta Jan 23, 2025
e62df20
Remove hacky fix
fmoletta Jan 23, 2025
61261fc
remove unused import
fmoletta Jan 23, 2025
b08ff00
Lower request byte limit
fmoletta Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/networking/p2p/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ async fn peers_revalidation(
table.update_peer_ping_with_revalidation(peer.node.node_id, ping_hash);
previously_pinged_peers.insert(peer.node.node_id);

debug!("Pinging peer {:?} to re-validate!", peer.node.node_id);
debug!("Pinging peer {} to re-validate!", peer.node.node_id);
}

debug!("Peer revalidation finished");
Expand Down Expand Up @@ -1029,7 +1029,7 @@ pub fn node_id_from_signing_key(signer: &SigningKey) -> H512 {

/// Shows the amount of connected peers, active peers, and peers suitable for snap sync on a set interval
pub async fn periodically_show_peer_stats(peer_table: Arc<Mutex<KademliaTable>>) {
const INTERVAL_DURATION: tokio::time::Duration = tokio::time::Duration::from_secs(60);
const INTERVAL_DURATION: tokio::time::Duration = tokio::time::Duration::from_secs(120);
let mut interval = tokio::time::interval(INTERVAL_DURATION);
loop {
peer_table.lock().await.show_peer_stats();
Expand Down
68 changes: 66 additions & 2 deletions crates/networking/p2p/peer_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{

pub const PEER_REPLY_TIMOUT: Duration = Duration::from_secs(45);
pub const MAX_MESSAGES_IN_PEER_CHANNEL: usize = 25;
pub const MAX_RESPONSE_BYTES: u64 = 512 * 1024;
pub const MAX_RESPONSE_BYTES: u64 = 2 * 1024 * 1024;
pub const HASH_MAX: H256 = H256([0xFF; 32]);

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -260,7 +260,7 @@ impl PeerChannels {
/// Requests storage ranges for accounts given their hashed address and storage roots, and the root of their state trie
/// account_hashes & storage_roots must have the same length
/// storage_roots must not contain empty trie hashes, we will treat empty ranges as invalid responses
/// Returns true if the last accoun't storage was not completely fetched by the request
/// Returns true if the last account's storage was not completely fetched by the request
/// Returns the list of hashed storage keys and values for each account's storage or None if:
/// - There are no available peers (the node just started up or was rejected by all other nodes)
/// - The response timed out
Expand Down Expand Up @@ -447,4 +447,68 @@ impl PeerChannels {
})
.flatten()
}

/// Requests a single storage range for an accouns given its hashed address and storage root, and the root of its state trie
/// This is a simplified version of `request_storage_range` meant to be used for large tries that require their own single requests
/// account_hashes & storage_roots must have the same length
/// storage_root must not be an empty trie hash, we will treat empty ranges as invalid responses
/// Returns true if the account's storage was not completely fetched by the request
/// Returns the list of hashed storage keys and values for the account's storage or None if:
/// - There are no available peers (the node just started up or was rejected by all other nodes)
/// - The response timed out
/// - The response was empty or not valid
pub async fn request_storage_range(
&self,
state_root: H256,
storage_root: H256,
account_hash: H256,
start: H256,
) -> Option<(Vec<H256>, Vec<U256>, bool)> {
let request_id = rand::random();
let request = RLPxMessage::GetStorageRanges(GetStorageRanges {
id: request_id,
root_hash: state_root,
account_hashes: vec![account_hash],
starting_hash: start,
limit_hash: HASH_MAX,
response_bytes: MAX_RESPONSE_BYTES,
});
let mut receiver = self.receiver.lock().await;
self.sender.send(request).await.ok()?;
let (mut slots, proof) = tokio::time::timeout(PEER_REPLY_TIMOUT, async move {
loop {
match receiver.recv().await {
mpaulucci marked this conversation as resolved.
Show resolved Hide resolved
Some(RLPxMessage::StorageRanges(StorageRanges { id, slots, proof }))
if id == request_id =>
{
return Some((slots, proof))
}
// Ignore replies that don't match the expected id (such as late responses)
Some(_) => continue,
None => return None,
}
}
})
.await
.ok()??;
// Check we got a reasonable amount of storage ranges
if slots.len() != 1 {
return None;
}
ilitteri marked this conversation as resolved.
Show resolved Hide resolved
// Unzip & validate response
let proof = encodable_to_proof(&proof);
let (storage_keys, storage_values): (Vec<H256>, Vec<U256>) = slots
.remove(0)
.into_iter()
.map(|slot| (slot.hash, slot.data))
.unzip();
let encoded_values = storage_values
.iter()
.map(|val| val.encode_to_vec())
.collect::<Vec<_>>();
// Verify storage range
let should_continue =
verify_range(storage_root, &start, &storage_keys, &encoded_values, &proof).ok()?;
Some((storage_keys, storage_values, should_continue))
}
}
6 changes: 5 additions & 1 deletion crates/networking/p2p/rlpx/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use tokio::{
};
use tokio_stream::StreamExt;
use tokio_util::codec::Framed;
use tracing::{debug, error};
use tracing::{debug, error, warn};
const CAP_P2P: (Capability, u8) = (Capability::P2p, 5);
const CAP_ETH: (Capability, u8) = (Capability::Eth, 68);
const CAP_SNAP: (Capability, u8) = (Capability::Snap, 1);
Expand Down Expand Up @@ -614,6 +614,10 @@ impl<S: AsyncWrite + AsyncRead + std::marker::Unpin> RLPxConnection<S> {
let msg_size = u16::from_be_bytes(ack_data) as usize;

// Read the rest of the message
// Guard unwrap
if buf.len() < msg_size + 2 {
return Err(RLPxError::CryptographyError(String::from("bad buf size")));
}
self.framed
.get_mut()
.read_exact(&mut buf[2..msg_size + 2])
Expand Down
4 changes: 3 additions & 1 deletion crates/networking/p2p/rlpx/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ fn decrypt_message(

// Verify the MAC.
let expected_d = sha256_hmac(&mac_key, &[iv, c], size_data);
assert_eq!(d, expected_d);
if d != expected_d {
return Err(RLPxError::HandshakeError(String::from("Invalid MAC")));
}

// Decrypt the message with the AES key.
let mut stream_cipher = Aes128Ctr64BE::new_from_slices(aes_key, iv)?;
Expand Down
Loading
Loading