Skip to content

Commit

Permalink
fix(wazero): remove panic from offchain submit transaction (#3988)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj authored May 30, 2024
1 parent 1b05ce8 commit ecdac36
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
1 change: 1 addition & 0 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func createRuntime(config *cfg.Config, ns runtime.NodeStorage, st *state.Service
LogLvl: wasmerLogLevel,
NodeStorage: ns,
Network: net,
Transaction: st.Transaction,
Role: config.Core.Role,
CodeHash: codeHash,
}
Expand Down
24 changes: 2 additions & 22 deletions lib/runtime/wazero/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/ChainSafe/gossamer/lib/crypto/secp256k1"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/transaction"
"github.com/ChainSafe/gossamer/pkg/scale"
"github.com/ChainSafe/gossamer/pkg/trie"
inmemory_trie "github.com/ChainSafe/gossamer/pkg/trie/inmemory"
Expand Down Expand Up @@ -1831,32 +1830,13 @@ func ext_offchain_random_seed_version_1(ctx context.Context, m api.Module) uint3
return ptr
}

func ext_offchain_submit_transaction_version_1(ctx context.Context, m api.Module, data uint64) uint64 {
// TODO Investigate via https://github.com/ChainSafe/gossamer/issues/3986
func ext_offchain_submit_transaction_version_1(ctx context.Context, m api.Module, data uint64) uint64 { //nolint
rtCtx := ctx.Value(runtimeContextKey).(*runtime.Context)
if rtCtx == nil {
panic("nil runtime context")
}

extBytes := read(m, data)

var extrinsic []byte
err := scale.Unmarshal(extBytes, &extrinsic)
if err != nil {
logger.Errorf("failed to decode extrinsic data: %s", err)
// Error case
ret, err := write(m, rtCtx.Allocator, []byte{1})
if err != nil {
panic(err)
}
return ret
}

// validate the transaction
txv := transaction.NewValidity(0, [][]byte{{}}, [][]byte{{}}, 0, false)
vtx := transaction.NewValidTransaction(extrinsic, txv)

rtCtx.Transaction.AddToPool(vtx)

// OK case
ret, err := write(m, rtCtx.Allocator, []byte{0})
if err != nil {
Expand Down

0 comments on commit ecdac36

Please sign in to comment.