Skip to content

Commit

Permalink
Rename InstanceConfig -> Config
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Aug 15, 2022
1 parent 995a37e commit 28edafa
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion dot/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewTestService(t *testing.T, cfg *Config) *Service {
}

if cfg.Runtime == nil {
var rtCfg wasmer.InstanceConfig
var rtCfg wasmer.Config

rtCfg.Storage = rtstorage.NewTrieState(genTrie)

Expand Down
2 changes: 1 addition & 1 deletion dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (s *Service) handleCodeSubstitution(hash common.Hash,

// 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
cfg := wasmer.InstanceConfig{
cfg := wasmer.Config{
Storage: state,
Keystore: rt.Keystore(),
NodeStorage: rt.NodeStorage(),
Expand Down
2 changes: 1 addition & 1 deletion dot/core/service_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func generateTestValidRemarkTxns(t *testing.T, pubKey []byte, accInfo types.Acco
nodeStorage := runtime.NodeStorage{
BaseDB: runtime.NewInMemoryDB(t),
}
cfg := wasmer.InstanceConfig{
cfg := wasmer.Config{
Storage: genState,
LogLvl: log.Error,
NodeStorage: nodeStorage,
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func newCoreServiceTest(t *testing.T) *core.Service {
err = cfg.Keystore.Acco.Insert(kp)
require.NoError(t, err)

var rtCfg wasmer.InstanceConfig
var rtCfg wasmer.Config

rtCfg.Storage = rtstorage.NewTrieState(genTrie)

Expand Down
4 changes: 2 additions & 2 deletions dot/rpc/modules/author_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type useRuntimeInstace func(*testing.T, *storage.TrieState) runtime.Instance
func useInstanceFromGenesis(t *testing.T, rtStorage *storage.TrieState) (instance runtime.Instance) {
t.Helper()

cfg := wasmer.InstanceConfig{
cfg := wasmer.Config{
Storage: rtStorage,
LogLvl: log.Warn,
NodeStorage: runtime.NodeStorage{
Expand All @@ -62,7 +62,7 @@ func useInstanceFromRuntimeV0910(t *testing.T, rtStorage *storage.TrieState) (in

rtStorage.Set(common.CodeKey, bytes)

cfg := wasmer.InstanceConfig{
cfg := wasmer.Config{
Role: 0,
LogLvl: log.Critical,
Storage: rtStorage,
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/chain_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func newTestStateService(t *testing.T) *state.Service {
err = stateSrvc.Start()
require.NoError(t, err)

var rtCfg wasmer.InstanceConfig
var rtCfg wasmer.Config

rtCfg.Storage = rtstorage.NewTrieState(genTrie)

Expand Down
2 changes: 1 addition & 1 deletion dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func createRuntime(cfg *Config, ns runtime.NodeStorage, st *state.Service,
var rt runtime.Instance
switch cfg.Core.WasmInterpreter {
case wasmer.Name:
rtCfg := wasmer.InstanceConfig{
rtCfg := wasmer.Config{
Storage: ts,
Keystore: ks,
LogLvl: cfg.Log.RuntimeLvl,
Expand Down
2 changes: 1 addition & 1 deletion dot/services_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newStateServiceWithoutMock(t *testing.T) *state.Service {

stateSrvc.Epoch = epochState

var rtCfg wasmer.InstanceConfig
var rtCfg wasmer.Config

rtCfg.Storage = rtstorage.NewTrieState(genTrie)

Expand Down
2 changes: 1 addition & 1 deletion dot/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func newStateService(t *testing.T, ctrl *gomock.Controller) *state.Service {

stateSrvc.Epoch = epochState

var rtCfg wasmer.InstanceConfig
var rtCfg wasmer.Config

rtCfg.Storage = rtstorage.NewTrieState(genTrie)

Expand Down
2 changes: 1 addition & 1 deletion dot/state/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func (bs *BlockState) HandleRuntimeChanges(newState *rtstorage.TrieState,
bHash, codeHash, previousVersion.SpecVersion(), currCodeHash, newVersion.SpecVersion())
}

rtCfg := wasmer.InstanceConfig{
rtCfg := wasmer.Config{
Storage: newState,
Keystore: rt.Keystore(),
NodeStorage: rt.NodeStorage(),
Expand Down
2 changes: 1 addition & 1 deletion dot/state/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *Service) CreateGenesisRuntime(t *trie.Trie, gen *genesis.Genesis) (runt
genTrie := rtstorage.NewTrieState(t)

// create genesis runtime
rtCfg := wasmer.InstanceConfig{
rtCfg := wasmer.Config{
LogLvl: s.logLvl,
Storage: genTrie,
}
Expand Down
2 changes: 1 addition & 1 deletion dot/sync/syncer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func newTestSyncer(t *testing.T) *Service {
// initialise runtime
genState := rtstorage.NewTrieState(genTrie)

rtCfg := wasmer.InstanceConfig{
rtCfg := wasmer.Config{
Storage: genState,
LogLvl: log.Critical,
}
Expand Down
4 changes: 2 additions & 2 deletions lib/babe/babe_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func createTestService(t *testing.T, cfg *ServiceConfig) *Service {
cfg.EpochState = dbSrv.Epoch
}

var rtCfg wasmer.InstanceConfig
var rtCfg wasmer.Config
rtCfg.Storage = rtstorage.NewTrieState(genTrie)

storageState := cfg.StorageState.(core.StorageState)
Expand Down Expand Up @@ -177,7 +177,7 @@ func newTestServiceSetupParameters(t *testing.T) (*Service, *state.EpochState, *
_ = dbSrv.Stop()
})

rtCfg := wasmer.InstanceConfig{
rtCfg := wasmer.Config{
Storage: rtstorage.NewTrieState(genTrie),
}

Expand Down
2 changes: 1 addition & 1 deletion lib/grandpa/grandpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func newTestState(t *testing.T) *state.Service {
block, err := state.NewBlockStateFromGenesis(db, tries, testGenesisHeader, telemetryMock)
require.NoError(t, err)

var rtCfg wasmer.InstanceConfig
var rtCfg wasmer.Config

rtCfg.Storage = rtstorage.NewTrieState(genTrie)

Expand Down
5 changes: 3 additions & 2 deletions lib/runtime/wasmer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"github.com/ChainSafe/gossamer/lib/runtime"
)

// InstanceConfig represents a runtime instance configuration
type InstanceConfig struct {
// Config is the configuration used to create a
// Wasmer runtime instance.
type Config struct {
Storage runtime.Storage
Keystore *keystore.GlobalKeystore
LogLvl log.Level
Expand Down
24 changes: 12 additions & 12 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestInstance_Version_KusamaRuntime(t *testing.T) {
// set state to genesis state
genState := storage.NewTrieState(genTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: genState,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestNodeRuntime_ValidateTransaction(t *testing.T) {
// set state to genesis state
genState := storage.NewTrieState(genTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: genState,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -526,7 +526,7 @@ func TestInstance_ExecuteBlock_GossamerRuntime(t *testing.T) {
// set state to genesis state
genState := storage.NewTrieState(genTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: genState,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -556,7 +556,7 @@ func TestInstance_ApplyExtrinsic_GossamerRuntime(t *testing.T) {
// set state to genesis state
genState := storage.NewTrieState(genTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: genState,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -616,7 +616,7 @@ func TestInstance_ExecuteBlock_PolkadotRuntime_PolkadotBlock1(t *testing.T) {
// set state to genesis state
genState := storage.NewTrieState(genTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: genState,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -668,7 +668,7 @@ func TestInstance_ExecuteBlock_KusamaRuntime_KusamaBlock1(t *testing.T) {
// set state to genesis state
genState := storage.NewTrieState(genTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: genState,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -714,7 +714,7 @@ func TestInstance_ExecuteBlock_KusamaRuntime_KusamaBlock3784(t *testing.T) {
// set state to genesis state
state3783 := storage.NewTrieState(gossTrie3783)

cfg := InstanceConfig{
cfg := Config{
Storage: state3783,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -760,7 +760,7 @@ func TestInstance_ExecuteBlock_KusamaRuntime_KusamaBlock901442(t *testing.T) {
// set state to genesis state
state901441 := storage.NewTrieState(ksmTrie901441)

cfg := InstanceConfig{
cfg := Config{
Storage: state901441,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -806,7 +806,7 @@ func TestInstance_ExecuteBlock_KusamaRuntime_KusamaBlock1377831(t *testing.T) {
// set state to genesis state
state := storage.NewTrieState(ksmTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: state,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -852,7 +852,7 @@ func TestInstance_ExecuteBlock_KusamaRuntime_KusamaBlock1482003(t *testing.T) {
// set state to genesis state
state := storage.NewTrieState(ksmTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: state,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -900,7 +900,7 @@ func TestInstance_ExecuteBlock_KusamaRuntime_KusamaBlock4939774(t *testing.T) {
// set state to genesis state
state := storage.NewTrieState(ksmTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: state,
LogLvl: log.Critical,
}
Expand Down Expand Up @@ -943,7 +943,7 @@ func TestInstance_ExecuteBlock_PolkadotBlock1089328(t *testing.T) {
// set state to genesis state
state := storage.NewTrieState(dotTrie)

cfg := InstanceConfig{
cfg := Config{
Storage: state,
LogLvl: log.Critical,
}
Expand Down
8 changes: 4 additions & 4 deletions lib/runtime/wasmer/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Instance struct {
}

// NewRuntimeFromGenesis creates a runtime instance from the genesis data
func NewRuntimeFromGenesis(cfg InstanceConfig) (instance runtime.Instance, err error) {
func NewRuntimeFromGenesis(cfg Config) (instance runtime.Instance, err error) {
if cfg.Storage == nil {
return nil, errors.New("storage is nil")
}
Expand All @@ -61,7 +61,7 @@ func NewRuntimeFromGenesis(cfg InstanceConfig) (instance runtime.Instance, err e
}

// NewInstanceFromTrie returns a new runtime instance with the code provided in the given trie
func NewInstanceFromTrie(t *trie.Trie, cfg InstanceConfig) (*Instance, error) {
func NewInstanceFromTrie(t *trie.Trie, cfg Config) (*Instance, error) {
code := t.Get(common.CodeKey)
if len(code) == 0 {
return nil, fmt.Errorf("cannot find :code in trie")
Expand All @@ -71,7 +71,7 @@ func NewInstanceFromTrie(t *trie.Trie, cfg InstanceConfig) (*Instance, error) {
}

// NewInstanceFromFile instantiates a runtime from a .wasm file
func NewInstanceFromFile(fp string, cfg InstanceConfig) (*Instance, error) {
func NewInstanceFromFile(fp string, cfg Config) (*Instance, error) {
// Reads the WebAssembly module as bytes.
bytes, err := wasm.ReadBytes(fp)
if err != nil {
Expand All @@ -82,7 +82,7 @@ func NewInstanceFromFile(fp string, cfg InstanceConfig) (*Instance, error) {
}

// NewInstance instantiates a runtime from raw wasm bytecode
func NewInstance(code []byte, cfg InstanceConfig) (instance *Instance, err error) {
func NewInstance(code []byte, cfg Config) (instance *Instance, err error) {
logger.Patch(log.SetLevel(cfg.LogLvl), log.SetCallerFunc(true))

wasmInstance, allocator, err := setupVM(code)
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime/wasmer/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewTestInstanceWithTrie(t *testing.T, targetRuntime string, tt *trie.Trie)
return r
}

func setupConfig(t *testing.T, tt *trie.Trie, lvl log.Level, role common.Roles) InstanceConfig {
func setupConfig(t *testing.T, tt *trie.Trie, lvl log.Level, role common.Roles) Config {
t.Helper()

s := storage.NewTrieState(tt)
Expand All @@ -52,7 +52,7 @@ func setupConfig(t *testing.T, tt *trie.Trie, lvl log.Level, role common.Roles)
BaseDB: runtime.NewInMemoryDB(t), // we're using a local storage here since this is a test runtime
}

return InstanceConfig{
return Config{
Storage: s,
Keystore: keystore.NewGlobalKeystore(),
LogLvl: lvl,
Expand Down

0 comments on commit 28edafa

Please sign in to comment.