Skip to content

Commit

Permalink
feat: use DepositContract on ChainSpec (#4041)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
joshieDo and mattsse authored Aug 3, 2023
1 parent ce6e247 commit 704c098
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
5 changes: 4 additions & 1 deletion bin/reth/src/args/pruning_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ impl PruningArgs {
parts: PruneModes {
sender_recovery: Some(PruneMode::Distance(128)),
transaction_lookup: None,
receipts: chain_spec.deposit_contract_deployment_block.map(PruneMode::Before),
receipts: chain_spec
.deposit_contract
.as_ref()
.map(|contract| PruneMode::Before(contract.block)),
account_history: Some(PruneMode::Distance(128)),
storage_history: Some(PruneMode::Distance(128)),
},
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ mod tests {
fork_timestamps: ForkTimestamps::default(),
genesis_hash: None,
paris_block_and_final_difficulty: None,
deposit_contract_deployment_block: None,
deposit_contract: None,
});

let db = create_test_rw_db();
Expand Down
49 changes: 39 additions & 10 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{
forkid::ForkFilterKey,
header::Head,
proofs::genesis_state_root,
BlockNumber, Chain, ForkFilter, ForkHash, ForkId, Genesis, Hardfork, Header, SealedHeader,
H256, U256,
Address, BlockNumber, Chain, ForkFilter, ForkHash, ForkId, Genesis, Hardfork, Header,
SealedHeader, H160, H256, U256,
};
use hex_literal::hex;
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -55,7 +55,11 @@ pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
(Hardfork::Shanghai, ForkCondition::Timestamp(1681338455)),
]),
// https://etherscan.io/tx/0xe75fb554e433e03763a1560646ee22dcb74e5274b34c5ad644e7c0f619a7e1d0
deposit_contract_deployment_block: Some(11052984),
deposit_contract: Some(DepositContract::new(
H160(hex!("00000000219ab540356cbb839cbe05303d7705fa")),
11052984,
H256(hex!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5")),
)),
}
.into()
});
Expand Down Expand Up @@ -91,7 +95,11 @@ pub static GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
(Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)),
]),
// https://goerli.etherscan.io/tx/0xa3c07dc59bfdb1bfc2d50920fed2ef2c1c4e0a09fe2325dbc14e07702f965a78
deposit_contract_deployment_block: Some(4367322),
deposit_contract: Some(DepositContract::new(
H160(hex!("ff50ed3d0ec03ac01d4c79aad74928bff48a7b2b")),
4367322,
H256(hex!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5")),
)),
}
.into()
});
Expand Down Expand Up @@ -131,7 +139,11 @@ pub static SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
(Hardfork::Shanghai, ForkCondition::Timestamp(1677557088)),
]),
// https://sepolia.etherscan.io/tx/0x025ecbf81a2f1220da6285d1701dc89fb5a956b62562ee922e1a9efd73eb4b14
deposit_contract_deployment_block: Some(1273020),
deposit_contract: Some(DepositContract::new(
H160(hex!("7f02c3e3c98b133055b8b348b2ac625669ed295d")),
1273020,
H256(hex!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5")),
)),
}
.into()
});
Expand Down Expand Up @@ -169,7 +181,7 @@ pub static DEV: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
),
(Hardfork::Shanghai, ForkCondition::Timestamp(0)),
]),
deposit_contract_deployment_block: Some(0),
deposit_contract: None, // TODO: do we even have?
}
.into()
});
Expand Down Expand Up @@ -209,9 +221,9 @@ pub struct ChainSpec {
/// The active hard forks and their activation conditions
pub hardforks: BTreeMap<Hardfork, ForkCondition>,

/// The block at which the deposit contract for PoS was deployed.
/// The deposit contract deployed for PoS.
#[serde(skip, default)]
pub deposit_contract_deployment_block: Option<BlockNumber>,
pub deposit_contract: Option<DepositContract>,
}

impl ChainSpec {
Expand Down Expand Up @@ -444,7 +456,7 @@ impl From<Genesis> for ChainSpec {
fork_timestamps: ForkTimestamps::from_hardforks(&hardforks),
hardforks,
paris_block_and_final_difficulty: None,
deposit_contract_deployment_block: None,
deposit_contract: None,
}
}
}
Expand Down Expand Up @@ -667,7 +679,7 @@ impl ChainSpecBuilder {
fork_timestamps: ForkTimestamps::from_hardforks(&self.hardforks),
hardforks: self.hardforks,
paris_block_and_final_difficulty: None,
deposit_contract_deployment_block: None,
deposit_contract: None,
}
}
}
Expand Down Expand Up @@ -960,6 +972,23 @@ where
}
}

/// PoS deposit contract details.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DepositContract {
/// Deposit Contract Address
pub address: Address,
/// Deployment Block
pub block: BlockNumber,
/// `DepositEvent` event signature
pub topic: H256,
}

impl DepositContract {
fn new(address: Address, block: BlockNumber, topic: H256) -> Self {
DepositContract { address, block, topic }
}
}

#[cfg(test)]
mod tests {
use crate::{
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives/src/hardfork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mod tests {
hardforks: BTreeMap::from([(Hardfork::Frontier, ForkCondition::Never)]),
fork_timestamps: Default::default(),
paris_block_and_final_difficulty: None,
deposit_contract_deployment_block: None,
deposit_contract: None,
};

assert_eq!(Hardfork::Frontier.fork_id(&spec), None);
Expand All @@ -179,7 +179,7 @@ mod tests {
hardforks: BTreeMap::from([(Hardfork::Shanghai, ForkCondition::Never)]),
fork_timestamps: Default::default(),
paris_block_and_final_difficulty: None,
deposit_contract_deployment_block: None,
deposit_contract: None,
};

assert_eq!(Hardfork::Shanghai.fork_filter(&spec), None);
Expand Down
2 changes: 1 addition & 1 deletion crates/prune/src/pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ mod tests {
},
};
use reth_primitives::{
Address, BlockNumber, PruneCheckpoint, PruneMode, PruneModes, PrunePart, H256, MAINNET,
BlockNumber, PruneCheckpoint, PruneMode, PruneModes, PrunePart, H256, MAINNET,
};
use reth_provider::PruneCheckpointReader;
use reth_stages::test_utils::TestTransaction;
Expand Down

0 comments on commit 704c098

Please sign in to comment.