refactor(platformvm): remove dead LUXAssetID fallback + unify asset-id naming to UTXOAssetID

The fallback if/else had identical branches (dead code); collapse to a single assignment. Rename stale LUXAssetID comment + utxosByLUXAssetID local var to the canonical UTXOAssetID.

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
This commit is contained in:
Antje Worring
2026-06-06 23:26:24 -07:00
co-authored by Hanzo Dev
parent 32e77e7db6
commit 3635d010b7
3 changed files with 19 additions and 24 deletions
+4 -4
View File
@@ -4,7 +4,6 @@
package txstest
import (
"github.com/luxfi/runtime"
"github.com/luxfi/crypto/secp256k1"
"github.com/luxfi/ids"
wkeychain "github.com/luxfi/keychain"
@@ -13,6 +12,7 @@ import (
"github.com/luxfi/node/vms/platformvm/state"
"github.com/luxfi/node/wallet/chain/p/builder"
"github.com/luxfi/node/wallet/chain/p/signer"
"github.com/luxfi/runtime"
"github.com/luxfi/utxo/secp256k1fx"
)
@@ -74,9 +74,9 @@ func (w *WalletFactory) NewWallet(keys ...*secp256k1.PrivateKey) (builder.Builde
kc = secp256k1fx.NewKeychain(keys...)
addrSet = kc.AddressSet()
backend = newBackend(addrSet, w.state)
// Extract networkID and LUXAssetID from context
networkID = w.rt.NetworkID
utxoAssetID = w.rt.UTXOAssetID
// Extract networkID and UTXOAssetID from context
networkID = w.rt.NetworkID
utxoAssetID = w.rt.UTXOAssetID
)
context := newContext(w.rt, networkID, utxoAssetID, w.cfg, nil, w.state.GetTimestamp())
+7 -12
View File
@@ -94,12 +94,12 @@ type VM struct {
db database.Database
// Additional fields needed for platformvm
log log.Logger
nodeID ids.NodeID
lock sync.RWMutex
log log.Logger
nodeID ids.NodeID
lock sync.RWMutex
utxoAssetID ids.ID
chainID ids.ID
state state.State
chainID ids.ID
state state.State
fx fx.Fx
codecRegistry pcodecs.Registry
@@ -224,13 +224,8 @@ func (vm *VM) Initialize(
// Initialize utxo.UTXOAssetID from the context
utxo.UTXOAssetID = init.Runtime.UTXOAssetID
// Initialize vm.utxoAssetID for GetStakingAssetID API
// Use LUXAssetID if set, otherwise fall back to UTXOAssetID
if init.Runtime.UTXOAssetID != ids.Empty {
vm.utxoAssetID = init.Runtime.UTXOAssetID
} else {
vm.utxoAssetID = init.Runtime.UTXOAssetID
}
// Initialize vm.utxoAssetID for the GetStakingAssetID API.
vm.utxoAssetID = init.Runtime.UTXOAssetID
// Get the current database from the DBManager
// Since DBManager is now an interface{}, we need to handle it differently
+8 -8
View File
@@ -10,21 +10,21 @@ import (
"time"
"github.com/luxfi/constants"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/ids"
"github.com/luxfi/math/set"
"github.com/luxfi/node/utils"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/node/utils/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/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/txs/fee"
"github.com/luxfi/utxo/secp256k1fx"
"github.com/luxfi/node/wallet/network/primary/common"
lux "github.com/luxfi/utxo"
"github.com/luxfi/utxo/secp256k1fx"
)
var (
@@ -1138,7 +1138,7 @@ func (b *builder) NewImportTx(
var (
addrs = ops.Addresses(b.addrs)
minIssuanceTime = ops.MinIssuanceTime()
utxoAssetID = b.context.UTXOAssetID
utxoAssetID = b.context.UTXOAssetID
importedInputs = make([]*lux.TransferableInput, 0, len(utxos))
importedAmounts = make(map[ids.ID]uint64)
@@ -1718,8 +1718,8 @@ func (b *builder) spend(
}
// LUX is handled last to account for fees.
utxosByLUXAssetID := splitByAssetID(utxosByLocktime.unlocked, b.context.UTXOAssetID)
for _, utxo := range utxosByLUXAssetID.other {
utxosByUTXOAssetID := splitByAssetID(utxosByLocktime.unlocked, b.context.UTXOAssetID)
for _, utxo := range utxosByUTXOAssetID.other {
assetID := utxo.AssetID()
if !s.shouldConsumeAsset(assetID) {
continue
@@ -1768,7 +1768,7 @@ func (b *builder) spend(
}
}
for _, utxo := range utxosByLUXAssetID.requested {
for _, utxo := range utxosByUTXOAssetID.requested {
// Check if we already have enough excessLUX to pay fees before adding more inputs.
// This early exit is crucial for ImportTx where imported inputs may already provide
// sufficient LUX to cover fees, and we don't want to add unnecessary platform chain inputs.
@@ -1894,7 +1894,7 @@ func (b *builder) spend(
// If excessLUX <= feeWithChange, we don't add the change output
// and we don't modify s.complexity (it stays without the change output)
utils.Sort(s.inputs) // sort inputs
utils.Sort(s.inputs) // sort inputs
lux.SortTransferableOutputs(s.changeOutputs) // sort the change outputs
lux.SortTransferableOutputs(s.stakeOutputs) // sort stake outputs
return s.inputs, s.changeOutputs, s.stakeOutputs, nil