Skip to content

Commit

Permalink
feat(chain): Add Westend network as command line chain option (#3103)
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Feb 13, 2023
1 parent 56ec4cb commit d9cdd45
Show file tree
Hide file tree
Showing 6 changed files with 366 additions and 13 deletions.
59 changes: 59 additions & 0 deletions chain/westend/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[global]
basepath = "~/.gossamer/westend"
log = "info"
metrics-address = "localhost:9876"

[log]
core = ""
network = ""
rpc = ""
state = ""
runtime = ""
babe = ""
grandpa = ""
sync = ""
digest = ""

[init]
genesis = "./chain/westend/genesis.json"

[account]
key = ""
unlock = ""

[core]
roles = 1
babe-authority = false
grandpa-authority = false

[network]
port = 7001
nobootstrap = false
nomdns = false

[rpc]
enabled = false
external = false
port = 8545
host = "localhost"
modules = [
"system",
"author",
"chain",
"state",
"rpc",
"grandpa",
"offchain",
"childstate",
"syncstate",
"payment",
]
ws-port = 8546
ws = false
ws-external = false


[pprof]
listening-address = "localhost:6060"
block-rate = 0
mutex-rate = 0
99 changes: 99 additions & 0 deletions chain/westend/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package westend

import (
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
)

var (
// GlobalConfig

// DefaultName Default node name
DefaultName = string("Westend")
// DefaultID Default chain ID
DefaultID = string("westend2")
// DefaultConfig Default toml configuration path
DefaultConfig = string("./chain/westend/config.toml")
// DefaultBasePath Default node base directory path
DefaultBasePath = string("~/.gossamer/westend")

// DefaultLvl is the default log level
DefaultLvl = log.Info

// DefaultPruningMode is the default pruning mode
DefaultPruningMode = "archive"
// DefaultRetainBlocks is the default pruning mode
DefaultRetainBlocks = uint32(512)

// DefaultTelemetryURLs is the default URL of the telemetry server to connect to.
DefaultTelemetryURLs []genesis.TelemetryEndpoint

// InitConfig

// DefaultGenesis is the default genesis configuration path
DefaultGenesis = string("./chain/westend/genesis.json")

// AccountConfig

// DefaultKey Default account key
DefaultKey = string("")
// DefaultUnlock Default account unlock
DefaultUnlock = string("")

// CoreConfig

// DefaultAuthority is true if the node is a block producer and a grandpa authority
DefaultAuthority = true
// DefaultRoles Default node roles
DefaultRoles = common.FullNodeRole // authority node (see Table D.2)
// DefaultBabeAuthority is true if the node is a block producer (overwrites previous settings)
DefaultBabeAuthority = true
// DefaultGrandpaAuthority is true if the node is a grandpa authority (overwrites previous settings)
DefaultGrandpaAuthority = true
// DefaultWasmInterpreter is the name of the wasm interpreter to use by default
DefaultWasmInterpreter = wasmer.Name

// NetworkConfig

// DefaultNetworkPort network port
DefaultNetworkPort = uint16(7001)
// DefaultNetworkBootnodes network bootnodes
DefaultNetworkBootnodes = []string(nil)
// DefaultNoBootstrap disables bootstrap
DefaultNoBootstrap = false
// DefaultNoMDNS disables mDNS discovery
DefaultNoMDNS = false

// RPCConfig

// DefaultRPCHTTPHost rpc host
DefaultRPCHTTPHost = string("localhost")
// DefaultRPCHTTPPort rpc port
DefaultRPCHTTPPort = uint32(8545)
// DefaultRPCModules rpc modules
DefaultRPCModules = []string{
"system", "author", "chain", "state", "rpc",
"grandpa", "offchain", "childstate", "syncstate", "payment"}
// DefaultRPCWSPort rpc websocket port
DefaultRPCWSPort = uint32(8546)
)

const (
// PprofConfig

// DefaultPprofListeningAddress default pprof HTTP server listening address.
DefaultPprofListeningAddress = "localhost:6060"

// DefaultPprofBlockRate default block profile rate.
// Set to 0 to disable profiling.
DefaultPprofBlockRate = 0

// DefaultPprofMutexRate default mutex profile rate.
// Set to 0 to disable profiling.
DefaultPprofMutexRate = 0
)
140 changes: 140 additions & 0 deletions chain/westend/genesis.json

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ var (
defaultKusamaConfigPath = "./chain/kusama/config.toml"
defaultPolkadotConfigPath = "./chain/polkadot/config.toml"
defaultDevConfigPath = "./chain/dev/config.toml"

gossamerName = "gssmr"
kusamaName = "kusama"
polkadotName = "polkadot"
devName = "dev"
defaultWestendConfigPath = "./chain/westend/config.toml"
)

// loadConfigFile loads a default config file if --chain is specified, a specific
Expand Down Expand Up @@ -70,25 +66,30 @@ func setupConfigFromChain(ctx *cli.Context) (*ctoml.Config, *dot.Config, error)
// check --chain flag and load configuration from defaults.go
if id := ctx.GlobalString(ChainFlag.Name); id != "" {
switch id {
case gossamerName:
case "gssmr":
logger.Info("loading toml configuration from " + defaultGssmrConfigPath + "...")
tomlCfg = &ctoml.Config{}
err = loadConfig(tomlCfg, defaultGssmrConfigPath)
case kusamaName:
case "kusama":
logger.Info("loading toml configuration from " + defaultKusamaConfigPath + "...")
tomlCfg = &ctoml.Config{}
cfg = dot.KusamaConfig()
err = loadConfig(tomlCfg, defaultKusamaConfigPath)
case polkadotName:
case "polkadot":
logger.Info("loading toml configuration from " + defaultPolkadotConfigPath + "...")
tomlCfg = &ctoml.Config{}
cfg = dot.PolkadotConfig()
err = loadConfig(tomlCfg, defaultPolkadotConfigPath)
case devName:
case "dev":
logger.Info("loading toml configuration from " + defaultDevConfigPath + "...")
tomlCfg = &ctoml.Config{}
cfg = dot.DevConfig()
err = loadConfig(tomlCfg, defaultDevConfigPath)
case "westend":
logger.Info("loading toml configuration from " + defaultWestendConfigPath + "...")
tomlCfg = &ctoml.Config{}
cfg = dot.WestendConfig()
err = loadConfig(tomlCfg, defaultWestendConfigPath)
default:
return nil, nil, fmt.Errorf("unknown chain id provided: %s", id)
}
Expand Down
58 changes: 58 additions & 0 deletions dot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ChainSafe/gossamer/chain/gssmr"
"github.com/ChainSafe/gossamer/chain/kusama"
"github.com/ChainSafe/gossamer/chain/polkadot"
"github.com/ChainSafe/gossamer/chain/westend"
"github.com/ChainSafe/gossamer/dot/state/pruner"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/internal/log"
Expand Down Expand Up @@ -423,3 +424,60 @@ func DevConfig() *Config {
},
}
}

// WestendConfig returns a "westend" node configuration
func WestendConfig() *Config {
return &Config{
Global: GlobalConfig{
Name: westend.DefaultName,
ID: westend.DefaultID,
BasePath: westend.DefaultBasePath,
LogLvl: westend.DefaultLvl,
RetainBlocks: gssmr.DefaultRetainBlocks,
Pruning: pruner.Mode(gssmr.DefaultPruningMode),
MetricsAddress: gssmr.DefaultMetricsAddress,
TelemetryURLs: westend.DefaultTelemetryURLs,
},
Log: LogConfig{
CoreLvl: westend.DefaultLvl,
DigestLvl: westend.DefaultLvl,
SyncLvl: westend.DefaultLvl,
NetworkLvl: westend.DefaultLvl,
RPCLvl: westend.DefaultLvl,
StateLvl: westend.DefaultLvl,
RuntimeLvl: westend.DefaultLvl,
BlockProducerLvl: westend.DefaultLvl,
FinalityGadgetLvl: westend.DefaultLvl,
},
Init: InitConfig{
Genesis: westend.DefaultGenesis,
},
Account: AccountConfig{
Key: westend.DefaultKey,
Unlock: westend.DefaultUnlock,
},
Core: CoreConfig{
Roles: westend.DefaultRoles,
WasmInterpreter: westend.DefaultWasmInterpreter,
},
Network: NetworkConfig{
Port: westend.DefaultNetworkPort,
Bootnodes: westend.DefaultNetworkBootnodes,
NoBootstrap: westend.DefaultNoBootstrap,
NoMDNS: westend.DefaultNoMDNS,
},
RPC: RPCConfig{
Port: westend.DefaultRPCHTTPPort,
Host: westend.DefaultRPCHTTPHost,
Modules: westend.DefaultRPCModules,
WSPort: westend.DefaultRPCWSPort,
},
Pprof: PprofConfig{
Settings: pprof.Settings{
ListeningAddress: westend.DefaultPprofListeningAddress,
BlockProfileRate: westend.DefaultPprofBlockRate,
MutexProfileRate: westend.DefaultPprofMutexRate,
},
},
}
}
4 changes: 0 additions & 4 deletions lib/grandpa/vote_message_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,6 @@ func TestValidateMessage_Equivocation(t *testing.T) {

_, err = gs.validateVoteMessage("", msg)
require.ErrorIs(t, err, ErrEquivocation)
require.EqualError(t, err, "checking for equivocation: vote is equivocatory: "+
"voter 0x88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee has "+
"existing vote 0xfa6648885514eb4e8e5cbcbd18bdcf18a903f71b44769131604304099384e930 "+
"and new vote 0x3d5687d4ca7f086a0e18c4730cac0e1bcfa0e1ae592b5966dcc1a5330a58d10b")
}

func TestValidateMessage_BlockDoesNotExist(t *testing.T) {
Expand Down

0 comments on commit d9cdd45

Please sign in to comment.