Skip to content

Commit

Permalink
fix execute block logic; fix transaction validity error; refactor logger
Browse files Browse the repository at this point in the history
  • Loading branch information
radkomih committed Jun 11, 2024
1 parent 4796de4 commit 6fb6146
Show file tree
Hide file tree
Showing 45 changed files with 202 additions and 225 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ substrate-start-bob:
--rpc-port 9946 \
--validator

start-network-aura:
cd ../../../..; \
WASMTIME_BACKTRACE_DETAILS=1 RUST_LOG=runtime=trace ./target/release/node-template --dev --execution=wasm

start-network-babe:
cd polkadot-sdk/substrate/bin/node/cli; \
cargo build --release; \
Expand Down
4 changes: 2 additions & 2 deletions api/account_nonce/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const (
type Module struct {
systemModule system.Module
memUtils utils.WasmMemoryTranslator
logger log.Logger
logger log.RuntimeLogger
}

func New(systemModule system.Module, logger log.Logger) Module {
func New(systemModule system.Module, logger log.RuntimeLogger) Module {
return Module{
systemModule: systemModule,
memUtils: utils.NewMemoryTranslator(),
Expand Down
4 changes: 2 additions & 2 deletions api/aura/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const (
type Module struct {
aura aura.AuraModule
memUtils utils.WasmMemoryTranslator
logger log.Logger
logger log.RuntimeLogger
}

func New(aura aura.AuraModule, logger log.Logger) Module {
func New(aura aura.AuraModule, logger log.RuntimeLogger) Module {
return Module{
aura: aura,
memUtils: utils.NewMemoryTranslator(),
Expand Down
4 changes: 2 additions & 2 deletions api/babe/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const (
type Module struct {
babe babe.Module
memUtils utils.WasmMemoryTranslator
logger log.Logger
logger log.RuntimeLogger
}

func New(babe babe.Module, logger log.Logger) Module {
func New(babe babe.Module, logger log.RuntimeLogger) Module {
return Module{
babe: babe,
memUtils: utils.NewMemoryTranslator(),
Expand Down
7 changes: 4 additions & 3 deletions api/benchmarking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package benchmarking

import (
"bytes"

sc "github.com/LimeChain/goscale"
"github.com/LimeChain/gosemble/execution/types"
"github.com/LimeChain/gosemble/frame/support"
Expand All @@ -24,10 +25,10 @@ type Module struct {
decoder types.RuntimeDecoder
memUtils utils.WasmMemoryTranslator
hashing io.Hashing
logger log.Logger
logger log.RuntimeLogger
}

func New(systemIndex sc.U8, modules []primitives.Module, decoder types.RuntimeDecoder, logger log.Logger) Module {
func New(systemIndex sc.U8, modules []primitives.Module, decoder types.RuntimeDecoder, logger log.RuntimeLogger) Module {
systemModule := primitives.MustGetModule(systemIndex, modules).(system.Module)

return Module{
Expand Down Expand Up @@ -161,7 +162,7 @@ func (m Module) BenchmarkHook(dataPtr int32, dataLen int32) int64 {
return m.memUtils.BytesToOffsetAndSize(benchmarkResult.Bytes())
}

func measureHooks(modules []primitives.Module, hookFn func(module primitives.DispatchModule) error, logger log.Logger) float64 {
func measureHooks(modules []primitives.Module, hookFn func(module primitives.DispatchModule) error, logger log.RuntimeLogger) float64 {
var start, end int64

for _, module := range modules {
Expand Down
14 changes: 7 additions & 7 deletions api/block_builder/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ type Module struct {
decoder types.RuntimeDecoder
memUtils utils.WasmMemoryTranslator
mdGenerator *primitives.MetadataTypeGenerator
logger log.Logger
logger log.RuntimeLogger
}

func New(runtimeExtrinsic extrinsic.RuntimeExtrinsic, executive executive.Module, decoder types.RuntimeDecoder, mdGenerator *primitives.MetadataTypeGenerator, logger log.Logger) Module {
func New(runtimeExtrinsic extrinsic.RuntimeExtrinsic, executive executive.Module, decoder types.RuntimeDecoder, mdGenerator *primitives.MetadataTypeGenerator, logger log.RuntimeLogger) Module {
return Module{
runtimeExtrinsic: runtimeExtrinsic,
executive: executive,
Expand Down Expand Up @@ -80,18 +80,18 @@ func (m Module) ApplyExtrinsic(dataPtr int32, dataLen int32) int64 {
}

err = m.executive.ApplyExtrinsic(uxt)

var applyExtrinsicResult primitives.ApplyExtrinsicResult
switch typedErr := err.(type) {
case nil:
dispatchOutcome := primitives.DispatchOutcome(sc.NewVaryingData(sc.Empty{}))
applyExtrinsicResult, err = primitives.NewApplyExtrinsicResult(dispatchOutcome)
case primitives.TransactionValidityError:
applyExtrinsicResult, err = primitives.NewApplyExtrinsicResult(typedErr)
case primitives.DispatchError:
dispatchOutcome := primitives.DispatchOutcome(sc.NewVaryingData(typedErr))
applyExtrinsicResult, err = primitives.NewApplyExtrinsicResult(dispatchOutcome)
case nil:
dispatchOutcome := primitives.DispatchOutcome(sc.NewVaryingData(sc.Empty{}))
applyExtrinsicResult, err = primitives.NewApplyExtrinsicResult(dispatchOutcome)
}
if err != nil {
default:
m.logger.Critical(err.Error())
}

Expand Down
4 changes: 2 additions & 2 deletions api/core/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ type Module struct {
runtimeVersion *primitives.RuntimeVersion
memUtils utils.WasmMemoryTranslator
mdGenerator *primitives.MetadataTypeGenerator
logger log.Logger
logger log.RuntimeLogger
}

func New(module executive.Module, decoder types.RuntimeDecoder, runtimeVersion *primitives.RuntimeVersion, mdGenerator *primitives.MetadataTypeGenerator, logger log.Logger) Module {
func New(module executive.Module, decoder types.RuntimeDecoder, runtimeVersion *primitives.RuntimeVersion, mdGenerator *primitives.MetadataTypeGenerator, logger log.RuntimeLogger) Module {
return Module{
executive: module,
decoder: decoder,
Expand Down
4 changes: 2 additions & 2 deletions api/genesis_builder/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ type GenesisBuilder interface {
type Module struct {
modules []primitives.Module
memUtils utils.WasmMemoryTranslator
logger log.Logger
logger log.RuntimeLogger
}

func New(modules []primitives.Module, logger log.Logger) Module {
func New(modules []primitives.Module, logger log.RuntimeLogger) Module {
return Module{
modules: modules,
memUtils: utils.NewMemoryTranslator(),
Expand Down
4 changes: 2 additions & 2 deletions api/grandpa/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const (
type Module struct {
grandpa grandpa.Module
memUtils utils.WasmMemoryTranslator
logger log.Logger
logger log.RuntimeLogger
}

func New(grandpa grandpa.Module, logger log.Logger) Module {
func New(grandpa grandpa.Module, logger log.RuntimeLogger) Module {
return Module{
grandpa: grandpa,
memUtils: utils.NewMemoryTranslator(),
Expand Down
4 changes: 2 additions & 2 deletions api/metadata/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ type Module struct {
runtimeExtrinsic extrinsic.RuntimeExtrinsic
memUtils utils.WasmMemoryTranslator
generator *primitives.MetadataTypeGenerator
logger log.Logger
logger log.RuntimeLogger
}

func New(runtimeExtrinsic extrinsic.RuntimeExtrinsic, runtimeApiModules []primitives.RuntimeApiModule, logger log.Logger, generator *primitives.MetadataTypeGenerator) Module {
func New(runtimeExtrinsic extrinsic.RuntimeExtrinsic, runtimeApiModules []primitives.RuntimeApiModule, logger log.RuntimeLogger, generator *primitives.MetadataTypeGenerator) Module {
return Module{
runtimeApiModules: runtimeApiModules,
runtimeExtrinsic: runtimeExtrinsic,
Expand Down
4 changes: 2 additions & 2 deletions api/offchain_worker/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const (
type Module struct {
executive executive.Module
memUtils utils.WasmMemoryTranslator
logger log.Logger
logger log.RuntimeLogger
}

func New(executive executive.Module, logger log.Logger) Module {
func New(executive executive.Module, logger log.RuntimeLogger) Module {
return Module{
executive: executive,
memUtils: utils.NewMemoryTranslator(),
Expand Down
4 changes: 2 additions & 2 deletions api/session_keys/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type Module struct {
sessions []types.Session
crypto io.Crypto
memUtils utils.WasmMemoryTranslator
logger log.Logger
logger log.RuntimeLogger
}

func New(sessions []types.Session, logger log.Logger) Module {
func New(sessions []types.Session, logger log.RuntimeLogger) Module {
return Module{
sessions: sessions,
crypto: io.NewCrypto(),
Expand Down
4 changes: 2 additions & 2 deletions api/tagged_transaction_queue/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ type Module struct {
decoder types.RuntimeDecoder
memUtils utils.WasmMemoryTranslator
mdGenerator *primitives.MetadataTypeGenerator
logger log.Logger
logger log.RuntimeLogger
}

func New(executive executive.Module, decoder types.RuntimeDecoder, mdGenerator *primitives.MetadataTypeGenerator, logger log.Logger) Module {
func New(executive executive.Module, decoder types.RuntimeDecoder, mdGenerator *primitives.MetadataTypeGenerator, logger log.RuntimeLogger) Module {
return Module{
executive: executive,
decoder: decoder,
Expand Down
4 changes: 2 additions & 2 deletions api/transaction_payment/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type Module struct {
decoder types.RuntimeDecoder
txPayments transaction_payment.Module
memUtils utils.WasmMemoryTranslator
logger log.Logger
logger log.RuntimeLogger
}

func New(decoder types.RuntimeDecoder, txPayments transaction_payment.Module, logger log.Logger) Module {
func New(decoder types.RuntimeDecoder, txPayments transaction_payment.Module, logger log.RuntimeLogger) Module {
return Module{
decoder: decoder,
txPayments: txPayments,
Expand Down
4 changes: 2 additions & 2 deletions api/transaction_payment_call/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type Module struct {
decoder types.RuntimeDecoder
txPayments transaction_payment.Module
memUtils utils.WasmMemoryTranslator
logger log.Logger
logger log.RuntimeLogger
}

func New(decoder types.RuntimeDecoder, txPayments transaction_payment.Module, logger log.Logger) Module {
func New(decoder types.RuntimeDecoder, txPayments transaction_payment.Module, logger log.RuntimeLogger) Module {
return Module{
decoder: decoder,
txPayments: txPayments,
Expand Down
Binary file modified build/runtime-benchmarks.wasm
Binary file not shown.
Binary file modified build/runtime.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions execution/extrinsic/runtime_extrinsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type runtimeExtrinsic struct {
modules []primitives.Module
extra primitives.SignedExtra
mdGenerator *primitives.MetadataTypeGenerator
logger log.DebugLogger
logger log.RuntimeLogger
}

func New(modules []primitives.Module, extra primitives.SignedExtra, mdGenerator *primitives.MetadataTypeGenerator, logger log.DebugLogger) RuntimeExtrinsic {
func New(modules []primitives.Module, extra primitives.SignedExtra, mdGenerator *primitives.MetadataTypeGenerator, logger log.RuntimeLogger) RuntimeExtrinsic {
return runtimeExtrinsic{
modules: modules,
extra: extra,
Expand Down
4 changes: 2 additions & 2 deletions execution/types/checked_extrinsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type checkedExtrinsic struct {
transactional support.Transactional[primitives.PostDispatchInfo]
}

func NewCheckedExtrinsic(signer sc.Option[primitives.AccountId], function primitives.Call, extra primitives.SignedExtra, logger log.WarnLogger) primitives.CheckedExtrinsic {
func NewCheckedExtrinsic(signer sc.Option[primitives.AccountId], function primitives.Call, extra primitives.SignedExtra, logger log.RuntimeLogger) primitives.CheckedExtrinsic {
return checkedExtrinsic{
signer: signer,
function: function,
Expand Down Expand Up @@ -67,12 +67,12 @@ func (c checkedExtrinsic) Apply(validator primitives.UnsignedValidator, info *pr
maybeWho, maybePre = sc.NewOption[primitives.AccountId](nil), sc.NewOption[sc.Sequence[primitives.Pre]](nil)
}

// TODO: revise if the error handling is correct
postInfo, err := c.transactional.WithStorageLayer(
func() (primitives.PostDispatchInfo, error) {
return c.dispatch(maybeWho)
},
)
// TODO: handle error

if err := c.extra.PostDispatch(maybePre, info, &postInfo, length, err); err != nil {
return primitives.PostDispatchInfo{}, err
Expand Down
4 changes: 2 additions & 2 deletions execution/types/runtime_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

type RuntimeApi struct {
apis []primitives.ApiModule
logger log.Logger
logger log.RuntimeLogger
}

func NewRuntimeApi(apis []primitives.ApiModule, logger log.Logger) RuntimeApi {
func NewRuntimeApi(apis []primitives.ApiModule, logger log.RuntimeLogger) RuntimeApi {
return RuntimeApi{apis: apis, logger: logger}
}

Expand Down
2 changes: 2 additions & 0 deletions execution/types/runtime_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ var (

func Test_RuntimeApi_New(t *testing.T) {
target := setupRuntimeApi()

expect := RuntimeApi{
apis: []primitives.ApiModule{
mockApiModuleOne,
mockApiModuleTwo,
},
logger: logger,
}

assert.Equal(t, expect, target)
Expand Down
5 changes: 3 additions & 2 deletions execution/types/runtime_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"

sc "github.com/LimeChain/goscale"
"github.com/LimeChain/gosemble/primitives/log"
"github.com/LimeChain/gosemble/primitives/types"
Expand All @@ -29,10 +30,10 @@ type runtimeDecoder struct {
modules []types.Module
extra primitives.SignedExtra
sudoIndex sc.U8 // Used for additional decoding related to Sudo calls. Default is 0 and not considered a valid sudo index.
logger log.WarnLogger
logger log.RuntimeLogger
}

func NewRuntimeDecoder(modules []types.Module, extra primitives.SignedExtra, sudoIndex sc.U8, logger log.WarnLogger) RuntimeDecoder {
func NewRuntimeDecoder(modules []types.Module, extra primitives.SignedExtra, sudoIndex sc.U8, logger log.RuntimeLogger) RuntimeDecoder {
return runtimeDecoder{
modules: modules,
extra: extra,
Expand Down
4 changes: 2 additions & 2 deletions execution/types/unchecked_extrinsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ type uncheckedExtrinsic struct {
initializePayload PayloadInitializer
crypto io.Crypto
hashing io.Hashing
logger log.WarnLogger
logger log.RuntimeLogger
}

// NewUncheckedExtrinsic returns a new instance of an unchecked extrinsic.
func NewUncheckedExtrinsic(version sc.U8, signature sc.Option[primitives.ExtrinsicSignature], function primitives.Call, extra primitives.SignedExtra, logger log.WarnLogger) primitives.UncheckedExtrinsic {
func NewUncheckedExtrinsic(version sc.U8, signature sc.Option[primitives.ExtrinsicSignature], function primitives.Call, extra primitives.SignedExtra, logger log.RuntimeLogger) primitives.UncheckedExtrinsic {
return uncheckedExtrinsic{
version: version,
signature: signature,
Expand Down
4 changes: 2 additions & 2 deletions frame/aura/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ type Module struct {
mdGenerator *primitives.MetadataTypeGenerator
logDepositor system.LogDepositor
disabledValidators primitives.DisabledValidators
logger log.Logger
logger log.RuntimeLogger
}

func New(index sc.U8, config *Config, mdGenerator *primitives.MetadataTypeGenerator, logger log.Logger) Module {
func New(index sc.U8, config *Config, mdGenerator *primitives.MetadataTypeGenerator, logger log.RuntimeLogger) Module {
storage := newStorage()

return Module{
Expand Down
4 changes: 2 additions & 2 deletions frame/authorship/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type module struct {
functions map[sc.U8]primitives.Call
systemModule system.Module
mdGenerator *primitives.MetadataTypeGenerator
logger log.Logger
logger log.RuntimeLogger
}

func New(index sc.U8, config *Config, mdGenerator *primitives.MetadataTypeGenerator, logger log.Logger) Module {
func New(index sc.U8, config *Config, mdGenerator *primitives.MetadataTypeGenerator, logger log.RuntimeLogger) Module {
storage := newStorage()

return module{
Expand Down
4 changes: 2 additions & 2 deletions frame/babe/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ type module struct {
constants *consts
functions map[sc.U8]primitives.Call
storage *storage
logger log.Logger
logger log.RuntimeLogger
systemModule system.Module
disabledValidators primitives.DisabledValidators
epochChangeTrigger EpochChangeTrigger
ioHashing io.Hashing
mdGenerator *primitives.MetadataTypeGenerator
}

func New(index sc.U8, config *Config, mdGenerator *primitives.MetadataTypeGenerator, logger log.Logger) Module {
func New(index sc.U8, config *Config, mdGenerator *primitives.MetadataTypeGenerator, logger log.RuntimeLogger) Module {
storage := newStorage()

functions := map[sc.U8]primitives.Call{
Expand Down
4 changes: 2 additions & 2 deletions frame/balances/call_force_free.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
type callForceFree struct {
primitives.Callable
transfer
logger log.DebugLogger
logger log.RuntimeLogger
}

func newCallForceFree(moduleId sc.U8, functionId sc.U8, storedMap primitives.StoredMap, constants *consts, mutator accountMutator, logger log.DebugLogger) primitives.Call {
func newCallForceFree(moduleId sc.U8, functionId sc.U8, storedMap primitives.StoredMap, constants *consts, mutator accountMutator, logger log.RuntimeLogger) primitives.Call {
call := callForceFree{
Callable: primitives.Callable{
ModuleId: moduleId,
Expand Down
Loading

0 comments on commit 6fb6146

Please sign in to comment.