system

package
v0.0.2-rc-2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorInvalidSpecName sc.U8 = iota
	ErrorSpecVersionNeedsToIncrease
	ErrorFailedToExtractRuntimeVersion
	ErrorNonDefaultComposite
	ErrorNonZeroRefCount
	ErrorCallFiltered
	ErrorNothingAuthorized
	ErrorUnauthorized
)

System module errors.

View Source
const (
	EventExtrinsicSuccess sc.U8 = iota
	EventExtrinsicFailed
	EventCodeUpdated
	EventNewAccount
	EventKilledAccount
	EventRemarked
	EventUpgradeAuthorized
)

System module events.

Variables

This section is empty.

Functions

func DecodeEvent

func DecodeEvent(moduleIndex sc.U8, buffer *bytes.Buffer) (types.Event, error)

func EnsureRoot

func EnsureRoot(origin primitives.RuntimeOrigin) error

EnsureRoot ensures that the origin represents the root.

func EnsureSigned

func EnsureSigned(origin primitives.RawOrigin) (sc.Option[primitives.AccountId], error)

EnsureSigned ensures that the origin represents a signed extrinsic (i.e. transaction). Returns `Ok` with the account that signed the extrinsic or an `Err` otherwise.

func EnsureSignedOrRoot

func EnsureSignedOrRoot(origin primitives.RawOrigin) (sc.Option[primitives.AccountId], error)

EnsureSignedOrRoot ensures the origin represents either a signed extrinsic or the root. Returns an empty Option if the origin is `Root`. Returns an Option with the signer if the origin is signed. Returns a `BadOrigin` error if neither of the above.

func MaxWithNormalRatio

func MaxWithNormalRatio(max sc.U32, normal types.Perbill) (types.BlockLength, error)

MaxWithNormalRatio Create new `BlockLength` with `max` for `Operational` & `Mandatory` and `normal * max` for `Normal`.

func NewDefaultOnSetCode

func NewDefaultOnSetCode(module Module) defaultOnSetCode

func NewDispatchErrorCallFiltered

func NewDispatchErrorCallFiltered(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorFailedToExtractRuntimeVersion

func NewDispatchErrorFailedToExtractRuntimeVersion(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorInvalidSpecName

func NewDispatchErrorInvalidSpecName(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorNonDefaultComposite

func NewDispatchErrorNonDefaultComposite(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorNonZeroRefCount

func NewDispatchErrorNonZeroRefCount(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorNothingAuthorized

func NewDispatchErrorNothingAuthorized(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorSpecVersionNeedsToIncrease

func NewDispatchErrorSpecVersionNeedsToIncrease(moduleId sc.U8) primitives.DispatchError

func NewDispatchErrorUnauthorized

func NewDispatchErrorUnauthorized(moduleId sc.U8) primitives.DispatchError

func WithSensibleDefaults

func WithSensibleDefaults(expectedBlockWeight types.Weight, normalRatio types.Perbill) (types.BlockWeights, error)

WithSensibleDefaults Create a sensible default weights system given only expected maximal block weight and the ratio that `Normal` extrinsics should occupy.

Assumptions:

  • Average block initialization is assumed to be `10%`.
  • `Operational` transactions have reserved allowance (`1.0 - normal_ratio`)

Types

type BlockWeightsBuilder

type BlockWeightsBuilder struct {
	Weights  types.BlockWeights
	InitCost sc.Option[types.Perbill]
}

An opinionated builder for `Weights` object.

func NewBlockWeightsBuilder

func NewBlockWeightsBuilder() *BlockWeightsBuilder

Start constructing new `BlockWeights` object.

By default all kinds except of `Mandatory` extrinsics are disallowed.

func (*BlockWeightsBuilder) AvgBlockInitialization

func (b *BlockWeightsBuilder) AvgBlockInitialization(initCost types.Perbill) *BlockWeightsBuilder

AvgBlockInitialization Average block initial ization weight cost.

This value is used to derive maximal allowed extrinsic weight for each class, based on the allowance.

This is to make sure that extrinsics don't stay forever in the pool, because they could seamingly fit the block (since they are below `max_block`), but the cost of calling `on_initialize` always prevents them from being included.

func (*BlockWeightsBuilder) BaseBlock

func (b *BlockWeightsBuilder) BaseBlock(baseBlock types.Weight) *BlockWeightsBuilder

Set base block weight.

func (*BlockWeightsBuilder) Build

Construct the `BlockWeights` object.

func (*BlockWeightsBuilder) ForClass

func (b *BlockWeightsBuilder) ForClass(classes []types.DispatchClass, action func(_ *types.WeightsPerClass)) (*BlockWeightsBuilder, error)

ForClass Set parameters for particular class.

Note: `None` values of `max_extrinsic` will be overwritten in `build` in case `avg_block_initialization` rate is set to a non-zero value.

type CodeUpgradeAuthorization

type CodeUpgradeAuthorization struct {
	// Hash of the new runtime binary.
	CodeHash primitives.H256
	// Whether or not to carry out version checks.
	CheckVersion sc.Bool
}

Information needed when a new runtime binary is submitted and needs to be authorized before replacing the current runtime.

func DecodeCodeUpgradeAuthorization

func DecodeCodeUpgradeAuthorization(buffer *bytes.Buffer) (CodeUpgradeAuthorization, error)

func (CodeUpgradeAuthorization) Bytes

func (c CodeUpgradeAuthorization) Bytes() []byte

func (CodeUpgradeAuthorization) Encode

func (c CodeUpgradeAuthorization) Encode(buffer *bytes.Buffer) error

type CodeUpgrader

type CodeUpgrader interface {
	CanSetCode(codeBlob sc.Sequence[sc.U8]) error
	DoAuthorizeUpgrade(codeHash primitives.H256, checkVersion sc.Bool)
	DoApplyAuthorizeUpgrade(codeBlob sc.Sequence[sc.U8]) (primitives.PostDispatchInfo, error)
}

type Config

type Config struct {
	BlockHashCount types.BlockHashCount
	BlockWeights   types.BlockWeights
	BlockLength    types.BlockLength
	DbWeight       types.RuntimeDbWeight
	Version        *types.RuntimeVersion
	MaxConsumers   sc.U32
}

func NewConfig

func NewConfig(
	blockHashCount types.BlockHashCount,
	blockWeights types.BlockWeights,
	blockLength types.BlockLength,
	dbWeight types.RuntimeDbWeight,
	version *types.RuntimeVersion,
	maxConsumers sc.U32,
) *Config

type GenesisConfig

type GenesisConfig struct{}

type KeyValue

type KeyValue struct {
	Key   sc.Sequence[sc.U8]
	Value sc.Sequence[sc.U8]
}

func DecodeKeyValue

func DecodeKeyValue(buffer *bytes.Buffer) (KeyValue, error)

func (KeyValue) Bytes

func (pair KeyValue) Bytes() []byte

func (KeyValue) Encode

func (pair KeyValue) Encode(buffer *bytes.Buffer) error

type LogDepositor

type LogDepositor interface {
	DepositLog(item primitives.DigestItem)
}

type Module

type Module interface {
	primitives.Module

	CodeUpgrader
	LogDepositor
	primitives.EventDepositor

	Initialize(blockNumber sc.U64, parentHash primitives.Blake2bHash, digest primitives.Digest)
	RegisterExtraWeightUnchecked(weight primitives.Weight, class primitives.DispatchClass) error
	NoteFinishedInitialize()
	NoteExtrinsic(encodedExt []byte) error
	NoteAppliedExtrinsic(postInfo primitives.PostDispatchInfo, postDispatchErr error, info primitives.DispatchInfo) error
	Finalize() (primitives.Header, error)
	NoteFinishedExtrinsics() error
	ResetEvents()
	Get(key primitives.AccountId) (primitives.AccountInfo, error)
	CanDecProviders(who primitives.AccountId) (bool, error)
	CanIncConsumer(who primitives.AccountId) (bool, error)
	DecConsumers(who primitives.AccountId) error
	IncConsumers(who primitives.AccountId) error
	IncConsumersWithoutLimit(who primitives.AccountId) error
	IncProviders(who primitives.AccountId) (primitives.IncRefStatus, error)

	TryMutateExists(who primitives.AccountId, f func(who *primitives.AccountData) (sc.Encodable, error)) (sc.Encodable, error)
	Metadata() primitives.MetadataModule

	BlockHashCount() types.BlockHashCount
	BlockLength() types.BlockLength
	BlockWeights() types.BlockWeights
	DbWeight() types.RuntimeDbWeight
	Version() types.RuntimeVersion

	StorageDigest() (types.Digest, error)

	StorageBlockWeight() (primitives.ConsumedWeight, error)
	StorageBlockWeightSet(weight primitives.ConsumedWeight)

	StorageBlockHash(key sc.U64) (types.Blake2bHash, error)
	StorageBlockHashSet(key sc.U64, value types.Blake2bHash)
	StorageBlockHashExists(key sc.U64) bool

	StorageBlockNumber() (sc.U64, error)
	StorageBlockNumberSet(sc.U64)

	StorageLastRuntimeUpgrade() (types.LastRuntimeUpgradeInfo, error)
	StorageLastRuntimeUpgradeSet(lrui types.LastRuntimeUpgradeInfo)

	StorageAccount(key types.AccountId) (types.AccountInfo, error)
	StorageAccountSet(key types.AccountId, value types.AccountInfo)

	StorageAllExtrinsicsLen() (sc.U32, error)
	StorageAllExtrinsicsLenSet(value sc.U32)

	StorageCodeSet(codeBlob sc.Sequence[sc.U8])
}

func New

func New(index sc.U8, config *Config, mdGenerator *primitives.MetadataTypeGenerator, logger log.Logger) Module

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL