core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: LGPL-3.0 Imports: 29 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 ErrNilBlockState = errors.New("cannot have nil BlockState")

ErrNilBlockState is returned when BlockState is nik

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 nik

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 ErrNoKeysProvided = errors.New("no keys provided for authority node")

ErrNoKeysProvided is returned when no keys are given for an authority node

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 int) error

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

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() ([]byte, error)

GetMetadata calls runtime Metadata_metadata function

func (*Service) GetRuntimeVersion

func (s *Service) GetRuntimeVersion() (*runtime.VersionAPI, 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) 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 keystore

func (*Service) IsBabeAuthority

func (s *Service) IsBabeAuthority() bool

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

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 {
	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.

func NewSyncer

func NewSyncer(cfg *SyncerConfig) (*Syncer, error)

NewSyncer returns a new Syncer

func (*Syncer) Start

func (s *Syncer) Start() error

Start begins the syncer

func (*Syncer) Stop

func (s *Syncer) Stop() error

Stop stops the syncer

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.

Jump to

Keyboard shortcuts

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