mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
vms/platformvm: rip luxfi/codec via pcodecs (wave 2D — final)
Thirty platformvm files migrated. Every codec.Manager / codec.Registry / linearcodec / wrappers / zapcodec reference inside vms/platformvm now flows through node/vms/pcodecs, completing wave 2D of the codec rip (#101). zero direct luxfi/codec imports remain anywhere in node/vms outside vms/pcodecs/{pcodecs.go,pcodecsmock/manager.go}. Codec construction sites (singletons preserved for external API compatibility — wallet, indexer, network — pcodecs is the construction layer only): platformvm/txs/codec.go — V0+V1 linearcodec + V2 zapcodec via pcodecs.NewLinearCodec / NewZAPCodec / NewDefaultManager / NewMaxInt32Manager helpers platformvm/block/codec.go — v1 + v0 read-only + GenesisCodec via pcodecs helpers platformvm/warp/codec.go — Codec via pcodecs.NewMaxIntManager platformvm/warp/message/codec.go — Codec via pcodecs.NewMaxIntManager platformvm/warp/payload/codec.go — Codec via pcodecs.NewManager platformvm/state/metadata_codec.go — MetadataCodec via pcodecs Production code typed through pcodecs: platformvm/txs/{tx,initial_state,operation}.go — codec.Manager → pcodecs.Manager platformvm/txs/fee/complexity.go — wrappers.{LongLen,IntLen,ShortLen, ByteLen} + codec.VersionSize → pcodecs.{LongLen,IntLen,ShortLen, ByteLen,VersionSize} platformvm/state/{state,codec_helpers,metadata_validator}.go — pcodecs.Manager / pcodecs.Registry / pcodecs.{VersionSize,LongLen,IntLen, BoolLen} platformvm/block/{parse,v0/block}.go — pcodecs.Manager + LinearCodec + Errs platformvm/metrics/metrics.go — wrappers.Errs → pcodecs.Errs platformvm/vm.go — codec.Registry / linearcodec.NewDefault → pcodecs.Registry / pcodecs.NewLinearCodec Tests: platformvm/block/codec_multiversion_test.go — codec.ErrUnknownVersion → pcodecs platformvm/state/{codec_helpers,metadata_validator, metadata_delegator,state_v0_codec}_test.go — codec sentinel errors → pcodecs; linearcodec.NewDefault / codec.NewDefaultManager → pcodecs helpers platformvm/txs/{fee/complexity,tx_fuzz}_test.go — pcodecs.VersionSize / NewLinearCodec / Packer platformvm/warp/{message,unsigned_message}_test.go — pcodecs.ErrUnknownVersion platformvm/warp/message/payload_test.go — pcodecs.ErrUnknownVersion platformvm/warp/payload/{addressed_call,hash,payload}_test.go — pcodecs.ErrUnknownVersion Build: go build ./vms/... Tests: go test ./vms/platformvm/... — all green. Pre-existing failures in vms/xvm (TestTxAcceptAfterParseTx, TestIssueImportTx, TestIssueNFT, TestIssueProperty, TestVerifyFxUsage) are unrelated to wave 2D — they fail on the baseline branch without any change to xvm. Independent fix. Wave 2D complete: - Components: 8 files migrated - Proposervm: 9 files migrated - EVM: 5 files migrated - XSVM: 2 files migrated - RPCchainvm: 1 file migrated - XVM: 18 files migrated - Platformvm: 30 files migrated -- Total: 73 files migrated to pcodecs. vms/pcodecs is the single canonical construction site.
This commit is contained in:
@@ -5,11 +5,8 @@ package block
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/codec/linearcodec"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/block/v0"
|
||||
"github.com/luxfi/node/vms/platformvm/txs"
|
||||
)
|
||||
@@ -41,7 +38,7 @@ var (
|
||||
// 2-byte prefix and selects v0Codec or Codec) because v0 blocks
|
||||
// implement v0.Block, not block.Block — they cannot be unmarshalled
|
||||
// into a block.Block destination. Hence Codec is v1-only by design.
|
||||
Codec codec.Manager
|
||||
Codec pcodecs.Manager
|
||||
|
||||
// GenesisCodec is the unbounded-size codec.Manager used by both
|
||||
// large-genesis decode AND every P-Chain state-side read of
|
||||
@@ -62,39 +59,39 @@ var (
|
||||
// not GenesisCodec.Unmarshal(b, &Block). The v0 slot map registered
|
||||
// here covers the tx + sub-tx slots referenced by serialized state
|
||||
// values (e.g. fx.Owner -> secp256k1fx.OutputOwners).
|
||||
GenesisCodec codec.Manager
|
||||
GenesisCodec pcodecs.Manager
|
||||
|
||||
// v0Codec is the v1.23.x read-only codec.Manager. It registers v0
|
||||
// block + tx slots and unmarshals into v0.Block (the v0 interface),
|
||||
// not block.Block — these are two distinct interface destinations.
|
||||
// External packages MUST NOT Marshal at v0; that is verified at
|
||||
// Parse time (Parse never re-marshals).
|
||||
v0Codec codec.Manager
|
||||
v0Codec pcodecs.Manager
|
||||
|
||||
// v0GenesisCodec mirrors v0Codec at large size.
|
||||
v0GenesisCodec codec.Manager
|
||||
v0GenesisCodec pcodecs.Manager
|
||||
|
||||
// genesisLinearCodec is the underlying v1 codec for GenesisCodec.
|
||||
// This is exposed for registering additional types from other
|
||||
// packages (e.g. state) at the canonical write version.
|
||||
genesisLinearCodec linearcodec.Codec
|
||||
genesisLinearCodec pcodecs.LinearCodec
|
||||
|
||||
// genesisLinearCodecV0 is the underlying v0 codec for GenesisCodec.
|
||||
// Exposed so state-side types that want to be decodable from both
|
||||
// v0 and v1 state bytes can register symmetrically via
|
||||
// RegisterGenesisType.
|
||||
genesisLinearCodecV0 linearcodec.Codec
|
||||
genesisLinearCodecV0 pcodecs.LinearCodec
|
||||
)
|
||||
|
||||
func init() {
|
||||
cV1 := linearcodec.NewDefault()
|
||||
gcV1 := linearcodec.NewDefault()
|
||||
gcV0 := linearcodec.NewDefault()
|
||||
cV0 := linearcodec.NewDefault()
|
||||
gcV0BlockOnly := linearcodec.NewDefault()
|
||||
cV1 := pcodecs.NewLinearCodec()
|
||||
gcV1 := pcodecs.NewLinearCodec()
|
||||
gcV0 := pcodecs.NewLinearCodec()
|
||||
cV0 := pcodecs.NewLinearCodec()
|
||||
gcV0BlockOnly := pcodecs.NewLinearCodec()
|
||||
|
||||
errs := wrappers.Errs{}
|
||||
for _, c := range []linearcodec.Codec{cV1, gcV1} {
|
||||
errs := pcodecs.Errs{}
|
||||
for _, c := range []pcodecs.LinearCodec{cV1, gcV1} {
|
||||
errs.Add(RegisterBlockTypes(c))
|
||||
}
|
||||
// gcV0 carries only the v0 tx slot map (no block types) because
|
||||
@@ -103,14 +100,14 @@ func init() {
|
||||
errs.Add(v0.RegisterTxTypes(gcV0))
|
||||
// cV0 and gcV0BlockOnly carry the full v0 block+tx slot map for
|
||||
// block.Parse's v0 dispatch path.
|
||||
for _, c := range []linearcodec.Codec{cV0, gcV0BlockOnly} {
|
||||
for _, c := range []pcodecs.LinearCodec{cV0, gcV0BlockOnly} {
|
||||
errs.Add(v0.RegisterBlockTypes(c))
|
||||
}
|
||||
|
||||
Codec = codec.NewDefaultManager()
|
||||
GenesisCodec = codec.NewManager(math.MaxInt32)
|
||||
v0Codec = codec.NewDefaultManager()
|
||||
v0GenesisCodec = codec.NewManager(math.MaxInt32)
|
||||
Codec = pcodecs.NewDefaultManager()
|
||||
GenesisCodec = pcodecs.NewMaxInt32Manager()
|
||||
v0Codec = pcodecs.NewDefaultManager()
|
||||
v0GenesisCodec = pcodecs.NewMaxInt32Manager()
|
||||
errs.Add(
|
||||
Codec.RegisterCodec(CodecVersionV1, cV1),
|
||||
// GenesisCodec carries BOTH v0 (read-only) AND v1 (read+write)
|
||||
@@ -152,7 +149,7 @@ func RegisterGenesisType(val interface{}) error {
|
||||
// is exactly one type per block kind: ProposalBlock, AbortBlock,
|
||||
// CommitBlock, StandardBlock. Tx types come from txs.RegisterTypes
|
||||
// (which registers the v1 tx slot layout).
|
||||
func RegisterBlockTypes(targetCodec linearcodec.Codec) error {
|
||||
func RegisterBlockTypes(targetCodec pcodecs.LinearCodec) error {
|
||||
return errors.Join(
|
||||
txs.RegisterTypes(targetCodec),
|
||||
targetCodec.RegisterType(&ProposalBlock{}),
|
||||
|
||||
@@ -10,9 +10,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
|
||||
"github.com/luxfi/node/vms/components/gas"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/txs"
|
||||
)
|
||||
|
||||
@@ -26,7 +25,7 @@ import (
|
||||
// testnet bootstrapped at v1.23.x had written feeState bytes with the
|
||||
// v0 prefix (0x0000); v1.28.0+ called block.GenesisCodec.Unmarshal on
|
||||
// those bytes, codec.Manager looked up version 0 in its map, missed,
|
||||
// and returned codec.ErrUnknownVersion — surfacing as the
|
||||
// and returned pcodecs.ErrUnknownVersion — surfacing as the
|
||||
// "unknown codec version" error at loadMetadata: feeState.
|
||||
//
|
||||
// Post-fix, block.GenesisCodec is multi-version (v0 read-only + v1
|
||||
@@ -47,7 +46,7 @@ func TestGenesisCodecAcceptsV0FeeState(t *testing.T) {
|
||||
require.Equal(uint16(CodecVersionV0), binary.BigEndian.Uint16(v0Bytes[:2]),
|
||||
"marshaled bytes must carry the v0 wire prefix")
|
||||
|
||||
// The bug: this Unmarshal used to fail with codec.ErrUnknownVersion.
|
||||
// The bug: this Unmarshal used to fail with pcodecs.ErrUnknownVersion.
|
||||
var decoded gas.State
|
||||
version, err := GenesisCodec.Unmarshal(v0Bytes, &decoded)
|
||||
require.NoError(err, "v0-prefixed feeState must decode via the multi-version GenesisCodec")
|
||||
@@ -81,7 +80,7 @@ func TestGenesisCodecAcceptsV1FeeState(t *testing.T) {
|
||||
// TestGenesisCodecRejectsUnknownVersion locks in that the multi-version
|
||||
// extension did NOT silently open the door to bogus prefixes. Only v0
|
||||
// and v1 are registered on GenesisCodec; anything else must surface as
|
||||
// codec.ErrUnknownVersion.
|
||||
// pcodecs.ErrUnknownVersion.
|
||||
func TestGenesisCodecRejectsUnknownVersion(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
@@ -90,7 +89,7 @@ func TestGenesisCodecRejectsUnknownVersion(t *testing.T) {
|
||||
|
||||
var sink gas.State
|
||||
_, err := GenesisCodec.Unmarshal(bogus, &sink)
|
||||
require.ErrorIs(err, codec.ErrUnknownVersion)
|
||||
require.ErrorIs(err, pcodecs.ErrUnknownVersion)
|
||||
}
|
||||
|
||||
// TestGenesisCodecV0RoundtripIsBytePreserving documents the byte-
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/block/v0"
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ var ErrShortBytes = errors.New("block bytes too short for codec version prefix")
|
||||
// c must be one of block.Codec or block.GenesisCodec. The v0 codec is
|
||||
// selected internally based on the size class of c. Other codecs are
|
||||
// rejected with codec.ErrUnknownVersion.
|
||||
func Parse(c codec.Manager, b []byte) (Block, error) {
|
||||
func Parse(c pcodecs.Manager, b []byte) (Block, error) {
|
||||
if len(b) < 2 {
|
||||
return nil, ErrShortBytes
|
||||
}
|
||||
@@ -41,14 +41,14 @@ func Parse(c codec.Manager, b []byte) (Block, error) {
|
||||
case CodecVersionV0:
|
||||
return parseV0(c, b)
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %d", codec.ErrUnknownVersion, version)
|
||||
return nil, fmt.Errorf("%w: %d", pcodecs.ErrUnknownVersion, version)
|
||||
}
|
||||
}
|
||||
|
||||
// parseV1 is the canonical block-decode path. Bytes are unmarshalled
|
||||
// against the v1 slot map and the resulting Block keeps b as its
|
||||
// authoritative bytes.
|
||||
func parseV1(c codec.Manager, b []byte) (Block, error) {
|
||||
func parseV1(c pcodecs.Manager, b []byte) (Block, error) {
|
||||
var blk Block
|
||||
if _, err := c.Unmarshal(b, &blk); err != nil {
|
||||
return nil, err
|
||||
@@ -76,7 +76,7 @@ func parseV1(c codec.Manager, b []byte) (Block, error) {
|
||||
// pre-Banff atomic block left on disk should have been replaced by the
|
||||
// Banff history. We return an explicit error so the caller can decide
|
||||
// whether to surface it as DB corruption or as a soft skip.
|
||||
func parseV0(c codec.Manager, b []byte) (Block, error) {
|
||||
func parseV0(c pcodecs.Manager, b []byte) (Block, error) {
|
||||
v0c := v0CodecFor(c)
|
||||
var v0blk v0.Block
|
||||
if _, err := v0c.Unmarshal(b, &v0blk); err != nil {
|
||||
@@ -89,7 +89,7 @@ func parseV0(c codec.Manager, b []byte) (Block, error) {
|
||||
// of c. We mirror the size class so that a GenesisCodec caller (large
|
||||
// max size) gets the v0GenesisCodec (also large) rather than v0Codec
|
||||
// (1 MiB).
|
||||
func v0CodecFor(c codec.Manager) codec.Manager {
|
||||
func v0CodecFor(c pcodecs.Manager) pcodecs.Manager {
|
||||
if c == GenesisCodec {
|
||||
return v0GenesisCodec
|
||||
}
|
||||
|
||||
@@ -22,10 +22,9 @@
|
||||
package v0
|
||||
|
||||
import (
|
||||
"github.com/luxfi/codec/linearcodec"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/node/vms/platformvm/stakeable"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/signer"
|
||||
"github.com/luxfi/node/vms/platformvm/stakeable"
|
||||
"github.com/luxfi/node/vms/platformvm/txs"
|
||||
"github.com/luxfi/utxo/secp256k1fx"
|
||||
)
|
||||
@@ -56,8 +55,8 @@ const CodecVersion uint16 = 0
|
||||
// ConvertNetworkToL1Tx (post-rename source type, identical struct
|
||||
// layout, same slot 35). Codec wire matching is by slot ID, not type
|
||||
// name; the rename did not change the serialized format.
|
||||
func RegisterBlockTypes(c linearcodec.Codec) error {
|
||||
errs := wrappers.Errs{}
|
||||
func RegisterBlockTypes(c pcodecs.LinearCodec) error {
|
||||
errs := pcodecs.Errs{}
|
||||
|
||||
// Slots 0-4: Apricot blocks.
|
||||
errs.Add(
|
||||
@@ -144,8 +143,8 @@ func RegisterBlockTypes(c linearcodec.Codec) error {
|
||||
// used by v1.23.x txs.init(). Apricot block slots (0-4) and Banff block
|
||||
// slots (29-32) are SkipRegistrations rather than RegisterType so that
|
||||
// shared tx slots line up with the block codec.
|
||||
func RegisterTxTypes(c linearcodec.Codec) error {
|
||||
errs := wrappers.Errs{}
|
||||
func RegisterTxTypes(c pcodecs.LinearCodec) error {
|
||||
errs := pcodecs.Errs{}
|
||||
|
||||
// Slots 0-4: Apricot block slots reserved.
|
||||
c.SkipRegistrations(5)
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
"github.com/luxfi/ids"
|
||||
utilmetric "github.com/luxfi/node/utils/metric"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/node/vms/components/gas"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/block"
|
||||
)
|
||||
|
||||
@@ -145,7 +145,7 @@ func New(registerer metric.Registerer) (Metrics, error) {
|
||||
}),
|
||||
}
|
||||
|
||||
errs := wrappers.Errs{Err: err}
|
||||
errs := pcodecs.Errs{Err: err}
|
||||
registry, ok := registerer.(metric.Registry)
|
||||
if !ok {
|
||||
return nil, errors.New("registerer must be a Registry")
|
||||
|
||||
@@ -6,8 +6,8 @@ package state
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/log"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
// probe is a flat struct chosen so its codec walk is the empty walk
|
||||
@@ -36,7 +36,7 @@ type probe struct{}
|
||||
// returns ErrUnknownVersion if and only if version 0 is not registered
|
||||
// in its map. The probe is cheap (a 10-byte Marshal at most) and only
|
||||
// happens on the first observation of each distinct codec pointer.
|
||||
func multiVersionUnmarshal(c codec.Manager, b []byte, dest interface{}) (uint16, error) {
|
||||
func multiVersionUnmarshal(c pcodecs.Manager, b []byte, dest interface{}) (uint16, error) {
|
||||
checkMultiVersion(c)
|
||||
return c.Unmarshal(b, dest)
|
||||
}
|
||||
@@ -45,7 +45,7 @@ var (
|
||||
multiVersionProbeOnce sync.Map // codec.Manager -> struct{}
|
||||
)
|
||||
|
||||
func checkMultiVersion(c codec.Manager) {
|
||||
func checkMultiVersion(c pcodecs.Manager) {
|
||||
if _, observed := multiVersionProbeOnce.LoadOrStore(c, struct{}{}); observed {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -10,10 +10,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/codec/linearcodec"
|
||||
|
||||
"github.com/luxfi/node/vms/components/gas"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/block"
|
||||
)
|
||||
|
||||
@@ -49,14 +47,14 @@ func TestMultiVersionUnmarshalAcceptsBothVersions(t *testing.T) {
|
||||
// We can't directly intercept log.Warn (it's a global logger), so we
|
||||
// instead exercise the underlying probe deterministically: marshaling
|
||||
// the empty `probe` struct at v0 on a single-version codec must return
|
||||
// codec.ErrUnknownVersion. This is the exact condition that triggers
|
||||
// pcodecs.ErrUnknownVersion. This is the exact condition that triggers
|
||||
// the warning emission.
|
||||
func TestMultiVersionUnmarshalSurfacesSingleVersionCodec(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
// Build a single-version codec by hand — only v1 registered.
|
||||
singleC := linearcodec.NewDefault()
|
||||
singleVersion := codec.NewDefaultManager()
|
||||
singleC := pcodecs.NewLinearCodec()
|
||||
singleVersion := pcodecs.NewDefaultManager()
|
||||
require.NoError(singleVersion.RegisterCodec(block.CodecVersionV1, singleC))
|
||||
|
||||
// Confirm v1 Unmarshal still succeeds (helper is non-blocking).
|
||||
@@ -72,7 +70,7 @@ func TestMultiVersionUnmarshalSurfacesSingleVersionCodec(t *testing.T) {
|
||||
// Marshal on this codec returns ErrUnknownVersion, which is what
|
||||
// the post-condition check picks up.
|
||||
_, err = singleVersion.Marshal(block.CodecVersionV0, probe{})
|
||||
require.ErrorIs(err, codec.ErrUnknownVersion,
|
||||
require.ErrorIs(err, pcodecs.ErrUnknownVersion,
|
||||
"single-version codec must surface ErrUnknownVersion on the v0 probe — this is the warning trigger")
|
||||
}
|
||||
|
||||
@@ -84,8 +82,8 @@ func TestMultiVersionUnmarshalSurfacesSingleVersionCodec(t *testing.T) {
|
||||
func TestMultiVersionUnmarshalSurfacesSingleVersionCodec_Idempotent(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
singleC := linearcodec.NewDefault()
|
||||
singleVersion := codec.NewDefaultManager()
|
||||
singleC := pcodecs.NewLinearCodec()
|
||||
singleVersion := pcodecs.NewDefaultManager()
|
||||
require.NoError(singleVersion.RegisterCodec(block.CodecVersionV1, singleC))
|
||||
|
||||
v1Bytes, err := singleVersion.Marshal(block.CodecVersionV1, gas.State{Capacity: 5, Excess: 6})
|
||||
@@ -109,7 +107,7 @@ func TestMultiVersionUnmarshalSurfacesSingleVersionCodec_Idempotent(t *testing.T
|
||||
}
|
||||
|
||||
// TestMultiVersionUnmarshalRejectsUnknownVersionUpstream confirms the
|
||||
// helper does NOT swallow codec.ErrUnknownVersion — if the input bytes
|
||||
// helper does NOT swallow pcodecs.ErrUnknownVersion — if the input bytes
|
||||
// carry a prefix that the codec does not have registered (e.g. a future
|
||||
// codec v2 prefix on a v0+v1 codec), the original error surfaces so the
|
||||
// caller can decide whether to treat it as a corruption or a soft skip.
|
||||
@@ -121,7 +119,7 @@ func TestMultiVersionUnmarshalRejectsUnknownVersionUpstream(t *testing.T) {
|
||||
|
||||
var sink gas.State
|
||||
_, err := multiVersionUnmarshal(block.GenesisCodec, bogus, &sink)
|
||||
require.ErrorIs(err, codec.ErrUnknownVersion)
|
||||
require.ErrorIs(err, pcodecs.ErrUnknownVersion)
|
||||
}
|
||||
|
||||
// TestBlockGenesisCodecPassesMultiVersionProbe pins the post-v1.28.2
|
||||
|
||||
@@ -5,10 +5,8 @@ package state
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/codec/linearcodec"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,12 +17,12 @@ const (
|
||||
CodecVersion1 uint16 = 1
|
||||
)
|
||||
|
||||
var MetadataCodec codec.Manager
|
||||
var MetadataCodec pcodecs.Manager
|
||||
|
||||
func init() {
|
||||
c0 := linearcodec.NewDefault()
|
||||
c1 := linearcodec.NewDefault()
|
||||
MetadataCodec = codec.NewManager(math.MaxInt32)
|
||||
c0 := pcodecs.NewLinearCodec()
|
||||
c1 := pcodecs.NewLinearCodec()
|
||||
MetadataCodec = pcodecs.NewMaxInt32Manager()
|
||||
|
||||
err := errors.Join(
|
||||
MetadataCodec.RegisterCodec(CodecVersion0, c0),
|
||||
|
||||
@@ -8,10 +8,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/database/memdb"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
func TestParseDelegatorMetadata(t *testing.T) {
|
||||
@@ -60,7 +59,7 @@ func TestParseDelegatorMetadata(t *testing.T) {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc8,
|
||||
},
|
||||
expected: nil,
|
||||
expectedErr: codec.ErrUnknownVersion,
|
||||
expectedErr: pcodecs.ErrUnknownVersion,
|
||||
},
|
||||
{
|
||||
name: "short byte len",
|
||||
@@ -73,7 +72,7 @@ func TestParseDelegatorMetadata(t *testing.T) {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
},
|
||||
expected: nil,
|
||||
expectedErr: wrappers.ErrInsufficientLength,
|
||||
expectedErr: pcodecs.ErrInsufficientLength,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -6,25 +6,24 @@ package state
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/database"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/math/set"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
// preDelegateeRewardSize is the size of codec marshalling
|
||||
// [preDelegateeRewardMetadata].
|
||||
//
|
||||
// CodecVersionLen + UpDurationLen + LastUpdatedLen + PotentialRewardLen
|
||||
const preDelegateeRewardSize = codec.VersionSize + 3*wrappers.LongLen
|
||||
const preDelegateeRewardSize = pcodecs.VersionSize + 3*pcodecs.LongLen
|
||||
|
||||
// preStakerStartTimeSize is the size of codec marshalling
|
||||
// [preStakerStartTimeMetadata].
|
||||
//
|
||||
// CodecVersionLen + UpDurationLen + LastUpdatedLen + PotentialRewardLen + PotentialDelegateeRewardLen
|
||||
const preStakerStartTimeSize = codec.VersionSize + 4*wrappers.LongLen
|
||||
const preStakerStartTimeSize = pcodecs.VersionSize + 4*pcodecs.LongLen
|
||||
|
||||
var _ validatorState = (*metadata)(nil)
|
||||
|
||||
|
||||
@@ -9,11 +9,10 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/database"
|
||||
"github.com/luxfi/database/memdb"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
func TestValidatorUptimes(t *testing.T) {
|
||||
@@ -264,7 +263,7 @@ func TestParseValidatorMetadata(t *testing.T) {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x20,
|
||||
},
|
||||
expected: nil,
|
||||
expectedErr: codec.ErrUnknownVersion,
|
||||
expectedErr: pcodecs.ErrUnknownVersion,
|
||||
},
|
||||
{
|
||||
name: "short byte len",
|
||||
@@ -281,7 +280,7 @@ func TestParseValidatorMetadata(t *testing.T) {
|
||||
0x00, 0x00, 0x00, 0x00, 0x4E, 0x20,
|
||||
},
|
||||
expected: nil,
|
||||
expectedErr: wrappers.ErrInsufficientLength,
|
||||
expectedErr: pcodecs.ErrInsufficientLength,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -12,8 +12,7 @@ import (
|
||||
"github.com/google/btree"
|
||||
"github.com/luxfi/metric"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/runtime"
|
||||
validators "github.com/luxfi/validators"
|
||||
"github.com/luxfi/validators/uptime"
|
||||
@@ -260,7 +259,7 @@ type stateBlk struct {
|
||||
|
||||
// RegisterStateBlockType registers the stateBlk type with the given codec.
|
||||
// This is needed for backward compatibility with old block storage format.
|
||||
func RegisterStateBlockType(targetCodec codec.Registry) error {
|
||||
func RegisterStateBlockType(targetCodec pcodecs.Registry) error {
|
||||
return targetCodec.RegisterType(&stateBlk{})
|
||||
}
|
||||
|
||||
@@ -546,7 +545,7 @@ func txAndStatusSize(_ ids.ID, t *txAndStatus) int {
|
||||
if t == nil {
|
||||
return ids.IDLen + constants.PointerOverhead
|
||||
}
|
||||
return ids.IDLen + len(t.tx.Bytes()) + wrappers.IntLen + 2*constants.PointerOverhead
|
||||
return ids.IDLen + len(t.tx.Bytes()) + pcodecs.IntLen + 2*constants.PointerOverhead
|
||||
}
|
||||
|
||||
func blockSize(_ ids.ID, blk block.Block) int {
|
||||
@@ -620,7 +619,7 @@ func New(
|
||||
"l1_validator_weights_cache",
|
||||
reg,
|
||||
lru.NewSizedCache(execCfg.L1WeightsCacheSize, func(ids.ID, uint64) int {
|
||||
return ids.IDLen + wrappers.LongLen
|
||||
return ids.IDLen + pcodecs.LongLen
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
@@ -634,8 +633,8 @@ func New(
|
||||
execCfg.L1InactiveValidatorsCacheSize,
|
||||
func(_ ids.ID, maybeL1Validator maybe.Maybe[L1Validator]) int {
|
||||
const (
|
||||
l1ValidatorOverhead = ids.IDLen + ids.NodeIDLen + 4*wrappers.LongLen + 3*constants.PointerOverhead
|
||||
maybeL1ValidatorOverhead = wrappers.BoolLen + l1ValidatorOverhead
|
||||
l1ValidatorOverhead = ids.IDLen + ids.NodeIDLen + 4*pcodecs.LongLen + 3*constants.PointerOverhead
|
||||
maybeL1ValidatorOverhead = pcodecs.BoolLen + l1ValidatorOverhead
|
||||
entryOverhead = ids.IDLen + maybeL1ValidatorOverhead
|
||||
)
|
||||
if maybeL1Validator.IsNothing() {
|
||||
@@ -655,7 +654,7 @@ func New(
|
||||
"l1_validator_chain_id_node_id_cache",
|
||||
reg,
|
||||
lru.NewSizedCache(execCfg.L1ChainIDNodeIDCacheSize, func(chainIDNodeID, bool) int {
|
||||
return ids.IDLen + ids.NodeIDLen + wrappers.BoolLen
|
||||
return ids.IDLen + ids.NodeIDLen + pcodecs.BoolLen
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/ids"
|
||||
|
||||
"github.com/luxfi/node/vms/components/gas"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/block"
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
// failed on the v1.28.1 testnet-canary:
|
||||
//
|
||||
// loadMetadata → getFeeState → block.GenesisCodec.Unmarshal(v0Bytes, &feeState)
|
||||
// → codec.ErrUnknownVersion (unknown codec version)
|
||||
// → pcodecs.ErrUnknownVersion (unknown codec version)
|
||||
//
|
||||
// The fixture is byte-for-byte what v1.23.x wrote to singletonDB at the
|
||||
// FeeStateKey: 2 bytes wire prefix (0x0000) + 8 bytes Capacity + 8 bytes
|
||||
@@ -250,5 +250,5 @@ func TestStateCodecRejectsUnknownVersion(t *testing.T) {
|
||||
|
||||
var sink gas.State
|
||||
_, err := block.GenesisCodec.Unmarshal(bogus, &sink)
|
||||
require.ErrorIs(err, codec.ErrUnknownVersion)
|
||||
require.ErrorIs(err, pcodecs.ErrUnknownVersion)
|
||||
}
|
||||
|
||||
+16
-20
@@ -5,12 +5,8 @@ package txs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/codec/linearcodec"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/codec/zapcodec"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/signer"
|
||||
"github.com/luxfi/node/vms/platformvm/stakeable"
|
||||
"github.com/luxfi/utxo/secp256k1fx"
|
||||
@@ -57,25 +53,25 @@ var (
|
||||
// Registers V0 + V1 (linearcodec) AND V2 (zapcodec). The right write
|
||||
// version is selected via CodecVersionForTimestamp; reads dispatch on
|
||||
// the 2-byte wire prefix.
|
||||
Codec codec.Manager
|
||||
Codec pcodecs.Manager
|
||||
|
||||
// GenesisCodec allows txs of larger than usual size to be parsed.
|
||||
// It registers the same versioned slot layouts as Codec but with an
|
||||
// unbounded maximum size. New, unverified txs MUST be processed by
|
||||
// Codec; GenesisCodec is reserved for genesis decode + state read
|
||||
// fallback paths.
|
||||
GenesisCodec codec.Manager
|
||||
GenesisCodec pcodecs.Manager
|
||||
)
|
||||
|
||||
func init() {
|
||||
cV0 := linearcodec.NewDefault()
|
||||
cV1 := linearcodec.NewDefault()
|
||||
cV2 := zapcodec.NewDefault()
|
||||
gcV0 := linearcodec.NewDefault()
|
||||
gcV1 := linearcodec.NewDefault()
|
||||
gcV2 := zapcodec.NewDefault()
|
||||
cV0 := pcodecs.NewLinearCodec()
|
||||
cV1 := pcodecs.NewLinearCodec()
|
||||
cV2 := pcodecs.NewZAPCodec()
|
||||
gcV0 := pcodecs.NewLinearCodec()
|
||||
gcV1 := pcodecs.NewLinearCodec()
|
||||
gcV2 := pcodecs.NewZAPCodec()
|
||||
|
||||
errs := wrappers.Errs{}
|
||||
errs := pcodecs.Errs{}
|
||||
errs.Add(
|
||||
registerV0TxTypes(cV0),
|
||||
registerV0TxTypes(gcV0),
|
||||
@@ -87,8 +83,8 @@ func init() {
|
||||
registerV1TxTypes(gcV2),
|
||||
)
|
||||
|
||||
Codec = codec.NewDefaultManager()
|
||||
GenesisCodec = codec.NewManager(math.MaxInt32)
|
||||
Codec = pcodecs.NewDefaultManager()
|
||||
GenesisCodec = pcodecs.NewMaxInt32Manager()
|
||||
errs.Add(
|
||||
Codec.RegisterCodec(CodecVersionV0, cV0),
|
||||
Codec.RegisterCodec(CodecVersionV1, cV1),
|
||||
@@ -140,7 +136,7 @@ func CodecVersionForTimestamp(ts uint64) uint16 {
|
||||
// CodecForTimestamp is a no-op for the manager handle, kept here so
|
||||
// future evolutions can swap the manager itself (e.g. a ZAP-only
|
||||
// manager after V1 retirement) without changing call sites.
|
||||
func CodecForTimestamp(_ uint64) codec.Manager {
|
||||
func CodecForTimestamp(_ uint64) pcodecs.Manager {
|
||||
return Codec
|
||||
}
|
||||
|
||||
@@ -172,7 +168,7 @@ func CodecRequiresLegacy(v uint16) bool {
|
||||
// new build path uses) on the given linearcodec. Existing call sites
|
||||
// outside this package continue to compose with RegisterTypes; the v0
|
||||
// decoder is gated to the txs.Codec / txs.GenesisCodec entries.
|
||||
func RegisterTypes(targetCodec linearcodec.Codec) error {
|
||||
func RegisterTypes(targetCodec pcodecs.LinearCodec) error {
|
||||
return registerV1TxTypes(targetCodec)
|
||||
}
|
||||
|
||||
@@ -197,7 +193,7 @@ func registerV1TxTypes(targetCodec slotRegistrar) error {
|
||||
// slot (atomic block ID) so existing tx type IDs remain stable.
|
||||
targetCodec.SkipRegistrations(5)
|
||||
|
||||
errs := wrappers.Errs{}
|
||||
errs := pcodecs.Errs{}
|
||||
|
||||
// secp256k1fx types are registered here because this matches the
|
||||
// XVM registration order — utxos crossed in shared memory must
|
||||
@@ -294,7 +290,7 @@ func registerV0TxTypes(targetCodec slotRegistrar) error {
|
||||
// Slots 0-4: reserved for block-codec block types.
|
||||
targetCodec.SkipRegistrations(5)
|
||||
|
||||
errs := wrappers.Errs{}
|
||||
errs := pcodecs.Errs{}
|
||||
|
||||
// Slots 5-11: secp256k1fx with the two v0 historical holes.
|
||||
errs.Add(targetCodec.RegisterType(&secp256k1fx.TransferInput{}))
|
||||
|
||||
@@ -8,20 +8,19 @@ package fee
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/crypto/bls"
|
||||
"github.com/luxfi/crypto/secp256k1"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/math"
|
||||
"github.com/luxfi/node/vms/components/gas"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/node/vms/components/verify"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/fx"
|
||||
"github.com/luxfi/node/vms/platformvm/signer"
|
||||
"github.com/luxfi/node/vms/platformvm/stakeable"
|
||||
"github.com/luxfi/node/vms/platformvm/txs"
|
||||
"github.com/luxfi/node/vms/platformvm/warp"
|
||||
"github.com/luxfi/math"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/node/vms/platformvm/fx"
|
||||
"github.com/luxfi/node/vms/platformvm/signer"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/utxo/secp256k1fx"
|
||||
)
|
||||
|
||||
@@ -29,53 +28,53 @@ import (
|
||||
// an AWS c5.xlarge instance.
|
||||
const (
|
||||
intrinsicValidatorBandwidth = ids.NodeIDLen + // nodeID
|
||||
wrappers.LongLen + // start
|
||||
wrappers.LongLen + // end
|
||||
wrappers.LongLen // weight
|
||||
pcodecs.LongLen + // start
|
||||
pcodecs.LongLen + // end
|
||||
pcodecs.LongLen // weight
|
||||
|
||||
intrinsicNetValidatorBandwidth = intrinsicValidatorBandwidth + // validator
|
||||
ids.IDLen // subchainID
|
||||
|
||||
intrinsicOutputBandwidth = ids.IDLen + // assetID
|
||||
wrappers.IntLen // output typeID
|
||||
pcodecs.IntLen // output typeID
|
||||
|
||||
intrinsicStakeableLockedOutputBandwidth = wrappers.LongLen + // locktime
|
||||
wrappers.IntLen // output typeID
|
||||
intrinsicStakeableLockedOutputBandwidth = pcodecs.LongLen + // locktime
|
||||
pcodecs.IntLen // output typeID
|
||||
|
||||
intrinsicSECP256k1FxOutputOwnersBandwidth = wrappers.LongLen + // locktime
|
||||
wrappers.IntLen + // threshold
|
||||
wrappers.IntLen // num addresses
|
||||
intrinsicSECP256k1FxOutputOwnersBandwidth = pcodecs.LongLen + // locktime
|
||||
pcodecs.IntLen + // threshold
|
||||
pcodecs.IntLen // num addresses
|
||||
|
||||
intrinsicSECP256k1FxOutputBandwidth = wrappers.LongLen + // amount
|
||||
intrinsicSECP256k1FxOutputBandwidth = pcodecs.LongLen + // amount
|
||||
intrinsicSECP256k1FxOutputOwnersBandwidth
|
||||
|
||||
intrinsicInputBandwidth = ids.IDLen + // txID
|
||||
wrappers.IntLen + // output index
|
||||
pcodecs.IntLen + // output index
|
||||
ids.IDLen + // assetID
|
||||
wrappers.IntLen + // input typeID
|
||||
wrappers.IntLen // credential typeID
|
||||
pcodecs.IntLen + // input typeID
|
||||
pcodecs.IntLen // credential typeID
|
||||
|
||||
intrinsicStakeableLockedInputBandwidth = wrappers.LongLen + // locktime
|
||||
wrappers.IntLen // input typeID
|
||||
intrinsicStakeableLockedInputBandwidth = pcodecs.LongLen + // locktime
|
||||
pcodecs.IntLen // input typeID
|
||||
|
||||
intrinsicSECP256k1FxInputBandwidth = wrappers.IntLen + // num indices
|
||||
wrappers.IntLen // num signatures
|
||||
intrinsicSECP256k1FxInputBandwidth = pcodecs.IntLen + // num indices
|
||||
pcodecs.IntLen // num signatures
|
||||
|
||||
intrinsicSECP256k1FxTransferableInputBandwidth = wrappers.LongLen + // amount
|
||||
intrinsicSECP256k1FxTransferableInputBandwidth = pcodecs.LongLen + // amount
|
||||
intrinsicSECP256k1FxInputBandwidth
|
||||
|
||||
intrinsicSECP256k1FxSignatureBandwidth = wrappers.IntLen + // signature index
|
||||
intrinsicSECP256k1FxSignatureBandwidth = pcodecs.IntLen + // signature index
|
||||
secp256k1.SignatureLen // signature length
|
||||
|
||||
intrinsicSECP256k1FxSignatureCompute = 200 // secp256k1 signature verification time is around 200us
|
||||
|
||||
intrinsicConvertNetworkToL1ValidatorBandwidth = wrappers.IntLen + // nodeID length
|
||||
wrappers.LongLen + // weight
|
||||
wrappers.LongLen + // balance
|
||||
wrappers.IntLen + // remaining balance owner threshold
|
||||
wrappers.IntLen + // remaining balance owner num addresses
|
||||
wrappers.IntLen + // deactivation owner threshold
|
||||
wrappers.IntLen // deactivation owner num addresses
|
||||
intrinsicConvertNetworkToL1ValidatorBandwidth = pcodecs.IntLen + // nodeID length
|
||||
pcodecs.LongLen + // weight
|
||||
pcodecs.LongLen + // balance
|
||||
pcodecs.IntLen + // remaining balance owner threshold
|
||||
pcodecs.IntLen + // remaining balance owner num addresses
|
||||
pcodecs.IntLen + // deactivation owner threshold
|
||||
pcodecs.IntLen // deactivation owner num addresses
|
||||
|
||||
intrinsicBLSAggregateCompute = 5 // BLS public key aggregation time is around 5us
|
||||
intrinsicBLSVerifyCompute = 1_000 // BLS verification time is around 1000us
|
||||
@@ -100,44 +99,44 @@ var (
|
||||
IntrinsicAddChainValidatorTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
intrinsicNetValidatorBandwidth + // netValidator
|
||||
wrappers.IntLen + // netAuth typeID
|
||||
wrappers.IntLen, // netAuthCredential typeID
|
||||
pcodecs.IntLen + // netAuth typeID
|
||||
pcodecs.IntLen, // netAuthCredential typeID
|
||||
gas.DBRead: 3, // get net auth + check for net transformation + check for net conversion
|
||||
gas.DBWrite: 3, // put current staker + write weight diff + write pk diff
|
||||
}
|
||||
IntrinsicCreateChainTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.IDLen + // subchainID
|
||||
wrappers.ShortLen + // chainName length
|
||||
pcodecs.ShortLen + // chainName length
|
||||
ids.IDLen + // vmID
|
||||
wrappers.IntLen + // num fxIDs
|
||||
wrappers.IntLen + // genesis length
|
||||
wrappers.IntLen + // chainAuth typeID
|
||||
wrappers.IntLen, // chainAuthCredential typeID
|
||||
pcodecs.IntLen + // num fxIDs
|
||||
pcodecs.IntLen + // genesis length
|
||||
pcodecs.IntLen + // chainAuth typeID
|
||||
pcodecs.IntLen, // chainAuthCredential typeID
|
||||
gas.DBRead: 3, // get chain auth + check for chain transformation + check for chain conversion
|
||||
gas.DBWrite: 1, // put chain
|
||||
}
|
||||
IntrinsicCreateNetworkTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
wrappers.IntLen, // owner typeID
|
||||
pcodecs.IntLen, // owner typeID
|
||||
gas.DBWrite: 1, // write chain owner
|
||||
}
|
||||
IntrinsicImportTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.IDLen + // source chainID
|
||||
wrappers.IntLen, // num importing inputs
|
||||
pcodecs.IntLen, // num importing inputs
|
||||
}
|
||||
IntrinsicExportTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.IDLen + // destination chainID
|
||||
wrappers.IntLen, // num exported outputs
|
||||
pcodecs.IntLen, // num exported outputs
|
||||
}
|
||||
IntrinsicRemoveChainValidatorTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.NodeIDLen + // nodeID
|
||||
ids.IDLen + // netID
|
||||
wrappers.IntLen + // netAuth typeID
|
||||
wrappers.IntLen, // netAuthCredential typeID
|
||||
pcodecs.IntLen + // netAuth typeID
|
||||
pcodecs.IntLen, // netAuthCredential typeID
|
||||
gas.DBRead: 1, // read net auth
|
||||
gas.DBWrite: 3, // delete validator + write weight diff + write pk diff
|
||||
}
|
||||
@@ -145,11 +144,11 @@ var (
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
intrinsicValidatorBandwidth + // validator
|
||||
ids.IDLen + // subchainID
|
||||
wrappers.IntLen + // signer typeID
|
||||
wrappers.IntLen + // num stake outs
|
||||
wrappers.IntLen + // validator rewards typeID
|
||||
wrappers.IntLen + // delegator rewards typeID
|
||||
wrappers.IntLen, // delegation shares
|
||||
pcodecs.IntLen + // signer typeID
|
||||
pcodecs.IntLen + // num stake outs
|
||||
pcodecs.IntLen + // validator rewards typeID
|
||||
pcodecs.IntLen + // delegator rewards typeID
|
||||
pcodecs.IntLen, // delegation shares
|
||||
gas.DBRead: 1, // get staking config
|
||||
gas.DBWrite: 3, // put current staker + write weight diff + write pk diff
|
||||
}
|
||||
@@ -157,17 +156,17 @@ var (
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
intrinsicValidatorBandwidth + // validator
|
||||
ids.IDLen + // subchainID
|
||||
wrappers.IntLen + // num stake outs
|
||||
wrappers.IntLen, // delegator rewards typeID
|
||||
pcodecs.IntLen + // num stake outs
|
||||
pcodecs.IntLen, // delegator rewards typeID
|
||||
gas.DBRead: 1, // get staking config
|
||||
gas.DBWrite: 2, // put current staker + write weight diff
|
||||
}
|
||||
IntrinsicTransferChainOwnershipTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.IDLen + // netID
|
||||
wrappers.IntLen + // netAuth typeID
|
||||
wrappers.IntLen + // owner typeID
|
||||
wrappers.IntLen, // netAuthCredential typeID
|
||||
pcodecs.IntLen + // netAuth typeID
|
||||
pcodecs.IntLen + // owner typeID
|
||||
pcodecs.IntLen, // netAuthCredential typeID
|
||||
gas.DBRead: 1, // read net auth
|
||||
gas.DBWrite: 1, // set net owner
|
||||
}
|
||||
@@ -175,83 +174,83 @@ var (
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.IDLen + // netID
|
||||
ids.IDLen + // assetID
|
||||
wrappers.IntLen + // initialSupply
|
||||
wrappers.IntLen + // maximumSupply
|
||||
wrappers.IntLen + // minConsumptionRate
|
||||
wrappers.IntLen + // maxConsumptionRate
|
||||
wrappers.LongLen + // minValidatorStake
|
||||
wrappers.LongLen + // maxValidatorStake
|
||||
wrappers.IntLen + // minStakeDuration
|
||||
wrappers.IntLen + // maxStakeDuration
|
||||
wrappers.IntLen + // minDelegationFee
|
||||
wrappers.IntLen + // minDelegatorStake
|
||||
wrappers.IntLen + // maxValidatorWeightFactor
|
||||
wrappers.IntLen + // uptimeRequirement
|
||||
wrappers.IntLen + // netAuth typeID
|
||||
wrappers.IntLen, // netAuthCredential typeID
|
||||
pcodecs.IntLen + // initialSupply
|
||||
pcodecs.IntLen + // maximumSupply
|
||||
pcodecs.IntLen + // minConsumptionRate
|
||||
pcodecs.IntLen + // maxConsumptionRate
|
||||
pcodecs.LongLen + // minValidatorStake
|
||||
pcodecs.LongLen + // maxValidatorStake
|
||||
pcodecs.IntLen + // minStakeDuration
|
||||
pcodecs.IntLen + // maxStakeDuration
|
||||
pcodecs.IntLen + // minDelegationFee
|
||||
pcodecs.IntLen + // minDelegatorStake
|
||||
pcodecs.IntLen + // maxValidatorWeightFactor
|
||||
pcodecs.IntLen + // uptimeRequirement
|
||||
pcodecs.IntLen + // netAuth typeID
|
||||
pcodecs.IntLen, // netAuthCredential typeID
|
||||
gas.DBRead: 2, // get net auth + check for net transformation
|
||||
gas.DBWrite: 1, // write net transformation
|
||||
}
|
||||
IntrinsicBaseTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: codec.VersionSize + // codecVersion
|
||||
wrappers.IntLen + // typeID
|
||||
wrappers.IntLen + // networkID
|
||||
gas.Bandwidth: pcodecs.VersionSize + // codecVersion
|
||||
pcodecs.IntLen + // typeID
|
||||
pcodecs.IntLen + // networkID
|
||||
ids.IDLen + // blockchainID
|
||||
wrappers.IntLen + // number of outputs
|
||||
wrappers.IntLen + // number of inputs
|
||||
wrappers.IntLen + // length of memo
|
||||
wrappers.IntLen, // number of credentials
|
||||
pcodecs.IntLen + // number of outputs
|
||||
pcodecs.IntLen + // number of inputs
|
||||
pcodecs.IntLen + // length of memo
|
||||
pcodecs.IntLen, // number of credentials
|
||||
}
|
||||
IntrinsicConvertNetworkToL1TxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.IDLen + // subchainID
|
||||
ids.IDLen + // chainID
|
||||
wrappers.IntLen + // address length
|
||||
wrappers.IntLen + // validators length
|
||||
wrappers.IntLen + // chainAuth typeID
|
||||
wrappers.IntLen, // chainAuthCredential typeID
|
||||
pcodecs.IntLen + // address length
|
||||
pcodecs.IntLen + // validators length
|
||||
pcodecs.IntLen + // chainAuth typeID
|
||||
pcodecs.IntLen, // chainAuthCredential typeID
|
||||
gas.DBRead: 3, // chain auth + transformation lookup + conversion lookup
|
||||
gas.DBWrite: 2, // write conversion manager + total weight
|
||||
}
|
||||
IntrinsicRegisterL1ValidatorTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
wrappers.LongLen + // balance
|
||||
pcodecs.LongLen + // balance
|
||||
bls.SignatureLen + // proof of possession
|
||||
wrappers.IntLen, // message length
|
||||
pcodecs.IntLen, // message length
|
||||
gas.DBRead: 5, // conversion owner + expiry lookup + sov lookup + subchainID/nodeID lookup + weight lookup
|
||||
gas.DBWrite: 6, // write current staker + expiry + write weight diff + write pk diff + subchainID/nodeID lookup + weight lookup
|
||||
gas.Compute: intrinsicBLSPoPVerifyCompute,
|
||||
}
|
||||
IntrinsicSetL1ValidatorWeightTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
wrappers.IntLen, // message length
|
||||
pcodecs.IntLen, // message length
|
||||
gas.DBRead: 3, // read staker + read conversion + read weight
|
||||
gas.DBWrite: 5, // remaining balance utxo + write weight diff + write pk diff + weights lookup + validator write
|
||||
}
|
||||
IntrinsicIncreaseL1ValidatorBalanceTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.IDLen + // validationID
|
||||
wrappers.LongLen, // balance
|
||||
pcodecs.LongLen, // balance
|
||||
gas.DBRead: 1, // read staker
|
||||
gas.DBWrite: 5, // weight diff + deactivated weight diff + public key diff + delete staker + write staker
|
||||
}
|
||||
IntrinsicDisableL1ValidatorTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.IDLen + // validationID
|
||||
wrappers.IntLen + // auth typeID
|
||||
wrappers.IntLen, // authCredential typeID
|
||||
pcodecs.IntLen + // auth typeID
|
||||
pcodecs.IntLen, // authCredential typeID
|
||||
gas.DBRead: 1, // read staker
|
||||
gas.DBWrite: 6, // write remaining balance utxo + weight diff + deactivated weight diff + public key diff + delete staker + write staker
|
||||
}
|
||||
IntrinsicSlashValidatorTxComplexities = gas.Dimensions{
|
||||
gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] +
|
||||
ids.NodeIDLen + // nodeID
|
||||
wrappers.LongLen + // evidence height
|
||||
wrappers.ByteLen + // evidence type
|
||||
wrappers.IntLen + // messageA length prefix
|
||||
wrappers.IntLen + // messageB length prefix
|
||||
pcodecs.LongLen + // evidence height
|
||||
pcodecs.ByteLen + // evidence type
|
||||
pcodecs.IntLen + // messageA length prefix
|
||||
pcodecs.IntLen + // messageB length prefix
|
||||
2*bls.SignatureLen + // two BLS signatures
|
||||
wrappers.IntLen, // slashPercentage
|
||||
pcodecs.IntLen, // slashPercentage
|
||||
gas.DBRead: 1, // read validator
|
||||
gas.DBWrite: 2, // delete + re-insert validator (or just delete if below minimum)
|
||||
}
|
||||
|
||||
@@ -10,17 +10,17 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/crypto/secp256k1"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/vms/components/gas"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/node/vms/components/verify"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/fx"
|
||||
"github.com/luxfi/node/vms/platformvm/signer"
|
||||
"github.com/luxfi/node/vms/platformvm/stakeable"
|
||||
"github.com/luxfi/node/vms/platformvm/txs"
|
||||
"github.com/luxfi/node/vms/platformvm/warp/message"
|
||||
"github.com/luxfi/node/vms/platformvm/fx"
|
||||
"github.com/luxfi/node/vms/platformvm/signer"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/utxo/secp256k1fx"
|
||||
)
|
||||
|
||||
@@ -219,7 +219,7 @@ func TestOutputComplexity(t *testing.T) {
|
||||
bytes, err := txs.Codec.Marshal(txs.CodecVersion, test.out)
|
||||
require.NoError(err)
|
||||
|
||||
numBytesWithoutCodecVersion := uint64(len(bytes) - codec.VersionSize)
|
||||
numBytesWithoutCodecVersion := uint64(len(bytes) - pcodecs.VersionSize)
|
||||
require.Equal(numBytesWithoutCodecVersion, actual[gas.Bandwidth])
|
||||
})
|
||||
}
|
||||
@@ -343,7 +343,7 @@ func TestInputComplexity(t *testing.T) {
|
||||
credentialBytes, err := txs.Codec.Marshal(txs.CodecVersion, &cred)
|
||||
require.NoError(err)
|
||||
|
||||
numBytesWithoutCodecVersion := uint64(len(inputBytes) + len(credentialBytes) - 2*codec.VersionSize)
|
||||
numBytesWithoutCodecVersion := uint64(len(inputBytes) + len(credentialBytes) - 2*pcodecs.VersionSize)
|
||||
require.Equal(numBytesWithoutCodecVersion, actual[gas.Bandwidth])
|
||||
})
|
||||
}
|
||||
@@ -419,7 +419,7 @@ func TestConvertNetworkToL1ValidatorComplexity(t *testing.T) {
|
||||
vdrBytes, err := txs.Codec.Marshal(txs.CodecVersion, test.vdr)
|
||||
require.NoError(err)
|
||||
|
||||
numBytesWithoutCodecVersion := uint64(len(vdrBytes) - codec.VersionSize)
|
||||
numBytesWithoutCodecVersion := uint64(len(vdrBytes) - pcodecs.VersionSize)
|
||||
require.Equal(numBytesWithoutCodecVersion, actual[gas.Bandwidth])
|
||||
})
|
||||
}
|
||||
@@ -484,7 +484,7 @@ func TestOwnerComplexity(t *testing.T) {
|
||||
ownerBytes, err := txs.Codec.Marshal(txs.CodecVersion, test.owner)
|
||||
require.NoError(err)
|
||||
|
||||
numBytesWithoutCodecVersion := uint64(len(ownerBytes) - codec.VersionSize)
|
||||
numBytesWithoutCodecVersion := uint64(len(ownerBytes) - pcodecs.VersionSize)
|
||||
require.Equal(numBytesWithoutCodecVersion, actual[gas.Bandwidth])
|
||||
})
|
||||
}
|
||||
@@ -565,7 +565,7 @@ func TestAuthComplexity(t *testing.T) {
|
||||
credentialBytes, err := txs.Codec.Marshal(txs.CodecVersion, test.cred)
|
||||
require.NoError(err)
|
||||
|
||||
numBytesWithoutCodecVersion := uint64(len(authBytes) + len(credentialBytes) - 2*codec.VersionSize)
|
||||
numBytesWithoutCodecVersion := uint64(len(authBytes) + len(credentialBytes) - 2*pcodecs.VersionSize)
|
||||
require.Equal(numBytesWithoutCodecVersion, actual[gas.Bandwidth])
|
||||
})
|
||||
}
|
||||
@@ -615,7 +615,7 @@ func TestSignerComplexity(t *testing.T) {
|
||||
signerBytes, err := txs.Codec.Marshal(txs.CodecVersion, test.signer)
|
||||
require.NoError(err)
|
||||
|
||||
numBytesWithoutCodecVersion := uint64(len(signerBytes) - codec.VersionSize)
|
||||
numBytesWithoutCodecVersion := uint64(len(signerBytes) - pcodecs.VersionSize)
|
||||
require.Equal(numBytesWithoutCodecVersion, actual[gas.Bandwidth])
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/runtime"
|
||||
"github.com/luxfi/node/vms/components/verify"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/runtime"
|
||||
"github.com/luxfi/utils"
|
||||
)
|
||||
|
||||
@@ -42,7 +42,7 @@ type InitialState struct {
|
||||
func (is *InitialState) InitRuntime(_ *runtime.Runtime) {}
|
||||
|
||||
// Verify returns nil iff this InitialState is well formed.
|
||||
func (is *InitialState) Verify(c codec.Manager) error {
|
||||
func (is *InitialState) Verify(c pcodecs.Manager) error {
|
||||
switch {
|
||||
case is == nil:
|
||||
return ErrNilInitialState
|
||||
@@ -70,13 +70,13 @@ func (is *InitialState) Compare(other *InitialState) int {
|
||||
}
|
||||
|
||||
// Sort orders the outputs of this InitialState by their byte representation.
|
||||
func (is *InitialState) Sort(c codec.Manager) {
|
||||
func (is *InitialState) Sort(c pcodecs.Manager) {
|
||||
sortState(is.Outs, c)
|
||||
}
|
||||
|
||||
type innerSortState struct {
|
||||
vers []verify.State
|
||||
codec codec.Manager
|
||||
codec pcodecs.Manager
|
||||
}
|
||||
|
||||
func (s *innerSortState) Less(i, j int) bool {
|
||||
@@ -96,10 +96,10 @@ func (s *innerSortState) Less(i, j int) bool {
|
||||
func (s *innerSortState) Len() int { return len(s.vers) }
|
||||
func (s *innerSortState) Swap(i, j int) { s.vers[j], s.vers[i] = s.vers[i], s.vers[j] }
|
||||
|
||||
func sortState(vers []verify.State, c codec.Manager) {
|
||||
func sortState(vers []verify.State, c pcodecs.Manager) {
|
||||
sort.Sort(&innerSortState{vers: vers, codec: c})
|
||||
}
|
||||
|
||||
func isSortedState(vers []verify.State, c codec.Manager) bool {
|
||||
func isSortedState(vers []verify.State, c pcodecs.Manager) bool {
|
||||
return sort.IsSorted(&innerSortState{vers: vers, codec: c})
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/crypto/secp256k1"
|
||||
"github.com/luxfi/node/vms/components/verify"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/utils"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/utxo/secp256k1fx"
|
||||
)
|
||||
|
||||
@@ -65,7 +65,7 @@ var _ = secp256k1fx.ID
|
||||
// SortOperations sorts the given operations by their codec-marshalled bytes.
|
||||
type operationAndCodec struct {
|
||||
op *Operation
|
||||
codec codec.Manager
|
||||
codec pcodecs.Manager
|
||||
}
|
||||
|
||||
func (o *operationAndCodec) Compare(other *operationAndCodec) int {
|
||||
@@ -80,7 +80,7 @@ func (o *operationAndCodec) Compare(other *operationAndCodec) int {
|
||||
return bytes.Compare(oBytes, otherBytes)
|
||||
}
|
||||
|
||||
func SortOperations(ops []*Operation, c codec.Manager) {
|
||||
func SortOperations(ops []*Operation, c pcodecs.Manager) {
|
||||
wrapped := make([]*operationAndCodec, len(ops))
|
||||
for i, op := range ops {
|
||||
wrapped[i] = &operationAndCodec{op: op, codec: c}
|
||||
@@ -93,7 +93,7 @@ func SortOperations(ops []*Operation, c codec.Manager) {
|
||||
|
||||
// IsSortedAndUniqueOperations reports whether [ops] is sorted by codec bytes
|
||||
// and contains no duplicates.
|
||||
func IsSortedAndUniqueOperations(ops []*Operation, c codec.Manager) bool {
|
||||
func IsSortedAndUniqueOperations(ops []*Operation, c pcodecs.Manager) bool {
|
||||
wrapped := make([]*operationAndCodec, len(ops))
|
||||
for i, op := range ops {
|
||||
wrapped[i] = &operationAndCodec{op: op, codec: c}
|
||||
@@ -104,7 +104,7 @@ func IsSortedAndUniqueOperations(ops []*Operation, c codec.Manager) bool {
|
||||
type innerSortOperationsWithSigners struct {
|
||||
ops []*Operation
|
||||
signers [][]*secp256k1.PrivateKey
|
||||
codec codec.Manager
|
||||
codec pcodecs.Manager
|
||||
}
|
||||
|
||||
func (s *innerSortOperationsWithSigners) Less(i, j int) bool {
|
||||
@@ -125,6 +125,6 @@ func (s *innerSortOperationsWithSigners) Swap(i, j int) {
|
||||
s.signers[j], s.signers[i] = s.signers[i], s.signers[j]
|
||||
}
|
||||
|
||||
func SortOperationsWithSigners(ops []*Operation, signers [][]*secp256k1.PrivateKey, c codec.Manager) {
|
||||
func SortOperationsWithSigners(ops []*Operation, signers [][]*secp256k1.PrivateKey, c pcodecs.Manager) {
|
||||
sort.Sort(&innerSortOperationsWithSigners{ops: ops, signers: signers, codec: c})
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/runtime"
|
||||
"github.com/luxfi/crypto/hash"
|
||||
"github.com/luxfi/crypto/secp256k1"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/math/set"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/node/vms/components/verify"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/p2p/gossip"
|
||||
"github.com/luxfi/runtime"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/utxo/secp256k1fx"
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ type Tx struct {
|
||||
|
||||
func NewSigned(
|
||||
unsigned UnsignedTx,
|
||||
c codec.Manager,
|
||||
c pcodecs.Manager,
|
||||
signers [][]*secp256k1.PrivateKey,
|
||||
) (*Tx, error) {
|
||||
res := &Tx{Unsigned: unsigned}
|
||||
@@ -54,7 +54,7 @@ func NewSigned(
|
||||
// builder). For txs loaded from disk or received from the wire, use
|
||||
// InitializeFromBytes — Initialize would re-encode at v1, changing the
|
||||
// TxID of any tx that was originally serialized at v0.
|
||||
func (tx *Tx) Initialize(c codec.Manager) error {
|
||||
func (tx *Tx) Initialize(c pcodecs.Manager) error {
|
||||
signedBytes, err := c.Marshal(CodecVersion, tx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't marshal ProposalTx: %w", err)
|
||||
@@ -81,7 +81,7 @@ func (tx *Tx) Initialize(c codec.Manager) error {
|
||||
// by codec.Manager.Unmarshal). It selects the c.Size(...) call used to
|
||||
// split signedBytes into unsignedBytes (the prefix the signature
|
||||
// covers) and the credentials suffix.
|
||||
func (tx *Tx) InitializeFromBytes(c codec.Manager, version uint16, signedBytes []byte) error {
|
||||
func (tx *Tx) InitializeFromBytes(c pcodecs.Manager, version uint16, signedBytes []byte) error {
|
||||
unsignedBytesLen, err := c.Size(version, &tx.Unsigned)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't calculate UnsignedTx marshal length: %w", err)
|
||||
@@ -121,7 +121,7 @@ func (tx *Tx) InitializeFromBytes(c codec.Manager, version uint16, signedBytes [
|
||||
// Once every genesis blob and every stored block on disk has been
|
||||
// re-encoded at v1 (a future migration), this method becomes dead
|
||||
// code and the v0 codec entry can be removed.
|
||||
func (tx *Tx) InitializeFromBytesAtVersion(c codec.Manager, version uint16) error {
|
||||
func (tx *Tx) InitializeFromBytesAtVersion(c pcodecs.Manager, version uint16) error {
|
||||
signedBytes, err := c.Marshal(version, tx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't re-marshal tx at v%d: %w", version, err)
|
||||
@@ -148,7 +148,7 @@ func (tx *Tx) SetBytes(unsignedBytes, signedBytes []byte) {
|
||||
// We explicitly pass the codec in Parse since some call sites (genesis,
|
||||
// state fallback) must use GenesisCodec to admit txs larger than the
|
||||
// max length of Codec.
|
||||
func Parse(c codec.Manager, signedBytes []byte) (*Tx, error) {
|
||||
func Parse(c pcodecs.Manager, signedBytes []byte) (*Tx, error) {
|
||||
tx := &Tx{}
|
||||
version, err := c.Unmarshal(signedBytes, tx)
|
||||
if err != nil {
|
||||
@@ -212,7 +212,7 @@ func (tx *Tx) SyntacticVerify(rt *runtime.Runtime) error {
|
||||
// Sign this transaction with the provided signers
|
||||
// Note: We explicitly pass the codec in Sign since we may need to sign P-Chain
|
||||
// genesis txs whose length exceed the max length of txs.Codec.
|
||||
func (tx *Tx) Sign(c codec.Manager, signers [][]*secp256k1.PrivateKey) error {
|
||||
func (tx *Tx) Sign(c pcodecs.Manager, signers [][]*secp256k1.PrivateKey) error {
|
||||
unsignedBytes, err := c.Marshal(CodecVersion, &tx.Unsigned)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't marshal UnsignedTx: %w", err)
|
||||
|
||||
@@ -8,12 +8,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/codec/linearcodec"
|
||||
"github.com/luxfi/crypto/secp256k1"
|
||||
"github.com/luxfi/ids"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/node/vms/components/verify"
|
||||
"github.com/luxfi/codec/wrappers"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/utxo/secp256k1fx"
|
||||
)
|
||||
|
||||
@@ -93,7 +92,7 @@ func FuzzBaseTx(f *testing.F) {
|
||||
testID := ids.GenerateTestID()
|
||||
f.Add(uint64(0), uint32(0), testID[:])
|
||||
|
||||
c := linearcodec.NewDefault()
|
||||
c := pcodecs.NewLinearCodec()
|
||||
|
||||
f.Fuzz(func(t *testing.T, networkID uint64, blockchainID uint32, assetData []byte) {
|
||||
// Create asset ID
|
||||
@@ -124,7 +123,7 @@ func FuzzBaseTx(f *testing.F) {
|
||||
}
|
||||
|
||||
// Try to serialize
|
||||
p := wrappers.Packer{MaxSize: 1024 * 1024}
|
||||
p := pcodecs.Packer{MaxSize: 1024 * 1024}
|
||||
err := c.MarshalInto(baseTx, &p)
|
||||
if err != nil {
|
||||
// Some combinations might be invalid
|
||||
@@ -133,7 +132,7 @@ func FuzzBaseTx(f *testing.F) {
|
||||
|
||||
// Try to deserialize
|
||||
var parsed BaseTx
|
||||
p2 := wrappers.Packer{Bytes: p.Bytes, MaxSize: 1024 * 1024}
|
||||
p2 := pcodecs.Packer{Bytes: p.Bytes, MaxSize: 1024 * 1024}
|
||||
err = c.UnmarshalFrom(&p2, &parsed)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to unmarshal BaseTx: %v", err)
|
||||
@@ -158,7 +157,7 @@ func FuzzCreateChainTx(f *testing.F) {
|
||||
f.Add([]byte("test"), bytes.Repeat([]byte{0x01}, 100), []byte("customvm"))
|
||||
f.Add([]byte{}, []byte{}, []byte{})
|
||||
|
||||
c := linearcodec.NewDefault()
|
||||
c := pcodecs.NewLinearCodec()
|
||||
|
||||
f.Fuzz(func(t *testing.T, chainName []byte, genesisData []byte, vmIDData []byte) {
|
||||
// Limit sizes
|
||||
@@ -196,7 +195,7 @@ func FuzzCreateChainTx(f *testing.F) {
|
||||
}
|
||||
|
||||
// Try to serialize
|
||||
p := wrappers.Packer{MaxSize: 10 * 1024 * 1024}
|
||||
p := pcodecs.Packer{MaxSize: 10 * 1024 * 1024}
|
||||
err := c.MarshalInto(tx, &p)
|
||||
if err != nil {
|
||||
// Some combinations might be invalid
|
||||
@@ -205,7 +204,7 @@ func FuzzCreateChainTx(f *testing.F) {
|
||||
|
||||
// Try to deserialize
|
||||
var parsed CreateChainTx
|
||||
p2 := wrappers.Packer{Bytes: p.Bytes, MaxSize: 10 * 1024 * 1024}
|
||||
p2 := pcodecs.Packer{Bytes: p.Bytes, MaxSize: 10 * 1024 * 1024}
|
||||
err = c.UnmarshalFrom(&p2, &parsed)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to unmarshal CreateChainTx: %v", err)
|
||||
@@ -234,7 +233,7 @@ func FuzzAddValidatorTx(f *testing.F) {
|
||||
f.Add(uint64(0), uint64(0), uint64(0), uint32(0))
|
||||
f.Add(uint64(time.Now().Unix()), uint64(time.Now().Add(time.Hour).Unix()), uint64(1000000), uint32(20000))
|
||||
|
||||
c := linearcodec.NewDefault()
|
||||
c := pcodecs.NewLinearCodec()
|
||||
|
||||
f.Fuzz(func(t *testing.T, startTime, endTime, weight uint64, shares uint32) {
|
||||
// Create validator transaction
|
||||
@@ -273,7 +272,7 @@ func FuzzAddValidatorTx(f *testing.F) {
|
||||
}
|
||||
|
||||
// Try to serialize
|
||||
p := wrappers.Packer{MaxSize: 1024 * 1024}
|
||||
p := pcodecs.Packer{MaxSize: 1024 * 1024}
|
||||
err := c.MarshalInto(tx, &p)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -281,7 +280,7 @@ func FuzzAddValidatorTx(f *testing.F) {
|
||||
|
||||
// Try to deserialize
|
||||
var parsed AddValidatorTx
|
||||
p2 := wrappers.Packer{Bytes: p.Bytes, MaxSize: 1024 * 1024}
|
||||
p2 := pcodecs.Packer{Bytes: p.Bytes, MaxSize: 1024 * 1024}
|
||||
err = c.UnmarshalFrom(&p2, &parsed)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to unmarshal AddValidatorTx: %v", err)
|
||||
@@ -316,7 +315,7 @@ func FuzzImportExportTx(f *testing.F) {
|
||||
f.Add(testID1[:], testID2[:])
|
||||
f.Add(bytes.Repeat([]byte{0xff}, 32), bytes.Repeat([]byte{0xaa}, 32))
|
||||
|
||||
c := linearcodec.NewDefault()
|
||||
c := pcodecs.NewLinearCodec()
|
||||
|
||||
f.Fuzz(func(t *testing.T, sourceChainData, destChainData []byte) {
|
||||
// Create chain IDs
|
||||
@@ -362,7 +361,7 @@ func FuzzImportExportTx(f *testing.F) {
|
||||
}
|
||||
|
||||
// Try to serialize ImportTx
|
||||
p := wrappers.Packer{MaxSize: 1024 * 1024}
|
||||
p := pcodecs.Packer{MaxSize: 1024 * 1024}
|
||||
err := c.MarshalInto(importTx, &p)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -370,7 +369,7 @@ func FuzzImportExportTx(f *testing.F) {
|
||||
|
||||
// Try to deserialize
|
||||
var parsedImport ImportTx
|
||||
p2 := wrappers.Packer{Bytes: p.Bytes, MaxSize: 1024 * 1024}
|
||||
p2 := pcodecs.Packer{Bytes: p.Bytes, MaxSize: 1024 * 1024}
|
||||
err = c.UnmarshalFrom(&p2, &parsedImport)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to unmarshal ImportTx: %v", err)
|
||||
@@ -408,7 +407,7 @@ func FuzzImportExportTx(f *testing.F) {
|
||||
}
|
||||
|
||||
// Try to serialize ExportTx
|
||||
p3 := wrappers.Packer{MaxSize: 1024 * 1024}
|
||||
p3 := pcodecs.Packer{MaxSize: 1024 * 1024}
|
||||
err = c.MarshalInto(exportTx, &p3)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -416,7 +415,7 @@ func FuzzImportExportTx(f *testing.F) {
|
||||
|
||||
// Try to deserialize
|
||||
var parsedExport ExportTx
|
||||
p4 := wrappers.Packer{Bytes: p3.Bytes, MaxSize: 1024 * 1024}
|
||||
p4 := pcodecs.Packer{Bytes: p3.Bytes, MaxSize: 1024 * 1024}
|
||||
err = c.UnmarshalFrom(&p4, &parsedExport)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to unmarshal ExportTx: %v", err)
|
||||
|
||||
@@ -14,9 +14,6 @@ import (
|
||||
"github.com/gorilla/rpc/v2"
|
||||
"github.com/luxfi/metric"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/codec/linearcodec"
|
||||
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/database"
|
||||
"github.com/luxfi/database/memdb"
|
||||
@@ -25,7 +22,7 @@ import (
|
||||
"github.com/luxfi/node/cache/lru"
|
||||
"github.com/luxfi/node/utils/json"
|
||||
"github.com/luxfi/node/version"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
"github.com/luxfi/node/vms/platformvm/block"
|
||||
"github.com/luxfi/node/vms/platformvm/config"
|
||||
"github.com/luxfi/node/vms/platformvm/fx"
|
||||
@@ -38,6 +35,7 @@ import (
|
||||
"github.com/luxfi/runtime"
|
||||
"github.com/luxfi/timer/mockable"
|
||||
"github.com/luxfi/utils"
|
||||
lux "github.com/luxfi/utxo"
|
||||
"github.com/luxfi/utxo/secp256k1fx"
|
||||
validators "github.com/luxfi/validators"
|
||||
"github.com/luxfi/validators/uptime"
|
||||
@@ -104,7 +102,7 @@ type VM struct {
|
||||
state state.State
|
||||
|
||||
fx fx.Fx
|
||||
codecRegistry codec.Registry
|
||||
codecRegistry pcodecs.Registry
|
||||
|
||||
// Bootstrapped remembers if this chain has finished bootstrapping or not
|
||||
bootstrappedConsensus utils.Atomic[bool]
|
||||
@@ -239,7 +237,7 @@ func (vm *VM) Initialize(
|
||||
// logic simplified as we now just trust init.DB or fallback to memdb if nil above
|
||||
|
||||
// Note: this codec is never used to serialize anything
|
||||
vm.codecRegistry = linearcodec.NewDefault()
|
||||
vm.codecRegistry = pcodecs.NewLinearCodec()
|
||||
vm.fx = &secp256k1fx.Fx{}
|
||||
if err := vm.fx.Initialize(vm); err != nil {
|
||||
return fmt.Errorf("failed to initialize fx: %w", err)
|
||||
@@ -784,7 +782,7 @@ func (vm *VM) Disconnected(ctx context.Context, nodeID ids.NodeID) error {
|
||||
return vm.Network.Disconnected(ctx, nodeID)
|
||||
}
|
||||
|
||||
func (vm *VM) CodecRegistry() codec.Registry {
|
||||
func (vm *VM) CodecRegistry() pcodecs.Registry {
|
||||
return vm.codecRegistry
|
||||
}
|
||||
|
||||
|
||||
@@ -5,19 +5,17 @@ package warp
|
||||
|
||||
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() {
|
||||
Codec = codec.NewManager(math.MaxInt)
|
||||
lc := linearcodec.NewDefault()
|
||||
Codec = pcodecs.NewMaxIntManager()
|
||||
lc := pcodecs.NewLinearCodec()
|
||||
|
||||
// CRITICAL: RegisterType order is the on-chain wire format. linearcodec
|
||||
// assigns a monotonically increasing typeID per call. Reordering ANY of
|
||||
|
||||
@@ -5,19 +5,17 @@ package message
|
||||
|
||||
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() {
|
||||
Codec = codec.NewManager(math.MaxInt)
|
||||
lc := linearcodec.NewDefault()
|
||||
Codec = pcodecs.NewMaxIntManager()
|
||||
lc := pcodecs.NewLinearCodec()
|
||||
|
||||
err := errors.Join(
|
||||
lc.RegisterType(&ChainToL1Conversion{}),
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/crypto/bls"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
@@ -27,7 +27,7 @@ func TestParse(t *testing.T) {
|
||||
{
|
||||
name: "invalid message",
|
||||
bytes: []byte{255, 255, 255, 255},
|
||||
expectedErr: codec.ErrUnknownVersion,
|
||||
expectedErr: pcodecs.ErrUnknownVersion,
|
||||
},
|
||||
{
|
||||
name: "ChainToL1Conversion",
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/crypto/bls"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
func TestMessage(t *testing.T) {
|
||||
@@ -47,5 +47,5 @@ func TestParseMessageJunk(t *testing.T) {
|
||||
|
||||
bytes := []byte{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
_, err := ParseMessage(bytes)
|
||||
require.ErrorIs(err, codec.ErrUnknownVersion)
|
||||
require.ErrorIs(err, pcodecs.ErrUnknownVersion)
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
func TestAddressedCall(t *testing.T) {
|
||||
@@ -31,7 +31,7 @@ func TestAddressedCall(t *testing.T) {
|
||||
|
||||
func TestParseAddressedCallJunk(t *testing.T) {
|
||||
_, err := ParseAddressedCall(junkBytes)
|
||||
require.ErrorIs(t, err, codec.ErrUnknownVersion)
|
||||
require.ErrorIs(t, err, pcodecs.ErrUnknownVersion)
|
||||
}
|
||||
|
||||
func TestAddressedCallBytes(t *testing.T) {
|
||||
|
||||
@@ -6,9 +6,8 @@ package payload
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/codec/linearcodec"
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -17,11 +16,11 @@ const (
|
||||
MaxMessageSize = 24 * constants.KiB
|
||||
)
|
||||
|
||||
var Codec codec.Manager
|
||||
var Codec pcodecs.Manager
|
||||
|
||||
func init() {
|
||||
Codec = codec.NewManager(MaxMessageSize)
|
||||
lc := linearcodec.NewDefault()
|
||||
Codec = pcodecs.NewManager(MaxMessageSize)
|
||||
lc := pcodecs.NewLinearCodec()
|
||||
|
||||
err := errors.Join(
|
||||
lc.RegisterType(&Hash{}),
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
func TestHash(t *testing.T) {
|
||||
@@ -27,7 +27,7 @@ func TestHash(t *testing.T) {
|
||||
|
||||
func TestParseHashJunk(t *testing.T) {
|
||||
_, err := ParseHash(junkBytes)
|
||||
require.ErrorIs(t, err, codec.ErrUnknownVersion)
|
||||
require.ErrorIs(t, err, pcodecs.ErrUnknownVersion)
|
||||
}
|
||||
|
||||
func TestHashBytes(t *testing.T) {
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
var junkBytes = []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}
|
||||
@@ -17,7 +17,7 @@ var junkBytes = []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}
|
||||
func TestParseJunk(t *testing.T) {
|
||||
require := require.New(t)
|
||||
_, err := Parse(junkBytes)
|
||||
require.ErrorIs(err, codec.ErrUnknownVersion)
|
||||
require.ErrorIs(err, pcodecs.ErrUnknownVersion)
|
||||
}
|
||||
|
||||
func TestParseWrongPayloadType(t *testing.T) {
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/codec"
|
||||
"github.com/luxfi/constants"
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/vms/pcodecs"
|
||||
)
|
||||
|
||||
func TestUnsignedMessage(t *testing.T) {
|
||||
@@ -34,5 +34,5 @@ func TestParseUnsignedMessageJunk(t *testing.T) {
|
||||
|
||||
bytes := []byte{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
_, err := ParseUnsignedMessage(bytes)
|
||||
require.ErrorIs(err, codec.ErrUnknownVersion)
|
||||
require.ErrorIs(err, pcodecs.ErrUnknownVersion)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user