Skip to content

Commit

Permalink
Merge branch 'development' into issue-1767
Browse files Browse the repository at this point in the history
  • Loading branch information
noot authored Oct 21, 2021
2 parents 7b6e3e6 + 7abcce6 commit 30e0dbc
Show file tree
Hide file tree
Showing 67 changed files with 1,117 additions and 1,199 deletions.
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`,
}
)

// 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)
}

// 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
2 changes: 1 addition & 1 deletion dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestHandleChainReorg_WithReorg_Trans(t *testing.T) {

nonce := uint64(0)

// Add extrinsic to block `block31`
// Add extrinsic to block `block41`
ext := createExtrinsic(t, rt, bs.GenesisHash(), nonce)

block41 := sync.BuildBlock(t, rt, &block31.Header, ext)
Expand Down
6 changes: 4 additions & 2 deletions dot/digest/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ func TestHandler_GrandpaScheduledChange(t *testing.T) {

headers, _ := state.AddBlocksToState(t, handler.blockState.(*state.BlockState), 2, false)
for i, h := range headers {
handler.blockState.(*state.BlockState).SetFinalisedHash(h.Hash(), uint64(i), 0)
err = handler.blockState.(*state.BlockState).SetFinalisedHash(h.Hash(), uint64(i), 0)
require.NoError(t, err)
}

// authorities should change on start of block 3 from start
headers, _ = state.AddBlocksToState(t, handler.blockState.(*state.BlockState), 1, false)
for _, h := range headers {
handler.blockState.(*state.BlockState).SetFinalisedHash(h.Hash(), 3, 0)
err = handler.blockState.(*state.BlockState).SetFinalisedHash(h.Hash(), 3, 0)
require.NoError(t, err)
}

time.Sleep(time.Millisecond * 500)
Expand Down
12 changes: 6 additions & 6 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,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 @@ -306,6 +300,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
2 changes: 1 addition & 1 deletion dot/rpc/modules/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (cm *ChainModule) GetBlock(r *http.Request, req *ChainHashRequest, res *Cha
return err
}
for _, e := range ext {
res.Block.Body = append(res.Block.Body, fmt.Sprintf("0x%x", e))
res.Block.Body = append(res.Block.Body, e.String())
}
}
return nil
Expand Down
55 changes: 22 additions & 33 deletions dot/rpc/modules/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,14 @@ func TestChainGetFinalizedHeadByRound(t *testing.T) {

digest := types.NewDigest()
digest.Add(*types.NewBabeSecondaryPlainPreDigest(0, 1).ToPreRuntimeDigest())
header := &types.Header{

header := types.Header{
ParentHash: genesisHeader.Hash(),
Number: big.NewInt(1),
Digest: digest,
}
err = state.Block.AddBlock(&types.Block{
Header: *header,
Header: header,
Body: types.Body{},
})
require.NoError(t, err)
Expand Down Expand Up @@ -369,60 +370,48 @@ func newTestStateService(t *testing.T) *state.Service {
rt, err := wasmer.NewRuntimeFromGenesis(rtCfg)
require.NoError(t, err)

err = loadTestBlocks(t, genesisHeader.Hash(), stateSrvc.Block, rt)
require.NoError(t, err)
loadTestBlocks(t, genesisHeader.Hash(), stateSrvc.Block, rt)

t.Cleanup(func() {
stateSrvc.Stop()
})
return stateSrvc
}

func loadTestBlocks(t *testing.T, gh common.Hash, bs *state.BlockState, rt runtime.Instance) error {
// Create header
header0 := &types.Header{
Number: big.NewInt(0),
func loadTestBlocks(t *testing.T, gh common.Hash, bs *state.BlockState, rt runtime.Instance) {
header1 := &types.Header{
Number: big.NewInt(1),
Digest: types.NewDigest(),
ParentHash: gh,
StateRoot: trie.EmptyHash,
}
// Create blockHash
blockHash0 := header0.Hash()
block0 := &types.Block{
Header: *header0,
Body: sampleBodyBytes,
}

err := bs.AddBlock(block0)
if err != nil {
return err
block1 := &types.Block{
Header: *header1,
Body: sampleBodyBytes,
}

bs.StoreRuntime(block0.Header.Hash(), rt)
err := bs.AddBlock(block1)
require.NoError(t, err)
bs.StoreRuntime(header1.Hash(), rt)

// Create header & blockData for block 1
digest := types.NewDigest()
err = digest.Add(*types.NewBabeSecondaryPlainPreDigest(0, 1).ToPreRuntimeDigest())
require.NoError(t, err)
header1 := &types.Header{
Number: big.NewInt(1),

header2 := &types.Header{
Number: big.NewInt(2),
Digest: digest,
ParentHash: blockHash0,
ParentHash: header1.Hash(),
StateRoot: trie.EmptyHash,
}

block1 := &types.Block{
Header: *header1,
block2 := &types.Block{
Header: *header2,
Body: sampleBodyBytes,
}

// Add the block1 to the DB
err = bs.AddBlock(block1)
if err != nil {
return err
}

bs.StoreRuntime(block1.Header.Hash(), rt)

return nil
err = bs.AddBlock(block2)
require.NoError(t, err)
bs.StoreRuntime(header2.Hash(), rt)
}
2 changes: 1 addition & 1 deletion dot/rpc/modules/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newState(t *testing.T) (*state.BlockState, *state.EpochState) {
_, _, genesisHeader := genesis.NewTestGenesisWithTrieAndHeader(t)
bs, err := state.NewBlockStateFromGenesis(db, genesisHeader)
require.NoError(t, err)
es, err := state.NewEpochStateFromGenesis(db, genesisBABEConfig)
es, err := state.NewEpochStateFromGenesis(db, bs, genesisBABEConfig)
require.NoError(t, err)
return bs, es
}
Expand Down
Loading

0 comments on commit 30e0dbc

Please sign in to comment.