|
|
|
|
@ -1,11 +1,9 @@
|
|
|
|
|
use super::StageId;
|
|
|
|
|
use alloc::vec::Vec;
|
|
|
|
|
use alloy_primitives::{Address, BlockNumber, B256};
|
|
|
|
|
use bytes::Buf;
|
|
|
|
|
use reth_codecs::{add_arbitrary_tests, Compact};
|
|
|
|
|
use core::ops::RangeInclusive;
|
|
|
|
|
use reth_trie_common::{hash_builder::HashBuilderState, StoredSubNode};
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use std::ops::RangeInclusive;
|
|
|
|
|
|
|
|
|
|
use super::StageId;
|
|
|
|
|
|
|
|
|
|
/// Saves the progress of Merkle stage.
|
|
|
|
|
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
@ -32,7 +30,8 @@ impl MerkleCheckpoint {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Compact for MerkleCheckpoint {
|
|
|
|
|
#[cfg(any(test, feature = "reth-codec"))]
|
|
|
|
|
impl reth_codecs::Compact for MerkleCheckpoint {
|
|
|
|
|
fn to_compact<B>(&self, buf: &mut B) -> usize
|
|
|
|
|
where
|
|
|
|
|
B: bytes::BufMut + AsMut<[u8]>,
|
|
|
|
|
@ -56,6 +55,7 @@ impl Compact for MerkleCheckpoint {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn from_compact(mut buf: &[u8], _len: usize) -> (Self, &[u8]) {
|
|
|
|
|
use bytes::Buf;
|
|
|
|
|
let target_block = buf.get_u64();
|
|
|
|
|
|
|
|
|
|
let last_account_key = B256::from_slice(&buf[..32]);
|
|
|
|
|
@ -75,9 +75,10 @@ impl Compact for MerkleCheckpoint {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Saves the progress of AccountHashing stage.
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Compact)]
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
|
|
|
|
#[add_arbitrary_tests(compact)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
|
|
|
|
pub struct AccountHashingCheckpoint {
|
|
|
|
|
/// The next account to start hashing from.
|
|
|
|
|
pub address: Option<Address>,
|
|
|
|
|
@ -88,9 +89,10 @@ pub struct AccountHashingCheckpoint {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Saves the progress of StorageHashing stage.
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Compact)]
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
|
|
|
|
#[add_arbitrary_tests(compact)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
|
|
|
|
pub struct StorageHashingCheckpoint {
|
|
|
|
|
/// The next account to start hashing from.
|
|
|
|
|
pub address: Option<Address>,
|
|
|
|
|
@ -103,9 +105,10 @@ pub struct StorageHashingCheckpoint {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Saves the progress of Execution stage.
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Compact)]
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
|
|
|
|
#[add_arbitrary_tests(compact)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
|
|
|
|
pub struct ExecutionCheckpoint {
|
|
|
|
|
/// Block range which this checkpoint is valid for.
|
|
|
|
|
pub block_range: CheckpointBlockRange,
|
|
|
|
|
@ -114,9 +117,10 @@ pub struct ExecutionCheckpoint {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Saves the progress of Headers stage.
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Compact)]
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
|
|
|
|
#[add_arbitrary_tests(compact)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
|
|
|
|
pub struct HeadersCheckpoint {
|
|
|
|
|
/// Block range which this checkpoint is valid for.
|
|
|
|
|
pub block_range: CheckpointBlockRange,
|
|
|
|
|
@ -125,9 +129,10 @@ pub struct HeadersCheckpoint {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Saves the progress of Index History stages.
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Compact)]
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
|
|
|
|
#[add_arbitrary_tests(compact)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
|
|
|
|
pub struct IndexHistoryCheckpoint {
|
|
|
|
|
/// Block range which this checkpoint is valid for.
|
|
|
|
|
pub block_range: CheckpointBlockRange,
|
|
|
|
|
@ -136,9 +141,10 @@ pub struct IndexHistoryCheckpoint {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Saves the progress of abstract stage iterating over or downloading entities.
|
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Compact)]
|
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
|
|
|
|
#[add_arbitrary_tests(compact)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
|
|
|
|
pub struct EntitiesCheckpoint {
|
|
|
|
|
/// Number of entities already processed.
|
|
|
|
|
pub processed: u64,
|
|
|
|
|
@ -165,9 +171,10 @@ impl EntitiesCheckpoint {
|
|
|
|
|
|
|
|
|
|
/// Saves the block range. Usually, it's used to check the validity of some stage checkpoint across
|
|
|
|
|
/// multiple executions.
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Compact)]
|
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
|
|
|
|
#[add_arbitrary_tests(compact)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
|
|
|
|
pub struct CheckpointBlockRange {
|
|
|
|
|
/// The first block of the range, inclusive.
|
|
|
|
|
pub from: BlockNumber,
|
|
|
|
|
@ -188,9 +195,10 @@ impl From<&RangeInclusive<BlockNumber>> for CheckpointBlockRange {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Saves the progress of a stage.
|
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Compact)]
|
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
|
|
|
|
#[add_arbitrary_tests(compact)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
|
|
|
|
pub struct StageCheckpoint {
|
|
|
|
|
/// The maximum block processed by the stage.
|
|
|
|
|
pub block_number: BlockNumber,
|
|
|
|
|
@ -255,9 +263,10 @@ impl StageCheckpoint {
|
|
|
|
|
// TODO(alexey): add a merkle checkpoint. Currently it's hard because [`MerkleCheckpoint`]
|
|
|
|
|
// is not a Copy type.
|
|
|
|
|
/// Stage-specific checkpoint metrics.
|
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Compact)]
|
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
|
|
|
|
#[add_arbitrary_tests(compact)]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
|
|
|
|
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
|
|
|
|
pub enum StageUnitCheckpoint {
|
|
|
|
|
/// Saves the progress of AccountHashing stage.
|
|
|
|
|
Account(AccountHashingCheckpoint),
|
|
|
|
|
@ -386,6 +395,7 @@ stage_unit_checkpoints!(
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
use rand::Rng;
|
|
|
|
|
use reth_codecs::Compact;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn merkle_checkpoint_roundtrip() {
|
|
|
|
|
|