Skip to content

Commit

Permalink
refactor(cli): removes babe-lead flag and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro committed Apr 5, 2023
1 parent 5e3a1a5 commit 77f16ea
Show file tree
Hide file tree
Showing 24 changed files with 8 additions and 60 deletions.
5 changes: 0 additions & 5 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,6 @@ func setDotCoreConfig(ctx *cli.Context, tomlCfg ctoml.CoreConfig, cfg *dot.CoreC
cfg.GrandpaAuthority = common.Roles(tomlCfg.Roles) == common.AuthorityRole
cfg.GrandpaInterval = time.Second * time.Duration(tomlCfg.GrandpaInterval)

cfg.BABELead = tomlCfg.BABELead
if ctx.IsSet(BABELeadFlag.Name) {
cfg.BABELead = ctx.Bool(BABELeadFlag.Name)
}

// check --roles flag and update node configuration
if roles := ctx.String(RolesFlag.Name); roles != "" {
// convert string to byte
Expand Down
5 changes: 0 additions & 5 deletions cmd/gossamer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,6 @@ var (

// BABE flags
var (
BABELeadFlag = cli.BoolFlag{
Name: "babe-lead",
Usage: `specify whether node should build block 1 of the network. only used when starting a new network`,
}
ValidatorFlag = cli.BoolFlag{
Name: "validator", // TODO(ed) implement
}
Expand Down Expand Up @@ -461,7 +457,6 @@ var (
&TelemetryURLFlag,

// BABE flags
&BABELeadFlag,
&ValidatorFlag,
}
)
Expand Down
2 changes: 1 addition & 1 deletion devnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export $DD_API_KEY=YourKey

There are four Docker files used in the devnet.

- `alice.Dockerfile` is the lead node and is initiated with the `babe-lead` flag to build the first block.
- `alice.Dockerfile` is the lead node.
- `bob.Dockerfile` is used for both `bob` and `charlie` and shares the same genesis as alice docker file.
- `substrate_alice.Dockerfile` is the alice node initiated with explicit node key to keep a deterministic peer id (the same used by gossamer alice node)
- `substrate_bob.Dockerfile` is used for `bob` and `charlie` and shares the same genesis as alice docker file.
Expand Down
2 changes: 1 addition & 1 deletion devnet/alice.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:alic

WORKDIR /gossamer

ENTRYPOINT service datadog-agent start && gossamer --key=alice --babe-lead --publish-metrics --metrics-address=":9876" --rpc --rpc-external=true --pubdns=alice --port 7001
ENTRYPOINT service datadog-agent start && gossamer --key=alice --publish-metrics --metrics-address=":9876" --rpc --rpc-external=true --pubdns=alice --port 7001

EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp 6060/tcp
1 change: 0 additions & 1 deletion dot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ type NetworkConfig struct {
type CoreConfig struct {
Roles common.Roles
BabeAuthority bool
BABELead bool
GrandpaAuthority bool
WasmInterpreter string
GrandpaInterval time.Duration
Expand Down
1 change: 0 additions & 1 deletion dot/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ type CoreConfig struct {
EpochLength uint64 `toml:"epoch-length,omitempty"`
WasmInterpreter string `toml:"wasm-interpreter,omitempty"`
GrandpaInterval uint32 `toml:"grandpa-interval,omitempty"`
BABELead bool `toml:"babe-lead,omitempty"`
}

// StateConfig contains the configuration for the state.
Expand Down
1 change: 0 additions & 1 deletion dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func (nodeBuilder) createBABEServiceWithBuilder(cfg *Config, st *state.Service,
BlockImportHandler: cs,
Authority: cfg.Core.BabeAuthority,
IsDev: cfg.Global.ID == "dev",
Lead: cfg.Core.BABELead,
Telemetry: telemetryMailer,
}

Expand Down
1 change: 0 additions & 1 deletion dot/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func TestNewTestConfig(t *testing.T) {
Core: CoreConfig{
Roles: 4,
BabeAuthority: true,
BABELead: false,
GrandpaAuthority: true,
WasmInterpreter: "wasmer",
GrandpaInterval: 1000000000,
Expand Down
15 changes: 4 additions & 11 deletions lib/babe/babe.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ var logger = log.NewFromGlobal(log.AddContext("pkg", "babe"))

// Service contains the VRF keys for the validator, as well as BABE configuation data
type Service struct {
ctx context.Context
cancel context.CancelFunc
authority bool
dev bool
// lead is used when setting up a new network from genesis.
// the "lead" node is the node that is designated to build block 1, after which the rest of the nodes
// will sync block 1 and determine the first slot of the network based on it
lead bool
ctx context.Context
cancel context.CancelFunc
authority bool
dev bool
constants constants
epochHandler *epochHandler

Expand Down Expand Up @@ -64,7 +60,6 @@ type ServiceConfig struct {
AuthData []types.Authority
IsDev bool
Authority bool
Lead bool
Telemetry Telemetry
}

Expand Down Expand Up @@ -112,7 +107,6 @@ func (Builder) NewServiceIFace(cfg *ServiceConfig) (service *Service, err error)
authority: cfg.Authority,
dev: cfg.IsDev,
blockImportHandler: cfg.BlockImportHandler,
lead: cfg.Lead,
constants: constants{
slotDuration: slotDuration,
epochLength: epochLength,
Expand Down Expand Up @@ -160,7 +154,6 @@ func NewService(cfg *ServiceConfig) (*Service, error) {
authority: cfg.Authority,
dev: cfg.IsDev,
blockImportHandler: cfg.BlockImportHandler,
lead: cfg.Lead,
constants: constants{
slotDuration: slotDuration,
epochLength: epochLength,
Expand Down
10 changes: 2 additions & 8 deletions lib/babe/babe_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestService_ProducesBlocks(t *testing.T) {
Return(nil).MinTimes(2)
cfg := ServiceConfig{
Authority: true,
Lead: true,
BlockImportHandler: blockImportHandler,
}

Expand Down Expand Up @@ -90,9 +89,7 @@ func TestService_GetAuthorityIndex(t *testing.T) {
}

func TestStartAndStop(t *testing.T) {
cfg := ServiceConfig{
Lead: true,
}
cfg := ServiceConfig{}
gen, genTrie, genHeader := newWestendLocalGenesisWithTrieAndHeader(t)
bs := createTestService(t, cfg, gen, genTrie, genHeader, nil)
err := bs.Start()
Expand All @@ -102,9 +99,7 @@ func TestStartAndStop(t *testing.T) {
}

func TestService_PauseAndResume(t *testing.T) {
cfg := ServiceConfig{
Lead: true,
}
cfg := ServiceConfig{}
genesis, genesisTrie, genesisHeader := newWestendLocalGenesisWithTrieAndHeader(t)
babeService := createTestService(t, cfg, genesis, genesisTrie, genesisHeader, nil)
err := babeService.Start()
Expand Down Expand Up @@ -136,7 +131,6 @@ func TestService_PauseAndResume(t *testing.T) {
func TestService_HandleSlotWithLaggingSlot(t *testing.T) {
cfg := ServiceConfig{
Authority: true,
Lead: true,
}

genesis, genesisTrie, genesisHeader := newWestendDevGenesisWithTrieAndHeader(t)
Expand Down
1 change: 0 additions & 1 deletion tests/polkadotjs_test/start_polkadotjs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestStartGossamerAndPolkadotAPI(t *testing.T) {

tomlConfig := config.Default()
tomlConfig.Init.Genesis = libutils.GetWestendLocalRawGenesisPath(t)
tomlConfig.Core.BABELead = true
tomlConfig.RPC.WS = true
tomlConfig.RPC.Unsafe = true
tomlConfig.RPC.WSUnsafe = true
Expand Down
2 changes: 0 additions & 2 deletions tests/rpc/rpc_02-author_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func TestAuthorSubmitExtrinsic(t *testing.T) {
tomlConfig := config.Default()
tomlConfig.Account.Key = "alice"
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true

node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -100,7 +99,6 @@ func TestAuthorRPC(t *testing.T) { //nolint:tparallel
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
node.InitAndStartTest(ctx, t, cancel)
Expand Down
2 changes: 0 additions & 2 deletions tests/rpc/rpc_03-chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestChainRPC(t *testing.T) {
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true

node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -138,7 +137,6 @@ func TestChainSubscriptionRPC(t *testing.T) { //nolint:tparallel
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true
tomlConfig.RPC.WS = true // WS port is set in the node.New constructor
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
Expand Down
1 change: 0 additions & 1 deletion tests/rpc/rpc_04-offchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func TestOffchainRPC(t *testing.T) { //nolint:tparallel

genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Core.BABELead = true
tomlConfig.Init.Genesis = genesisPath
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
Expand Down
3 changes: 0 additions & 3 deletions tests/rpc/rpc_05-state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestStateRPCResponseValidation(t *testing.T) { //nolint:tparallel
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
node.InitAndStartTest(ctx, t, cancel)
Expand Down Expand Up @@ -165,7 +164,6 @@ func TestStateRPCAPI(t *testing.T) {
genesisPath := libutils.GetWestendLocalRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
node.InitAndStartTest(ctx, t, cancel)
Expand Down Expand Up @@ -367,7 +365,6 @@ func TestStateRPCAPI(t *testing.T) {
func TestRPCStructParamUnmarshal(t *testing.T) {
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Core.BABELead = true
tomlConfig.Init.Genesis = genesisPath
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
Expand Down
1 change: 0 additions & 1 deletion tests/rpc/rpc_06-engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func TestEngineRPC(t *testing.T) { //nolint:tparallel
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
node.InitAndStartTest(ctx, t, cancel)
Expand Down
1 change: 0 additions & 1 deletion tests/rpc/rpc_07-payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func TestPaymentRPC(t *testing.T) { //nolint:tparallel
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
node.InitAndStartTest(ctx, t, cancel)
Expand Down
1 change: 0 additions & 1 deletion tests/rpc/rpc_08-contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func TestContractsRPC(t *testing.T) { //nolint:tparallel
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
node.InitAndStartTest(ctx, t, cancel)
Expand Down
1 change: 0 additions & 1 deletion tests/rpc/rpc_09-babe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func TestBabeRPC(t *testing.T) { //nolint:tparallel
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true
node := node.New(t, tomlConfig)
ctx, cancel := context.WithCancel(context.Background())
node.InitAndStartTest(ctx, t, cancel)
Expand Down
1 change: 0 additions & 1 deletion tests/stress/grandpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
func TestStress_Grandpa_OneAuthority(t *testing.T) {
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Core.BABELead = true
tomlConfig.Init.Genesis = genesisPath
n := node.New(t, tomlConfig)

Expand Down
7 changes: 0 additions & 7 deletions tests/stress/stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func TestSync_SingleBlockProducer(t *testing.T) {

configNoGrandpa := config.NoGrandpa()
configNoGrandpa.Init.Genesis = genesisPath
configNoGrandpa.Core.BABELead = true
configNoGrandpa.Account.Key = "alice"
babeLeadNode := node.New(t, configNoGrandpa, node.SetIndex(numNodes-1))

Expand Down Expand Up @@ -212,7 +211,6 @@ func TestSync_SingleSyncingNode(t *testing.T) {
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
blockProducingConfig := config.Default()
blockProducingConfig.Init.Genesis = genesisPath
blockProducingConfig.Core.BABELead = true
alice := node.New(t, blockProducingConfig, node.SetIndex(0))

alice.InitAndStartTest(ctx, t, cancel)
Expand Down Expand Up @@ -252,7 +250,6 @@ func TestSync_Bench(t *testing.T) {
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
configNoGrandpa := config.NoGrandpa()
configNoGrandpa.Init.Genesis = genesisPath
configNoGrandpa.Core.BABELead = true

alice := node.New(t, configNoGrandpa, node.SetIndex(0))

Expand Down Expand Up @@ -284,7 +281,6 @@ func TestSync_Bench(t *testing.T) {
// start syncing node
configNoAuthority := config.NotAuthority()
configNoAuthority.Init.Genesis = genesisPath
configNoAuthority.Core.BABELead = true
bob := node.New(t, configNoAuthority, node.SetIndex(1))

bob.InitAndStartTest(ctx, t, cancel)
Expand Down Expand Up @@ -362,7 +358,6 @@ func TestSync_Restart(t *testing.T) {
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
blockProducingConfig := config.Default()
blockProducingConfig.Init.Genesis = genesisPath
blockProducingConfig.Core.BABELead = true
producingNode := node.New(t, blockProducingConfig, node.SetIndex(numNodes-1))

err := producingNode.Init(mainCtx)
Expand Down Expand Up @@ -456,7 +451,6 @@ func TestSync_SubmitExtrinsic(t *testing.T) {
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
configNoGrandpa := config.NoGrandpa()
configNoGrandpa.Init.Genesis = genesisPath
configNoGrandpa.Core.BABELead = true
producingNode := node.New(t, configNoGrandpa, node.SetIndex(0))
producingNode.InitAndStartTest(ctx, t, cancel)

Expand Down Expand Up @@ -628,7 +622,6 @@ func Test_SubmitAndWatchExtrinsic(t *testing.T) {
tomlConfig := config.NoGrandpa()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.RPC.WS = true
tomlConfig.Core.BABELead = true
producingNode := node.New(t, tomlConfig, node.SetIndex(0))
ctx, cancel := context.WithCancel(context.Background())
producingNode.InitAndStartTest(ctx, t, cancel)
Expand Down
1 change: 0 additions & 1 deletion tests/utils/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func NoBabe() (cfg toml.Config) {
func NoGrandpa() (cfg toml.Config) {
cfg = Default()
cfg.Core.GrandpaAuthority = false
cfg.Core.BABELead = true
cfg.Core.GrandpaInterval = 1
return cfg
}
Expand Down
1 change: 0 additions & 1 deletion tests/utils/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func Test_Node_InitAndStartTest(t *testing.T) {
t.Cleanup(cancel)

tomlConfig := config.Default()
tomlConfig.Core.BABELead = true

n := New(t, tomlConfig)

Expand Down
2 changes: 0 additions & 2 deletions tests/utils/node/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ type Nodes []Node

// MakeNodes creates `num` nodes using the `tomlConfig`
// as a base config for each node. It overrides some of configuration:
// - the first node is always the BABE lead (overrides the toml configuration)
// - the index of each node is incremented per node (overrides the SetIndex option, if set)
func MakeNodes(t *testing.T, num int, tomlConfig toml.Config,
options ...Option) (nodes Nodes) {
nodes = make(Nodes, num)
for i := range nodes {
options = append(options, SetIndex(i))
tomlConfig.Core.BABELead = i == 0
nodes[i] = New(t, tomlConfig, options...)
}
return nodes
Expand Down

0 comments on commit 77f16ea

Please sign in to comment.