Files
zeekay 7cf87b230b node-unified is the node
The module already called itself github.com/luxfi/node while containing no node
in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and
the Go column of the matrix measured a VM plugin. A repo that fetches the thing
it claims to be has not replaced it, so the Go sources move in — 1515 files,
the daemon and everything under it — and the build reaches outside this module
for nothing.

Rust and C++ sit beside it unchanged and are still measured against it by the
differential. That is the point of one repo: the reference implementation and
the two ports are the same checkout, so parity is a thing you can run rather
than a thing you assert.

Verified: builds, and the closure carries no lux-private — checked at build time
rather than believed. The daemon starts twelve chains on a local network
(P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
2026-09-07 16:15:25 -07:00

166 lines
4.0 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package executor
import (
"errors"
"fmt"
"time"
"github.com/luxfi/ids"
"github.com/luxfi/node/vms/platformvm/state"
"github.com/luxfi/node/vms/platformvm/txs"
)
var (
_ txs.Visitor = (*MempoolTxVerifier)(nil)
ErrFutureStakeTime = errors.New("staker starts in the future")
)
type MempoolTxVerifier struct {
*Backend
ParentID ids.ID
StateVersions state.Versions
Tx *txs.Tx
}
func (*MempoolTxVerifier) RewardValidatorTx(*txs.RewardValidatorTx) error {
return ErrWrongTxType
}
func (v *MempoolTxVerifier) AddValidatorTx(tx *txs.AddValidatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) AddChainValidatorTx(tx *txs.AddChainValidatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) AddDelegatorTx(tx *txs.AddDelegatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) CreateChainTx(tx *txs.CreateChainTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) CreateNetworkTx(tx *txs.CreateNetworkTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) ImportTx(tx *txs.ImportTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) ExportTx(tx *txs.ExportTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) RemoveChainValidatorTx(tx *txs.RemoveChainValidatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) TransformChainTx(tx *txs.TransformChainTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) AddPermissionlessValidatorTx(tx *txs.AddPermissionlessValidatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) AddPermissionlessDelegatorTx(tx *txs.AddPermissionlessDelegatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) TransferChainOwnershipTx(tx *txs.TransferChainOwnershipTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) BaseTx(tx *txs.BaseTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) ConvertNetworkTx(tx *txs.ConvertNetworkTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) RegisterL1ValidatorTx(tx *txs.RegisterL1ValidatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) SetL1ValidatorWeightTx(tx *txs.SetL1ValidatorWeightTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) IncreaseL1ValidatorBalanceTx(tx *txs.IncreaseL1ValidatorBalanceTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) DisableL1ValidatorTx(tx *txs.DisableL1ValidatorTx) error {
return v.standardTx(tx)
}
func (v *MempoolTxVerifier) standardTx(tx txs.UnsignedTx) error {
baseState, err := v.standardBaseState()
if err != nil {
return err
}
executor := standardTxExecutor{
backend: v.Backend,
state: baseState,
tx: v.Tx,
}
err = tx.Visit(&executor)
// We ignore [ErrFutureStakeTime] here because the time will be advanced
// when this transaction is issued.
if errors.Is(err, ErrFutureStakeTime) {
return nil
}
return err
}
func (v *MempoolTxVerifier) standardBaseState() (state.Diff, error) {
state, err := state.NewDiff(v.ParentID, v.StateVersions)
if err != nil {
return nil, err
}
nextBlkTime, err := v.nextBlockTime(state)
if err != nil {
return nil, err
}
_, err = AdvanceTimeTo(v.Backend, state, nextBlkTime)
if err != nil {
return nil, err
}
state.SetTimestamp(nextBlkTime)
return state, nil
}
func (v *MempoolTxVerifier) nextBlockTime(chainState state.Diff) (time.Time, error) {
var (
parentTime = chainState.GetTimestamp()
nextBlkTime = v.Clk.Time()
)
if parentTime.After(nextBlkTime) {
nextBlkTime = parentTime
}
nextStakerChangeTime, err := state.GetNextStakerChangeTime(
v.Backend.Config.ValidatorFeeConfig,
chainState,
nextBlkTime,
)
if err != nil {
return time.Time{}, fmt.Errorf("could not calculate next staker change time: %w", err)
}
if !nextBlkTime.Before(nextStakerChangeTime) {
nextBlkTime = nextStakerChangeTime
}
return nextBlkTime, nil
}