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

refactor: enable sudo guards and update tests #418

Merged
merged 4 commits into from
Jun 11, 2024
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
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
11 changes: 6 additions & 5 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,16 +80,17 @@ 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 {
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.
8 changes: 8 additions & 0 deletions docs/docs/development/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ permalink: /development/test
Currently, the project contains unit and integration tests. Integration tests use [Gossamer](https://github.com/LimeChain/gossamer), which
imports all the necessary Host functions and interacts with the Runtime.

Before running the tests, make sure to build the runtime with the benchmarking features enabled, as there are some tests that rely on them.

````bash
make build-benchmarking
````

And then run the tests with:

```bash
make test
```
Expand Down
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
11 changes: 5 additions & 6 deletions frame/babe/call_plan_config_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

sc "github.com/LimeChain/goscale"
"github.com/LimeChain/gosemble/frame/support"
"github.com/LimeChain/gosemble/frame/system"
babetypes "github.com/LimeChain/gosemble/primitives/babe"
primitives "github.com/LimeChain/gosemble/primitives/types"
)
Expand Down Expand Up @@ -80,12 +81,10 @@ func (_ callPlanConfigChange) PaysFee(baseWeight primitives.Weight) primitives.P
}

func (c callPlanConfigChange) Dispatch(origin primitives.RuntimeOrigin, args sc.VaryingData) (primitives.PostDispatchInfo, error) {
// TODO: enable once 'sudo' module is implemented
//
// err := EnsureRoot(origin)
// if err != nil {
// return primitives.PostDispatchInfo{}, err
// }
err := system.EnsureRoot(origin)
if err != nil {
return primitives.PostDispatchInfo{}, err
}

config := args[0].(NextConfigDescriptor)

Expand Down
Loading