Skip to content

Commit f26ef82

Browse files
Merge branch 'development' into eclesio/host-optional-returns
2 parents 55f89ea + 0b06742 commit f26ef82

77 files changed

Lines changed: 1137 additions & 7292 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,6 @@ make install
8181

8282
To install Gossamer
8383

84-
#### Troubleshooting for Apple Silicon users
85-
86-
Apple Silicon users may encounter these errors:
87-
88-
```sh
89-
undefined: cWasmerImportObjectT
90-
undefined: cWasmerImportFuncT
91-
undefined: cWasmerValueTag
92-
```
93-
94-
If so, set the following
95-
[Golang environment variables](https://pkg.go.dev/cmd/go#hdr-Environment_variables):
96-
97-
```sh
98-
GOARCH="amd64"
99-
```
100-
10184
## Use Gossamer
10285

10386
A comprehensive guide to

cmd/gossamer/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ cd gossamer
1414
### Compile
1515

1616
To put the binary in ./bin, run:
17+
1718
```bash
1819
make build
1920
```
@@ -62,7 +63,7 @@ The node configuration can be modified in the `config.toml` file.
6263
### Start the node
6364

6465
```bash
65-
gossamer --basepath /tmp/gossamer --key alice
66+
gossamer --basepath /tmp/gossamer --key alice
6667
```
6768

6869
**Note: The `init` command is optional. If the node is not initialised, it will be initialised with the default configuration.**
@@ -108,19 +109,22 @@ This subcommand provides capabilities that are similar to
108109
[Parity's Subkey utility](https://docs.substrate.io/v3/tools/subkey).
109110

110111
The account command supports following arguments:
112+
111113
- `generate` - generates a new key pair; specify `--scheme ed25519`, `--scheme secp256k1`, or `--scheme sr25519` (default)
112114
- `list` - lists the keys in the Gossamer keystore
113115
- `import` - imports a key from a keystore file
114116
- `import-raw` - imports a raw key from a keystore file
115117

116118
Supported flags:
119+
117120
- `keystore-path` - path to the Gossamer keystore
118121
- `keystore-file` - path to the keystore file
119122
- `chain` - path to the human-readable chain-spec file
120123
- `--scheme` - `ed25519`, `secp256k1`, or `sr25519` (default)
121124
- `--password` - allows the user to provide a password to either encrypt a generated key or unlock the Gossamer keystore
122125

123126
Examples:
127+
124128
- `gossamer account generate --scheme ed25519` - generates an `ed25519` key pair
125129
- `gossamer account list` - lists the keys in the Gossamer keystore
126130
- `gossamer account import --keystore-file keystore.json` - imports a key from a keystore file
@@ -145,6 +149,7 @@ represent the Gossamer default configuration.
145149
- `--output-path` - path to the file where the compiled chain-spec should be written
146150

147151
Examples:
152+
148153
- `gossamer build-spec --chain chain-spec.json --output-path compiled-chain-spec.json` - compiles a human-readable
149154
chain-spec into a format that Gossamer can consume
150155
- `gossamer build-spec --chain chain-spec.json --raw --output-path compiled-chain-spec.json` - compiles a human-readable
@@ -166,6 +171,7 @@ of a JSON file. The input for this subcommand can be retrieved from
166171
- `--chain` - path to the human-readable chain-spec file
167172

168173
Examples:
174+
169175
- `gossamer import-state --first-slot 1 --header header.json --state state.json --chain chain-spec.json` - seeds Gossamer
170176
storage with key-value pairs from a JSON file
171177

@@ -185,9 +191,8 @@ What follows is a list that describes the services and capabilities that inform
185191

186192
#### State
187193

188-
This service is a wrapper around an instance of [`chaindb`](https://github.com/ChainSafe/chaindb), a key-value database
189-
that is built on top of [BadgerDB](https://github.com/dgraph-io/badger) from [Dgraph](https://dgraph.io/). The state
190-
service provides storage capabilities for the other Gossamer services - each service is assigned a prefix that is added
194+
This service is a wrapper around an instance of [`pebble`](https://github.com/cockroachdb/pebble), a LevelDB/RocksDB inspired key-value database.
195+
The state service provides storage capabilities for the other Gossamer services - each service is assigned a prefix that is added
191196
to its storage keys. The state service is defined in [dot/state/service.go](../../dot/state/service.go).
192197

193198
#### Network
@@ -271,4 +276,4 @@ capabilities are defined in the [dot/telemetry](../../dot/telemetry) package and
271276
The default listening address for Prometheus metrics is `localhost:9876`, and Gossamer allows the user to configure this parameter with the
272277
`--metrics-address` command-line parameter. The Gossamer telemetry server publishes telemetry data that is compatible with
273278
[Polkadot Telemetry](https://github.com/paritytech/substrate-telemetry) and
274-
[its helpful UI](https://telemetry.polkadot.io/).
279+
[its helpful UI](https://telemetry.polkadot.io/).

cmd/gossamer/commands/init.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ func execInit(cmd *cobra.Command) error {
4343
return fmt.Errorf("failed to get --force: %s", err)
4444
}
4545

46-
if dot.IsNodeInitialised(config.BasePath) {
46+
isInitialised, err := dot.IsNodeInitialised(config.BasePath)
47+
if err != nil {
48+
return fmt.Errorf("checking if node is initialised: %w", err)
49+
}
50+
51+
if isInitialised {
4752
// prompt user to confirm reinitialization
4853
if force || confirmMessage("Are you sure you want to reinitialise the node? [Y/n]") {
4954
logger.Info("reinitialising node at base path " + config.BasePath + "...")

cmd/gossamer/commands/root.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,13 @@ func execRoot(cmd *cobra.Command) error {
601601
return fmt.Errorf("failed to ensure root: %s", err)
602602
}
603603

604+
isInitialised, err := dot.IsNodeInitialised(config.BasePath)
605+
if err != nil {
606+
return fmt.Errorf("failed to check is not is initialised: %w", err)
607+
}
608+
604609
// if the node is not initialised, initialise it
605-
if !dot.IsNodeInitialised(config.BasePath) {
610+
if !isInitialised {
606611
if err := dot.InitNode(config); err != nil {
607612
return fmt.Errorf("failed to initialise node: %s", err)
608613
}

config/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/ChainSafe/gossamer/lib/common"
1313
"github.com/ChainSafe/gossamer/lib/genesis"
1414
"github.com/ChainSafe/gossamer/lib/os"
15-
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
1615
wazero "github.com/ChainSafe/gossamer/lib/runtime/wazero"
1716
)
1817

@@ -279,7 +278,7 @@ func (c *CoreConfig) ValidateBasic() error {
279278
if c.WasmInterpreter == "" {
280279
return fmt.Errorf("wasm-interpreter cannot be empty")
281280
}
282-
if c.WasmInterpreter != wasmer.Name && c.WasmInterpreter != wazero.Name {
281+
if c.WasmInterpreter != wazero.Name {
283282
return fmt.Errorf("wasm-interpreter is invalid")
284283
}
285284

dot/build_spec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestBuildFromDB(t *testing.T) {
147147
},
148148
}}},
149149
{name: "invalid_db_path", path: t.TempDir(),
150-
err: errors.New("cannot start state service: failed to create block state: cannot get block 0: Key not found")},
150+
err: errors.New("cannot start state service: failed to create block state: cannot get block 0: pebble: not found")},
151151
}
152152
for _, tt := range tests {
153153
t.Run(tt.name, func(t *testing.T) {

dot/core/helpers_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/ChainSafe/gossamer/dot/network"
1212
"github.com/ChainSafe/gossamer/dot/state"
1313
"github.com/ChainSafe/gossamer/dot/types"
14+
"github.com/ChainSafe/gossamer/internal/database"
1415
"github.com/ChainSafe/gossamer/internal/log"
1516
"github.com/ChainSafe/gossamer/lib/common"
1617
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
@@ -225,7 +226,7 @@ func NewTestService(t *testing.T, cfg *Config) *Service {
225226
if stateSrvc != nil {
226227
nodeStorage.BaseDB = stateSrvc.Base
227228
} else {
228-
nodeStorage.BaseDB, err = utils.SetupDatabase(filepath.Join(testDatadirPath, "offline_storage"), false)
229+
nodeStorage.BaseDB, err = database.LoadDatabase(filepath.Join(testDatadirPath, "offline_storage"), false)
229230
require.NoError(t, err)
230231
}
231232

dot/mock_node_builder_test.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dot/network/service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,12 @@ func (s *Service) publishNetworkTelemetry(done <-chan struct{}) {
428428

429429
func (s *Service) sentBlockIntervalTelemetry() {
430430
for {
431+
select {
432+
case <-s.ctx.Done():
433+
return
434+
default:
435+
}
436+
431437
best, err := s.blockState.BestBlockHeader()
432438
if err != nil {
433439
continue

dot/node.go

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/ChainSafe/gossamer/dot/system"
2626
"github.com/ChainSafe/gossamer/dot/telemetry"
2727
"github.com/ChainSafe/gossamer/dot/types"
28+
"github.com/ChainSafe/gossamer/internal/database"
2829
"github.com/ChainSafe/gossamer/internal/log"
2930
"github.com/ChainSafe/gossamer/internal/metrics"
3031
"github.com/ChainSafe/gossamer/lib/babe"
@@ -34,7 +35,6 @@ import (
3435
"github.com/ChainSafe/gossamer/lib/keystore"
3536
"github.com/ChainSafe/gossamer/lib/runtime"
3637
"github.com/ChainSafe/gossamer/lib/services"
37-
"github.com/ChainSafe/gossamer/lib/utils"
3838
)
3939

4040
var logger = log.NewFromGlobal(log.AddContext("pkg", "dot"))
@@ -49,7 +49,7 @@ type Node struct {
4949
}
5050

5151
type nodeBuilderIface interface {
52-
isNodeInitialised(basepath string) error
52+
isNodeInitialised(basepath string) (bool, error)
5353
initNode(config *cfg.Config) error
5454
createStateService(config *cfg.Config) (*state.Service, error)
5555
createNetworkService(config *cfg.Config, stateSrvc *state.Service, telemetryMailer Telemetry) (*network.Service,
@@ -78,26 +78,37 @@ type nodeBuilder struct{}
7878

7979
// IsNodeInitialised returns true if, within the configured data directory for the
8080
// node, the state database has been created and the genesis data can been loaded
81-
func IsNodeInitialised(basepath string) bool {
81+
func IsNodeInitialised(basepath string) (bool, error) {
8282
nodeInstance := nodeBuilder{}
83-
err := nodeInstance.isNodeInitialised(basepath)
84-
return err == nil
83+
return nodeInstance.isNodeInitialised(basepath)
8584
}
8685

8786
// isNodeInitialised returns nil if the node is successfully initialised
8887
// and an error otherwise.
89-
func (*nodeBuilder) isNodeInitialised(basepath string) error {
88+
func (*nodeBuilder) isNodeInitialised(basepath string) (bool, error) {
9089
// check if key registry exists
91-
registry := filepath.Join(basepath, utils.DefaultDatabaseDir, "KEYREGISTRY")
90+
nodeDatabaseDir := filepath.Join(basepath, database.DefaultDatabaseDir)
9291

93-
_, err := os.Stat(registry)
94-
if os.IsNotExist(err) {
95-
return fmt.Errorf("cannot find key registry in database directory: %w", err)
92+
_, err := os.Stat(nodeDatabaseDir)
93+
if err != nil {
94+
if os.IsNotExist(err) {
95+
return false, nil
96+
}
97+
return false, err
9698
}
9799

98-
db, err := utils.SetupDatabase(basepath, false)
100+
entries, err := os.ReadDir(nodeDatabaseDir)
99101
if err != nil {
100-
return fmt.Errorf("cannot setup database: %w", err)
102+
return false, fmt.Errorf("failed to read dir %s: %w", nodeDatabaseDir, err)
103+
}
104+
105+
if len(entries) == 0 {
106+
return false, nil
107+
}
108+
109+
db, err := database.LoadDatabase(basepath, false)
110+
if err != nil {
111+
return false, fmt.Errorf("cannot setup database: %w", err)
101112
}
102113

103114
defer func() {
@@ -109,10 +120,10 @@ func (*nodeBuilder) isNodeInitialised(basepath string) error {
109120

110121
_, err = state.NewBaseState(db).LoadGenesisData()
111122
if err != nil {
112-
return fmt.Errorf("cannot load genesis data in base state: %w", err)
123+
return false, fmt.Errorf("cannot load genesis data in base state: %w", err)
113124
}
114125

115-
return nil
126+
return true, nil
116127
}
117128

118129
// InitNode initialise the node with the given Config
@@ -204,7 +215,7 @@ func (*nodeBuilder) initNode(config *cfg.Config) error {
204215
// LoadGlobalNodeName returns the stored global node name from database
205216
func LoadGlobalNodeName(basepath string) (nodename string, err error) {
206217
// initialise database using data directory
207-
db, err := utils.SetupDatabase(basepath, false)
218+
db, err := database.LoadDatabase(basepath, false)
208219
if err != nil {
209220
return "", err
210221
}
@@ -242,7 +253,12 @@ func newNode(config *cfg.Config,
242253
debug.SetGCPercent(prev)
243254
}
244255

245-
if builder.isNodeInitialised(config.BasePath) != nil {
256+
isInitialised, err := builder.isNodeInitialised(config.BasePath)
257+
if err != nil {
258+
return nil, fmt.Errorf("checking if node is initialised: %w", err)
259+
}
260+
261+
if isInitialised {
246262
err := builder.initNode(config)
247263
if err != nil {
248264
return nil, fmt.Errorf("cannot initialise node: %w", err)
@@ -450,7 +466,7 @@ func setupTelemetry(config *cfg.Config, genesisData *genesis.Data) (mailer Telem
450466

451467
// stores the global node name to reuse
452468
func storeGlobalNodeName(name, basepath string) (err error) {
453-
db, err := utils.SetupDatabase(basepath, false)
469+
db, err := database.LoadDatabase(basepath, false)
454470
if err != nil {
455471
return err
456472
}

0 commit comments

Comments
 (0)