Skip to content

Commit

Permalink
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
Browse files Browse the repository at this point in the history
…/grandpa-fix
  • Loading branch information
noot committed Jul 26, 2021
2 parents 1550040 + 3c22ace commit 2946d6b
Show file tree
Hide file tree
Showing 33 changed files with 441 additions and 277 deletions.
1 change: 1 addition & 0 deletions chain/gssmr/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ grandpa-authority = true
port = 7001
nobootstrap = false
nomdns = false
discovery-interval = 10

[rpc]
enabled = false
Expand Down
5 changes: 5 additions & 0 deletions chain/gssmr/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package gssmr

import (
"time"

"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
log "github.com/ChainSafe/log15"
)
Expand Down Expand Up @@ -80,6 +82,9 @@ var (
// DefaultNoMDNS disables mDNS discovery
DefaultNoMDNS = false

// DefaultDiscoveryInterval is the default interval for searching for DHT peers
DefaultDiscoveryInterval = time.Second * 10

// RPCConfig

// DefaultRPCHTTPHost rpc host
Expand Down
1 change: 1 addition & 0 deletions chain/polkadot/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[global]
basepath = "~/.gossamer/polkadot"
log = "info"
metrics-port = 9876

[log]
core = ""
Expand Down
8 changes: 8 additions & 0 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/ChainSafe/gossamer/chain/dev"
"github.com/ChainSafe/gossamer/chain/gssmr"
Expand Down Expand Up @@ -627,6 +628,12 @@ func setDotNetworkConfig(ctx *cli.Context, tomlCfg ctoml.NetworkConfig, cfg *dot
cfg.MaxPeers = tomlCfg.MaxPeers
cfg.PersistentPeers = tomlCfg.PersistentPeers

if tomlCfg.DiscoveryInterval > 0 {
cfg.DiscoveryInterval = time.Second * time.Duration(tomlCfg.DiscoveryInterval)
} else {
cfg.DiscoveryInterval = 0
}

// check --port flag and update node configuration
if port := ctx.GlobalUint(PortFlag.Name); port != 0 {
cfg.Port = uint32(port)
Expand Down Expand Up @@ -671,6 +678,7 @@ func setDotNetworkConfig(ctx *cli.Context, tomlCfg ctoml.NetworkConfig, cfg *dot
"minpeers", cfg.MinPeers,
"maxpeers", cfg.MaxPeers,
"persistent-peers", cfg.PersistentPeers,
"discovery-interval", cfg.DiscoveryInterval,
)
}

Expand Down
67 changes: 37 additions & 30 deletions cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"io/ioutil"
"testing"
"time"

"github.com/ChainSafe/gossamer/chain/dev"
"github.com/ChainSafe/gossamer/chain/gssmr"
Expand Down Expand Up @@ -383,59 +384,64 @@ func TestNetworkConfigFromFlags(t *testing.T) {
[]string{"config", "port"},
[]interface{}{testCfgFile.Name(), "1234"},
dot.NetworkConfig{
Port: 1234,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Port: 1234,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: time.Second * 10,
},
},
{
"Test gossamer --bootnodes",
[]string{"config", "bootnodes"},
[]interface{}{testCfgFile.Name(), "peer1,peer2"},
dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: []string{"peer1", "peer2"},
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Port: testCfg.Network.Port,
Bootnodes: []string{"peer1", "peer2"},
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: time.Second * 10,
},
},
{
"Test gossamer --protocol",
[]string{"config", "protocol"},
[]interface{}{testCfgFile.Name(), "/gossamer/test/0"},
dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: "/gossamer/test/0",
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: "/gossamer/test/0",
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: time.Second * 10,
},
},
{
"Test gossamer --nobootstrap",
[]string{"config", "nobootstrap"},
[]interface{}{testCfgFile.Name(), "true"},
dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: true,
NoMDNS: testCfg.Network.NoMDNS,
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: true,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: time.Second * 10,
},
},
{
"Test gossamer --nomdns",
[]string{"config", "nomdns"},
[]interface{}{testCfgFile.Name(), "true"},
dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: true,
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: true,
DiscoveryInterval: time.Second * 10,
},
},
}
Expand Down Expand Up @@ -804,11 +810,12 @@ func TestUpdateConfigFromGenesisData(t *testing.T) {
Account: testCfg.Account,
Core: testCfg.Core,
Network: dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: []string{}, // TODO: improve cmd tests #687
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Port: testCfg.Network.Port,
Bootnodes: []string{}, // TODO: improve cmd tests #687
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: testCfg.Network.DiscoveryInterval,
},
RPC: testCfg.RPC,
System: testCfg.System,
Expand Down
12 changes: 7 additions & 5 deletions cmd/gossamer/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"fmt"
"time"

"github.com/ChainSafe/gossamer/dot"
ctoml "github.com/ChainSafe/gossamer/dot/config/toml"
Expand Down Expand Up @@ -117,11 +118,12 @@ func dotConfigToToml(dcfg *dot.Config) *ctoml.Config {
}

cfg.Network = ctoml.NetworkConfig{
Port: dcfg.Network.Port,
Bootnodes: dcfg.Network.Bootnodes,
ProtocolID: dcfg.Network.ProtocolID,
NoBootstrap: dcfg.Network.NoBootstrap,
NoMDNS: dcfg.Network.NoMDNS,
Port: dcfg.Network.Port,
Bootnodes: dcfg.Network.Bootnodes,
ProtocolID: dcfg.Network.ProtocolID,
NoBootstrap: dcfg.Network.NoBootstrap,
NoMDNS: dcfg.Network.NoMDNS,
DiscoveryInterval: int(dcfg.Network.DiscoveryInterval / time.Second),
}

cfg.RPC = ctoml.RPCConfig{
Expand Down
33 changes: 18 additions & 15 deletions cmd/gossamer/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ func TestExportCommand(t *testing.T) {
Account: testCfg.Account,
Core: testCfg.Core,
Network: dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes, // TODO: improve cmd tests #687
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes, // TODO: improve cmd tests #687
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: testCfg.Network.DiscoveryInterval,
},
RPC: testCfg.RPC,
},
Expand All @@ -112,11 +113,12 @@ func TestExportCommand(t *testing.T) {
Account: testCfg.Account,
Core: testCfg.Core,
Network: dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: []string{testBootnode},
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Port: testCfg.Network.Port,
Bootnodes: []string{testBootnode},
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: testCfg.Network.DiscoveryInterval,
},
RPC: testCfg.RPC,
},
Expand All @@ -143,11 +145,12 @@ func TestExportCommand(t *testing.T) {
Account: testCfg.Account,
Core: testCfg.Core,
Network: dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: []string{testBootnode}, // TODO: improve cmd tests #687
ProtocolID: testProtocol,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Port: testCfg.Network.Port,
Bootnodes: []string{testBootnode}, // TODO: improve cmd tests #687
ProtocolID: testProtocol,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
DiscoveryInterval: testCfg.Network.DiscoveryInterval,
},
RPC: testCfg.RPC,
},
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/usage/import-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Note: the `import-runtime` subcommand does not validate that the runtime in the
To create the raw genesis file used by the node, you can use the `gossamer build-spec` subcommand.

```
./bin/gossamer build-spec --raw --genesis genesis-spec.json > genesis.json
./bin/gossamer build-spec --raw --genesis-spec genesis-spec.json > genesis.json
or
./bin/gossamer build-spec --raw --genesis-spec genesis-spec.json --output genesis.json
```

This creates a genesis file `genesis.json` that is usable by the node.
Expand Down
28 changes: 16 additions & 12 deletions dot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package dot

import (
"encoding/json"
"time"

"github.com/ChainSafe/gossamer/chain/dev"
"github.com/ChainSafe/gossamer/chain/gssmr"
Expand Down Expand Up @@ -82,14 +83,15 @@ type AccountConfig struct {

// NetworkConfig is to marshal/unmarshal toml network config vars
type NetworkConfig struct {
Port uint32
Bootnodes []string
ProtocolID string
NoBootstrap bool
NoMDNS bool
MinPeers int
MaxPeers int
PersistentPeers []string
Port uint32
Bootnodes []string
ProtocolID string
NoBootstrap bool
NoMDNS bool
MinPeers int
MaxPeers int
PersistentPeers []string
DiscoveryInterval time.Duration
}

// CoreConfig is to marshal/unmarshal toml core config vars
Expand Down Expand Up @@ -166,10 +168,11 @@ func GssmrConfig() *Config {
WasmInterpreter: gssmr.DefaultWasmInterpreter,
},
Network: NetworkConfig{
Port: gssmr.DefaultNetworkPort,
Bootnodes: gssmr.DefaultNetworkBootnodes,
NoBootstrap: gssmr.DefaultNoBootstrap,
NoMDNS: gssmr.DefaultNoMDNS,
Port: gssmr.DefaultNetworkPort,
Bootnodes: gssmr.DefaultNetworkBootnodes,
NoBootstrap: gssmr.DefaultNoBootstrap,
NoMDNS: gssmr.DefaultNoMDNS,
DiscoveryInterval: gssmr.DefaultDiscoveryInterval,
},
RPC: RPCConfig{
Port: gssmr.DefaultRPCHTTPPort,
Expand Down Expand Up @@ -238,6 +241,7 @@ func PolkadotConfig() *Config {
LogLvl: polkadot.DefaultLvl,
RetainBlocks: gssmr.DefaultRetainBlocks,
Pruning: pruner.Mode(gssmr.DefaultPruningMode),
MetricsPort: gssmr.DefaultMetricsPort,
},
Log: LogConfig{
CoreLvl: polkadot.DefaultLvl,
Expand Down
17 changes: 9 additions & 8 deletions dot/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ type AccountConfig struct {

// NetworkConfig is to marshal/unmarshal toml network config vars
type NetworkConfig struct {
Port uint32 `toml:"port,omitempty"`
Bootnodes []string `toml:"bootnodes,omitempty"`
ProtocolID string `toml:"protocol,omitempty"`
NoBootstrap bool `toml:"nobootstrap,omitempty"`
NoMDNS bool `toml:"nomdns,omitempty"`
MinPeers int `toml:"min-peers,omitempty"`
MaxPeers int `toml:"max-peers,omitempty"`
PersistentPeers []string `toml:"persistent-peers,omitempty"`
Port uint32 `toml:"port,omitempty"`
Bootnodes []string `toml:"bootnodes,omitempty"`
ProtocolID string `toml:"protocol,omitempty"`
NoBootstrap bool `toml:"nobootstrap,omitempty"`
NoMDNS bool `toml:"nomdns,omitempty"`
MinPeers int `toml:"min-peers,omitempty"`
MaxPeers int `toml:"max-peers,omitempty"`
PersistentPeers []string `toml:"persistent-peers,omitempty"`
DiscoveryInterval int `toml:"discovery-interval,omitempty"`
}

// CoreConfig is to marshal/unmarshal toml core config vars
Expand Down
16 changes: 9 additions & 7 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ func (s *Service) handleCodeSubstitution(hash common.Hash) error {
return err
}

// TODO: this needs to create a new runtime instance, otherwise it will update
// the blocks that reference the current runtime version to use the code substition
err = rt.UpdateRuntimeCode(code)
if err != nil {
return err
Expand Down Expand Up @@ -307,16 +309,17 @@ func (s *Service) handleCurrentSlot(header *types.Header) error {
// does not need to be completed before the next block can be imported.
func (s *Service) handleBlocksAsync() {
for {
prev := s.blockState.BestBlockHash()

select {
case block := <-s.blockAddCh:
if block == nil {
continue
}

// TODO: add inherent check
// if err := s.handleChainReorg(prev, block.Header.Hash()); err != nil {
// logger.Warn("failed to re-add transactions to chain upon re-org", "error", err)
// }
if err := s.handleChainReorg(prev, block.Header.Hash()); err != nil {
logger.Warn("failed to re-add transactions to chain upon re-org", "error", err)
}

if err := s.maintainTransactionPool(block); err != nil {
logger.Warn("failed to maintain transaction pool", "error", err)
Expand Down Expand Up @@ -422,12 +425,11 @@ func (s *Service) maintainTransactionPool(block *types.Block) error {
// re-validate transactions in the pool and move them to the queue
txs := s.transactionState.PendingInPool()
for _, tx := range txs {
// TODO: re-add this on update to v0.8

// TODO: re-add this
// val, err := s.rt.ValidateTransaction(tx.Extrinsic)
// if err != nil {
// // failed to validate tx, remove it from the pool or queue
// s.transactionState.RemoveExtrinsic(ext)
// s.transactionState.RemoveExtrinsic(tx.Extrinsic)
// continue
// }

Expand Down
Loading

0 comments on commit 2946d6b

Please sign in to comment.