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): improve healing #1867

Merged
merged 264 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
264 commits
Select commit Hold shift + click to select a range
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
fb0b509
Fix potential unwrap
fmoletta Jan 21, 2025
12b2791
Fix conditional
fmoletta Jan 21, 2025
1541cce
Debug
fmoletta Jan 21, 2025
34b4fd9
Fix logic
fmoletta Jan 21, 2025
d4b0350
Soft reset
fmoletta Jan 21, 2025
cddf287
Get rid of noisy unwrap
fmoletta Jan 21, 2025
598e14a
Get rid of noisy unwrap
fmoletta Jan 21, 2025
1fd66c5
Debug
fmoletta Jan 21, 2025
9fd8425
Not so much debug
fmoletta Jan 21, 2025
4f4b6c9
Debug
fmoletta Jan 21, 2025
49c165e
Remove soft reset
fmoletta Jan 21, 2025
7dc43bf
Debug
fmoletta Jan 21, 2025
f1e5416
Debug
fmoletta Jan 21, 2025
a1c8f53
Debug
fmoletta Jan 21, 2025
7dc1a4f
Debug
fmoletta Jan 21, 2025
791a6be
Debug
fmoletta Jan 21, 2025
e9db4f2
Recount
fmoletta Jan 22, 2025
06425cc
Debug
fmoletta Jan 22, 2025
b699909
Filter out storages without paths left to fetch
fmoletta Jan 22, 2025
91ed3b9
Revert "Debug"
fmoletta Jan 22, 2025
2404d2d
Revert "Recount"
fmoletta Jan 22, 2025
fd14b20
Debug leaf touches
fmoletta Jan 22, 2025
c318740
Debug leaf touches
fmoletta Jan 22, 2025
8872ee1
Make storage heal quieter and state heal louder
fmoletta Jan 22, 2025
070034d
Prioritize reaching leaves on state trie heal + increase batch size f…
fmoletta Jan 22, 2025
384f1b2
Fix
fmoletta Jan 22, 2025
09f14c3
Cleaning
fmoletta Jan 22, 2025
ef868d2
Soft reset
fmoletta Jan 23, 2025
4d2a6c4
Revert "Soft reset"
fmoletta Jan 23, 2025
7656bd5
Revert "Cleaning"
fmoletta Jan 23, 2025
9f3afb9
Revert "Fix"
fmoletta Jan 23, 2025
b24a118
Revert "Prioritize reaching leaves on state trie heal + increase batc…
fmoletta Jan 23, 2025
b4adf6c
Save full nodes instead of leafs during healing
fmoletta Jan 23, 2025
eef3b60
restore one net trace
fmoletta Jan 23, 2025
ce5ea22
Lower request byte limit
fmoletta Jan 23, 2025
2580fce
Revert "restore one net trace"
fmoletta Jan 23, 2025
2ca9357
Show active peers more frequently
fmoletta Jan 23, 2025
c64b209
Soft reset + add enode
fmoletta Jan 27, 2025
7bb6e50
Revert "Lower request byte limit"
fmoletta Jan 27, 2025
1ffb043
Remove soft reset
fmoletta Jan 27, 2025
180970c
Revert "Revert "Lower request byte limit""
fmoletta Jan 27, 2025
f562b1e
Remove slow bootnode
fmoletta Jan 27, 2025
1c1028e
Show peer distribution
fmoletta Jan 27, 2025
794eeb0
Update cancun engine tests
fmoletta Jan 27, 2025
ab5ebb3
[PickMe] Use `recv_many` to avoid piling up multiple incoming batches…
fmoletta Jan 28, 2025
83caa20
[PickMe] Store state sync checkpoints regardless of staleness
fmoletta Jan 28, 2025
8a12e2c
Skip state sync if we already begun healing
fmoletta Jan 28, 2025
fa62807
Fix
fmoletta Jan 28, 2025
27567ca
Speed up Storage healing
fmoletta Jan 29, 2025
cf45dd7
Limit amount of paths in node request
fmoletta Jan 29, 2025
4f0d547
Reduce noise
fmoletta Jan 30, 2025
08e876b
Ugly solution to not wait for incoming batch to start storage healing
fmoletta Jan 30, 2025
cd886c4
Add mekong presets
fmoletta Jan 31, 2025
f3da0ce
Push files
fmoletta Jan 31, 2025
df6795e
Trim discport from bootnodes
fmoletta Jan 31, 2025
940ed67
Fake NewPayloadV4 endpoint
fmoletta Jan 31, 2025
3a1473e
Fake NewPayloadV4 endpoint
fmoletta Jan 31, 2025
d4bf205
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Jan 31, 2025
a2524e4
Fix
fmoletta Jan 31, 2025
693b39b
Merge branch 'healing-rethink' into mekong-plus-healing-rethink
fmoletta Jan 31, 2025
a599a17
Mute some spammy p2p errors
fmoletta Jan 31, 2025
d13e8ed
Mute some spammy p2p errors
fmoletta Jan 31, 2025
8f4c3c3
Merge branch 'mekong-debug' into mekong-plus-healing-rethink
fmoletta Jan 31, 2025
c48076f
Sleep to force healing
fmoletta Jan 31, 2025
a4d507a
Sleep to force healing
fmoletta Jan 31, 2025
f4f4560
Fix
fmoletta Feb 3, 2025
a7ee633
Trie health checkup
fmoletta Feb 3, 2025
8443ba0
Trie health checkup
fmoletta Feb 3, 2025
62a6e06
Restore byte limit
fmoletta Feb 3, 2025
349186b
Soft reset
fmoletta Feb 3, 2025
c3f3116
Unify snap state clearing
fmoletta Feb 3, 2025
49d06ec
Silence peer errors
fmoletta Feb 3, 2025
9e6b36a
Debug
fmoletta Feb 3, 2025
036f598
Fix
fmoletta Feb 3, 2025
b7ae9b1
Fix
fmoletta Feb 3, 2025
bc8dc02
Execute block before setting it as cannonical
fmoletta Feb 3, 2025
bc18433
Merge branch 'main' of github.com:lambdaclass/lambda_ethereum_rust in…
fmoletta Feb 3, 2025
c093271
Revert "Silence peer errors"
fmoletta Feb 3, 2025
a9318a2
Remove trie health checkup
fmoletta Feb 3, 2025
7a9f831
Remove debug code
fmoletta Feb 3, 2025
4e64984
Fix merge conflict
fmoletta Feb 3, 2025
f981067
Fix merge conflict
fmoletta Feb 3, 2025
39f3309
Amend diffs
fmoletta Feb 3, 2025
9142a84
Amend diffs
fmoletta Feb 3, 2025
12b89da
Amend diffs
fmoletta Feb 3, 2025
5242b4d
Amend diffs
fmoletta Feb 3, 2025
1b38b53
Amend diffs
fmoletta Feb 3, 2025
3c13cef
Amend diffs
fmoletta Feb 3, 2025
b41778f
Update storage names + doc
fmoletta Feb 3, 2025
397836f
doc
fmoletta Feb 3, 2025
335b563
Update redb impl
fmoletta Feb 3, 2025
4e727e8
Amend diffs
fmoletta Feb 3, 2025
036d8b2
fmt
fmoletta Feb 3, 2025
88f8fd7
remove debug print
fmoletta Feb 3, 2025
50d58f2
Update comment
fmoletta Feb 3, 2025
2387897
Update paths
fmoletta Feb 3, 2025
dd742b4
Clippy
fmoletta Feb 3, 2025
e6fb8b4
Fix
fmoletta Feb 3, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/networking/p2p/discv4/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Discv4Server {
debug!("Received {read} bytes from {from}");

match Packet::decode(&buf[..read]) {
Err(e) => error!("Could not decode packet: {:?}", e),
Err(e) => debug!("Could not decode packet: {:?}", e),
Ok(packet) => {
let msg = packet.get_message();
let msg_name = msg.to_string();
Expand Down
8 changes: 4 additions & 4 deletions crates/networking/p2p/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tokio::{
sync::Mutex,
};
use tokio_util::task::TaskTracker;
use tracing::{error, info};
use tracing::{debug, error, info};
use types::Node;

pub(crate) mod discv4;
Expand Down Expand Up @@ -139,7 +139,7 @@ async fn handle_peer_as_receiver(context: P2PContext, peer_addr: SocketAddr, str
// TODO We should remove the peer from the table if connection failed
// but currently it will make the tests fail
// table.lock().await.replace_peer(node.node_id);
error!("Error creating tcp connection with peer at {peer_addr}: {e}")
debug!("Error creating tcp connection with peer at {peer_addr}: {e}")
}
}
}
Expand All @@ -152,7 +152,7 @@ async fn handle_peer_as_initiator(context: P2PContext, node: Node) {
// TODO We should remove the peer from the table if connection failed
// but currently it will make the tests fail
// table.lock().await.replace_peer(node.node_id);
error!("Error establishing tcp connection with peer at {addr}: {e}");
debug!("Error establishing tcp connection with peer at {addr}: {e}");
return;
}
};
Expand All @@ -163,7 +163,7 @@ async fn handle_peer_as_initiator(context: P2PContext, node: Node) {
// TODO We should remove the peer from the table if connection failed
// but currently it will make the tests fail
// table.lock().await.replace_peer(node.node_id);
error!("Error creating tcp connection with peer at {addr}: {e}")
debug!("Error creating tcp connection with peer at {addr}: {e}")
}
};
}
Expand Down
174 changes: 85 additions & 89 deletions crates/networking/p2p/sync.rs

Large diffs are not rendered by default.

29 changes: 14 additions & 15 deletions crates/storage/store/engines/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ethrex_core::types::{
use std::{fmt::Debug, panic::RefUnwindSafe};

use crate::error::StoreError;
use ethrex_trie::Trie;
use ethrex_trie::{Nibbles, Trie};

pub trait StoreEngine: Debug + Send + Sync + RefUnwindSafe {
/// Add block header
Expand Down Expand Up @@ -258,35 +258,34 @@ pub trait StoreEngine: Debug + Send + Sync + RefUnwindSafe {
/// Gets the hash of the last header downloaded during a snap sync
fn get_header_download_checkpoint(&self) -> Result<Option<BlockHash>, StoreError>;

/// Clears the hash of the last header downloaded during a snap sync
fn clear_header_download_checkpoint(&self) -> Result<(), StoreError>;

/// Sets the current state root of the state trie being rebuilt during snap sync
fn set_state_trie_root_checkpoint(&self, current_root: H256) -> Result<(), StoreError>;

/// Gets the current state root of the state trie being rebuilt during snap sync
fn get_state_trie_root_checkpoint(&self) -> Result<Option<H256>, StoreError>;

/// Clears the current state root of the state trie being rebuilt during snap sync
fn clear_state_trie_root_checkpoint(&self) -> Result<(), StoreError>;

/// Sets the last key fetched from the state trie being fetched during snap sync
fn set_state_trie_key_checkpoint(&self, last_key: H256) -> Result<(), StoreError>;

/// Gets the last key fetched from the state trie being fetched during snap sync
fn get_state_trie_key_checkpoint(&self) -> Result<Option<H256>, StoreError>;

/// Clears the last key fetched from the state trie being fetched during snap sync
fn clear_state_trie_key_checkpoint(&self) -> Result<(), StoreError>;
/// Sets the storage trie paths in need of healing, grouped by hashed address
fn set_storage_heal_paths(&self, accounts: Vec<(H256, Vec<Nibbles>)>)
-> Result<(), StoreError>;

/// Gets the storage trie paths in need of healing, grouped by hashed address
#[allow(clippy::type_complexity)]
fn get_storage_heal_paths(&self) -> Result<Option<Vec<(H256, Vec<Nibbles>)>>, StoreError>;

/// Sets the list of account hashes whose storage needs healing
fn set_pending_storage_heal_accounts(&self, accounts: Vec<H256>) -> Result<(), StoreError>;
/// Sets the state trie paths in need of healing
fn set_state_heal_paths(&self, paths: Vec<Nibbles>) -> Result<(), StoreError>;

/// Gets the list of account hashes whos storage needs healing
fn get_pending_storage_heal_accounts(&self) -> Result<Option<Vec<H256>>, StoreError>;
/// Gets the state trie paths in need of healing
fn get_state_heal_paths(&self) -> Result<Option<Vec<Nibbles>>, StoreError>;

/// Clears the list of account hashes whose storage needs healing
fn clear_pending_storage_heal_accounts(&self) -> Result<(), StoreError>;
/// Clears all checkpoint data created during the last snap sync
fn clear_snap_state(&self) -> Result<(), StoreError>;

fn is_synced(&self) -> Result<bool, StoreError>;

Expand Down
49 changes: 22 additions & 27 deletions crates/storage/store/engines/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ethereum_types::{H256, U256};
use ethrex_core::types::{
BlobsBundle, Block, BlockBody, BlockHash, BlockHeader, BlockNumber, ChainConfig, Index, Receipt,
};
use ethrex_trie::{InMemoryTrieDB, Trie};
use ethrex_trie::{InMemoryTrieDB, Nibbles, Trie};
use std::{
collections::HashMap,
fmt::Debug,
Expand Down Expand Up @@ -65,7 +65,9 @@ pub struct SnapState {
/// Last downloaded key of the latest State Trie
state_trie_key_checkpoint: Option<H256>,
/// Accounts which storage needs healing
pending_storage_heal_accounts: Option<Vec<H256>>,
storage_heal_paths: Option<Vec<(H256, Vec<Nibbles>)>>,
/// State trie Paths in need of healing
state_heal_paths: Option<Vec<Nibbles>>,
}

impl Store {
Expand Down Expand Up @@ -449,11 +451,6 @@ impl StoreEngine for Store {
Ok(self.inner().snap_state.header_download_checkpoint)
}

fn clear_header_download_checkpoint(&self) -> Result<(), StoreError> {
self.inner().snap_state.header_download_checkpoint = None;
Ok(())
}

fn set_state_trie_root_checkpoint(&self, current_root: H256) -> Result<(), StoreError> {
self.inner().snap_state.state_trie_root_checkpoint = Some(current_root);
Ok(())
Expand All @@ -463,11 +460,6 @@ impl StoreEngine for Store {
Ok(self.inner().snap_state.state_trie_root_checkpoint)
}

fn clear_state_trie_root_checkpoint(&self) -> Result<(), StoreError> {
self.inner().snap_state.state_trie_root_checkpoint = None;
Ok(())
}

fn set_state_trie_key_checkpoint(&self, last_key: H256) -> Result<(), StoreError> {
self.inner().snap_state.state_trie_key_checkpoint = Some(last_key);
Ok(())
Expand All @@ -477,26 +469,20 @@ impl StoreEngine for Store {
Ok(self.inner().snap_state.state_trie_key_checkpoint)
}

fn clear_state_trie_key_checkpoint(&self) -> Result<(), StoreError> {
self.inner().snap_state.state_trie_key_checkpoint = None;
Ok(())
}

fn set_pending_storage_heal_accounts(&self, accounts: Vec<H256>) -> Result<(), StoreError> {
self.inner().snap_state.pending_storage_heal_accounts = Some(accounts);
fn set_storage_heal_paths(
&self,
accounts: Vec<(H256, Vec<Nibbles>)>,
) -> Result<(), StoreError> {
self.inner().snap_state.storage_heal_paths = Some(accounts);
Ok(())
}

fn get_pending_storage_heal_accounts(&self) -> Result<Option<Vec<H256>>, StoreError> {
Ok(self
.inner()
.snap_state
.pending_storage_heal_accounts
.clone())
fn get_storage_heal_paths(&self) -> Result<Option<Vec<(H256, Vec<Nibbles>)>>, StoreError> {
Ok(self.inner().snap_state.storage_heal_paths.clone())
}

fn clear_pending_storage_heal_accounts(&self) -> Result<(), StoreError> {
self.inner().snap_state.pending_storage_heal_accounts = None;
fn clear_snap_state(&self) -> Result<(), StoreError> {
self.inner().snap_state = Default::default();
Ok(())
}

Expand All @@ -508,6 +494,15 @@ impl StoreEngine for Store {
self.inner().chain_data.is_synced = status;
Ok(())
}

fn set_state_heal_paths(&self, paths: Vec<Nibbles>) -> Result<(), StoreError> {
self.inner().snap_state.state_heal_paths = Some(paths);
Ok(())
}

fn get_state_heal_paths(&self) -> Result<Option<Vec<Nibbles>>, StoreError> {
Ok(self.inner().snap_state.state_heal_paths.clone())
}
}

impl Debug for Store {
Expand Down
67 changes: 31 additions & 36 deletions crates/storage/store/engines/libmdbx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ethrex_core::types::{
};
use ethrex_rlp::decode::RLPDecode;
use ethrex_rlp::encode::RLPEncode;
use ethrex_trie::{LibmdbxDupsortTrieDB, LibmdbxTrieDB, Trie};
use ethrex_trie::{LibmdbxDupsortTrieDB, LibmdbxTrieDB, Nibbles, Trie};
use libmdbx::orm::{Decodable, Encodable, Table};
use libmdbx::{
dupsort,
Expand Down Expand Up @@ -72,17 +72,6 @@ impl Store {
txn.get::<T>(key).map_err(StoreError::LibmdbxError)
}

// Helper method to remove a value from a libmdbx table
fn delete<T: Table>(&self, key: T::Key) -> Result<(), StoreError> {
let txn = self
.db
.begin_readwrite()
.map_err(StoreError::LibmdbxError)?;
txn.delete::<T>(key, None)
.map_err(StoreError::LibmdbxError)?;
txn.commit().map_err(StoreError::LibmdbxError)
}

fn get_block_hash_by_block_number(
&self,
number: BlockNumber,
Expand Down Expand Up @@ -540,10 +529,6 @@ impl StoreEngine for Store {
.map_err(StoreError::RLPDecode)
}

fn clear_header_download_checkpoint(&self) -> Result<(), StoreError> {
self.delete::<SnapState>(SnapStateIndex::HeaderDownloadCheckpoint)
}

fn set_state_trie_root_checkpoint(&self, current_root: H256) -> Result<(), StoreError> {
self.write::<SnapState>(
SnapStateIndex::StateTrieRootCheckpoint,
Expand All @@ -558,10 +543,6 @@ impl StoreEngine for Store {
.map_err(StoreError::RLPDecode)
}

fn clear_state_trie_root_checkpoint(&self) -> Result<(), StoreError> {
self.delete::<SnapState>(SnapStateIndex::StateTrieRootCheckpoint)
}

fn set_state_trie_key_checkpoint(&self, last_key: H256) -> Result<(), StoreError> {
self.write::<SnapState>(
SnapStateIndex::StateTrieRootCheckpoint,
Expand All @@ -576,37 +557,51 @@ impl StoreEngine for Store {
.map_err(StoreError::RLPDecode)
}

fn clear_state_trie_key_checkpoint(&self) -> Result<(), StoreError> {
self.delete::<SnapState>(SnapStateIndex::StateTrieRootCheckpoint)
}

fn set_pending_storage_heal_accounts(&self, accounts: Vec<H256>) -> Result<(), StoreError> {
self.write::<SnapState>(
SnapStateIndex::PendingStorageHealAccounts,
accounts.encode_to_vec(),
)
fn set_storage_heal_paths(
&self,
accounts: Vec<(H256, Vec<Nibbles>)>,
) -> Result<(), StoreError> {
self.write::<SnapState>(SnapStateIndex::StorageHealPaths, accounts.encode_to_vec())
}

fn get_pending_storage_heal_accounts(&self) -> Result<Option<Vec<H256>>, StoreError> {
self.read::<SnapState>(SnapStateIndex::PendingStorageHealAccounts)?
.map(|ref h| <Vec<H256>>::decode(h))
fn get_storage_heal_paths(&self) -> Result<Option<Vec<(H256, Vec<Nibbles>)>>, StoreError> {
self.read::<SnapState>(SnapStateIndex::StorageHealPaths)?
.map(|ref h| <Vec<(H256, Vec<Nibbles>)>>::decode(h))
.transpose()
.map_err(StoreError::RLPDecode)
}

fn clear_pending_storage_heal_accounts(&self) -> Result<(), StoreError> {
self.delete::<SnapState>(SnapStateIndex::PendingStorageHealAccounts)
}

fn is_synced(&self) -> Result<bool, StoreError> {
match self.read::<ChainData>(ChainDataIndex::IsSynced)? {
None => Err(StoreError::Custom("Sync status not found".to_string())),
Some(ref rlp) => RLPDecode::decode(rlp).map_err(|_| StoreError::DecodeError),
}
}

fn update_sync_status(&self, status: bool) -> Result<(), StoreError> {
self.write::<ChainData>(ChainDataIndex::IsSynced, status.encode_to_vec())
}

fn set_state_heal_paths(&self, paths: Vec<Nibbles>) -> Result<(), StoreError> {
self.write::<SnapState>(SnapStateIndex::StateHealPaths, paths.encode_to_vec())
}

fn get_state_heal_paths(&self) -> Result<Option<Vec<Nibbles>>, StoreError> {
self.read::<SnapState>(SnapStateIndex::StateHealPaths)?
.map(|ref h| <Vec<Nibbles>>::decode(h))
.transpose()
.map_err(StoreError::RLPDecode)
}

fn clear_snap_state(&self) -> Result<(), StoreError> {
let txn = self
.db
.begin_readwrite()
.map_err(StoreError::LibmdbxError)?;
txn.clear_table::<SnapState>()
.map_err(StoreError::LibmdbxError)?;
txn.commit().map_err(StoreError::LibmdbxError)
}
}

impl Debug for Store {
Expand Down
Loading