blockchain

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
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

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

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

func (pool *BlockPool) GetStatus() (height int64, numPending int32, lenRequesters int)

GetStatus returns pool's height, numPending requests and the number of requesters.

func (*BlockPool) IsCaughtUp

func (pool *BlockPool) IsCaughtUp() bool

IsCaughtUp returns true if this node is caught up, false - otherwise. TODO: relax conditions, prevent abuse.

func (*BlockPool) MaxPeerHeight

func (pool *BlockPool) MaxPeerHeight() int64

MaxPeerHeight returns the highest reported height.

func (*BlockPool) OnStart

func (pool *BlockPool) OnStart() error

OnStart implements service.Service by spawning requesters routine and recording pool's start time.

func (*BlockPool) PeekTwoBlocks

func (pool *BlockPool) PeekTwoBlocks() (first *types.Block, second *types.Block)

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

func (pool *BlockPool) RedoRequest(height int64) p2pTypes.ID

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

func (pool *BlockPool) RemovePeer(peerID p2pTypes.ID)

RemovePeer removes the peer with peerID from the pool. If there's no peer with peerID, function is a no-op.

func (*BlockPool) SetPeerHeight

func (pool *BlockPool) SetPeerHeight(peerID p2pTypes.ID, height int64)

SetPeerHeight sets the peer's alleged blockchain height.

type BlockRequest

type BlockRequest struct {
	Height int64
	PeerID p2pTypes.ID
}

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.

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 interface{})

RemovePeer implements Reactor by removing peer from the pool.

func (*BlockchainReactor) SetLogger

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

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

type SwitchToConsensusFn

type SwitchToConsensusFn func(sm.State, int)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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