Documentation ¶
Index ¶
- Variables
- func ErrMessageCast(s string) error
- func ErrNilChannel(s string) error
- func ErrUnsupportedMsgType(d byte) error
- type BlockState
- type CodeSubstitutedState
- type Config
- type EpochState
- type Network
- type QueryKeyValueChanges
- type Service
- func (s *Service) DecodeSessionKeys(enc []byte) ([]byte, error)
- func (s *Service) GetMetadata(bhash *common.Hash) ([]byte, error)
- func (s *Service) GetReadProofAt(block common.Hash, keys [][]byte) (hash common.Hash, proofForKeys [][]byte, err error)
- func (s *Service) GetRuntimeVersion(bhash *common.Hash) (runtime.Version, error)
- func (s *Service) HandleBlockImport(block *types.Block, state *rtstorage.TrieState) error
- func (s *Service) HandleBlockProduced(block *types.Block, state *rtstorage.TrieState) error
- func (s *Service) HandleSubmittedExtrinsic(ext types.Extrinsic) error
- func (s *Service) HandleTransactionMessage(peerID peer.ID, msg *network.TransactionMessage) (bool, error)
- func (s *Service) HasKey(pubKeyStr, keystoreType string) (bool, error)
- func (s *Service) InsertKey(kp crypto.Keypair, keystoreType string) error
- func (s *Service) QueryStorage(from, to common.Hash, keys ...string) (map[common.Hash]QueryKeyValueChanges, error)
- func (s *Service) Start() error
- func (s *Service) Stop() error
- func (s *Service) StorageRoot() (common.Hash, error)
- func (s *Service) TransactionsCount() int
- type StorageState
- type TransactionState
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilBlockState is returned when BlockState is nil ErrNilBlockState = errors.New("cannot have nil BlockState") // ErrNilStorageState is returned when StorageState is nil ErrNilStorageState = errors.New("cannot have nil StorageState") // ErrNilKeystore is returned when keystore is nil ErrNilKeystore = errors.New("cannot have nil keystore") // ErrServiceStopped is returned when the service has been stopped ErrServiceStopped = errors.New("service has been stopped") // ErrInvalidBlock is returned when a block cannot be verified ErrInvalidBlock = errors.New("could not verify block") // ErrNilVerifier is returned when trying to instantiate a Syncer without a Verifier ErrNilVerifier = errors.New("cannot have nil Verifier") // ErrNilRuntime is returned when trying to instantiate a Service or Syncer without a runtime ErrNilRuntime = errors.New("cannot have nil runtime") // ErrNilBlockProducer is returned when trying to instantiate a block producing Service without a block producer ErrNilBlockProducer = errors.New("cannot have nil BlockProducer") // ErrNilConsensusMessageHandler is returned when trying to instantiate a Service without a FinalityMessageHandler ErrNilConsensusMessageHandler = errors.New("cannot have nil ErrNilFinalityMessageHandler") ErrNilBlockHandlerParameter = errors.New("unable to handle block due to nil parameter") // ErrNilNetwork is returned when the Network interface is nil ErrNilNetwork = errors.New("cannot have nil Network") // ErrEmptyRuntimeCode is returned when the storage :code is empty ErrEmptyRuntimeCode = errors.New("new :code is empty") )
Functions ¶
func ErrMessageCast ¶
ErrMessageCast is returned if unable to cast a network.Message to a type
func ErrNilChannel ¶
ErrNilChannel is returned if a channel is nil
func ErrUnsupportedMsgType ¶
ErrUnsupportedMsgType is returned if we receive an unknown message type
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) HighestCommonAncestor(a, b common.Hash) (common.Hash, error) 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(*common.Hash) (runtime.Instance, error) StoreRuntime(common.Hash, runtime.Instance) }
BlockState interface for block state methods
type CodeSubstitutedState ¶
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 runtime.Instance CodeSubstitutes map[common.Hash]string CodeSubstitutedState CodeSubstitutedState }
Config holds the configuration for the core Service.
type EpochState ¶
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 ¶
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 ¶
QueryKeyValueChanges represents the key-value data inside a block storage
type Service ¶
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 ¶
NewService returns a new core service that connects the runtime, BABE session, and network service.
func (*Service) DecodeSessionKeys ¶
DecodeSessionKeys executes the runtime DecodeSessionKeys and return the scale encoded keys
func (*Service) GetMetadata ¶
GetMetadata calls runtime Metadata_metadata function
func (*Service) GetReadProofAt ¶
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 ¶
GetRuntimeVersion gets the current RuntimeVersion
func (*Service) HandleBlockImport ¶
HandleBlockImport handles a block that was imported via the network
func (*Service) HandleBlockProduced ¶
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 ¶
HandleSubmittedExtrinsic is used to send a Transaction message containing a Extrinsic @ext
func (*Service) HandleTransactionMessage ¶
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 ¶
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) QueryStorage ¶
func (s *Service) QueryStorage(from, to common.Hash, keys ...string) (map[common.Hash]QueryKeyValueChanges, error)
QueryStorage returns the key-value data by block based on `keys` params on every block starting `from` until `to` block, if `to` is not nil
func (*Service) StorageRoot ¶
StorageRoot returns the hash of the storage root
func (*Service) TransactionsCount ¶
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 ¶
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