core

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: LGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Copyright 2019 ChainSafe Systems (ON) Corp. This file is part of gossamer.

The gossamer library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The gossamer library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidBlock = errors.New("could not verify block")

ErrInvalidBlock is returned when a block cannot be verified

View Source
var ErrNilBlockProducer = errors.New("cannot have nil BlockProducer")

ErrNilBlockProducer is returned when trying to instantiate a block producing Service without a block producer

View Source
var ErrNilBlockState = errors.New("cannot have nil BlockState")

ErrNilBlockState is returned when BlockState is nil

View Source
var ErrNilConsensusMessageHandler = errors.New("cannot have nil ErrNilFinalityMessageHandler")

ErrNilConsensusMessageHandler is returned when trying to instantiate a Service without a FinalityMessageHandler

View Source
var ErrNilFinalityGadget = errors.New("cannot have nil FinalityGadget")

ErrNilFinalityGadget is returned when trying to instantiate a finalizing Service without a finality gadget

View Source
var ErrNilKeystore = errors.New("cannot have nil keystore")

ErrNilKeystore is returned when keystore is nil

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

ErrNilRuntime is returned when trying to instantiate a Service or Syncer without a runtime

View Source
var ErrNilStorageState = errors.New("cannot have nil StorageState")

ErrNilStorageState is returned when StorageState is nil

View Source
var ErrNilVerifier = errors.New("cannot have nil Verifier")

ErrNilVerifier is returned when trying to instantiate a Syncer without a Verifier

View Source
var ErrServiceStopped = errors.New("service has been stopped")

ErrServiceStopped is returned when the service has been stopped

Functions

func ErrMessageCast

func ErrMessageCast(s string) error

ErrMessageCast is returned if unable to cast a network.Message to a type

func ErrNilChannel

func ErrNilChannel(s string) error

ErrNilChannel is returned if a channel is nil

func ErrUnsupportedMsgType

func ErrUnsupportedMsgType(d byte) error

ErrUnsupportedMsgType is returned if we receive an unknown message type

Types

type BlockProducer added in v0.2.0

type BlockProducer interface {
	GetBlockChannel() <-chan types.Block
	SetOnDisabled(authorityIndex uint32)
}

BlockProducer is the interface that a block production service must implement

type BlockState

type BlockState interface {
	BestBlockHash() common.Hash
	BestBlockHeader() (*types.Header, error)
	BestBlockNumber() (*big.Int, 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)
	GenesisHash() common.Hash
	GetSlotForBlock(common.Hash) (uint64, error)
	HighestBlockHash() common.Hash
	HighestBlockNumber() *big.Int
	GetFinalizedHeader(uint64, uint64) (*types.Header, error)
	GetFinalizedHash(uint64, uint64) (common.Hash, error)
	SetFinalizedHash(common.Hash, uint64, uint64) error
	RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
	UnregisterImportedChannel(id byte)
	RegisterFinalizedChannel(ch chan<- *types.Header) (byte, error)
	UnregisterFinalizedChannel(id byte)
	HighestCommonAncestor(a, b common.Hash) (common.Hash, error)
	SubChain(start, end common.Hash) ([]common.Hash, error)
	GetBlockBody(hash common.Hash) (*types.Body, error)
}

BlockState interface for block state methods

type Config

type Config struct {
	LogLvl              log.Lvl
	BlockState          BlockState
	EpochState          EpochState
	StorageState        StorageState
	TransactionState    TransactionState
	Network             Network
	Keystore            *keystore.GlobalKeystore
	Runtime             runtime.Instance
	BlockProducer       BlockProducer
	IsBlockProducer     bool
	FinalityGadget      FinalityGadget
	IsFinalityAuthority bool
	Verifier            Verifier

	NewBlocks chan types.Block // only used for testing purposes
}

Config holds the configuration for the core Service.

type DigestHandler added in v0.2.0

type DigestHandler struct {
	// contains filtered or unexported fields
}

DigestHandler is used to handle consensus messages and relevant authority updates to BABE and GRANDPA

func NewDigestHandler added in v0.2.0

func NewDigestHandler(blockState BlockState, epochState EpochState, babe BlockProducer, grandpa FinalityGadget, verifier Verifier) (*DigestHandler, error)

NewDigestHandler returns a new DigestHandler

func (*DigestHandler) HandleConsensusDigest added in v0.2.0

func (h *DigestHandler) HandleConsensusDigest(d *types.ConsensusDigest, header *types.Header) error

HandleConsensusDigest is the function used by the syncer to handle a consensus digest

func (*DigestHandler) NextGrandpaAuthorityChange added in v0.2.0

func (h *DigestHandler) NextGrandpaAuthorityChange() uint64

NextGrandpaAuthorityChange returns the block number of the next upcoming grandpa authorities change. It returns 0 if no change is scheduled.

func (*DigestHandler) SetFinalityGadget added in v0.2.0

func (h *DigestHandler) SetFinalityGadget(grandpa FinalityGadget)

SetFinalityGadget sets the digest handler's grandpa instance

func (*DigestHandler) Start added in v0.2.0

func (h *DigestHandler) Start()

Start starts the DigestHandler

func (*DigestHandler) Stop added in v0.2.0

func (h *DigestHandler) Stop()

Stop stops the DigestHandler

type EpochState added in v0.3.0

type EpochState interface {
	GetEpochForBlock(header *types.Header) (uint64, error)
	SetEpochData(epoch uint64, info *types.EpochData) error
	SetConfigData(epoch uint64, info *types.ConfigData) error
	SetCurrentEpoch(epoch uint64) error
	GetCurrentEpoch() (uint64, error)
}

EpochState is the interface for state.EpochState

type FinalityGadget added in v0.2.0

type FinalityGadget interface {
	services.Service

	UpdateAuthorities(ad []*types.Authority)
	Authorities() []*types.Authority
}

FinalityGadget is the interface that a finality gadget must implement

type Network added in v0.2.0

type Network interface {
	SendMessage(network.NotificationsMessage)
}

Network is the interface for the network service

type Service

type Service struct {
	// 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 NewTestService

func NewTestService(t *testing.T, cfg *Config) *Service

NewTestService creates a new test core service

func (*Service) GetMetadata

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

GetMetadata calls runtime Metadata_metadata function

func (*Service) GetRuntimeVersion

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

GetRuntimeVersion gets the current RuntimeVersion

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(msg *network.TransactionMessage) error

HandleTransactionMessage validates each transaction in the message and adds valid transactions to the transaction queue of the BABE session

func (*Service) HasKey

func (s *Service) HasKey(pubKeyStr string, keyType 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)

InsertKey inserts keypair into the account keystore TODO: define which keystores need to be updated and create separate insert funcs for each

func (*Service) IsBlockProducer added in v0.2.0

func (s *Service) IsBlockProducer() bool

IsBlockProducer returns true if node is a block producer

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

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)
	GetStateRootFromBlock(bhash *common.Hash) (*common.Hash, error)
}

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
}

TransactionState is the interface for transaction state methods

type Verifier

type Verifier interface {
	SetOnDisabled(authorityIndex uint32, block *types.Header) error
}

Verifier is the interface for the block verifier

Jump to

Keyboard shortcuts

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