Skip to content

Commit

Permalink
chore(config): respect the xdg data home specification (#3698)
Browse files Browse the repository at this point in the history
Co-authored-by: q9f <[email protected]>
Co-authored-by: Kishan Mohanbhai Sagathiya <[email protected]>
  • Loading branch information
3 people authored Jan 18, 2024
1 parent a9db0ec commit 51d57ae
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.staging
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM golang:1.21

ARG chain="polkadot"
ARG basepath="~/.gossamer"
ARG basepath="~/.local/share/gossamer"
ARG DD_API_KEY

ENV chain=${chain}
Expand Down
6 changes: 4 additions & 2 deletions chain/kusama/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package kusama

import (
cfg "github.com/ChainSafe/gossamer/config"

"github.com/adrg/xdg"
)

var (
// defaultBasePath Default node base directory path
defaultBasePath = "~/.gossamer/kusama"
// defaultBasePath is the default base directory path for kusama node
defaultBasePath = xdg.DataHome + "/gossamer/kusama"
// defaultChainSpec is the default chain-spec json path
defaultChainSpec = "./chain/kusama/chain-spec-raw.json"
)
Expand Down
11 changes: 3 additions & 8 deletions chain/paseo/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ package paseo

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

var (
// defaultName Default node name
defaultName = "Paseo"
// defaultID Default chain ID
defaultID = "paseo"
// defaultBasePath Default node base directory path
defaultBasePath = "~/.gossamer/paseo"
// defaultBasePath is the default directory base path for paseo node
defaultBasePath = xdg.DataHome + "/gossamer/paseo"
// defaultChainSpec is the default chain spec configuration path
defaultChainSpec = "./chain/paseo/chain-spec-raw.json"
)
Expand All @@ -22,8 +19,6 @@ var (
func DefaultConfig() *cfg.Config {
config := cfg.DefaultConfig()
config.BasePath = defaultBasePath
config.ID = defaultID
config.Name = defaultName
config.ChainSpec = defaultChainSpec
config.Core.BabeAuthority = false
config.Core.GrandpaAuthority = false
Expand Down
5 changes: 3 additions & 2 deletions chain/polkadot/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ package polkadot

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

var (
// defaultBasePath Default node base directory path
defaultBasePath = "~/.gossamer/polkadot"
// defaultBasePath is default base directory path for polkadot node
defaultBasePath = xdg.DataHome + "/gossamer/polkadot"
// defaultChainSpec is the default chain spec configuration path
defaultChainSpec = "./chain/polkadot/chain-spec-raw.json"
)
Expand Down
5 changes: 3 additions & 2 deletions chain/westend-dev/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ package westenddev

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

const (
var (
// defaultBasePath is the default basepath for the westend dev node
defaultBasePath = "~/.gossamer/westend-dev"
defaultBasePath = xdg.DataHome + "/gossamer/westend-dev"
// defaultChainSpec is the default chain spec for the westend dev node
defaultChainSpec = "./chain/westend-dev/westend-dev-spec-raw.json"
)
Expand Down
21 changes: 11 additions & 10 deletions chain/westend-local/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ package westendlocal

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

const (
var (
// defaultChainSpec is the default chain spec for the westend local node
defaultChainSpec = "./chain/westend-local/westend-local-spec-raw.json"

// DefaultBasePathAlice is the default basepath for the westend local alice node
DefaultBasePathAlice = "~/.gossamer/westend-local-alice"
// DefaultBasePathBob is the default basepath for the westend local bob node
DefaultBasePathBob = "~/.gossamer/westend-local-bob"
// DefaultBasePathCharlie is the default basepath for the westend local charlie node
DefaultBasePathCharlie = "~/.gossamer/westend-local-charlie"
// defaultBasePathAlice is the default basepath for the westend local alice node
defaultBasePathAlice = xdg.DataHome + "/gossamer/westend-local/alice"
// defaultBasePathBob is the default basepath for the westend local bob node
defaultBasePathBob = xdg.DataHome + "/gossamer/westend-local/bob"
// defaultBasePathCharlie is the default basepath for the westend local charlie node
defaultBasePathCharlie = xdg.DataHome + "/gossamer/westend-local/charlie"
)

// DefaultConfig returns a westend local node configuration
Expand All @@ -35,7 +36,7 @@ func DefaultConfig() *cfg.Config {
// DefaultAliceConfig returns a westend local node configuration
func DefaultAliceConfig() *cfg.Config {
config := DefaultConfig()
config.BasePath = DefaultBasePathAlice
config.BasePath = defaultBasePathAlice
config.PrometheusPort = uint32(9856)
config.Network.Port = 7001
config.RPC.Port = 8545
Expand All @@ -48,7 +49,7 @@ func DefaultAliceConfig() *cfg.Config {
// DefaultBobConfig returns a westend local node configuration with bob as the authority
func DefaultBobConfig() *cfg.Config {
config := DefaultConfig()
config.BasePath = DefaultBasePathBob
config.BasePath = defaultBasePathBob
config.PrometheusPort = uint32(9866)
config.Network.Port = 7011
config.RPC.Port = 8555
Expand All @@ -61,7 +62,7 @@ func DefaultBobConfig() *cfg.Config {
// DefaultCharlieConfig returns a westend local node configuration with charlie as the authority
func DefaultCharlieConfig() *cfg.Config {
config := DefaultConfig()
config.BasePath = DefaultBasePathCharlie
config.BasePath = defaultBasePathCharlie
config.PrometheusPort = uint32(9876)
config.Network.Port = 7021
config.RPC.Port = 8565
Expand Down
5 changes: 3 additions & 2 deletions chain/westend/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ package westend

import (
cfg "github.com/ChainSafe/gossamer/config"
"github.com/adrg/xdg"
)

var (
// defaultBasePath Default node base directory path
defaultBasePath = "~/.gossamer/westend"
// defaultBasePath is the default base directory path for westend node
defaultBasePath = xdg.DataHome + "/gossamer/westend"
// defaultChainSpec is the default chain specification path
defaultChainSpec = "./chain/westend/chain-spec-raw.json"
)
Expand Down
15 changes: 7 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ import (
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/os"
wazero "github.com/ChainSafe/gossamer/lib/runtime/wazero"
"github.com/adrg/xdg"
)

const (
// uint32Max is the maximum value of a uint32
uint32Max = ^uint32(0)
// defaultChainSpecFile is the default genesis file
defaultChainSpecFile = "chain-spec-raw.json"
// defaultBasePath is the default base path
defaultBasePath = "~/.gossamer/gssmr"
// DefaultLogLevel is the default log level
DefaultLogLevel = "info"
// DefaultPrometheusPort is the default prometheus port
DefaultPrometheusPort = uint32(9876)
// DefaultRetainBlocks is the default number of blocks to retain
DefaultRetainBlocks = 512
DefaultRetainBlocks = uint32(512)
// DefaultPruning is the default pruning strategy
DefaultPruning = pruner.Archive

Expand All @@ -40,7 +39,7 @@ const (
DefaultWasmInterpreter = wazero.Name

// DefaultNetworkPort is the default network port
DefaultNetworkPort = 7001
DefaultNetworkPort = uint16(7001)
// DefaultDiscoveryInterval is the default discovery interval
DefaultDiscoveryInterval = 10 * time.Second
// DefaultMinPeers is the default minimum number of peers
Expand All @@ -49,11 +48,11 @@ const (
DefaultMaxPeers = 50

// DefaultRPCPort is the default RPC port
DefaultRPCPort = 8545
DefaultRPCPort = uint32(8545)
// DefaultRPCHost is the default RPC host
DefaultRPCHost = "localhost"
// DefaultWSPort is the default WS port
DefaultWSPort = 8546
DefaultWSPort = uint32(8546)

// DefaultPprofListenAddress is the default pprof listen address
DefaultPprofListenAddress = "localhost:6060"
Expand Down Expand Up @@ -332,7 +331,7 @@ func DefaultConfig() *Config {
BaseConfig: BaseConfig{
Name: "Gossamer",
ID: "gssmr",
BasePath: defaultBasePath,
BasePath: xdg.DataHome + "gossamer",
ChainSpec: "",
LogLevel: DefaultLogLevel,
PrometheusPort: DefaultPrometheusPort,
Expand Down Expand Up @@ -413,7 +412,7 @@ func DefaultConfigFromSpec(nodeSpec *genesis.Genesis) *Config {
BaseConfig: BaseConfig{
Name: nodeSpec.Name,
ID: nodeSpec.ID,
BasePath: defaultBasePath,
BasePath: xdg.DataHome + "gossamer",
ChainSpec: "",
LogLevel: DefaultLogLevel,
PrometheusPort: uint32(9876),
Expand Down
8 changes: 4 additions & 4 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const defaultConfigTemplate = `# This is a TOML config file.
# NOTE: Any path below can be absolute (e.g. "/var/gossamer/data") or
# relative to the home directory (e.g. "data"). The home directory is
# "$HOME/.gossamer" by default, but could be changed via $GSSMRHOME env variable
# or --home cmd flag.
# "$HOME/.local/share/gossamer" by default, but could be changed via
# $GSSMRHOME env variable or --home cmd flag.
#######################################################################
### Main Base Config Options ###
Expand All @@ -71,7 +71,7 @@ name = "{{ .BaseConfig.Name }}"
id = "{{ .BaseConfig.ID }}"
# Path to the working directory of the node
# Defaults to "$HOME/.gossamer/<CHAIN>"
# Defaults to "$HOME/.local/share/gossamer/<CHAIN>"
base-path = "{{ .BaseConfig.BasePath }}"
# Path to the chain-spec raw JSON file
Expand Down Expand Up @@ -103,7 +103,7 @@ no-telemetry = {{ .BaseConfig.NoTelemetry }}
# [[telemetry-urls]]
# endpoint = "wss://telemetry.polkadot.io/submit/"
# verbosity = 0
{{range .BaseConfig.TelemetryURLs}}
{{range .BaseConfig.TelemetryURLs}}
[[telemetry-urls]]
endpoint = "{{ .Endpoint }}"
verbosity = {{ .Verbosity }}
Expand Down
6 changes: 3 additions & 3 deletions devnet/alice.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ RUN go install -trimpath github.com/ChainSafe/gossamer/cmd/gossamer
# use the 3 node westend local network
RUN cp -f chain/$CHAIN/$CHAIN-spec-raw.json chain/$CHAIN/$CHAIN-spec.json

RUN gossamer init --key=alice --chain chain/$CHAIN/$CHAIN-spec.json --base-path ~/.gossamer/gssmr
RUN gossamer init --key=alice --chain chain/$CHAIN/$CHAIN-spec.json --base-path ~/.local/share/gossamer

# use a hardcoded key for alice, so we can determine what the peerID is for subsequent nodes
RUN cp devnet/alice.node.key ~/.gossamer/gssmr/node.key
RUN cp devnet/alice.node.key ~/.local/share/gossamer/node.key

ARG METRICS_NAMESPACE=gossamer.local.devnet

Expand All @@ -35,6 +35,6 @@ RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:alic

WORKDIR /gossamer

ENTRYPOINT service datadog-agent start && gossamer --base-path ~/.gossamer/gssmr --key=alice --prometheus-external --prometheus-port=9876 --rpc-external=true --public-dns=alice --port 7001
ENTRYPOINT service datadog-agent start && gossamer --base-path ~/.local/share/gossamer --key=alice --prometheus-external --prometheus-port=9876 --rpc-external=true --public-dns=alice --port 7001

EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp 6060/tcp
4 changes: 2 additions & 2 deletions devnet/bob.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ARG key
RUN test -n "$key"
ENV key=${key}

RUN gossamer --key=${key} init --chain chain/$CHAIN/$CHAIN-spec.json --base-path ~/.gossamer/gssmr
RUN gossamer --key=${key} init --chain chain/$CHAIN/$CHAIN-spec.json --base-path ~/.local/share/gossamer

ARG METRICS_NAMESPACE=gossamer.local.devnet

Expand All @@ -36,7 +36,7 @@ RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:${ke

WORKDIR /gossamer

ENTRYPOINT service datadog-agent start && gossamer --base-path ~/.gossamer/gssmr \
ENTRYPOINT service datadog-agent start && gossamer --base-path ~/.local/share/gossamer \
--key=${key} \
--bootnodes=/dns/alice/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU \
--prometheus-external \
Expand Down
24 changes: 12 additions & 12 deletions docs/docs/usage/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ permalink: /usage/command-line/

## Gossamer Command

The `gossamer` command is the root command for the `gossamer` package (`cmd/gossamer`). The root command starts the node (and initialises the node if the node has not already been initialised).
The `gossamer` command is the root command for the `gossamer` package (`cmd/gossamer`). The root command starts the node (and initialises the node if the node has not already been initialised).

### Flags

Expand All @@ -17,7 +17,7 @@ These are the flags that can be used with the `gossamer` command
--base-path Working directory for the node
--bootnodes Comma separated enode URLs for network discovery bootstrap
--chain chain-spec-raw.json used to load node configuration. It can also be a chain name (eg. kusama, polkadot, westend, westend-dev and westend-local)
--discovery-interval Interval between network discovery lookups (in duration format)
--discovery-interval Interval between network discovery lookups (in duration format)
--grandpa-authority Runs as a GRANDPA authority node
--grandpa-interval GRANDPA voting period in duration (default 10s)
--help help for gossamer
Expand Down Expand Up @@ -120,22 +120,22 @@ Two options for running another node at the same time...

(1) run `gossamer init` with two different `base-path` and manually update `port` in `base-path/config/config.toml`:
```
gossamer init --base-path ~/.gossamer/gssmr-alice --chain westend-local
gossamer init --base-path ~/.gossamer/gssmr-bob --chain westend-local
# open ~/.gossamer/gssmr-bob/config/config.toml, set port=7002
gossamer init --base-path ~/.local/share/gossamer/alice --chain westend-local
gossamer init --base-path ~/.local/share/gossamer/bob --chain westend-local
# open ~/.local/share/gossamer/bob/config/config.toml, set port=7002
# set role=4 to also make bob an authority node, or role=1 to make bob a non-authority node
```

(2) run with `--base-path` flag:
```
./bin/gossamer --base-path ~/.gossamer/gssmr-alice --key alice --roles 4
./bin/gossamer --base-path ~/.gossamer/gssmr-bob --key bob --roles 4
./bin/gossamer --base-path ~/.local/share/gossamer/alice --key alice --roles 4
./bin/gossamer --base-path ~/.local/share/gossamer/bob --key bob --roles 4
```

or run with port, base-path flags:
```
./bin/gossamer --base-path ~/.gossamer/gssmr-alice --key alice --role 4 --port 7001
./bin/gossamer --base-path ~/.gossamer/gssmr-bob --key bob --role 4 --port 7002
./bin/gossamer --base-path ~/.local/share/gossamer/alice --key alice --role 4 --port 7001
./bin/gossamer --base-path ~/.local/share/gossamer/bob --key bob --role 4 --port 7002
```

To run more than two nodes, repeat steps for bob with a new `port` and `base-path` replacing `bob`.
Expand All @@ -156,11 +156,11 @@ Available built-in keys:

To initialise or re-initialise a node, use the init subcommand `init`:
```
./bin/gossamer init --base-path ~/.gossamer/gssmr-alice --chain westend-local
./bin/gossamer --base-path ~/.gossamer/gssmr-alice --key alice --roles 4
./bin/gossamer init --base-path ~/.local/share/gossamer/alice --chain westend-local
./bin/gossamer --base-path ~/.local/share/gossamer/alice --key alice --roles 4
```

`init` can be used with the `--base-path` or `--chain` flag to re-initialise a custom node (ie, `bob` from the example above):
```
./bin/gossamer init --base-path ~/.gossamer/gssmr-bob --chain westend-local
./bin/gossamer init --base-path ~/.local/share/gossamer/bob --chain westend-local
```
10 changes: 5 additions & 5 deletions docs/docs/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Gossamer consumes a `.toml` file containing predefined settings for the node fro

# NOTE: Any path below can be absolute (e.g. "/var/gossamer/data") or
# relative to the home directory (e.g. "data"). The home directory is
# "$HOME/.gossamer" by default, but could be changed via $GSSMRHOME env variable
# or --home cmd flag.
# "$HOME/.local/share/gossamer" by default, but could be changed via
# $GSSMRHOME env variable or --home cmd flag.

#######################################################################
### Main Base Config Options ###
Expand All @@ -32,11 +32,11 @@ name = "Westend"
id = "westend_dev"

# Path to the working directory of the node
# Defaults to "$HOME/.gossamer/<CHAIN>"
base-path = "/Users/k/.gossamer/alice"
# Defaults to "$HOME/.local/share/gossamer/<CHAIN>"
base-path = "/Users/user/.local/share/gossamer/alice"

# Path to the chain-spec raw JSON file
chain-spec = "/Users/k/.gossamer/alice/chain-spec.json"
chain-spec = "/Users/user/.local/share/gossamer/alice/chain-spec.json"

# Global log level
# One of: crit, error, warn, info, debug, trace
Expand Down
Loading

0 comments on commit 51d57ae

Please sign in to comment.