Documentation
¶
Index ¶
- Constants
- Variables
- func Handle(backend Backend, peer *Peer) error
- func MakeProtocols(backend Backend, network uint64) []p2p.Protocol
- type Backend
- type Decoder
- type GetWitnessMetadataPacket
- type GetWitnessMetadataRequest
- type GetWitnessPacket
- type GetWitnessRequest
- type Handler
- type KnownCache
- type NewWitnessHashesPacket
- type NewWitnessPacket
- type NodeInfo
- type Packet
- type Peer
- func (p *Peer) AddKnownWitness(hash common.Hash)
- func (p *Peer) AsyncSendNewWitness(witness *stateless.Witness)
- func (p *Peer) AsyncSendNewWitnessHash(hash common.Hash, number uint64)
- func (p *Peer) Close()
- func (p *Peer) ID() string
- func (p *Peer) KnownWitnessContainsHash(hash common.Hash) bool
- func (p *Peer) KnownWitnesses() *KnownCache
- func (p *Peer) KnownWitnessesContains(witness *stateless.Witness) bool
- func (p *Peer) KnownWitnessesCount() int
- func (p *Peer) Log() log.Logger
- func (p *Peer) ReplyWitness(requestID uint64, response *WitnessPacketResponse) error
- func (p *Peer) ReplyWitnessMetadata(requestID uint64, metadata []WitnessMetadataResponse) error
- func (p *Peer) RequestWitness(witnessPages []WitnessPageRequest, sink chan *Response) (*Request, error)
- func (p *Peer) RequestWitnessMetadata(hashes []common.Hash, sink chan *Response) (*Request, error)
- func (p *Peer) Version() uint
- type Request
- type Response
- type WitnessMetadataPacket
- type WitnessMetadataResponse
- type WitnessPacketRLPPacket
- type WitnessPacketResponse
- type WitnessPageRequest
- type WitnessPageResponse
Constants ¶
const ( WIT0 = 1 WIT1 = 2 )
Constants to match up protocol versions and messages
const ( NewWitnessMsg = 0x00 NewWitnessHashesMsg = 0x01 GetMsgWitness = 0x02 MsgWitness = 0x03 GetWitnessMetadataMsg = 0x04 WitnessMetadataMsg = 0x05 )
const ProtocolName = "wit"
ProtocolName is the official short name of the `wit` protocol used during devp2p capability negotiation.
Variables ¶
var ProtocolVersions = []uint{WIT1, WIT0}
ProtocolVersions are the supported versions of the `wit` protocol (first is primary).
Functions ¶
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 `wit` 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 `wit` 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
}
Backend defines the data retrieval methods to serve remote requests and the callback methods to invoke on remote deliveries.
type GetWitnessMetadataPacket ¶
type GetWitnessMetadataPacket struct {
RequestId uint64
*GetWitnessMetadataRequest
}
GetWitnessMetadataPacket represents a witness metadata query with request ID wrapping
type GetWitnessMetadataRequest ¶
GetWitnessMetadataRequest represents a request for witness metadata (just page count, no data)
func (*GetWitnessMetadataRequest) Kind ¶
func (w *GetWitnessMetadataRequest) Kind() byte
func (*GetWitnessMetadataRequest) Name ¶
func (w *GetWitnessMetadataRequest) Name() string
type GetWitnessPacket ¶
type GetWitnessPacket struct {
RequestId uint64
*GetWitnessRequest
}
GetWitnessPacket represents a witness query with request ID wrapping.
type GetWitnessRequest ¶
type GetWitnessRequest struct {
WitnessPages []WitnessPageRequest // Request by list of witness pages
}
GetWitnessRequest represents a list of witnesses query by witness pages.
func (*GetWitnessRequest) Kind ¶
func (w *GetWitnessRequest) Kind() byte
func (*GetWitnessRequest) Name ¶
func (w *GetWitnessRequest) Name() string
type Handler ¶
Handler is a callback to invoke from an outside runner after the boilerplate exchanges have passed.
type KnownCache ¶
type KnownCache struct {
// contains filtered or unexported fields
}
KnownCache is a thread-safe cache for known witness hashes, identified by the hash of the parent witness block. The internal mutex guards the Pop+Add eviction sequence in Add(); individual reads use the underlying thread-safe mapset and do not need external synchronization.
func (*KnownCache) Add ¶
func (k *KnownCache) Add(hash common.Hash)
Add adds a witness to the set, evicting old entries if at capacity.
func (*KnownCache) Cardinality ¶
func (k *KnownCache) Cardinality() int
Cardinality returns the number of elements in the set.
type NewWitnessHashesPacket ¶
func (*NewWitnessHashesPacket) Kind ¶
func (w *NewWitnessHashesPacket) Kind() byte
func (*NewWitnessHashesPacket) Name ¶
func (w *NewWitnessHashesPacket) Name() string
type NewWitnessPacket ¶
func (*NewWitnessPacket) Kind ¶
func (w *NewWitnessPacket) Kind() byte
func (*NewWitnessPacket) Name ¶
func (w *NewWitnessPacket) Name() string
type NodeInfo ¶
type NodeInfo struct {
Network uint64 `json:"network"` // Ethereum network ID (1=Mainnet, Holesky=17000)
Difficulty *big.Int `json:"difficulty"` // Total difficulty of the host's blockchain
Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block
Config *params.ChainConfig `json:"config"` // Chain configuration for the fork rules
Head common.Hash `json:"head"` // Hex hash of the host's best owned block
}
NodeInfo represents a short summary of the `wit` sub-protocol metadata known about the host peer. TODO(@pratikspatil024) - evaluate if we need all these fields
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 `wit` 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 `wit` peer.
func (*Peer) AddKnownWitness ¶
AddKnownWitnesses adds a witness hash to the set of known witness hashes.
func (*Peer) AsyncSendNewWitness ¶
AsyncSendNewWitness queues an entire witness for broadcast to the peer. The witness will be sent in the background to avoid blocking the caller. If the queue is full, the witness will be dropped.
func (*Peer) AsyncSendNewWitnessHash ¶
AsyncSendNewWitnessHash queues witness hash for broadcast to the peer.
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) KnownWitnessContainsHash ¶
func (*Peer) KnownWitnesses ¶
func (p *Peer) KnownWitnesses() *KnownCache
KnownWitnesses retrieves the set of witness hashes known to be known by this peer.
func (*Peer) KnownWitnessesContains ¶
KnownWitnessesContains checks if a witness is known to be known by this peer.
func (*Peer) KnownWitnessesCount ¶
KnownWitnessesCount returns the number of known witness.
func (*Peer) ReplyWitness ¶
func (p *Peer) ReplyWitness(requestID uint64, response *WitnessPacketResponse) error
ReplyWitness is the response to GetWitness
func (*Peer) ReplyWitnessMetadata ¶
func (p *Peer) ReplyWitnessMetadata(requestID uint64, metadata []WitnessMetadataResponse) error
ReplyWitnessMetadata is the response to GetWitnessMetadata
func (*Peer) RequestWitness ¶
func (p *Peer) RequestWitness(witnessPages []WitnessPageRequest, sink chan *Response) (*Request, error)
RequestWitness sends a request to the peer for witnesses by witness pages.
func (*Peer) RequestWitnessMetadata ¶
RequestWitnessMetadata sends a request to the peer for witness metadata (page count only).
type Request ¶
type Request struct {
Peer string // Demultiplexer if cross-peer requests are batched together
Sent time.Time // Timestamp when the request was sent
// contains filtered or unexported fields
}
Request is a pending request to allow tracking it and delivering a response back to the requester on their chosen channel.
type Response ¶
type Response struct {
Req *Request // Original request to cross-reference with
Res interface{} // Remote response for the request query
Meta interface{} // Metadata generated locally on the receiver thread
Time time.Duration // Time it took for the request to be served
Done chan error // Channel to signal message handling to the reader
// contains filtered or unexported fields
}
Response is a reply packet to a previously created request. It is delivered on the channel assigned by the requester subsystem and contains the original request embedded to allow uniquely matching it caller side.
type WitnessMetadataPacket ¶
type WitnessMetadataPacket struct {
RequestId uint64
Metadata []WitnessMetadataResponse
}
WitnessMetadataPacket represents a witness metadata response with request ID wrapping
func (*WitnessMetadataPacket) Kind ¶
func (w *WitnessMetadataPacket) Kind() byte
func (*WitnessMetadataPacket) Name ¶
func (w *WitnessMetadataPacket) Name() string
type WitnessMetadataResponse ¶
type WitnessMetadataResponse struct {
Hash common.Hash
TotalPages uint64 // Total number of pages for this witness
WitnessSize uint64 // Total witness size in bytes
BlockNumber uint64 // Block number this witness belongs to
Available bool // Whether witness exists in database
}
WitnessMetadataResponse represents a single witness metadata response
type WitnessPacketRLPPacket ¶
type WitnessPacketRLPPacket struct {
RequestId uint64
WitnessPacketResponse
}
WitnessPacketRLPPacket represents a witness response with request ID wrapping.
func (*WitnessPacketRLPPacket) Kind ¶
func (*WitnessPacketRLPPacket) Kind() byte
func (*WitnessPacketRLPPacket) Name ¶
func (*WitnessPacketRLPPacket) Name() string
type WitnessPacketResponse ¶
type WitnessPacketResponse []WitnessPageResponse
WitnessPacketResponse represents a witness response, to use when we already have the witness rlp encoded.