From 368a2c4bcaa731a68bf0c0c536508365908d66b8 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:36:55 -0500 Subject: [PATCH 1/2] feat: add cancun mainnet timestamp --- crates/primitives/src/chain/spec.rs | 68 +++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/crates/primitives/src/chain/spec.rs b/crates/primitives/src/chain/spec.rs index 35e7d2bb99ca..00de8ea72cbb 100644 --- a/crates/primitives/src/chain/spec.rs +++ b/crates/primitives/src/chain/spec.rs @@ -57,6 +57,7 @@ pub static MAINNET: Lazy> = Lazy::new(|| { }, ), (Hardfork::Shanghai, ForkCondition::Timestamp(1681338455)), + (Hardfork::Cancun, ForkCondition::Timestamp(1710338135)), ]), // https://etherscan.io/tx/0xe75fb554e433e03763a1560646ee22dcb74e5274b34c5ad644e7c0f619a7e1d0 deposit_contract: Some(DepositContract::new( @@ -1177,6 +1178,12 @@ impl ChainSpecBuilder { self } + /// Remove the given fork from the spec. + pub fn without_fork(mut self, fork: Hardfork) -> Self { + self.hardforks.remove(&fork); + self + } + /// Enable the Paris hardfork at the given TTD. /// /// Does not set the merge netsplit block. @@ -1682,6 +1689,7 @@ Merge hard forks: Post-merge hard forks (timestamp based): - Shanghai @1681338455 +- Cancun @1710338135 " ); } @@ -1735,8 +1743,8 @@ Post-merge hard forks (timestamp based): assert!(spec.fork_timestamps.shanghai.is_some()); } - // 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 mainnet: shanghai, cancun + ensure_timestamp_fork_conditions(&MAINNET, 2); // currently there are 2 timestamp forks known for sepolia: shanghai, cancun ensure_timestamp_fork_conditions(&SEPOLIA, 2); @@ -1958,7 +1966,11 @@ Post-merge hard forks (timestamp based): Hardfork::GrayGlacier, ForkId { hash: ForkHash([0xf0, 0xaf, 0xd0, 0xe3]), next: 1681338455 }, ), - (Hardfork::Shanghai, ForkId { hash: ForkHash([0xdc, 0xe9, 0x6c, 0x2d]), next: 0 }), + ( + Hardfork::Shanghai, + ForkId { hash: ForkHash([0xdc, 0xe9, 0x6c, 0x2d]), next: 1710338135 }, + ), + (Hardfork::Cancun, ForkId { hash: ForkHash([0x9f, 0x3d, 0x22, 0x54]), next: 0 }), ], ); } @@ -2135,12 +2147,17 @@ Post-merge hard forks (timestamp based): // First Shanghai block ( Head { number: 20000000, timestamp: 1681338455, ..Default::default() }, - ForkId { hash: ForkHash([0xdc, 0xe9, 0x6c, 0x2d]), next: 0 }, + ForkId { hash: ForkHash([0xdc, 0xe9, 0x6c, 0x2d]), next: 1710338135 }, ), - // Future Shanghai block + // First Cancun block + ( + Head { number: 20000001, timestamp: 1710338135, ..Default::default() }, + ForkId { hash: ForkHash([0x9f, 0x3d, 0x22, 0x54]), next: 0 }, + ), + // Future Cancun block ( - Head { number: 20000000, timestamp: 2000000000, ..Default::default() }, - ForkId { hash: ForkHash([0xdc, 0xe9, 0x6c, 0x2d]), next: 0 }, + Head { number: 20000002, timestamp: 2000000000, ..Default::default() }, + ForkId { hash: ForkHash([0x9f, 0x3d, 0x22, 0x54]), next: 0 }, ), ], ); @@ -2361,11 +2378,9 @@ Post-merge hard forks (timestamp based): /// This is based off of the test vectors here: https://github.com/ethereum/go-ethereum/blob/5c8cc10d1e05c23ff1108022f4150749e73c0ca1/core/forkid/forkid_test.go#L155-L188 #[test] fn timestamped_forks() { - let mainnet_with_shanghai = ChainSpecBuilder::mainnet() - .with_fork(Hardfork::Shanghai, ForkCondition::Timestamp(1668000000)) - .build(); + let mainnet_with_timestamps = ChainSpecBuilder::mainnet().build(); test_fork_ids( - &mainnet_with_shanghai, + &mainnet_with_timestamps, &[ ( Head { number: 0, timestamp: 0, ..Default::default() }, @@ -2465,20 +2480,28 @@ Post-merge hard forks (timestamp based): ), // Last Arrow Glacier block ( Head { number: 15050000, timestamp: 0, ..Default::default() }, - ForkId { hash: ForkHash([0xf0, 0xaf, 0xd0, 0xe3]), next: 1668000000 }, + ForkId { hash: ForkHash([0xf0, 0xaf, 0xd0, 0xe3]), next: 1681338455 }, ), // First Gray Glacier block ( Head { number: 19999999, timestamp: 1667999999, ..Default::default() }, - ForkId { hash: ForkHash([0xf0, 0xaf, 0xd0, 0xe3]), next: 1668000000 }, + ForkId { hash: ForkHash([0xf0, 0xaf, 0xd0, 0xe3]), next: 1681338455 }, ), // Last Gray Glacier block ( - Head { number: 20000000, timestamp: 1668000000, ..Default::default() }, - ForkId { hash: ForkHash([0x71, 0x14, 0x76, 0x44]), next: 0 }, - ), // First Shanghai block + Head { number: 20000000, timestamp: 1681338455, ..Default::default() }, + ForkId { hash: ForkHash([0xdc, 0xe9, 0x6c, 0x2d]), next: 1710338135 }, + ), // Last Shanghai block + ( + Head { number: 20000001, timestamp: 1710338134, ..Default::default() }, + ForkId { hash: ForkHash([0xdc, 0xe9, 0x6c, 0x2d]), next: 1710338135 }, + ), // First Cancun block + ( + Head { number: 20000002, timestamp: 1710338135, ..Default::default() }, + ForkId { hash: ForkHash([0x9f, 0x3d, 0x22, 0x54]), next: 0 }, + ), // Future Cancun block ( - Head { number: 20000000, timestamp: 2668000000, ..Default::default() }, - ForkId { hash: ForkHash([0x71, 0x14, 0x76, 0x44]), next: 0 }, - ), // Future Shanghai block + Head { number: 20000003, timestamp: 2000000000, ..Default::default() }, + ForkId { hash: ForkHash([0x9f, 0x3d, 0x22, 0x54]), next: 0 }, + ), ], ); } @@ -2579,6 +2602,7 @@ Post-merge hard forks (timestamp based): "arrowGlacierBlock": 0, "grayGlacierBlock": 0, "shanghaiTime": 0, + "cancunTime": 1, "terminalTotalDifficulty": 0, "terminalTotalDifficultyPassed": true, "ethash": {} @@ -2674,6 +2698,12 @@ Post-merge hard forks (timestamp based): &ForkCondition::Timestamp(0) ); + // including time based hardforks + assert_eq!( + chainspec.hardforks.get(&Hardfork::Cancun).unwrap(), + &ForkCondition::Timestamp(1) + ); + // alloc key -> expected rlp mapping let key_rlp = vec![ (hex!("658bdf435d810c91414ec09147daa6db62406379"), &hex!("f84d8089487a9a304539440000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")[..]), From c1e576ca5220d763bde10aacfbc0698a236b140c Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:52:11 -0500 Subject: [PATCH 2/2] add cancun to fork_timestamps --- crates/primitives/src/chain/spec.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/primitives/src/chain/spec.rs b/crates/primitives/src/chain/spec.rs index 00de8ea72cbb..9706312c1d3c 100644 --- a/crates/primitives/src/chain/spec.rs +++ b/crates/primitives/src/chain/spec.rs @@ -33,7 +33,7 @@ pub static MAINNET: Lazy> = Lazy::new(|| { 15537394, U256::from(58_750_003_716_598_352_816_469u128), )), - fork_timestamps: ForkTimestamps::default().shanghai(1681338455), + fork_timestamps: ForkTimestamps::default().shanghai(1681338455).cancun(1710338135), hardforks: BTreeMap::from([ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(1150000)), @@ -83,7 +83,7 @@ pub static GOERLI: Lazy> = Lazy::new(|| { )), // paris_block_and_final_difficulty: Some((7382818, U256::from(10_790_000))), - fork_timestamps: ForkTimestamps::default().shanghai(1678832736), + fork_timestamps: ForkTimestamps::default().shanghai(1678832736).cancun(1705473120), hardforks: BTreeMap::from([ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)), @@ -127,7 +127,7 @@ pub static SEPOLIA: Lazy> = Lazy::new(|| { )), // paris_block_and_final_difficulty: Some((1450409, U256::from(17_000_018_015_853_232u128))), - fork_timestamps: ForkTimestamps::default().shanghai(1677557088), + fork_timestamps: ForkTimestamps::default().shanghai(1677557088).cancun(1706655072), hardforks: BTreeMap::from([ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)), @@ -174,7 +174,7 @@ pub static HOLESKY: Lazy> = Lazy::new(|| { "b5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4" )), paris_block_and_final_difficulty: Some((0, U256::from(1))), - fork_timestamps: ForkTimestamps::default().shanghai(1696000704), + fork_timestamps: ForkTimestamps::default().shanghai(1696000704).cancun(1707305664), hardforks: BTreeMap::from([ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)),