mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
* feat(platformvm): CreateSovereignL1Tx — single-tx sovereign L1 launch
Adds a new platformvm tx type that atomically registers a sovereign L1
in one P-chain commit. Replaces what is today the four-step flow:
CreateNetworkTx + AddChainValidatorTx ×N + CreateChainTx ×K + ConvertNetworkToL1Tx
with one signed tx. After commit, the primary network has a permanent
record of the L1's network ID + initial validator set + chain manifest
+ on-chain validator-manager contract — but it does NOT track-chains
or validate the L1's blocks. The L1 runs its own consensus from
genesis. L2/L3/L4 follow the same pattern recursively.
Type shape:
type CreateSovereignL1Tx struct {
BaseTx
Owner fx.Owner // CreateNetworkTx parity
Validators []*ConvertNetworkToL1Validator // genesis validator set
Chains []*SovereignL1Chain // VM ID + genesis blob per chain
ManagerChainIdx uint32 // index into Chains[]
ManagerAddress types.JSONByteSlice // validator-manager contract
}
type SovereignL1Chain struct {
BlockchainName string
VMID ids.ID
FxIDs []ids.ID
GenesisData []byte
}
SyntacticVerify enforces:
- at least one validator (sorted, unique)
- at least one chain, ≤ MaxSovereignL1Chains (16)
- ManagerChainIdx is in range of Chains[]
- ManagerAddress ≤ MaxChainAddressLength
- per-chain name + VMID + FxIDs + genesis bounds
- BaseTx + Owner + each Validator each verify
Wired into:
- Visitor interface
- codec (registered as the next tx type after ConvertNetworkToL1Tx)
- signer + complexity + metrics + executor stubs across all visitor
implementations
Executor body is stubbed with a TODO. The atomic state transition
(mint new networkID from tx hash, seed validator-manager state,
register each Chain, charge fee) lands in a follow-up PR. This PR is
the type definition + interface plumbing so downstream tools (wallet,
CLI, fee calc, metrics) can target the tx type while the executor is
implemented.
* chore(node): kill subnet — chain/network vocabulary across node
Zero remaining `subnet|Subnet|SUBNET` in node Go source. Per canonical
no-subnet rule.
## Wire types (Go fields only; byte-level wire encoding unchanged)
message/wire/types.go TrackedSubnets → TrackedChains
message/wire/zap.go same on Read/Write
proto/p2p/p2p_zap.go SubnetUptime alias → ChainUptime
(consumes luxfi/proto rename in companion PR)
## Comment scrub
message/wire/types.go "(chain, subnet) pair" → "(chain, network) pair"
network/peer/handshake.go "primary-network or subnet" → "primary-network or per-chain"
node/node.go "per-subnet" → "per-chain"
"P→subnet warp" → "P→chain warp"
genesis/builder/builder.go "their own subnets" → "their own chains"
vms/platformvm/client.go dropped "subnet jargon" reference
vms/platformvm/service.go dropped "net / subnet jargon" reference
vms/platformvm/config/internal.go "subnet-spawned blockchain" → "per-chain blockchain"
## ICPSubnet (Internet Computer adapter)
ICPSubnet → ICPNet (type rename — unrelated to platform subnet,
but still a subnet word; killed for consistency)
map field `subnets` → `nets`
## Examples
wallet/network/primary/examples/bootstrap-hanzo/main.go:
--subnet-id → --network-id (CLI flag)
existingSubnetID local var → existingNetID
"subnet ID" log lines → "network ID"
"SUBNET_ID=" output → "NETWORK_ID="
"subnet-evm VM ID" → "EVM VM ID"
All comments rephrased.
wallet/network/primary/examples/heartbeat-tx/main.go: one comment
rephrase.
go.work workspace cleanup:
- Removed ./operator/go entry (placeholder; lux/operator polyglot
layout pending the cross-repo migration)
- Removed ./operator entry (mid-migration; nothing to build)
Build clean. Zero `grep -rIn "subnet|Subnet" --include="*.go"` matches.
220 lines
7.0 KiB
Go
220 lines
7.0 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package txs
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/runtime"
|
|
"github.com/luxfi/node/vms/components/verify"
|
|
lux "github.com/luxfi/utxo"
|
|
"github.com/luxfi/utxo/secp256k1fx"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func newRuntime(t *testing.T) *runtime.Runtime {
|
|
t.Helper()
|
|
return &runtime.Runtime{
|
|
NetworkID: 1337,
|
|
ChainID: ids.GenerateTestID(),
|
|
XAssetID: ids.GenerateTestID(),
|
|
}
|
|
}
|
|
|
|
func validBaseTxForAsset(rt *runtime.Runtime) BaseTx {
|
|
return BaseTx{
|
|
BaseTx: lux.BaseTx{
|
|
NetworkID: rt.NetworkID,
|
|
BlockchainID: rt.ChainID,
|
|
Ins: []*lux.TransferableInput{},
|
|
Outs: []*lux.TransferableOutput{},
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestCreateAssetTx_SyntacticVerify_NameTooShort(t *testing.T) {
|
|
rt := newRuntime(t)
|
|
tx := &CreateAssetTx{
|
|
BaseTx: validBaseTxForAsset(rt),
|
|
Name: "",
|
|
Symbol: "LUX",
|
|
}
|
|
require.ErrorIs(t, tx.SyntacticVerify(rt), ErrNameTooShort)
|
|
}
|
|
|
|
func TestCreateAssetTx_SyntacticVerify_NameTooLong(t *testing.T) {
|
|
rt := newRuntime(t)
|
|
tx := &CreateAssetTx{
|
|
BaseTx: validBaseTxForAsset(rt),
|
|
Name: strings.Repeat("a", maxNameLen+1),
|
|
Symbol: "LUX",
|
|
}
|
|
require.ErrorIs(t, tx.SyntacticVerify(rt), ErrNameTooLong)
|
|
}
|
|
|
|
func TestCreateAssetTx_SyntacticVerify_SymbolBadChar(t *testing.T) {
|
|
rt := newRuntime(t)
|
|
tx := &CreateAssetTx{
|
|
BaseTx: validBaseTxForAsset(rt),
|
|
Name: "ValidAsset",
|
|
Symbol: "lux", // must be upper-case
|
|
States: []*InitialState{{FxIndex: 0, Outs: []verify.State{}}},
|
|
}
|
|
require.ErrorIs(t, tx.SyntacticVerify(rt), ErrIllegalSymbolChar)
|
|
}
|
|
|
|
func TestCreateAssetTx_SyntacticVerify_DenominationTooLarge(t *testing.T) {
|
|
rt := newRuntime(t)
|
|
tx := &CreateAssetTx{
|
|
BaseTx: validBaseTxForAsset(rt),
|
|
Name: "LUX",
|
|
Symbol: "LUX",
|
|
Denomination: maxDenomination + 1,
|
|
States: []*InitialState{{FxIndex: 0, Outs: []verify.State{}}},
|
|
}
|
|
require.ErrorIs(t, tx.SyntacticVerify(rt), ErrDenominationTooLarge)
|
|
}
|
|
|
|
func TestCreateAssetTx_SyntacticVerify_NoInitialStates(t *testing.T) {
|
|
rt := newRuntime(t)
|
|
tx := &CreateAssetTx{
|
|
BaseTx: validBaseTxForAsset(rt),
|
|
Name: "LUX",
|
|
Symbol: "LUX",
|
|
States: nil,
|
|
}
|
|
require.ErrorIs(t, tx.SyntacticVerify(rt), ErrNoInitialStates)
|
|
}
|
|
|
|
func TestCreateAssetTx_SyntacticVerify_NonZeroFxIndexRejected(t *testing.T) {
|
|
rt := newRuntime(t)
|
|
tx := &CreateAssetTx{
|
|
BaseTx: validBaseTxForAsset(rt),
|
|
Name: "LUX",
|
|
Symbol: "LUX",
|
|
Denomination: 9,
|
|
States: []*InitialState{{FxIndex: 1, Outs: []verify.State{}}},
|
|
}
|
|
require.ErrorIs(t, tx.SyntacticVerify(rt), ErrInitialStateNonZero)
|
|
}
|
|
|
|
func TestCreateAssetTx_CodecRoundtrip(t *testing.T) {
|
|
require := require.New(t)
|
|
tx := &CreateAssetTx{
|
|
BaseTx: BaseTx{
|
|
BaseTx: lux.BaseTx{
|
|
NetworkID: 1337,
|
|
BlockchainID: ids.GenerateTestID(),
|
|
},
|
|
},
|
|
Name: "LUX",
|
|
Symbol: "LUX",
|
|
Denomination: 9,
|
|
States: []*InitialState{
|
|
{FxIndex: 0, Outs: []verify.State{
|
|
&secp256k1fx.TransferOutput{
|
|
Amt: 1,
|
|
OutputOwners: secp256k1fx.OutputOwners{
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{ids.GenerateTestShortID()},
|
|
},
|
|
},
|
|
}},
|
|
},
|
|
}
|
|
|
|
var unsigned UnsignedTx = tx
|
|
bytes, err := Codec.Marshal(CodecVersion, &unsigned)
|
|
require.NoError(err)
|
|
|
|
var roundtripped UnsignedTx
|
|
_, err = Codec.Unmarshal(bytes, &roundtripped)
|
|
require.NoError(err)
|
|
|
|
got, ok := roundtripped.(*CreateAssetTx)
|
|
require.True(ok)
|
|
require.Equal(tx.Name, got.Name)
|
|
require.Equal(tx.Symbol, got.Symbol)
|
|
require.Equal(tx.Denomination, got.Denomination)
|
|
require.Equal(len(tx.States), len(got.States))
|
|
}
|
|
|
|
func TestOperationTx_SyntacticVerify_NoOperations(t *testing.T) {
|
|
rt := newRuntime(t)
|
|
tx := &OperationTx{
|
|
BaseTx: validBaseTxForAsset(rt),
|
|
Ops: nil,
|
|
}
|
|
require.ErrorIs(t, tx.SyntacticVerify(rt), ErrNoOperations)
|
|
}
|
|
|
|
func TestOperationTx_VisitorDispatches(t *testing.T) {
|
|
require := require.New(t)
|
|
tx := &OperationTx{}
|
|
|
|
called := false
|
|
v := &mockVisitor{operationFn: func(*OperationTx) error {
|
|
called = true
|
|
return nil
|
|
}}
|
|
require.NoError(tx.Visit(v))
|
|
require.True(called)
|
|
}
|
|
|
|
func TestCreateAssetTx_VisitorDispatches(t *testing.T) {
|
|
require := require.New(t)
|
|
tx := &CreateAssetTx{}
|
|
|
|
called := false
|
|
v := &mockVisitor{createAssetFn: func(*CreateAssetTx) error {
|
|
called = true
|
|
return nil
|
|
}}
|
|
require.NoError(tx.Visit(v))
|
|
require.True(called)
|
|
}
|
|
|
|
// mockVisitor stubs every Visitor method but the two we exercise here.
|
|
type mockVisitor struct {
|
|
createAssetFn func(*CreateAssetTx) error
|
|
operationFn func(*OperationTx) error
|
|
}
|
|
|
|
func (*mockVisitor) AddValidatorTx(*AddValidatorTx) error { return nil }
|
|
func (*mockVisitor) AddChainValidatorTx(*AddChainValidatorTx) error { return nil }
|
|
func (*mockVisitor) AddDelegatorTx(*AddDelegatorTx) error { return nil }
|
|
func (*mockVisitor) CreateNetworkTx(*CreateNetworkTx) error { return nil }
|
|
func (*mockVisitor) CreateChainTx(*CreateChainTx) error { return nil }
|
|
func (*mockVisitor) ImportTx(*ImportTx) error { return nil }
|
|
func (*mockVisitor) ExportTx(*ExportTx) error { return nil }
|
|
func (*mockVisitor) AdvanceTimeTx(*AdvanceTimeTx) error { return nil }
|
|
func (*mockVisitor) RewardValidatorTx(*RewardValidatorTx) error { return nil }
|
|
func (*mockVisitor) RemoveChainValidatorTx(*RemoveChainValidatorTx) error { return nil }
|
|
func (*mockVisitor) TransformChainTx(*TransformChainTx) error { return nil }
|
|
func (*mockVisitor) AddPermissionlessValidatorTx(*AddPermissionlessValidatorTx) error { return nil }
|
|
func (*mockVisitor) AddPermissionlessDelegatorTx(*AddPermissionlessDelegatorTx) error { return nil }
|
|
func (*mockVisitor) TransferChainOwnershipTx(*TransferChainOwnershipTx) error { return nil }
|
|
func (*mockVisitor) BaseTx(*BaseTx) error { return nil }
|
|
func (*mockVisitor) ConvertNetworkToL1Tx(*ConvertNetworkToL1Tx) error { return nil }
|
|
func (*mockVisitor) CreateSovereignL1Tx(*CreateSovereignL1Tx) error { return nil }
|
|
func (*mockVisitor) RegisterL1ValidatorTx(*RegisterL1ValidatorTx) error { return nil }
|
|
func (*mockVisitor) SetL1ValidatorWeightTx(*SetL1ValidatorWeightTx) error { return nil }
|
|
func (*mockVisitor) IncreaseL1ValidatorBalanceTx(*IncreaseL1ValidatorBalanceTx) error { return nil }
|
|
func (*mockVisitor) DisableL1ValidatorTx(*DisableL1ValidatorTx) error { return nil }
|
|
func (*mockVisitor) SlashValidatorTx(*SlashValidatorTx) error { return nil }
|
|
func (m *mockVisitor) CreateAssetTx(tx *CreateAssetTx) error {
|
|
if m.createAssetFn != nil {
|
|
return m.createAssetFn(tx)
|
|
}
|
|
return nil
|
|
}
|
|
func (m *mockVisitor) OperationTx(tx *OperationTx) error {
|
|
if m.operationFn != nil {
|
|
return m.operationFn(tx)
|
|
}
|
|
return nil
|
|
}
|