bsc

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Bsc1 = 1
	Bsc2 = 2
)

Constants to match up protocol versions and messages

View Source
const (
	BscCapMsg           = 0x00 // bsc capability msg used upon handshake
	VotesMsg            = 0x01
	GetBlocksByRangeMsg = 0x02 // it can request (StartBlockHeight-Count, StartBlockHeight] range blocks from remote peer
	BlocksByRangeMsg    = 0x03 // the replied blocks from remote peer
)
View Source
const MaxRequestRangeBlocksCount = 64
View Source
const ProtocolName = "bsc"

ProtocolName is the official short name of the `bsc` protocol used during devp2p capability negotiation.

Variables

View Source
var (
	IngressRegistrationErrorMeter = metrics.NewRegisteredMeter(ingressRegistrationErrorName, nil)
	EgressRegistrationErrorMeter  = metrics.NewRegisteredMeter(egressRegistrationErrorName, nil)
)
View Source
var ProtocolVersions = []uint{Bsc1, Bsc2}

ProtocolVersions are the supported versions of the `bsc` protocol (first is primary).

Functions

func Handle

func Handle(backend Backend, peer *Peer) error

Handle is the callback invoked to manage the life cycle of a `bsc` peer. When this function terminates, the peer is disconnected.

func MakeProtocols

func MakeProtocols(backend Backend) []p2p.Protocol

MakeProtocols constructs the P2P protocol definitions for `bsc`.

Types

type Backend

type Backend interface {
	// Chain retrieves the blockchain object to serve data.
	Chain() *core.BlockChain

	// RunPeer is invoked when a peer joins on the `bsc` protocol. The handler
	// should do any peer maintenance work, handshakes and validations. If all
	// is passed, control should be given back to the `handler` to process the
	// inbound messages going forward.
	RunPeer(peer *Peer, handler Handler) error

	// PeerInfo retrieves all known `bsc` information about a peer.
	PeerInfo(id enode.ID) interface{}

	// Handle is a callback to be invoked when a data packet is received from
	// the remote peer. Only packets not consumed by the protocol handler will
	// be forwarded to the backend.
	Handle(peer *Peer, packet Packet) error
}

type BlockData

type BlockData struct {
	Header      *types.Header
	Txs         []*types.Transaction
	Uncles      []*types.Header
	Withdrawals []*types.Withdrawal `rlp:"optional"`
	Sidecars    types.BlobSidecars  `rlp:"optional"`
}

BlockData contains types.extblock + sidecars

func NewBlockData

func NewBlockData(block *types.Block) *BlockData

NewBlockData creates a new BlockData object from a block

type BlocksByRangePacket

type BlocksByRangePacket struct {
	RequestId uint64
	Blocks    []*BlockData
}

func (*BlocksByRangePacket) Kind

func (*BlocksByRangePacket) Kind() byte

func (*BlocksByRangePacket) Name

func (*BlocksByRangePacket) Name() string

type BscCapPacket

type BscCapPacket struct {
	ProtocolVersion uint
	Extra           rlp.RawValue // for extension
}

BscCapPacket is the network packet for bsc capability message.

func (*BscCapPacket) Kind

func (*BscCapPacket) Kind() byte

func (*BscCapPacket) Name

func (*BscCapPacket) Name() string

type Decoder

type Decoder interface {
	Decode(val interface{}) error
}

type Dispatcher

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

Dispatcher handles message requests and responses

func NewDispatcher

func NewDispatcher(peer *Peer) *Dispatcher

NewDispatcher creates a new message dispatcher

func (*Dispatcher) DispatchRequest

func (d *Dispatcher) DispatchRequest(req *Request) (interface{}, error)

DispatchRequest send the request, and block until the later response

func (*Dispatcher) DispatchResponse

func (d *Dispatcher) DispatchResponse(res *Response) error

func (*Dispatcher) GenRequestID

func (d *Dispatcher) GenRequestID() uint64

GenRequestID get requestID for packet

type GetBlocksByRangePacket

type GetBlocksByRangePacket struct {
	RequestId        uint64
	StartBlockHeight uint64      // The start block height expected to be obtained from
	StartBlockHash   common.Hash // The start block hash expected to be obtained from
	Count            uint64      // Get the number of blocks from the start
}

func (*GetBlocksByRangePacket) Kind

func (*GetBlocksByRangePacket) Kind() byte

func (*GetBlocksByRangePacket) Name

type Handler

type Handler func(peer *Peer) error

Handler is a callback to invoke from an outside runner after the boilerplate exchanges have passed.

type NodeInfo

type NodeInfo struct{}

NodeInfo represents a short summary of the `bsc` sub-protocol metadata known about the host peer.

type Packet

type Packet interface {
	Name() string // Name returns a string corresponding to the message type.
	Kind() byte   // Kind returns the message type.
}

Packet represents a p2p message in the `bsc` protocol.

type Peer

type Peer struct {
	*p2p.Peer // The embedded P2P package peer
	// contains filtered or unexported fields
}

Peer is a collection of relevant information we have about a `bsc` peer.

func NewPeer

func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter) *Peer

NewPeer create a wrapper for a network connection and negotiated protocol version.

func (*Peer) AsyncSendVotes

func (p *Peer) AsyncSendVotes(votes []*types.VoteEnvelope)

AsyncSendVotes queues a batch of vote hashes for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.

func (*Peer) Close

func (p *Peer) Close()

Close signals the broadcast goroutine to terminate. Only ever call this if you created the peer yourself via NewPeer. Otherwise let whoever created it clean it up!

func (*Peer) Handshake

func (p *Peer) Handshake() error

Handshake executes the bsc protocol handshake,

func (*Peer) ID

func (p *Peer) ID() string

ID retrieves the peer's unique identifier.

func (*Peer) IsOverLimitAfterReceiving

func (p *Peer) IsOverLimitAfterReceiving() bool

Step into the next period when secondsPerPeriod seconds passed, Otherwise, check whether the number of received votes extra (secondsPerPeriod * receiveRateLimitPerSecond)

func (*Peer) KnownVote

func (p *Peer) KnownVote(hash common.Hash) bool

KnownVote returns whether peer is known to already have a vote.

func (*Peer) Log

func (p *Peer) Log() log.Logger

Log overrides the P2P logget with the higher level one containing only the id.

func (*Peer) RequestBlocksByRange

func (p *Peer) RequestBlocksByRange(startHeight uint64, startHash common.Hash, count uint64) ([]*BlockData, error)

RequestBlocksByRange send GetBlocksByRangeMsg by request start block hash

func (*Peer) Version

func (p *Peer) Version() uint

Version retrieves the peer's negotiated `bsc` protocol version.

type Request

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

type Response

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

type VotesPacket

type VotesPacket struct {
	Votes []*types.VoteEnvelope
}

VotesPacket is the network packet for votes record.

func (*VotesPacket) Kind

func (*VotesPacket) Kind() byte

func (*VotesPacket) Name

func (*VotesPacket) Name() string

Jump to

Keyboard shortcuts

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