Skip to content

Commit

Permalink
refactor(cli): removes babe-lead flag logic to test how nodes works
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro committed Apr 5, 2023
1 parent af38364 commit 5e3a1a5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 54 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
53 changes: 0 additions & 53 deletions lib/babe/babe.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,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 @@ -177,10 +173,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 +182,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

0 comments on commit 5e3a1a5

Please sign in to comment.