wit

package
v0.0.2-tenderly Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: GPL-3.0, LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WIT0 = 1
	WIT1 = 2
)

Constants to match up protocol versions and messages

View Source
const (
	NewWitnessMsg         = 0x00
	NewWitnessHashesMsg   = 0x01
	GetMsgWitness         = 0x02
	MsgWitness            = 0x03
	GetWitnessMetadataMsg = 0x04
	WitnessMetadataMsg    = 0x05
)
View Source
const ProtocolName = "wit"

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

Variables

View Source
var ProtocolVersions = []uint{WIT1, WIT0}

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

Functions

func Handle

func Handle(backend Backend, peer *Peer) error

Handle is invoked whenever an `wit` connection is made that successfully passes the protocol handshake. This method will keep processing messages until the connection is torn down.

func MakeProtocols

func MakeProtocols(backend Backend, network uint64) []p2p.Protocol

MakeProtocols constructs the P2P protocol definitions for `wit`.

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 Decoder

type Decoder interface {
	Decode(val interface{}) error
	Time() time.Time
}

type GetWitnessMetadataPacket

type GetWitnessMetadataPacket struct {
	RequestId uint64
	*GetWitnessMetadataRequest
}

GetWitnessMetadataPacket represents a witness metadata query with request ID wrapping

type GetWitnessMetadataRequest

type GetWitnessMetadataRequest struct {
	Hashes []common.Hash // Block hashes to get metadata for
}

GetWitnessMetadataRequest represents a request for witness metadata (just page count, no data)

func (*GetWitnessMetadataRequest) Kind

func (w *GetWitnessMetadataRequest) Kind() byte

func (*GetWitnessMetadataRequest) Name

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

type Handler func(peer *Peer) error

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.

func (*KnownCache) Contains

func (k *KnownCache) Contains(hash common.Hash) bool

Contains returns whether the given item is in the set.

type NewWitnessHashesPacket

type NewWitnessHashesPacket struct {
	Hashes  []common.Hash
	Numbers []uint64
}

func (*NewWitnessHashesPacket) Kind

func (w *NewWitnessHashesPacket) Kind() byte

func (*NewWitnessHashesPacket) Name

func (w *NewWitnessHashesPacket) Name() string

type NewWitnessPacket

type NewWitnessPacket struct {
	Witness *stateless.Witness
}

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 NewPeer

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

NewPeer creates a new WIT peer and starts its background processes.

func (*Peer) AddKnownWitness

func (p *Peer) AddKnownWitness(hash common.Hash)

AddKnownWitnesses adds a witness hash to the set of known witness hashes.

func (*Peer) AsyncSendNewWitness

func (p *Peer) AsyncSendNewWitness(witness *stateless.Witness)

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

func (p *Peer) AsyncSendNewWitnessHash(hash common.Hash, number uint64)

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) ID

func (p *Peer) ID() string

ID retrieves the peer's unique identifier.

func (*Peer) KnownWitnessContainsHash

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

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

func (p *Peer) KnownWitnessesContains(witness *stateless.Witness) bool

KnownWitnessesContains checks if a witness is known to be known by this peer.

func (*Peer) KnownWitnessesCount

func (p *Peer) KnownWitnessesCount() int

KnownWitnessesCount returns the number of known witness.

func (*Peer) Log

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

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

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

func (p *Peer) RequestWitnessMetadata(hashes []common.Hash, sink chan *Response) (*Request, error)

RequestWitnessMetadata sends a request to the peer for witness metadata (page count only).

func (*Peer) Version

func (p *Peer) Version() uint

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

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.

func (*Request) Close

func (r *Request) Close() error

Close aborts an in-flight request. Although there's no way to notify the remote peer about the cancellation, this method notifies the dispatcher to discard any late responses.

func (*Request) ID

func (r *Request) ID() uint64

ID returns the request ID for logging purposes

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

type WitnessPacketResponse

type WitnessPacketResponse []WitnessPageResponse

WitnessPacketResponse represents a witness response, to use when we already have the witness rlp encoded.

type WitnessPageRequest

type WitnessPageRequest struct {
	Hash common.Hash // BlockHash
	Page uint64      // Starts on 0
}

type WitnessPageResponse

type WitnessPageResponse struct {
	Data       []byte
	Hash       common.Hash
	Page       uint64 // Starts on 0; If Page >= TotalPages means the request was invalid and the response is an empty data array
	TotalPages uint64 // Length of pages
}

Jump to

Keyboard shortcuts

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