mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
vms/platformvm/... build + vet PASS with pcodecs/txs.Codec gone from the VM. Executor semantics (standard_tx_executor): - registerOwnSet(): shared primitive — per-validator state.L1Validator with native owner blobs (txs.MarshalOwner/UnmarshalOwner, no codec), active-set capacity check, EndAccumulatedFee=balance+accruedFees, SetNetToL1Conversion manager-authority recording (byte-for-byte legacy tail). - ConvertNetworkTx: promote endomorphism (owner-authorized, folds old ConvertNetworkToL1Tx), gated by security.Mode.Manager. - CreateNetworkTx: base (AddNet/SetNetOwner) + sovereign path registers own set. - Deleted CreateSovereignL1Tx + ConvertNetworkToL1Tx. - txs.UnmarshalOwner added: canonical owner marshal/unmarshal pair, no codec. All ~13 txs.Visitor impls carry ConvertNetworkTx; gossip/block Parse(b) codec-free; wallet/network/primary off txs.Codec. KNOWN GAP (pending design decision, NOT silently green): CreateNetworkTx reads tx.Chains() only to derive managerChainID — it does NOT create the genesis chains (no AddChain). Atomic-spawn-with-chains vs decomplect-to-CreateChainTx is the open call. 17 codec-era _test.go parked as .bak for follow-up rewrite. Co-authored-by: Hanzo Dev <dev@hanzo.ai>
186 lines
4.6 KiB
Go
186 lines
4.6 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package genesistest
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/constants"
|
|
"github.com/luxfi/crypto/secp256k1"
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/node/upgrade"
|
|
lux "github.com/luxfi/utxo"
|
|
"github.com/luxfi/node/vms/platformvm/reward"
|
|
"github.com/luxfi/node/vms/platformvm/txs"
|
|
"github.com/luxfi/utxo/secp256k1fx"
|
|
|
|
platformvmgenesis "github.com/luxfi/node/vms/platformvm/genesis"
|
|
)
|
|
|
|
const (
|
|
DefaultValidatorDuration = 28 * 24 * time.Hour
|
|
DefaultValidatorWeight = 5 * constants.MilliLux
|
|
DefaultInitialBalance = 110 * constants.MegaLux // Increased to 110M LUX to cover all executor test fees (L1 validators, conversions, etc.)
|
|
|
|
ValidatorDelegationShares = reward.PercentDenominator
|
|
XChainName = "x"
|
|
InitialSupply = 360 * constants.MegaLux
|
|
)
|
|
|
|
var (
|
|
// Use a fixed test asset ID for X-chain native asset
|
|
UTXOAssetID = ids.ID{'l', 'u', 'x', ' ', 'a', 's', 's', 'e', 't', ' ', 'i', 'd'}
|
|
XAsset = lux.Asset{ID: UTXOAssetID}
|
|
|
|
DefaultValidatorStartTime = upgrade.InitiallyActiveTime
|
|
DefaultValidatorStartTimeUnix = uint64(DefaultValidatorStartTime.Unix())
|
|
DefaultValidatorEndTime = DefaultValidatorStartTime.Add(DefaultValidatorDuration)
|
|
DefaultValidatorEndTimeUnix = uint64(DefaultValidatorEndTime.Unix())
|
|
)
|
|
|
|
var (
|
|
// Keys that are funded in the genesis
|
|
DefaultFundedKeys = secp256k1.TestKeys()
|
|
|
|
// Node IDs of genesis validators
|
|
DefaultNodeIDs []ids.NodeID
|
|
)
|
|
|
|
func init() {
|
|
DefaultNodeIDs = make([]ids.NodeID, len(DefaultFundedKeys))
|
|
for i := range DefaultFundedKeys {
|
|
DefaultNodeIDs[i] = ids.GenerateTestNodeID()
|
|
}
|
|
}
|
|
|
|
type Config struct {
|
|
NetworkID uint32
|
|
NodeIDs []ids.NodeID
|
|
ValidatorWeight uint64
|
|
ValidatorStartTime time.Time
|
|
ValidatorEndTime time.Time
|
|
|
|
FundedKeys []*secp256k1.PrivateKey
|
|
InitialBalance uint64
|
|
}
|
|
|
|
func New(t testing.TB, c Config) *platformvmgenesis.Genesis {
|
|
if c.NetworkID == 0 {
|
|
c.NetworkID = constants.UnitTestID
|
|
}
|
|
if len(c.NodeIDs) == 0 {
|
|
c.NodeIDs = DefaultNodeIDs
|
|
}
|
|
if c.ValidatorWeight == 0 {
|
|
c.ValidatorWeight = DefaultValidatorWeight
|
|
}
|
|
if c.ValidatorStartTime.IsZero() {
|
|
c.ValidatorStartTime = DefaultValidatorStartTime
|
|
}
|
|
if c.ValidatorEndTime.IsZero() {
|
|
c.ValidatorEndTime = DefaultValidatorEndTime
|
|
}
|
|
if len(c.FundedKeys) == 0 {
|
|
c.FundedKeys = DefaultFundedKeys
|
|
}
|
|
if c.InitialBalance == 0 {
|
|
c.InitialBalance = DefaultInitialBalance
|
|
}
|
|
|
|
require := require.New(t)
|
|
|
|
genesis := &platformvmgenesis.Genesis{
|
|
UTXOs: make([]*platformvmgenesis.UTXO, len(c.FundedKeys)),
|
|
Validators: make([]*txs.Tx, len(c.NodeIDs)),
|
|
Timestamp: uint64(c.ValidatorStartTime.Unix()),
|
|
InitialSupply: InitialSupply,
|
|
}
|
|
for i, key := range c.FundedKeys {
|
|
genesis.UTXOs[i] = &platformvmgenesis.UTXO{UTXO: lux.UTXO{
|
|
UTXOID: lux.UTXOID{
|
|
TxID: UTXOAssetID,
|
|
OutputIndex: uint32(i),
|
|
},
|
|
Asset: XAsset,
|
|
Out: &secp256k1fx.TransferOutput{
|
|
Amt: c.InitialBalance,
|
|
OutputOwners: secp256k1fx.OutputOwners{
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{
|
|
key.Address(),
|
|
},
|
|
},
|
|
},
|
|
}}
|
|
}
|
|
for i, nodeID := range c.NodeIDs {
|
|
key := c.FundedKeys[i%len(c.FundedKeys)]
|
|
owner := secp256k1fx.OutputOwners{
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{
|
|
key.Address(),
|
|
},
|
|
}
|
|
validatorBase := &lux.BaseTx{
|
|
NetworkID: c.NetworkID,
|
|
BlockchainID: constants.PlatformChainID,
|
|
}
|
|
validator, err := txs.NewAddValidatorTx(
|
|
validatorBase,
|
|
txs.Validator{
|
|
NodeID: nodeID,
|
|
Start: uint64(c.ValidatorStartTime.Unix()),
|
|
End: uint64(c.ValidatorEndTime.Unix()),
|
|
Wght: c.ValidatorWeight,
|
|
},
|
|
[]*lux.TransferableOutput{
|
|
{
|
|
Asset: XAsset,
|
|
Out: &secp256k1fx.TransferOutput{
|
|
Amt: c.ValidatorWeight,
|
|
OutputOwners: owner,
|
|
},
|
|
},
|
|
},
|
|
&owner,
|
|
ValidatorDelegationShares,
|
|
)
|
|
require.NoError(err)
|
|
validatorTx := &txs.Tx{Unsigned: validator}
|
|
require.NoError(validatorTx.Initialize())
|
|
|
|
genesis.Validators[i] = validatorTx
|
|
}
|
|
|
|
chainBase := &lux.BaseTx{
|
|
NetworkID: c.NetworkID,
|
|
BlockchainID: constants.PlatformChainID,
|
|
}
|
|
chain, err := txs.NewCreateChainTx(
|
|
chainBase,
|
|
constants.PrimaryNetworkID,
|
|
XChainName,
|
|
constants.XVMID,
|
|
nil,
|
|
nil,
|
|
&secp256k1fx.Input{},
|
|
)
|
|
require.NoError(err)
|
|
chainTx := &txs.Tx{Unsigned: chain}
|
|
require.NoError(chainTx.Initialize())
|
|
|
|
genesis.Chains = []*txs.Tx{chainTx}
|
|
return genesis
|
|
}
|
|
|
|
func NewBytes(t testing.TB, c Config) []byte {
|
|
g := New(t, c)
|
|
genesisBytes, err := g.Bytes()
|
|
require.NoError(t, err)
|
|
return genesisBytes
|
|
}
|