Documentation
¶
Index ¶
- Constants
- Variables
- type BlockPool
- func (pool *BlockPool) AddBlock(peerID p2pTypes.ID, block *types.Block, blockSize int)
- func (pool *BlockPool) GetStatus() (height int64, numPending int32, lenRequesters int)
- func (pool *BlockPool) IsCaughtUp() bool
- func (pool *BlockPool) MaxPeerHeight() int64
- func (pool *BlockPool) OnStart() error
- func (pool *BlockPool) PeekTwoBlocks() (first *types.Block, second *types.Block)
- func (pool *BlockPool) PopRequest()
- func (pool *BlockPool) RedoRequest(height int64) p2pTypes.ID
- func (pool *BlockPool) RemovePeer(peerID p2pTypes.ID)
- func (pool *BlockPool) SetPeerHeight(peerID p2pTypes.ID, height int64)
- type BlockRequest
- type BlockchainMessage
- type BlockchainReactor
- func (bcR *BlockchainReactor) AddPeer(peer p2p.PeerConn)
- func (bcR *BlockchainReactor) BroadcastStatusRequest() error
- func (bcR *BlockchainReactor) GetChannels() []*p2p.ChannelDescriptor
- func (bcR *BlockchainReactor) OnStart() error
- func (bcR *BlockchainReactor) OnStop()
- func (bcR *BlockchainReactor) Receive(chID byte, src p2p.PeerConn, msgBytes []byte)
- func (bcR *BlockchainReactor) RemovePeer(peer p2p.PeerConn, reason any)
- func (bcR *BlockchainReactor) SetDeferredWrites(app abci.DeferredCommitter)
- func (bcR *BlockchainReactor) SetLogger(l *slog.Logger)
- type DeferredWrites
- type SwitchToConsensusFn
Constants ¶
const ( // BlockchainChannel is a channel for blocks and status updates (`BlockStore` height) BlockchainChannel = byte(0x40) )
Variables ¶
var Package = amino.RegisterPackage(amino.NewPackage( "github.com/gnolang/gno/tm2/pkg/bft/blockchain", "tm", amino.GetCallersDirname(), ).WithDependencies( btypes.Package, ).WithTypes( &bcBlockRequestMessage{}, "BlockRequest", &bcBlockResponseMessage{}, "BlockResponse", &bcNoBlockResponseMessage{}, "NoBlockResponse", &bcStatusRequestMessage{}, "StatusRequest", &bcStatusResponseMessage{}, "StatusResponse", ))
Functions ¶
This section is empty.
Types ¶
type BlockPool ¶
type BlockPool struct {
service.BaseService
// contains filtered or unexported fields
}
BlockPool keeps track of the fast sync peers, block requests and block responses.
func NewBlockPool ¶
func NewBlockPool(start int64, requestsCh chan<- BlockRequest, errorsCh chan<- peerError) *BlockPool
NewBlockPool returns a new BlockPool with the height equal to start. Block requests and errors will be sent to requestsCh and errorsCh accordingly.
func (*BlockPool) AddBlock ¶
AddBlock validates that the block comes from the peer it was expected from and calls the requester to store it. TODO: ensure that blocks come in order for each peer.
func (*BlockPool) GetStatus ¶
GetStatus returns pool's height, numPending requests and the number of requesters.
func (*BlockPool) IsCaughtUp ¶
IsCaughtUp returns true if this node is caught up, false - otherwise. TODO: relax conditions, prevent abuse.
func (*BlockPool) MaxPeerHeight ¶
MaxPeerHeight returns the highest reported height.
func (*BlockPool) OnStart ¶
OnStart implements service.Service by spawning requesters routine and recording pool's start time.
func (*BlockPool) PeekTwoBlocks ¶
PeekTwoBlocks returns blocks at pool.height and pool.height+1. We need to see the second block's Commit to validate the first block. So we peek two blocks at a time. The caller will verify the commit.
func (*BlockPool) PopRequest ¶
func (pool *BlockPool) PopRequest()
PopRequest pops the first block at pool.height. It must have been validated by 'second'.Commit from PeekTwoBlocks().
func (*BlockPool) RedoRequest ¶
RedoRequest invalidates the block at pool.height, Remove the peer and redo request from others. Returns the ID of the removed peer.
func (*BlockPool) RemovePeer ¶
RemovePeer removes the peer with peerID from the pool. If there's no peer with peerID, function is a no-op.
type BlockRequest ¶
BlockRequest stores a block request identified by the block Height and the PeerID responsible for delivering the block
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, switchToConsensusFn SwitchToConsensusFn, ) *BlockchainReactor
NewBlockchainReactor returns new reactor instance.
func (*BlockchainReactor) AddPeer ¶
func (bcR *BlockchainReactor) AddPeer(peer p2p.PeerConn)
AddPeer implements Reactor by sending our state to peer.
func (*BlockchainReactor) BroadcastStatusRequest ¶
func (bcR *BlockchainReactor) BroadcastStatusRequest() error
BroadcastStatusRequest broadcasts `BlockStore` height.
func (*BlockchainReactor) GetChannels ¶
func (bcR *BlockchainReactor) GetChannels() []*p2p.ChannelDescriptor
GetChannels implements Reactor
func (*BlockchainReactor) OnStart ¶
func (bcR *BlockchainReactor) OnStart() error
OnStart implements cmn.Service.
func (*BlockchainReactor) OnStop ¶
func (bcR *BlockchainReactor) OnStop()
OnStop implements cmn.Service. It waits for the block-sync routine, which returns once the pool is stopped, at the end of its current block or flush point: whoever stops the node may then close the application's database.
func (*BlockchainReactor) Receive ¶
func (bcR *BlockchainReactor) Receive(chID byte, src p2p.PeerConn, msgBytes []byte)
Receive implements Reactor by handling 4 types of messages (look below).
func (*BlockchainReactor) RemovePeer ¶
func (bcR *BlockchainReactor) RemovePeer(peer p2p.PeerConn, reason any)
RemovePeer implements Reactor by removing peer from the pool.
func (*BlockchainReactor) SetDeferredWrites ¶
func (bcR *BlockchainReactor) SetDeferredWrites(app abci.DeferredCommitter)
SetDeferredWrites makes block sync hold the writes of the block store, of the state and of app in memory, and write all of them at flush points, if their databases are HoldingDBs and app agrees to defer its commits (see DeferredWrites). Call it before the reactor starts.
func (*BlockchainReactor) SetLogger ¶
func (bcR *BlockchainReactor) SetLogger(l *slog.Logger)
SetLogger implements cmn.Service by setting the logger on reactor and pool.
type DeferredWrites ¶
type DeferredWrites struct {
// contains filtered or unexported fields
}
DeferredWrites holds, during block sync, the writes of the block store, of the state and of the application in memory, and writes all of them at flush points (see FlushPoint and tm2/adr, deferred writes during block sync). Its methods run on the block-sync goroutine, between blocks.
func NewDeferredWrites ¶
func NewDeferredWrites(blockStore *store.BlockStore, blockExec *sm.BlockExecutor, app abci.DeferredCommitter) *DeferredWrites
NewDeferredWrites returns the DeferredWrites of blockStore and blockExec, whose databases must be HoldingDBs, and of their application; nil if the databases cannot hold.
func (*DeferredWrites) FlushPoint ¶
func (d *DeferredWrites) FlushPoint(height int64)
FlushPoint writes everything held since the last flush point, up to the block at height, in the order that leaves the three databases consistent after a crash at any instant: the block store, with a record of the window, then the state, then the application, each as one synced, all-or-nothing write. The window's events fire only then. A failed write ends the node: going on would write the next window over a gap.
func (*DeferredWrites) NeedsFlushPoint ¶
func (d *DeferredWrites) NeedsFlushPoint() bool
NeedsFlushPoint reports whether to take a flush point now: the interval since the last one has passed, a database holds too much, or the application needs one (its halt height, or a halt param written).
func (*DeferredWrites) Start ¶
func (d *DeferredWrites) Start(height int64) bool
Start starts holding the writes of the blocks applied after height, the height on disk, if the application agrees to defer its commits, and reports whether it did: deferring only the node's side would let the application's commits reach the disk ahead of the node's records, which no restart recovers from.
func (*DeferredWrites) Stop ¶
func (d *DeferredWrites) Stop()
Stop stops holding writes, right after a flush point.
type SwitchToConsensusFn ¶
SwitchToConsensusFn is a callback method that is meant to stop the syncing process as soon as the latest known height is reached, and start the consensus process for the validator node