Documentation
¶
Overview ¶
Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved. See the file LICENSE for licensing terms.
Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved. See the file LICENSE for licensing terms.
Index ¶
- Constants
- Variables
- func RequestToBytes(marshaler RequestMarshaler, request Request) ([]byte, error)
- type AcceptImplFn
- type BlockRequest
- type BlockResponse
- type BlockSyncSummary
- func (s *BlockSyncSummary) Accept(context.Context) (block.StateSyncMode, error)
- func (s *BlockSyncSummary) Bytes() []byte
- func (s *BlockSyncSummary) GetBlockHash() common.Hash
- func (s *BlockSyncSummary) GetBlockRoot() common.Hash
- func (s *BlockSyncSummary) Height() uint64
- func (s *BlockSyncSummary) ID() ids.ID
- func (s *BlockSyncSummary) String() string
- type BlockSyncSummaryParser
- type BlockSyncSummaryProvider
- type CodeRequest
- type CodeResponse
- type LeafsRequest
- type LeafsResponse
- type Manager
- type NodeType
- type NoopRequestHandler
- func (NoopRequestHandler) HandleBlockRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, request BlockRequest) ([]byte, error)
- func (NoopRequestHandler) HandleCodeRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, ...) ([]byte, error)
- func (NoopRequestHandler) HandleLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, ...) ([]byte, error)
- type Request
- type RequestHandler
- type RequestMarshaler
- type ResponseHandler
- type Syncable
- type SyncableParser
Constants ¶
const ( StateTrieNode = NodeType(1) StateTrieKeyLength = common.HashLength )
const MaxCodeHashesPerRequest = 5
const ( // Version is the current wire version. Increment on any incompatible // schema change. There is no "v0 read fallback" — hard cut, one shape. Version = uint16(0) )
Wire format
All message-package wire blobs are length-prefixed-and-versioned:
[u16 version][... type-specific big-endian fields ...]
Version is currently 0. Slices and byte blobs are length-prefixed with a u32. Fixed-size byte arrays (common.Hash) are emitted as raw bytes. bool is a single byte (0/1). Big-endian throughout. Layout is preserved byte-for-byte against the legacy linearcodec encoding so on-the-wire peers do not need to re-sync.
Variables ¶
var ( ErrUnknownVersion = errors.New("unknown wire version") ErrCantUnpackVersion = errors.New("couldn't unpack version") ErrCantPackVersion = errors.New("couldn't pack version") ErrUnsupportedType = errors.New("unsupported message type") ErrMaxSliceLenExceeded = errors.New("max message size exceeded") )
ErrUnknownVersion is returned by (*manager).Unmarshal when the leading u16 version does not equal Version. Preserved as an exported sentinel for callers that switch on it.
Functions ¶
func RequestToBytes ¶
func RequestToBytes(marshaler RequestMarshaler, request Request) ([]byte, error)
RequestToBytes marshals the given request object into bytes. The `marshaler` argument exists for symmetry with the legacy codec.Manager signature; in-tree callers always pass Codec.
Types ¶
type AcceptImplFn ¶ added in v0.15.50
type AcceptImplFn func(Syncable) (block.StateSyncMode, error)
AcceptImplFn is the accept implementation callback.
type BlockRequest ¶
type BlockRequest struct {
Hash common.Hash `serialize:"true"`
Height uint64 `serialize:"true"`
Parents uint16 `serialize:"true"`
}
BlockRequest is a request to retrieve Parents number of blocks starting from Hash from newest-oldest manner
func (BlockRequest) Handle ¶
func (b BlockRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error)
func (BlockRequest) String ¶
func (b BlockRequest) String() string
type BlockResponse ¶
type BlockResponse struct {
Blocks [][]byte `serialize:"true"`
}
BlockResponse is a response to a BlockRequest Blocks is slice of RLP encoded blocks starting with the block requested in BlockRequest.Hash. The next block is the parent, etc. handler: handlers.BlockRequestHandler
type BlockSyncSummary ¶ added in v0.15.50
type BlockSyncSummary struct {
BlockNumber uint64 `serialize:"true"`
BlockHash common.Hash `serialize:"true"`
BlockRoot common.Hash `serialize:"true"`
// contains filtered or unexported fields
}
BlockSyncSummary provides the information necessary to sync a node starting at the given block.
func NewBlockSyncSummary ¶ added in v0.15.50
func (*BlockSyncSummary) Accept ¶ added in v0.15.50
func (s *BlockSyncSummary) Accept(context.Context) (block.StateSyncMode, error)
func (*BlockSyncSummary) Bytes ¶ added in v0.15.50
func (s *BlockSyncSummary) Bytes() []byte
func (*BlockSyncSummary) GetBlockHash ¶ added in v0.15.50
func (s *BlockSyncSummary) GetBlockHash() common.Hash
func (*BlockSyncSummary) GetBlockRoot ¶ added in v0.15.50
func (s *BlockSyncSummary) GetBlockRoot() common.Hash
func (*BlockSyncSummary) Height ¶ added in v0.15.50
func (s *BlockSyncSummary) Height() uint64
func (*BlockSyncSummary) ID ¶ added in v0.15.50
func (s *BlockSyncSummary) ID() ids.ID
func (*BlockSyncSummary) String ¶ added in v0.15.50
func (s *BlockSyncSummary) String() string
type BlockSyncSummaryParser ¶ added in v0.15.50
type BlockSyncSummaryParser struct{}
func NewBlockSyncSummaryParser ¶ added in v0.15.50
func NewBlockSyncSummaryParser() *BlockSyncSummaryParser
func (*BlockSyncSummaryParser) Parse ¶ added in v0.15.50
func (b *BlockSyncSummaryParser) Parse(summaryBytes []byte, acceptImpl AcceptImplFn) (Syncable, error)
type BlockSyncSummaryProvider ¶ added in v0.15.50
type BlockSyncSummaryProvider struct{}
func (*BlockSyncSummaryProvider) StateSummaryAtBlock ¶ added in v0.15.50
func (a *BlockSyncSummaryProvider) StateSummaryAtBlock(blk *types.Block) (block.StateSummary, error)
StateSummaryAtBlock returns the block state summary at block if valid.
type CodeRequest ¶
type CodeRequest struct {
// Hashes is a list of contract code hashes
Hashes []common.Hash `serialize:"true"`
}
CodeRequest is a request to retrieve a contract code with specified Hash
func NewCodeRequest ¶
func NewCodeRequest(hashes []common.Hash) CodeRequest
func (CodeRequest) Handle ¶
func (c CodeRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error)
func (CodeRequest) String ¶
func (c CodeRequest) String() string
type CodeResponse ¶
type CodeResponse struct {
Data [][]byte `serialize:"true"`
}
CodeResponse is a response to a CodeRequest crypto.Keccak256Hash of each element in Data is expected to equal the corresponding element in CodeRequest.Hashes handler: handlers.CodeRequestHandler
type LeafsRequest ¶
type LeafsRequest struct {
Root common.Hash `serialize:"true"`
Account common.Hash `serialize:"true"`
Start []byte `serialize:"true"`
End []byte `serialize:"true"`
Limit uint16 `serialize:"true"`
NodeType NodeType `serialize:"true"`
}
LeafsRequest is a request to receive trie leaves at specified Root within Start and End byte range Limit outlines maximum number of leaves to returns starting at Start NodeType outlines which trie to read from state/atomic.
func (LeafsRequest) Handle ¶
func (l LeafsRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error)
func (LeafsRequest) String ¶
func (l LeafsRequest) String() string
type LeafsResponse ¶
type LeafsResponse struct {
// Keys and Vals provides the key-value pairs in the trie in the response.
Keys [][]byte `serialize:"true"`
Vals [][]byte `serialize:"true"`
// More indicates if there are more leaves to the right of the last value in this response.
//
// This is not serialized since it is set in the client after verifying the response via
// VerifyRangeProof and determining if there are in fact more leaves to the right of the
// last value in this response.
More bool `serialize:"-"`
// ProofVals contain the edge merkle-proofs for the range of keys included in the response.
// The keys for the proof are simply the keccak256 hashes of the values, so they are not included in the response to save bandwidth.
ProofVals [][]byte `serialize:"true"`
}
LeafsResponse is a response to a LeafsRequest Keys must be within LeafsRequest.Start and LeafsRequest.End and sorted in lexicographical order.
ProofVals must be non-empty and contain a valid range proof unless the key-value pairs in the response are the entire trie. If the key-value pairs make up the entire trie, ProofVals should be empty since the root will be sufficient to prove that the leaves are included in the trie.
More is a flag set in the client after verifying the response, which indicates if the last key-value pair in the response has any more elements to its right within the trie.
type Manager ¶ added in v1.23.2
type Manager interface {
Marshal(version uint16, source interface{}) ([]byte, error)
Unmarshal(bytes []byte, dest interface{}) (uint16, error)
}
Manager is the surface every wire-touching peer of this package needs. It's the smallest method set that lets a caller serialise or parse a message blob — no reflection registry, no codec.Codec sub-interface.
The package singleton Codec implements Manager. Downstream packages (sync/handlers, sync/client, network) should accept Manager in their constructors rather than coupling to a specific concrete type.
var Codec Manager = &manager{maxSize: maxMessageSize}
Codec is the singleton package codec. Callers use Codec.Marshal / Codec.Unmarshal.
type NodeType ¶
type NodeType uint8
NodeType outlines the trie that a leaf node belongs to handlers.LeafsRequestHandler uses this information to determine which trie type to fetch the information from
type NoopRequestHandler ¶
type NoopRequestHandler struct{}
func (NoopRequestHandler) HandleBlockRequest ¶
func (NoopRequestHandler) HandleBlockRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, request BlockRequest) ([]byte, error)
func (NoopRequestHandler) HandleCodeRequest ¶
func (NoopRequestHandler) HandleCodeRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, codeRequest CodeRequest) ([]byte, error)
func (NoopRequestHandler) HandleLeafsRequest ¶ added in v0.15.50
func (NoopRequestHandler) HandleLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest LeafsRequest) ([]byte, error)
type Request ¶
type Request interface {
// Requests should implement String() for logging.
fmt.Stringer
// Handle allows `Request` to call respective methods on handler to handle
// this particular request type
Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error)
}
Request represents a Network request type
type RequestHandler ¶
type RequestHandler interface {
HandleLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest LeafsRequest) ([]byte, error)
HandleBlockRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, request BlockRequest) ([]byte, error)
HandleCodeRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, codeRequest CodeRequest) ([]byte, error)
}
RequestHandler interface handles incoming requests from peers Must have methods in format of handleType(context.Context, ids.NodeID, uint32, request Type) error so that the Request object of relevant Type can invoke its respective handle method on this struct.
type RequestMarshaler ¶ added in v1.23.2
RequestMarshaler is the minimal surface RequestToBytes needs from the package codec. The concrete *manager satisfies it; callers should pass Codec.
type ResponseHandler ¶
type ResponseHandler interface {
// OnResponse is invoked when the peer responded to a request
OnResponse(response []byte) error
// OnFailure is invoked when there was a failure in processing a request
OnFailure() error
}
ResponseHandler handles response for a sent request Only one of OnResponse or OnFailure is called for a given requestID, not both
type Syncable ¶ added in v0.15.50
type Syncable interface {
block.StateSummary
GetBlockHash() common.Hash
GetBlockRoot() common.Hash
}
Syncable extends block.StateSummary with additional getters for coreth.
type SyncableParser ¶ added in v0.15.50
type SyncableParser interface {
Parse(summaryBytes []byte, acceptImpl AcceptImplFn) (Syncable, error)
}
SyncableParser parses byte-encoded summaries.