diff --git a/dot/core/interface.go b/dot/core/interface.go index dcc3b8fe3a..76b97e3904 100644 --- a/dot/core/interface.go +++ b/dot/core/interface.go @@ -52,6 +52,7 @@ type BlockState interface { HandleRuntimeChanges(newState *rtstorage.TrieState, in runtime.Instance, bHash common.Hash) error GetRuntime(*common.Hash) (runtime.Instance, bool) StoreRuntime(common.Hash, runtime.Instance) + GetAllBlocks() []common.Hash } // StorageState interface for storage state methods diff --git a/dot/core/test_helpers.go b/dot/core/test_helpers.go index c0af1948ee..393db564c6 100644 --- a/dot/core/test_helpers.go +++ b/dot/core/test_helpers.go @@ -127,6 +127,8 @@ func NewTestService(t *testing.T, cfg *Config) *Service { require.NoError(t, err) cfg.BlockState.StoreRuntime(cfg.BlockState.BestBlockHash(), rt) + } else { + cfg.BlockState.StoreRuntime(cfg.BlockState.BestBlockHash(), cfg.Runtime) } if cfg.Network == nil { diff --git a/dot/node.go b/dot/node.go index 06892eaee6..94d1a3e59a 100644 --- a/dot/node.go +++ b/dot/node.go @@ -36,6 +36,7 @@ import ( "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/genesis" "github.com/ChainSafe/gossamer/lib/keystore" + "github.com/ChainSafe/gossamer/lib/runtime" "github.com/ChainSafe/gossamer/lib/services" "github.com/ChainSafe/gossamer/lib/utils" log "github.com/ChainSafe/log15" @@ -259,7 +260,7 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node, } // create runtime - rt, err := createRuntime(cfg, stateSrvc, ks, networkSrvc) + err = loadRuntime(cfg, stateSrvc, ks, networkSrvc) if err != nil { return nil, err } @@ -287,13 +288,13 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node, } nodeSrvcs = append(nodeSrvcs, bp) - fg, err := createGRANDPAService(cfg, rt, stateSrvc, dh, ks.Gran, networkSrvc) + fg, err := createGRANDPAService(cfg, stateSrvc, dh, ks.Gran, networkSrvc) if err != nil { return nil, err } nodeSrvcs = append(nodeSrvcs, fg) - syncer, err := newSyncService(cfg, stateSrvc, fg, ver, rt, coreSrvc) + syncer, err := newSyncService(cfg, stateSrvc, fg, ver, coreSrvc) if err != nil { return nil, err } @@ -311,7 +312,7 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node, // check if rpc service is enabled if enabled := cfg.RPC.Enabled; enabled { - rpcSrvc := createRPCService(cfg, stateSrvc, coreSrvc, networkSrvc, bp, rt, sysSrvc) + rpcSrvc := createRPCService(cfg, stateSrvc, coreSrvc, networkSrvc, bp, sysSrvc) nodeSrvcs = append(nodeSrvcs, rpcSrvc) } else { logger.Debug("rpc service disabled by default", "rpc", enabled) @@ -446,3 +447,28 @@ func (n *Node) Stop() { n.Services.StopAll() n.wg.Done() } + +func loadRuntime(cfg *Config, stateSrvc *state.Service, ks *keystore.GlobalKeystore, net *network.Service) error { + blocks := stateSrvc.Block.GetAllBlocks() + runtimeCode := make(map[string]runtime.Instance) + for _, hash := range blocks { + code, err := stateSrvc.Storage.GetStorageByBlockHash(hash, []byte(":code")) + if err != nil { + return err + } + + if rt, ok := runtimeCode[string(code)]; ok { + stateSrvc.Block.StoreRuntime(hash, rt) + continue + } + + rt, err := createRuntime(cfg, stateSrvc, ks, net, code) + if err != nil { + return err + } + + runtimeCode[string(code)] = rt + } + + return nil +} diff --git a/dot/rpc/modules/chain_test.go b/dot/rpc/modules/chain_test.go index a0c22510b0..41faeda381 100644 --- a/dot/rpc/modules/chain_test.go +++ b/dot/rpc/modules/chain_test.go @@ -23,9 +23,9 @@ import ( "github.com/ChainSafe/gossamer/dot/state" "github.com/ChainSafe/gossamer/dot/types" - "github.com/ChainSafe/gossamer/lib/blocktree" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/lib/genesis" + "github.com/ChainSafe/gossamer/lib/runtime" "github.com/ChainSafe/gossamer/lib/trie" database "github.com/ChainSafe/chaindb" @@ -319,25 +319,16 @@ func newTestStateService(t *testing.T) *state.Service { stateSrvc.UseMemDB() err = stateSrvc.Initialise(gen, genesisHeader, genTrie) - if err != nil { - t.Fatal(err) - } - - hash := genesisHeader.Hash() - rt, ok := stateSrvc.Block.GetRuntime(&hash) - require.True(t, ok) + require.NoError(t, err) err = stateSrvc.Start() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) - stateSrvc.Block.StoreRuntime(hash, rt) + rt, err := stateSrvc.CreateGenesisRuntime(genTrie, gen) + require.NoError(t, err) - err = loadTestBlocks(genesisHeader.Hash(), stateSrvc.Block) - if err != nil { - t.Fatal(err) - } + err = loadTestBlocks(genesisHeader.Hash(), stateSrvc.Block, rt) + require.NoError(t, err) t.Cleanup(func() { stateSrvc.Stop() @@ -363,7 +354,7 @@ func newTestGenesisWithTrieAndHeader() (*genesis.Genesis, *trie.Trie, *types.Hea return gen, genTrie, genesisHeader } -func loadTestBlocks(gh common.Hash, bs *state.BlockState) error { +func loadTestBlocks(gh common.Hash, bs *state.BlockState, rt runtime.Instance) error { // Create header header0 := &types.Header{ Number: big.NewInt(0), @@ -386,11 +377,6 @@ func loadTestBlocks(gh common.Hash, bs *state.BlockState) error { return err } - rt, ok := bs.GetRuntime(&gh) - if !ok { - return blocktree.ErrFailedToGetRuntime - } - bs.StoreRuntime(block0.Header.Hash(), rt) // Create header & blockData for block 1 @@ -417,7 +403,7 @@ func loadTestBlocks(gh common.Hash, bs *state.BlockState) error { return err } - bs.StoreRuntime(block0.Header.Hash(), rt) + bs.StoreRuntime(block1.Header.Hash(), rt) return nil } diff --git a/dot/rpc/modules/dev_test.go b/dot/rpc/modules/dev_test.go index d018587658..36948087cd 100644 --- a/dot/rpc/modules/dev_test.go +++ b/dot/rpc/modules/dev_test.go @@ -44,14 +44,13 @@ func newBABEService(t *testing.T) *babe.Service { bs, es := newState(t) tt := trie.NewEmptyTrie() rt := wasmer.NewTestInstanceWithTrie(t, runtime.NODE_RUNTIME, tt, log.LvlInfo) - + bs.StoreRuntime(bs.GenesisHash(), rt) tt.Put(common.MustHexToBytes("0x886726f904d8372fdabb7707870c2fad"), common.MustHexToBytes("0x24d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01000000000000008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48010000000000000090b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe220100000000000000306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc200100000000000000e659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e01000000000000001cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c01000000000000004603307f855321776922daeea21ee31720388d097cdaac66f05a6f8462b317570100000000000000be1d9d59de1283380100550a7b024501cb62d6cc40e3db35fcc5cf341814986e01000000000000001206960f920a23f7f4c43cc9081ec2ed0721f31a9bef2c10fd7602e16e08a32c0100000000000000")) cfg := &babe.ServiceConfig{ BlockState: bs, EpochState: es, Keypair: kr.Alice().(*sr25519.Keypair), - Runtime: rt, IsDev: true, BlockImportHandler: new(babemocks.BlockImportHandler), } diff --git a/dot/rpc/modules/state_test.go b/dot/rpc/modules/state_test.go index fce741b7d1..1cd732919e 100644 --- a/dot/rpc/modules/state_test.go +++ b/dot/rpc/modules/state_test.go @@ -443,8 +443,8 @@ func setupStateModule(t *testing.T) (*StateModule, *common.Hash, *common.Hash) { err = chain.Block.AddBlock(b) require.NoError(t, err) - genHash := chain.Block.GenesisHash() - rt, ok := chain.Block.GetRuntime(&genHash) + + rt, ok := chain.Block.GetRuntime(&b.Header.ParentHash) require.True(t, ok) chain.Block.StoreRuntime(b.Header.Hash(), rt) diff --git a/dot/rpc/websocket_test.go b/dot/rpc/websocket_test.go index 25cff1dc96..e9e16662b4 100644 --- a/dot/rpc/websocket_test.go +++ b/dot/rpc/websocket_test.go @@ -17,6 +17,7 @@ package rpc import ( "flag" + "fmt" "log" "net/url" "testing" @@ -91,6 +92,8 @@ func TestHTTPServer_ServeHTTP(t *testing.T) { _, message, err := c.ReadMessage() require.Nil(t, err) + fmt.Println("message", string(message)) + fmt.Println("item.expected", string(item.expected)) require.Equal(t, item.expected, message) } } diff --git a/dot/services.go b/dot/services.go index 8d4fd1589d..763e98cfe1 100644 --- a/dot/services.go +++ b/dot/services.go @@ -32,6 +32,7 @@ import ( "github.com/ChainSafe/gossamer/dot/system" "github.com/ChainSafe/gossamer/dot/types" "github.com/ChainSafe/gossamer/lib/babe" + "github.com/ChainSafe/gossamer/lib/blocktree" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/lib/crypto" "github.com/ChainSafe/gossamer/lib/crypto/ed25519" @@ -90,18 +91,12 @@ func createStateService(cfg *Config) (*state.Service, error) { return stateSrvc, nil } -func createRuntime(cfg *Config, st *state.Service, ks *keystore.GlobalKeystore, net *network.Service) (runtime.Instance, error) { +func createRuntime(cfg *Config, st *state.Service, ks *keystore.GlobalKeystore, net *network.Service, code []byte) (runtime.Instance, error) { logger.Info( "creating runtime...", "interpreter", cfg.Core.WasmInterpreter, ) - // load runtime code from trie - code, err := st.Storage.GetStorage(nil, []byte(":code")) - if err != nil { - return nil, fmt.Errorf("failed to retrieve :code from trie: %s", err) - } - // check if code substitute is in use, if so replace code codeSubHash := st.Base.LoadCodeSubstitutedBlockHash() @@ -324,7 +319,7 @@ func createNetworkService(cfg *Config, stateSrvc *state.Service) (*network.Servi // RPC Service // createRPCService creates the RPC service from the provided core configuration -func createRPCService(cfg *Config, stateSrvc *state.Service, coreSrvc *core.Service, networkSrvc *network.Service, bp modules.BlockProducerAPI, rt runtime.Instance, sysSrvc *system.Service) *rpc.HTTPServer { +func createRPCService(cfg *Config, stateSrvc *state.Service, coreSrvc *core.Service, networkSrvc *network.Service, bp modules.BlockProducerAPI, sysSrvc *system.Service) *rpc.HTTPServer { logger.Info( "creating rpc service...", "host", cfg.RPC.Host, @@ -344,7 +339,7 @@ func createRPCService(cfg *Config, stateSrvc *state.Service, coreSrvc *core.Serv NetworkAPI: networkSrvc, CoreAPI: coreSrvc, BlockProducerAPI: bp, - RuntimeAPI: rt, + RuntimeAPI: stateSrvc.Block, TransactionQueueAPI: stateSrvc.Transaction, RPCAPI: rpcService, SystemAPI: sysSrvc, @@ -372,7 +367,12 @@ func createSystemService(cfg *types.SystemInfo, stateSrvc *state.Service) (*syst } // createGRANDPAService creates a new GRANDPA service -func createGRANDPAService(cfg *Config, rt runtime.Instance, st *state.Service, dh *digest.Handler, ks keystore.Keystore, net *network.Service) (*grandpa.Service, error) { +func createGRANDPAService(cfg *Config, st *state.Service, dh *digest.Handler, ks keystore.Keystore, net *network.Service) (*grandpa.Service, error) { + rt, ok := st.Block.GetRuntime(nil) + if !ok { + return nil, blocktree.ErrFailedToGetRuntime + } + ad, err := rt.GrandpaAuthorities() if err != nil { return nil, err @@ -415,7 +415,7 @@ func createBlockVerifier(st *state.Service) (*babe.VerificationManager, error) { return ver, nil } -func newSyncService(cfg *Config, st *state.Service, fg sync.FinalityGadget, verifier *babe.VerificationManager, rt runtime.Instance, cs *core.Service) (*sync.Service, error) { +func newSyncService(cfg *Config, st *state.Service, fg sync.FinalityGadget, verifier *babe.VerificationManager, cs *core.Service) (*sync.Service, error) { syncCfg := &sync.Config{ LogLvl: cfg.Log.SyncLvl, BlockState: st.Block, @@ -423,7 +423,6 @@ func newSyncService(cfg *Config, st *state.Service, fg sync.FinalityGadget, veri TransactionState: st.Transaction, FinalityGadget: fg, Verifier: verifier, - Runtime: rt, BlockImportHandler: cs, } diff --git a/dot/services_test.go b/dot/services_test.go index abf3690473..dce5b902b3 100644 --- a/dot/services_test.go +++ b/dot/services_test.go @@ -140,7 +140,7 @@ func TestCreateSyncService(t *testing.T) { coreSrvc, err := createCoreService(cfg, ks, stateSrvc, &network.Service{}, dh) require.NoError(t, err) - _, err = newSyncService(cfg, stateSrvc, nil, ver, nil, coreSrvc) + _, err = newSyncService(cfg, stateSrvc, nil, ver, coreSrvc) require.NoError(t, err) } @@ -197,7 +197,7 @@ func TestCreateRPCService(t *testing.T) { ed25519Keyring, _ := keystore.NewEd25519Keyring() ks.Gran.Insert(ed25519Keyring.Alice()) - rt, err := createRuntime(cfg, stateSrvc, ks, networkSrvc) + err = loadRuntime(cfg, stateSrvc, ks, networkSrvc) require.NoError(t, err) dh, err := createDigestHandler(stateSrvc) @@ -209,7 +209,7 @@ func TestCreateRPCService(t *testing.T) { sysSrvc, err := createSystemService(&cfg.System, stateSrvc) require.NoError(t, err) - rpcSrvc := createRPCService(cfg, stateSrvc, coreSrvc, networkSrvc, nil, rt, sysSrvc) + rpcSrvc := createRPCService(cfg, stateSrvc, coreSrvc, networkSrvc, nil, sysSrvc) require.NotNil(t, rpcSrvc) } @@ -237,7 +237,7 @@ func TestCreateBABEService(t *testing.T) { require.NoError(t, err) ks.Babe.Insert(kr.Alice()) - rt, err := createRuntime(cfg, stateSrvc, ks, &network.Service{}) + err = loadRuntime(cfg, stateSrvc, ks, &network.Service{}) require.NoError(t, err) dh, err := createDigestHandler(stateSrvc) @@ -246,7 +246,7 @@ func TestCreateBABEService(t *testing.T) { coreSrvc, err := createCoreService(cfg, ks, stateSrvc, &network.Service{}, dh) require.NoError(t, err) - bs, err := createBABEService(cfg, rt, stateSrvc, ks.Babe, coreSrvc) + bs, err := createBABEService(cfg, stateSrvc, ks.Babe, coreSrvc) require.NoError(t, err) require.NotNil(t, bs) } @@ -275,13 +275,13 @@ func TestCreateGrandpaService(t *testing.T) { require.NoError(t, err) ks.Gran.Insert(kr.Alice()) - rt, err := createRuntime(cfg, stateSrvc, ks, &network.Service{}) + err = loadRuntime(cfg, stateSrvc, ks, &network.Service{}) require.NoError(t, err) dh, err := createDigestHandler(stateSrvc) require.NoError(t, err) - gs, err := createGRANDPAService(cfg, rt, stateSrvc, dh, ks.Gran, &network.Service{}) + gs, err := createGRANDPAService(cfg, stateSrvc, dh, ks.Gran, &network.Service{}) require.NoError(t, err) require.NotNil(t, gs) } @@ -327,7 +327,8 @@ func TestNewWebSocketServer(t *testing.T) { ks := keystore.NewGlobalKeystore() ed25519Keyring, _ := keystore.NewEd25519Keyring() ks.Gran.Insert(ed25519Keyring.Alice()) - rt, err := createRuntime(cfg, stateSrvc, ks, networkSrvc) + + err = loadRuntime(cfg, stateSrvc, ks, networkSrvc) require.NoError(t, err) dh, err := createDigestHandler(stateSrvc) @@ -339,7 +340,7 @@ func TestNewWebSocketServer(t *testing.T) { sysSrvc, err := createSystemService(&cfg.System, stateSrvc) require.NoError(t, err) - rpcSrvc := createRPCService(cfg, stateSrvc, coreSrvc, networkSrvc, nil, rt, sysSrvc) + rpcSrvc := createRPCService(cfg, stateSrvc, coreSrvc, networkSrvc, nil, sysSrvc) err = rpcSrvc.Start() require.Nil(t, err) diff --git a/dot/state/block.go b/dot/state/block.go index 10c33225d6..6f18fac1ec 100644 --- a/dot/state/block.go +++ b/dot/state/block.go @@ -34,6 +34,8 @@ import ( "github.com/ChainSafe/gossamer/lib/runtime" rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage" "github.com/ChainSafe/gossamer/lib/runtime/wasmer" + "github.com/ChainSafe/gossamer/lib/scale" + "github.com/ChainSafe/gossamer/lib/transaction" "github.com/ChainSafe/gossamer/lib/utils" ) @@ -45,6 +47,7 @@ const pruneKeyBufferSize = 1000 type BlockState struct { bt *blocktree.BlockTree baseState *BaseState + dbPath string db chaindb.Database sync.RWMutex genesisHash common.Hash @@ -67,6 +70,7 @@ func NewBlockState(db chaindb.Database, bt *blocktree.BlockTree) (*BlockState, e bs := &BlockState{ bt: bt, + dbPath: db.Path(), baseState: NewBaseState(db), db: chaindb.NewTable(db, blockPrefix), imported: make(map[byte]chan<- *types.Block), @@ -188,6 +192,28 @@ func (bs *BlockState) GenesisHash() common.Hash { return bs.genesisHash } +// ValidateTransaction validates transaction +func (bs *BlockState) ValidateTransaction(e types.Extrinsic) (*transaction.Validity, error) { + rt, ok := bs.GetRuntime(nil) + if !ok { + return nil, blocktree.ErrFailedToGetRuntime + } + + ret, err := rt.Exec(runtime.TaggedTransactionQueueValidateTransaction, e) + if err != nil { + return nil, err + } + + if ret[0] != 0 { + return nil, runtime.NewValidateTransactionError(ret) + } + + v := transaction.NewValidity(0, [][]byte{{}}, [][]byte{{}}, 0, false) + _, err = scale.Decode(ret[1:], v) + + return v, err +} + // DeleteBlock deletes all instances of the block and its related data in the database func (bs *BlockState) DeleteBlock(hash common.Hash) error { if has, _ := bs.HasHeader(hash); has { @@ -782,7 +808,7 @@ func (bs *BlockState) HandleRuntimeChanges(newState *rtstorage.TrieState, rt run codeHash := rt.GetCodeHash() if bytes.Equal(codeHash[:], currCodeHash[:]) { - //bs.StoreRuntime(bHash, rt) + bs.StoreRuntime(bHash, rt) return err } @@ -811,7 +837,7 @@ func (bs *BlockState) HandleRuntimeChanges(newState *rtstorage.TrieState, rt run Imports: wasmer.ImportsNodeRuntime, } - localStorage, err := utils.SetupDatabase(filepath.Join(bs.db.Path(), bHash.String(), "local_storage"), true) + localStorage, err := utils.SetupDatabase(filepath.Join(bs.dbPath, bHash.String(), "local_storage"), true) if err != nil { return err } @@ -838,7 +864,7 @@ func (bs *BlockState) HandleRuntimeChanges(newState *rtstorage.TrieState, rt run return nil } -// GetRuntime gets the runtime from block tree for the corresponding block hash. +// GetRuntime gets the runtime for the corresponding block hash. func (bs *BlockState) GetRuntime(hash *common.Hash) (runtime.Instance, bool) { if hash == nil { rt, ok := bs.bt.GetBlockRuntime(bs.BestBlockHash()) @@ -851,7 +877,12 @@ func (bs *BlockState) GetRuntime(hash *common.Hash) (runtime.Instance, bool) { return bs.bt.GetBlockRuntime(*hash) } -// StoreRuntime stores the runtime in blocktree for corresponding block hash. +// StoreRuntime stores the runtime for corresponding block hash. func (bs *BlockState) StoreRuntime(hash common.Hash, rt runtime.Instance) { bs.bt.StoreRuntime(hash, rt) } + +// GetAllBlocks get all the blocks +func (bs *BlockState) GetAllBlocks() []common.Hash { + return bs.bt.GetAllBlocks() +} diff --git a/dot/state/initialize.go b/dot/state/initialize.go index e92632e410..c0af7de590 100644 --- a/dot/state/initialize.go +++ b/dot/state/initialize.go @@ -60,7 +60,7 @@ func (s *Service) Initialise(gen *genesis.Genesis, header *types.Header, t *trie s.Base = NewBaseState(db) - rt, err := s.createGenesisRuntime(t, gen) + rt, err := s.CreateGenesisRuntime(t, gen) if err != nil { return err } @@ -88,8 +88,6 @@ func (s *Service) Initialise(gen *genesis.Genesis, header *types.Header, t *trie return fmt.Errorf("failed to create block state from genesis: %s", err) } - blockState.StoreRuntime(header.Hash(), rt) - // create storage state from genesis trie storageState, err := NewStorageState(db, blockState, t, pruner.Config{}) if err != nil { @@ -183,7 +181,8 @@ func (s *Service) storeInitialValues(data *genesis.Data, header *types.Header, t return nil } -func (s *Service) createGenesisRuntime(t *trie.Trie, gen *genesis.Genesis) (runtime.Instance, error) { +// CreateGenesisRuntime creates runtime instance form genesis +func (s *Service) CreateGenesisRuntime(t *trie.Trie, gen *genesis.Genesis) (runtime.Instance, error) { // load genesis state into database genTrie, err := rtstorage.NewTrieState(t) if err != nil { diff --git a/dot/sync/syncer.go b/dot/sync/syncer.go index c6e3b5cf5b..65bb7fd7a7 100644 --- a/dot/sync/syncer.go +++ b/dot/sync/syncer.go @@ -46,7 +46,6 @@ type Service struct { // Synchronisation variables synced bool highestSeenBlock *big.Int // highest block number we have seen - runtime runtime.Instance // BABE verification verifier Verifier @@ -78,10 +77,6 @@ func NewService(cfg *Config) (*Service, error) { return nil, errNilVerifier } - if cfg.Runtime == nil { - return nil, errNilRuntime - } - if cfg.BlockImportHandler == nil { return nil, errNilBlockImportHandler } @@ -98,7 +93,6 @@ func NewService(cfg *Config) (*Service, error) { synced: true, highestSeenBlock: big.NewInt(0), transactionState: cfg.TransactionState, - runtime: cfg.Runtime, verifier: cfg.Verifier, }, nil } @@ -332,10 +326,16 @@ func (s *Service) handleBlock(block *types.Block) error { panic("parent state root does not match snapshot state root") } - s.runtime.SetContextStorage(ts) + hash := parent.Hash() + rt, ok := s.blockState.GetRuntime(&hash) + if !ok { + return blocktree.ErrFailedToGetRuntime + } + + rt.SetContextStorage(ts) logger.Trace("going to execute block", "header", block.Header, "exts", block.Body) - _, err = s.runtime.ExecuteBlock(block) + _, err = rt.ExecuteBlock(block) if err != nil { return fmt.Errorf("failed to execute block %d: %w", block.Header.Number, err) } diff --git a/dot/sync/syncer_test.go b/dot/sync/syncer_test.go index c7a62163a8..d14fc1231d 100644 --- a/dot/sync/syncer_test.go +++ b/dot/sync/syncer_test.go @@ -61,8 +61,11 @@ func TestHandleBlockResponse(t *testing.T) { parent, err := responder.blockState.(*state.BlockState).BestBlockHeader() require.NoError(t, err) + rt, ok := responder.blockState.GetRuntime(nil) + require.True(t, ok) + for i := 0; i < 130; i++ { - block := BuildBlock(t, responder.runtime, parent, nil) + block := BuildBlock(t, rt, parent, nil) err = responder.blockState.AddBlock(block) require.NoError(t, err) parent = block.Header @@ -98,8 +101,11 @@ func TestHandleBlockResponse_MissingBlocks(t *testing.T) { parent, err := syncer.blockState.(*state.BlockState).BestBlockHeader() require.NoError(t, err) + rt, ok := syncer.blockState.GetRuntime(nil) + require.True(t, ok) + for i := 0; i < 4; i++ { - block := BuildBlock(t, syncer.runtime, parent, nil) + block := BuildBlock(t, rt, parent, nil) err = syncer.blockState.AddBlock(block) require.NoError(t, err) parent = block.Header @@ -110,8 +116,11 @@ func TestHandleBlockResponse_MissingBlocks(t *testing.T) { parent, err = responder.blockState.(*state.BlockState).BestBlockHeader() require.NoError(t, err) + rt, ok = responder.blockState.GetRuntime(nil) + require.True(t, ok) + for i := 0; i < 16; i++ { - block := BuildBlock(t, responder.runtime, parent, nil) + block := BuildBlock(t, rt, parent, nil) err = responder.blockState.AddBlock(block) require.NoError(t, err) parent = block.Header @@ -145,7 +154,8 @@ func TestRemoveIncludedExtrinsics(t *testing.T) { Validity: &transaction.Validity{Priority: 1}, } - syncer.transactionState.(*state.TransactionState).Push(tx) + _, err := syncer.transactionState.(*state.TransactionState).Push(tx) + require.NoError(t, err) exts := []types.Extrinsic{ext} body, err := types.NewBodyFromExtrinsics(exts) @@ -177,7 +187,11 @@ func TestHandleBlockResponse_BlockData(t *testing.T) { parent, err := syncer.blockState.(*state.BlockState).BestBlockHeader() require.NoError(t, err) - block := BuildBlock(t, syncer.runtime, parent, nil) + + rt, ok := syncer.blockState.GetRuntime(nil) + require.True(t, ok) + + block := BuildBlock(t, rt, parent, nil) bd := []*types.BlockData{{ Hash: block.Header.Hash(), @@ -200,14 +214,18 @@ func TestSyncer_ExecuteBlock(t *testing.T) { parent, err := syncer.blockState.(*state.BlockState).BestBlockHeader() require.NoError(t, err) - block := BuildBlock(t, syncer.runtime, parent, nil) + + rt, ok := syncer.blockState.GetRuntime(nil) + require.True(t, ok) + + block := BuildBlock(t, rt, parent, nil) // reset parentState parentState, err := syncer.storageState.TrieState(&parent.StateRoot) require.NoError(t, err) - syncer.runtime.SetContextStorage(parentState) + rt.SetContextStorage(parentState) - _, err = syncer.runtime.ExecuteBlock(block) + _, err = rt.ExecuteBlock(block) require.NoError(t, err) } @@ -241,10 +259,14 @@ func TestSyncer_ProcessJustification(t *testing.T) { parent, err := syncer.blockState.(*state.BlockState).BestBlockHeader() require.NoError(t, err) - block := BuildBlock(t, syncer.runtime, parent, nil) - block.Header.Digest = types.Digest{ - types.NewBabeSecondaryPlainPreDigest(0, 1).ToPreRuntimeDigest(), - } + + rt, ok := syncer.blockState.GetRuntime(nil) + require.True(t, ok) + + block := BuildBlock(t, rt, parent, nil) +block.Header.Digest = types.Digest{ +types.NewBabeSecondaryPlainPreDigest(0, 1).ToPreRuntimeDigest(), +} err = syncer.blockState.(*state.BlockState).AddBlock(block) require.NoError(t, err) diff --git a/dot/sync/test_helpers.go b/dot/sync/test_helpers.go index 4345afcb7f..88ef8345af 100644 --- a/dot/sync/test_helpers.go +++ b/dot/sync/test_helpers.go @@ -97,9 +97,14 @@ func NewTestSyncer(t *testing.T, usePolkadotGenesis bool) *Service { rtCfg.Storage = genState rtCfg.LogLvl = 3 + rtCfg.CodeHash, err = cfg.StorageState.LoadCodeHash(nil) + require.NoError(t, err) + instance, err := wasmer.NewRuntimeFromGenesis(gen, rtCfg) //nolint require.NoError(t, err) cfg.Runtime = instance + + cfg.BlockState.StoreRuntime(cfg.BlockState.BestBlockHash(), instance) } if cfg.TransactionState == nil { diff --git a/go.mod b/go.mod index 01a0602622..8746d205ab 100644 --- a/go.mod +++ b/go.mod @@ -39,8 +39,8 @@ require ( github.com/libp2p/go-libp2p-kad-dht v0.11.1 github.com/libp2p/go-libp2p-peerstore v0.2.7 github.com/libp2p/go-libp2p-secio v0.2.2 - github.com/mattn/go-colorable v0.1.4 // indirect - github.com/mattn/go-isatty v0.0.11 // indirect + github.com/mattn/go-colorable v0.1.8 // indirect + github.com/mattn/go-isatty v0.0.13 // indirect github.com/multiformats/go-multiaddr v0.3.1 github.com/nanobox-io/golang-scribble v0.0.0-20190309225732-aa3e7c118975 github.com/naoina/go-stringutil v0.1.0 // indirect @@ -52,8 +52,9 @@ require ( github.com/urfave/cli v1.20.0 github.com/wasmerio/go-ext-wasm v0.3.2-0.20200326095750-0a32be6068ec golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 - golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect + golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 + golang.org/x/tools v0.1.4 // indirect google.golang.org/appengine v1.6.5 // indirect google.golang.org/protobuf v1.26.0-rc.1 ) diff --git a/go.sum b/go.sum index cbd5a83445..32d702efa7 100644 --- a/go.sum +++ b/go.sum @@ -156,7 +156,6 @@ github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200j github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= @@ -557,13 +556,14 @@ github.com/marten-seemann/qtls-go1-15 v0.1.1/go.mod h1:GyFwywLKkRt+6mfU99csTEY1j github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= -github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA= +github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= @@ -781,6 +781,7 @@ github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7V github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA= @@ -843,8 +844,9 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPI golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -868,6 +870,7 @@ golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6 h1:0PC75Fz/kyMGhL0e1QnypqK2kQMqKt9csD1GnMJR+Zk= golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -906,8 +909,8 @@ golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -917,10 +920,12 @@ golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426080607-c94f62235c83/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 h1:JWgyZ1qgdTaF3N3oxC+MdTV7qvEEgHo3otj+HB5CM7Q= -golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -951,8 +956,9 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/lib/blocktree/blocktree.go b/lib/blocktree/blocktree.go index 75263a060c..99029cf024 100644 --- a/lib/blocktree/blocktree.go +++ b/lib/blocktree/blocktree.go @@ -404,10 +404,12 @@ func (bt *BlockTree) DeepCopy() *BlockTree { return btCopy } +// StoreRuntime stores the runtime for corresponding block hash. func (bt *BlockTree) StoreRuntime(hash common.Hash, in runtime.Instance) { bt.blockRt.Store(hash, in) } +// DeleteRuntime deletes the runtime for corresponding block hash. func (bt *BlockTree) DeleteRuntime(hash common.Hash) { in, ok := bt.GetBlockRuntime(hash) if !ok { @@ -418,6 +420,7 @@ func (bt *BlockTree) DeleteRuntime(hash common.Hash) { bt.blockRt.Delete(hash) } +// GetBlockRuntime returns block runtime for corresponding block hash. func (bt *BlockTree) GetBlockRuntime(hash common.Hash) (runtime.Instance, bool) { ins, ok := bt.blockRt.Load(hash) if !ok { diff --git a/lib/runtime/life/instance.go b/lib/runtime/life/instance.go index 3a95fbaa89..5c14826f40 100644 --- a/lib/runtime/life/instance.go +++ b/lib/runtime/life/instance.go @@ -47,15 +47,14 @@ type Config struct { // Instance represents a v0.8 runtime life instance type Instance struct { - vm *exec.VirtualMachine - mu sync.Mutex - version runtime.Version - isClosed bool - codeHash common.Hash + vm *exec.VirtualMachine + mu sync.Mutex + version runtime.Version } +// GetCodeHash returns code hash of the runtime func (in *Instance) GetCodeHash() common.Hash { - return in.codeHash + return common.Hash{} } // NewRuntimeFromGenesis creates a runtime instance from the genesis data @@ -113,8 +112,7 @@ func NewInstance(code []byte, cfg *Config) (runtime.Instance, error) { logger.Debug("creating new runtime instance", "context", runtimeCtx) inst := &Instance{ - vm: instance, - codeHash: cfg.CodeHash, + vm: instance, } ctx = runtimeCtx diff --git a/lib/runtime/wasmtime/instance.go b/lib/runtime/wasmtime/instance.go index b93faaa809..fa0db3fb36 100644 --- a/lib/runtime/wasmtime/instance.go +++ b/lib/runtime/wasmtime/instance.go @@ -51,14 +51,15 @@ type Config struct { // Instance represents a v0.8 runtime go-wasmtime instance type Instance struct { - vm *wasmtime.Instance - mu sync.Mutex - mem *wasmtime.Memory - isClosed bool - codeHash common.Hash + vm *wasmtime.Instance + mu sync.Mutex + mem *wasmtime.Memory } -func (in *Instance) GetCodeHash() common.Hash { return in.codeHash } +// GetCodeHash ... +func (in *Instance) GetCodeHash() common.Hash { + return common.Hash{} +} // NewInstanceFromFile instantiates a runtime from a .wasm file func NewInstanceFromFile(fp string, cfg *Config) (*Instance, error) { @@ -120,9 +121,8 @@ func newInstanceFromModule(module *wasmtime.Module, engine *wasmtime.Engine, cfg } return &Instance{ - vm: instance, - mem: mem, - codeHash: cfg.CodeHash, + vm: instance, + mem: mem, }, nil } diff --git a/tests/polkadotjs_test/test/node_runtime.compact.wasm b/tests/polkadotjs_test/test/node_runtime.compact.wasm new file mode 100644 index 0000000000..1e9ebe1b03 Binary files /dev/null and b/tests/polkadotjs_test/test/node_runtime.compact.wasm differ