vms/proposervm: rip luxfi/codec via pcodecs (wave 2D)

Five files migrated:
  proposervm/state/codec.go    — singleton via pcodecs.Manager+helpers
  proposervm/summary/codec.go  — singleton via pcodecs.Manager+helpers
  proposervm/block/codec.go    — singleton via pcodecs.Manager+helpers
  proposervm/batched_vm.go     — wrappers.IntLen → pcodecs.IntLen
  proposervm/proposer/windower.go — wrappers.Packer → pcodecs.Packer
  proposervm/state/block_state.go — wrappers.IntLen → pcodecs.IntLen
  proposervm/block/block.go    — wrappers.IntLen → pcodecs.IntLen
  proposervm/block/build.go    — wrappers.IntLen → pcodecs.IntLen

Tests:
  proposervm/block/parse_test.go    — wrappers.ErrInsufficientLength
                                       + codec.ErrUnknownVersion
                                       → pcodecs.{ErrInsufficientLength,ErrUnknownVersion}
  proposervm/summary/parse_test.go  — codec.ErrUnknownVersion → pcodecs

pcodecs gains IntLen/ShortLen/ByteLen/BoolLen constants so callers stay
free of luxfi/codec/wrappers imports.

build: go build ./vms/proposervm/...
test: go test ./vms/proposervm/...

zero direct luxfi/codec imports remain in vms/proposervm.
This commit is contained in:
Hanzo AI
2026-06-06 02:36:12 -07:00
parent 562b6028c7
commit cb85cd6f2e
11 changed files with 47 additions and 41 deletions
+14
View File
@@ -88,6 +88,20 @@ var (
// — 8 bytes). Used by index code to size cursor buffers.
const LongLen = wrappers.LongLen
// IntLen re-exports wrappers.IntLen (the on-wire length of a uint32
// — 4 bytes). Used by p2p response-size accounting code.
const IntLen = wrappers.IntLen
// ShortLen re-exports wrappers.ShortLen (the on-wire length of a uint16
// — 2 bytes).
const ShortLen = wrappers.ShortLen
// ByteLen re-exports wrappers.ByteLen (1).
const ByteLen = wrappers.ByteLen
// BoolLen re-exports wrappers.BoolLen (1).
const BoolLen = wrappers.BoolLen
// NewLinearCodec returns a fresh linearcodec-backed Codec instance with
// the default tag set. Mirrors linearcodec.NewDefault().
func NewLinearCodec() LinearCodec {
+3 -3
View File
@@ -7,10 +7,10 @@ import (
"context"
"time"
"github.com/luxfi/codec/wrappers"
chain "github.com/luxfi/vm/chain"
"github.com/luxfi/ids"
"github.com/luxfi/node/vms/pcodecs"
statelessblock "github.com/luxfi/node/vms/proposervm/block"
)
@@ -42,10 +42,10 @@ func (vm *VM) GetAncestors(
blkBytes := blk.Bytes()
// Ensure response size isn't too large. Include wrappers.IntLen because
// Ensure response size isn't too large. Include pcodecs.IntLen because
// the size of the message is included with each container, and the size
// is repr. by an int.
currentByteLength += wrappers.IntLen + len(blkBytes)
currentByteLength += pcodecs.IntLen + len(blkBytes)
elapsedTime := vm.Clock.Time().Sub(startTime)
if len(res) > 0 && (currentByteLength >= maxBlocksSize || maxBlocksRetrievalTime <= elapsedTime) {
return res, nil // reached maximum size or ran out of time
+3 -3
View File
@@ -8,10 +8,10 @@ import (
"fmt"
"time"
"github.com/luxfi/crypto/hash"
"github.com/luxfi/ids"
"github.com/luxfi/node/staking"
"github.com/luxfi/crypto/hash"
"github.com/luxfi/codec/wrappers"
"github.com/luxfi/node/vms/pcodecs"
)
var (
@@ -104,7 +104,7 @@ func (b *statelessBlock) initialize(bytes []byte) error {
// The serialized form of the block is the unsignedBytes followed by the
// signature, which is prefixed by a uint32. So, we need to strip off the
// signature as well as it's length prefix to get the unsigned bytes.
lenUnsignedBytes := len(bytes) - wrappers.IntLen - len(b.Signature)
lenUnsignedBytes := len(bytes) - pcodecs.IntLen - len(b.Signature)
unsignedBytes := bytes[:lenUnsignedBytes]
b.id = hash.ComputeHash256Array(unsignedBytes)
+3 -3
View File
@@ -8,10 +8,10 @@ import (
"crypto/rand"
"time"
"github.com/luxfi/crypto/hash"
"github.com/luxfi/ids"
"github.com/luxfi/node/staking"
"github.com/luxfi/crypto/hash"
"github.com/luxfi/codec/wrappers"
"github.com/luxfi/node/vms/pcodecs"
)
func BuildUnsigned(
@@ -78,7 +78,7 @@ func Build(
// signature, which is prefixed by a uint32. Because we are marshalling the
// block with an empty signature, we only need to strip off the length
// prefix to get the unsigned bytes.
lenUnsignedBytes := len(unsignedBytesWithEmptySignature) - wrappers.IntLen
lenUnsignedBytes := len(unsignedBytesWithEmptySignature) - pcodecs.IntLen
unsignedBytes := unsignedBytesWithEmptySignature[:lenUnsignedBytes]
block.id = hash.ComputeHash256Array(unsignedBytes)
+4 -6
View File
@@ -5,21 +5,19 @@ package block
import (
"errors"
"math"
"github.com/luxfi/codec"
"github.com/luxfi/codec/linearcodec"
"github.com/luxfi/node/vms/pcodecs"
)
const CodecVersion = 0
var Codec codec.Manager
var Codec pcodecs.Manager
func init() {
lc := linearcodec.NewDefault()
lc := pcodecs.NewLinearCodec()
// The maximum block size is enforced by the p2p message size limit.
// See: [constants.DefaultMaxMessageSize]
Codec = codec.NewManager(math.MaxInt)
Codec = pcodecs.NewMaxIntManager()
err := errors.Join(
lc.RegisterType(&statelessBlock{}),
+5 -6
View File
@@ -11,10 +11,9 @@ import (
"github.com/stretchr/testify/require"
"github.com/luxfi/codec"
"github.com/luxfi/ids"
"github.com/luxfi/node/staking"
"github.com/luxfi/codec/wrappers"
"github.com/luxfi/node/vms/pcodecs"
)
func TestParseBlocks(t *testing.T) {
@@ -55,12 +54,12 @@ func TestParseBlocks(t *testing.T) {
{
name: "ValidThenInvalid",
input: [][]byte{signedBlockBytes, malformedBlockBytes},
output: []ParseResult{{Block: &statelessBlock{bytes: signedBlockBytes}}, {Err: wrappers.ErrInsufficientLength}},
output: []ParseResult{{Block: &statelessBlock{bytes: signedBlockBytes}}, {Err: pcodecs.ErrInsufficientLength}},
},
{
name: "InvalidThenValid",
input: [][]byte{malformedBlockBytes, signedBlockBytes},
output: []ParseResult{{Err: wrappers.ErrInsufficientLength}, {Block: &statelessBlock{bytes: signedBlockBytes}}},
output: []ParseResult{{Err: pcodecs.ErrInsufficientLength}, {Block: &statelessBlock{bytes: signedBlockBytes}}},
},
} {
t.Run(testCase.name, func(t *testing.T) {
@@ -183,12 +182,12 @@ func TestParseBytes(t *testing.T) {
{
name: "duplicate extensions in certificate",
hex: "0000000000000100000000000000000000000000000000000000000000000000000000000000000000000000007b0000000000000002000004bd308204b9308202a1a003020102020100300d06092a864886f70d01010b050030003020170d3939313233313030303030305a180f32313232303830333233323835335a300030820222300d06092a864886f70d01010105000382020f003082020a0282020100c2b2de1c16924d9b9254a0d5b80a4bc5f9beaa4f4f40a0e4efb69eb9b55d7d37f8c82328c237d7c5b451f5427b487284fa3f365f9caa53c7fcfef8d7a461d743bd7d88129f2da62b877ebe9d6feabf1bd12923e6c12321382c782fc3bb6b6cb4986a937a1edc3814f4e621e1a62053deea8c7649e43edd97ab6b56315b00d9ab5026bb9c31fb042dc574ba83c54e720e0120fcba2e8a66b77839be3ece0d4a6383ef3f76aac952b49a15b65e18674cd1340c32cecbcbaf80ae45be001366cb56836575fb0ab51ea44bf7278817e99b6b180fdd110a49831a132968489822c56692161bbd372cf89d9b8ee5a734cff15303b3a960ee78d79e76662a701941d9ec084429f26707f767e9b1d43241c0e4f96655d95c1f4f4aa00add78eff6bf0a6982766a035bf0b465786632c5bb240788ca0fdf032d8815899353ea4bec5848fd30118711e5b356bde8a0da074cc25709623225e734ff5bd0cf65c40d9fd8fccf746d8f8f35145bcebcf378d2b086e57d78b11e84f47fa467c4d037f92bff6dd4e934e0189b58193f24c4222ffb72b5c06361cf68ca64345bc3e230cc0f40063ad5f45b1659c643662996328c2eeddcd760d6f7c9cbae081ccc065844f7ea78c858564a408979764de882793706acc67d88092790dff567ed914b03355330932616a0f26f994b963791f0b1dbd8df979db86d1ea490700a3120293c3c2b10bef10203010001a33c303a300e0603551d0f0101ff0404030204b030130603551d25040c300a06082b0601050507030230130603551d25040c300a06082b06010505070302300d06092a864886f70d01010b05000382020100a21a0d73ec9ef4eb39f810557ac70b0b775772b8bae5f42c98565bc50b5b2c57317aa9cb1da12f55d0aac7bb36a00cd4fd0d7384c4efa284b53520c5a3c4b8a65240b393eeab02c802ea146c0728c3481c9e8d3aaad9d4dd7607103dcfaa96da83460adbe18174ed5b71bde7b0a93d4fb52234a9ff54e3fd25c5b74790dfb090f2e59dc5907357f510cc3a0b70ccdb87aee214def794b316224f318b471ffa13b66e44b467670e881cb1628c99c048a503376d9b6d7b8eef2e7be47ff7d5c1d56221f4cf7fa2519b594cb5917815c64dc75d8d281bcc99b5a12899b08f2ca0f189857b64a1afc5963337f3dd6e79390e85221569f6dbbb13aadce06a3dfb5032f0cc454809627872cd7cd0cea5eba187723f07652c8abc3fc42bd62136fc66287f2cc19a7cb416923ad1862d7f820b55cacb65e43731cb6df780e2651e457a3438456aeeeb278ad9c0ad2e760f6c1cbe276eeb621c8a4e609b5f2d902beb3212e3e45df99497021ff536d0b56390c5d785a8bf7909f6b61bdc705d7d92ae22f58e7b075f164a0450d82d8286bf449072751636ab5185f59f518b845a75d112d6f7b65223479202cff67635e2ad88106bc8a0cc9352d87c5b182ac19a4680a958d814a093acf46730f87da0df6926291d02590f215041b44a0a1a32eeb3a52cddabc3d256689bace18a8d85e644cf9137cce3718f7caac1cb16ae06e874f4c701000000010300000200b8e3a4d9a4394bac714cb597f5ba1a81865185e35c782d0317e7abc0b52d49ff8e10f787bedf86f08148e3dbd2d2d478caa2a2893d31db7d5ee51339883fe84d3004440f16cb3797a7fab0f627d3ebd79217e995488e785cd6bb7b96b9d306f8109daa9cfc4162f9839f60fb965bcb3b56a5fa787549c153a4c80027398f73a617b90b7f24f437b140cd3ac832c0b75ec98b9423b275782988a9fd426937b8f82fbb0e88a622934643fb6335c1a080a4d13125544b04585d5f5295be7cd2c8be364246ea3d5df3e837b39a85074575a1fa2f4799050460110bdfb20795c8a9172a20f61b95e1c5c43eccd0c2c155b67385366142c63409cb3fb488e7aba6c8930f7f151abf1c24a54bd21c3f7a06856ea9db35beddecb30d2c61f533a3d0590bdbb438c6f2a2286dfc3c71b383354f0abad72771c2cc3687b50c2298783e53857cf26058ed78d0c1cf53786eb8d006a058ee3c85a7b2b836b5d03ef782709ce8f2725548e557b3de45a395a669a15f1d910e97015d22ac70020cab7e2531e8b1f739b023b49e742203e9e19a7fe0053826a9a2fe2e118d3b83498c2cb308573202ad41aa4a390aee4b6b5dd2164e5c5cd1b5f68b7d5632cf7dbb9a9139663c9aac53a74b2c6fc73cad80e228a186ba027f6f32f0182d62503e04fcced385f2e7d2e11c00940622ebd533b4d144689082f9777e5b16c36f9af9066e0ad6564d43",
expectedErr: wrappers.ErrInsufficientLength,
expectedErr: pcodecs.ErrInsufficientLength,
},
{
name: "gibberish",
hex: "000102030405",
expectedErr: codec.ErrUnknownVersion,
expectedErr: pcodecs.ErrUnknownVersion,
},
}
for _, test := range tests {
+3 -3
View File
@@ -12,11 +12,11 @@ import (
"gonum.org/v1/gonum/mathext/prng"
validators "github.com/luxfi/validators"
"github.com/luxfi/container/sampler"
"github.com/luxfi/ids"
"github.com/luxfi/math"
"github.com/luxfi/node/vms/pcodecs"
"github.com/luxfi/utils"
"github.com/luxfi/container/sampler"
"github.com/luxfi/codec/wrappers"
)
// Proposer list constants
@@ -106,7 +106,7 @@ type windower struct {
}
func New(state validators.State, netID, chainID ids.ID) Windower {
w := wrappers.Packer{Bytes: chainID[:]}
w := pcodecs.Packer{Bytes: chainID[:]}
return &windower{
state: state,
netID: netID,
+2 -2
View File
@@ -14,8 +14,8 @@ import (
"github.com/luxfi/node/cache"
"github.com/luxfi/node/cache/lru"
"github.com/luxfi/node/cache/metercacher"
"github.com/luxfi/node/vms/pcodecs"
"github.com/luxfi/node/vms/proposervm/block"
"github.com/luxfi/codec/wrappers"
)
const blockCacheSize = 64 * constants.MiB
@@ -52,7 +52,7 @@ func cachedBlockSize(_ ids.ID, bw *blockWrapper) int {
if bw == nil {
return ids.IDLen + constants.PointerOverhead
}
return ids.IDLen + len(bw.Block) + wrappers.IntLen + 2*constants.PointerOverhead
return ids.IDLen + len(bw.Block) + pcodecs.IntLen + 2*constants.PointerOverhead
}
func NewBlockState(db database.Database) BlockState {
+4 -7
View File
@@ -4,19 +4,16 @@
package state
import (
"math"
"github.com/luxfi/codec"
"github.com/luxfi/codec/linearcodec"
"github.com/luxfi/node/vms/pcodecs"
)
const CodecVersion = 0
var Codec codec.Manager
var Codec pcodecs.Manager
func init() {
lc := linearcodec.NewDefault()
Codec = codec.NewManager(math.MaxInt32)
lc := pcodecs.NewLinearCodec()
Codec = pcodecs.NewMaxInt32Manager()
err := Codec.RegisterCodec(CodecVersion, lc)
if err != nil {
+4 -6
View File
@@ -5,23 +5,21 @@ package summary
import (
"errors"
"math"
"github.com/luxfi/codec"
"github.com/luxfi/codec/linearcodec"
"github.com/luxfi/node/vms/pcodecs"
)
const CodecVersion = 0
var (
Codec codec.Manager
Codec pcodecs.Manager
errWrongCodecVersion = errors.New("wrong codec version")
)
func init() {
lc := linearcodec.NewDefault()
Codec = codec.NewManager(math.MaxInt32)
lc := pcodecs.NewLinearCodec()
Codec = pcodecs.NewMaxInt32Manager()
if err := Codec.RegisterCodec(CodecVersion, lc); err != nil {
panic(err)
}
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/luxfi/codec"
"github.com/luxfi/node/vms/pcodecs"
)
func TestParse(t *testing.T) {
@@ -37,5 +37,5 @@ func TestParseGibberish(t *testing.T) {
bytes := []byte{0, 1, 2, 3, 4, 5}
_, err := Parse(bytes)
require.ErrorIs(err, codec.ErrUnknownVersion)
require.ErrorIs(err, pcodecs.ErrUnknownVersion)
}