Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib/runtime): avoid caching version in runtime instance #2425

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions lib/runtime/life/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package life

import (
"bytes"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -141,12 +140,6 @@ func (in *Instance) ExecuteBlock(block *types.Block) ([]byte, error) {

// remove seal digest only
for _, d := range block.Header.Digest.Types {
// hack since substrate node_runtime can't seem to handle BABE pre-runtime digests
// with type prefix (ie Primary, Secondary...)
if bytes.Equal(in.version.SpecName(), []byte("node")) {
break
}

switch d.Value().(type) {
case types.SealDigest:
continue
Expand Down
2 changes: 2 additions & 0 deletions lib/runtime/life/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func TestInstance_FinalizeBlock_NodeRuntime(t *testing.T) {
}

func TestInstance_ExecuteBlock_GossamerRuntime(t *testing.T) {
t.Skip("Broken due to outdated runtime")

instance := newInstanceFromGenesis(t)
block := buildBlock(t, instance)

Expand Down
11 changes: 3 additions & 8 deletions lib/runtime/life/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ type Config struct {
Resolver exec.ImportResolver
}

// Instance represents a v0.8 runtime life instance
// Instance is a runtime life instance
type Instance struct {
vm *exec.VirtualMachine
mu sync.Mutex
version runtime.Version
vm *exec.VirtualMachine
mu sync.Mutex
}

// GetCodeHash returns code hash of the runtime
Expand Down Expand Up @@ -123,10 +122,6 @@ func NewInstance(code []byte, cfg *Config) (*Instance, error) {
}

ctx = runtimeCtx
inst.version, err = inst.Version()
if err != nil {
logger.Errorf("error checking instance version: %s", err)
}
return inst, nil
}

Expand Down
12 changes: 0 additions & 12 deletions lib/runtime/wasmer/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ func (in *Instance) ValidateTransaction(e types.Extrinsic) (*transaction.Validit

// Version calls runtime function Core_Version
func (in *Instance) Version() (runtime.Version, error) {
// kusama seems to use the legacy version format
if in.version != nil {
return in.version, nil
}

res, err := in.exec(runtime.CoreVersion, []byte{})
if err != nil {
return nil, err
Expand Down Expand Up @@ -141,13 +136,6 @@ func (in *Instance) ExecuteBlock(block *types.Block) ([]byte, error) {
return nil, err
}

if in.version == nil {
in.version, err = in.Version()
if err != nil {
return nil, err
}
}

b.Header.Digest = types.NewDigest()

// remove seal digest only
Expand Down
8 changes: 3 additions & 5 deletions lib/runtime/wasmer/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,11 +949,9 @@ func ext_misc_runtime_version_version_1(context unsafe.Pointer, dataSpan C.int64
return 0
}

// instance version is set and cached in NewInstance
version := instance.version

if version == nil {
logger.Error("failed to get runtime version")
version, err := instance.Version()
if err != nil {
logger.Errorf("failed to get runtime version: %s", err)
out, _ := toWasmMemoryOptional(instanceContext, nil)
return C.int64_t(out)
}
Expand Down
8 changes: 0 additions & 8 deletions lib/runtime/wasmer/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type Config struct {
type Instance struct {
vm wasm.Instance
ctx *runtime.Context
version runtime.Version
imports func() (*wasm.Imports, error)
isClosed bool
codeHash common.Hash
Expand Down Expand Up @@ -162,7 +161,6 @@ func NewInstance(code []byte, cfg *Config) (*Instance, error) {
codeHash: cfg.CodeHash,
}

inst.version, _ = inst.Version()
return inst, nil
}

Expand Down Expand Up @@ -196,12 +194,6 @@ func (in *Instance) UpdateRuntimeCode(code []byte) error {
return err
}

in.version = nil
in.version, err = in.Version()
if err != nil {
return err
}

return nil
}

Expand Down