Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
c4105ee
Made it so that it writes stts for default
fedacking Sep 17, 2025
87cfc01
format
fedacking Sep 17, 2025
b7f29e7
Update utils.rs
fedacking Sep 17, 2025
72f00b7
compare
fedacking Sep 17, 2025
999115d
moved function outside
fedacking Sep 17, 2025
2384772
Update sync.rs
fedacking Sep 17, 2025
ae963c8
Update Cargo.toml
fedacking Sep 17, 2025
b60cd75
Update Cargo.toml
fedacking Sep 17, 2025
29c4b4c
Update sync.rs
fedacking Sep 17, 2025
287da4e
Sorted trie
fedacking Sep 18, 2025
dded7b7
Compiles
fedacking Sep 18, 2025
1dc3e74
dedup
fedacking Sep 18, 2025
500be72
Update Cargo.toml
fedacking Sep 18, 2025
5a49a83
Update sync.rs
fedacking Sep 18, 2025
79b6795
par iter
fedacking Sep 18, 2025
278da8a
Update sync.rs
fedacking Sep 18, 2025
b9e0f83
Merge remote-tracking branch 'origin/main' into perf/fast-insert-snap
fedacking Sep 19, 2025
90f0752
Fixed compile
fedacking Sep 22, 2025
0a38b20
added logging for error
fedacking Sep 23, 2025
85cd817
Fixed edge case and pushed fix
fedacking Sep 23, 2025
211a6b6
print the account with an error
fedacking Sep 23, 2025
141019c
what's going on
fedacking Sep 23, 2025
6fa1883
Fix attempt
fedacking Sep 23, 2025
20b1a7c
Update sync.rs
fedacking Sep 23, 2025
0126919
Update trie_sorted.rs
fedacking Sep 23, 2025
33f750a
Added inc
fedacking Sep 23, 2025
34eebd1
rocksdb iterator
fedacking Sep 23, 2025
80557ad
fixed bytecodes
fedacking Sep 23, 2025
dc8d0ec
returned par iter
fedacking Sep 23, 2025
4298c21
added logging
fedacking Sep 24, 2025
74f2e5a
Scoped thread
fedacking Sep 24, 2025
46bb452
Removed logging
fedacking Sep 24, 2025
5a5d9a0
Don't spawn that many threads
fedacking Sep 24, 2025
0e53046
Improved error handling
fedacking Sep 24, 2025
8add39d
Fixed race condition
fedacking Sep 24, 2025
edc2f91
perf(l1): use BTree for tracking storages during snap sync
Oppen Sep 24, 2025
df2811d
fast put batch
fedacking Sep 24, 2025
13d6659
Update rocksdb.rs
fedacking Sep 24, 2025
8896db3
threadpool
fedacking Sep 24, 2025
86869ec
perf(l1): compress storage trie downloads
Oppen Sep 25, 2025
2ec688b
fix order
Oppen Sep 25, 2025
f0d1e0e
fix insertion
Oppen Sep 25, 2025
bccc632
Back into par iter
fedacking Sep 25, 2025
f7a4702
fix typo + time roots
Oppen Sep 25, 2025
9ea9ddf
extra data + reuse storages
Oppen Sep 25, 2025
e66cd62
Make lint
fedacking Sep 25, 2025
6756108
Merge remote-tracking branch 'origin/main' into perf/fast-insert-snap
fedacking Sep 25, 2025
37c1d79
Update db.rs
fedacking Sep 25, 2025
9473681
Merge remote-tracking branch 'origin/main' into perf/fast-insert-snap
fedacking Sep 25, 2025
6c8e0fb
WIP: scoped thread pool
pablodeymo Sep 25, 2025
2ebcafa
Finished scoped threadpool
fedacking Sep 25, 2025
677bf5c
Merge remote-tracking branch 'origin/thread_pool' into perf/fast-inse…
fedacking Sep 25, 2025
d650922
Adopted thread pool
fedacking Sep 25, 2025
6718148
Pool arc
fedacking Sep 25, 2025
c301529
Update sync.rs
fedacking Sep 25, 2025
8b5e934
naming threads
fedacking Sep 25, 2025
aa6fdbe
Update sync.rs
fedacking Sep 25, 2025
53b8163
Executed separatedly last task
fedacking Sep 25, 2025
8e704cc
Added crossbeam
fedacking Sep 26, 2025
ab9df8b
Merged the snap sync optimizations that improve storage leaves downlo…
jrchatruc Sep 26, 2025
af4c4e4
2 pools
fedacking Sep 26, 2025
888472a
Comment out debug! on insertion for now
jrchatruc Sep 26, 2025
b75034f
Testing priority queue
fedacking Sep 26, 2025
a7e2084
Add TODO
jrchatruc Sep 26, 2025
08fbdf6
Update sync.rs
fedacking Sep 26, 2025
07b8ea5
Update sync.rs
fedacking Sep 26, 2025
5795636
Merge branch 'perf/fast-insert-snap-pool' into merge_optimizations_fa…
fedacking Sep 26, 2025
ec81b86
Compiles
fedacking Sep 26, 2025
7a7e0f3
Update sync.rs
fedacking Sep 26, 2025
4e3621b
Simple semaphore
fedacking Sep 26, 2025
193327d
Update sync.rs
fedacking Sep 26, 2025
fa9ac95
Changed to fixed amount of buffers
fedacking Sep 29, 2025
e0ec836
Removed unneeded compaction
fedacking Sep 29, 2025
c93aa46
cleanup
fedacking Sep 29, 2025
9680d09
Merge remote-tracking branch 'origin/main' into merge_optimizations_f…
fedacking Sep 29, 2025
303f9e0
Compiles
fedacking Sep 29, 2025
adaf0b0
fixed tomls
fedacking Sep 29, 2025
1e0910a
Update code_collector.rs
fedacking Sep 30, 2025
ac7a8b9
Update rocksdb.rs
fedacking Sep 30, 2025
6d0e8d8
Removed unnecesaty alloc in put_batch_no_alloc
fedacking Sep 30, 2025
ca3942a
Removed cfg_if
fedacking Sep 30, 2025
ebcccd6
Update db.rs
fedacking Sep 30, 2025
f47bcb3
Fixed buffer count
fedacking Sep 30, 2025
60b9372
Update trie_sorted.rs
fedacking Sep 30, 2025
2c79fe0
Update sync.rs
fedacking Sep 30, 2025
7a14f42
Optimized insertion to disk
fedacking Sep 30, 2025
c02f069
fixed potential bug
fedacking Sep 30, 2025
60f0bc6
added debug logging
fedacking Sep 30, 2025
4528ac0
Update utils.rs
fedacking Sep 30, 2025
c8c00bc
fix
fedacking Sep 30, 2025
939ac99
Lint
fedacking Sep 30, 2025
dda32e4
Cleaned up code
fedacking Sep 30, 2025
fd55d47
Update Cargo.lock
fedacking Sep 30, 2025
558c5f0
simplified
fedacking Sep 30, 2025
d0663d5
Untested remove dir
fedacking Sep 30, 2025
3b19599
Merge remote-tracking branch 'origin/main' into delete-unneeded-files
fedacking Oct 8, 2025
726fdf7
Untested remove dir
fedacking Oct 8, 2025
1bf391d
Merge remote-tracking branch 'origin/main' into delete-unneeded-files
fedacking Oct 13, 2025
92576ff
validating folders
fedacking Oct 13, 2025
cfa1c8b
Merge branch 'main' into delete-unneeded-files
fedacking Oct 13, 2025
ab32e20
Update utils.rs
fedacking Oct 13, 2025
e1f2ad9
Update utils.rs
fedacking Oct 13, 2025
91c99e6
Merge remote-tracking branch 'origin/main' into delete-unneeded-files
fedacking Oct 13, 2025
b2ca23c
Update sync.rs
fedacking Oct 13, 2025
b0a45ef
Update sync.rs
fedacking Oct 13, 2025
d585487
Update sync.rs
fedacking Oct 13, 2025
5b48878
Update sync.rs
fedacking Oct 13, 2025
f96095e
Update sync.rs
fedacking Oct 13, 2025
49a4cc2
Include code hashes dir
fedacking Oct 13, 2025
b4255d8
Update sync.rs
fedacking Oct 13, 2025
2e1af0a
Merge branch 'main' into delete-unneeded-files
fedacking Oct 13, 2025
d569c44
chore: cahnge exit code to 1
MegaRedHand Oct 15, 2025
aa0c916
Merge branch 'main' into delete-unneeded-files
MegaRedHand Oct 15, 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
43 changes: 39 additions & 4 deletions crates/networking/p2p/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::sync::state_healing::heal_state_trie_wrap;
use crate::sync::storage_healing::heal_storage_trie;
use crate::utils::{
current_unix_time, get_account_state_snapshots_dir, get_account_storages_snapshots_dir,
get_code_hashes_snapshots_dir,
get_code_hashes_snapshots_dir, validate_folders,
};
use crate::{
metrics::METRICS,
Expand Down Expand Up @@ -197,6 +197,19 @@ impl Syncer {
Err(e) => return Err(e.into()),
};

// We validate that we have the folders that are being used empty, as we currently assume
// they are.
if !validate_folders(&self.datadir) {
// Temp std::process::exit until #2767 is done
error!(
"One of the folders used for temporary leaves during snap is still used. Delete them in {}",
&self.datadir.to_str().unwrap_or_default()
);
std::process::exit(1);
// Cloning a single string, the node should stop after this
// return Err(SyncError::NotEmptyDatadirFolders(self.datadir.clone()));
}

loop {
debug!("Sync Log 1: In snap sync");
debug!(
Expand Down Expand Up @@ -1120,6 +1133,9 @@ impl Syncer {
.await?;
}

std::fs::remove_dir_all(code_hashes_dir)
.map_err(|_| SyncError::CodeHashesSnapshotsDirNotFound)?;

*METRICS.bytecode_download_end_time.lock().await = Some(SystemTime::now());

debug_assert!(validate_bytecodes(store.clone(), pivot_header.state_root).await);
Expand Down Expand Up @@ -1322,6 +1338,8 @@ pub enum SyncError {
NoPeers,
#[error("Failed to get block headers")]
NoBlockHeaders,
#[error("The download datadir folders at {0} are not empty, delete them first")]
NotEmptyDatadirFolders(PathBuf),
#[error("Couldn't create a thread")]
ThreadCreationError,
#[error("Called update_pivot outside snapsync mode")]
Expand Down Expand Up @@ -1405,7 +1423,7 @@ pub async fn validate_storage_root(store: Store, state_root: H256) -> bool {
.all(|valid| valid);
info!("Finished validate_storage_root");
if !is_valid {
std::process::exit(-1);
std::process::exit(1);
}
is_valid
}
Expand All @@ -1430,7 +1448,7 @@ pub async fn validate_bytecodes(store: Store, state_root: H256) -> bool {
}
}
if !is_valid {
std::process::exit(-1);
std::process::exit(1);
}
is_valid
}
Expand Down Expand Up @@ -1493,6 +1511,8 @@ async fn insert_accounts(

computed_state_root = current_state_root?;
}
std::fs::remove_dir_all(account_state_snapshots_dir)
.map_err(|_| SyncError::AccountStoragesSnapshotsDirNotFound)?;
info!("computed_state_root {computed_state_root}");
Ok((computed_state_root, BTreeSet::new()))
}
Expand Down Expand Up @@ -1561,6 +1581,10 @@ async fn insert_storages(
.write_storage_trie_nodes_batch(storage_trie_node_changes)
.await?;
}

std::fs::remove_dir_all(account_storages_snapshots_dir)
.map_err(|_| SyncError::AccountStoragesSnapshotsDirNotFound)?;

Ok(())
}

Expand Down Expand Up @@ -1620,6 +1644,11 @@ async fn insert_accounts(
)
.map_err(SyncError::TrieGenerationError)?;

std::fs::remove_dir_all(account_state_snapshots_dir)
.map_err(|_| SyncError::AccountStateSnapshotsDirNotFound)?;
std::fs::remove_dir_all(get_rocksdb_temp_accounts_dir(datadir))
.map_err(|_| SyncError::AccountTempDBDirNotFound)?;

let accounts_with_storage =
BTreeSet::from_iter(storage_accounts.accounts_with_storage_root.keys().copied());
Ok((compute_state_root, accounts_with_storage))
Expand Down Expand Up @@ -1679,7 +1708,7 @@ async fn insert_storages(
let mut db_options = rocksdb::Options::default();
db_options.create_if_missing(true);
let db = rocksdb::DB::open(&db_options, get_rocksdb_temp_storage_dir(datadir))
.map_err(|_| SyncError::StorageTempDBDirNotFound)?;
.map_err(|err: rocksdb::Error| SyncError::RocksDBError(err.into_string()))?;
let file_paths: Vec<PathBuf> = std::fs::read_dir(account_storages_snapshots_dir)
.map_err(|_| SyncError::AccountStoragesSnapshotsDirNotFound)?
.collect::<Result<Vec<_>, _>>()
Expand Down Expand Up @@ -1755,5 +1784,11 @@ async fn insert_storages(
pool.execute(task);
}
});

std::fs::remove_dir_all(account_storages_snapshots_dir)
.map_err(|_| SyncError::AccountStoragesSnapshotsDirNotFound)?;
std::fs::remove_dir_all(get_rocksdb_temp_storage_dir(datadir))
.map_err(|_| SyncError::StorageTempDBDirNotFound)?;

Ok(())
}
16 changes: 16 additions & 0 deletions crates/networking/p2p/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ pub fn public_key_from_signing_key(signer: &SecretKey) -> H512 {
H512::from_slice(&encoded[1..])
}

/// Returns true if the folders used for the partial download of the leaves exists. if they do exist, it
/// should be deleted. We don't auto delete them on the off chance we want to backup the files
pub fn validate_folders(datadir: &Path) -> bool {
let folder_doesnt_exist = !std::fs::exists(get_account_state_snapshots_dir(datadir))
.is_ok_and(|exists| exists)
&& !std::fs::exists(get_account_storages_snapshots_dir(datadir)).is_ok_and(|exists| exists)
&& !std::fs::exists(get_code_hashes_snapshots_dir(datadir)).is_ok_and(|exists| exists);
#[cfg(feature = "rocksdb")]
let folder_doesnt_exist = {
folder_doesnt_exist
&& !std::fs::exists(get_rocksdb_temp_accounts_dir(datadir)).is_ok_and(|exists| exists)
&& !std::fs::exists(get_rocksdb_temp_storage_dir(datadir)).is_ok_and(|exists| exists)
};
folder_doesnt_exist
}

pub fn get_account_storages_snapshots_dir(datadir: &Path) -> PathBuf {
datadir.join("account_storages_snapshots")
}
Expand Down
Loading