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 int) error
- type BlockState
- type Config
- type Service
- func (s *Service) GetMetadata() ([]byte, error)
- func (s *Service) GetRuntimeVersion() (*runtime.VersionAPI, error)
- func (s *Service) HandleSubmittedExtrinsic(ext types.Extrinsic) error
- func (s *Service) HasKey(pubKeyStr string, keyType string) (bool, error)
- func (s *Service) InsertKey(kp crypto.Keypair)
- func (s *Service) IsBabeAuthority() bool
- func (s *Service) ProcessBlockAnnounceMessage(msg *network.BlockAnnounceMessage) error
- func (s *Service) ProcessBlockRequestMessage(msg *network.BlockRequestMessage) error
- func (s *Service) ProcessBlockResponseMessage(msg *network.BlockResponseMessage) error
- func (s *Service) ProcessTransactionMessage(msg *network.TransactionMessage) error
- func (s *Service) Start() error
- func (s *Service) Stop() error
- func (s *Service) StorageRoot() (common.Hash, error)
- type StorageState
- type Syncer
- type SyncerConfig
- type TransactionQueue
- 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 ErrNilBlockState = errors.New("cannot have nil BlockState")
ErrNilBlockState is returned when BlockState is nik
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 nik
var ErrNilVerifier = errors.New("cannot have nil Verifier")
ErrNilVerifier is returned when trying to instantiate a Syncer without a Verifier
var ErrNoKeysProvided = errors.New("no keys provided for authority node")
ErrNoKeysProvided is returned when no keys are given for an authority node
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 BlockState ¶
type BlockState interface {
BestBlockHash() common.Hash
BestBlockHeader() (*types.Header, error)
BestBlockNumber() (*big.Int, error)
BestBlock() (*types.Block, error)
SubChain(start, end common.Hash) ([]common.Hash, error)
AddBlock(*types.Block) error
GetAllBlocksAtDepth(hash common.Hash) []common.Hash
AddBlockWithArrivalTime(*types.Block, uint64) error
CompareAndSetBlockData(bd *types.BlockData) error
GetBlockBody(common.Hash) (*types.Body, error)
SetHeader(*types.Header) error
GetHeader(common.Hash) (*types.Header, error)
HasHeader(hash common.Hash) (bool, error)
GetReceipt(common.Hash) ([]byte, error)
GetMessageQueue(common.Hash) ([]byte, error)
GetJustification(common.Hash) ([]byte, error)
GetBlockByNumber(*big.Int) (*types.Block, error)
GetBlockByHash(common.Hash) (*types.Block, error)
GetArrivalTime(common.Hash) (uint64, error)
GenesisHash() common.Hash
GetSlotForBlock(common.Hash) (uint64, error)
HighestBlockHash() common.Hash
HighestBlockNumber() *big.Int
}
BlockState interface for block state methods
type Config ¶
type Config struct {
BlockState BlockState
StorageState StorageState
TransactionQueue TransactionQueue
Keystore *keystore.Keystore
Runtime *runtime.Runtime
IsBabeAuthority bool
NewBlocks chan types.Block // only used for testing purposes
Verifier Verifier // only used for testing purposes
MsgRec <-chan network.Message
MsgSend chan<- network.Message
SyncChan chan *big.Int
}
Config holds the configuration for the core 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 ¶
func (s *Service) GetRuntimeVersion() (*runtime.VersionAPI, error)
GetRuntimeVersion gets the current RuntimeVersion
func (*Service) HandleSubmittedExtrinsic ¶
HandleSubmittedExtrinsic is used to send a Transaction message containing a Extrinsic @ext
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) IsBabeAuthority ¶
IsBabeAuthority returns true if node is BABE authority
func (*Service) ProcessBlockAnnounceMessage ¶
func (s *Service) ProcessBlockAnnounceMessage(msg *network.BlockAnnounceMessage) error
ProcessBlockAnnounceMessage creates a block request message from the block announce messages (block announce messages include the header but the full block is required to execute `core_execute_block`).
func (*Service) ProcessBlockRequestMessage ¶
func (s *Service) ProcessBlockRequestMessage(msg *network.BlockRequestMessage) error
ProcessBlockRequestMessage processes a block request message, returning a block response message
func (*Service) ProcessBlockResponseMessage ¶
func (s *Service) ProcessBlockResponseMessage(msg *network.BlockResponseMessage) error
ProcessBlockResponseMessage attempts to validate and add the block to the chain by calling `core_execute_block`. Valid blocks are stored in the block database to become part of the canonical chain.
func (*Service) ProcessTransactionMessage ¶
func (s *Service) ProcessTransactionMessage(msg *network.TransactionMessage) error
ProcessTransactionMessage validates each transaction in the message and adds valid transactions to the transaction queue of the BABE session
type StorageState ¶
type StorageState interface {
StorageRoot() (common.Hash, error)
SetStorage([]byte, []byte) error
GetStorage([]byte) ([]byte, error)
StoreInDB() error
LoadCode() ([]byte, error)
LoadCodeHash() (common.Hash, error)
SetStorageChild([]byte, *trie.Trie) error
SetStorageIntoChild([]byte, []byte, []byte) error
GetStorageFromChild([]byte, []byte) ([]byte, error)
ClearStorage([]byte) error
Entries() map[string][]byte
SetBalance(key [32]byte, balance uint64) error
GetBalance(key [32]byte) (uint64, error)
}
StorageState interface for storage state methods
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
Syncer deals with chain syncing by sending block request messages and watching for responses.
type SyncerConfig ¶
type SyncerConfig struct {
BlockState BlockState
BlockNumIn <-chan *big.Int
RespIn <-chan *network.BlockResponseMessage
MsgOut chan<- network.Message
Lock *sync.Mutex
ChanLock *sync.Mutex
TransactionQueue TransactionQueue
Runtime *runtime.Runtime
Verifier Verifier
}
SyncerConfig is the configuration for the Syncer.
type TransactionQueue ¶
type TransactionQueue interface {
Push(vt *transaction.ValidTransaction) (common.Hash, error)
Pop() *transaction.ValidTransaction
Peek() *transaction.ValidTransaction
RemoveExtrinsic(ext types.Extrinsic)
}
TransactionQueue is the interface for transaction queue methods
type Verifier ¶
type Verifier interface {
VerifyBlock(header *types.Header) (bool, error)
// IncrementEpoch is called when we have received all the blocks for an epoch.
IncrementEpoch() (*babe.NextEpochDescriptor, error)
EpochNumber() uint64
}
Verifier deals with block verification, as well as NextEpochDescriptors.