sync

package
v0.0.0-...-c69f244 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: LGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNilBlockData is returned when trying to process a BlockResponseMessage with nil BlockData
	ErrNilBlockData = errors.New("got nil BlockData")

	// ErrServiceStopped is returned when the service has been stopped
	ErrServiceStopped = errors.New("service has been stopped")

	// ErrInvalidBlock is returned when a block cannot be verified
	ErrInvalidBlock = errors.New("could not verify block")

	// ErrInvalidBlockRequest is returned when an invalid block request is received
	ErrInvalidBlockRequest = errors.New("invalid block request")
)

Functions

func BuildBlock

func BuildBlock(t *testing.T, instance runtime.Instance, parent *types.Header, ext types.Extrinsic) *types.Block

BuildBlock ...

func ErrNilChannel

func ErrNilChannel(s string) error

ErrNilChannel is returned if a channel is nil

Types

type BabeVerifier

type BabeVerifier interface {
	VerifyBlock(header *types.Header) error
}

BabeVerifier deals with BABE block verification

type BlockImportHandler

type BlockImportHandler interface {
	HandleBlockImport(block *types.Block, state *rtstorage.TrieState) error
}

BlockImportHandler is the interface for the handler of newly imported blocks

type BlockState

type BlockState interface {
	BestBlockHash() common.Hash
	BestBlockHeader() (*types.Header, error)
	BestBlockNumber() (number uint, err error)
	AddBlock(*types.Block) error
	CompareAndSetBlockData(bd *types.BlockData) error
	GetBlockByNumber(blockNumber uint) (*types.Block, error)
	HasBlockBody(hash common.Hash) (bool, 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)
	SetJustification(hash common.Hash, data []byte) error
	SetFinalisedHash(hash common.Hash, round, setID uint64) error
	AddBlockToBlockTree(block *types.Block) error
	GetHashByNumber(blockNumber uint) (common.Hash, error)
	GetBlockByHash(common.Hash) (*types.Block, error)
	GetRuntime(*common.Hash) (runtime.Instance, error)
	StoreRuntime(common.Hash, runtime.Instance)
	GetHighestFinalisedHeader() (*types.Header, error)
	GetFinalisedNotifierChannel() chan *types.FinalisationInfo
	GetHeaderByNumber(num uint) (*types.Header, error)
	GetAllBlocksAtNumber(num uint) ([]common.Hash, error)
	IsDescendantOf(parent, child common.Hash) (bool, error)
}

BlockState is the interface for the block state

type ChainProcessor

type ChainProcessor interface {
	// contains filtered or unexported methods
}

ChainProcessor processes ready blocks. it is implemented by *chainProcessor

type ChainSync

type ChainSync interface {
	// contains filtered or unexported methods
}

ChainSync contains the methods used by the high-level service into the `chainSync` module

type CodeSubstitutedState

type CodeSubstitutedState interface {
	LoadCodeSubstitutedBlockHash() common.Hash
	StoreCodeSubstitutedBlockHash(hash common.Hash) error
}

CodeSubstitutedState interface to handle storage of code substitute state

type Config

type Config struct {
	LogLvl             log.Level
	Network            Network
	BlockState         BlockState
	StorageState       StorageState
	FinalityGadget     FinalityGadget
	TransactionState   TransactionState
	BlockImportHandler BlockImportHandler
	BabeVerifier       BabeVerifier
	MinPeers, MaxPeers int
	SlotDuration       time.Duration
	Telemetry          telemetry.Client
}

Config is the configuration for the sync Service.

type DisjointBlockSet

type DisjointBlockSet interface {
	// contains filtered or unexported methods
}

DisjointBlockSet represents a set of incomplete blocks, or blocks with an unknown parent. it is implemented by *disjointBlockSet

type FinalityGadget

type FinalityGadget interface {
	VerifyBlockJustification(common.Hash, []byte) error
}

FinalityGadget implements justification verification functionality

type Network

type Network interface {
	// DoBlockRequest sends a request to the given peer.
	// If a response is received within a certain time period,
	// it is returned, otherwise an error is returned.
	DoBlockRequest(to peer.ID, req *network.BlockRequestMessage) (*network.BlockResponseMessage, error)

	// Peers returns a list of currently connected peers
	Peers() []common.PeerInfo

	// ReportPeer reports peer based on the peer behaviour.
	ReportPeer(change peerset.ReputationChange, p peer.ID)
}

Network is the interface for the network

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(req *network.BlockRequestMessage) (*network.BlockResponseMessage, error)

CreateBlockResponse creates a block response message from a block request message

func (*Service) HandleBlockAnnounce

func (s *Service) HandleBlockAnnounce(from peer.ID, msg *network.BlockAnnounceMessage) error

HandleBlockAnnounce notifies the `chainSync` module that we have received a block announcement from the given peer.

func (*Service) HandleBlockAnnounceHandshake

func (s *Service) HandleBlockAnnounceHandshake(from peer.ID, msg *network.BlockAnnounceHandshake) error

HandleBlockAnnounceHandshake notifies the `chainSync` module that we have received a BlockAnnounceHandshake from the given peer.

func (*Service) HighestBlock

func (s *Service) HighestBlock() uint

HighestBlock gets the highest known block number

func (*Service) IsSynced

func (s *Service) IsSynced() bool

IsSynced exposes the synced state

func (*Service) Start

func (s *Service) Start() error

Start begins the chainSync and chainProcessor modules. It begins syncing in bootstrap mode

func (*Service) Stop

func (s *Service) Stop() error

Stop stops the chainSync and chainProcessor modules

type StorageState

type StorageState interface {
	TrieState(root *common.Hash) (*rtstorage.TrieState, error)
	LoadCodeHash(*common.Hash) (common.Hash, error)
	sync.Locker
}

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

Jump to

Keyboard shortcuts

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