Documentation
¶
Index ¶
- Constants
- func AggregationTopic() string
- func AttestationSubnetTopic(subnetID uint64) string
- func BlockTopic() string
- func BuildGossipTopic(forkDigest, topicName string) string
- func ComputeMessageID(topic string, rawData []byte) []byte
- func DecodeBlocksByRootRequest(payload []byte) ([][32]byte, error)
- func DecodeReqRespPayload(buf []byte) ([]byte, error)
- func DecodeResponse(r io.Reader, maxLen uint32) (byte, []byte, error)
- func DecodeVarint(buf []byte) (uint32, []byte, error)
- func EncodeBlocksByRootRequest(roots [][32]byte) []byte
- func EncodeReqRespPayload(data []byte) []byte
- func EncodeResponse(code byte, data []byte) []byte
- func EncodeVarint(value uint32) []byte
- func LoadBootnodes(path string) ([]multiaddr.Multiaddr, error)
- func ParseENR(enrStr string) (multiaddr.Multiaddr, error)
- func SetClientGitCommit(commit string)
- func SnappyRawDecode(data []byte) ([]byte, error)
- func SnappyRawEncode(data []byte) []byte
- func SubnetID(validatorID, committeeCount uint64) uint64
- func TopicString(kind string) string
- type ENRFields
- type Hooks
- type Host
- func (h *Host) Addrs() []multiaddr.Multiaddr
- func (h *Host) Close()
- func (h *Host) ConnectBootnodes(ctx context.Context, addrs []multiaddr.Multiaddr)
- func (h *Host) ConnectPeer(ctx context.Context, addr multiaddr.Multiaddr) error
- func (h *Host) ConnectedPeers() int
- func (h *Host) FetchBlocksByRange(ctx context.Context, peerID peer.ID, startSlot, count uint64) (blocks []*types.SignedBlock, err error)
- func (h *Host) FetchBlocksByRangeWithRetry(ctx context.Context, excluded map[peer.ID]bool, startSlot, count uint64) ([]*types.SignedBlock, peer.ID, error)
- func (h *Host) FetchBlocksByRoot(ctx context.Context, peerID peer.ID, roots [][32]byte) (blocks []*types.SignedBlock, err error)
- func (h *Host) FetchBlocksByRootBatchWithRetry(ctx context.Context, roots [][32]byte) ([]*types.SignedBlock, [][32]byte, error)
- func (h *Host) FetchBlocksByRootWithRetry(ctx context.Context, roots [][32]byte) ([]*SignedBlockResult, error)
- func (h *Host) JoinTopic(topic string) error
- func (h *Host) LibP2PHost() libp2phost.Host
- func (h *Host) MeshPeerCount() int
- func (h *Host) PeerID() peer.ID
- func (h *Host) Peers() []peer.ID
- func (h *Host) PublishAggregatedAttestation(ctx context.Context, agg *types.SignedAggregatedAttestation) error
- func (h *Host) PublishAttestation(ctx context.Context, att *types.SignedAttestation, committeeCount uint64) error
- func (h *Host) PublishBlock(ctx context.Context, block *types.SignedBlock) error
- func (h *Host) ReannounceSubscriptions() error
- func (h *Host) RegisterReqRespHandlers(statusFn func() *StatusMessage, ...)
- func (h *Host) SendStatusRequest(ctx context.Context, peerID peer.ID, ourStatus *StatusMessage) (*StatusMessage, error)
- func (h *Host) StartBootnodeRedial(ctx context.Context, addrs []multiaddr.Multiaddr)
- func (h *Host) StartGossipListeners(handler MessageHandler)
- func (h *Host) TopicMeshSizes() map[string]int
- type MessageHandler
- type PeerStore
- func (ps *PeerStore) AddNew(id peer.ID) bool
- func (ps *PeerStore) AllPeers() []peer.ID
- func (ps *PeerStore) Count() int
- func (ps *PeerStore) RecordRequest(id peer.ID, success bool)
- func (ps *PeerStore) Remove(id peer.ID)
- func (ps *PeerStore) SelectPeer(exclude map[peer.ID]bool, minSlot uint64) peer.ID
- func (ps *PeerStore) UpdateStatus(id peer.ID, headSlot uint64)
- type SignedBlockResult
- type StatusMessage
- type Verdict
Constants ¶
const ( MaxPayloadSize = 10 * 1024 * 1024 MaxCompressedPayloadSize = 32 + MaxPayloadSize + MaxPayloadSize/6 + 1024 MaxErrorMessageSize = 256 // MaxSignedBlockSize is the SSZ size of a SignedBlock with every list and // bitlist at its limit. A block response chunk declaring more cannot decode. MaxSignedBlockSize = 3_182_692 )
const ( RespSuccess byte = 0x00 RespInvalidRequest byte = 0x01 RespServerError byte = 0x02 )
const ( StatusProtocol = "/leanconsensus/req/status/1/ssz_snappy" BlocksByRootProtocol = "/leanconsensus/req/blocks_by_root/1/ssz_snappy" BlocksByRangeProtocol = "/leanconsensus/req/blocks_by_range/1/ssz_snappy" )
const ( MaxFetchRetries = 10 InitialBackoffMs = 5 BackoffMultiplier = 2 MaxBlocksPerRequest = 10 )
const ( GossipMeshN = 8 GossipMeshNLow = 6 GossipMeshNHigh = 12 GossipLazy = 6 GossipHeartbeatInterval = 700 * time.Millisecond GossipFanoutTTL = 60 * time.Second GossipHistoryLength = 6 GossipHistoryGossip = 3 GossipDuplicateCache = 24 * time.Second GossipMaxTransmitSize = MaxCompressedPayloadSize GossipMaxMsgPerRPC = 500 // GossipValidateQueueSize bounds messages waiting for validation. pubsub's // default of 32 drops anything beyond one small burst, silently; this holds // several full RPCs. GossipValidateQueueSize = 4 * GossipMaxMsgPerRPC )
const ( BlockTopicKind = "block" AttestationTopicKind = "attestation" AggregationTopicKind = "aggregation" )
const BootnodeRedialSecs = 12
const ForkDigest = "12345678"
const ReqRespTimeout = 15 * time.Second
ReqRespTimeout is the idle deadline applied to each individual req/resp read and write (see deadline.go). It bounds how long a single stalled operation may block, not the whole exchange — a transfer that keeps making progress is never cut.
Variables ¶
This section is empty.
Functions ¶
func AggregationTopic ¶
func AggregationTopic() string
func AttestationSubnetTopic ¶
func BlockTopic ¶
func BlockTopic() string
func BuildGossipTopic ¶
func ComputeMessageID ¶
func DecodeReqRespPayload ¶
func EncodeReqRespPayload ¶
func EncodeResponse ¶
func EncodeVarint ¶
func SetClientGitCommit ¶
func SetClientGitCommit(commit string)
func SnappyRawDecode ¶
func SnappyRawEncode ¶
func TopicString ¶
Types ¶
type Host ¶
type Host struct {
Hooks Hooks
// contains filtered or unexported fields
}
func (*Host) Close ¶
func (h *Host) Close()
Close shuts the host down and waits for its gossip listeners, req/resp handlers and other goroutines to return.
func (*Host) ConnectBootnodes ¶
func (*Host) ConnectPeer ¶
func (*Host) ConnectedPeers ¶
func (*Host) FetchBlocksByRange ¶
func (*Host) FetchBlocksByRangeWithRetry ¶
func (h *Host) FetchBlocksByRangeWithRetry( ctx context.Context, excluded map[peer.ID]bool, startSlot, count uint64, ) ([]*types.SignedBlock, peer.ID, error)
FetchBlocksByRangeWithRetry asks peers outside excluded for the range, picked by score and preferring those whose status covers its last slot, and returns the first non-empty response with the peer that served it. Each peer that fails is added to excluded, so a caller fetching several batches can keep it for all of them.
func (*Host) FetchBlocksByRoot ¶
func (*Host) FetchBlocksByRootBatchWithRetry ¶
func (*Host) FetchBlocksByRootWithRetry ¶
func (*Host) LibP2PHost ¶
func (h *Host) LibP2PHost() libp2phost.Host
func (*Host) MeshPeerCount ¶
func (*Host) PublishAggregatedAttestation ¶
func (*Host) PublishAttestation ¶
func (*Host) PublishBlock ¶
func (*Host) ReannounceSubscriptions ¶
func (*Host) RegisterReqRespHandlers ¶
func (h *Host) RegisterReqRespHandlers( statusFn func() *StatusMessage, blockByRootFn func(root [32]byte) *types.SignedBlock, currentSlotFn func() uint64, blocksInRangeFn func(startSlot, count uint64) ([]*types.SignedBlock, bool), )
func (*Host) SendStatusRequest ¶
func (h *Host) SendStatusRequest(ctx context.Context, peerID peer.ID, ourStatus *StatusMessage) (*StatusMessage, error)
func (*Host) StartBootnodeRedial ¶
func (*Host) StartGossipListeners ¶
func (h *Host) StartGossipListeners(handler MessageHandler)
func (*Host) TopicMeshSizes ¶
type MessageHandler ¶
type MessageHandler interface {
OnBlock(block *types.SignedBlock)
OnGossipAttestation(att *types.SignedAttestation)
OnGossipAggregatedAttestation(agg *types.SignedAggregatedAttestation)
// The Validate methods run on pubsub's validation goroutines, concurrently
// with each other and with the node's own loop.
ValidateGossipBlock(block *types.SignedBlock) Verdict
ValidateGossipAttestation(att *types.SignedAttestation) Verdict
ValidateGossipAggregatedAttestation(agg *types.SignedAggregatedAttestation) Verdict
}
type PeerStore ¶
type PeerStore struct {
// contains filtered or unexported fields
}
func NewPeerStore ¶
func NewPeerStore() *PeerStore
func (*PeerStore) AddNew ¶
AddNew tracks a peer at the initial score and reports whether it was new.
func (*PeerStore) RecordRequest ¶
RecordRequest adjusts a tracked peer's score for one block request. The score gauge changes under the same lock as the peer set, so a peer removed concurrently cannot leave its series behind.
func (*PeerStore) SelectPeer ¶
SelectPeer picks a peer outside exclude at random, weighted by score. With minSlot above zero it prefers peers whose reported head reaches minSlot and falls back to any peer when none does, since a status can be stale.
type SignedBlockResult ¶
type SignedBlockResult struct {
Root [32]byte
Block []*types.SignedBlock
Err error
}
type StatusMessage ¶
type StatusMessage struct {
FinalizedRoot [32]byte
FinalizedSlot uint64
HeadRoot [32]byte
HeadSlot uint64
}
func (*StatusMessage) MarshalSSZ ¶
func (s *StatusMessage) MarshalSSZ() []byte
func (*StatusMessage) UnmarshalSSZ ¶
func (s *StatusMessage) UnmarshalSSZ(buf []byte) error