From 3d6fad312149475e821fb4770faad77d3d3df6d3 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Wed, 25 Aug 2021 12:18:29 -0500 Subject: [PATCH] Update Prater config to include Altair fork epoch (#9467) * Update Prater config after https://github.com/eth2-clients/eth2-networks/pull/58. Add tests to enforce compliance. * gofmt * spec: true * fix test Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- WORKSPACE | 16 +++++++ beacon-chain/rpc/eth/beacon/config_test.go | 4 +- shared/params/BUILD.bazel | 3 ++ shared/params/config.go | 1 + shared/params/loader_test.go | 48 +++++++++++---------- shared/params/testnet_config_test.go | 16 +++++++ shared/params/testnet_prater_config.go | 7 ++- shared/params/testnet_prater_config_test.go | 12 ++++++ 8 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 shared/params/testnet_config_test.go create mode 100644 shared/params/testnet_prater_config_test.go diff --git a/WORKSPACE b/WORKSPACE index 4906ae83e..db71b3a44 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -263,6 +263,22 @@ filegroup( url = "https://github.com/ethereum/consensus-specs/archive/refs/tags/%s.tar.gz" % consensus_spec_version, ) +http_archive( + name = "eth2_networks", + build_file_content = """ +filegroup( + name = "configs", + srcs = glob([ + "shared/**/config.yaml", + ]), + visibility = ["//visibility:public"], +) + """, + sha256 = "9dc47bf6b14aed7fac8833e35ab83a69131b43fa5789b3256bf1ac3d4861aeb8", + strip_prefix = "eth2-networks-7fa1b868985ee24aad65567f9250cf7fa86f97b1", + url = "https://github.com/eth2-clients/eth2-networks/archive/7fa1b868985ee24aad65567f9250cf7fa86f97b1.tar.gz", +) + http_archive( name = "com_github_bazelbuild_buildtools", sha256 = "7a182df18df1debabd9e36ae07c8edfa1378b8424a04561b674d933b965372b3", diff --git a/beacon-chain/rpc/eth/beacon/config_test.go b/beacon-chain/rpc/eth/beacon/config_test.go index 3a7bee41e..66fcf6d04 100644 --- a/beacon-chain/rpc/eth/beacon/config_test.go +++ b/beacon-chain/rpc/eth/beacon/config_test.go @@ -124,7 +124,7 @@ func TestGetSpec(t *testing.T) { resp, err := server.GetSpec(context.Background(), &emptypb.Empty{}) require.NoError(t, err) - assert.Equal(t, 89, len(resp.Data)) + assert.Equal(t, 90, len(resp.Data)) for k, v := range resp.Data { switch k { case "CONFIG_NAME": @@ -313,6 +313,8 @@ func TestGetSpec(t *testing.T) { assert.Equal(t, "0x08000000", v) case "DOMAIN_CONTRIBUTION_AND_PROOF": assert.Equal(t, "0x09000000", v) + case "TRANSITION_TOTAL_DIFFICULTY": + assert.Equal(t, "0", v) default: t.Errorf("Incorrect key: %s", k) } diff --git a/shared/params/BUILD.bazel b/shared/params/BUILD.bazel index 903db3cd0..9f501733f 100644 --- a/shared/params/BUILD.bazel +++ b/shared/params/BUILD.bazel @@ -37,11 +37,14 @@ go_test( "checktags_test.go", "config_test.go", "loader_test.go", + "testnet_config_test.go", + "testnet_prater_config_test.go", ], data = glob(["*.yaml"]) + [ "@consensus_spec//:spec_data", "@consensus_spec_tests_mainnet//:test_data", "@consensus_spec_tests_minimal//:test_data", + "@eth2_networks//:configs", ], embed = [":go_default_library"], gotags = ["develop"], diff --git a/shared/params/config.go b/shared/params/config.go index 816619df6..f90dbefd7 100644 --- a/shared/params/config.go +++ b/shared/params/config.go @@ -138,6 +138,7 @@ type BeaconChainConfig struct { ShardingForkEpoch types.Epoch `yaml:"SHARDING_FORK_EPOCH" spec:"true"` // ShardingForkEpoch is used to represent the assigned fork epoch for sharding. ForkVersionSchedule map[[4]byte]types.Epoch // Schedule of fork epochs by version. MinAnchorPowBlockDifficulty uint64 `yaml:"MIN_ANCHOR_POW_BLOCK_DIFFICULTY" spec:"true"` // MinAnchorPowBlockDifficulty specifies the target chain difficulty at the time of the merge. + TransitionTotalDifficulty uint64 `yaml:"TRANSITION_TOTAL_DIFFICULTY" spec:"true"` // TransitionTotalDifficulty is part of the experimental merge spec. This value is not used (yet) and is expected to be a uint256. // Weak subjectivity values. SafetyDecay uint64 // SafetyDecay is defined as the loss in the 1/3 consensus safety margin of the casper FFG mechanism. diff --git a/shared/params/loader_test.go b/shared/params/loader_test.go index 2268e7dbd..81768939d 100644 --- a/shared/params/loader_test.go +++ b/shared/params/loader_test.go @@ -100,28 +100,7 @@ func TestLoadConfigFileMainnet(t *testing.T) { assert.Equal(t, c1.DomainSelectionProof, c2.DomainSelectionProof, "%s: DomainSelectionProof", name) assert.Equal(t, c1.DomainAggregateAndProof, c2.DomainAggregateAndProof, "%s: DomainAggregateAndProof", name) - // Ensure all fields from the yaml file exist, were set, and correctly match the expected value. - ft1 := reflect.TypeOf(*c1) - for _, field := range fields { - var found bool - for i := 0; i < ft1.NumField(); i++ { - v, ok := ft1.Field(i).Tag.Lookup("yaml") - if ok && v == field { - found = true - v1 := reflect.ValueOf(*c1).Field(i).Interface() - v2 := reflect.ValueOf(*c2).Field(i).Interface() - if reflect.ValueOf(v1).Kind() == reflect.Slice { - assert.DeepEqual(t, v1, v2, "%s: %s", name, field) - } else { - assert.Equal(t, v1, v2, "%s: %s", name, field) - } - break - } - } - if !found { - t.Errorf("No struct tag found `yaml:%s`", field) - } - } + assertYamlFieldsMatch(t, name, fields, c1, c2) } t.Run("mainnet", func(t *testing.T) { @@ -263,3 +242,28 @@ func fieldsFromYaml(t *testing.T, fp string) []string { return keys } + +func assertYamlFieldsMatch(t *testing.T, name string, fields []string, c1, c2 *BeaconChainConfig) { + // Ensure all fields from the yaml file exist, were set, and correctly match the expected value. + ft1 := reflect.TypeOf(*c1) + for _, field := range fields { + var found bool + for i := 0; i < ft1.NumField(); i++ { + v, ok := ft1.Field(i).Tag.Lookup("yaml") + if ok && v == field { + found = true + v1 := reflect.ValueOf(*c1).Field(i).Interface() + v2 := reflect.ValueOf(*c2).Field(i).Interface() + if reflect.ValueOf(v1).Kind() == reflect.Slice { + assert.DeepEqual(t, v1, v2, "%s: %s", name, field) + } else { + assert.Equal(t, v1, v2, "%s: %s", name, field) + } + break + } + } + if !found { + t.Errorf("No struct tag found `yaml:%s`", field) + } + } +} diff --git a/shared/params/testnet_config_test.go b/shared/params/testnet_config_test.go new file mode 100644 index 000000000..9d516621c --- /dev/null +++ b/shared/params/testnet_config_test.go @@ -0,0 +1,16 @@ +package params + +import ( + "path" + "testing" + + "github.com/bazelbuild/rules_go/go/tools/bazel" + "github.com/prysmaticlabs/prysm/shared/testutil/require" +) + +func testnetConfigFilePath(t *testing.T, network string) string { + filepath, err := bazel.Runfile("external/eth2_networks") + require.NoError(t, err) + configFilePath := path.Join(filepath, "shared", network, "config.yaml") + return configFilePath +} diff --git a/shared/params/testnet_prater_config.go b/shared/params/testnet_prater_config.go index 2fa1abf0c..183c7033d 100644 --- a/shared/params/testnet_prater_config.go +++ b/shared/params/testnet_prater_config.go @@ -39,6 +39,11 @@ func PraterConfig() *BeaconChainConfig { cfg.SecondsPerETH1Block = 14 cfg.DepositChainID = eth1Params.GoerliChainConfig.ChainID.Uint64() cfg.DepositNetworkID = eth1Params.GoerliChainConfig.ChainID.Uint64() - cfg.DepositContractAddress = "0xff50ed3d0ec03ac01d4c79aad74928bff48a7b2b" + cfg.AltairForkEpoch = 36660 + cfg.AltairForkVersion = []byte{0x1, 0x0, 0x10, 0x20} + cfg.ShardingForkVersion = []byte{0x3, 0x0, 0x10, 0x20} + cfg.MergeForkVersion = []byte{0x2, 0x0, 0x10, 0x20} + cfg.TransitionTotalDifficulty = 4294967296 + cfg.DepositContractAddress = "0xff50ed3d0ec03aC01D4C79aAd74928BFF48a7b2b" return cfg } diff --git a/shared/params/testnet_prater_config_test.go b/shared/params/testnet_prater_config_test.go new file mode 100644 index 000000000..dbefd9d52 --- /dev/null +++ b/shared/params/testnet_prater_config_test.go @@ -0,0 +1,12 @@ +package params + +import ( + "testing" +) + +func TestPraterConfigMatchesUpstreamYaml(t *testing.T) { + configFP := testnetConfigFilePath(t, "prater") + LoadChainConfigFile(configFP) + fields := fieldsFromYaml(t, configFP) + assertYamlFieldsMatch(t, "prater", fields, BeaconConfig(), PraterConfig()) +}