Skip to content

Commit

Permalink
refactor(cli): Remove babe-lead flag (#3193)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro authored Apr 11, 2023
1 parent 91b748f commit af0435d
Show file tree
Hide file tree
Showing 26 changed files with 8 additions and 116 deletions.
1 change: 0 additions & 1 deletion chain/westend-local/config-alice.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ unlock = ""
roles = 4
babe-authority = true
grandpa-authority = true
babe-lead = true

[network]
port = 7001
Expand Down
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
68 changes: 4 additions & 64 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 All @@ -125,10 +119,6 @@ func (Builder) NewServiceIFace(cfg *ServiceConfig) (service *Service, err error)
cfg.Authority, babeService.constants.slotDuration, babeService.constants.epochLength,
)

if cfg.Lead {
logger.Debug("node designated to build block 1")
}

return babeService, nil
}

Expand Down Expand Up @@ -164,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 All @@ -177,10 +166,6 @@ func NewService(cfg *ServiceConfig) (*Service, error) {
cfg.Authority, babeService.constants.slotDuration, babeService.constants.epochLength,
)

if cfg.Lead {
logger.Debug("node designated to build block 1")
}

return babeService, nil
}

Expand All @@ -190,55 +175,10 @@ func (b *Service) Start() error {
return nil
}

// if we aren't leading node, wait for first block
if !b.lead {
if err := b.waitForFirstBlock(); err != nil {
return err
}
}

go b.initiate()
return nil
}

func (b *Service) waitForFirstBlock() error {
head, err := b.blockState.BestBlockHeader()
if err != nil {
return fmt.Errorf("cannot get best block header: %w", err)
}

if head.Number > 0 {
return nil
}

ch := b.blockState.GetImportedBlockNotifierChannel()
defer b.blockState.FreeImportedBlockNotifierChannel(ch)

const firstBlockTimeout = time.Minute * 5
timer := time.NewTimer(firstBlockTimeout)

// loop until block 1
for {
select {
case block, ok := <-ch:
if !ok {
timer.Stop()
return errChannelClosed
}

if ok && block.Header.Number > 0 {
timer.Stop()
return nil
}
case <-timer.C:
return errFirstBlockTimeout
case <-b.ctx.Done():
timer.Stop()
return b.ctx.Err()
}
}
}

// SlotDuration returns the current service slot duration in milliseconds
func (b *Service) SlotDuration() uint64 {
return uint64(b.constants.slotDuration.Milliseconds())
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
2 changes: 0 additions & 2 deletions lib/babe/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ var (

errNilParentHeader = errors.New("parent header is nil")
errInvalidResult = errors.New("invalid error value")
errFirstBlockTimeout = errors.New("timed out waiting for first block")
errChannelClosed = errors.New("block notifier channel was closed")
errOverPrimarySlotThreshold = errors.New("cannot claim slot, over primary threshold")
errNotOurTurnToPropose = errors.New("cannot claim slot, not our turn to propose a block")
errMissingDigestItems = errors.New("block header is missing digest items")
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
Loading

0 comments on commit af0435d

Please sign in to comment.