mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
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.
86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package message
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/zap"
|
|
)
|
|
|
|
var ErrWrongType = errors.New("wrong payload type")
|
|
|
|
// Payload provides a common interface for all payloads implemented by this
|
|
// package. Each payload is a native-ZAP struct-is-wire object whose first byte
|
|
// is an mkind discriminator (the struct IS the buffer; no codec).
|
|
type Payload interface {
|
|
// Bytes returns the binary representation of this payload.
|
|
//
|
|
// If the payload is not initialized, this method will return nil.
|
|
Bytes() []byte
|
|
|
|
// initialize the payload with the provided binary representation.
|
|
initialize(b []byte)
|
|
}
|
|
|
|
// payload is embedded by all the payloads to provide the common implementation
|
|
// of Payload.
|
|
type payload []byte
|
|
|
|
func (p payload) Bytes() []byte {
|
|
return p
|
|
}
|
|
|
|
func (p *payload) initialize(bytes []byte) {
|
|
*p = bytes
|
|
}
|
|
|
|
// mkind is the 1-byte message-payload discriminator at object offset 0. The
|
|
// values are the on-wire type ids (formerly the linearcodec registration
|
|
// order): ChainToL1Conversion=0, RegisterL1Validator=1,
|
|
// L1ValidatorRegistration=2, L1ValidatorWeight=3. Appending a new payload
|
|
// appends a new id — never reorder.
|
|
type mkind uint8
|
|
|
|
const (
|
|
mkindChainToL1Conversion mkind = 0
|
|
mkindRegisterL1Validator mkind = 1
|
|
mkindL1ValidatorRegistration mkind = 2
|
|
mkindL1ValidatorWeight mkind = 3
|
|
|
|
offMKind = 0
|
|
)
|
|
|
|
func readID(o zap.Object, off int) ids.ID {
|
|
var id ids.ID
|
|
copy(id[:], o.BytesFixedSlice(off, 32))
|
|
return id
|
|
}
|
|
|
|
// Parse dispatches a payload buffer on its mkind discriminator.
|
|
func Parse(bytes []byte) (Payload, error) {
|
|
msg, err := zap.Parse(bytes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
root := msg.Root()
|
|
var p Payload
|
|
switch k := mkind(root.Uint8(offMKind)); k {
|
|
case mkindChainToL1Conversion:
|
|
p = parseChainToL1Conversion(root)
|
|
case mkindRegisterL1Validator:
|
|
p = parseRegisterL1Validator(root)
|
|
case mkindL1ValidatorRegistration:
|
|
p = parseL1ValidatorRegistration(root)
|
|
case mkindL1ValidatorWeight:
|
|
p = parseL1ValidatorWeight(root)
|
|
default:
|
|
return nil, fmt.Errorf("%w: unknown mkind %d", ErrWrongType, k)
|
|
}
|
|
p.initialize(bytes)
|
|
return p, nil
|
|
}
|