mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Config registry (#10683)
* test coverage and updates to config twiddlers * LoadChainConfigFile error if SetActive conflicts * lint * wip working around test issues * more fixes, mass test updates * lint * linting * thanks deepsource! * fix undeclared vars * fixing more undefined * fix a bug, make a bug, repeat * gaz * use stock mainnet in case fork schedule matters * remove unused KnownConfigs * post-merge cleanup * eliminating OverrideBeaconConfig outside tests * more cleanup of OverrideBeaconConfig outside tests * config for interop w/ genesis gen support * improve var name * API on package instead of exported value * cleanup remainders of "registry" naming * Nishant feedback * add ropstein to configset * lint * lint #2 * ✂️ * revert accidental commented line * check if active is nil (replace called on empty) * Nishant feedback * replace OverrideBeaconConfig call * update interop instructions w/ new flag * don't let interop replace config set via cli flags Co-authored-by: kasey <kasey@users.noreply.github.com>
This commit is contained in:
parent
1012ec1915
commit
588dea83b7
17
INTEROP.md
17
INTEROP.md
@ -26,15 +26,18 @@ You can use `bazel run //tools/genesis-state-gen` to create a deterministic gene
|
||||
### Usage
|
||||
|
||||
- **--genesis-time** uint: Unix timestamp used as the genesis time in the generated genesis state (defaults to now)
|
||||
- **--mainnet-config** bool: Select whether genesis state should be generated with mainnet or minimal (default) params
|
||||
- **--num-validators** int: Number of validators to deterministically include in the generated genesis state
|
||||
- **--output-ssz** string: Output filename of the SSZ marshaling of the generated genesis state
|
||||
- **--config-name=interop** string: name of the beacon chain config to use when generating the state. ex mainnet|minimal|interop
|
||||
|
||||
**deprecated flag: use --config-name instead**
|
||||
- **--mainnet-config** bool: Select whether genesis state should be generated with mainnet or minimal (default) params
|
||||
|
||||
The example below creates 64 validator keys, instantiates a genesis state with those 64 validators and with genesis unix timestamp 1567542540,
|
||||
and finally writes a ssz encoded output to ~/Desktop/genesis.ssz. This file can be used to kickstart the beacon chain in the next section.
|
||||
and finally writes a ssz encoded output to ~/Desktop/genesis.ssz. This file can be used to kickstart the beacon chain in the next section. When using the `--interop-*` flags, the beacon node will assume the `interop` config should be used, unless a different config is specified on the command line.
|
||||
|
||||
```
|
||||
bazel run //tools/genesis-state-gen -- --output-ssz ~/Desktop/genesis.ssz --num-validators 64 --genesis-time 1567542540
|
||||
bazel run //tools/genesis-state-gen -- --config-name interop --output-ssz ~/Desktop/genesis.ssz --num-validators 64 --genesis-time 1567542540
|
||||
```
|
||||
|
||||
## Launching a Beacon Node + Validator Client
|
||||
@ -46,8 +49,10 @@ Open up two terminal windows, run:
|
||||
```
|
||||
bazel run //beacon-chain -- \
|
||||
--bootstrap-node= \
|
||||
--deposit-contract $(curl -s https://prylabs.net/contract) \
|
||||
--deposit-contract 0x8A04d14125D0FDCDc742F4A05C051De07232EDa4 \
|
||||
--datadir=/tmp/beacon-chain-interop \
|
||||
--force-clear-db \
|
||||
--min-sync-peers=0 \
|
||||
--interop-num-validators 64 \
|
||||
--interop-eth1data-votes
|
||||
```
|
||||
@ -69,8 +74,10 @@ Assuming you generated a `genesis.ssz` file with 64 validators, open up two term
|
||||
```
|
||||
bazel run //beacon-chain -- \
|
||||
--bootstrap-node= \
|
||||
--deposit-contract $(curl -s https://prylabs.net/contract) \
|
||||
--deposit-contract 0x8A04d14125D0FDCDc742F4A05C051De07232EDa4 \
|
||||
--datadir=/tmp/beacon-chain-interop \
|
||||
--force-clear-db \
|
||||
--min-sync-peers=0 \
|
||||
--interop-genesis-state /path/to/genesis.ssz \
|
||||
--interop-eth1data-votes
|
||||
```
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
func init() {
|
||||
// Override network name so that hardcoded genesis files are not loaded.
|
||||
cfg := params.BeaconConfig()
|
||||
cfg.ConfigName = "test"
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
if err := params.SetActive(params.MainnetTestConfig()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func TestService_ReceiveBlock(t *testing.T) {
|
||||
return blk
|
||||
}
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bc := params.BeaconConfig()
|
||||
bc := params.BeaconConfig().Copy()
|
||||
bc.ShardCommitteePeriod = 0 // Required for voluntary exits test in reasonable time.
|
||||
params.OverrideBeaconConfig(bc)
|
||||
|
||||
|
@ -20,7 +20,9 @@ import (
|
||||
var runAmount = 25
|
||||
|
||||
func BenchmarkExecuteStateTransition_FullBlock(b *testing.B) {
|
||||
benchmark.SetBenchmarkConfig()
|
||||
undo, err := benchmark.SetBenchmarkConfig()
|
||||
require.NoError(b, err)
|
||||
defer undo()
|
||||
beaconState, err := benchmark.PreGenState1Epoch()
|
||||
require.NoError(b, err)
|
||||
cleanStates := clonedStates(beaconState)
|
||||
@ -37,7 +39,9 @@ func BenchmarkExecuteStateTransition_FullBlock(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkExecuteStateTransition_WithCache(b *testing.B) {
|
||||
benchmark.SetBenchmarkConfig()
|
||||
undo, err := benchmark.SetBenchmarkConfig()
|
||||
require.NoError(b, err)
|
||||
defer undo()
|
||||
|
||||
beaconState, err := benchmark.PreGenState1Epoch()
|
||||
require.NoError(b, err)
|
||||
@ -67,7 +71,9 @@ func BenchmarkExecuteStateTransition_WithCache(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkProcessEpoch_2FullEpochs(b *testing.B) {
|
||||
benchmark.SetBenchmarkConfig()
|
||||
undo, err := benchmark.SetBenchmarkConfig()
|
||||
require.NoError(b, err)
|
||||
defer undo()
|
||||
beaconState, err := benchmark.PreGenstateFullEpochs()
|
||||
require.NoError(b, err)
|
||||
|
||||
|
@ -579,10 +579,10 @@ func TestProcessSlots_OnlyAltairEpoch(t *testing.T) {
|
||||
|
||||
func TestProcessSlots_OnlyBellatrixEpoch(t *testing.T) {
|
||||
transition.SkipSlotCache.Disable()
|
||||
conf := params.BeaconConfig()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
conf := params.BeaconConfig().Copy()
|
||||
conf.BellatrixForkEpoch = 5
|
||||
params.OverrideBeaconConfig(conf)
|
||||
defer params.UseMainnetConfig()
|
||||
|
||||
st, _ := util.DeterministicGenesisStateBellatrix(t, params.BeaconConfig().MaxValidatorsPerCommittee)
|
||||
require.NoError(t, st.SetSlot(params.BeaconConfig().SlotsPerEpoch*6))
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/iface"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/testing/util"
|
||||
)
|
||||
|
||||
@ -28,41 +29,70 @@ func testGenesisDataSaved(t *testing.T, db iface.Database) {
|
||||
ctx := context.Background()
|
||||
|
||||
gb, err := db.GenesisBlock(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, gb)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, gb)
|
||||
|
||||
gbHTR, err := gb.Block().HashTreeRoot()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
gss, err := db.StateSummary(ctx, gbHTR)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, gss)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, gss)
|
||||
|
||||
head, err := db.HeadBlock(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, head)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, head)
|
||||
|
||||
headHTR, err := head.Block().HashTreeRoot()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, gbHTR, headHTR, "head block does not match genesis block")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, gbHTR, headHTR, "head block does not match genesis block")
|
||||
}
|
||||
|
||||
func TestLoadGenesisFromFile(t *testing.T) {
|
||||
// for this test to work, we need the active config to have these properties:
|
||||
// - fork version schedule that matches mainnnet.genesis.ssz
|
||||
// - name that does not match params.MainnetName - otherwise we'll trigger the codepath that loads the state
|
||||
// from the compiled binary.
|
||||
// to do that, first we need to rewrite the mainnet fork schedule so it won't conflict with a renamed config that
|
||||
// uses the mainnet fork schedule. construct the differently named mainnet config and set it active.
|
||||
// finally, revert all this at the end of the test.
|
||||
|
||||
// first get the real mainnet out of the way by overwriting it schedule.
|
||||
cfg, err := params.ByName(params.MainnetName)
|
||||
require.NoError(t, err)
|
||||
cfg = cfg.Copy()
|
||||
reversioned := cfg.Copy()
|
||||
params.FillTestVersions(reversioned, 127)
|
||||
undo, err := params.SetActiveWithUndo(reversioned)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, undo())
|
||||
}()
|
||||
|
||||
// then set up a new config, which uses the real mainnet schedule, and activate it
|
||||
cfg.ConfigName = "genesis-test"
|
||||
undo2, err := params.SetActiveWithUndo(cfg)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, undo2())
|
||||
}()
|
||||
|
||||
fp := "testdata/mainnet.genesis.ssz"
|
||||
rfp, err := bazel.Runfile(fp)
|
||||
if err == nil {
|
||||
fp = rfp
|
||||
}
|
||||
sb, err := os.ReadFile(fp)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
db := setupDB(t)
|
||||
assert.NoError(t, db.LoadGenesis(context.Background(), sb))
|
||||
require.NoError(t, db.LoadGenesis(context.Background(), sb))
|
||||
testGenesisDataSaved(t, db)
|
||||
|
||||
// Loading the same genesis again should not throw an error
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, db.LoadGenesis(context.Background(), sb))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.LoadGenesis(context.Background(), sb))
|
||||
testGenesisDataSaved(t, db)
|
||||
}
|
||||
|
||||
func TestLoadGenesisFromFile_mismatchedForkVersion(t *testing.T) {
|
||||
@ -80,11 +110,15 @@ func TestLoadGenesisFromFile_mismatchedForkVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnsureEmbeddedGenesis(t *testing.T) {
|
||||
// Embedded Genesis works with Mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg.ConfigName = params.MainnetName
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
// Embedded Genesis works with Mainnet config
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.SecondsPerSlot = 1
|
||||
undo, err := params.SetActiveWithUndo(cfg)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, undo())
|
||||
}()
|
||||
|
||||
ctx := context.Background()
|
||||
db := setupDB(t)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
func init() {
|
||||
// Override network name so that hardcoded genesis files are not loaded.
|
||||
cfg := params.BeaconConfig()
|
||||
cfg.ConfigName = "test"
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
if err := params.SetActive(params.MainnetTestConfig()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,9 @@ import (
|
||||
)
|
||||
|
||||
func TestSaveOrigin(t *testing.T) {
|
||||
// Embedded Genesis works with Mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg.ConfigName = params.MainnetName
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
// Embedded Genesis works with Mainnet config
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
|
||||
ctx := context.Background()
|
||||
db := setupDB(t)
|
||||
|
@ -23,19 +23,22 @@ func configureTracing(cliCtx *cli.Context) error {
|
||||
)
|
||||
}
|
||||
|
||||
func configureChainConfig(cliCtx *cli.Context) {
|
||||
func configureChainConfig(cliCtx *cli.Context) error {
|
||||
if cliCtx.IsSet(cmd.ChainConfigFileFlag.Name) {
|
||||
chainConfigFileName := cliCtx.String(cmd.ChainConfigFileFlag.Name)
|
||||
params.LoadChainConfigFile(chainConfigFileName, nil)
|
||||
return params.LoadChainConfigFile(chainConfigFileName, nil)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func configureHistoricalSlasher(cliCtx *cli.Context) {
|
||||
func configureHistoricalSlasher(cliCtx *cli.Context) error {
|
||||
if cliCtx.Bool(flags.HistoricalSlasherNode.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
// Save a state every 4 epochs.
|
||||
c.SlotsPerArchivedPoint = params.BeaconConfig().SlotsPerEpoch * 4
|
||||
params.OverrideBeaconConfig(c)
|
||||
if err := params.SetActive(c); err != nil {
|
||||
return err
|
||||
}
|
||||
cmdConfig := cmd.Get()
|
||||
// Allow up to 4096 attestations at a time to be requested from the beacon nde.
|
||||
cmdConfig.MaxRPCPageSize = int(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().MaxAttestations)) // lint:ignore uintcast -- Page size should not exceed int64 with these constants.
|
||||
@ -46,40 +49,52 @@ func configureHistoricalSlasher(cliCtx *cli.Context) {
|
||||
cmdConfig.MaxRPCPageSize,
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func configureSafeSlotsToImportOptimistically(cliCtx *cli.Context) {
|
||||
func configureSafeSlotsToImportOptimistically(cliCtx *cli.Context) error {
|
||||
if cliCtx.IsSet(flags.SafeSlotsToImportOptimistically.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
c.SafeSlotsToImportOptimistically = types.Slot(cliCtx.Int(flags.SafeSlotsToImportOptimistically.Name))
|
||||
params.OverrideBeaconConfig(c)
|
||||
if err := params.SetActive(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func configureSlotsPerArchivedPoint(cliCtx *cli.Context) {
|
||||
func configureSlotsPerArchivedPoint(cliCtx *cli.Context) error {
|
||||
if cliCtx.IsSet(flags.SlotsPerArchivedPoint.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
c.SlotsPerArchivedPoint = types.Slot(cliCtx.Int(flags.SlotsPerArchivedPoint.Name))
|
||||
params.OverrideBeaconConfig(c)
|
||||
if err := params.SetActive(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func configureEth1Config(cliCtx *cli.Context) {
|
||||
func configureEth1Config(cliCtx *cli.Context) error {
|
||||
c := params.BeaconConfig().Copy()
|
||||
if cliCtx.IsSet(flags.ChainID.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.DepositChainID = cliCtx.Uint64(flags.ChainID.Name)
|
||||
params.OverrideBeaconConfig(c)
|
||||
if err := params.SetActive(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if cliCtx.IsSet(flags.NetworkID.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.DepositNetworkID = cliCtx.Uint64(flags.NetworkID.Name)
|
||||
params.OverrideBeaconConfig(c)
|
||||
if err := params.SetActive(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if cliCtx.IsSet(flags.DepositContractFlag.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.DepositContractAddress = cliCtx.String(flags.DepositContractFlag.Name)
|
||||
params.OverrideBeaconConfig(c)
|
||||
if err := params.SetActive(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func configureNetwork(cliCtx *cli.Context) {
|
||||
@ -95,17 +110,22 @@ func configureNetwork(cliCtx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func configureInteropConfig(cliCtx *cli.Context) {
|
||||
func configureInteropConfig(cliCtx *cli.Context) error {
|
||||
// an explicit chain config was specified, don't mess with it
|
||||
if cliCtx.IsSet(cmd.ChainConfigFileFlag.Name) {
|
||||
return nil
|
||||
}
|
||||
genStateIsSet := cliCtx.IsSet(flags.InteropGenesisStateFlag.Name)
|
||||
genTimeIsSet := cliCtx.IsSet(flags.InteropGenesisTimeFlag.Name)
|
||||
numValsIsSet := cliCtx.IsSet(flags.InteropNumValidatorsFlag.Name)
|
||||
votesIsSet := cliCtx.IsSet(flags.InteropMockEth1DataVotesFlag.Name)
|
||||
|
||||
if genStateIsSet || genTimeIsSet || numValsIsSet || votesIsSet {
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg.ConfigName = "interop"
|
||||
params.OverrideBeaconConfig(bCfg)
|
||||
if err := params.SetActive(params.InteropConfig().Copy()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func configureExecutionSetting(cliCtx *cli.Context) error {
|
||||
@ -113,7 +133,7 @@ func configureExecutionSetting(cliCtx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
ha := cliCtx.String(flags.SuggestedFeeRecipient.Name)
|
||||
if !common.IsHexAddress(ha) {
|
||||
return fmt.Errorf("%s is not a valid fee recipient address", ha)
|
||||
@ -130,6 +150,5 @@ func configureExecutionSetting(cliCtx *cli.Context) error {
|
||||
"to prevent spelling mistakes in your fee recipient Ethereum address", ha, checksumAddress.Hex())
|
||||
}
|
||||
c.DefaultFeeRecipient = checksumAddress
|
||||
params.OverrideBeaconConfig(c)
|
||||
return nil
|
||||
return params.SetActive(c)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func TestConfigureHistoricalSlasher(t *testing.T) {
|
||||
set.Bool(flags.HistoricalSlasherNode.Name, true, "")
|
||||
cliCtx := cli.NewContext(&app, set, nil)
|
||||
|
||||
configureHistoricalSlasher(cliCtx)
|
||||
require.NoError(t, configureHistoricalSlasher(cliCtx))
|
||||
|
||||
assert.Equal(t, params.BeaconConfig().SlotsPerEpoch*4, params.BeaconConfig().SlotsPerArchivedPoint)
|
||||
assert.LogsContain(t, hook,
|
||||
@ -46,7 +46,7 @@ func TestConfigureSafeSlotsToImportOptimistically(t *testing.T) {
|
||||
require.NoError(t, set.Set(flags.SafeSlotsToImportOptimistically.Name, strconv.Itoa(128)))
|
||||
cliCtx := cli.NewContext(&app, set, nil)
|
||||
|
||||
configureSafeSlotsToImportOptimistically(cliCtx)
|
||||
require.NoError(t, configureSafeSlotsToImportOptimistically(cliCtx))
|
||||
|
||||
assert.Equal(t, types.Slot(128), params.BeaconConfig().SafeSlotsToImportOptimistically)
|
||||
}
|
||||
@ -60,7 +60,7 @@ func TestConfigureSlotsPerArchivedPoint(t *testing.T) {
|
||||
require.NoError(t, set.Set(flags.SlotsPerArchivedPoint.Name, strconv.Itoa(100)))
|
||||
cliCtx := cli.NewContext(&app, set, nil)
|
||||
|
||||
configureSlotsPerArchivedPoint(cliCtx)
|
||||
require.NoError(t, configureSlotsPerArchivedPoint(cliCtx))
|
||||
|
||||
assert.Equal(t, types.Slot(100), params.BeaconConfig().SlotsPerArchivedPoint)
|
||||
}
|
||||
@ -78,7 +78,7 @@ func TestConfigureProofOfWork(t *testing.T) {
|
||||
require.NoError(t, set.Set(flags.DepositContractFlag.Name, "deposit-contract"))
|
||||
cliCtx := cli.NewContext(&app, set, nil)
|
||||
|
||||
configureEth1Config(cliCtx)
|
||||
require.NoError(t, configureEth1Config(cliCtx))
|
||||
|
||||
assert.Equal(t, uint64(100), params.BeaconConfig().DepositChainID)
|
||||
assert.Equal(t, uint64(200), params.BeaconConfig().DepositNetworkID)
|
||||
@ -198,7 +198,7 @@ func TestConfigureInterop(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
configureInteropConfig(tt.flagSetter())
|
||||
require.NoError(t, configureInteropConfig(tt.flagSetter()))
|
||||
assert.DeepEqual(t, tt.configName, params.BeaconConfig().ConfigName)
|
||||
})
|
||||
}
|
||||
|
@ -118,16 +118,32 @@ func New(cliCtx *cli.Context, opts ...Option) (*BeaconNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
prereqs.WarnIfPlatformNotSupported(cliCtx.Context)
|
||||
features.ConfigureBeaconChain(cliCtx)
|
||||
cmd.ConfigureBeaconChain(cliCtx)
|
||||
if err := features.ConfigureBeaconChain(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := cmd.ConfigureBeaconChain(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flags.ConfigureGlobalFlags(cliCtx)
|
||||
configureChainConfig(cliCtx)
|
||||
configureHistoricalSlasher(cliCtx)
|
||||
configureSafeSlotsToImportOptimistically(cliCtx)
|
||||
configureSlotsPerArchivedPoint(cliCtx)
|
||||
configureEth1Config(cliCtx)
|
||||
if err := configureChainConfig(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := configureHistoricalSlasher(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := configureSafeSlotsToImportOptimistically(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := configureSlotsPerArchivedPoint(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := configureEth1Config(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
configureNetwork(cliCtx)
|
||||
configureInteropConfig(cliCtx)
|
||||
if err := configureInteropConfig(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := configureExecutionSetting(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ func TestRefreshENR_ForkBoundaries(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Update params
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.AltairForkEpoch = 5
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
params.BeaconConfig().InitializeForkSchedule()
|
||||
@ -441,7 +441,7 @@ func TestRefreshENR_ForkBoundaries(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Update params
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.AltairForkEpoch = 5
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
params.BeaconConfig().InitializeForkSchedule()
|
||||
@ -471,7 +471,7 @@ func TestRefreshENR_ForkBoundaries(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Update params
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.AltairForkEpoch = 5
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
params.BeaconConfig().InitializeForkSchedule()
|
||||
|
@ -114,6 +114,7 @@ func TestStartDiscv5_DifferentForkDigests(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStartDiscv5_SameForkDigests_DifferentNextForkData(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
hook := logTest.NewGlobal()
|
||||
logrus.SetLevel(logrus.TraceLevel)
|
||||
port := 2000
|
||||
@ -136,14 +137,13 @@ func TestStartDiscv5_SameForkDigests_DifferentNextForkData(t *testing.T) {
|
||||
UDPPort: uint(port),
|
||||
}
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
var listeners []*discover.UDPv5
|
||||
for i := 1; i <= 5; i++ {
|
||||
port = 3000 + i
|
||||
cfg.UDPPort = uint(port)
|
||||
ipAddr, pkey := createAddrAndPrivKey(t)
|
||||
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
nextForkEpoch := types.Epoch(i)
|
||||
c.ForkVersionSchedule[[4]byte{'A', 'B', 'C', 'D'}] = nextForkEpoch
|
||||
params.OverrideBeaconConfig(c)
|
||||
@ -209,7 +209,7 @@ func TestStartDiscv5_SameForkDigests_DifferentNextForkData(t *testing.T) {
|
||||
|
||||
func TestDiscv5_AddRetrieveForkEntryENR(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
c.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion): 0,
|
||||
{0, 0, 0, 1}: 1,
|
||||
@ -264,7 +264,7 @@ func TestAddForkEntry_Genesis(t *testing.T) {
|
||||
db, err := enode.OpenDB("")
|
||||
require.NoError(t, err)
|
||||
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.MainnetConfig().Copy()
|
||||
bCfg.ForkVersionSchedule = map[[4]byte]types.Epoch{}
|
||||
bCfg.ForkVersionSchedule[bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)] = bCfg.GenesisEpoch
|
||||
params.OverrideBeaconConfig(bCfg)
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
|
||||
func TestCorrect_ActiveValidatorsCount(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig()
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.ConfigName = "test"
|
||||
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMappingHasNoDuplicates(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
m := make(map[reflect.Type]bool)
|
||||
for _, v := range gossipTopicMappings {
|
||||
if _, ok := m[reflect.TypeOf(v)]; ok {
|
||||
@ -23,7 +24,7 @@ func TestMappingHasNoDuplicates(t *testing.T) {
|
||||
|
||||
func TestGossipTopicMappings_CorrectBlockType(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.BeaconConfig().Copy()
|
||||
altairForkEpoch := eth2types.Epoch(100)
|
||||
BellatrixForkEpoch := eth2types.Epoch(200)
|
||||
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMsgID_HashesCorrectly(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
genesisValidatorsRoot := bytesutil.PadTo([]byte{'A'}, 32)
|
||||
d, err := forks.CreateForkDigest(time.Now(), genesisValidatorsRoot)
|
||||
assert.NoError(t, err)
|
||||
@ -36,6 +37,7 @@ func TestMsgID_HashesCorrectly(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMessageIDFunction_HashesCorrectlyAltair(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
genesisValidatorsRoot := bytesutil.PadTo([]byte{'A'}, 32)
|
||||
d, err := signing.ComputeForkDigest(params.BeaconConfig().AltairForkVersion, genesisValidatorsRoot)
|
||||
assert.NoError(t, err)
|
||||
@ -65,6 +67,7 @@ func TestMessageIDFunction_HashesCorrectlyAltair(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMessageIDFunction_HashesCorrectlyBellatrix(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
genesisValidatorsRoot := bytesutil.PadTo([]byte{'A'}, 32)
|
||||
d, err := signing.ComputeForkDigest(params.BeaconConfig().BellatrixForkVersion, genesisValidatorsRoot)
|
||||
assert.NoError(t, err)
|
||||
@ -94,6 +97,7 @@ func TestMessageIDFunction_HashesCorrectlyBellatrix(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMsgID_WithNilTopic(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
msg := &pubsubpb.Message{
|
||||
Data: make([]byte, 32),
|
||||
Topic: nil,
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func TestPrivateKeyLoading(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
file, err := os.CreateTemp(t.TempDir(), "key")
|
||||
require.NoError(t, err)
|
||||
key, _, err := crypto.GenerateSecp256k1Key(rand.Reader)
|
||||
@ -44,6 +45,7 @@ func TestPrivateKeyLoading(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIPV6Support(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
key, err := gethCrypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
db, err := enode.OpenDB("")
|
||||
|
@ -4,10 +4,12 @@ import (
|
||||
"testing"
|
||||
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
)
|
||||
|
||||
func TestOverlayParameters(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
pms := pubsubGossipParam()
|
||||
assert.Equal(t, gossipSubD, pms.D, "gossipSubD")
|
||||
assert.Equal(t, gossipSubDlo, pms.Dlo, "gossipSubDlo")
|
||||
@ -15,6 +17,7 @@ func TestOverlayParameters(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGossipParameters(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
setPubSubParameters()
|
||||
pms := pubsubGossipParam()
|
||||
assert.Equal(t, gossipSubMcacheLen, pms.HistoryLength, "gossipSubMcacheLen")
|
||||
@ -23,6 +26,7 @@ func TestGossipParameters(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFanoutParameters(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
pms := pubsubGossipParam()
|
||||
if pms.FanoutTTL != gossipSubFanoutTTL {
|
||||
t.Errorf("gossipSubFanoutTTL, wanted: %d, got: %d", gossipSubFanoutTTL, pms.FanoutTTL)
|
||||
@ -30,6 +34,7 @@ func TestFanoutParameters(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHeartbeatParameters(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
pms := pubsubGossipParam()
|
||||
if pms.HeartbeatInterval != gossipSubHeartbeatInterval {
|
||||
t.Errorf("gossipSubHeartbeatInterval, wanted: %d, got: %d", gossipSubHeartbeatInterval, pms.HeartbeatInterval)
|
||||
@ -37,6 +42,7 @@ func TestHeartbeatParameters(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMiscParameters(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
setPubSubParameters()
|
||||
assert.Equal(t, randomSubD, pubsub.RandomSubD, "randomSubD")
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/network/forks"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
@ -21,6 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func TestService_CanSubscribe(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
currentFork := [4]byte{0x01, 0x02, 0x03, 0x04}
|
||||
validProtocolSuffix := "/" + encoder.ProtocolSuffixSSZSnappy
|
||||
genesisTime := time.Now()
|
||||
@ -115,11 +117,13 @@ func TestService_CanSubscribe(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_CanSubscribe_uninitialized(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
s := &Service{}
|
||||
require.Equal(t, false, s.CanSubscribe("foo"))
|
||||
}
|
||||
|
||||
func Test_scanfcheck(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
type args struct {
|
||||
input string
|
||||
format string
|
||||
@ -191,6 +195,7 @@ func Test_scanfcheck(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGossipTopicMapping_scanfcheck_GossipTopicFormattingSanityCheck(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
// scanfcheck only supports integer based substitutions at the moment. Any others will
|
||||
// inaccurately fail validation.
|
||||
for _, topic := range AllTopics() {
|
||||
@ -208,6 +213,7 @@ func TestGossipTopicMapping_scanfcheck_GossipTopicFormattingSanityCheck(t *testi
|
||||
}
|
||||
|
||||
func TestService_FilterIncomingSubscriptions(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
validProtocolSuffix := "/" + encoder.ProtocolSuffixSSZSnappy
|
||||
genesisTime := time.Now()
|
||||
valRoot := [32]byte{}
|
||||
@ -328,6 +334,7 @@ func TestService_FilterIncomingSubscriptions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_MonitorsStateForkUpdates(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
notifier := &mock.MockStateNotifier{}
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func TestVerifyRPCMappings(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
assert.NoError(t, VerifyTopicMapping(RPCStatusTopicV1, &pb.Status{}), "Failed to verify status rpc topic")
|
||||
assert.NotNil(t, VerifyTopicMapping(RPCStatusTopicV1, new([]byte)), "Incorrect message type verified for status rpc topic")
|
||||
|
||||
@ -25,6 +26,7 @@ func TestVerifyRPCMappings(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTopicDeconstructor(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
tt := []struct {
|
||||
name string
|
||||
topic string
|
||||
@ -81,7 +83,7 @@ func TestTopicDeconstructor(t *testing.T) {
|
||||
|
||||
func TestTopicFromMessage_CorrectType(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.BeaconConfig().Copy()
|
||||
forkEpoch := eth2types.Epoch(100)
|
||||
bCfg.AltairForkEpoch = forkEpoch
|
||||
bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.AltairForkVersion)] = eth2types.Epoch(100)
|
||||
|
@ -6,17 +6,18 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/testing/util"
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
testp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/testing/util"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func TestService_Send(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
p1 := testp2p.NewTestP2P(t)
|
||||
p2 := testp2p.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/scorers"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/network/forks"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
@ -81,6 +82,7 @@ func createHost(t *testing.T, port int) (host.Host, *ecdsa.PrivateKey, net.IP) {
|
||||
}
|
||||
|
||||
func TestService_Stop_SetsStartedToFalse(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
s, err := NewService(context.Background(), &Config{StateNotifier: &mock.MockStateNotifier{}})
|
||||
require.NoError(t, err)
|
||||
s.started = true
|
||||
@ -90,12 +92,14 @@ func TestService_Stop_SetsStartedToFalse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_Stop_DontPanicIfDv5ListenerIsNotInited(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
s, err := NewService(context.Background(), &Config{StateNotifier: &mock.MockStateNotifier{}})
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, s.Stop())
|
||||
}
|
||||
|
||||
func TestService_Start_OnlyStartsOnce(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
cfg := &Config{
|
||||
@ -131,12 +135,14 @@ func TestService_Start_OnlyStartsOnce(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_Status_NotRunning(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
s := &Service{started: false}
|
||||
s.dv5Listener = &mockListener{}
|
||||
assert.ErrorContains(t, "not running", s.Status(), "Status returned wrong error")
|
||||
}
|
||||
|
||||
func TestService_Status_NoGenesisTimeSet(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
s := &Service{started: true}
|
||||
s.dv5Listener = &mockListener{}
|
||||
assert.ErrorContains(t, "no genesis time set", s.Status(), "Status returned wrong error")
|
||||
@ -147,6 +153,7 @@ func TestService_Status_NoGenesisTimeSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListenForNewNodes(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
// Setup bootnode.
|
||||
notifier := &mock.MockStateNotifier{}
|
||||
cfg := &Config{StateNotifier: notifier}
|
||||
@ -241,6 +248,7 @@ func TestListenForNewNodes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPeer_Disconnect(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
h1, _, _ := createHost(t, 5000)
|
||||
defer func() {
|
||||
if err := h1.Close(); err != nil {
|
||||
@ -271,6 +279,7 @@ func TestPeer_Disconnect(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_JoinLeaveTopic(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
s, err := NewService(ctx, &Config{StateNotifier: &mock.MockStateNotifier{}})
|
||||
@ -329,6 +338,7 @@ func initializeStateWithForkDigest(ctx context.Context, t *testing.T, ef *event.
|
||||
}
|
||||
|
||||
func TestService_connectWithPeer(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
peers *peers.Status
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
@ -24,6 +25,7 @@ import (
|
||||
)
|
||||
|
||||
func TestStartDiscV5_DiscoverPeersWithSubnets(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
// This test needs to be entirely rewritten and should be done in a follow up PR from #7885.
|
||||
t.Skip("This test is now failing after PR 7885 due to false positive")
|
||||
gFlags := new(flags.GlobalFlags)
|
||||
@ -146,6 +148,7 @@ func TestStartDiscV5_DiscoverPeersWithSubnets(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_AttSubnets(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
record func(t *testing.T) *enr.Record
|
||||
@ -330,6 +333,7 @@ func Test_AttSubnets(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_SyncSubnets(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
record func(t *testing.T) *enr.Record
|
||||
|
@ -24,7 +24,7 @@ func TestInitializeDataMaps(t *testing.T) {
|
||||
{
|
||||
name: "fork version changes",
|
||||
action: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.GenesisForkVersion = []byte{0x01, 0x02, 0x00, 0x00}
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
},
|
||||
@ -33,7 +33,7 @@ func TestInitializeDataMaps(t *testing.T) {
|
||||
{
|
||||
name: "fork version changes with reset",
|
||||
action: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.GenesisForkVersion = []byte{0x01, 0x02, 0x00, 0x00}
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
InitializeDataMaps()
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
@ -14,6 +15,7 @@ import (
|
||||
// Test `verifyConnectivity` function by trying to connect to google.com (successfully)
|
||||
// and then by connecting to an unreachable IP and ensuring that a log is emitted
|
||||
func TestVerifyConnectivity(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
hook := logTest.NewGlobal()
|
||||
cases := []struct {
|
||||
address string
|
||||
@ -39,6 +41,7 @@ func TestVerifyConnectivity(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSerializeENR(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
t.Run("Ok", func(t *testing.T) {
|
||||
key, err := crypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
|
@ -26,7 +26,7 @@ const pubKeyErr = "could not convert bytes to public key"
|
||||
|
||||
func TestDepositContractAddress_EmptyAddress(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
config := params.BeaconConfig()
|
||||
config := params.BeaconConfig().Copy()
|
||||
config.DepositContractAddress = ""
|
||||
params.OverrideBeaconConfig(config)
|
||||
|
||||
@ -36,7 +36,7 @@ func TestDepositContractAddress_EmptyAddress(t *testing.T) {
|
||||
|
||||
func TestDepositContractAddress_NotHexAddress(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
config := params.BeaconConfig()
|
||||
config := params.BeaconConfig().Copy()
|
||||
config.DepositContractAddress = "abc?!"
|
||||
params.OverrideBeaconConfig(config)
|
||||
|
||||
|
@ -488,7 +488,7 @@ func TestServer_getPowBlockHashAtTerminalTotalDifficulty(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.TerminalTotalDifficulty = tt.paramsTd
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
var m map[[32]byte]*pb.ExecutionBlock
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
func init() {
|
||||
// Override network name so that hardcoded genesis files are not loaded.
|
||||
cfg := params.BeaconConfig()
|
||||
cfg.ConfigName = "test"
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
if err := params.SetActive(params.MainnetTestConfig()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ func TestProcessETH2GenesisLog_8DuplicatePubkeys(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bConfig := params.MinimalSpecConfig()
|
||||
bConfig := params.MinimalSpecConfig().Copy()
|
||||
bConfig.MinGenesisTime = 0
|
||||
params.OverrideBeaconConfig(bConfig)
|
||||
|
||||
@ -284,7 +284,7 @@ func TestProcessETH2GenesisLog_8DuplicatePubkeys(t *testing.T) {
|
||||
|
||||
func TestProcessETH2GenesisLog(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.GenesisDelay = 0
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
hook := logTest.NewGlobal()
|
||||
@ -310,7 +310,7 @@ func TestProcessETH2GenesisLog(t *testing.T) {
|
||||
web3Service.depositContractCaller, err = contracts.NewDepositContractCaller(testAcc.ContractAddr, testAcc.Backend)
|
||||
require.NoError(t, err)
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bConfig := params.MinimalSpecConfig()
|
||||
bConfig := params.MinimalSpecConfig().Copy()
|
||||
bConfig.MinGenesisTime = 0
|
||||
params.OverrideBeaconConfig(bConfig)
|
||||
|
||||
@ -378,6 +378,7 @@ func TestProcessETH2GenesisLog(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessETH2GenesisLog_CorrectNumOfDeposits(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := mock.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
@ -406,8 +407,7 @@ func TestProcessETH2GenesisLog_CorrectNumOfDeposits(t *testing.T) {
|
||||
web3Service.latestEth1Data.LastRequestedBlock = 0
|
||||
web3Service.latestEth1Data.BlockHeight = testAcc.Backend.Blockchain().CurrentBlock().NumberU64()
|
||||
web3Service.latestEth1Data.BlockTime = testAcc.Backend.Blockchain().CurrentBlock().Time()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bConfig := params.MinimalSpecConfig()
|
||||
bConfig := params.MinimalSpecConfig().Copy()
|
||||
bConfig.MinGenesisTime = 0
|
||||
bConfig.SecondsPerETH1Block = 10
|
||||
params.OverrideBeaconConfig(bConfig)
|
||||
@ -476,6 +476,7 @@ func TestProcessETH2GenesisLog_CorrectNumOfDeposits(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessETH2GenesisLog_LargePeriodOfNoLogs(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := mock.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
@ -504,8 +505,7 @@ func TestProcessETH2GenesisLog_LargePeriodOfNoLogs(t *testing.T) {
|
||||
web3Service.latestEth1Data.LastRequestedBlock = 0
|
||||
web3Service.latestEth1Data.BlockHeight = testAcc.Backend.Blockchain().CurrentBlock().NumberU64()
|
||||
web3Service.latestEth1Data.BlockTime = testAcc.Backend.Blockchain().CurrentBlock().Time()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bConfig := params.MinimalSpecConfig()
|
||||
bConfig := params.MinimalSpecConfig().Copy()
|
||||
bConfig.SecondsPerETH1Block = 10
|
||||
params.OverrideBeaconConfig(bConfig)
|
||||
nConfig := params.BeaconNetworkConfig()
|
||||
@ -552,7 +552,7 @@ func TestProcessETH2GenesisLog_LargePeriodOfNoLogs(t *testing.T) {
|
||||
|
||||
// Set the genesis time 500 blocks ahead of the last
|
||||
// deposit log.
|
||||
bConfig = params.MinimalSpecConfig()
|
||||
bConfig = params.MinimalSpecConfig().Copy()
|
||||
bConfig.MinGenesisTime = wantedGenesisTime - 10
|
||||
params.OverrideBeaconConfig(bConfig)
|
||||
|
||||
@ -616,7 +616,7 @@ func newPowchainService(t *testing.T, eth1Backend *mock.TestAccount, beaconDB db
|
||||
web3Service.eth1DataFetcher = &goodFetcher{backend: eth1Backend.Backend}
|
||||
web3Service.httpLogger = &goodLogger{backend: eth1Backend.Backend}
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bConfig := params.MinimalSpecConfig()
|
||||
bConfig := params.MinimalSpecConfig().Copy()
|
||||
bConfig.MinGenesisTime = 0
|
||||
params.OverrideBeaconConfig(bConfig)
|
||||
return web3Service
|
||||
|
@ -252,7 +252,7 @@ func TestFollowBlock_OK(t *testing.T) {
|
||||
// simulated backend sets eth1 block
|
||||
// time as 10 seconds
|
||||
params.SetupTestConfigCleanup(t)
|
||||
conf := params.BeaconConfig()
|
||||
conf := params.BeaconConfig().Copy()
|
||||
conf.SecondsPerETH1Block = 10
|
||||
params.OverrideBeaconConfig(conf)
|
||||
|
||||
@ -340,7 +340,7 @@ func TestLogTillGenesis_OK(t *testing.T) {
|
||||
}()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.Eth1FollowDistance = 5
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
@ -506,7 +506,7 @@ func TestNewService_EarliestVotingBlock(t *testing.T) {
|
||||
// simulated backend sets eth1 block
|
||||
// time as 10 seconds
|
||||
params.SetupTestConfigCleanup(t)
|
||||
conf := params.BeaconConfig()
|
||||
conf := params.BeaconConfig().Copy()
|
||||
conf.SecondsPerETH1Block = 10
|
||||
conf.Eth1FollowDistance = 50
|
||||
params.OverrideBeaconConfig(conf)
|
||||
|
@ -364,7 +364,7 @@ func TestWrapSignedContributionAndProofsArray(t *testing.T) {
|
||||
|
||||
func TestSetInitialPublishBlockPostRequest(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.BellatrixForkEpoch = params.BeaconConfig().AltairForkEpoch + 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
@ -470,7 +470,7 @@ func TestPreparePublishedBlock(t *testing.T) {
|
||||
|
||||
func TestSetInitialPublishBlindedBlockPostRequest(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.BellatrixForkEpoch = params.BeaconConfig().AltairForkEpoch + 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
|
||||
func TestGetSpec(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
config := params.BeaconConfig()
|
||||
config := params.BeaconConfig().Copy()
|
||||
|
||||
config.ConfigName = "ConfigName"
|
||||
config.PresetBase = "PresetBase"
|
||||
@ -353,7 +353,7 @@ func TestGetDepositContract(t *testing.T) {
|
||||
const chainId = 99
|
||||
const address = "0x0000000000000000000000000000000000000009"
|
||||
params.SetupTestConfigCleanup(t)
|
||||
config := params.BeaconConfig()
|
||||
config := params.BeaconConfig().Copy()
|
||||
config.DepositChainID = chainId
|
||||
config.DepositContractAddress = address
|
||||
params.OverrideBeaconConfig(config)
|
||||
@ -372,7 +372,7 @@ func TestForkSchedule_Ok(t *testing.T) {
|
||||
thirdForkVersion, thirdForkEpoch := []byte("Thir"), types.Epoch(300)
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
config := params.BeaconConfig()
|
||||
config := params.BeaconConfig().Copy()
|
||||
config.GenesisForkVersion = genesisForkVersion
|
||||
// Create fork schedule adding keys in non-sorted order.
|
||||
schedule := make(map[[4]byte]types.Epoch, 3)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
func init() {
|
||||
// Override network name so that hardcoded genesis files are not loaded.
|
||||
cfg := params.BeaconConfig()
|
||||
cfg.ConfigName = "test"
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
if err := params.SetActive(params.MainnetTestConfig()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -703,7 +703,7 @@ func TestSubmitVoluntaryExit_InvalidExit(t *testing.T) {
|
||||
func TestServer_SubmitAttestations_Ok(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
// Required for correct committee size calculation.
|
||||
c.SlotsPerEpoch = 1
|
||||
params.OverrideBeaconConfig(c)
|
||||
@ -809,7 +809,7 @@ func TestServer_SubmitAttestations_ValidAttestationSubmitted(t *testing.T) {
|
||||
ctx := grpc.NewContextWithServerTransportStream(context.Background(), &runtime.ServerTransportStream{})
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
// Required for correct committee size calculation.
|
||||
c.SlotsPerEpoch = 1
|
||||
params.OverrideBeaconConfig(c)
|
||||
@ -909,7 +909,7 @@ func TestServer_SubmitAttestations_InvalidAttestationGRPCHeader(t *testing.T) {
|
||||
ctx := grpc.NewContextWithServerTransportStream(context.Background(), &runtime.ServerTransportStream{})
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
// Required for correct committee size calculation.
|
||||
c.SlotsPerEpoch = 1
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
func TestGetGenesis(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
config := params.BeaconConfig()
|
||||
config := params.BeaconConfig().Copy()
|
||||
config.GenesisForkVersion = []byte("genesis")
|
||||
params.OverrideBeaconConfig(config)
|
||||
genesis := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
@ -864,7 +864,7 @@ func TestProduceBlockV2(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bc := params.BeaconConfig()
|
||||
bc := params.BeaconConfig().Copy()
|
||||
bc.AltairForkEpoch = types.Epoch(0)
|
||||
params.OverrideBeaconConfig(bc)
|
||||
|
||||
@ -1006,7 +1006,7 @@ func TestProduceBlockV2(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bc := params.BeaconConfig()
|
||||
bc := params.BeaconConfig().Copy()
|
||||
bc.AltairForkEpoch = types.Epoch(0)
|
||||
bc.BellatrixForkEpoch = types.Epoch(1)
|
||||
params.OverrideBeaconConfig(bc)
|
||||
@ -1852,7 +1852,7 @@ func TestProduceBlindedBlock(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bc := params.BeaconConfig()
|
||||
bc := params.BeaconConfig().Copy()
|
||||
bc.AltairForkEpoch = types.Epoch(0)
|
||||
params.OverrideBeaconConfig(bc)
|
||||
|
||||
@ -1995,7 +1995,7 @@ func TestProduceBlindedBlock(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bc := params.BeaconConfig()
|
||||
bc := params.BeaconConfig().Copy()
|
||||
bc.AltairForkEpoch = types.Epoch(0)
|
||||
bc.BellatrixForkEpoch = types.Epoch(1)
|
||||
params.OverrideBeaconConfig(bc)
|
||||
|
@ -740,7 +740,8 @@ func TestServer_StreamBlocks_ContextCanceled(t *testing.T) {
|
||||
|
||||
func TestServer_StreamBlocks_OnHeadUpdated(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.UseMainnetConfig()
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
|
||||
ctx := context.Background()
|
||||
beaconState, privs := util.DeterministicGenesisState(t, 32)
|
||||
b, err := util.GenerateFullBlock(beaconState, privs, util.DefaultBlockGenConfig(), 1)
|
||||
@ -778,7 +779,8 @@ func TestServer_StreamBlocks_OnHeadUpdated(t *testing.T) {
|
||||
|
||||
func TestServer_StreamBlocksVerified_OnHeadUpdated(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.UseMainnetConfig()
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
beaconState, privs := util.DeterministicGenesisState(t, 32)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
func init() {
|
||||
// Override network name so that hardcoded genesis files are not loaded.
|
||||
cfg := params.BeaconConfig()
|
||||
cfg.ConfigName = "test"
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
if err := params.SetActive(params.MainnetTestConfig()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -1028,6 +1028,7 @@ func TestServer_ListValidators_DefaultPageSize(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_FromOldEpoch(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
transition.SkipSlotCache.Disable()
|
||||
|
||||
|
@ -100,7 +100,7 @@ func TestSubmitAggregateAndProof_IsAggregatorAndNoAtts(t *testing.T) {
|
||||
|
||||
func TestSubmitAggregateAndProof_UnaggregateOk(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
c := params.MinimalSpecConfig()
|
||||
c := params.MinimalSpecConfig().Copy()
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
@ -135,7 +135,7 @@ func TestSubmitAggregateAndProof_UnaggregateOk(t *testing.T) {
|
||||
|
||||
func TestSubmitAggregateAndProof_AggregateOk(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
c := params.MinimalSpecConfig()
|
||||
c := params.MinimalSpecConfig().Copy()
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
@ -181,7 +181,7 @@ func TestSubmitAggregateAndProof_AggregateOk(t *testing.T) {
|
||||
|
||||
func TestSubmitAggregateAndProof_AggregateNotOk(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
c := params.MinimalSpecConfig()
|
||||
c := params.MinimalSpecConfig().Copy()
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
@ -293,7 +293,7 @@ func generateUnaggregatedAtt(state state.ReadOnlyBeaconState, index uint64, priv
|
||||
|
||||
func TestSubmitAggregateAndProof_PreferOwnAttestation(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
c := params.MinimalSpecConfig()
|
||||
c := params.MinimalSpecConfig().Copy()
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
@ -349,7 +349,7 @@ func TestSubmitAggregateAndProof_PreferOwnAttestation(t *testing.T) {
|
||||
|
||||
func TestSubmitAggregateAndProof_SelectsMostBitsWhenOwnAttestationNotPresent(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
c := params.MinimalSpecConfig()
|
||||
c := params.MinimalSpecConfig().Copy()
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
|
@ -103,7 +103,7 @@ func TestGetDuties_OK(t *testing.T) {
|
||||
|
||||
func TestGetAltairDuties_SyncCommitteeOK(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig()
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.AltairForkEpoch = types.Epoch(0)
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
@ -205,7 +205,7 @@ func TestGetAltairDuties_SyncCommitteeOK(t *testing.T) {
|
||||
|
||||
func TestGetBellatrixDuties_SyncCommitteeOK(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig()
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.AltairForkEpoch = types.Epoch(0)
|
||||
cfg.BellatrixForkEpoch = types.Epoch(1)
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
@ -311,7 +311,7 @@ func TestGetBellatrixDuties_SyncCommitteeOK(t *testing.T) {
|
||||
|
||||
func TestGetAltairDuties_UnknownPubkey(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig()
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.AltairForkEpoch = types.Epoch(0)
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
|
@ -173,7 +173,7 @@ func TestGetAttestationData_SyncNotReady(t *testing.T) {
|
||||
|
||||
func TestGetAttestationData_Optimistic(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.BellatrixForkEpoch = 0
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
@ -214,7 +214,7 @@ func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) {
|
||||
|
||||
// Ensure HistoricalRootsLimit matches scenario
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig()
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.HistoricalRootsLimit = 8192
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
|
@ -23,9 +23,10 @@ import (
|
||||
)
|
||||
|
||||
func TestServer_activationEpochNotReached(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
require.Equal(t, false, activationEpochNotReached(0))
|
||||
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.TerminalBlockHash = common.BytesToHash(bytesutil.PadTo([]byte{0x01}, 32))
|
||||
cfg.TerminalBlockHashActivationEpoch = 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
@ -112,7 +113,7 @@ func TestServer_getExecutionPayload(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.TerminalBlockHash = tt.terminalBlockHash
|
||||
cfg.TerminalBlockHashActivationEpoch = tt.activationEpoch
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
@ -198,6 +199,7 @@ func TestServer_getExecutionPayload_UnexpectedFeeRecipient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_getTerminalBlockHashIfExists(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
tests := []struct {
|
||||
name string
|
||||
paramsTerminalHash []byte
|
||||
@ -240,7 +242,7 @@ func TestServer_getTerminalBlockHashIfExists(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.TerminalTotalDifficulty = tt.paramsTd
|
||||
cfg.TerminalBlockHash = common.BytesToHash(tt.paramsTerminalHash)
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
@ -2585,7 +2585,7 @@ func setupGetBlock(bm *testing.B) (*Server, state.BeaconState, []bls.SecretKey)
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(bm)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
beaconState, privKeys := util.DeterministicGenesisState(bm, 64)
|
||||
|
||||
stateRoot, err := beaconState.HashTreeRoot(ctx)
|
||||
|
@ -93,7 +93,7 @@ func TestWaitForActivation_ContextClosed(t *testing.T) {
|
||||
func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
// This test breaks if it doesnt use mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
ctx := context.Background()
|
||||
|
||||
priv1, err := bls.RandKey()
|
||||
|
@ -236,7 +236,7 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
func TestValidatorStatus_Active(t *testing.T) {
|
||||
// This test breaks if it doesnt use mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
ctx := context.Background()
|
||||
|
||||
pubKey := pubKey(1)
|
||||
@ -439,7 +439,7 @@ func TestValidatorStatus_Exited(t *testing.T) {
|
||||
genesisRoot, err := block.Block.HashTreeRoot()
|
||||
require.NoError(t, err, "Could not get signing root")
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
params.OverrideBeaconConfig(params.MainnetConfig().Copy())
|
||||
state, err := util.NewBeaconState()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, state.SetSlot(slot))
|
||||
@ -603,12 +603,12 @@ func TestActivationStatus_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOptimisticStatus(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
server := &Server{OptimisticModeFetcher: &mockChain.ChainService{}, TimeFetcher: &mockChain.ChainService{}}
|
||||
err := server.optimisticStatus(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.BellatrixForkEpoch = 2
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
|
@ -37,7 +37,7 @@ func TestGetSyncMessageBlockRoot_OK(t *testing.T) {
|
||||
|
||||
func TestGetSyncMessageBlockRoot_Optimistic(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.BellatrixForkEpoch = 0
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
|
@ -50,7 +50,7 @@ func TestGetState(t *testing.T) {
|
||||
|
||||
t.Run("genesis", func(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.ConfigName = "test"
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
|
@ -127,7 +127,7 @@ func TestService_pruneSlasherDataWithinSlidingWindow_ProposalsPruned(t *testing.
|
||||
|
||||
// Override beacon config to 1 slot per epoch for easier testing.
|
||||
params2.SetupTestConfigCleanup(t)
|
||||
config := params2.BeaconConfig()
|
||||
config := params2.BeaconConfig().Copy()
|
||||
config.SlotsPerEpoch = 1
|
||||
params2.OverrideBeaconConfig(config)
|
||||
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
func init() {
|
||||
// Override network name so that hardcoded genesis files are not loaded.
|
||||
cfg := params.BeaconConfig()
|
||||
cfg.ConfigName = "test"
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
if err := params.SetActive(params.MainnetTestConfig()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func TestReplayBlocks_LowerSlotBlock(t *testing.T) {
|
||||
|
||||
func TestReplayBlocks_ThroughForkBoundary(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.BeaconConfig().Copy()
|
||||
bCfg.AltairForkEpoch = 1
|
||||
bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.AltairForkVersion)] = 1
|
||||
params.OverrideBeaconConfig(bCfg)
|
||||
@ -141,7 +141,7 @@ func TestReplayBlocks_ThroughForkBoundary(t *testing.T) {
|
||||
|
||||
func TestReplayBlocks_ThroughBellatrixForkBoundary(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.BeaconConfig().Copy()
|
||||
bCfg.AltairForkEpoch = 1
|
||||
bCfg.ForkVersionSchedule[bytesutil.ToBytes4(bCfg.AltairForkVersion)] = 1
|
||||
bCfg.BellatrixForkEpoch = 2
|
||||
|
@ -62,7 +62,7 @@ func TestService_CheckForNextEpochFork(t *testing.T) {
|
||||
Genesis: time.Now().Add(-4 * oneEpoch()),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
}
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.BeaconConfig().Copy()
|
||||
bCfg.AltairForkEpoch = 5
|
||||
params.OverrideBeaconConfig(bCfg)
|
||||
params.BeaconConfig().InitializeForkSchedule()
|
||||
@ -105,7 +105,7 @@ func TestService_CheckForNextEpochFork(t *testing.T) {
|
||||
Genesis: time.Now().Add(-4 * oneEpoch()),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
}
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.BeaconConfig().Copy()
|
||||
bCfg.AltairForkEpoch = 3
|
||||
bCfg.BellatrixForkEpoch = 5
|
||||
params.OverrideBeaconConfig(bCfg)
|
||||
@ -207,7 +207,7 @@ func TestService_CheckForPreviousEpochFork(t *testing.T) {
|
||||
Genesis: time.Now().Add(-4 * oneEpoch()),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
}
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.BeaconConfig().Copy()
|
||||
bCfg.AltairForkEpoch = 3
|
||||
params.OverrideBeaconConfig(bCfg)
|
||||
params.BeaconConfig().InitializeForkSchedule()
|
||||
@ -281,7 +281,7 @@ func TestService_CheckForPreviousEpochFork(t *testing.T) {
|
||||
Genesis: time.Now().Add(-4 * oneEpoch()),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
}
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.BeaconConfig().Copy()
|
||||
bCfg.AltairForkEpoch = 1
|
||||
bCfg.BellatrixForkEpoch = 3
|
||||
params.OverrideBeaconConfig(bCfg)
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
db "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
@ -20,6 +21,11 @@ import (
|
||||
)
|
||||
|
||||
func TestGoodByeRPCHandler_Disconnects_With_Peer(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.SecondsPerSlot = 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
|
@ -141,7 +141,7 @@ func TestMetadataRPCHandler_SendsMetadata(t *testing.T) {
|
||||
|
||||
func TestMetadataRPCHandler_SendsMetadataAltair(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
bCfg := params.BeaconConfig()
|
||||
bCfg := params.BeaconConfig().Copy()
|
||||
bCfg.AltairForkEpoch = 5
|
||||
params.OverrideBeaconConfig(bCfg)
|
||||
params.BeaconConfig().InitializeForkSchedule()
|
||||
|
@ -115,6 +115,11 @@ func TestSubscribe_UnsubscribeTopic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubscribe_ReceivesAttesterSlashing(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.SecondsPerSlot = 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
p2pService := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
d := db.SetupDB(t)
|
||||
@ -138,8 +143,6 @@ func TestSubscribe_ReceivesAttesterSlashing(t *testing.T) {
|
||||
topic := "/eth2/%x/attester_slashing"
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
var err error
|
||||
p2pService.Digest, err = r.currentForkDigest()
|
||||
require.NoError(t, err)
|
||||
@ -437,6 +440,11 @@ func Test_wrapAndReportValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFilterSubnetPeers(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.SecondsPerSlot = 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
gFlags := new(flags.GlobalFlags)
|
||||
gFlags.MinimumPeersPerSubnet = 4
|
||||
flags.Init(gFlags)
|
||||
@ -504,6 +512,11 @@ func TestFilterSubnetPeers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubscribeWithSyncSubnets_StaticOK(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.MainnetTestConfig().Copy()
|
||||
cfg.SecondsPerSlot = 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
currSlot := types.Slot(100)
|
||||
@ -530,11 +543,12 @@ func TestSubscribeWithSyncSubnets_StaticOK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubscribeWithSyncSubnets_DynamicOK(t *testing.T) {
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.MainnetConfig().Copy()
|
||||
cfg.SecondsPerSlot = 1
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
currSlot := types.Slot(100)
|
||||
r := Service{
|
||||
@ -611,9 +625,9 @@ func TestSubscribeWithSyncSubnets_StaticSwitchFork(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubscribeWithSyncSubnets_DynamicSwitchFork(t *testing.T) {
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.AltairForkEpoch = 1
|
||||
cfg.SecondsPerSlot = 1
|
||||
cfg.SlotsPerEpoch = 4
|
||||
|
@ -42,39 +42,53 @@ func InitWithReset(c *Flags) func() {
|
||||
|
||||
// ConfigureBeaconChain sets the global config based
|
||||
// on what flags are enabled for the beacon-chain client.
|
||||
func ConfigureBeaconChain(ctx *cli.Context) {
|
||||
cfg := newConfig(ctx)
|
||||
func ConfigureBeaconChain(ctx *cli.Context) error {
|
||||
cfg, err := newConfig(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ctx.IsSet(RPCMaxPageSizeFlag.Name) {
|
||||
cfg.MaxRPCPageSize = ctx.Int(RPCMaxPageSizeFlag.Name)
|
||||
log.Warnf("Starting beacon chain with max RPC page size of %d", cfg.MaxRPCPageSize)
|
||||
}
|
||||
Init(cfg)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigureValidator sets the global config based
|
||||
// on what flags are enabled for the validator client.
|
||||
func ConfigureValidator(ctx *cli.Context) {
|
||||
cfg := newConfig(ctx)
|
||||
func ConfigureValidator(ctx *cli.Context) error {
|
||||
cfg, err := newConfig(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Init(cfg)
|
||||
return nil
|
||||
}
|
||||
|
||||
func newConfig(ctx *cli.Context) *Flags {
|
||||
func newConfig(ctx *cli.Context) (*Flags, error) {
|
||||
cfg := Get()
|
||||
if ctx.Bool(MinimalConfigFlag.Name) {
|
||||
log.Warn("Using minimal config")
|
||||
cfg.MinimalConfig = true
|
||||
params.UseMinimalConfig()
|
||||
if err := params.SetActive(params.MinimalSpecConfig().Copy()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if ctx.Bool(E2EConfigFlag.Name) {
|
||||
log.Warn("Using end-to-end testing config")
|
||||
switch fieldparams.Preset {
|
||||
case "mainnet":
|
||||
params.UseE2EMainnetConfig()
|
||||
if err := params.SetActive(params.E2EMainnetTestConfig().Copy()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case "minimal":
|
||||
params.UseE2EConfig()
|
||||
if err := params.SetActive(params.E2ETestConfig().Copy()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
log.Fatalf("Unrecognized preset being used: %s", fieldparams.Preset)
|
||||
}
|
||||
}
|
||||
return cfg
|
||||
return cfg, nil
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -37,7 +38,7 @@ func TestConfigureBeaconConfig(t *testing.T) {
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.Bool(MinimalConfigFlag.Name, true, "test")
|
||||
context := cli.NewContext(&app, set, nil)
|
||||
ConfigureBeaconChain(context)
|
||||
require.NoError(t, ConfigureBeaconChain(context))
|
||||
c := Get()
|
||||
assert.Equal(t, true, c.MinimalConfig)
|
||||
}
|
||||
|
@ -39,7 +39,9 @@ var Commands = &cli.Command{
|
||||
if err := tos.VerifyTosAcceptedOrPrompt(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
@ -76,7 +78,9 @@ var Commands = &cli.Command{
|
||||
if err := tos.VerifyTosAcceptedOrPrompt(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
@ -110,7 +114,9 @@ var Commands = &cli.Command{
|
||||
return tos.VerifyTosAcceptedOrPrompt(cliCtx)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := accounts.BackupAccountsCli(cliCtx); err != nil {
|
||||
log.Fatalf("Could not backup accounts: %v", err)
|
||||
}
|
||||
@ -138,7 +144,9 @@ var Commands = &cli.Command{
|
||||
return tos.VerifyTosAcceptedOrPrompt(cliCtx)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := accounts.ImportAccountsCli(cliCtx); err != nil {
|
||||
log.Fatalf("Could not import accounts: %v", err)
|
||||
}
|
||||
@ -172,7 +180,9 @@ var Commands = &cli.Command{
|
||||
return tos.VerifyTosAcceptedOrPrompt(cliCtx)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := accounts.ExitAccountsCli(cliCtx, os.Stdin); err != nil {
|
||||
log.Fatalf("Could not perform voluntary exit: %v", err)
|
||||
}
|
||||
|
@ -33,7 +33,9 @@ var Commands = &cli.Command{
|
||||
return tos.VerifyTosAcceptedOrPrompt(cliCtx)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := exportSlashingProtectionJSON(cliCtx); err != nil {
|
||||
logrus.Fatalf("Could not export slashing protection file: %v", err)
|
||||
}
|
||||
@ -58,7 +60,9 @@ var Commands = &cli.Command{
|
||||
return tos.VerifyTosAcceptedOrPrompt(cliCtx)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
err := importSlashingProtectionJSON(cliCtx)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Could not import slashing protection cli: %v", err)
|
||||
|
@ -45,7 +45,9 @@ var Commands = &cli.Command{
|
||||
return tos.VerifyTosAcceptedOrPrompt(cliCtx)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := accounts.CreateAndSaveWalletCli(cliCtx); err != nil {
|
||||
log.Fatalf("Could not create a wallet: %v", err)
|
||||
}
|
||||
@ -75,7 +77,9 @@ var Commands = &cli.Command{
|
||||
return tos.VerifyTosAcceptedOrPrompt(cliCtx)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := accounts.EditWalletConfigurationCli(cliCtx); err != nil {
|
||||
log.Fatalf("Could not edit wallet configuration: %v", err)
|
||||
}
|
||||
@ -104,7 +108,9 @@ var Commands = &cli.Command{
|
||||
return tos.VerifyTosAcceptedOrPrompt(cliCtx)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := accounts.RecoverWalletCli(cliCtx); err != nil {
|
||||
log.Fatalf("Could not recover wallet: %v", err)
|
||||
}
|
||||
|
@ -33,7 +33,9 @@ var Commands = &cli.Command{
|
||||
return tos.VerifyTosAcceptedOrPrompt(cliCtx)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
features.ConfigureValidator(cliCtx)
|
||||
if err := features.ConfigureValidator(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
walletDirPath := cliCtx.String(flags.WalletDirFlag.Name)
|
||||
if walletDirPath == "" {
|
||||
log.Fatal("--wallet-dir not specified")
|
||||
|
@ -27,6 +27,7 @@ go_test(
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"@com_github_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -110,30 +110,39 @@ func InitWithReset(c *Flags) func() {
|
||||
}
|
||||
|
||||
// configureTestnet sets the config according to specified testnet flag
|
||||
func configureTestnet(ctx *cli.Context) {
|
||||
func configureTestnet(ctx *cli.Context) error {
|
||||
if ctx.Bool(PraterTestnet.Name) {
|
||||
log.Warn("Running on the Prater Testnet")
|
||||
params.UsePraterConfig()
|
||||
if err := params.SetActive(params.PraterConfig().Copy()); err != nil {
|
||||
return err
|
||||
}
|
||||
params.UsePraterNetworkConfig()
|
||||
} else if ctx.Bool(RopstenTestnet.Name) {
|
||||
log.Warn("Running on the Ropsten Beacon Chain Testnet")
|
||||
params.UseRopstenConfig()
|
||||
if err := params.SetActive(params.RopstenConfig().Copy()); err != nil {
|
||||
return err
|
||||
}
|
||||
params.UseRopstenNetworkConfig()
|
||||
} else {
|
||||
log.Warn("Running on Ethereum Consensus Mainnet")
|
||||
params.UseMainnetConfig()
|
||||
if err := params.SetActive(params.MainnetConfig().Copy()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigureBeaconChain sets the global config based
|
||||
// on what flags are enabled for the beacon-chain client.
|
||||
func ConfigureBeaconChain(ctx *cli.Context) {
|
||||
func ConfigureBeaconChain(ctx *cli.Context) error {
|
||||
complainOnDeprecatedFlags(ctx)
|
||||
cfg := &Flags{}
|
||||
if ctx.Bool(devModeFlag.Name) {
|
||||
enableDevModeFlags(ctx)
|
||||
}
|
||||
configureTestnet(ctx)
|
||||
if err := configureTestnet(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ctx.Bool(writeSSZStateTransitionsFlag.Name) {
|
||||
logEnabled(writeSSZStateTransitionsFlag)
|
||||
@ -190,14 +199,17 @@ func ConfigureBeaconChain(ctx *cli.Context) {
|
||||
cfg.EnableBatchGossipAggregation = true
|
||||
}
|
||||
Init(cfg)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigureValidator sets the global config based
|
||||
// on what flags are enabled for the validator client.
|
||||
func ConfigureValidator(ctx *cli.Context) {
|
||||
func ConfigureValidator(ctx *cli.Context) error {
|
||||
complainOnDeprecatedFlags(ctx)
|
||||
cfg := &Flags{}
|
||||
configureTestnet(ctx)
|
||||
if err := configureTestnet(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if ctx.Bool(enableExternalSlasherProtectionFlag.Name) {
|
||||
log.Fatal(
|
||||
"Remote slashing protection has currently been disabled in Prysm due to safety concerns. " +
|
||||
@ -226,6 +238,7 @@ func ConfigureValidator(ctx *cli.Context) {
|
||||
}
|
||||
cfg.KeystoreImportDebounceInterval = ctx.Duration(dynamicKeyReloadDebounceInterval.Name)
|
||||
Init(cfg)
|
||||
return nil
|
||||
}
|
||||
|
||||
// enableDevModeFlags switches development mode features on.
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -45,7 +46,7 @@ func TestConfigureBeaconConfig(t *testing.T) {
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.Bool(enablePeerScorer.Name, true, "test")
|
||||
context := cli.NewContext(&app, set, nil)
|
||||
ConfigureBeaconChain(context)
|
||||
require.NoError(t, ConfigureBeaconChain(context))
|
||||
c := Get()
|
||||
assert.Equal(t, true, c.EnablePeerScorer)
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ go_test(
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@ -30,9 +30,10 @@ go_test(
|
||||
"minimal_test.go",
|
||||
],
|
||||
eth_network = "minimal",
|
||||
tags = ["minimal"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -5,18 +5,18 @@ import (
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func testFieldParametersMatchConfig(t *testing.T) {
|
||||
assert.Equal(t, uint64(params.BeaconConfig().SlotsPerHistoricalRoot), uint64(fieldparams.BlockRootsLength))
|
||||
assert.Equal(t, uint64(params.BeaconConfig().SlotsPerHistoricalRoot), uint64(fieldparams.StateRootsLength))
|
||||
assert.Equal(t, params.BeaconConfig().HistoricalRootsLimit, uint64(fieldparams.HistoricalRootsLength))
|
||||
assert.Equal(t, uint64(params.BeaconConfig().EpochsPerHistoricalVector), uint64(fieldparams.RandaoMixesLength))
|
||||
assert.Equal(t, params.BeaconConfig().ValidatorRegistryLimit, uint64(fieldparams.ValidatorRegistryLimit))
|
||||
assert.Equal(t, uint64(params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().EpochsPerEth1VotingPeriod))), uint64(fieldparams.Eth1DataVotesLength))
|
||||
assert.Equal(t, uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().MaxAttestations)), uint64(fieldparams.PreviousEpochAttestationsLength))
|
||||
assert.Equal(t, uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().MaxAttestations)), uint64(fieldparams.CurrentEpochAttestationsLength))
|
||||
assert.Equal(t, uint64(params.BeaconConfig().EpochsPerSlashingsVector), uint64(fieldparams.SlashingsLength))
|
||||
assert.Equal(t, params.BeaconConfig().SyncCommitteeSize, uint64(fieldparams.SyncCommitteeLength))
|
||||
require.Equal(t, uint64(params.BeaconConfig().SlotsPerHistoricalRoot), uint64(fieldparams.BlockRootsLength))
|
||||
require.Equal(t, uint64(params.BeaconConfig().SlotsPerHistoricalRoot), uint64(fieldparams.StateRootsLength))
|
||||
require.Equal(t, params.BeaconConfig().HistoricalRootsLimit, uint64(fieldparams.HistoricalRootsLength))
|
||||
require.Equal(t, uint64(params.BeaconConfig().EpochsPerHistoricalVector), uint64(fieldparams.RandaoMixesLength))
|
||||
require.Equal(t, params.BeaconConfig().ValidatorRegistryLimit, uint64(fieldparams.ValidatorRegistryLimit))
|
||||
require.Equal(t, uint64(params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().EpochsPerEth1VotingPeriod))), uint64(fieldparams.Eth1DataVotesLength))
|
||||
require.Equal(t, uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().MaxAttestations)), uint64(fieldparams.PreviousEpochAttestationsLength))
|
||||
require.Equal(t, uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().MaxAttestations)), uint64(fieldparams.CurrentEpochAttestationsLength))
|
||||
require.Equal(t, uint64(params.BeaconConfig().EpochsPerSlashingsVector), uint64(fieldparams.SlashingsLength))
|
||||
require.Equal(t, params.BeaconConfig().SyncCommitteeSize, uint64(fieldparams.SyncCommitteeLength))
|
||||
}
|
||||
|
@ -8,11 +8,17 @@ import (
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestFieldParametersValues(t *testing.T) {
|
||||
params.UseMainnetConfig()
|
||||
assert.Equal(t, "mainnet", fieldparams.Preset)
|
||||
min, err := params.ByName(params.MainnetName)
|
||||
require.NoError(t, err)
|
||||
undo, err := params.SetActiveWithUndo(min)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, undo())
|
||||
}()
|
||||
require.Equal(t, "mainnet", fieldparams.Preset)
|
||||
testFieldParametersMatchConfig(t)
|
||||
}
|
||||
|
@ -8,11 +8,13 @@ import (
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestFieldParametersValues(t *testing.T) {
|
||||
params.UseMinimalConfig()
|
||||
assert.Equal(t, "minimal", fieldparams.Preset)
|
||||
params.SetupTestConfigCleanup(t)
|
||||
min := params.MinimalSpecConfig().Copy()
|
||||
params.OverrideBeaconConfig(min)
|
||||
require.Equal(t, "minimal", fieldparams.Preset)
|
||||
testFieldParametersMatchConfig(t)
|
||||
}
|
||||
|
@ -6,12 +6,14 @@ go_library(
|
||||
"config.go",
|
||||
"config_utils_develop.go", # keep
|
||||
"config_utils_prod.go",
|
||||
"configset.go",
|
||||
"init.go",
|
||||
"interop.go",
|
||||
"io_config.go",
|
||||
"loader.go",
|
||||
"mainnet_config.go",
|
||||
"minimal_config.go",
|
||||
"network_config.go",
|
||||
"registry.go",
|
||||
"testnet_e2e_config.go",
|
||||
"testnet_prater_config.go",
|
||||
"testnet_ropsten_config.go",
|
||||
@ -40,6 +42,7 @@ go_test(
|
||||
srcs = [
|
||||
"checktags_test.go",
|
||||
"config_test.go",
|
||||
"configset_test.go",
|
||||
"loader_test.go",
|
||||
"testnet_config_test.go",
|
||||
"testnet_prater_config_test.go",
|
||||
@ -51,10 +54,11 @@ go_test(
|
||||
"@eth2_networks//:configs",
|
||||
"testdata/e2e_config.yaml",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
gotags = ["develop"],
|
||||
race = "on",
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//io/file:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
|
@ -34,6 +34,7 @@ func TestConfig_OverrideBeaconConfigTestTeardown(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfig_DataRace(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
for i := 0; i < 10; i++ {
|
||||
go func() {
|
||||
cfg := params.BeaconConfig()
|
||||
|
@ -9,14 +9,13 @@ import (
|
||||
"github.com/mohae/deepcopy"
|
||||
)
|
||||
|
||||
var beaconConfig = MainnetConfig()
|
||||
var beaconConfigLock sync.RWMutex
|
||||
var cfgrw sync.RWMutex
|
||||
|
||||
// BeaconConfig retrieves beacon chain config.
|
||||
func BeaconConfig() *BeaconChainConfig {
|
||||
beaconConfigLock.RLock()
|
||||
defer beaconConfigLock.RUnlock()
|
||||
return beaconConfig
|
||||
cfgrw.RLock()
|
||||
defer cfgrw.RUnlock()
|
||||
return configs.getActive()
|
||||
}
|
||||
|
||||
// OverrideBeaconConfig by replacing the config. The preferred pattern is to
|
||||
@ -24,18 +23,18 @@ func BeaconConfig() *BeaconChainConfig {
|
||||
// OverrideBeaconConfig(c). Any subsequent calls to params.BeaconConfig() will
|
||||
// return this new configuration.
|
||||
func OverrideBeaconConfig(c *BeaconChainConfig) {
|
||||
beaconConfigLock.Lock()
|
||||
defer beaconConfigLock.Unlock()
|
||||
beaconConfig = c
|
||||
cfgrw.Lock()
|
||||
defer cfgrw.Unlock()
|
||||
configs.active = c
|
||||
}
|
||||
|
||||
// Copy returns a copy of the config object.
|
||||
func (b *BeaconChainConfig) Copy() *BeaconChainConfig {
|
||||
beaconConfigLock.RLock()
|
||||
defer beaconConfigLock.RUnlock()
|
||||
cfgrw.RLock()
|
||||
defer cfgrw.RUnlock()
|
||||
config, ok := deepcopy.Copy(*b).(BeaconChainConfig)
|
||||
if !ok {
|
||||
config = *beaconConfig
|
||||
panic("somehow deepcopy produced a BeaconChainConfig that is not of the same type as the original")
|
||||
}
|
||||
return &config
|
||||
}
|
||||
|
@ -7,11 +7,9 @@ import (
|
||||
"github.com/mohae/deepcopy"
|
||||
)
|
||||
|
||||
var beaconConfig = MainnetConfig()
|
||||
|
||||
// BeaconConfig retrieves beacon chain config.
|
||||
func BeaconConfig() *BeaconChainConfig {
|
||||
return beaconConfig
|
||||
return configs.getActive()
|
||||
}
|
||||
|
||||
// OverrideBeaconConfig by replacing the config. The preferred pattern is to
|
||||
@ -19,14 +17,14 @@ func BeaconConfig() *BeaconChainConfig {
|
||||
// OverrideBeaconConfig(c). Any subsequent calls to params.BeaconConfig() will
|
||||
// return this new configuration.
|
||||
func OverrideBeaconConfig(c *BeaconChainConfig) {
|
||||
beaconConfig = c
|
||||
configs.active = c
|
||||
}
|
||||
|
||||
// Copy returns a copy of the config object.
|
||||
func (b *BeaconChainConfig) Copy() *BeaconChainConfig {
|
||||
config, ok := deepcopy.Copy(*b).(BeaconChainConfig)
|
||||
if !ok {
|
||||
config = *beaconConfig
|
||||
panic("somehow deepcopy produced a BeaconChainConfig that is not of the same type as the original")
|
||||
}
|
||||
return &config
|
||||
}
|
||||
|
171
config/params/configset.go
Normal file
171
config/params/configset.go
Normal file
@ -0,0 +1,171 @@
|
||||
package params
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
)
|
||||
|
||||
var configs *configset
|
||||
|
||||
// All returns a slice of every BeaconChainConfig contained in the configset.
|
||||
func All() []*BeaconChainConfig {
|
||||
return configs.all()
|
||||
}
|
||||
|
||||
// ByName returns the BeaconChainConfig with the matching `ConfigName` field.
|
||||
// The runtime ensures that each config name uniquely refers to a single BeaconChainConfig.
|
||||
func ByName(name string) (*BeaconChainConfig, error) {
|
||||
return configs.byName(name)
|
||||
}
|
||||
|
||||
// ByVersion returns the BeaconChainConfig that has the given version in its ForkVersionSchedule.
|
||||
// The configset ensures that each fork version schedule entry uniquely points to a single BeaconChainConfig.
|
||||
func ByVersion(version [fieldparams.VersionLength]byte) (*BeaconChainConfig, error) {
|
||||
return configs.byVersion(version)
|
||||
}
|
||||
|
||||
// SetActive sets the given config as active (the config that will be returned by GetActive).
|
||||
// SetActive will always overwrite any config with the same ConfigName before setting the updated value to active.
|
||||
func SetActive(c *BeaconChainConfig) error {
|
||||
return configs.setActive(c)
|
||||
}
|
||||
|
||||
// SetActiveWithUndo attempts to set the active config, and if successful,
|
||||
// returns a callback function that can be used to revert the configset back to its previous state.
|
||||
func SetActiveWithUndo(c *BeaconChainConfig) (func() error, error) {
|
||||
return configs.setActiveWithUndo(c)
|
||||
}
|
||||
|
||||
type configset struct {
|
||||
active *BeaconChainConfig
|
||||
versionToName map[[fieldparams.VersionLength]byte]string
|
||||
nameToConfig map[string]*BeaconChainConfig
|
||||
}
|
||||
|
||||
func newConfigset(configs ...*BeaconChainConfig) *configset {
|
||||
r := &configset{
|
||||
versionToName: make(map[[fieldparams.VersionLength]byte]string),
|
||||
nameToConfig: make(map[string]*BeaconChainConfig),
|
||||
}
|
||||
for _, c := range configs {
|
||||
if err := r.add(c); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
var errCannotNullifyActive = errors.New("cannot set a config marked as active to nil")
|
||||
var errCollisionFork = errors.New("configset cannot add config with conflicting fork version schedule")
|
||||
var errCollisionName = errors.New("config with conflicting name already exists")
|
||||
var errConfigNotFound = errors.New("unable to find requested BeaconChainConfig")
|
||||
var errReplaceNilConfig = errors.New("replace called with a nil value")
|
||||
|
||||
func (r *configset) add(c *BeaconChainConfig) error {
|
||||
name := c.ConfigName
|
||||
if _, exists := r.nameToConfig[name]; exists {
|
||||
return errors.Wrapf(errCollisionName, "ConfigName=%s", name)
|
||||
}
|
||||
c.InitializeForkSchedule()
|
||||
for v := range c.ForkVersionSchedule {
|
||||
if n, exists := r.versionToName[v]; exists {
|
||||
return errors.Wrapf(errCollisionFork, "config name=%s conflicts with existing config named=%s", name, n)
|
||||
}
|
||||
r.versionToName[v] = name
|
||||
}
|
||||
r.nameToConfig[name] = c
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *configset) delete(name string) {
|
||||
c, exists := r.nameToConfig[name]
|
||||
if !exists {
|
||||
return
|
||||
}
|
||||
for v := range c.ForkVersionSchedule {
|
||||
delete(r.versionToName, v)
|
||||
}
|
||||
delete(r.nameToConfig, name)
|
||||
}
|
||||
|
||||
func (r *configset) replace(cfg *BeaconChainConfig) error {
|
||||
if cfg == nil {
|
||||
return errReplaceNilConfig
|
||||
}
|
||||
name := cfg.ConfigName
|
||||
r.delete(name)
|
||||
if err := r.add(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
if r.active != nil && r.active.ConfigName == name {
|
||||
r.active = cfg
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *configset) replaceWithUndo(cfg *BeaconChainConfig) (func() error, error) {
|
||||
name := cfg.ConfigName
|
||||
prev := r.nameToConfig[name]
|
||||
if err := r.replace(cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return func() error {
|
||||
if prev == nil {
|
||||
if r.active.ConfigName == name {
|
||||
return errors.Wrapf(errCannotNullifyActive, "active config name=%s", name)
|
||||
}
|
||||
r.delete(name)
|
||||
return nil
|
||||
}
|
||||
return r.replace(prev)
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *configset) getActive() *BeaconChainConfig {
|
||||
return r.active
|
||||
}
|
||||
|
||||
func (r *configset) setActive(c *BeaconChainConfig) error {
|
||||
if err := r.replace(c); err != nil {
|
||||
return err
|
||||
}
|
||||
r.active = c
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *configset) setActiveWithUndo(c *BeaconChainConfig) (func() error, error) {
|
||||
active := r.active
|
||||
r.active = c
|
||||
undo, err := r.replaceWithUndo(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return func() error {
|
||||
r.active = active
|
||||
return undo()
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *configset) byName(name string) (*BeaconChainConfig, error) {
|
||||
c, ok := r.nameToConfig[name]
|
||||
if !ok {
|
||||
return nil, errors.Wrapf(errConfigNotFound, "name=%s is not a known BeaconChainConfig name", name)
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (r *configset) byVersion(version [fieldparams.VersionLength]byte) (*BeaconChainConfig, error) {
|
||||
name, ok := r.versionToName[version]
|
||||
if !ok {
|
||||
return nil, errors.Wrapf(errConfigNotFound, "version=%#x not found in any known fork choice schedule", version)
|
||||
}
|
||||
return r.byName(name)
|
||||
}
|
||||
|
||||
func (r *configset) all() []*BeaconChainConfig {
|
||||
all := make([]*BeaconChainConfig, 0)
|
||||
for _, c := range r.nameToConfig {
|
||||
all = append(all, c)
|
||||
}
|
||||
return all
|
||||
}
|
203
config/params/configset_test.go
Normal file
203
config/params/configset_test.go
Normal file
@ -0,0 +1,203 @@
|
||||
package params
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestConfigset_Add(t *testing.T) {
|
||||
r := newConfigset()
|
||||
name := "devnet"
|
||||
cfg := testConfig(name)
|
||||
require.NoError(t, r.add(cfg))
|
||||
c, err := r.byName(name)
|
||||
require.NoError(t, err)
|
||||
compareConfigs(t, cfg, c)
|
||||
require.ErrorIs(t, r.add(cfg), errCollisionName)
|
||||
cfg.ConfigName = "test"
|
||||
require.ErrorIs(t, r.add(cfg), errCollisionFork)
|
||||
}
|
||||
|
||||
func TestConfigsetReplaceMainnet(t *testing.T) {
|
||||
r := newConfigset()
|
||||
mainnet := MainnetConfig().Copy()
|
||||
require.NoError(t, r.setActive(mainnet))
|
||||
FillTestVersions(mainnet, 128)
|
||||
require.NoError(t, r.replace(mainnet))
|
||||
}
|
||||
|
||||
func TestConfigset_Replace(t *testing.T) {
|
||||
r := newConfigset()
|
||||
mainnet := MainnetConfig().Copy()
|
||||
require.NoError(t, r.add(mainnet))
|
||||
require.NoError(t, r.setActive(mainnet))
|
||||
require.ErrorIs(t, r.add(mainnet), errCollisionName)
|
||||
c, err := r.byName(MainnetName)
|
||||
require.NoError(t, err)
|
||||
fail := c.Copy()
|
||||
fail.ConfigName = "test"
|
||||
require.ErrorIs(t, r.replace(fail), errCollisionFork)
|
||||
|
||||
o := c.Copy()
|
||||
FillTestVersions(o, 128)
|
||||
o.ConfigName = MainnetName
|
||||
require.NoError(t, r.replace(o))
|
||||
// mainnet is replaced, we shouldn't be able to find its fork version anymore
|
||||
_, err = r.byVersion(bytesutil.ToBytes4(mainnet.GenesisForkVersion))
|
||||
require.ErrorIs(t, err, errConfigNotFound)
|
||||
undo := o.Copy()
|
||||
FillTestVersions(undo, 127)
|
||||
undoFunc, err := r.replaceWithUndo(undo)
|
||||
require.NoError(t, err)
|
||||
u, err := r.byName(undo.ConfigName)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, undo, u)
|
||||
u, err = r.byVersion(bytesutil.ToBytes4(undo.GenesisForkVersion))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, undo, u)
|
||||
_, err = r.byVersion(bytesutil.ToBytes4(o.GenesisForkVersion))
|
||||
require.ErrorIs(t, err, errConfigNotFound)
|
||||
require.NoError(t, undoFunc())
|
||||
// replaced config restored by undoFunc, lookup should now succeed
|
||||
_, err = r.byVersion(bytesutil.ToBytes4(o.GenesisForkVersion))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func testConfig(name string) *BeaconChainConfig {
|
||||
c := MainnetConfig().Copy()
|
||||
FillTestVersions(c, 127)
|
||||
c.ConfigName = name
|
||||
return c
|
||||
}
|
||||
|
||||
func compareConfigs(t *testing.T, expected, actual *BeaconChainConfig) {
|
||||
require.DeepEqual(t, expected.GenesisEpoch, actual.GenesisEpoch)
|
||||
require.DeepEqual(t, expected.FarFutureEpoch, actual.FarFutureEpoch)
|
||||
require.DeepEqual(t, expected.FarFutureSlot, actual.FarFutureSlot)
|
||||
require.DeepEqual(t, expected.BaseRewardsPerEpoch, actual.BaseRewardsPerEpoch)
|
||||
require.DeepEqual(t, expected.DepositContractTreeDepth, actual.DepositContractTreeDepth)
|
||||
require.DeepEqual(t, expected.JustificationBitsLength, actual.JustificationBitsLength)
|
||||
require.DeepEqual(t, expected.PresetBase, actual.PresetBase)
|
||||
require.DeepEqual(t, expected.ConfigName, actual.ConfigName)
|
||||
require.DeepEqual(t, expected.TargetCommitteeSize, actual.TargetCommitteeSize)
|
||||
require.DeepEqual(t, expected.MaxValidatorsPerCommittee, actual.MaxValidatorsPerCommittee)
|
||||
require.DeepEqual(t, expected.MaxCommitteesPerSlot, actual.MaxCommitteesPerSlot)
|
||||
require.DeepEqual(t, expected.MinPerEpochChurnLimit, actual.MinPerEpochChurnLimit)
|
||||
require.DeepEqual(t, expected.ChurnLimitQuotient, actual.ChurnLimitQuotient)
|
||||
require.DeepEqual(t, expected.ShuffleRoundCount, actual.ShuffleRoundCount)
|
||||
require.DeepEqual(t, expected.MinGenesisActiveValidatorCount, actual.MinGenesisActiveValidatorCount)
|
||||
require.DeepEqual(t, expected.MinGenesisTime, actual.MinGenesisTime)
|
||||
require.DeepEqual(t, expected.TargetAggregatorsPerCommittee, actual.TargetAggregatorsPerCommittee)
|
||||
require.DeepEqual(t, expected.HysteresisQuotient, actual.HysteresisQuotient)
|
||||
require.DeepEqual(t, expected.HysteresisDownwardMultiplier, actual.HysteresisDownwardMultiplier)
|
||||
require.DeepEqual(t, expected.HysteresisUpwardMultiplier, actual.HysteresisUpwardMultiplier)
|
||||
require.DeepEqual(t, expected.MinDepositAmount, actual.MinDepositAmount)
|
||||
require.DeepEqual(t, expected.MaxEffectiveBalance, actual.MaxEffectiveBalance)
|
||||
require.DeepEqual(t, expected.EjectionBalance, actual.EjectionBalance)
|
||||
require.DeepEqual(t, expected.EffectiveBalanceIncrement, actual.EffectiveBalanceIncrement)
|
||||
require.DeepEqual(t, expected.BLSWithdrawalPrefixByte, actual.BLSWithdrawalPrefixByte)
|
||||
require.DeepEqual(t, expected.ZeroHash, actual.ZeroHash)
|
||||
require.DeepEqual(t, expected.GenesisDelay, actual.GenesisDelay)
|
||||
require.DeepEqual(t, expected.MinAttestationInclusionDelay, actual.MinAttestationInclusionDelay)
|
||||
require.DeepEqual(t, expected.SecondsPerSlot, actual.SecondsPerSlot)
|
||||
require.DeepEqual(t, expected.SlotsPerEpoch, actual.SlotsPerEpoch)
|
||||
require.DeepEqual(t, expected.SqrRootSlotsPerEpoch, actual.SqrRootSlotsPerEpoch)
|
||||
require.DeepEqual(t, expected.MinSeedLookahead, actual.MinSeedLookahead)
|
||||
require.DeepEqual(t, expected.MaxSeedLookahead, actual.MaxSeedLookahead)
|
||||
require.DeepEqual(t, expected.EpochsPerEth1VotingPeriod, actual.EpochsPerEth1VotingPeriod)
|
||||
require.DeepEqual(t, expected.SlotsPerHistoricalRoot, actual.SlotsPerHistoricalRoot)
|
||||
require.DeepEqual(t, expected.MinValidatorWithdrawabilityDelay, actual.MinValidatorWithdrawabilityDelay)
|
||||
require.DeepEqual(t, expected.ShardCommitteePeriod, actual.ShardCommitteePeriod)
|
||||
require.DeepEqual(t, expected.MinEpochsToInactivityPenalty, actual.MinEpochsToInactivityPenalty)
|
||||
require.DeepEqual(t, expected.Eth1FollowDistance, actual.Eth1FollowDistance)
|
||||
require.DeepEqual(t, expected.SafeSlotsToUpdateJustified, actual.SafeSlotsToUpdateJustified)
|
||||
require.DeepEqual(t, expected.SafeSlotsToImportOptimistically, actual.SafeSlotsToImportOptimistically)
|
||||
require.DeepEqual(t, expected.SecondsPerETH1Block, actual.SecondsPerETH1Block)
|
||||
require.DeepEqual(t, expected.ProposerScoreBoost, actual.ProposerScoreBoost)
|
||||
require.DeepEqual(t, expected.IntervalsPerSlot, actual.IntervalsPerSlot)
|
||||
require.DeepEqual(t, expected.DepositChainID, actual.DepositChainID)
|
||||
require.DeepEqual(t, expected.DepositNetworkID, actual.DepositNetworkID)
|
||||
require.DeepEqual(t, expected.DepositContractAddress, actual.DepositContractAddress)
|
||||
require.DeepEqual(t, expected.RandomSubnetsPerValidator, actual.RandomSubnetsPerValidator)
|
||||
require.DeepEqual(t, expected.EpochsPerRandomSubnetSubscription, actual.EpochsPerRandomSubnetSubscription)
|
||||
require.DeepEqual(t, expected.EpochsPerHistoricalVector, actual.EpochsPerHistoricalVector)
|
||||
require.DeepEqual(t, expected.EpochsPerSlashingsVector, actual.EpochsPerSlashingsVector)
|
||||
require.DeepEqual(t, expected.HistoricalRootsLimit, actual.HistoricalRootsLimit)
|
||||
require.DeepEqual(t, expected.ValidatorRegistryLimit, actual.ValidatorRegistryLimit)
|
||||
require.DeepEqual(t, expected.BaseRewardFactor, actual.BaseRewardFactor)
|
||||
require.DeepEqual(t, expected.WhistleBlowerRewardQuotient, actual.WhistleBlowerRewardQuotient)
|
||||
require.DeepEqual(t, expected.ProposerRewardQuotient, actual.ProposerRewardQuotient)
|
||||
require.DeepEqual(t, expected.InactivityPenaltyQuotient, actual.InactivityPenaltyQuotient)
|
||||
require.DeepEqual(t, expected.MinSlashingPenaltyQuotient, actual.MinSlashingPenaltyQuotient)
|
||||
require.DeepEqual(t, expected.ProportionalSlashingMultiplier, actual.ProportionalSlashingMultiplier)
|
||||
require.DeepEqual(t, expected.MaxProposerSlashings, actual.MaxProposerSlashings)
|
||||
require.DeepEqual(t, expected.MaxAttesterSlashings, actual.MaxAttesterSlashings)
|
||||
require.DeepEqual(t, expected.MaxAttestations, actual.MaxAttestations)
|
||||
require.DeepEqual(t, expected.MaxDeposits, actual.MaxDeposits)
|
||||
require.DeepEqual(t, expected.MaxVoluntaryExits, actual.MaxVoluntaryExits)
|
||||
require.DeepEqual(t, expected.DomainBeaconProposer, actual.DomainBeaconProposer)
|
||||
require.DeepEqual(t, expected.DomainRandao, actual.DomainRandao)
|
||||
require.DeepEqual(t, expected.DomainBeaconAttester, actual.DomainBeaconAttester)
|
||||
require.DeepEqual(t, expected.DomainDeposit, actual.DomainDeposit)
|
||||
require.DeepEqual(t, expected.DomainVoluntaryExit, actual.DomainVoluntaryExit)
|
||||
require.DeepEqual(t, expected.DomainSelectionProof, actual.DomainSelectionProof)
|
||||
require.DeepEqual(t, expected.DomainAggregateAndProof, actual.DomainAggregateAndProof)
|
||||
require.DeepEqual(t, expected.DomainSyncCommittee, actual.DomainSyncCommittee)
|
||||
require.DeepEqual(t, expected.DomainSyncCommitteeSelectionProof, actual.DomainSyncCommitteeSelectionProof)
|
||||
require.DeepEqual(t, expected.DomainContributionAndProof, actual.DomainContributionAndProof)
|
||||
require.DeepEqual(t, expected.GweiPerEth, actual.GweiPerEth)
|
||||
require.DeepEqual(t, expected.BLSSecretKeyLength, actual.BLSSecretKeyLength)
|
||||
require.DeepEqual(t, expected.BLSPubkeyLength, actual.BLSPubkeyLength)
|
||||
require.DeepEqual(t, expected.DefaultBufferSize, actual.DefaultBufferSize)
|
||||
require.DeepEqual(t, expected.ValidatorPrivkeyFileName, actual.ValidatorPrivkeyFileName)
|
||||
require.DeepEqual(t, expected.WithdrawalPrivkeyFileName, actual.WithdrawalPrivkeyFileName)
|
||||
require.DeepEqual(t, expected.RPCSyncCheck, actual.RPCSyncCheck)
|
||||
require.DeepEqual(t, expected.EmptySignature, actual.EmptySignature)
|
||||
require.DeepEqual(t, expected.DefaultPageSize, actual.DefaultPageSize)
|
||||
require.DeepEqual(t, expected.MaxPeersToSync, actual.MaxPeersToSync)
|
||||
require.DeepEqual(t, expected.SlotsPerArchivedPoint, actual.SlotsPerArchivedPoint)
|
||||
require.DeepEqual(t, expected.GenesisCountdownInterval, actual.GenesisCountdownInterval)
|
||||
require.DeepEqual(t, expected.BeaconStateFieldCount, actual.BeaconStateFieldCount)
|
||||
require.DeepEqual(t, expected.BeaconStateAltairFieldCount, actual.BeaconStateAltairFieldCount)
|
||||
require.DeepEqual(t, expected.BeaconStateBellatrixFieldCount, actual.BeaconStateBellatrixFieldCount)
|
||||
require.DeepEqual(t, expected.WeakSubjectivityPeriod, actual.WeakSubjectivityPeriod)
|
||||
require.DeepEqual(t, expected.PruneSlasherStoragePeriod, actual.PruneSlasherStoragePeriod)
|
||||
require.DeepEqual(t, expected.SlashingProtectionPruningEpochs, actual.SlashingProtectionPruningEpochs)
|
||||
require.DeepEqual(t, expected.GenesisForkVersion, actual.GenesisForkVersion)
|
||||
require.DeepEqual(t, expected.AltairForkVersion, actual.AltairForkVersion)
|
||||
require.DeepEqual(t, expected.AltairForkEpoch, actual.AltairForkEpoch)
|
||||
require.DeepEqual(t, expected.BellatrixForkVersion, actual.BellatrixForkVersion)
|
||||
require.DeepEqual(t, expected.BellatrixForkEpoch, actual.BellatrixForkEpoch)
|
||||
require.DeepEqual(t, expected.ShardingForkVersion, actual.ShardingForkVersion)
|
||||
require.DeepEqual(t, expected.ShardingForkEpoch, actual.ShardingForkEpoch)
|
||||
require.DeepEqual(t, expected.ForkVersionSchedule, actual.ForkVersionSchedule)
|
||||
require.DeepEqual(t, expected.SafetyDecay, actual.SafetyDecay)
|
||||
require.DeepEqual(t, expected.TimelySourceFlagIndex, actual.TimelySourceFlagIndex)
|
||||
require.DeepEqual(t, expected.TimelyTargetFlagIndex, actual.TimelyTargetFlagIndex)
|
||||
require.DeepEqual(t, expected.TimelyHeadFlagIndex, actual.TimelyHeadFlagIndex)
|
||||
require.DeepEqual(t, expected.TimelySourceWeight, actual.TimelySourceWeight)
|
||||
require.DeepEqual(t, expected.TimelyTargetWeight, actual.TimelyTargetWeight)
|
||||
require.DeepEqual(t, expected.TimelyHeadWeight, actual.TimelyHeadWeight)
|
||||
require.DeepEqual(t, expected.SyncRewardWeight, actual.SyncRewardWeight)
|
||||
require.DeepEqual(t, expected.WeightDenominator, actual.WeightDenominator)
|
||||
require.DeepEqual(t, expected.ProposerWeight, actual.ProposerWeight)
|
||||
require.DeepEqual(t, expected.TargetAggregatorsPerSyncSubcommittee, actual.TargetAggregatorsPerSyncSubcommittee)
|
||||
require.DeepEqual(t, expected.SyncCommitteeSubnetCount, actual.SyncCommitteeSubnetCount)
|
||||
require.DeepEqual(t, expected.SyncCommitteeSize, actual.SyncCommitteeSize)
|
||||
require.DeepEqual(t, expected.InactivityScoreBias, actual.InactivityScoreBias)
|
||||
require.DeepEqual(t, expected.InactivityScoreRecoveryRate, actual.InactivityScoreRecoveryRate)
|
||||
require.DeepEqual(t, expected.EpochsPerSyncCommitteePeriod, actual.EpochsPerSyncCommitteePeriod)
|
||||
require.DeepEqual(t, expected.InactivityPenaltyQuotientAltair, actual.InactivityPenaltyQuotientAltair)
|
||||
require.DeepEqual(t, expected.MinSlashingPenaltyQuotientAltair, actual.MinSlashingPenaltyQuotientAltair)
|
||||
require.DeepEqual(t, expected.ProportionalSlashingMultiplierAltair, actual.ProportionalSlashingMultiplierAltair)
|
||||
require.DeepEqual(t, expected.MinSlashingPenaltyQuotientBellatrix, actual.MinSlashingPenaltyQuotientBellatrix)
|
||||
require.DeepEqual(t, expected.ProportionalSlashingMultiplierBellatrix, actual.ProportionalSlashingMultiplierBellatrix)
|
||||
require.DeepEqual(t, expected.InactivityPenaltyQuotientBellatrix, actual.InactivityPenaltyQuotientBellatrix)
|
||||
require.DeepEqual(t, expected.MinSyncCommitteeParticipants, actual.MinSyncCommitteeParticipants)
|
||||
require.DeepEqual(t, expected.TerminalBlockHash, actual.TerminalBlockHash)
|
||||
require.DeepEqual(t, expected.TerminalBlockHashActivationEpoch, actual.TerminalBlockHashActivationEpoch)
|
||||
require.DeepEqual(t, expected.TerminalTotalDifficulty, actual.TerminalTotalDifficulty)
|
||||
require.DeepEqual(t, expected.DefaultFeeRecipient, actual.DefaultFeeRecipient)
|
||||
}
|
26
config/params/init.go
Normal file
26
config/params/init.go
Normal file
@ -0,0 +1,26 @@
|
||||
package params
|
||||
|
||||
func init() {
|
||||
defaults := []*BeaconChainConfig{
|
||||
MainnetConfig(),
|
||||
PraterConfig(),
|
||||
MinimalSpecConfig(),
|
||||
E2ETestConfig(),
|
||||
E2EMainnetTestConfig(),
|
||||
InteropConfig(),
|
||||
RopstenConfig(),
|
||||
}
|
||||
configs = newConfigset(defaults...)
|
||||
// ensure that main net is always present and active by default
|
||||
if err := SetActive(MainnetConfig()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// make sure mainnet is present and active
|
||||
m, err := ByName(MainnetName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if configs.getActive() != m {
|
||||
panic("mainnet should always be the active config at init() time")
|
||||
}
|
||||
}
|
16
config/params/interop.go
Normal file
16
config/params/interop.go
Normal file
@ -0,0 +1,16 @@
|
||||
package params
|
||||
|
||||
// InteropConfig provides a generic config suitable for interop testing.
|
||||
func InteropConfig() *BeaconChainConfig {
|
||||
c := MainnetConfig().Copy()
|
||||
|
||||
// Prysm constants.
|
||||
c.ConfigName = InteropName
|
||||
c.GenesisForkVersion = []byte{0, 0, 0, 235}
|
||||
c.AltairForkVersion = []byte{1, 0, 0, 235}
|
||||
c.BellatrixForkVersion = []byte{2, 0, 0, 235}
|
||||
c.ShardingForkVersion = []byte{3, 0, 0, 235}
|
||||
|
||||
c.InitializeForkSchedule()
|
||||
return c
|
||||
}
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/math"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -24,12 +25,10 @@ func isMinimal(lines []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// LoadChainConfigFile load, convert hex values into valid param yaml format,
|
||||
// unmarshal , and apply beacon chain config file.
|
||||
func LoadChainConfigFile(chainConfigFileName string, conf *BeaconChainConfig) {
|
||||
yamlFile, err := os.ReadFile(chainConfigFileName) // #nosec G304
|
||||
func UnmarshalConfigFile(path string, conf *BeaconChainConfig) (*BeaconChainConfig, error) {
|
||||
yamlFile, err := os.ReadFile(path) // #nosec G304
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("Failed to read chain config file.")
|
||||
return nil, errors.Wrap(err, "Failed to read chain config file.")
|
||||
}
|
||||
// To track if config name is defined inside config file.
|
||||
hasConfigName := false
|
||||
@ -59,19 +58,28 @@ func LoadChainConfigFile(chainConfigFileName string, conf *BeaconChainConfig) {
|
||||
yamlFile = []byte(strings.Join(lines, "\n"))
|
||||
if err := yaml.UnmarshalStrict(yamlFile, conf); err != nil {
|
||||
if _, ok := err.(*yaml.TypeError); !ok {
|
||||
log.WithError(err).Fatal("Failed to parse chain config yaml file.")
|
||||
return nil, errors.Wrap(err, "Failed to parse chain config yaml file.")
|
||||
} else {
|
||||
log.WithError(err).Error("There were some issues parsing the config from a yaml file")
|
||||
}
|
||||
}
|
||||
if !hasConfigName {
|
||||
conf.ConfigName = "devnet"
|
||||
conf.ConfigName = DevnetName
|
||||
}
|
||||
// recompute SqrRootSlotsPerEpoch constant to handle non-standard values of SlotsPerEpoch
|
||||
conf.SqrRootSlotsPerEpoch = types.Slot(math.IntegerSquareRoot(uint64(conf.SlotsPerEpoch)))
|
||||
log.Debugf("Config file values: %+v", conf)
|
||||
conf.InitializeForkSchedule()
|
||||
OverrideBeaconConfig(conf)
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// LoadChainConfigFile load, convert hex values into valid param yaml format,
|
||||
// unmarshal , and apply beacon chain config file.
|
||||
func LoadChainConfigFile(path string, conf *BeaconChainConfig) error {
|
||||
c, err := UnmarshalConfigFile(path, conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return SetActive(c)
|
||||
}
|
||||
|
||||
// ReplaceHexStringWithYAMLFormat will replace hex strings that the yaml parser will understand.
|
||||
|
@ -1,6 +1,8 @@
|
||||
package params_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -109,36 +111,49 @@ func TestLoadConfigFile(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("mainnet", func(t *testing.T) {
|
||||
mn := params.MainnetConfig().Copy()
|
||||
mainnetPresetsFiles := presetsFilePath(t, "mainnet")
|
||||
var err error
|
||||
for _, fp := range mainnetPresetsFiles {
|
||||
params.LoadChainConfigFile(fp, nil)
|
||||
mn, err = params.UnmarshalConfigFile(fp, mn)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
// configs loaded from file get the name 'devnet' unless they specify a specific name in the yaml itself.
|
||||
// since these are partial patches for presets, they do not have the config name
|
||||
mn.ConfigName = params.MainnetName
|
||||
mainnetConfigFile := configFilePath(t, "mainnet")
|
||||
params.LoadChainConfigFile(mainnetConfigFile, nil)
|
||||
mnf, err := params.UnmarshalConfigFile(mainnetConfigFile, nil)
|
||||
require.NoError(t, err)
|
||||
fields := fieldsFromYamls(t, append(mainnetPresetsFiles, mainnetConfigFile))
|
||||
assertVals("mainnet", fields, params.MainnetConfig(), params.BeaconConfig())
|
||||
assertVals("mainnet", fields, mn, mnf)
|
||||
})
|
||||
|
||||
t.Run("minimal", func(t *testing.T) {
|
||||
min := params.MinimalSpecConfig().Copy()
|
||||
minimalPresetsFiles := presetsFilePath(t, "minimal")
|
||||
var err error
|
||||
for _, fp := range minimalPresetsFiles {
|
||||
params.LoadChainConfigFile(fp, nil)
|
||||
min, err = params.UnmarshalConfigFile(fp, min)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
// configs loaded from file get the name 'devnet' unless they specify a specific name in the yaml itself.
|
||||
// since these are partial patches for presets, they do not have the config name
|
||||
min.ConfigName = params.MinimalName
|
||||
minimalConfigFile := configFilePath(t, "minimal")
|
||||
params.LoadChainConfigFile(minimalConfigFile, nil)
|
||||
minf, err := params.UnmarshalConfigFile(minimalConfigFile, nil)
|
||||
require.NoError(t, err)
|
||||
fields := fieldsFromYamls(t, append(minimalPresetsFiles, minimalConfigFile))
|
||||
assertVals("minimal", fields, params.MinimalSpecConfig(), params.BeaconConfig())
|
||||
assertVals("minimal", fields, min, minf)
|
||||
})
|
||||
|
||||
t.Run("e2e", func(t *testing.T) {
|
||||
minimalPresetsFiles := presetsFilePath(t, "minimal")
|
||||
for _, fp := range minimalPresetsFiles {
|
||||
params.LoadChainConfigFile(fp, nil)
|
||||
}
|
||||
e2e, err := params.ByName(params.EndToEndName)
|
||||
require.NoError(t, err)
|
||||
configFile := "testdata/e2e_config.yaml"
|
||||
params.LoadChainConfigFile(configFile, nil)
|
||||
fields := fieldsFromYamls(t, append(minimalPresetsFiles, configFile))
|
||||
assertVals("e2e", fields, params.E2ETestConfig(), params.BeaconConfig())
|
||||
e2ef, err := params.UnmarshalConfigFile(configFile, nil)
|
||||
require.NoError(t, err)
|
||||
fields := fieldsFromYamls(t, []string{configFile})
|
||||
assertVals("e2e", fields, e2e, e2ef)
|
||||
})
|
||||
}
|
||||
|
||||
@ -146,21 +161,34 @@ func TestLoadConfigFile_OverwriteCorrectly(t *testing.T) {
|
||||
file, err := os.CreateTemp("", "")
|
||||
require.NoError(t, err)
|
||||
// Set current config to minimal config
|
||||
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
||||
cfg := params.MinimalSpecConfig().Copy()
|
||||
params.FillTestVersions(cfg, 128)
|
||||
_, err = io.Copy(file, bytes.NewBuffer(params.ConfigToYaml(cfg)))
|
||||
require.NoError(t, err)
|
||||
|
||||
// set active config to mainnet, so that we can confirm LoadChainConfigFile overrides it
|
||||
mainnet, err := params.ByName(params.MainnetName)
|
||||
require.NoError(t, err)
|
||||
undo, err := params.SetActiveWithUndo(mainnet)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
err := undo()
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
// load empty config file, so that it defaults to mainnet values
|
||||
params.LoadChainConfigFile(file.Name(), nil)
|
||||
if params.BeaconConfig().MinGenesisTime != params.MainnetConfig().MinGenesisTime {
|
||||
t.Errorf("Expected MinGenesisTime to be set to mainnet value: %d found: %d",
|
||||
params.MainnetConfig().MinGenesisTime,
|
||||
require.NoError(t, params.LoadChainConfigFile(file.Name(), nil))
|
||||
if params.BeaconConfig().MinGenesisTime != cfg.MinGenesisTime {
|
||||
t.Errorf("Expected MinGenesisTime to be set to value written to config: %d found: %d",
|
||||
cfg.MinGenesisTime,
|
||||
params.BeaconConfig().MinGenesisTime)
|
||||
}
|
||||
if params.BeaconConfig().SlotsPerEpoch != params.MainnetConfig().SlotsPerEpoch {
|
||||
t.Errorf("Expected SlotsPerEpoch to be set to mainnet value: %d found: %d",
|
||||
params.MainnetConfig().SlotsPerEpoch,
|
||||
if params.BeaconConfig().SlotsPerEpoch != cfg.SlotsPerEpoch {
|
||||
t.Errorf("Expected SlotsPerEpoch to be set to value written to config: %d found: %d",
|
||||
cfg.SlotsPerEpoch,
|
||||
params.BeaconConfig().SlotsPerEpoch)
|
||||
}
|
||||
require.Equal(t, "devnet", params.BeaconConfig().ConfigName)
|
||||
require.Equal(t, params.MinimalName, params.BeaconConfig().ConfigName)
|
||||
}
|
||||
|
||||
func Test_replaceHexStringWithYAMLFormat(t *testing.T) {
|
||||
@ -241,7 +269,7 @@ func TestConfigParityYaml(t *testing.T) {
|
||||
yamlObj := params.ConfigToYaml(testCfg)
|
||||
assert.NoError(t, file.WriteFile(yamlDir, yamlObj))
|
||||
|
||||
params.LoadChainConfigFile(yamlDir, params.E2ETestConfig().Copy())
|
||||
require.NoError(t, params.LoadChainConfigFile(yamlDir, params.E2ETestConfig().Copy()))
|
||||
assert.DeepEqual(t, params.BeaconConfig(), testCfg)
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
)
|
||||
|
||||
@ -15,11 +16,6 @@ func MainnetConfig() *BeaconChainConfig {
|
||||
return mainnetBeaconConfig
|
||||
}
|
||||
|
||||
// UseMainnetConfig for beacon chain services.
|
||||
func UseMainnetConfig() {
|
||||
beaconConfig = MainnetConfig()
|
||||
}
|
||||
|
||||
const (
|
||||
// Genesis Fork Epoch for the mainnet config.
|
||||
genesisForkEpoch = 0
|
||||
@ -247,3 +243,32 @@ var mainnetBeaconConfig = &BeaconChainConfig{
|
||||
TerminalBlockHash: [32]byte{},
|
||||
TerminalTotalDifficulty: "115792089237316195423570985008687907853269984665640564039457584007913129638912",
|
||||
}
|
||||
|
||||
// MainnetTestConfig provides a version of the mainnet config that has a different name
|
||||
// and a different fork choice schedule. This can be used in cases where we want to use config values
|
||||
// that are consistent with mainnet, but won't conflict or cause the hard-coded genesis to be loaded.
|
||||
func MainnetTestConfig() *BeaconChainConfig {
|
||||
mn := MainnetConfig().Copy()
|
||||
mn.ConfigName = MainnetTestName
|
||||
FillTestVersions(mn, 128)
|
||||
return mn
|
||||
}
|
||||
|
||||
// FillTestVersions replaces the byte in the last position of each fork version
|
||||
// so that
|
||||
func FillTestVersions(c *BeaconChainConfig, b byte) {
|
||||
c.GenesisForkVersion = make([]byte, fieldparams.VersionLength)
|
||||
c.AltairForkVersion = make([]byte, fieldparams.VersionLength)
|
||||
c.BellatrixForkVersion = make([]byte, fieldparams.VersionLength)
|
||||
c.ShardingForkVersion = make([]byte, fieldparams.VersionLength)
|
||||
|
||||
c.GenesisForkVersion[fieldparams.VersionLength-1] = b
|
||||
c.AltairForkVersion[fieldparams.VersionLength-1] = b
|
||||
c.BellatrixForkVersion[fieldparams.VersionLength-1] = b
|
||||
c.ShardingForkVersion[fieldparams.VersionLength-1] = b
|
||||
|
||||
c.GenesisForkVersion[0] = 0
|
||||
c.AltairForkVersion[0] = 1
|
||||
c.BellatrixForkVersion[0] = 2
|
||||
c.ShardingForkVersion[0] = 3
|
||||
}
|
||||
|
@ -6,11 +6,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
)
|
||||
|
||||
// UseMinimalConfig for beacon chain services.
|
||||
func UseMinimalConfig() {
|
||||
beaconConfig = MinimalSpecConfig()
|
||||
}
|
||||
|
||||
// MinimalSpecConfig retrieves the minimal config used in spec tests.
|
||||
func MinimalSpecConfig() *BeaconChainConfig {
|
||||
minimalConfig := mainnetBeaconConfig.Copy()
|
||||
|
@ -1,10 +0,0 @@
|
||||
package params
|
||||
|
||||
var Registry *registry
|
||||
|
||||
type registry struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
Registry = ®istry{}
|
||||
}
|
@ -28,7 +28,7 @@ func TestE2EConfigParity(t *testing.T) {
|
||||
yamlObj := params.E2EMainnetConfigYaml()
|
||||
assert.NoError(t, file.WriteFile(yamlDir, yamlObj))
|
||||
|
||||
params.LoadChainConfigFile(yamlDir, params.MainnetConfig().Copy())
|
||||
require.NoError(t, params.LoadChainConfigFile(yamlDir, params.MainnetConfig().Copy()))
|
||||
|
||||
// compareConfigs makes it easier to figure out exactly what changed
|
||||
compareConfigs(t, params.BeaconConfig(), testCfg)
|
||||
|
@ -5,22 +5,6 @@ const (
|
||||
bellatrixE2EForkEpoch = 8 //nolint:deadcode
|
||||
)
|
||||
|
||||
// UseE2EConfig for beacon chain services.
|
||||
func UseE2EConfig() {
|
||||
beaconConfig = E2ETestConfig()
|
||||
|
||||
cfg := BeaconNetworkConfig().Copy()
|
||||
OverrideBeaconNetworkConfig(cfg)
|
||||
}
|
||||
|
||||
// UseE2EMainnetConfig for beacon chain services.
|
||||
func UseE2EMainnetConfig() {
|
||||
beaconConfig = E2EMainnetTestConfig()
|
||||
|
||||
cfg := BeaconNetworkConfig().Copy()
|
||||
OverrideBeaconNetworkConfig(cfg)
|
||||
}
|
||||
|
||||
// E2ETestConfig retrieves the configurations made specifically for E2E testing.
|
||||
//
|
||||
// WARNING: This config is only for testing, it is not meant for use outside of E2E.
|
||||
@ -91,7 +75,7 @@ func E2EMainnetTestConfig() *BeaconChainConfig {
|
||||
e2eConfig.TerminalTotalDifficulty = "616"
|
||||
|
||||
// Prysm constants.
|
||||
e2eConfig.ConfigName = EndToEndName
|
||||
e2eConfig.ConfigName = EndToEndMainnetName
|
||||
e2eConfig.GenesisForkVersion = []byte{0, 0, 0, 254}
|
||||
e2eConfig.AltairForkVersion = []byte{1, 0, 0, 254}
|
||||
e2eConfig.BellatrixForkVersion = []byte{2, 0, 0, 254}
|
||||
|
@ -22,12 +22,6 @@ func UsePraterNetworkConfig() {
|
||||
OverrideBeaconNetworkConfig(cfg)
|
||||
}
|
||||
|
||||
// UsePraterConfig sets the main beacon chain
|
||||
// config for Prater.
|
||||
func UsePraterConfig() {
|
||||
beaconConfig = PraterConfig()
|
||||
}
|
||||
|
||||
// PraterConfig defines the config for the
|
||||
// Prater testnet.
|
||||
func PraterConfig() *BeaconChainConfig {
|
||||
|
@ -4,15 +4,21 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestPraterConfigMatchesUpstreamYaml(t *testing.T) {
|
||||
presetFPs := presetsFilePath(t, "mainnet")
|
||||
mn, err := params.ByName(params.MainnetName)
|
||||
require.NoError(t, err)
|
||||
cfg := mn.Copy()
|
||||
for _, fp := range presetFPs {
|
||||
params.LoadChainConfigFile(fp, nil)
|
||||
cfg, err = params.UnmarshalConfigFile(fp, cfg)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
configFP := testnetConfigFilePath(t, "prater")
|
||||
params.LoadChainConfigFile(configFP, nil)
|
||||
pcfg, err := params.UnmarshalConfigFile(configFP, nil)
|
||||
require.NoError(t, err)
|
||||
fields := fieldsFromYamls(t, append(presetFPs, configFP))
|
||||
assertYamlFieldsMatch(t, "prater", fields, params.BeaconConfig(), params.PraterConfig())
|
||||
assertYamlFieldsMatch(t, "prater", fields, pcfg, params.PraterConfig())
|
||||
}
|
||||
|
@ -17,11 +17,6 @@ func UseRopstenNetworkConfig() {
|
||||
OverrideBeaconNetworkConfig(cfg)
|
||||
}
|
||||
|
||||
// UseRopstenConfig sets the main beacon chain config for Ropsten beacon chain.
|
||||
func UseRopstenConfig() {
|
||||
beaconConfig = RopstenConfig()
|
||||
}
|
||||
|
||||
// RopstenConfig defines the config for the Ropsten beacon chain testnet.
|
||||
func RopstenConfig() *BeaconChainConfig {
|
||||
cfg := MainnetConfig().Copy()
|
||||
|
@ -1,16 +1,25 @@
|
||||
package params
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// SetupTestConfigCleanup preserves configurations allowing to modify them within tests without any
|
||||
// restrictions, everything is restored after the test.
|
||||
func SetupTestConfigCleanup(t testing.TB) {
|
||||
prevDefaultBeaconConfig := mainnetBeaconConfig.Copy()
|
||||
prevBeaconConfig := beaconConfig.Copy()
|
||||
temp := configs.getActive().Copy()
|
||||
undo, err := SetActiveWithUndo(temp)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
prevNetworkCfg := networkConfig.Copy()
|
||||
t.Cleanup(func() {
|
||||
mainnetBeaconConfig = prevDefaultBeaconConfig
|
||||
beaconConfig = prevBeaconConfig
|
||||
err = undo()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
networkConfig = prevNetworkCfg
|
||||
})
|
||||
}
|
||||
|
@ -1,79 +1,13 @@
|
||||
package params
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
)
|
||||
|
||||
const (
|
||||
DevnetName = "devnet"
|
||||
EndToEndName = "end-to-end"
|
||||
EndToEndMainnetName = "end-to-end-mainnet"
|
||||
InteropName = "interop"
|
||||
MainnetName = "mainnet"
|
||||
MainnetTestName = "mainnet-test"
|
||||
MinimalName = "minimal"
|
||||
PraterName = "prater"
|
||||
RopstenName = "ropsten"
|
||||
)
|
||||
|
||||
// KnownConfigs provides an index of all known BeaconChainConfig values.
|
||||
var KnownConfigs = map[string]func() *BeaconChainConfig{
|
||||
MainnetName: MainnetConfig,
|
||||
PraterName: PraterConfig,
|
||||
MinimalName: MinimalSpecConfig,
|
||||
EndToEndName: E2ETestConfig,
|
||||
EndToEndMainnetName: E2EMainnetTestConfig,
|
||||
}
|
||||
|
||||
var knownForkVersions map[[fieldparams.VersionLength]byte]string
|
||||
|
||||
var errUnknownForkVersion = errors.New("version not found in fork version schedule for any known config")
|
||||
|
||||
// ConfigForVersion find the BeaconChainConfig corresponding to the version bytes.
|
||||
// Version bytes for BeaconChainConfig values in KnownConfigs are proven to be unique during package initialization.
|
||||
func ConfigForVersion(version [fieldparams.VersionLength]byte) (*BeaconChainConfig, error) {
|
||||
cfg, ok := knownForkVersions[version]
|
||||
if !ok {
|
||||
return nil, errors.Wrapf(errUnknownForkVersion, "version=%#x", version)
|
||||
}
|
||||
return KnownConfigs[cfg](), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
knownForkVersions = make(map[[fieldparams.VersionLength]byte]string)
|
||||
for n, cfunc := range KnownConfigs {
|
||||
cfg := cfunc()
|
||||
// ensure that fork schedule is consistent w/ struct fields for all known configurations
|
||||
if err := equalForkSchedules(configForkSchedule(cfg), cfg.ForkVersionSchedule); err != nil {
|
||||
panic(errors.Wrapf(err, "improperly initialized for schedule for config %s", n))
|
||||
}
|
||||
// ensure that all fork versions are unique
|
||||
for v := range cfg.ForkVersionSchedule {
|
||||
pn, exists := knownForkVersions[v]
|
||||
if exists {
|
||||
previous := KnownConfigs[pn]()
|
||||
msg := fmt.Sprintf("version %#x is duplicated in 2 configs, %s at epoch %d, %s at epoch %d",
|
||||
v, pn, previous.ForkVersionSchedule[v], n, cfg.ForkVersionSchedule[v])
|
||||
panic(msg)
|
||||
}
|
||||
knownForkVersions[v] = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func equalForkSchedules(a, b map[[fieldparams.VersionLength]byte]types.Epoch) error {
|
||||
if len(a) != len(b) {
|
||||
return fmt.Errorf("different lengths, a=%d, b=%d", len(a), len(b))
|
||||
}
|
||||
for k, v := range a {
|
||||
bv, ok := b[k]
|
||||
if !ok {
|
||||
return fmt.Errorf("fork version %#x from 'a', not present in 'b'", k)
|
||||
}
|
||||
if v != bv {
|
||||
return fmt.Errorf("fork version mismatch, epoch in a=%d, b=%d", v, bv)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ var ErrForkNotFound = errors.New("version found in fork schedule but can't be ma
|
||||
// FromForkVersion uses a lookup table to resolve a Version (from a beacon node api for instance, or obtained by peeking at
|
||||
// the bytes of a marshaled BeaconState) to a VersionedUnmarshaler.
|
||||
func FromForkVersion(cv [fieldparams.VersionLength]byte) (*VersionedUnmarshaler, error) {
|
||||
cfg, err := params.ConfigForVersion(cv)
|
||||
cfg, err := params.ByVersion(cv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -48,8 +48,12 @@ func TestSlotFromBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestByState(t *testing.T) {
|
||||
bc, cleanup := hackBellatrixMaxuint()
|
||||
defer cleanup()
|
||||
undo, err := hackBellatrixMaxuint()
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, undo())
|
||||
}()
|
||||
bc := params.BeaconConfig()
|
||||
altairSlot, err := slots.EpochStart(bc.AltairForkEpoch)
|
||||
bellaSlot, err := slots.EpochStart(bc.BellatrixForkEpoch)
|
||||
require.NoError(t, err)
|
||||
@ -112,8 +116,12 @@ func stateForVersion(v int) (state.BeaconState, error) {
|
||||
|
||||
func TestUnmarshalState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bc, cleanup := hackBellatrixMaxuint()
|
||||
defer cleanup()
|
||||
undo, err := hackBellatrixMaxuint()
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, undo())
|
||||
}()
|
||||
bc := params.BeaconConfig()
|
||||
altairSlot, err := slots.EpochStart(bc.AltairForkEpoch)
|
||||
bellaSlot, err := slots.EpochStart(bc.BellatrixForkEpoch)
|
||||
require.NoError(t, err)
|
||||
@ -165,37 +173,29 @@ func TestUnmarshalState(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func hackBellatrixMaxuint() (*params.BeaconChainConfig, func()) {
|
||||
func hackBellatrixMaxuint() (func() error, error) {
|
||||
// We monkey patch the config to use a smaller value for the bellatrix fork epoch.
|
||||
// Upstream configs use MaxUint64, which leads to a multiplication overflow when converting epoch->slot.
|
||||
// Unfortunately we have unit tests that assert our config matches the upstream config, so we have to choose between
|
||||
// breaking conformance, adding a special case to the conformance unit test, or patch it here.
|
||||
previous := params.BeaconConfig()
|
||||
bc := params.MainnetConfig().Copy()
|
||||
bc.BellatrixForkEpoch = math.MaxUint32
|
||||
bc.InitializeForkSchedule()
|
||||
params.OverrideBeaconConfig(bc)
|
||||
// override the param used for mainnet with the patched version
|
||||
params.KnownConfigs[params.MainnetName] = func() *params.BeaconChainConfig {
|
||||
return bc
|
||||
}
|
||||
return bc, func() {
|
||||
// put the previous BeaconChainConfig back in place at the end of the test
|
||||
params.OverrideBeaconConfig(previous)
|
||||
// restore the normal MainnetConfig func in the KnownConfigs mapping
|
||||
params.KnownConfigs[params.MainnetName] = params.MainnetConfig
|
||||
}
|
||||
undo, err := params.SetActiveWithUndo(bc)
|
||||
return undo, err
|
||||
}
|
||||
|
||||
func TestUnmarshalBlock(t *testing.T) {
|
||||
bc, cleanup := hackBellatrixMaxuint()
|
||||
defer cleanup()
|
||||
require.Equal(t, types.Epoch(math.MaxUint32), params.KnownConfigs[params.MainnetName]().BellatrixForkEpoch)
|
||||
genv := bytesutil.ToBytes4(bc.GenesisForkVersion)
|
||||
altairv := bytesutil.ToBytes4(bc.AltairForkVersion)
|
||||
bellav := bytesutil.ToBytes4(bc.BellatrixForkVersion)
|
||||
altairS, err := slots.EpochStart(bc.AltairForkEpoch)
|
||||
bellaS, err := slots.EpochStart(bc.BellatrixForkEpoch)
|
||||
undo, err := hackBellatrixMaxuint()
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, undo())
|
||||
}()
|
||||
require.Equal(t, types.Epoch(math.MaxUint32), params.BeaconConfig().BellatrixForkEpoch)
|
||||
genv := bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)
|
||||
altairv := bytesutil.ToBytes4(params.BeaconConfig().AltairForkVersion)
|
||||
bellav := bytesutil.ToBytes4(params.BeaconConfig().BellatrixForkVersion)
|
||||
altairS, err := slots.EpochStart(params.BeaconConfig().AltairForkEpoch)
|
||||
bellaS, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch)
|
||||
require.NoError(t, err)
|
||||
cases := []struct {
|
||||
b func(*testing.T, types.Slot) interfaces.SignedBeaconBlock
|
||||
@ -277,14 +277,17 @@ func TestUnmarshalBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnmarshalBlindedBlock(t *testing.T) {
|
||||
bc, cleanup := hackBellatrixMaxuint()
|
||||
defer cleanup()
|
||||
require.Equal(t, types.Epoch(math.MaxUint32), params.KnownConfigs[params.MainnetName]().BellatrixForkEpoch)
|
||||
genv := bytesutil.ToBytes4(bc.GenesisForkVersion)
|
||||
altairv := bytesutil.ToBytes4(bc.AltairForkVersion)
|
||||
bellav := bytesutil.ToBytes4(bc.BellatrixForkVersion)
|
||||
altairS, err := slots.EpochStart(bc.AltairForkEpoch)
|
||||
bellaS, err := slots.EpochStart(bc.BellatrixForkEpoch)
|
||||
undo, err := hackBellatrixMaxuint()
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
require.NoError(t, undo())
|
||||
}()
|
||||
require.Equal(t, types.Epoch(math.MaxUint32), params.BeaconConfig().BellatrixForkEpoch)
|
||||
genv := bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)
|
||||
altairv := bytesutil.ToBytes4(params.BeaconConfig().AltairForkVersion)
|
||||
bellav := bytesutil.ToBytes4(params.BeaconConfig().BellatrixForkVersion)
|
||||
altairS, err := slots.EpochStart(params.BeaconConfig().AltairForkEpoch)
|
||||
bellaS, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch)
|
||||
require.NoError(t, err)
|
||||
cases := []struct {
|
||||
b func(*testing.T, types.Slot) interfaces.SignedBeaconBlock
|
||||
|
@ -15,6 +15,8 @@ import (
|
||||
|
||||
func TestFork(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
targetEpoch types.Epoch
|
||||
@ -32,7 +34,7 @@ func TestFork(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{}
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
@ -48,7 +50,7 @@ func TestFork(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
{'A', 'B', 'C', 'D'}: 0,
|
||||
@ -66,7 +68,7 @@ func TestFork(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.AltairForkVersion = []byte{'A', 'B', 'C', 'F'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
@ -86,7 +88,7 @@ func TestFork(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.AltairForkVersion = []byte{'A', 'B', 'C', 'F'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
@ -107,7 +109,7 @@ func TestFork(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.AltairForkVersion = []byte{'A', 'B', 'C', 'F'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
@ -128,7 +130,7 @@ func TestFork(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
{'A', 'B', 'C', 'D'}: 0,
|
||||
@ -148,7 +150,7 @@ func TestFork(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
{'A', 'B', 'C', 'D'}: 0,
|
||||
@ -176,13 +178,16 @@ func TestFork(t *testing.T) {
|
||||
|
||||
func TestRetrieveForkDataFromDigest(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
{'A', 'B', 'C', 'D'}: 0,
|
||||
{'A', 'B', 'C', 'F'}: 10,
|
||||
{'A', 'B', 'C', 'Z'}: 100,
|
||||
}
|
||||
cfg.GenesisEpoch = 0
|
||||
cfg.AltairForkVersion = []byte{'A', 'B', 'C', 'F'}
|
||||
cfg.AltairForkEpoch = 10
|
||||
cfg.BellatrixForkVersion = []byte{'A', 'B', 'C', 'Z'}
|
||||
cfg.BellatrixForkEpoch = 100
|
||||
cfg.ShardingForkVersion = []byte{'A', 'B', 'C', 'Y'}
|
||||
cfg.ShardingForkEpoch = 1000
|
||||
cfg.InitializeForkSchedule()
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
genValRoot := [32]byte{'A', 'B', 'C', 'D'}
|
||||
digest, err := signing.ComputeForkDigest([]byte{'A', 'B', 'C', 'F'}, genValRoot[:])
|
||||
@ -204,13 +209,14 @@ func TestRetrieveForkDataFromDigest(t *testing.T) {
|
||||
|
||||
func TestIsForkNextEpoch(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig()
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
{'A', 'B', 'C', 'D'}: 0,
|
||||
{'A', 'B', 'C', 'F'}: 10,
|
||||
{'A', 'B', 'C', 'Z'}: 100,
|
||||
}
|
||||
params.OverrideBeaconConfig(cfg)
|
||||
genTimeCreator := func(epoch types.Epoch) time.Time {
|
||||
return time.Now().Add(-time.Duration(uint64(params.BeaconConfig().SlotsPerEpoch)*uint64(epoch)*params.BeaconConfig().SecondsPerSlot) * time.Second)
|
||||
}
|
||||
@ -246,6 +252,7 @@ func TestIsForkNextEpoch(t *testing.T) {
|
||||
|
||||
func TestNextForkData(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
cfg := params.BeaconConfig().Copy()
|
||||
tests := []struct {
|
||||
name string
|
||||
setConfg func()
|
||||
@ -259,7 +266,7 @@ func TestNextForkData(t *testing.T) {
|
||||
wantedForkVerison: [4]byte{'A', 'B', 'C', 'D'},
|
||||
wantedEpoch: math.MaxUint64,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
{'A', 'B', 'C', 'D'}: 0,
|
||||
@ -273,7 +280,7 @@ func TestNextForkData(t *testing.T) {
|
||||
wantedForkVerison: [4]byte{'A', 'B', 'C', 'F'},
|
||||
wantedEpoch: 10,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.AltairForkVersion = []byte{'A', 'B', 'C', 'F'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
@ -289,7 +296,7 @@ func TestNextForkData(t *testing.T) {
|
||||
wantedForkVerison: [4]byte{'A', 'B', 'C', 'F'},
|
||||
wantedEpoch: math.MaxUint64,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.AltairForkVersion = []byte{'A', 'B', 'C', 'F'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
@ -306,7 +313,7 @@ func TestNextForkData(t *testing.T) {
|
||||
wantedForkVerison: [4]byte{'A', 'B', 'C', 'F'},
|
||||
wantedEpoch: math.MaxUint64,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.AltairForkVersion = []byte{'A', 'B', 'C', 'F'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
@ -323,7 +330,7 @@ func TestNextForkData(t *testing.T) {
|
||||
wantedForkVerison: [4]byte{'A', 'B', 'C', 'F'},
|
||||
wantedEpoch: 10,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
{'A', 'B', 'C', 'D'}: 0,
|
||||
@ -339,7 +346,7 @@ func TestNextForkData(t *testing.T) {
|
||||
wantedForkVerison: [4]byte{'A', 'B', 'C', 'Z'},
|
||||
wantedEpoch: 100,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
{'A', 'B', 'C', 'D'}: 0,
|
||||
@ -355,7 +362,7 @@ func TestNextForkData(t *testing.T) {
|
||||
wantedForkVerison: [4]byte{'A', 'B', 'C', 'Z'},
|
||||
wantedEpoch: math.MaxUint64,
|
||||
setConfg: func() {
|
||||
cfg := params.BeaconConfig()
|
||||
cfg = cfg.Copy()
|
||||
cfg.GenesisForkVersion = []byte{'A', 'B', 'C', 'D'}
|
||||
cfg.ForkVersionSchedule = map[[4]byte]types.Epoch{
|
||||
{'A', 'B', 'C', 'D'}: 0,
|
||||
|
@ -11,9 +11,8 @@ import (
|
||||
|
||||
func TestOrderedConfigSchedule(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
for name, getCfg := range params.KnownConfigs {
|
||||
cfg := getCfg()
|
||||
t.Run(name, func(t *testing.T) {
|
||||
for _, cfg := range params.All() {
|
||||
t.Run(cfg.ConfigName, func(t *testing.T) {
|
||||
prevVersion := [4]byte{0, 0, 0, 0}
|
||||
// epoch 0 is genesis, and it's a uint so can't make it -1
|
||||
// so we use a pointer to detect the boundary condition and skip it
|
||||
|
@ -92,14 +92,19 @@ func PreGenFullBlock() (*ethpb.SignedBeaconBlock, error) {
|
||||
|
||||
// SetBenchmarkConfig changes the beacon config to match the requested amount of
|
||||
// attestations set to AttestationsPerEpoch.
|
||||
func SetBenchmarkConfig() {
|
||||
func SetBenchmarkConfig() (func(), error) {
|
||||
maxAtts := AttestationsPerEpoch
|
||||
slotsPerEpoch := uint64(params.BeaconConfig().SlotsPerEpoch)
|
||||
committeeSize := (ValidatorCount / slotsPerEpoch) / (maxAtts / slotsPerEpoch)
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
c.ShardCommitteePeriod = 0
|
||||
c.MinValidatorWithdrawabilityDelay = 0
|
||||
c.TargetCommitteeSize = committeeSize
|
||||
c.MaxAttestations = maxAtts
|
||||
params.OverrideBeaconConfig(c)
|
||||
undo, err := params.SetActiveWithUndo(c)
|
||||
return func() {
|
||||
if err := undo(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}, err
|
||||
}
|
||||
|
@ -20,7 +20,8 @@ func TestEndToEnd_MainnetConfig_ValidatorAtCurrentRelease(t *testing.T) {
|
||||
}
|
||||
|
||||
func e2eMainnet(t *testing.T, usePrysmSh, useMultiClient bool) {
|
||||
params.UseE2EMainnetConfig()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.E2EMainnetTestConfig())
|
||||
if useMultiClient {
|
||||
require.NoError(t, e2eParams.InitMultiClient(e2eParams.StandardBeaconCount, e2eParams.StandardLighthouseNodeCount))
|
||||
} else {
|
||||
|
@ -22,7 +22,9 @@ func TestEndToEnd_MinimalConfig_Web3Signer(t *testing.T) {
|
||||
}
|
||||
|
||||
func e2eMinimal(t *testing.T, useWeb3RemoteSigner bool, extraEpochs uint64) {
|
||||
params.UseE2EConfig()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.E2ETestConfig().Copy())
|
||||
|
||||
require.NoError(t, e2eParams.Init(e2eParams.StandardBeaconCount))
|
||||
|
||||
// Run for 12 epochs if not in long-running to confirm long-running has no issues.
|
||||
|
@ -12,7 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestEndToEnd_Slasher_MinimalConfig(t *testing.T) {
|
||||
params.UseE2EConfig()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.E2ETestConfig().Copy())
|
||||
require.NoError(t, e2eParams.Init(e2eParams.StandardBeaconCount))
|
||||
|
||||
tracingPort := e2eParams.TestParams.Ports.JaegerTracingPort
|
||||
|
@ -125,8 +125,15 @@ func (s *Simulator) Start() {
|
||||
config := params.BeaconConfig().Copy()
|
||||
config.SecondsPerSlot = s.srvConfig.Params.SecondsPerSlot
|
||||
config.SlotsPerEpoch = s.srvConfig.Params.SlotsPerEpoch
|
||||
params.OverrideBeaconConfig(config)
|
||||
defer params.OverrideBeaconConfig(params.BeaconConfig())
|
||||
undo, err := params.SetActiveWithUndo(config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := undo(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Start slasher in the background.
|
||||
go s.slasher.Start()
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
func TestMain(m *testing.M) {
|
||||
prevConfig := params.BeaconConfig().Copy()
|
||||
defer params.OverrideBeaconConfig(prevConfig)
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
c.MinGenesisActiveValidatorCount = 16384
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
func TestMain(m *testing.M) {
|
||||
prevConfig := params.BeaconConfig().Copy()
|
||||
defer params.OverrideBeaconConfig(prevConfig)
|
||||
c := params.BeaconConfig()
|
||||
c := params.BeaconConfig().Copy()
|
||||
c.MinGenesisActiveValidatorCount = 16384
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
|
@ -34,6 +34,7 @@ type ForkConfig struct {
|
||||
|
||||
// RunForkTransitionTest is a helper function that runs Altair's transition core tests.
|
||||
func RunForkTransitionTest(t *testing.T, config string) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
require.NoError(t, utils.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := utils.TestFolders(t, config, "altair", "transition/core/pyspec_tests")
|
||||
@ -93,7 +94,7 @@ func RunForkTransitionTest(t *testing.T, config string) {
|
||||
beaconState, err := v1.InitializeFromProto(beaconStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
bc := params.BeaconConfig()
|
||||
bc := params.BeaconConfig().Copy()
|
||||
bc.AltairForkEpoch = types.Epoch(config.ForkEpoch)
|
||||
params.OverrideBeaconConfig(bc)
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user