Documentation ¶
Index ¶
- Variables
- func GenerateNewBlocks(t *testing.T, chain blockchainShim, num int) []*types.Block
- func NewMockBlockchain(headers []*types.Header) *mockBlockchain
- func NewMockSubscription() *mockSubscription
- func NewRandomChain(t *testing.T, height int) blockchainShim
- func SetupSyncerNetwork(t *testing.T, chain blockchainShim, peerChains []blockchainShim) (syncer *Syncer, peerSyncers []*Syncer)
- func TryPopBlock(t *testing.T, syncer *Syncer, peerID peer.ID, timeout time.Duration) (*types.Block, bool)
- func WaitUntilPeerConnected(t *testing.T, syncer *Syncer, numPeer int, timeout time.Duration)
- func WaitUntilProcessedAllEvents(t *testing.T, syncer *Syncer, timeout time.Duration)
- func WaitUntilProgressionUpdated(t *testing.T, syncer *Syncer, timeout time.Duration, target uint64)
- type Status
- type SyncPeer
- type Syncer
- func (s *Syncer) AddPeer(peerID peer.ID) error
- func (s *Syncer) BestPeer() *SyncPeer
- func (s *Syncer) Broadcast(b *types.Block)
- func (s *Syncer) BulkSyncWithPeer(p *SyncPeer, newBlockHandler func(block *types.Block)) error
- func (s *Syncer) DeletePeer(peerID peer.ID) error
- func (s *Syncer) GetSyncProgression() *progress.Progression
- func (s *Syncer) Start()
- func (s *Syncer) WatchSyncWithPeer(p *SyncPeer, handler func(b *types.Block) bool)
Constants ¶
This section is empty.
Variables ¶
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 ¶
GenerateNewBlocks returns new blocks from latest block of given chain
func NewMockBlockchain ¶
func NewMockSubscription ¶
func NewMockSubscription() *mockSubscription
func NewRandomChain ¶
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 ¶
WaitUntilPeerConnected waits until syncer connects to given number of peers
func WaitUntilProcessedAllEvents ¶
WaitUntilProcessedAllEvents waits until syncer finish to process all blockchain events
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 ¶
HeaderToStatus converts given header to Status
type SyncPeer ¶
type SyncPeer struct {
// contains filtered or unexported fields
}
SyncPeer is a representation of the peer the node is syncing with
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 (*Syncer) BulkSyncWithPeer ¶
BulkSyncWithPeer finds common ancestor with a peer and syncs block until latest block
func (*Syncer) DeletePeer ¶
DeletePeer deletes a peer from syncer
func (*Syncer) GetSyncProgression ¶
func (s *Syncer) GetSyncProgression() *progress.Progression
GetSyncProgression returns the latest sync progression, if any