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(lib/babe): add --babe-lead flag, update epoch handling logic #1895

Merged
merged 55 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
f9d3d0c
implement tipSyncer.hasCurrentWorker
noot Oct 11, 2021
f11edb8
don't handle transaction messages when syncing
noot Oct 11, 2021
af49037
fix core tests
noot Oct 11, 2021
da7f10e
add unit test
noot Oct 11, 2021
56136ea
fix grandpa >2/3 check
noot Oct 11, 2021
3449217
lint
noot Oct 11, 2021
04fc7b0
fix grandpa unit tests
noot Oct 12, 2021
701dc09
fix grandpa skipped tests
noot Oct 12, 2021
d839ed9
fix get grandpa-ghost
noot Oct 12, 2021
a58ef35
update tracker, update network to cache/not re-gossip consensus msgs
noot Oct 12, 2021
e411560
merge w other branch
noot Oct 12, 2021
cd71260
re-gossip consensus msgs again
noot Oct 12, 2021
eb87877
Merge branch 'development' into noot/sync-cont
noot Oct 12, 2021
2a7eb15
update logs
noot Oct 13, 2021
3c23837
address comments
noot Oct 13, 2021
e267b53
Merge branch 'noot/sync-cont' of github.com:ChainSafe/gossamer into n…
noot Oct 13, 2021
2cc41c2
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Oct 13, 2021
7aa48d0
Merge branch 'noot/sync-cont' of github.com:ChainSafe/gossamer into n…
noot Oct 13, 2021
fde6e68
add epoch timeout in invokeBlockAuthoring, add lead bool to BABE, rem…
noot Oct 13, 2021
ea75c91
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Oct 13, 2021
d13d5fd
fix waiting for first block
noot Oct 13, 2021
70bd312
lint
noot Oct 13, 2021
9345b0e
lint
noot Oct 13, 2021
2294703
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Oct 13, 2021
2f59f64
cleanup
noot Oct 13, 2021
059e122
Merge branch 'noot/sync-finality' of github.com:ChainSafe/gossamer in…
noot Oct 13, 2021
7539451
add --babe-lead flag
noot Oct 13, 2021
21d2fb3
update log
noot Oct 14, 2021
1bbc646
Merge branch 'noot/sync-finality' of github.com:ChainSafe/gossamer in…
noot Oct 14, 2021
ec5fba9
address comments
noot Oct 15, 2021
674af10
update waitForFirstBlock to return err
noot Oct 15, 2021
67809ae
lint
noot Oct 15, 2021
6c3f134
Merge branch 'noot/sync-finality' of github.com:ChainSafe/gossamer in…
noot Oct 15, 2021
7a7d68c
update dev cfg to have babe-lead=true
noot Oct 15, 2021
edfee2c
Merge branch 'development' into noot/sync-finality
noot Oct 15, 2021
bae7217
merge w development
noot Oct 15, 2021
4fccb85
Merge branch 'noot/sync-finality' of github.com:ChainSafe/gossamer in…
noot Oct 15, 2021
5ce9c8e
fix grandpa round test
noot Oct 15, 2021
05e8e88
merge w base
noot Oct 15, 2021
dc8c892
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Oct 18, 2021
9719415
fix unit tests
noot Oct 18, 2021
fceafe3
fix integration tests
noot Oct 18, 2021
b0ee396
fix unit tests
noot Oct 19, 2021
9f2e5e7
address comments
noot Oct 19, 2021
c2dce86
lint
noot Oct 19, 2021
bc41726
fix log
noot Oct 19, 2021
7cd77c1
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Oct 19, 2021
911a7fc
fix tests
noot Oct 19, 2021
398eab2
fix deadlock
noot Oct 19, 2021
57717f4
fix stress tests
noot Oct 19, 2021
486001d
address comments
noot Oct 19, 2021
5b53ca0
address comments
noot Oct 20, 2021
b62dd86
lint
noot Oct 20, 2021
8d9dd14
Merge branch 'development' into noot/sync-babe-fix
noot Oct 20, 2021
bec16d8
Merge branch 'development' into noot/sync-babe-fix
noot Oct 21, 2021
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
1 change: 1 addition & 0 deletions chain/dev/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ unlock = ""
roles = 4
babe-authority = true
grandpa-authority = true
babe-lead = true

[network]
port = 7001
Expand Down
1 change: 1 addition & 0 deletions chain/gssmr/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ port = 7001
nobootstrap = false
nomdns = false
discovery-interval = 10
min-peers = 1

[rpc]
enabled = false
Expand Down
2 changes: 2 additions & 0 deletions chain/gssmr/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ var (
DefaultNoBootstrap = false
// DefaultNoMDNS disables mDNS discovery
DefaultNoMDNS = false
// DefaultMinPeers is the default minimum desired peer count
DefaultMinPeers = 1

// DefaultDiscoveryInterval is the default interval for searching for DHT peers
DefaultDiscoveryInterval = time.Second * 10
Expand Down
1 change: 1 addition & 0 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ func setDotCoreConfig(ctx *cli.Context, tomlCfg ctoml.CoreConfig, cfg *dot.CoreC
cfg.Roles = tomlCfg.Roles
cfg.BabeAuthority = tomlCfg.Roles == types.AuthorityRole
cfg.GrandpaAuthority = tomlCfg.Roles == types.AuthorityRole
cfg.BABELead = ctx.GlobalBool(BABELeadFlag.Name)

// check --roles flag and update node configuration
if roles := ctx.GlobalString(RolesFlag.Name); roles != "" {
Expand Down
6 changes: 6 additions & 0 deletions cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ func TestNetworkConfigFromFlags(t *testing.T) {
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: time.Second * 10,
MinPeers: testCfg.Network.MinPeers,
},
},
{
Expand All @@ -403,6 +404,7 @@ func TestNetworkConfigFromFlags(t *testing.T) {
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: time.Second * 10,
MinPeers: testCfg.Network.MinPeers,
},
},
{
Expand All @@ -416,6 +418,7 @@ func TestNetworkConfigFromFlags(t *testing.T) {
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: time.Second * 10,
MinPeers: testCfg.Network.MinPeers,
},
},
{
Expand All @@ -429,6 +432,7 @@ func TestNetworkConfigFromFlags(t *testing.T) {
NoBootstrap: true,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: time.Second * 10,
MinPeers: testCfg.Network.MinPeers,
},
},
{
Expand All @@ -442,6 +446,7 @@ func TestNetworkConfigFromFlags(t *testing.T) {
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: true,
DiscoveryInterval: time.Second * 10,
MinPeers: testCfg.Network.MinPeers,
},
},
}
Expand Down Expand Up @@ -816,6 +821,7 @@ func TestUpdateConfigFromGenesisData(t *testing.T) {
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: testCfg.Network.DiscoveryInterval,
MinPeers: testCfg.Network.MinPeers,
},
RPC: testCfg.RPC,
System: testCfg.System,
Expand Down
2 changes: 2 additions & 0 deletions cmd/gossamer/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func dotConfigToToml(dcfg *dot.Config) *ctoml.Config {
NoBootstrap: dcfg.Network.NoBootstrap,
NoMDNS: dcfg.Network.NoMDNS,
DiscoveryInterval: int(dcfg.Network.DiscoveryInterval / time.Second),
MinPeers: dcfg.Network.MinPeers,
MaxPeers: dcfg.Network.MaxPeers,
}

cfg.RPC = ctoml.RPCConfig{
Expand Down
3 changes: 3 additions & 0 deletions cmd/gossamer/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestExportCommand(t *testing.T) {
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: testCfg.Network.DiscoveryInterval,
MinPeers: testCfg.Network.MinPeers,
},
RPC: testCfg.RPC,
},
Expand Down Expand Up @@ -119,6 +120,7 @@ func TestExportCommand(t *testing.T) {
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: testCfg.Network.DiscoveryInterval,
MinPeers: testCfg.Network.MinPeers,
},
RPC: testCfg.RPC,
},
Expand Down Expand Up @@ -151,6 +153,7 @@ func TestExportCommand(t *testing.T) {
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: testCfg.Network.DiscoveryInterval,
MinPeers: testCfg.Network.MinPeers,
},
RPC: testCfg.RPC,
},
Expand Down
11 changes: 11 additions & 0 deletions cmd/gossamer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ 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`,
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
}
)

// flag sets that are shared by multiple commands
var (
// GlobalFlags are flags that are valid for use with the root command and all subcommands
Expand Down Expand Up @@ -366,6 +374,9 @@ var (

// telemetry flags
NoTelemetryFlag,

// BABE flags
BABELeadFlag,
}
)

Expand Down
2 changes: 2 additions & 0 deletions dot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type NetworkConfig struct {
type CoreConfig struct {
Roles byte
BabeAuthority bool
BABELead bool
GrandpaAuthority bool
WasmInterpreter string
}
Expand Down Expand Up @@ -183,6 +184,7 @@ func GssmrConfig() *Config {
NoBootstrap: gssmr.DefaultNoBootstrap,
NoMDNS: gssmr.DefaultNoMDNS,
DiscoveryInterval: gssmr.DefaultDiscoveryInterval,
MinPeers: gssmr.DefaultMinPeers,
},
RPC: RPCConfig{
Port: gssmr.DefaultRPCHTTPPort,
Expand Down
1 change: 1 addition & 0 deletions dot/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type CoreConfig struct {
SlotDuration uint64 `toml:"slot-duration,omitempty"`
EpochLength uint64 `toml:"epoch-length,omitempty"`
WasmInterpreter string `toml:"wasm-interpreter,omitempty"`
BABELead bool `toml:"babe-lead,omitempty"`
}

// RPCConfig is to marshal/unmarshal toml RPC config vars
Expand Down
31 changes: 1 addition & 30 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,6 @@ func (s *Service) handleBlock(block *types.Block, state *rtstorage.TrieState) er
return err
}

// check if block production epoch transitioned
if err := s.handleCurrentSlot(&block.Header); err != nil {
logger.Warn("failed to handle epoch for block", "block", block.Header.Hash(), "error", err)
return err
}

go func() {
s.Lock()
defer s.Unlock()
Expand Down Expand Up @@ -313,29 +307,6 @@ func (s *Service) handleCodeSubstitution(hash common.Hash, state *rtstorage.Trie
return nil
}

func (s *Service) handleCurrentSlot(header *types.Header) error {
head := s.blockState.BestBlockHash()
if header.Hash() != head {
return nil
}

epoch, err := s.epochState.GetEpochForBlock(header)
if err != nil {
return err
}

currEpoch, err := s.epochState.GetCurrentEpoch()
if err != nil {
return err
}

if currEpoch == epoch {
return nil
}

return s.epochState.SetCurrentEpoch(epoch)
}
qdm12 marked this conversation as resolved.
Show resolved Hide resolved

// handleBlocksAsync handles a block asynchronously; the handling performed by this function
// does not need to be completed before the next block can be imported.
func (s *Service) handleBlocksAsync() {
Expand Down Expand Up @@ -399,7 +370,7 @@ func (s *Service) handleChainReorg(prev, curr common.Hash) error {
}

for _, ext := range *body {
logger.Info("validating transaction on re-org chain", "extrinsic", ext)
logger.Trace("validating transaction on re-org chain", "extrinsic", ext)
encExt, err := scale.Marshal(ext)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,6 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node,
}
nodeSrvcs = append(nodeSrvcs, coreSrvc)

bp, err := createBABEService(cfg, stateSrvc, ks.Babe, coreSrvc)
if err != nil {
return nil, err
}
nodeSrvcs = append(nodeSrvcs, bp)

fg, err := createGRANDPAService(cfg, stateSrvc, dh, ks.Gran, networkSrvc)
if err != nil {
return nil, err
Expand All @@ -305,6 +299,12 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node,
}
nodeSrvcs = append(nodeSrvcs, syncer)

bp, err := createBABEService(cfg, stateSrvc, ks.Babe, coreSrvc)
if err != nil {
return nil, err
}
nodeSrvcs = append(nodeSrvcs, bp)

sysSrvc, err := createSystemService(&cfg.System, stateSrvc)
if err != nil {
return nil, fmt.Errorf("failed to create system service: %s", err)
Expand Down
1 change: 1 addition & 0 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func createBABEService(cfg *Config, st *state.Service, ks keystore.Keystore, cs
BlockImportHandler: cs,
Authority: cfg.Core.BabeAuthority,
IsDev: cfg.Global.ID == "dev",
Lead: cfg.Core.BABELead,
}

if cfg.Core.BabeAuthority {
Expand Down
Loading