diff --git a/vms/platformvm/blocks/builder/helpers_test.go b/vms/platformvm/blocks/builder/helpers_test.go index cc8c7706002f..30a0755452f2 100644 --- a/vms/platformvm/blocks/builder/helpers_test.go +++ b/vms/platformvm/blocks/builder/helpers_test.go @@ -130,7 +130,7 @@ func newEnvironment(t *testing.T) *environment { res.atomicUTXOs = avax.NewAtomicUTXOManager(res.ctx.SharedMemory, txs.Codec) res.uptimes = uptime.NewManager(res.state) - res.utxosHandler = utxo.NewHandler(res.ctx, res.clk, res.state, res.fx) + res.utxosHandler = utxo.NewHandler(res.ctx, res.clk, res.fx) res.txBuilder = txbuilder.New( res.ctx, diff --git a/vms/platformvm/blocks/executor/helpers_test.go b/vms/platformvm/blocks/executor/helpers_test.go index f077d0421d71..e260d7c5bb69 100644 --- a/vms/platformvm/blocks/executor/helpers_test.go +++ b/vms/platformvm/blocks/executor/helpers_test.go @@ -149,7 +149,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller) *environment { if ctrl == nil { res.state = defaultState(res.config, res.ctx, res.baseDB, rewardsCalc) res.uptimes = uptime.NewManager(res.state) - res.utxosHandler = utxo.NewHandler(res.ctx, res.clk, res.state, res.fx) + res.utxosHandler = utxo.NewHandler(res.ctx, res.clk, res.fx) res.txBuilder = p_tx_builder.New( res.ctx, res.config, @@ -163,7 +163,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller) *environment { genesisBlkID = ids.GenerateTestID() res.mockedState = state.NewMockState(ctrl) res.uptimes = uptime.NewManager(res.mockedState) - res.utxosHandler = utxo.NewHandler(res.ctx, res.clk, res.mockedState, res.fx) + res.utxosHandler = utxo.NewHandler(res.ctx, res.clk, res.fx) res.txBuilder = p_tx_builder.New( res.ctx, res.config, diff --git a/vms/platformvm/txs/builder/builder.go b/vms/platformvm/txs/builder/builder.go index 9ac71c1f03ca..14570ed7db82 100644 --- a/vms/platformvm/txs/builder/builder.go +++ b/vms/platformvm/txs/builder/builder.go @@ -174,7 +174,7 @@ func New( cfg *config.Config, clk *mockable.Clock, fx fx.Fx, - state state.Chain, + state state.State, atomicUTXOManager avax.AtomicUTXOManager, utxoSpender utxo.Spender, ) Builder { @@ -192,7 +192,7 @@ func New( type builder struct { avax.AtomicUTXOManager utxo.Spender - state state.Chain + state state.State cfg *config.Config ctx *snow.Context @@ -252,7 +252,7 @@ func (b *builder) NewImportTx( switch { case importedAVAX < b.cfg.TxFee: // imported amount goes toward paying tx fee var baseSigners [][]*secp256k1.PrivateKey - ins, outs, _, baseSigners, err = b.Spend(keys, 0, b.cfg.TxFee-importedAVAX, changeAddr) + ins, outs, _, baseSigners, err = b.Spend(b.state, keys, 0, b.cfg.TxFee-importedAVAX, changeAddr) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) } @@ -310,7 +310,7 @@ func (b *builder) NewExportTx( if err != nil { return nil, fmt.Errorf("amount (%d) + tx fee(%d) overflows", amount, b.cfg.TxFee) } - ins, outs, _, signers, err := b.Spend(keys, 0, toBurn, changeAddr) + ins, outs, _, signers, err := b.Spend(b.state, keys, 0, toBurn, changeAddr) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) } @@ -354,7 +354,7 @@ func (b *builder) NewCreateChainTx( ) (*txs.Tx, error) { timestamp := b.state.GetTimestamp() createBlockchainTxFee := b.cfg.GetCreateBlockchainTxFee(timestamp) - ins, outs, _, signers, err := b.Spend(keys, 0, createBlockchainTxFee, changeAddr) + ins, outs, _, signers, err := b.Spend(b.state, keys, 0, createBlockchainTxFee, changeAddr) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) } @@ -398,7 +398,7 @@ func (b *builder) NewCreateSubnetTx( ) (*txs.Tx, error) { timestamp := b.state.GetTimestamp() createSubnetTxFee := b.cfg.GetCreateSubnetTxFee(timestamp) - ins, outs, _, signers, err := b.Spend(keys, 0, createSubnetTxFee, changeAddr) + ins, outs, _, signers, err := b.Spend(b.state, keys, 0, createSubnetTxFee, changeAddr) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) } @@ -436,7 +436,7 @@ func (b *builder) NewAddValidatorTx( keys []*secp256k1.PrivateKey, changeAddr ids.ShortID, ) (*txs.Tx, error) { - ins, unstakedOuts, stakedOuts, signers, err := b.Spend(keys, stakeAmount, b.cfg.AddPrimaryNetworkValidatorFee, changeAddr) + ins, unstakedOuts, stakedOuts, signers, err := b.Spend(b.state, keys, stakeAmount, b.cfg.AddPrimaryNetworkValidatorFee, changeAddr) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) } @@ -478,7 +478,7 @@ func (b *builder) NewAddDelegatorTx( keys []*secp256k1.PrivateKey, changeAddr ids.ShortID, ) (*txs.Tx, error) { - ins, unlockedOuts, lockedOuts, signers, err := b.Spend(keys, stakeAmount, b.cfg.AddPrimaryNetworkDelegatorFee, changeAddr) + ins, unlockedOuts, lockedOuts, signers, err := b.Spend(b.state, keys, stakeAmount, b.cfg.AddPrimaryNetworkDelegatorFee, changeAddr) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) } @@ -519,7 +519,7 @@ func (b *builder) NewAddSubnetValidatorTx( keys []*secp256k1.PrivateKey, changeAddr ids.ShortID, ) (*txs.Tx, error) { - ins, outs, _, signers, err := b.Spend(keys, 0, b.cfg.TxFee, changeAddr) + ins, outs, _, signers, err := b.Spend(b.state, keys, 0, b.cfg.TxFee, changeAddr) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) } @@ -562,7 +562,7 @@ func (b *builder) NewRemoveSubnetValidatorTx( keys []*secp256k1.PrivateKey, changeAddr ids.ShortID, ) (*txs.Tx, error) { - ins, outs, _, signers, err := b.Spend(keys, 0, b.cfg.TxFee, changeAddr) + ins, outs, _, signers, err := b.Spend(b.state, keys, 0, b.cfg.TxFee, changeAddr) if err != nil { return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) } diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index 07f0f08b54cb..cca302f73b9a 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -201,7 +201,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { defer func() { require.NoError(shutdownEnvironment(env)) }() - ins, outs, _, signers, err := env.utxosHandler.Spend(preFundedKeys, 0, test.fee, ids.ShortEmpty) + ins, outs, _, signers, err := env.utxosHandler.Spend(env.state, preFundedKeys, 0, test.fee, ids.ShortEmpty) require.NoError(err) subnetAuth, subnetSigners, err := env.utxosHandler.Authorize(env.state, testSubnet1.ID(), preFundedKeys) diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index 7999b6395502..4a202ef226d8 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -55,7 +55,7 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { require.NoError(shutdownEnvironment(env)) }() - ins, outs, _, signers, err := env.utxosHandler.Spend(preFundedKeys, 0, test.fee, ids.ShortEmpty) + ins, outs, _, signers, err := env.utxosHandler.Spend(env.state, preFundedKeys, 0, test.fee, ids.ShortEmpty) require.NoError(err) // Create the tx diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 1ec3d69fae76..e18f3e15862a 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -130,7 +130,7 @@ func newEnvironment(postBanff bool) *environment { atomicUTXOs := avax.NewAtomicUTXOManager(ctx.SharedMemory, txs.Codec) uptimes := uptime.NewManager(baseState) - utxoHandler := utxo.NewHandler(ctx, &clk, baseState, fx) + utxoHandler := utxo.NewHandler(ctx, &clk, fx) txBuilder := builder.New( ctx, diff --git a/vms/platformvm/utxo/handler.go b/vms/platformvm/utxo/handler.go index 825c9114e436..501bb23cfcfd 100644 --- a/vms/platformvm/utxo/handler.go +++ b/vms/platformvm/utxo/handler.go @@ -75,6 +75,7 @@ type Spender interface { // the staking period // - [signers] the proof of ownership of the funds being moved Spend( + utxoReader avax.UTXOReader, keys []*secp256k1.PrivateKey, amount uint64, fee uint64, @@ -149,25 +150,23 @@ type Handler interface { func NewHandler( ctx *snow.Context, clk *mockable.Clock, - utxoReader avax.UTXOReader, fx fx.Fx, ) Handler { return &handler{ - ctx: ctx, - clk: clk, - utxosReader: utxoReader, - fx: fx, + ctx: ctx, + clk: clk, + fx: fx, } } type handler struct { - ctx *snow.Context - clk *mockable.Clock - utxosReader avax.UTXOReader - fx fx.Fx + ctx *snow.Context + clk *mockable.Clock + fx fx.Fx } func (h *handler) Spend( + utxoReader avax.UTXOReader, keys []*secp256k1.PrivateKey, amount uint64, fee uint64, @@ -183,7 +182,7 @@ func (h *handler) Spend( for _, key := range keys { addrs.Add(key.PublicKey().Address()) } - utxos, err := avax.GetAllUTXOs(h.utxosReader, addrs) // The UTXOs controlled by [keys] + utxos, err := avax.GetAllUTXOs(utxoReader, addrs) // The UTXOs controlled by [keys] if err != nil { return nil, nil, nil, nil, fmt.Errorf("couldn't get UTXOs: %w", err) } diff --git a/vms/platformvm/utxo/handler_test.go b/vms/platformvm/utxo/handler_test.go index c5eb2f6bc607..b377b8b5113a 100644 --- a/vms/platformvm/utxo/handler_test.go +++ b/vms/platformvm/utxo/handler_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" @@ -41,11 +40,7 @@ func TestVerifySpendUTXOs(t *testing.T) { h := &handler{ ctx: snow.DefaultContextTest(), clk: &mockable.Clock{}, - utxosReader: avax.NewUTXOState( - memdb.New(), - txs.Codec, - ), - fx: fx, + fx: fx, } // The handler time during a test, unless [chainTimestamp] is set diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index 7b9a82ea1339..016942f80a61 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -167,7 +167,7 @@ func (vm *VM) Initialize( } vm.atomicUtxosManager = avax.NewAtomicUTXOManager(chainCtx.SharedMemory, txs.Codec) - utxoHandler := utxo.NewHandler(vm.ctx, &vm.clock, vm.state, vm.fx) + utxoHandler := utxo.NewHandler(vm.ctx, &vm.clock, vm.fx) vm.uptimeManager = uptime.NewManager(vm.state) vm.UptimeLockedCalculator.SetCalculator(&vm.bootstrapped, &chainCtx.Lock, vm.uptimeManager)