node

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Context          context.Context
	Cancel           context.CancelFunc
	ValidatorManager *validator.ValidatorManager
	BlockService     *chain.BlockService
	ProtocolManager  *protocol.Manager
	PeersSet         *peer.PeerSet

	State state.State

	WorkReportGuarantor handlers.WorkReportProcessAndGuarantee

	WorkPackageSharingHandler *handlers.WorkPackageSharingHandler

	ValidatorService         validator.ValidatorService
	StateTrieStore           *store.Trie
	AvailabilityStore        *store.Shards
	TicketStore              *store.Ticket
	SegmentRootToErasureRoot map[crypto.Hash]crypto.Hash
	SegmentRootLookup        work.SegmentRootLookup
	// contains filtered or unexported fields
}

Node manages peer connections, handles protocol messages, and coordinates network operations. Each Node can act as both a client and server, maintaining connections with multiple peers simultaneously.

func NewNode

func NewNode(nodeCtx context.Context, listenAddr *net.UDPAddr, keys validator.ValidatorKeys, state state.State, validatorIdx uint16) (*Node, error)

NewNode creates a new Node instance with the specified configuration. It initializes the TLS certificate, protocol manager, and network transport.

func (*Node) AnnounceBlock

func (n *Node) AnnounceBlock(ctx context.Context, header *block.Header, peer *peer.Peer) error

AnnounceBlock implements the UP 0 block announcement protocol from the JAM spec. It announces a new block to a peer by sending the block header. The announcement also includes the latest finalized block information as required by the protocol.

func (*Node) AuditShardRequestSend

func (n *Node) AuditShardRequestSend(ctx context.Context, peerKey ed25519.PublicKey, erasureRoot crypto.Hash, shardIndex uint16) (bundleShard []byte, justification [][]byte, err error)

AuditShardRequestSend implements the sending side of the CE 138, it opens a connection to the provided peer allowing the auditors to request shards from the assurer

func (*Node) ConnectToNeighbours

func (n *Node) ConnectToNeighbours() error

ConnectToNeighbours connects to all neighbor validators according to the grid structure defined in the JAMNP

func (*Node) ConnectToPeer

func (n *Node) ConnectToPeer(addr *net.UDPAddr) error

ConnectToPeer initiates a connection to a peer at the specified address. It prevents duplicate connections to the same peer.

func (*Node) DistributeTicketToAll

func (n *Node) DistributeTicketToAll(ctx context.Context, ticket block.TicketProof) error

TODO: Timing of ticket distribution and actual execution of the protocol. CE 132 Protocol Requirements: - Proxy validator must send ticket to ALL current validators (broadcast) - Distribution should be evenly spaced over time to avoid network congestion - Should stop if ticket gets included in a finalized block - Timing: Start 3 minutes after connectivity changes, spread until halfway through lottery period

func (*Node) DistributeTicketToPeer

func (n *Node) DistributeTicketToPeer(ctx context.Context, ticket block.TicketProof, peerKey ed25519.PublicKey) error

DistributeTicketToPeer implements the CE 132 Safrole ticket distribute protocol. --> Epoch Index ++ Ticket --> FIN <-- FIN

func (*Node) GetAllPeers

func (n *Node) GetAllPeers() []*peer.Peer

func (*Node) GetByAddress

func (n *Node) GetByAddress(addr string) *peer.Peer

GetByAddress acquires the lock and return peer by address TODO: Temporary workaround for avoiding data race in e2e test. Should be removed after proper test setup is implemented.

func (*Node) GetGuaranteedShardsAndStore

func (n *Node) GetGuaranteedShardsAndStore(ctx context.Context, guarantee block.Guarantee) error

GetGuaranteedShardsAndStore requests the shards from the appropriate guarantors, if shard distribution request fails, will try again for the next guarantor, if unable to get shards from any guarantor will fail

func (*Node) GetProtocols

func (n *Node) GetProtocols() []string

GetProtocols returns the list of supported protocol versions and variants for this node.

func (*Node) OnConnection

func (n *Node) OnConnection(conn *transport.Conn)

OnConnection is called by the transport layer whenever a new QUIC connection is established. This is a callback-style interface where transport.Conn represents an authenticated QUIC connection with a verified peer certificate. The connection flow is:

1. Transport layer accepts QUIC connection 2. TLS handshake completes, peer's Ed25519 key verified 3. Transport calls this OnConnection method 4. We check for existing connection from same peer 5. If exists: Close old connection (This will change soon), cleanup peer state. 6. Create protocol-level connection wrapper 7. Add new peer to connection registry

This design separates transport-level connection handling (TLS, QUIC) from protocol-level peer management (stream handling, peer state).

func (*Node) RequestBlocks

func (n *Node) RequestBlocks(ctx context.Context, hash crypto.Hash, ascending bool, maxBlocks uint32, peerKey ed25519.PublicKey) ([]block.Block, error)

RequestBlocks implements the CE 128 block request protocol from the JAM spec. It requests one or more blocks from a peer, starting with the block identified by the given hash. The direction can be ascending (child blocks) or descending (parent blocks), with a maximum number of blocks to return.

func (*Node) RequestState

func (n *Node) RequestState(ctx context.Context, headerHash crypto.Hash, keyStart [31]byte, keyEnd [31]byte, maxSize uint32, peerKey ed25519.PublicKey) (store.TrieRangeResult, error)

RequestState implements the client side of the CE 129 State Request protocol from the JAMNP. It requests a range of key-value pairs from a block's posterior state from a peer node.

The method finds the specified peer by its Ed25519 public key, opens a stream for a state request, and uses the StateRequester to fetch the state data. The response includes boundary nodes (which form a Merkle proof path) and the requested key-value pairs from the state trie.

Parameters:

  • ctx: Context for the request, used for cancellation and timeouts
  • headerHash: Hash of the block header whose state is being requested
  • keyStart: First key in the requested range (inclusive, 31 bytes)
  • keyEnd: Last key in the requested range (inclusive, 31 bytes)
  • maxSize: Maximum size in bytes for the response
  • peerKey: Ed25519 public key of the peer to request state from

Returns:

  • A TrieRangeResult containing boundary nodes (for Merkle verification) and key-value pairs
  • An error if the request fails or no peer is found with the given key

Key = [u8; 31] (First 31 bytes of key only) Maximum Size = u32 Boundary Node = As returned by B/L, defined in the State Merklization appendix of the GP Value = len++[u8] Node -> Node --> Header Hash ++ Key (Start) ++ Key (End) ++ Maximum Size --> FIN <-- [Boundary Node] <-- [Key ++ Value] <-- FIN

func (*Node) RequestWorkReport

func (n *Node) RequestWorkReport(ctx context.Context, hash crypto.Hash, peerKey ed25519.PublicKey) (*block.WorkReport, error)

RequestWorkReport implements the CE 136 work-report request protocol from the JAM spec. It requests a work report from a peer identified by the given hash.

func (*Node) SegmentShardRequestJustificationSend

func (n *Node) SegmentShardRequestJustificationSend(ctx context.Context, peerKey ed25519.PublicKey, erasureRoot crypto.Hash, shardIndex uint16, segmentIndexes []uint16) (segmentShards [][]byte, justification [][][]byte, err error)

SegmentShardRequestJustificationSend implements the sending side of the CE 140 protocol, opens a connection between the guarantor and assurer allowing the guarantor to reconstruct the segments and to immediately assess the correctness of the response.

func (*Node) SegmentShardRequestSend

func (n *Node) SegmentShardRequestSend(ctx context.Context, peerKey ed25519.PublicKey, erasureRoot crypto.Hash, shardIndex uint16, segmentIndexes []uint16) (segmentShards [][]byte, err error)

SegmentShardRequestSend implements the sending side of the CE 139 protocol, opens a connection between the guarantor and assurer allowing the guarantor to reconstruct the segments

func (*Node) ShardDistributionSend

func (n *Node) ShardDistributionSend(ctx context.Context, peerKey ed25519.PublicKey, coreIndex uint16, erasureRoot crypto.Hash) (bundleShard []byte, segmentShard [][]byte, justification [][]byte, err error)

ShardDistributionSend implements the sending side of the CE 137, it opens a connection to the provided peer allowing the assurers request shards from the guarantor

func (*Node) Start

func (n *Node) Start() error

Start begins the node's network operations, including listening for incoming connections.

func (*Node) Stop

func (n *Node) Stop() error

Stop gracefully shuts down the node's network operations and closes all peer connections.

func (*Node) SubmitTicket

func (n *Node) SubmitTicket(ctx context.Context, ticket block.TicketProof, peerKey ed25519.PublicKey) error

SubmitTicket implements the CE 131 Safrole ticket submission protocol. CE 131 Protocol Flow (Generating Validator -> Proxy Validator):

  1. A validator generates a Safrole ticket for the current epoch
  2. The ticket is sent to a deterministically-selected "proxy" validator
  3. The proxy validator index is determined by: last 4 bytes of ticket's VRF output as big-endian uint32, modulo number of validators
  4. Proxy is selected from the NEXT epoch's validator list

--> Epoch Index ++ Ticket (epoch that ticket will be used in) --> FIN <-- FIN

func (*Node) SubmitWorkPackage

func (n *Node) SubmitWorkPackage(ctx context.Context, coreIndex uint16, pkg work.Package, extrinsics []byte, peerKey ed25519.PublicKey) error

SubmitWorkPackage implements the CE 133 work package submission protocol from the JAMNP. It allows a builder node to submit a work package to a guarantor for processing. The submission includes the core index, work package, and extrinsic data.

func (*Node) UpdateCoreAssignments

func (n *Node) UpdateCoreAssignments() error

UpdateCoreAssignments updates both the current core of this node and the co-guarantors (other validators assigned to the same core). Each validator is assigned to exactly one core per rotation period, and every core is backed by 3 unique validators.

Assignment follows the process defined in the Guarantor Assignment section (11.3): 1. Create a core assignment sequence by evenly mapping validators to cores 2. Shuffle the sequence deterministically using the epochal entropy η2 (for the current epoch guarantors) 3. Apply a rotation offset based on the current timeslot (every 10 blocks) 4. Update our local node’s core index via assignments 5. Identify and register other validators who share that same core and update WorkReportGuarantor handler for CE-134 TODO: Call this during node initialization and periodically to keep core and co-guarantors up to date.

func (*Node) ValidateConnection

func (n *Node) ValidateConnection(tlsState tls.ConnectionState) error

ValidateConnection verifies that an incoming TLS connection meets the protocol requirements, including certificate validation and protocol version checking.

Jump to

Keyboard shortcuts

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