From 679a0c9ec256572509bf0fe5db0ecf0a12b7508c Mon Sep 17 00:00:00 2001 From: terence Date: Thu, 10 Apr 2025 19:01:35 -0700 Subject: [PATCH] Add support for electra fork epoch (#15132) * Add support for electra fork epoch * Fix tests * fixing tests without needing to override electra fork config * reverting electra fork override on blob test too, replacing with custom timefetcher * reverting old changelog * Fix genesis time * Move mainnet test into mainnet_config_test.go * Update spec test to v1.5.0-beta.5 --------- Co-authored-by: james-prysm Co-authored-by: Preston Van Loon --- WORKSPACE | 26 +++++++++++--- .../rpc/eth/beacon/handlers_pool_test.go | 7 ++-- beacon-chain/rpc/eth/blob/handlers_test.go | 1 + changelog/tt_8.md | 3 ++ config/params/BUILD.bazel | 2 ++ config/params/loader_test.go | 2 ++ config/params/mainnet_config.go | 2 +- config/params/mainnet_config_export_test.go | 6 ++++ config/params/mainnet_config_test.go | 34 +++++++++++++++---- 9 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 changelog/tt_8.md create mode 100644 config/params/mainnet_config_export_test.go diff --git a/WORKSPACE b/WORKSPACE index 53797606eb..9cea5d7e44 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -255,7 +255,7 @@ filegroup( url = "https://github.com/ethereum/EIPs/archive/5480440fe51742ed23342b68cf106cefd427e39d.tar.gz", ) -consensus_spec_version = "v1.5.0-beta.4" +consensus_spec_version = "v1.5.0-beta.5" bls_test_version = "v0.1.1" @@ -271,7 +271,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - integrity = "sha256-QG0NUqaCvP5lKaKKwF/fmeICZVjONMlb7EE+MtYl0C0=", + integrity = "sha256-H+Pt4z+HCVDnEBAv814yvsjR7f5l1IpumjFoTj2XnLE=", url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/general.tar.gz" % consensus_spec_version, ) @@ -287,7 +287,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - integrity = "sha256-8NQngTSSqzW/j3tOUi3r5h+94ChRbLNWTt7BOGqr4+E=", + integrity = "sha256-Dqiwf5BG7yYyURGf+i87AIdArAyztvcgjoi2kSxrGvo=", url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/minimal.tar.gz" % consensus_spec_version, ) @@ -303,7 +303,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - integrity = "sha256-gFqxbaBnJ7dtdoj0zFbVrtlHv/bLNuWjrTHkyCAjFjI=", + integrity = "sha256-xrmsFF243pzXHAjh1EQYKS9gtcwmtHK3wRZDSLlVVRk=", url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/mainnet.tar.gz" % consensus_spec_version, ) @@ -318,7 +318,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - integrity = "sha256-9paalF0POULpP2ga+4ouHSETKYrWNCUCZoJHPuFw06E=", + integrity = "sha256-c+gGapqifCvFtmtxfhOwieBDO2Syxp13GECWEpWM/Ho=", strip_prefix = "consensus-specs-" + consensus_spec_version[1:], url = "https://github.com/ethereum/consensus-specs/archive/refs/tags/%s.tar.gz" % consensus_spec_version, ) @@ -370,6 +370,22 @@ filegroup( url = "https://github.com/eth-clients/holesky/archive/32a72e21c6e53c262f27d50dd540cb654517d03a.tar.gz", # 2025-03-17 ) +http_archive( + name = "mainnet", + build_file_content = """ +filegroup( + name = "configs", + srcs = [ + "metadata/config.yaml", + ], + visibility = ["//visibility:public"], +) +""", + integrity = "sha256-NZr/gsQK9rBHRnznlPBiNzJpK8MPMrfUa3f+QYqn1+g=", + strip_prefix = "mainnet-978f1794eada6f85bee76e4d2d5959a5fb8e0cc5", + url = "https://github.com/eth-clients/mainnet/archive/978f1794eada6f85bee76e4d2d5959a5fb8e0cc5.tar.gz", +) + http_archive( name = "sepolia_testnet", build_file_content = """ diff --git a/beacon-chain/rpc/eth/beacon/handlers_pool_test.go b/beacon-chain/rpc/eth/beacon/handlers_pool_test.go index 7fabcf54da..3a278c0e1f 100644 --- a/beacon-chain/rpc/eth/beacon/handlers_pool_test.go +++ b/beacon-chain/rpc/eth/beacon/handlers_pool_test.go @@ -211,8 +211,8 @@ func TestListAttestations(t *testing.T) { t.Run("Pre-Electra", func(t *testing.T) { bs, err := util.NewBeaconState() require.NoError(t, err) - - chainService := &blockchainmock.ChainService{State: bs} + slot := primitives.Slot(0) + chainService := &blockchainmock.ChainService{State: bs, Slot: &slot} s := &Server{ ChainInfoFetcher: chainService, TimeFetcher: chainService, @@ -1734,7 +1734,8 @@ func TestGetAttesterSlashings(t *testing.T) { t.Run("pre-electra-ok", func(t *testing.T) { bs, err := util.NewBeaconState() require.NoError(t, err) - chainService := &blockchainmock.ChainService{State: bs} + slot := primitives.Slot(0) + chainService := &blockchainmock.ChainService{State: bs, Slot: &slot} s := &Server{ ChainInfoFetcher: chainService, diff --git a/beacon-chain/rpc/eth/blob/handlers_test.go b/beacon-chain/rpc/eth/blob/handlers_test.go index 59c7805b62..3edcaea0c9 100644 --- a/beacon-chain/rpc/eth/blob/handlers_test.go +++ b/beacon-chain/rpc/eth/blob/handlers_test.go @@ -50,6 +50,7 @@ func TestBlobs(t *testing.T) { mockChainService := &mockChain.ChainService{ FinalizedRoots: map[[32]byte]bool{}, + Genesis: time.Now().Add(-time.Duration(uint64(params.BeaconConfig().SlotsPerEpoch)*uint64(params.BeaconConfig().DenebForkEpoch)*params.BeaconConfig().SecondsPerSlot) * time.Second), } s := &Server{ OptimisticModeFetcher: mockChainService, diff --git a/changelog/tt_8.md b/changelog/tt_8.md new file mode 100644 index 0000000000..cefccc8c89 --- /dev/null +++ b/changelog/tt_8.md @@ -0,0 +1,3 @@ +### Added + +- Add support for Electra fork epoch \ No newline at end of file diff --git a/config/params/BUILD.bazel b/config/params/BUILD.bazel index 79d890cf32..ede87d2576 100644 --- a/config/params/BUILD.bazel +++ b/config/params/BUILD.bazel @@ -47,6 +47,7 @@ go_test( "config_test.go", "configset_test.go", "loader_test.go", + "mainnet_config_export_test.go", "mainnet_config_test.go", "testnet_config_test.go", "testnet_holesky_config_test.go", @@ -61,6 +62,7 @@ go_test( "@eth2_networks//:configs", "@holesky_testnet//:configs", "@hoodi_testnet//:configs", + "@mainnet//:configs", "@sepolia_testnet//:configs", ], embed = [":go_default_library"], diff --git a/config/params/loader_test.go b/config/params/loader_test.go index bb55e32f75..5bbf8e7e48 100644 --- a/config/params/loader_test.go +++ b/config/params/loader_test.go @@ -35,6 +35,8 @@ var placeholderFields = []string{ "EIP7441_FORK_VERSION", "EIP7732_FORK_EPOCH", "EIP7732_FORK_VERSION", + "EIP7805_FORK_EPOCH", + "EIP7805_FORK_VERSION", "EPOCHS_PER_SHUFFLING_PHASE", "MAX_BLOBS_PER_BLOCK_FULU", "MAX_REQUEST_BLOB_SIDECARS_FULU", diff --git a/config/params/mainnet_config.go b/config/params/mainnet_config.go index 8c728c1915..9ef092e09d 100644 --- a/config/params/mainnet_config.go +++ b/config/params/mainnet_config.go @@ -28,7 +28,7 @@ const ( // Deneb Fork Epoch for mainnet config. mainnetDenebForkEpoch = 269568 // March 13, 2024, 13:55:35 UTC // Electra Fork Epoch for mainnet config - mainnetElectraForkEpoch = math.MaxUint64 // Far future / to be defined + mainnetElectraForkEpoch = 364032 // May 7, 2025, 10:05:11 UTC // Fulu Fork Epoch for mainnet config mainnetFuluForkEpoch = math.MaxUint64 // Far future / to be defined ) diff --git a/config/params/mainnet_config_export_test.go b/config/params/mainnet_config_export_test.go new file mode 100644 index 0000000000..fc5fc40b85 --- /dev/null +++ b/config/params/mainnet_config_export_test.go @@ -0,0 +1,6 @@ +package params + +// Re-exports for blackbox testing. +const MainnetDenebForkEpoch = mainnetDenebForkEpoch +var MainnetBeaconConfig = mainnetBeaconConfig + diff --git a/config/params/mainnet_config_test.go b/config/params/mainnet_config_test.go index e022923aac..fa141dce7d 100644 --- a/config/params/mainnet_config_test.go +++ b/config/params/mainnet_config_test.go @@ -1,9 +1,13 @@ -package params +package params_test import ( + "path" "testing" + "github.com/OffchainLabs/prysm/v6/config/params" "github.com/OffchainLabs/prysm/v6/consensus-types/primitives" + "github.com/OffchainLabs/prysm/v6/testing/require" + "github.com/bazelbuild/rules_go/go/tools/bazel" ) func TestMaxRequestBlock(t *testing.T) { @@ -13,21 +17,39 @@ func TestMaxRequestBlock(t *testing.T) { description string }{ { - epoch: primitives.Epoch(mainnetDenebForkEpoch - 1), // Assuming the fork epoch is not 0 - expectedMaxBlock: mainnetBeaconConfig.MaxRequestBlocks, + epoch: primitives.Epoch(params.MainnetDenebForkEpoch - 1), // Assuming the fork epoch is not 0 + expectedMaxBlock: params.MainnetBeaconConfig.MaxRequestBlocks, }, { - epoch: primitives.Epoch(mainnetDenebForkEpoch), - expectedMaxBlock: mainnetBeaconConfig.MaxRequestBlocksDeneb, + epoch: primitives.Epoch(params.MainnetDenebForkEpoch), + expectedMaxBlock: params.MainnetBeaconConfig.MaxRequestBlocksDeneb, }, } for _, tc := range testCases { t.Run(tc.description, func(t *testing.T) { - maxBlocks := MaxRequestBlock(tc.epoch) + maxBlocks := params.MaxRequestBlock(tc.epoch) if maxBlocks != tc.expectedMaxBlock { t.Errorf("For epoch %d, expected max blocks %d, got %d", tc.epoch, tc.expectedMaxBlock, maxBlocks) } }) } } + +func TestMainnetConfigMatchesUpstreamYaml(t *testing.T) { + presetFPs := presetsFilePath(t, "mainnet") + mn, err := params.ByName(params.MainnetName) + require.NoError(t, err) + cfg := mn.Copy() + for _, fp := range presetFPs { + cfg, err = params.UnmarshalConfigFile(fp, cfg) + require.NoError(t, err) + } + fPath, err := bazel.Runfile("external/mainnet") + require.NoError(t, err) + configFP := path.Join(fPath, "metadata", "config.yaml") + pcfg, err := params.UnmarshalConfigFile(configFP, nil) + require.NoError(t, err) + fields := fieldsFromYamls(t, append(presetFPs, configFP)) + assertYamlFieldsMatch(t, "mainnet", fields, pcfg, params.BeaconConfig()) +}