From 2aca34470f56e55e431771a185be71054feb1da9 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 21 Dec 2023 10:36:28 -0500 Subject: [PATCH 1/3] feat: add goerli cancun time --- crates/primitives/src/chain/spec.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/primitives/src/chain/spec.rs b/crates/primitives/src/chain/spec.rs index 7fe1d4ff7881..fc5ac8f4563b 100644 --- a/crates/primitives/src/chain/spec.rs +++ b/crates/primitives/src/chain/spec.rs @@ -97,6 +97,7 @@ pub static GOERLI: Lazy> = Lazy::new(|| { ForkCondition::TTD { fork_block: None, total_difficulty: U256::from(10_790_000) }, ), (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), + (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), ]), // https://goerli.etherscan.io/tx/0xa3c07dc59bfdb1bfc2d50920fed2ef2c1c4e0a09fe2325dbc14e07702f965a78 deposit_contract: Some(DepositContract::new( @@ -1922,7 +1923,12 @@ Post-merge hard forks (timestamp based): Hardfork::London, ForkId { hash: ForkHash([0xb8, 0xc6, 0x29, 0x9d]), next: 1678832736 }, ), - (Hardfork::Shanghai, ForkId { hash: ForkHash([0xf9, 0x84, 0x3a, 0xbf]), next: 0 }), + ( + Hardfork::Shanghai, + ForkId { hash: ForkHash([0xf9, 0x84, 0x3a, 0xbf]), next: 1705473120 }, + ), + // Future Cancun block + (Hardfork::Cancun, ForkId { hash: ForkHash([0x70, 0xcc, 0x14, 0xe2]), next: 0 }), ], ); } @@ -2088,12 +2094,17 @@ Post-merge hard forks (timestamp based): // First Shanghai block ( Head { number: 6000001, timestamp: 1678832736, ..Default::default() }, - ForkId { hash: ForkHash([0xf9, 0x84, 0x3a, 0xbf]), next: 0 }, + ForkId { hash: ForkHash([0xf9, 0x84, 0x3a, 0xbf]), next: 1705473120 }, ), // Future Shanghai block ( Head { number: 6500000, timestamp: 1678832736, ..Default::default() }, - ForkId { hash: ForkHash([0xf9, 0x84, 0x3a, 0xbf]), next: 0 }, + ForkId { hash: ForkHash([0xf9, 0x84, 0x3a, 0xbf]), next: 1705473120 }, + ), + // Future Cancun block + ( + Head { number: 6500001, timestamp: 1705473120, ..Default::default() }, + ForkId { hash: ForkHash([0x70, 0xcc, 0x14, 0xe2]), next: 0 }, ), ], ); From 67aed540425ada3f283fc0d2e6d899e74f4ea9f7 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 21 Dec 2023 10:44:14 -0500 Subject: [PATCH 2/3] add another test vector from geth --- crates/primitives/src/chain/spec.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/primitives/src/chain/spec.rs b/crates/primitives/src/chain/spec.rs index fc5ac8f4563b..2cb5140da556 100644 --- a/crates/primitives/src/chain/spec.rs +++ b/crates/primitives/src/chain/spec.rs @@ -1927,7 +1927,6 @@ Post-merge hard forks (timestamp based): Hardfork::Shanghai, ForkId { hash: ForkHash([0xf9, 0x84, 0x3a, 0xbf]), next: 1705473120 }, ), - // Future Cancun block (Hardfork::Cancun, ForkId { hash: ForkHash([0x70, 0xcc, 0x14, 0xe2]), next: 0 }), ], ); @@ -2098,12 +2097,17 @@ Post-merge hard forks (timestamp based): ), // Future Shanghai block ( - Head { number: 6500000, timestamp: 1678832736, ..Default::default() }, + Head { number: 6500002, timestamp: 1678832736, ..Default::default() }, ForkId { hash: ForkHash([0xf9, 0x84, 0x3a, 0xbf]), next: 1705473120 }, ), + // First Cancun block + ( + Head { number: 6500003, timestamp: 1705473120, ..Default::default() }, + ForkId { hash: ForkHash([0x70, 0xcc, 0x14, 0xe2]), next: 0 }, + ), // Future Cancun block ( - Head { number: 6500001, timestamp: 1705473120, ..Default::default() }, + Head { number: 6500003, timestamp: 2705473120, ..Default::default() }, ForkId { hash: ForkHash([0x70, 0xcc, 0x14, 0xe2]), next: 0 }, ), ], From a73d1b49b365d98fb48d8bb8c044b4bbae0537dc Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:01:05 -0500 Subject: [PATCH 3/3] add holesky, sepolia cancun fork times and tests --- crates/primitives/src/chain/spec.rs | 71 +++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/crates/primitives/src/chain/spec.rs b/crates/primitives/src/chain/spec.rs index 2cb5140da556..4717dc5f3eba 100644 --- a/crates/primitives/src/chain/spec.rs +++ b/crates/primitives/src/chain/spec.rs @@ -145,6 +145,7 @@ pub static SEPOLIA: Lazy> = Lazy::new(|| { }, ), (Hardfork::Shanghai, ForkCondition::Timestamp(1677557088)), + (Hardfork::Cancun, ForkCondition::Timestamp(1706655072)), ]), // https://sepolia.etherscan.io/tx/0x025ecbf81a2f1220da6285d1701dc89fb5a956b62562ee922e1a9efd73eb4b14 deposit_contract: Some(DepositContract::new( @@ -188,6 +189,7 @@ pub static HOLESKY: Lazy> = Lazy::new(|| { ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::ZERO }, ), (Hardfork::Shanghai, ForkCondition::Timestamp(1696000704)), + (Hardfork::Cancun, ForkCondition::Timestamp(1707305664)), ]), deposit_contract: Some(DepositContract::new( address!("4242424242424242424242424242424242424242"), @@ -1636,14 +1638,12 @@ Post-merge hard forks (timestamp based): // Tests that all predefined timestamps are correctly set up in the chainspecs #[test] fn test_predefined_chain_spec_fork_timestamps() { - fn ensure_timestamp_fork_conditions(spec: &ChainSpec) { + fn ensure_timestamp_fork_conditions(spec: &ChainSpec, known_timestamp_based_forks: usize) { // This is a sanity test that ensures we always set all currently known fork timestamps, // this will fail if a new timestamp based fork condition has added to the hardforks but // no corresponding entry in the ForkTimestamp types, See also // [ForkTimestamps::from_hardforks] - // currently there are only 1 timestamps known: shanghai - let known_timestamp_based_forks = 1; let num_timestamp_based_forks = spec.hardforks.values().copied().filter(ForkCondition::is_timestamp).count(); assert_eq!(num_timestamp_based_forks, known_timestamp_based_forks); @@ -1652,9 +1652,11 @@ Post-merge hard forks (timestamp based): assert!(spec.fork_timestamps.shanghai.is_some()); } - for spec in [&*MAINNET, &*SEPOLIA] { - ensure_timestamp_fork_conditions(spec); - } + // currently there is only 1 timestamp fork known for mainnet: shanghai + ensure_timestamp_fork_conditions(&MAINNET, 1); + + // currently there are 2 timestamp forks known for sepolia: shanghai, cancun + ensure_timestamp_fork_conditions(&SEPOLIA, 2); } // Tests that we skip any fork blocks in block #0 (the genesis ruleset) @@ -1981,7 +1983,11 @@ Post-merge hard forks (timestamp based): Hardfork::Paris, ForkId { hash: ForkHash([0xb9, 0x6c, 0xbd, 0x13]), next: 1677557088 }, ), - (Hardfork::Shanghai, ForkId { hash: ForkHash([0xf7, 0xf9, 0xbc, 0x08]), next: 0 }), + ( + Hardfork::Shanghai, + ForkId { hash: ForkHash([0xf7, 0xf9, 0xbc, 0x08]), next: 1706655072 }, + ), + (Hardfork::Cancun, ForkId { hash: ForkHash([0x88, 0xcf, 0x81, 0xd9]), next: 0 }), ], ); } @@ -2057,6 +2063,44 @@ Post-merge hard forks (timestamp based): ); } + #[test] + fn holesky_forkids() { + test_fork_ids( + &HOLESKY, + &[ + ( + Head { number: 0, ..Default::default() }, + ForkId { hash: ForkHash([0xc6, 0x1a, 0x60, 0x98]), next: 1696000704 }, + ), + // First MergeNetsplit block + ( + Head { number: 123, ..Default::default() }, + ForkId { hash: ForkHash([0xc6, 0x1a, 0x60, 0x98]), next: 1696000704 }, + ), + // Last MergeNetsplit block + ( + Head { number: 123, timestamp: 1696000703, ..Default::default() }, + ForkId { hash: ForkHash([0xc6, 0x1a, 0x60, 0x98]), next: 1696000704 }, + ), + // First Shanghai block + ( + Head { number: 123, timestamp: 1696000704, ..Default::default() }, + ForkId { hash: ForkHash([0xfd, 0x4f, 0x01, 0x6b]), next: 1707305664 }, + ), + // Last Shanghai block + ( + Head { number: 123, timestamp: 1707305663, ..Default::default() }, + ForkId { hash: ForkHash([0xfd, 0x4f, 0x01, 0x6b]), next: 1707305664 }, + ), + // First Cancun block + ( + Head { number: 123, timestamp: 1707305664, ..Default::default() }, + ForkId { hash: ForkHash([0x9b, 0x19, 0x2a, 0xd0]), next: 0 }, + ), + ], + ) + } + #[test] fn goerli_forkids() { test_fork_ids( @@ -2135,9 +2179,20 @@ Post-merge hard forks (timestamp based): Head { number: 1735372, timestamp: 1677557087, ..Default::default() }, ForkId { hash: ForkHash([0xb9, 0x6c, 0xbd, 0x13]), next: 1677557088 }, ), + // First Shanghai block ( Head { number: 1735372, timestamp: 1677557088, ..Default::default() }, - ForkId { hash: ForkHash([0xf7, 0xf9, 0xbc, 0x08]), next: 0 }, + ForkId { hash: ForkHash([0xf7, 0xf9, 0xbc, 0x08]), next: 1706655072 }, + ), + // Last Shanghai block + ( + Head { number: 1735372, timestamp: 1706655071, ..Default::default() }, + ForkId { hash: ForkHash([0xf7, 0xf9, 0xbc, 0x08]), next: 1706655072 }, + ), + // First Cancun block + ( + Head { number: 1735372, timestamp: 1706655072, ..Default::default() }, + ForkId { hash: ForkHash([0x88, 0xcf, 0x81, 0xd9]), next: 0 }, ), ], );