mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
Wave 1D of the luxfi/codec final rip: leaf-misc tier under node/.
This batch removes the direct codec/wrappers, codec/linearcodec, and
codec.Manager imports from p2p network protocol, IP/port encoding,
indexer/keystore on-disk storage, warp socket IPC, x/archivedb +
merkledb internals, and the primary-network wallet UTXO loader.
Migration shape:
(a) codec/wrappers.Packer + length constants
→ node/utils/wrappers (same shape, already in tree as the local
canonical home for binary IO helpers). 14 files: indexer/,
network/, utils/ips/, utils/metric/, warp/, x/.
(b) codec.Manager + linearcodec for on-disk container storage
→ hand-rolled big-endian binary marshal/unmarshal. Hard cut;
no codec-version prefix; payload size bounded explicitly:
- indexer/codec.go: marshalContainer/unmarshalContainer
- service/keystore/codec.go: marshalHash/unmarshalHash and
marshalUser/unmarshalUser, 16 MiB blob cap retained.
(c) codec.Manager for cross-chain UTXO parsing (wallet/network/primary)
→ utxo.ParseUTXO via the ZAP wire dispatcher already registered
by node/vms/components/lux. Drops the per-chain codec.Manager
slot from FetchState; AddAllUTXOs no longer takes a codec.
Underscore-import of vms/components/lux ensures the dispatcher
is wired even for callers that don't already pull platformvm.
No snow/snowman/snowball/avalanche/avm/subnet residue introduced.
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package peer
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/luxfi/node/utils/wrappers"
|
|
)
|
|
|
|
var (
|
|
errInvalidMessageLength = errors.New("invalid message length")
|
|
errMaxMessageLengthExceeded = errors.New("maximum message length exceeded")
|
|
)
|
|
|
|
func writeMsgLen(msgLen uint32, maxMsgLen uint32) ([wrappers.IntLen]byte, error) {
|
|
if msgLen > maxMsgLen {
|
|
return [wrappers.IntLen]byte{}, fmt.Errorf(
|
|
"%w; the message length %d exceeds the specified limit %d",
|
|
errMaxMessageLengthExceeded,
|
|
msgLen,
|
|
maxMsgLen,
|
|
)
|
|
}
|
|
|
|
b := [wrappers.IntLen]byte{}
|
|
binary.BigEndian.PutUint32(b[:], msgLen)
|
|
|
|
return b, nil
|
|
}
|
|
|
|
func readMsgLen(b []byte, maxMsgLen uint32) (uint32, error) {
|
|
if len(b) != wrappers.IntLen {
|
|
return 0, fmt.Errorf(
|
|
"%w; readMsgLen only supports 4 bytes (got %d bytes)",
|
|
errInvalidMessageLength,
|
|
len(b),
|
|
)
|
|
}
|
|
|
|
// parse the message length
|
|
msgLen := binary.BigEndian.Uint32(b)
|
|
if msgLen > maxMsgLen {
|
|
return 0, fmt.Errorf(
|
|
"%w; the message length %d exceeds the specified limit %d",
|
|
errMaxMessageLengthExceeded,
|
|
msgLen,
|
|
maxMsgLen,
|
|
)
|
|
}
|
|
|
|
return msgLen, nil
|
|
}
|