v1

package
v0.34.6 Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockchainChannel is a channel for blocks and status updates (`BlockStore` height)
	BlockchainChannel = byte(0x40)
)

Variables

This section is empty.

Functions

func RegisterBlockchainMessages

func RegisterBlockchainMessages(cdc *amino.Codec)

RegisterBlockchainMessages registers the fast sync messages for amino encoding.

Types

type BcReactorFSM

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

BcReactorFSM is the datastructure for the Blockchain Reactor State Machine

func NewFSM

func NewFSM(height int64, toBcR bcReactor) *BcReactorFSM

NewFSM creates a new reactor FSM.

func (*BcReactorFSM) FirstTwoBlocks

func (fsm *BcReactorFSM) FirstTwoBlocks() (first, second *types.Block, err error)

FirstTwoBlocks returns the two blocks at pool height and height+1

func (*BcReactorFSM) Handle

func (fsm *BcReactorFSM) Handle(msg *bcReactorMessage) error

Handle processes messages and events sent to the FSM.

func (*BcReactorFSM) NeedsBlocks

func (fsm *BcReactorFSM) NeedsBlocks() bool

NeedsBlocks checks if more block requests are required.

func (*BcReactorFSM) SetLogger

func (fsm *BcReactorFSM) SetLogger(l log.Logger)

SetLogger sets the FSM logger.

func (*BcReactorFSM) Start

func (fsm *BcReactorFSM) Start()

Start starts the FSM.

func (*BcReactorFSM) Status

func (fsm *BcReactorFSM) Status() (height, maxPeerHeight int64)

Status returns the pool's height and the maximum peer height.

type BlockData

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

BlockData stores the peer responsible to deliver a block and the actual block if delivered.

type BlockPool

type BlockPool struct {
	Height        int64 // height of next block to execute
	MaxPeerHeight int64 // maximum height of all peers
	// contains filtered or unexported fields
}

BlockPool keeps track of the fast sync peers, block requests and block responses.

func NewBlockPool

func NewBlockPool(height int64, toBcR bcReactor) *BlockPool

NewBlockPool creates a new BlockPool.

func (*BlockPool) AddBlock

func (pool *BlockPool) AddBlock(peerID p2p.ID, block *types.Block, blockSize int) error

AddBlock validates that the block comes from the peer it was expected from and stores it in the 'blocks' map.

func (*BlockPool) BlockAndPeerAtHeight

func (pool *BlockPool) BlockAndPeerAtHeight(height int64) (bData *BlockData, err error)

BlockAndPeerAtHeight retrieves the block and delivery peer at specified height. Returns errMissingBlock if a block was not found

func (*BlockPool) Cleanup

func (pool *BlockPool) Cleanup()

Cleanup performs pool and peer cleanup

func (*BlockPool) FirstTwoBlocksAndPeers

func (pool *BlockPool) FirstTwoBlocksAndPeers() (first, second *BlockData, err error)

FirstTwoBlocksAndPeers returns the blocks and the delivery peers at pool's height H and H+1.

func (*BlockPool) InvalidateFirstTwoBlocks

func (pool *BlockPool) InvalidateFirstTwoBlocks(err error)

InvalidateFirstTwoBlocks removes the peers that sent us the first two blocks, blocks are removed by RemovePeer().

func (*BlockPool) MakeNextRequests

func (pool *BlockPool) MakeNextRequests(maxNumRequests int)

MakeNextRequests creates more requests if the block pool is running low.

func (*BlockPool) NeedsBlocks

func (pool *BlockPool) NeedsBlocks() bool

NeedsBlocks returns true if more blocks are required.

func (*BlockPool) NumPeers

func (pool *BlockPool) NumPeers() int

NumPeers returns the number of peers in the pool

func (*BlockPool) ProcessedCurrentHeightBlock

func (pool *BlockPool) ProcessedCurrentHeightBlock()

ProcessedCurrentHeightBlock performs cleanup after a block is processed. It removes block at pool height and the peers that are now short.

func (*BlockPool) ReachedMaxHeight

func (pool *BlockPool) ReachedMaxHeight() bool

ReachedMaxHeight check if the pool has reached the maximum peer height.

func (*BlockPool) RemovePeer

func (pool *BlockPool) RemovePeer(peerID p2p.ID, err error)

RemovePeer removes the blocks and requests from the peer, reschedules them and deletes the peer.

func (*BlockPool) RemovePeerAtCurrentHeights

func (pool *BlockPool) RemovePeerAtCurrentHeights(err error)

RemovePeerAtCurrentHeights checks if a block at pool's height H exists and if not, it removes the delivery peer and returns. If a block at height H exists then the check and peer removal is done for H+1. This function is called when the FSM is not able to make progress for some time. This happens if either the block H or H+1 have not been delivered.

func (*BlockPool) SetLogger

func (pool *BlockPool) SetLogger(l log.Logger)

SetLogger sets the logger of the pool.

func (*BlockPool) UpdatePeer

func (pool *BlockPool) UpdatePeer(peerID p2p.ID, base int64, height int64) error

UpdatePeer adds a new peer or updates an existing peer with a new base and height. If a peer is short it is not added.

type BlockchainMessage

type BlockchainMessage interface {
	ValidateBasic() error
}

BlockchainMessage is a generic message for this reactor.

type BlockchainReactor

type BlockchainReactor struct {
	p2p.BaseReactor
	// contains filtered or unexported fields
}

BlockchainReactor handles long-term catchup syncing.

func NewBlockchainReactor

func NewBlockchainReactor(state sm.State, blockExec *sm.BlockExecutor, store *store.BlockStore,
	fastSync bool) *BlockchainReactor

NewBlockchainReactor returns new reactor instance.

func (*BlockchainReactor) AddPeer

func (bcR *BlockchainReactor) AddPeer(peer p2p.Peer)

AddPeer implements Reactor by sending our state to peer.

func (*BlockchainReactor) GetChannels

func (bcR *BlockchainReactor) GetChannels() []*p2p.ChannelDescriptor

GetChannels implements Reactor

func (*BlockchainReactor) OnStart

func (bcR *BlockchainReactor) OnStart() error

OnStart implements service.Service.

func (*BlockchainReactor) OnStop

func (bcR *BlockchainReactor) OnStop()

OnStop implements service.Service.

func (*BlockchainReactor) Receive

func (bcR *BlockchainReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)

Receive implements Reactor by handling 4 types of messages (look below).

func (*BlockchainReactor) RemovePeer

func (bcR *BlockchainReactor) RemovePeer(peer p2p.Peer, reason interface{})

RemovePeer implements Reactor by removing peer from the pool.

func (*BlockchainReactor) SetLogger

func (bcR *BlockchainReactor) SetLogger(l log.Logger)

SetLogger implements service.Service by setting the logger on reactor and pool.

type BpPeer

type BpPeer struct {
	ID p2p.ID

	Base                    int64 // the peer reported base
	Height                  int64 // the peer reported height
	NumPendingBlockRequests int   // number of requests still waiting for block responses
	// contains filtered or unexported fields
}

BpPeer is the datastructure associated with a fast sync peer.

func NewBpPeer

func NewBpPeer(peerID p2p.ID, base int64, height int64,
	onErr func(err error, peerID p2p.ID), params *BpPeerParams) *BpPeer

NewBpPeer creates a new peer.

func (*BpPeer) AddBlock

func (peer *BpPeer) AddBlock(block *types.Block, recvSize int) error

AddBlock adds a block at peer level. Block must be non-nil and recvSize a positive integer The peer must have a pending request for this block.

func (*BpPeer) BlockAtHeight

func (peer *BpPeer) BlockAtHeight(height int64) (*types.Block, error)

BlockAtHeight returns the block at a given height if available and errMissingBlock otherwise.

func (*BpPeer) CheckRate

func (peer *BpPeer) CheckRate() error

CheckRate verifies that the response rate of the peer is acceptable (higher than the minimum allowed).

func (*BpPeer) Cleanup

func (peer *BpPeer) Cleanup()

Cleanup performs cleanup of the peer, removes blocks, requests, stops timer and monitor.

func (*BpPeer) RemoveBlock

func (peer *BpPeer) RemoveBlock(height int64)

RemoveBlock removes the block of given height

func (*BpPeer) RequestSent

func (peer *BpPeer) RequestSent(height int64)

RequestSent records that a request was sent, and starts the peer timer and monitor if needed.

func (*BpPeer) SetLogger

func (peer *BpPeer) SetLogger(l log.Logger)

SetLogger sets the logger of the peer.

func (*BpPeer) String

func (peer *BpPeer) String() string

String returns a string representation of a peer.

type BpPeerParams

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

BpPeerParams stores the peer parameters that are used when creating a peer.

func BpPeerDefaultParams

func BpPeerDefaultParams() *BpPeerParams

BpPeerDefaultParams returns the default peer parameters.

Jump to

Keyboard shortcuts

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