protocol

package
v0.0.0-...-97e54d3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLoadLocalGenesisFailed = errors.New("failed to read local genesis")
	ErrMismatchGenesis        = errors.New("genesis does not match")
	ErrCommonAncestorNotFound = errors.New("header is nil")
	ErrForkNotFound           = errors.New("fork not found")
	ErrPopTimeout             = errors.New("timeout")
	ErrConnectionClosed       = errors.New("connection closed")
)

Functions

func GenerateNewBlocks

func GenerateNewBlocks(t *testing.T, chain blockchainShim, num int) []*types.Block

GenerateNewBlocks returns new blocks from latest block of given chain

func NewMockBlockchain

func NewMockBlockchain(headers []*types.Header) *mockBlockchain

func NewMockSubscription

func NewMockSubscription() *mockSubscription

func NewRandomChain

func NewRandomChain(t *testing.T, height int) blockchainShim

NewRandomChain returns new blockchain with random seed

func SetupSyncerNetwork

func SetupSyncerNetwork(
	t *testing.T,
	chain blockchainShim,
	peerChains []blockchainShim,
) (syncer *Syncer, peerSyncers []*Syncer)

SetupSyncerNetwork connects syncers

func TryPopBlock

func TryPopBlock(t *testing.T, syncer *Syncer, peerID peer.ID, timeout time.Duration) (*types.Block, bool)

TryPopBlock tries to take block from peer's queue in syncer within timeout

func WaitUntilPeerConnected

func WaitUntilPeerConnected(t *testing.T, syncer *Syncer, numPeer int, timeout time.Duration)

WaitUntilPeerConnected waits until syncer connects to given number of peers

func WaitUntilProcessedAllEvents

func WaitUntilProcessedAllEvents(t *testing.T, syncer *Syncer, timeout time.Duration)

WaitUntilProcessedAllEvents waits until syncer finish to process all blockchain events

func WaitUntilProgressionUpdated

func WaitUntilProgressionUpdated(t *testing.T, syncer *Syncer, timeout time.Duration, target uint64)

WaitUntilProgressionUpdated waits until the syncer's progression current block reaches a target

Types

type Status

type Status struct {
	Difficulty *big.Int   // Current difficulty
	Hash       types.Hash // Latest block hash
	Number     uint64     // Latest block number
}

Status defines the up to date information regarding the peer

func GetCurrentStatus

func GetCurrentStatus(b blockchainShim) *Status

GetCurrentStatus return status by latest block in blockchain

func HeaderToStatus

func HeaderToStatus(h *types.Header) *Status

HeaderToStatus converts given header to Status

func (*Status) Copy

func (s *Status) Copy() *Status

Copy creates a copy of the status

type SyncPeer

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

SyncPeer is a representation of the peer the node is syncing with

func (*SyncPeer) IsClosed

func (s *SyncPeer) IsClosed() bool

IsClosed returns whether peer's connectivity has been closed

func (*SyncPeer) Number

func (s *SyncPeer) Number() uint64

Number returns the latest peer block height

type Syncer

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

Syncer is a sync protocol

func CreateSyncer

func CreateSyncer(t *testing.T, blockchain blockchainShim, serverCfg *func(c *network.Config)) *Syncer

CreateSyncer initialize syncer with server

func NewSyncer

func NewSyncer(logger hclog.Logger, server *network.Server, blockchain blockchainShim) *Syncer

NewSyncer creates a new Syncer instance

func (*Syncer) AddPeer

func (s *Syncer) AddPeer(peerID peer.ID) error

AddPeer establishes new connection with the given peer

func (*Syncer) BestPeer

func (s *Syncer) BestPeer() *SyncPeer

BestPeer returns the best peer by difficulty (if any)

func (*Syncer) Broadcast

func (s *Syncer) Broadcast(b *types.Block)

Broadcast broadcasts a block to all peers

func (*Syncer) BulkSyncWithPeer

func (s *Syncer) BulkSyncWithPeer(p *SyncPeer, newBlockHandler func(block *types.Block)) error

BulkSyncWithPeer finds common ancestor with a peer and syncs block until latest block

func (*Syncer) DeletePeer

func (s *Syncer) DeletePeer(peerID peer.ID) error

DeletePeer deletes a peer from syncer

func (*Syncer) GetSyncProgression

func (s *Syncer) GetSyncProgression() *progress.Progression

GetSyncProgression returns the latest sync progression, if any

func (*Syncer) Start

func (s *Syncer) Start()

Start starts the syncer protocol

func (*Syncer) WatchSyncWithPeer

func (s *Syncer) WatchSyncWithPeer(p *SyncPeer, handler func(b *types.Block) bool)

WatchSyncWithPeer subscribes and adds peer's latest block

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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