From 227f81ea00cee443052f582c8496faadfb887fe3 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 2 Sep 2022 15:18:19 +0000 Subject: [PATCH] newTestGenesisWithTrieAndHeader returns values --- dot/core/helpers_test.go | 20 ++++++++-------- dot/core/service_integration_test.go | 6 ++--- dot/digest/digest_test.go | 4 ++-- dot/digest/helpers_test.go | 10 ++++---- dot/helpers_test.go | 10 ++++---- dot/node.go | 2 +- dot/node_test.go | 2 +- dot/rpc/helpers_test.go | 10 ++++---- dot/rpc/http_test.go | 6 ++--- dot/rpc/modules/author_integration_test.go | 20 ++++++++-------- dot/rpc/modules/chain_integration_test.go | 6 ++--- dot/rpc/modules/childstate_test.go | 4 ++-- dot/rpc/modules/dev_integration_test.go | 4 ++-- dot/rpc/modules/helpers_test.go | 10 ++++---- dot/services_integration_test.go | 4 ++-- dot/services_test.go | 4 ++-- dot/state/helpers_test.go | 10 ++++---- dot/state/service_test.go | 22 +++++++++--------- dot/state/storage_test.go | 4 ++-- dot/sync/syncer_integration_test.go | 27 ++++++++++++++-------- lib/babe/babe_integration_test.go | 4 ++-- lib/babe/helpers_test.go | 16 ++++++++----- lib/babe/verify_integration_test.go | 6 ++--- lib/grandpa/grandpa_test.go | 4 ++-- lib/grandpa/helpers_test.go | 10 ++++---- lib/runtime/wasmer/exports_test.go | 16 ++++++------- lib/runtime/wasmer/genesis.go | 9 ++++---- 27 files changed, 139 insertions(+), 111 deletions(-) diff --git a/dot/core/helpers_test.go b/dot/core/helpers_test.go index 775180bcd13..517677ef3ae 100644 --- a/dot/core/helpers_test.go +++ b/dot/core/helpers_test.go @@ -47,7 +47,7 @@ func NewTestService(t *testing.T, cfg *Config) *Service { var stateSrvc *state.Service testDatadirPath := t.TempDir() - gen, genTrie, genHeader := newTestGenesisWithTrieAndHeader(t) + gen, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) if cfg.BlockState == nil || cfg.StorageState == nil || cfg.TransactionState == nil || cfg.EpochState == nil || @@ -64,7 +64,7 @@ func NewTestService(t *testing.T, cfg *Config) *Service { stateSrvc = state.NewService(config) stateSrvc.UseMemDB() - err := stateSrvc.Initialise(gen, genHeader, genTrie) + err := stateSrvc.Initialise(&gen, &genesisHeader, &genesisTrie) require.NoError(t, err) err = stateSrvc.Start() @@ -94,7 +94,7 @@ func NewTestService(t *testing.T, cfg *Config) *Service { if cfg.Runtime == nil { var rtCfg wasmer.Config - rtCfg.Storage = rtstorage.NewTrieState(genTrie) + rtCfg.Storage = rtstorage.NewTrieState(&genesisTrie) var err error rtCfg.CodeHash, err = cfg.StorageState.LoadCodeHash(nil) @@ -138,12 +138,13 @@ func NewTestService(t *testing.T, cfg *Config) *Service { } func newTestGenesisWithTrieAndHeader(t *testing.T) ( - gen *genesis.Genesis, genesisTrie *trie.Trie, genesisHeader *types.Header) { + gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) - gen, err := genesis.NewGenesisFromJSONRaw(genesisPath) + genPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genPtr - genesisTrie, err = wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) parentHash := common.NewHash([]byte{0}) @@ -151,9 +152,10 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) ( extrinsicRoot := trie.EmptyHash const number = 0 digest := types.NewDigest() - genesisHeader, err = types.NewHeader(parentHash, + genesisHeaderPtr, err := types.NewHeader(parentHash, stateRoot, extrinsicRoot, number, digest) require.NoError(t, err) + genesisHeader = *genesisHeaderPtr return gen, genesisTrie, genesisHeader } @@ -167,10 +169,10 @@ func getGssmrRuntimeCode(t *testing.T) (code []byte) { gssmrGenesis, err := genesis.NewGenesisFromJSONRaw(path) require.NoError(t, err) - trie, err := wasmer.NewTrieFromGenesis(*gssmrGenesis) + genesisTrie, err := wasmer.NewTrieFromGenesis(*gssmrGenesis) require.NoError(t, err) - trieState := rtstorage.NewTrieState(trie) + trieState := rtstorage.NewTrieState(&genesisTrie) return trieState.LoadCode() } diff --git a/dot/core/service_integration_test.go b/dot/core/service_integration_test.go index 80f60ce89af..e9638ed4aaf 100644 --- a/dot/core/service_integration_test.go +++ b/dot/core/service_integration_test.go @@ -55,10 +55,10 @@ func generateTestValidRemarkTxns(t *testing.T, pubKey []byte, accInfo types.Acco gen, err := genesis.NewGenesisFromJSONRaw(projectRootPath) require.NoError(t, err) - genTrie, err := wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err := wasmer.NewTrieFromGenesis(*gen) require.NoError(t, err) - genState := rtstorage.NewTrieState(genTrie) + genState := rtstorage.NewTrieState(&genesisTrie) nodeStorage := runtime.NodeStorage{ BaseDB: runtime.NewInMemoryDB(t), @@ -82,7 +82,7 @@ func generateTestValidRemarkTxns(t *testing.T, pubKey []byte, accInfo types.Acco genesisHeader := &types.Header{ Number: 0, - StateRoot: genTrie.MustHash(), + StateRoot: genesisTrie.MustHash(), } // Hash of encrypted centrifuge extrinsic diff --git a/dot/digest/digest_test.go b/dot/digest/digest_test.go index 934dd1a2b69..65a01230267 100644 --- a/dot/digest/digest_test.go +++ b/dot/digest/digest_test.go @@ -39,8 +39,8 @@ func newTestHandler(t *testing.T) (*Handler, *state.Service) { stateSrvc := state.NewService(config) stateSrvc.UseMemDB() - gen, genTrie, genHeader := newTestGenesisWithTrieAndHeader(t) - err := stateSrvc.Initialise(gen, genHeader, genTrie) + gen, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) + err := stateSrvc.Initialise(&gen, &genesisHeader, &genesisTrie) require.NoError(t, err) err = stateSrvc.SetupBase() diff --git a/dot/digest/helpers_test.go b/dot/digest/helpers_test.go index eb85c4954d8..3387aa87939 100644 --- a/dot/digest/helpers_test.go +++ b/dot/digest/helpers_test.go @@ -16,12 +16,13 @@ import ( ) func newTestGenesisWithTrieAndHeader(t *testing.T) ( - gen *genesis.Genesis, genesisTrie *trie.Trie, genesisHeader *types.Header) { + gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) - gen, err := genesis.NewGenesisFromJSONRaw(genesisPath) + genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genesisPtr - genesisTrie, err = wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) parentHash := common.NewHash([]byte{0}) @@ -29,9 +30,10 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) ( extrinsicRoot := trie.EmptyHash const number = 0 digest := types.NewDigest() - genesisHeader, err = types.NewHeader(parentHash, + genesisHeaderPtr, err := types.NewHeader(parentHash, stateRoot, extrinsicRoot, number, digest) require.NoError(t, err) + genesisHeader = *genesisHeaderPtr return gen, genesisTrie, genesisHeader } diff --git a/dot/helpers_test.go b/dot/helpers_test.go index 44014cc43b3..78bf1b0aba5 100644 --- a/dot/helpers_test.go +++ b/dot/helpers_test.go @@ -28,12 +28,13 @@ func writeGenesisToTestJSON(t *testing.T, genesis genesis.Genesis) (filename str } func newTestGenesisWithTrieAndHeader(t *testing.T) ( - gen *genesis.Genesis, genesisTrie *trie.Trie, genesisHeader *types.Header) { + gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) - gen, err := genesis.NewGenesisFromJSONRaw(genesisPath) + genPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genPtr - genesisTrie, err = wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) parentHash := common.NewHash([]byte{0}) @@ -41,9 +42,10 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) ( extrinsicRoot := trie.EmptyHash const number = 0 digest := types.NewDigest() - genesisHeader, err = types.NewHeader(parentHash, + genesisHeaderPtr, err := types.NewHeader(parentHash, stateRoot, extrinsicRoot, number, digest) require.NoError(t, err) + genesisHeader = *genesisHeaderPtr return gen, genesisTrie, genesisHeader } diff --git a/dot/node.go b/dot/node.go index b5e1e85e55b..561f01925cc 100644 --- a/dot/node.go +++ b/dot/node.go @@ -176,7 +176,7 @@ func (*nodeBuilder) initNode(cfg *Config) error { stateSrvc := state.NewService(config) // initialise state service with genesis data, block, and trie - err = stateSrvc.Initialise(gen, &header, t) + err = stateSrvc.Initialise(gen, &header, &t) if err != nil { return fmt.Errorf("failed to initialise state service: %s", err) } diff --git a/dot/node_test.go b/dot/node_test.go index a9045670ffa..ce9be33a554 100644 --- a/dot/node_test.go +++ b/dot/node_test.go @@ -176,7 +176,7 @@ func TestNewNode(t *testing.T) { return nil, fmt.Errorf("failed to create genesis block from trie: %w", err) } stateSrvc.Telemetry = mockTelemetryClient - err = stateSrvc.Initialise(gen, &header, trie) + err = stateSrvc.Initialise(gen, &header, &trie) if err != nil { return nil, fmt.Errorf("failed to initialise state service: %s", err) } diff --git a/dot/rpc/helpers_test.go b/dot/rpc/helpers_test.go index e4c5a52ad22..aab2428a441 100644 --- a/dot/rpc/helpers_test.go +++ b/dot/rpc/helpers_test.go @@ -16,12 +16,13 @@ import ( ) func newTestGenesisWithTrieAndHeader(t *testing.T) ( - gen *genesis.Genesis, genesisTrie *trie.Trie, genesisHeader *types.Header) { + gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) - gen, err := genesis.NewGenesisFromJSONRaw(genesisPath) + genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genesisPtr - genesisTrie, err = wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) parentHash := common.NewHash([]byte{0}) @@ -29,9 +30,10 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) ( extrinsicRoot := trie.EmptyHash const number = 0 digest := types.NewDigest() - genesisHeader, err = types.NewHeader(parentHash, + genesisHeaderPtr, err := types.NewHeader(parentHash, stateRoot, extrinsicRoot, number, digest) require.NoError(t, err) + genesisHeader = *genesisHeaderPtr return gen, genesisTrie, genesisHeader } diff --git a/dot/rpc/http_test.go b/dot/rpc/http_test.go index 70b8b4c3d66..e92fda121ad 100644 --- a/dot/rpc/http_test.go +++ b/dot/rpc/http_test.go @@ -364,7 +364,7 @@ func newCoreServiceTest(t *testing.T) *core.Service { testDatadirPath := t.TempDir() - gen, genTrie, genHeader := newTestGenesisWithTrieAndHeader(t) + gen, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) ctrl := gomock.NewController(t) telemetryMock := NewMockClient(ctrl) @@ -379,7 +379,7 @@ func newCoreServiceTest(t *testing.T) *core.Service { stateSrvc := state.NewService(config) stateSrvc.UseMemDB() - err := stateSrvc.Initialise(gen, genHeader, genTrie) + err := stateSrvc.Initialise(&gen, &genesisHeader, &genesisTrie) require.NoError(t, err) err = stateSrvc.SetupBase() @@ -406,7 +406,7 @@ func newCoreServiceTest(t *testing.T) *core.Service { var rtCfg wasmer.Config - rtCfg.Storage = rtstorage.NewTrieState(genTrie) + rtCfg.Storage = rtstorage.NewTrieState(&genesisTrie) rtCfg.CodeHash, err = cfg.StorageState.LoadCodeHash(nil) require.NoError(t, err) diff --git a/dot/rpc/modules/author_integration_test.go b/dot/rpc/modules/author_integration_test.go index 06bf7243536..c76a3363316 100644 --- a/dot/rpc/modules/author_integration_test.go +++ b/dot/rpc/modules/author_integration_test.go @@ -571,7 +571,7 @@ type integrationTestController struct { func setupStateAndRuntime(t *testing.T, basepath string, useInstance useRuntimeInstace) *integrationTestController { t.Helper() - gen, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) + gen, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) ctrl := gomock.NewController(t) telemetryMock := NewMockClient(ctrl) @@ -591,7 +591,7 @@ func setupStateAndRuntime(t *testing.T, basepath string, useInstance useRuntimeI state2test.UseMemDB() state2test.Transaction = state.NewTransactionState(telemetryMock) - err := state2test.Initialise(gen, genesisHeader, genTrie) + err := state2test.Initialise(&gen, &genesisHeader, &genesisTrie) require.NoError(t, err) err = state2test.Start() @@ -604,9 +604,9 @@ func setupStateAndRuntime(t *testing.T, basepath string, useInstance useRuntimeI ks := keystore.NewGlobalKeystore() net2test := NewMockNetwork(nil) integrationTestController := &integrationTestController{ - genesis: gen, - genesisTrie: genTrie, - genesisHeader: genesisHeader, + genesis: &gen, + genesisTrie: &genesisTrie, + genesisHeader: &genesisHeader, stateSrv: state2test, storageState: state2test.Storage, keystore: ks, @@ -631,7 +631,7 @@ func setupStateAndPopulateTrieState(t *testing.T, basepath string, useInstance useRuntimeInstace) *integrationTestController { t.Helper() - gen, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) + gen, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) ctrl := gomock.NewController(t) telemetryMock := NewMockClient(ctrl) @@ -652,7 +652,7 @@ func setupStateAndPopulateTrieState(t *testing.T, basepath string, state2test.Transaction = state.NewTransactionState(telemetryMock) - err := state2test.Initialise(gen, genesisHeader, genTrie) + err := state2test.Initialise(&gen, &genesisHeader, &genesisTrie) require.NoError(t, err) err = state2test.Start() @@ -665,9 +665,9 @@ func setupStateAndPopulateTrieState(t *testing.T, basepath string, net2test := NewMockNetwork(nil) ks := keystore.NewGlobalKeystore() integrationTestController := &integrationTestController{ - genesis: gen, - genesisTrie: genTrie, - genesisHeader: genesisHeader, + genesis: &gen, + genesisTrie: &genesisTrie, + genesisHeader: &genesisHeader, stateSrv: state2test, storageState: state2test.Storage, keystore: ks, diff --git a/dot/rpc/modules/chain_integration_test.go b/dot/rpc/modules/chain_integration_test.go index cf329370781..efc0f824843 100644 --- a/dot/rpc/modules/chain_integration_test.go +++ b/dot/rpc/modules/chain_integration_test.go @@ -352,9 +352,9 @@ func newTestStateService(t *testing.T) *state.Service { stateSrvc := state.NewService(config) stateSrvc.UseMemDB() - gen, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) + gen, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := stateSrvc.Initialise(gen, genesisHeader, genTrie) + err := stateSrvc.Initialise(&gen, &genesisHeader, &genesisTrie) require.NoError(t, err) err = stateSrvc.Start() @@ -362,7 +362,7 @@ func newTestStateService(t *testing.T) *state.Service { var rtCfg wasmer.Config - rtCfg.Storage = rtstorage.NewTrieState(genTrie) + rtCfg.Storage = rtstorage.NewTrieState(&genesisTrie) if stateSrvc != nil { rtCfg.NodeStorage.BaseDB = stateSrvc.Base diff --git a/dot/rpc/modules/childstate_test.go b/dot/rpc/modules/childstate_test.go index 63032ab6a6b..b9d8b2ecc44 100644 --- a/dot/rpc/modules/childstate_test.go +++ b/dot/rpc/modules/childstate_test.go @@ -20,8 +20,8 @@ import ( func createTestTrieState(t *testing.T) (*trie.Trie, common.Hash) { t.Helper() - _, genTrie, _ := newTestGenesisWithTrieAndHeader(t) - tr := rtstorage.NewTrieState(genTrie) + _, genesisTrie, _ := newTestGenesisWithTrieAndHeader(t) + tr := rtstorage.NewTrieState(&genesisTrie) tr.Set([]byte(":first_key"), []byte(":value1")) tr.Set([]byte(":second_key"), []byte(":second_value")) diff --git a/dot/rpc/modules/dev_integration_test.go b/dot/rpc/modules/dev_integration_test.go index 7c4fd365f16..f759dfda717 100644 --- a/dot/rpc/modules/dev_integration_test.go +++ b/dot/rpc/modules/dev_integration_test.go @@ -42,8 +42,8 @@ func newState(t *testing.T) (*state.BlockState, *state.EpochState) { _, genesisTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) tries := state.NewTries() - tries.SetTrie(genesisTrie) - bs, err := state.NewBlockStateFromGenesis(db, tries, genesisHeader, telemetryMock) + tries.SetTrie(&genesisTrie) + bs, err := state.NewBlockStateFromGenesis(db, tries, &genesisHeader, telemetryMock) require.NoError(t, err) es, err := state.NewEpochStateFromGenesis(db, bs, genesisBABEConfig) require.NoError(t, err) diff --git a/dot/rpc/modules/helpers_test.go b/dot/rpc/modules/helpers_test.go index 8e62835e234..23188856ba0 100644 --- a/dot/rpc/modules/helpers_test.go +++ b/dot/rpc/modules/helpers_test.go @@ -23,12 +23,13 @@ func makeChange(keyHex, valueHex string) [2]*string { } func newTestGenesisWithTrieAndHeader(t *testing.T) ( - gen *genesis.Genesis, genesisTrie *trie.Trie, genesisHeader *types.Header) { + gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) - gen, err := genesis.NewGenesisFromJSONRaw(genesisPath) + genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genesisPtr - genesisTrie, err = wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) parentHash := common.NewHash([]byte{0}) @@ -36,9 +37,10 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) ( extrinsicRoot := trie.EmptyHash const number = 0 digest := types.NewDigest() - genesisHeader, err = types.NewHeader(parentHash, + genesisHeaderPtr, err := types.NewHeader(parentHash, stateRoot, extrinsicRoot, number, digest) require.NoError(t, err) + genesisHeader = *genesisHeaderPtr return gen, genesisTrie, genesisHeader } diff --git a/dot/services_integration_test.go b/dot/services_integration_test.go index 82283bed831..b970f433e1f 100644 --- a/dot/services_integration_test.go +++ b/dot/services_integration_test.go @@ -54,7 +54,7 @@ func newStateServiceWithoutMock(t *testing.T) *state.Service { stateSrvc := state.NewService(stateConfig) stateSrvc.UseMemDB() genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := stateSrvc.Initialise(genData, genesisHeader, genTrie) + err := stateSrvc.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) err = stateSrvc.SetupBase() @@ -76,7 +76,7 @@ func newStateServiceWithoutMock(t *testing.T) *state.Service { var rtCfg wasmer.Config - rtCfg.Storage = rtstorage.NewTrieState(genTrie) + rtCfg.Storage = rtstorage.NewTrieState(&genTrie) rtCfg.CodeHash, err = stateSrvc.Storage.LoadCodeHash(nil) require.NoError(t, err) diff --git a/dot/services_test.go b/dot/services_test.go index 0dcaab85cb0..95787fcdfc3 100644 --- a/dot/services_test.go +++ b/dot/services_test.go @@ -234,7 +234,7 @@ func newStateService(t *testing.T, ctrl *gomock.Controller) *state.Service { stateSrvc := state.NewService(stateConfig) stateSrvc.UseMemDB() genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := stateSrvc.Initialise(genData, genesisHeader, genTrie) + err := stateSrvc.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) err = stateSrvc.SetupBase() @@ -256,7 +256,7 @@ func newStateService(t *testing.T, ctrl *gomock.Controller) *state.Service { var rtCfg wasmer.Config - rtCfg.Storage = rtstorage.NewTrieState(genTrie) + rtCfg.Storage = rtstorage.NewTrieState(&genTrie) rtCfg.CodeHash, err = stateSrvc.Storage.LoadCodeHash(nil) require.NoError(t, err) diff --git a/dot/state/helpers_test.go b/dot/state/helpers_test.go index df31d3a4551..628dd92a57b 100644 --- a/dot/state/helpers_test.go +++ b/dot/state/helpers_test.go @@ -90,12 +90,13 @@ func generateRandBytes(tb testing.TB, size int, } func newTestGenesisWithTrieAndHeader(t *testing.T) ( - gen *genesis.Genesis, genesisTrie *trie.Trie, genesisHeader *types.Header) { + gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) - gen, err := genesis.NewGenesisFromJSONRaw(genesisPath) + genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genesisPtr - genesisTrie, err = wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) parentHash := common.NewHash([]byte{0}) @@ -103,9 +104,10 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) ( extrinsicRoot := trie.EmptyHash const number = 0 digest := types.NewDigest() - genesisHeader, err = types.NewHeader(parentHash, + genesisHeaderPtr, err := types.NewHeader(parentHash, stateRoot, extrinsicRoot, number, digest) require.NoError(t, err) + genesisHeader = *genesisHeaderPtr return gen, genesisTrie, genesisHeader } diff --git a/dot/state/service_test.go b/dot/state/service_test.go index 9a383c48863..13e461627a8 100644 --- a/dot/state/service_test.go +++ b/dot/state/service_test.go @@ -55,7 +55,7 @@ func TestService_Start(t *testing.T) { state := newTestService(t) genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := state.Initialise(genData, genesisHeader, genTrie) + err := state.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) err = state.SetupBase() @@ -72,14 +72,14 @@ func TestService_Initialise(t *testing.T) { state := newTestService(t) genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := state.Initialise(genData, genesisHeader, genTrie) + err := state.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) - genesisHeader, err = types.NewHeader(common.NewHash([]byte{77}), + genesisHeaderPtr, err := types.NewHeader(common.NewHash([]byte{77}), genTrie.MustHash(), trie.EmptyHash, 0, types.NewDigest()) require.NoError(t, err) - err = state.Initialise(genData, genesisHeader, genTrie) + err = state.Initialise(&genData, genesisHeaderPtr, &genTrie) require.NoError(t, err) err = state.SetupBase() @@ -90,14 +90,14 @@ func TestService_Initialise(t *testing.T) { head, err := state.Block.BestBlockHeader() require.NoError(t, err) - require.Equal(t, genesisHeader, head) + require.Equal(t, genesisHeaderPtr, head) } func TestMemDB_Start(t *testing.T) { state := newTestMemDBService(t) genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := state.Initialise(genData, genesisHeader, genTrie) + err := state.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) err = state.Start() @@ -125,7 +125,7 @@ func TestService_BlockTree(t *testing.T) { stateA := NewService(config) genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := stateA.Initialise(genData, genesisHeader, genTrie) + err := stateA.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) err = stateA.SetupBase() @@ -176,7 +176,7 @@ func TestService_StorageTriePruning(t *testing.T) { serv.UseMemDB() genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := serv.Initialise(genData, genesisHeader, genTrie) + err := serv.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) err = serv.Start() @@ -225,7 +225,7 @@ func TestService_PruneStorage(t *testing.T) { serv.UseMemDB() genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := serv.Initialise(genData, genesisHeader, genTrie) + err := serv.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) err = serv.Start() @@ -306,7 +306,7 @@ func TestService_Rewind(t *testing.T) { serv.UseMemDB() genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := serv.Initialise(genData, genesisHeader, genTrie) + err := serv.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) err = serv.Start() @@ -364,7 +364,7 @@ func TestService_Import(t *testing.T) { serv.UseMemDB() genData, genTrie, genesisHeader := newTestGenesisWithTrieAndHeader(t) - err := serv.Initialise(genData, genesisHeader, genTrie) + err := serv.Initialise(&genData, &genesisHeader, &genTrie) require.NoError(t, err) tr := trie.NewEmptyTrie() diff --git a/dot/state/storage_test.go b/dot/state/storage_test.go index 2dcd5e700df..f78bc4f96eb 100644 --- a/dot/state/storage_test.go +++ b/dot/state/storage_test.go @@ -192,13 +192,13 @@ func TestGetStorageChildAndGetStorageFromChild(t *testing.T) { tries := newTriesEmpty() - blockState, err := NewBlockStateFromGenesis(db, tries, genHeader, telemetryMock) + blockState, err := NewBlockStateFromGenesis(db, tries, &genHeader, telemetryMock) require.NoError(t, err) storage, err := NewStorageState(db, blockState, tries, pruner.Config{}) require.NoError(t, err) - trieState := runtime.NewTrieState(genTrie) + trieState := runtime.NewTrieState(&genTrie) header, err := types.NewHeader(blockState.GenesisHash(), trieState.MustRoot(), common.Hash{}, 1, types.NewDigest()) diff --git a/dot/sync/syncer_integration_test.go b/dot/sync/syncer_integration_test.go index e3eaff7b4c9..5e8dfe75a9a 100644 --- a/dot/sync/syncer_integration_test.go +++ b/dot/sync/syncer_integration_test.go @@ -46,7 +46,7 @@ func newTestSyncer(t *testing.T) *Service { stateSrvc.UseMemDB() gen, genTrie, genHeader := newTestGenesisWithTrieAndHeader(t) - err := stateSrvc.Initialise(gen, genHeader, genTrie) + err := stateSrvc.Initialise(&gen, &genHeader, &genTrie) require.NoError(t, err) err = stateSrvc.Start() @@ -61,7 +61,7 @@ func newTestSyncer(t *testing.T) *Service { } // initialise runtime - genState := rtstorage.NewTrieState(genTrie) + genState := rtstorage.NewTrieState(&genTrie) rtCfg := wasmer.Config{ Storage: genState, @@ -122,18 +122,27 @@ func newTestSyncer(t *testing.T) *Service { return syncer } -func newTestGenesisWithTrieAndHeader(t *testing.T) (*genesis.Genesis, *trie.Trie, *types.Header) { - fp := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) - gen, err := genesis.NewGenesisFromJSONRaw(fp) +func newTestGenesisWithTrieAndHeader(t *testing.T) ( + gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { + genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) + genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genesisPtr - genTrie, err := wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) - genesisHeader, err := types.NewHeader(common.NewHash([]byte{0}), - genTrie.MustHash(), trie.EmptyHash, 0, types.NewDigest()) + parentHash := common.NewHash([]byte{0}) + stateRoot := genesisTrie.MustHash() + extrinsicRoot := trie.EmptyHash + const number = 0 + digest := types.NewDigest() + genesisHeaderPtr, err := types.NewHeader(parentHash, + stateRoot, extrinsicRoot, number, digest) require.NoError(t, err) - return gen, genTrie, genesisHeader + genesisHeader = *genesisHeaderPtr + + return gen, genesisTrie, genesisHeader } func TestHighestBlock(t *testing.T) { diff --git a/lib/babe/babe_integration_test.go b/lib/babe/babe_integration_test.go index 7b9281e26f4..5b9f30cc1b3 100644 --- a/lib/babe/babe_integration_test.go +++ b/lib/babe/babe_integration_test.go @@ -154,7 +154,7 @@ func newTestServiceSetupParameters(t *testing.T) (*Service, *state.EpochState, * dbSrv.UseMemDB() gen, genTrie, genHeader := newTestGenesisWithTrieAndHeader(t) - err := dbSrv.Initialise(gen, genHeader, genTrie) + err := dbSrv.Initialise(&gen, &genHeader, &genTrie) require.NoError(t, err) err = dbSrv.Start() @@ -165,7 +165,7 @@ func newTestServiceSetupParameters(t *testing.T) (*Service, *state.EpochState, * }) rtCfg := wasmer.Config{ - Storage: rtstorage.NewTrieState(genTrie), + Storage: rtstorage.NewTrieState(&genTrie), } rt, err := wasmer.NewRuntimeFromGenesis(rtCfg) diff --git a/lib/babe/helpers_test.go b/lib/babe/helpers_test.go index 1c0fce6bb0a..13618e40af8 100644 --- a/lib/babe/helpers_test.go +++ b/lib/babe/helpers_test.go @@ -22,24 +22,27 @@ func newDevGenesisWithTrieAndHeader(t *testing.T) ( genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genesisPtr - genesisTriePtr, err := wasmer.NewTrieFromGenesis(*genesisPtr) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) genesisHeaderPtr, err := types.NewHeader(common.NewHash([]byte{0}), genesisTrie.MustHash(), trie.EmptyHash, 0, types.NewDigest()) require.NoError(t, err) + genesisHeader = *genesisHeaderPtr - return *genesisPtr, *genesisTriePtr, *genesisHeaderPtr + return gen, genesisTrie, genesisHeader } func newTestGenesisWithTrieAndHeader(t *testing.T) ( - gen *genesis.Genesis, genesisTrie *trie.Trie, genesisHeader *types.Header) { + gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) - gen, err := genesis.NewGenesisFromJSONRaw(genesisPath) + genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genesisPtr - genesisTrie, err = wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) parentHash := common.NewHash([]byte{0}) @@ -47,9 +50,10 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) ( extrinsicRoot := trie.EmptyHash const number = 0 digest := types.NewDigest() - genesisHeader, err = types.NewHeader(parentHash, + genesisHeaderPtr, err := types.NewHeader(parentHash, stateRoot, extrinsicRoot, number, digest) require.NoError(t, err) + genesisHeader = *genesisHeaderPtr return gen, genesisTrie, genesisHeader } diff --git a/lib/babe/verify_integration_test.go b/lib/babe/verify_integration_test.go index d4065ce1dbe..a1f4da42a24 100644 --- a/lib/babe/verify_integration_test.go +++ b/lib/babe/verify_integration_test.go @@ -518,7 +518,7 @@ func TestVerifyForkBlocksWithRespectiveEpochData(t *testing.T) { stateService.UseMemDB() - err := stateService.Initialise(genesis, genesisHeader, trie) + err := stateService.Initialise(&genesis, &genesisHeader, &trie) require.NoError(t, err) inMemoryDB, err := chaindb.NewBadgerDB(&chaindb.Config{ @@ -548,7 +548,7 @@ func TestVerifyForkBlocksWithRespectiveEpochData(t *testing.T) { C2: 10, SecondarySlots: 1, } - aliceBlockHeader := issueConsensusDigestsBlockFromGenesis(t, genesisHeader, keyring.KeyAlice, + aliceBlockHeader := issueConsensusDigestsBlockFromGenesis(t, &genesisHeader, keyring.KeyAlice, stateService, aliceBlockNextEpoch, aliceBlockNextConfigData) bobBlockNextEpoch := types.NextEpochData{ @@ -559,7 +559,7 @@ func TestVerifyForkBlocksWithRespectiveEpochData(t *testing.T) { C2: 8, SecondarySlots: 1, } - bobBlockHeader := issueConsensusDigestsBlockFromGenesis(t, genesisHeader, keyring.KeyBob, + bobBlockHeader := issueConsensusDigestsBlockFromGenesis(t, &genesisHeader, keyring.KeyBob, stateService, bobBlockNextEpoch, bobBlockNextConfigData) // wait for digest handleBlockImport goroutine gets the imported diff --git a/lib/grandpa/grandpa_test.go b/lib/grandpa/grandpa_test.go index 745f76e56b8..afd0d3a157e 100644 --- a/lib/grandpa/grandpa_test.go +++ b/lib/grandpa/grandpa_test.go @@ -51,13 +51,13 @@ func newTestState(t *testing.T) *state.Service { _, genTrie, _ := newTestGenesisWithTrieAndHeader(t) tries := state.NewTries() - tries.SetTrie(genTrie) + tries.SetTrie(&genTrie) block, err := state.NewBlockStateFromGenesis(db, tries, testGenesisHeader, telemetryMock) require.NoError(t, err) var rtCfg wasmer.Config - rtCfg.Storage = rtstorage.NewTrieState(genTrie) + rtCfg.Storage = rtstorage.NewTrieState(&genTrie) rt, err := wasmer.NewRuntimeFromGenesis(rtCfg) require.NoError(t, err) diff --git a/lib/grandpa/helpers_test.go b/lib/grandpa/helpers_test.go index 148b6eee932..420ae9fe138 100644 --- a/lib/grandpa/helpers_test.go +++ b/lib/grandpa/helpers_test.go @@ -16,12 +16,13 @@ import ( ) func newTestGenesisWithTrieAndHeader(t *testing.T) ( - gen *genesis.Genesis, genesisTrie *trie.Trie, genesisHeader *types.Header) { + gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) { genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t) - gen, err := genesis.NewGenesisFromJSONRaw(genesisPath) + genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath) require.NoError(t, err) + gen = *genesisPtr - genesisTrie, err = wasmer.NewTrieFromGenesis(*gen) + genesisTrie, err = wasmer.NewTrieFromGenesis(gen) require.NoError(t, err) parentHash := common.NewHash([]byte{0}) @@ -29,9 +30,10 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) ( extrinsicRoot := trie.EmptyHash const number = 0 digest := types.NewDigest() - genesisHeader, err = types.NewHeader(parentHash, + genesisHeaderPtr, err := types.NewHeader(parentHash, stateRoot, extrinsicRoot, number, digest) require.NoError(t, err) + genesisHeader = *genesisHeaderPtr return gen, genesisTrie, genesisHeader } diff --git a/lib/runtime/wasmer/exports_test.go b/lib/runtime/wasmer/exports_test.go index 27301f73cea..2ed1f3fd5d7 100644 --- a/lib/runtime/wasmer/exports_test.go +++ b/lib/runtime/wasmer/exports_test.go @@ -128,7 +128,7 @@ func Test_Instance_Version(t *testing.T) { require.NoError(t, err) cfg := Config{ - Storage: storage.NewTrieState(genesisTrie), + Storage: storage.NewTrieState(&genesisTrie), LogLvl: log.Critical, } @@ -302,7 +302,7 @@ func TestNodeRuntime_ValidateTransaction(t *testing.T) { require.NoError(t, err) // set state to genesis state - genState := storage.NewTrieState(genTrie) + genState := storage.NewTrieState(&genTrie) cfg := Config{ Storage: genState, @@ -534,7 +534,7 @@ func TestInstance_ExecuteBlock_GossamerRuntime(t *testing.T) { require.NoError(t, err) // set state to genesis state - genState := storage.NewTrieState(genTrie) + genState := storage.NewTrieState(&genTrie) cfg := Config{ Storage: genState, @@ -547,7 +547,7 @@ func TestInstance_ExecuteBlock_GossamerRuntime(t *testing.T) { block := runtime.InitializeRuntimeToTest(t, instance, common.Hash{}) // reset state back to parent state before executing - parentState := storage.NewTrieState(genTrie) + parentState := storage.NewTrieState(&genTrie) instance.SetContextStorage(parentState) _, err = instance.ExecuteBlock(block) @@ -562,7 +562,7 @@ func TestInstance_ApplyExtrinsic_GossamerRuntime(t *testing.T) { require.NoError(t, err) // set state to genesis state - genState := storage.NewTrieState(genTrie) + genState := storage.NewTrieState(&genTrie) cfg := Config{ Storage: genState, @@ -573,7 +573,7 @@ func TestInstance_ApplyExtrinsic_GossamerRuntime(t *testing.T) { require.NoError(t, err) // reset state back to parent state before executing - parentState := storage.NewTrieState(genTrie) + parentState := storage.NewTrieState(&genTrie) instance.SetContextStorage(parentState) parentHash := common.Hash{} @@ -620,7 +620,7 @@ func TestInstance_ExecuteBlock_PolkadotRuntime_PolkadotBlock1(t *testing.T) { require.Equal(t, expectedGenesisRoot, genTrie.MustHash()) // set state to genesis state - genState := storage.NewTrieState(genTrie) + genState := storage.NewTrieState(&genTrie) cfg := Config{ Storage: genState, @@ -670,7 +670,7 @@ func TestInstance_ExecuteBlock_KusamaRuntime_KusamaBlock1(t *testing.T) { require.Equal(t, expectedGenesisRoot, genTrie.MustHash()) // set state to genesis state - genState := storage.NewTrieState(genTrie) + genState := storage.NewTrieState(&genTrie) cfg := Config{ Storage: genState, diff --git a/lib/runtime/wasmer/genesis.go b/lib/runtime/wasmer/genesis.go index f253d98c174..91f033950b0 100644 --- a/lib/runtime/wasmer/genesis.go +++ b/lib/runtime/wasmer/genesis.go @@ -16,18 +16,19 @@ var ( ) // NewTrieFromGenesis creates a new trie from the raw genesis data -func NewTrieFromGenesis(gen genesis.Genesis) (tr *trie.Trie, err error) { - tr = trie.NewEmptyTrie() +func NewTrieFromGenesis(gen genesis.Genesis) (tr trie.Trie, err error) { + triePtr := trie.NewEmptyTrie() + tr = *triePtr genesisFields := gen.GenesisFields() keyValues, ok := genesisFields.Raw["top"] if !ok { - return nil, fmt.Errorf("%w: in genesis %s", + return tr, fmt.Errorf("%w: in genesis %s", ErrGenesisTopNotFound, gen.Name) } err = tr.LoadFromMap(keyValues) if err != nil { - return nil, fmt.Errorf("loading genesis top key values into trie: %w", err) + return tr, fmt.Errorf("loading genesis top key values into trie: %w", err) } return tr, nil