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 ¶
- Variables
- func ErrMessageCast(s string) error
- func ErrNilChannel(s string) error
- func ErrUnsupportedMsgType(d byte) error
- type BlockProducer
- type BlockState
- type Config
- type DigestHandler
- type EpochState
- type FinalityGadget
- type Network
- type Service
- func (s *Service) GetMetadata(bhash *common.Hash) ([]byte, error)
- func (s *Service) GetRuntimeVersion(bhash *common.Hash) (runtime.Version, error)
- func (s *Service) HandleSubmittedExtrinsic(ext types.Extrinsic) error
- func (s *Service) HandleTransactionMessage(msg *network.TransactionMessage) error
- func (s *Service) HasKey(pubKeyStr string, keyType string) (bool, error)
- func (s *Service) InsertKey(kp crypto.Keypair)
- func (s *Service) IsBlockProducer() bool
- func (s *Service) Start() error
- func (s *Service) Stop() error
- func (s *Service) StorageRoot() (common.Hash, error)
- type StorageState
- type TransactionState
- type Verifier
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidBlock = errors.New("could not verify block")
ErrInvalidBlock is returned when a block cannot be verified
var ErrNilBlockProducer = errors.New("cannot have nil BlockProducer")
ErrNilBlockProducer is returned when trying to instantiate a block producing Service without a block producer
var ErrNilBlockState = errors.New("cannot have nil BlockState")
ErrNilBlockState is returned when BlockState is nil
var ErrNilConsensusMessageHandler = errors.New("cannot have nil ErrNilFinalityMessageHandler")
ErrNilConsensusMessageHandler is returned when trying to instantiate a Service without a FinalityMessageHandler
var ErrNilFinalityGadget = errors.New("cannot have nil FinalityGadget")
ErrNilFinalityGadget is returned when trying to instantiate a finalizing Service without a finality gadget
var ErrNilKeystore = errors.New("cannot have nil keystore")
ErrNilKeystore is returned when keystore is nil
var ErrNilRuntime = errors.New("cannot have nil runtime")
ErrNilRuntime is returned when trying to instantiate a Service or Syncer without a runtime
var ErrNilStorageState = errors.New("cannot have nil StorageState")
ErrNilStorageState is returned when StorageState is nil
var ErrNilVerifier = errors.New("cannot have nil Verifier")
ErrNilVerifier is returned when trying to instantiate a Syncer without a Verifier
var ErrServiceStopped = errors.New("service has been stopped")
ErrServiceStopped is returned when the service has been stopped
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 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 ¶
NewService returns a new core service that connects the runtime, BABE session, and network service.
func NewTestService ¶
NewTestService creates a new test core service
func (*Service) GetMetadata ¶
GetMetadata calls runtime Metadata_metadata function
func (*Service) GetRuntimeVersion ¶
GetRuntimeVersion gets the current RuntimeVersion
func (*Service) HandleSubmittedExtrinsic ¶
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 ¶
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 ¶
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
IsBlockProducer returns true if node is a block producer
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