core

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: LGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilRuntime = errors.New("cannot have nil runtime")

	ErrNilBlockHandlerParameter = errors.New("unable to handle block due to nil parameter")

	// ErrEmptyRuntimeCode is returned when the storage :code is empty
	ErrEmptyRuntimeCode = errors.New("new :code is empty")
)

Functions

This section is empty.

Types

type BlockState

type BlockState interface {
	BestBlockHash() common.Hash
	BestBlockHeader() (*types.Header, error)
	BestBlockNumber() (blockNumber uint, err error)
	BestBlockStateRoot() (common.Hash, error)
	BestBlock() (*types.Block, error)
	AddBlock(*types.Block) error
	GetAllBlocksAtDepth(hash common.Hash) []common.Hash
	GetBlockByHash(common.Hash) (*types.Block, error)
	GetBlockStateRoot(bhash common.Hash) (common.Hash, error)
	GenesisHash() common.Hash
	GetSlotForBlock(common.Hash) (uint64, error)
	GetFinalisedHeader(uint64, uint64) (*types.Header, error)
	GetFinalisedHash(uint64, uint64) (common.Hash, error)
	GetImportedBlockNotifierChannel() chan *types.Block
	FreeImportedBlockNotifierChannel(ch chan *types.Block)
	GetFinalisedNotifierChannel() chan *types.FinalisationInfo
	FreeFinalisedNotifierChannel(ch chan *types.FinalisationInfo)
	SubChain(start, end common.Hash) ([]common.Hash, error)
	GetBlockBody(hash common.Hash) (*types.Body, error)
	HandleRuntimeChanges(newState *rtstorage.TrieState, in runtime.Instance, bHash common.Hash) error
	GetRuntime(blockHash common.Hash) (instance runtime.Instance, err error)
	StoreRuntime(common.Hash, runtime.Instance)
	LowestCommonAncestor(a, b common.Hash) (common.Hash, error)
}

BlockState interface for block state methods

type CodeSubstitutedState added in v0.7.0

type CodeSubstitutedState interface {
	LoadCodeSubstitutedBlockHash() common.Hash
	StoreCodeSubstitutedBlockHash(hash common.Hash) error
}

CodeSubstitutedState interface to handle storage of code substitute state

type Config

type Config struct {
	LogLvl log.Level

	BlockState       BlockState
	EpochState       EpochState
	StorageState     StorageState
	TransactionState TransactionState
	Network          Network
	Keystore         *keystore.GlobalKeystore
	Runtime          RuntimeInstance

	CodeSubstitutes      map[common.Hash]string
	CodeSubstitutedState CodeSubstitutedState
}

Config holds the configuration for the core Service.

type EpochState added in v0.3.0

type EpochState interface {
	GetEpochForBlock(header *types.Header) (uint64, error)
	SetCurrentEpoch(epoch uint64) error
	GetCurrentEpoch() (uint64, error)
}

EpochState is the interface for state.EpochState

type Network added in v0.2.0

type Network interface {
	GossipMessage(network.NotificationsMessage)
	IsSynced() bool
	ReportPeer(change peerset.ReputationChange, p peer.ID)
}

Network is the interface for the network service

type QueryKeyValueChanges added in v0.7.0

type QueryKeyValueChanges map[string]string

QueryKeyValueChanges represents the key-value data inside a block storage

type RuntimeInstance added in v0.7.0

type RuntimeInstance interface {
	UpdateRuntimeCode([]byte) error
	Stop()
	NodeStorage() runtime.NodeStorage
	NetworkService() runtime.BasicNetwork
	Keystore() *keystore.GlobalKeystore
	Validator() bool
	Exec(function string, data []byte) ([]byte, error)
	SetContextStorage(s runtime.Storage)
	GetCodeHash() common.Hash
	Version() (version runtime.Version)
	Metadata() ([]byte, error)
	BabeConfiguration() (*types.BabeConfiguration, error)
	GrandpaAuthorities() ([]types.Authority, error)
	ValidateTransaction(e types.Extrinsic) (*transaction.Validity, error)
	InitializeBlock(header *types.Header) error
	InherentExtrinsics(data []byte) ([]byte, error)
	ApplyExtrinsic(data types.Extrinsic) ([]byte, error)
	FinalizeBlock() (*types.Header, error)
	ExecuteBlock(block *types.Block) ([]byte, error)
	DecodeSessionKeys(enc []byte) ([]byte, error)
	PaymentQueryInfo(ext []byte) (*types.RuntimeDispatchInfo, error)
	CheckInherents()
	RandomSeed()
	OffchainWorker()
	GenerateSessionKeys()
}

RuntimeInstance for runtime methods

type Service

type Service struct {
	sync.Mutex // lock for channel
	// contains filtered or unexported fields
}

Service is an overhead layer that allows communication between the runtime, BABE session, and network service. It deals with the validation of transactions and blocks by calling their respective validation functions in the runtime.

func NewService

func NewService(cfg *Config) (*Service, error)

NewService returns a new core service that connects the runtime, BABE session, and network service.

func (*Service) DecodeSessionKeys added in v0.7.0

func (s *Service) DecodeSessionKeys(enc []byte) ([]byte, error)

DecodeSessionKeys executes the runtime DecodeSessionKeys and return the scale encoded keys

func (*Service) GetMetadata

func (s *Service) GetMetadata(bhash *common.Hash) (metadata []byte, err error)

GetMetadata calls runtime Metadata_metadata function

func (*Service) GetReadProofAt added in v0.7.0

func (s *Service) GetReadProofAt(block common.Hash, keys [][]byte) (
	hash common.Hash, proofForKeys [][]byte, err error)

GetReadProofAt will return an array with the proofs for the keys passed as params based on the block hash passed as param as well, if block hash is nil then the current state will take place

func (*Service) GetRuntimeVersion

func (s *Service) GetRuntimeVersion(bhash *common.Hash) (
	version runtime.Version, err error)

GetRuntimeVersion gets the current RuntimeVersion

func (*Service) HandleBlockImport added in v0.7.0

func (s *Service) HandleBlockImport(block *types.Block, state *rtstorage.TrieState, announce bool) error

HandleBlockImport handles a block that was imported via the network

func (*Service) HandleBlockProduced added in v0.7.0

func (s *Service) HandleBlockProduced(block *types.Block, state *rtstorage.TrieState) error

HandleBlockProduced handles a block that was produced by us It is handled the same as an imported block in terms of state updates; the only difference is we send a BlockAnnounceMessage to our peers.

func (*Service) HandleSubmittedExtrinsic

func (s *Service) HandleSubmittedExtrinsic(ext types.Extrinsic) error

HandleSubmittedExtrinsic is used to send a Transaction message containing a Extrinsic @ext

func (*Service) HandleTransactionMessage added in v0.3.0

func (s *Service) HandleTransactionMessage(peerID peer.ID, msg *network.TransactionMessage) (bool, error)

HandleTransactionMessage validates each transaction in the message and adds valid transactions to the transaction queue of the BABE session returns boolean for transaction propagation, true - transactions should be propagated

func (*Service) HasKey

func (s *Service) HasKey(pubKeyStr, keystoreType string) (bool, error)

HasKey returns true if given hex encoded public key string is found in keystore, false otherwise, error if there are issues decoding string

func (*Service) InsertKey

func (s *Service) InsertKey(kp crypto.Keypair, keystoreType string) error

InsertKey inserts keypair into the account keystore

func (*Service) Start

func (s *Service) Start() error

Start starts the core service

func (*Service) Stop

func (s *Service) Stop() error

Stop stops the core service

func (*Service) StorageRoot

func (s *Service) StorageRoot() (common.Hash, error)

StorageRoot returns the hash of the storage root

func (*Service) TransactionsCount added in v0.7.0

func (s *Service) TransactionsCount() int

TransactionsCount returns number for pending transactions in pool

type StorageState

type StorageState interface {
	LoadCode(root *common.Hash) ([]byte, error)
	LoadCodeHash(root *common.Hash) (common.Hash, error)
	TrieState(root *common.Hash) (*rtstorage.TrieState, error)
	StoreTrie(*rtstorage.TrieState, *types.Header) error
	GetStateRootFromBlock(bhash *common.Hash) (*common.Hash, error)
	GetStorage(root *common.Hash, key []byte) ([]byte, error)
	GenerateTrieProof(stateRoot common.Hash, keys [][]byte) ([][]byte, error)
	sync.Locker
}

StorageState interface for storage state methods

type TransactionState added in v0.2.0

type TransactionState interface {
	Push(vt *transaction.ValidTransaction) (common.Hash, error)
	AddToPool(vt *transaction.ValidTransaction) common.Hash
	RemoveExtrinsic(ext types.Extrinsic)
	RemoveExtrinsicFromPool(ext types.Extrinsic)
	PendingInPool() []*transaction.ValidTransaction
	Exists(ext types.Extrinsic) bool
}

TransactionState is the interface for transaction state methods

Jump to

Keyboard shortcuts

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