Files
zeekay 7cf87b230b node-unified is the node
The module already called itself github.com/luxfi/node while containing no node
in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and
the Go column of the matrix measured a VM plugin. A repo that fetches the thing
it claims to be has not replaced it, so the Go sources move in — 1515 files,
the daemon and everything under it — and the build reaches outside this module
for nothing.

Rust and C++ sit beside it unchanged and are still measured against it by the
differential. That is the point of one repo: the reference implementation and
the two ports are the same checkout, so parity is a thing you can run rather
than a thing you assert.

Verified: builds, and the closure carries no lux-private — checked at build time
rather than believed. The daemon starts twelve chains on a local network
(P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
2026-09-07 16:15:25 -07:00

90 lines
2.1 KiB
Go

// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package block
import (
"fmt"
"sync"
"github.com/luxfi/ids"
"github.com/luxfi/zap"
)
type ParseResult struct {
Block Block
Err error
}
// ParseBlocks parses the given raw blocks into tuples of (Block, error).
// Each ParseResult is returned in the same order as its corresponding bytes in the input.
func ParseBlocks(blks [][]byte, chainID ids.ID) []ParseResult {
results := make([]ParseResult, len(blks))
var wg sync.WaitGroup
wg.Add(len(blks))
for i, blk := range blks {
go func(i int, blkBytes []byte) {
defer wg.Done()
results[i].Block, results[i].Err = Parse(blkBytes, chainID)
}(i, blk)
}
wg.Wait()
return results
}
// Parse a block and verify that the signature attached to the block is valid
// for the certificate provided in the block.
func Parse(bytes []byte, chainID ids.ID) (Block, error) {
block, err := ParseWithoutVerification(bytes)
if err != nil {
return nil, err
}
return block, block.verify(chainID)
}
// ParseWithoutVerification parses a block without verifying that the signature
// on the block is correct. Dispatch is the 1-byte blockKind at object offset 0
// of the leading self-delimiting zap message — no codec, no version.
func ParseWithoutVerification(bytes []byte) (Block, error) {
n, err := zapLen(bytes)
if err != nil {
return nil, err
}
msg, err := zap.Parse(bytes[:n])
if err != nil {
return nil, err
}
switch k := blockKind(msg.Root().Uint8(offKind)); k {
case blkSigned:
block := &statelessBlock{}
return block, block.initialize(bytes)
case blkOption:
if n != len(bytes) {
return nil, errNonCanonicalWire
}
block := &option{}
return block, block.initialize(bytes)
default:
return nil, fmt.Errorf("%w: %d", errUnknownBlockType, k)
}
}
func ParseHeader(bytes []byte) (Header, error) {
msg, err := zap.Parse(bytes)
if err != nil {
return nil, err
}
root := msg.Root()
return &statelessHeader{
Chain: ids.ID(read32(root, hdrChain)),
Parent: ids.ID(read32(root, hdrParent)),
Body: ids.ID(read32(root, hdrBody)),
bytes: bytes,
}, nil
}