sync

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

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 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 ErrNilChannel

func ErrNilChannel(s string) error

ErrNilChannel is returned if a channel is nil

Types

type BlockProducer

type BlockProducer interface {
	Pause() error
	Resume() error
}

BlockProducer is the interface that a block production service must implement

type BlockState

type BlockState interface {
	BestBlockHash() common.Hash
	BestBlockNumber() (*big.Int, error)
	AddBlock(*types.Block) error
	CompareAndSetBlockData(bd *types.BlockData) error
	GetBlockByNumber(*big.Int) (*types.Block, error)
	GetBlockBody(common.Hash) (*types.Body, error)
	SetHeader(*types.Header) error
	GetHeader(common.Hash) (*types.Header, error)
	HasHeader(hash common.Hash) (bool, error)
	SubChain(start, end common.Hash) ([]common.Hash, error)
	GetReceipt(common.Hash) ([]byte, error)
	GetMessageQueue(common.Hash) ([]byte, error)
	GetJustification(common.Hash) ([]byte, error)
}

BlockState is the interface for the block state

type Config

type Config struct {
	LogLvl           log.Lvl
	BlockState       BlockState
	StorageState     StorageState
	BlockProducer    BlockProducer
	TransactionState TransactionState
	Runtime          runtime.LegacyInstance
	Verifier         Verifier
	DigestHandler    DigestHandler
}

Config is the configuration for the sync Service.

type DigestHandler

type DigestHandler interface {
	Start()
	Stop()
	HandleConsensusDigest(*types.ConsensusDigest) error
}

DigestHandler is the interface for the consensus digest handler

type Service

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

Service deals with chain syncing by sending block request messages and watching for responses.

func NewService

func NewService(cfg *Config) (*Service, error)

NewService returns a new *sync.Service

func (*Service) CreateBlockResponse

func (s *Service) CreateBlockResponse(blockRequest *network.BlockRequestMessage) (*network.BlockResponseMessage, error)

CreateBlockResponse creates a block response message from a block request message

func (*Service) HandleBlockAnnounce

func (s *Service) HandleBlockAnnounce(msg *network.BlockAnnounceMessage) *network.BlockRequestMessage

HandleBlockAnnounce 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) HandleBlockResponse

func (s *Service) HandleBlockResponse(msg *network.BlockResponseMessage) *network.BlockRequestMessage

HandleBlockResponse handles a BlockResponseMessage by processing the blocks found in it and adding them to the BlockState if necessary. If the node is still not synced after processing, it creates and returns the next BlockRequestMessage to send.

func (*Service) HandleSeenBlocks

func (s *Service) HandleSeenBlocks(blockNum *big.Int) *network.BlockRequestMessage

HandleSeenBlocks handles a block that is newly "seen" ie. a block that a peer claims to have through a StatusMessage

type StorageState

type StorageState interface {
	TrieState(root *common.Hash) (*state.TrieState, error)
	StoreTrie(root common.Hash, ts *state.TrieState) error
}

StorageState is the interface for the storage state

type TransactionState

type TransactionState interface {
	RemoveExtrinsic(ext types.Extrinsic)
}

TransactionState is the interface for transaction queue methods

type Verifier

type Verifier interface {
	VerifyBlock(header *types.Header) (bool, error)
}

Verifier deals with block verification

Jump to

Keyboard shortcuts

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