Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Interop Mode #8961

Merged
merged 2 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion beacon-chain/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func configureSlotsPerArchivedPoint(cliCtx *cli.Context) {
}
}

func configureProofOfWork(cliCtx *cli.Context) {
func configureEth1Config(cliCtx *cli.Context) {
if cliCtx.IsSet(flags.ChainID.Name) {
c := params.BeaconConfig()
c.DepositChainID = cliCtx.Uint64(flags.ChainID.Name)
Expand Down Expand Up @@ -82,3 +82,16 @@ func configureNetwork(cliCtx *cli.Context) {
params.OverrideBeaconNetworkConfig(networkCfg)
}
}

func configureInteropConfig(cliCtx *cli.Context) {
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be genStateIsSet && genTimeIsSet && numValsIsSet && votesIsSet?

we need all four flags to apply for interop to work right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope anyone should be fine, technically all we need is just the correct genesis state.

bCfg := params.BeaconConfig()
bCfg.ConfigName = "interop"
params.OverrideBeaconConfig(bCfg)
}
}
73 changes: 72 additions & 1 deletion beacon-chain/node/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestConfigureProofOfWork(t *testing.T) {
require.NoError(t, set.Set(flags.DepositContractFlag.Name, "deposit"))
cliCtx := cli.NewContext(&app, set, nil)

configureProofOfWork(cliCtx)
configureEth1Config(cliCtx)

assert.Equal(t, uint64(100), params.BeaconConfig().DepositChainID)
assert.Equal(t, uint64(200), params.BeaconConfig().DepositNetworkID)
Expand All @@ -88,3 +88,74 @@ func TestConfigureNetwork(t *testing.T) {
assert.DeepEqual(t, []string{"node1", "node2"}, params.BeaconNetworkConfig().BootstrapNodes)
assert.Equal(t, uint64(100), params.BeaconNetworkConfig().ContractDeploymentBlock)
}

func TestConfigureInterop(t *testing.T) {
params.SetupTestConfigCleanup(t)

tests := []struct {
name string
flagSetter func() *cli.Context
configName string
}{
{
"nothing set",
func() *cli.Context {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
return cli.NewContext(&app, set, nil)
},
"mainnet",
},
{
"mock votes set",
func() *cli.Context {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.Bool(flags.InteropMockEth1DataVotesFlag.Name, false, "")
assert.NoError(t, set.Set(flags.InteropMockEth1DataVotesFlag.Name, "true"))
return cli.NewContext(&app, set, nil)
},
"interop",
},
{
"validators set",
func() *cli.Context {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.Uint64(flags.InteropNumValidatorsFlag.Name, 0, "")
assert.NoError(t, set.Set(flags.InteropNumValidatorsFlag.Name, "20"))
return cli.NewContext(&app, set, nil)
},
"interop",
},
{
"genesis time set",
func() *cli.Context {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.Uint64(flags.InteropGenesisTimeFlag.Name, 0, "")
assert.NoError(t, set.Set(flags.InteropGenesisTimeFlag.Name, "200"))
return cli.NewContext(&app, set, nil)
},
"interop",
},
{
"genesis state set",
func() *cli.Context {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(flags.InteropGenesisStateFlag.Name, "", "")
assert.NoError(t, set.Set(flags.InteropGenesisStateFlag.Name, "/path/"))
return cli.NewContext(&app, set, nil)
},
"interop",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
configureInteropConfig(tt.flagSetter())
assert.DeepEqual(t, tt.configName, params.BeaconConfig().ConfigName)
})
}
}
3 changes: 2 additions & 1 deletion beacon-chain/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ func New(cliCtx *cli.Context) (*BeaconNode, error) {
configureChainConfig(cliCtx)
configureHistoricalSlasher(cliCtx)
configureSlotsPerArchivedPoint(cliCtx)
configureProofOfWork(cliCtx)
configureEth1Config(cliCtx)
configureNetwork(cliCtx)
configureInteropConfig(cliCtx)

registry := shared.NewServiceRegistry()

Expand Down