Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X-chain - introducing fees calculators #2700

Open
wants to merge 139 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 138 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
1adc328
E fork scaffolding
abi87 Jan 10, 2024
f6d7382
Merge branch 'dev' into e-fork-scaffolding
abi87 Jan 10, 2024
3889e51
Merge branch 'dev' into e-fork-scaffolding
abi87 Jan 12, 2024
e725961
Merge branch 'dev' into e-fork-scaffolding
abi87 Jan 15, 2024
30a4343
Merge branch 'dev' into e-fork-scaffolding
abi87 Jan 16, 2024
add3a35
Merge branch 'dev' into e-fork-scaffolding
abi87 Jan 17, 2024
3d08216
Merge branch 'dev' into e-fork-scaffolding
abi87 Jan 18, 2024
8f35564
Merge branch 'dev' into e-fork-scaffolding
abi87 Jan 19, 2024
2b16538
Merge branch 'master' into e-fork-scaffolding
abi87 Jan 26, 2024
4751e79
Merge branch 'master' into e-fork-scaffolding
abi87 Jan 29, 2024
e00d7c9
drop temporary fork time
abi87 Jan 29, 2024
b454987
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 1, 2024
f832034
nits
abi87 Feb 1, 2024
62ab6d0
upgraded codec for dynamic fees
abi87 Feb 2, 2024
2241711
wip: introducing x-chain fee calculator
abi87 Feb 2, 2024
0318ea8
wip:fixing UTs
abi87 Feb 2, 2024
d33a6a2
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 7, 2024
d846cba
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 7, 2024
8a89505
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 8, 2024
3daec34
cleanup
abi87 Feb 8, 2024
b1fdd62
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 8, 2024
a80ab15
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Feb 9, 2024
a0020b1
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 9, 2024
1fb0662
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 9, 2024
c1fdd20
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Feb 9, 2024
f28b80b
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 12, 2024
26fcb79
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 13, 2024
4d100eb
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 13, 2024
38f0386
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Feb 13, 2024
ccb05f5
appease linter
abi87 Feb 13, 2024
199424b
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 15, 2024
3b76de5
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 15, 2024
5ea9c0b
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 15, 2024
603fbec
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 15, 2024
8bc3da9
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Feb 16, 2024
2b05cf1
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 16, 2024
0baba01
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 16, 2024
7512037
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Feb 16, 2024
9b97764
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 19, 2024
1368b48
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 19, 2024
3046509
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Feb 19, 2024
a4b81e6
fork switch to the avm
abi87 Feb 20, 2024
392e935
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 21, 2024
78a1a5c
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 21, 2024
d3a733e
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 22, 2024
a362312
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 22, 2024
d251fe6
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Feb 23, 2024
f735491
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 25, 2024
6a1af7c
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 25, 2024
fd8e512
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Feb 25, 2024
33e3b70
Merge branch 'master' into e-fork-scaffolding
abi87 Feb 29, 2024
507636e
latestFork in avm
abi87 Feb 29, 2024
399dfc8
default test config for a few unit tests
abi87 Feb 29, 2024
089af5e
come more unit tests helpers
abi87 Feb 29, 2024
bf58efb
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Feb 29, 2024
a78cd4d
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Feb 29, 2024
3c52428
Merge branch 'master' into e-fork-scaffolding
abi87 Mar 4, 2024
198c910
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Mar 4, 2024
83caa3f
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 4, 2024
e34e3de
Merge branch 'master' into e-fork-scaffolding
abi87 Mar 5, 2024
7feb04f
Merge branch 'master' into e-fork-scaffolding
abi87 Mar 6, 2024
43169f4
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Mar 6, 2024
7d7d1f7
Merge branch 'master' into e-fork-scaffolding
abi87 Mar 7, 2024
2dd14a8
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Mar 7, 2024
68a1f57
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 7, 2024
5992b33
Merge branch 'master' into e-fork-scaffolding
abi87 Mar 11, 2024
d5ccb3b
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Mar 11, 2024
dca34a5
fixed merge
abi87 Mar 11, 2024
8aaf991
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 11, 2024
cda811f
Merge branch 'master' into e-fork-scaffolding
abi87 Mar 11, 2024
cd989f3
nits from code reviews
abi87 Mar 11, 2024
32da156
some more nits from code reviews
abi87 Mar 11, 2024
be7cf3e
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Mar 11, 2024
d2525d5
fixed merge
abi87 Mar 11, 2024
c6dd66c
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 11, 2024
ae8231b
Merge branch 'master' into e-fork-scaffolding
abi87 Mar 12, 2024
8270220
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Mar 12, 2024
b7b0e0f
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 12, 2024
95d3ab5
Merge branch 'master' into e-fork-scaffolding
abi87 Mar 13, 2024
7a17a9b
drop DurangoTime from avm config
abi87 Mar 13, 2024
2906756
nit
abi87 Mar 13, 2024
d3edbaa
nit
abi87 Mar 13, 2024
3dbdd6b
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Mar 13, 2024
e1e905c
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 13, 2024
737d429
Merge branch 'master' into e-fork-scaffolding
abi87 Mar 18, 2024
b47ef55
Merge branch 'e-fork-scaffolding' into codec_upgrades_dynamic_fees
abi87 Mar 18, 2024
af94f10
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 18, 2024
ee6bd99
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 19, 2024
6834a9e
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 19, 2024
cede533
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 20, 2024
3b04b63
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 20, 2024
d2772ec
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 22, 2024
6c7c6ec
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 22, 2024
50e75f9
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 25, 2024
b4d8ff4
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 25, 2024
6f36d2e
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 26, 2024
8cad1b3
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 26, 2024
b2e0b3e
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 27, 2024
bd2311e
reverted unnecessary changes
abi87 Mar 27, 2024
a18bf63
Merge branch 'codec_upgrades_dynamic_fees' into x-chain_introducing-f…
abi87 Mar 27, 2024
6cd51ab
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Mar 27, 2024
bfb4e56
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Mar 28, 2024
d637d8b
unlocked UT
abi87 Mar 28, 2024
e8a4c19
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Mar 28, 2024
0cbf3cd
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Mar 29, 2024
5130928
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Mar 29, 2024
6282fa4
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 2, 2024
3af2422
introduced fee calculator constructor
abi87 Apr 2, 2024
f573101
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 3, 2024
4d668bd
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 4, 2024
5daa831
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 8, 2024
a1eadc0
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 9, 2024
212c379
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 11, 2024
f8afae3
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 12, 2024
1382841
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 15, 2024
b0d590e
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 16, 2024
dd00cc6
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 21, 2024
d5ffeda
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 23, 2024
69c942f
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 26, 2024
9e977df
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Apr 29, 2024
bf03947
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 May 2, 2024
b9e1435
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 May 6, 2024
ce35df7
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 May 8, 2024
69bd78e
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 May 9, 2024
1ec2242
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 May 10, 2024
fa985ae
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 May 13, 2024
7ba37af
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 May 14, 2024
acda18a
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 May 14, 2024
f8019bd
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Jun 11, 2024
a4631db
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Jul 12, 2024
8e0d84f
restructured calculator API
abi87 Jul 12, 2024
c2d6e86
repackaged avm static fee config
abi87 Jul 12, 2024
018988e
renamed fees package to fee
abi87 Jul 12, 2024
d890cbc
added tx fees uts
abi87 Jul 12, 2024
7f79fd1
reverted fee checks to synctactic verifier
abi87 Jul 12, 2024
5ffcc49
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Jul 15, 2024
c0b2f50
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Jul 15, 2024
3c69dba
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Jul 17, 2024
e7958b3
Merge branch 'master' into x-chain_introducing-fees-calculators
abi87 Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import (
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms"
"github.com/ava-labs/avalanchego/vms/avm"
"github.com/ava-labs/avalanchego/vms/avm/txs/fee"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/upgrade"
Expand Down Expand Up @@ -1249,9 +1250,11 @@ func (n *Node) initVMs() error {
}),
n.VMManager.RegisterFactory(context.TODO(), constants.AVMID, &avm.Factory{
Config: avmconfig.Config{
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
EUpgradeTime: eUpgradeTime,
StaticConfig: fee.StaticConfig{
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
},
EUpgradeTime: eUpgradeTime,
},
}),
n.VMManager.RegisterFactory(context.TODO(), constants.EVMID, &coreth.Factory{}),
Expand Down
4 changes: 4 additions & 0 deletions vms/avm/block/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/vms/avm/block"
"github.com/ava-labs/avalanchego/vms/avm/config"
"github.com/ava-labs/avalanchego/vms/avm/fxs"
"github.com/ava-labs/avalanchego/vms/avm/metrics"
"github.com/ava-labs/avalanchego/vms/avm/state"
Expand Down Expand Up @@ -523,6 +524,9 @@ func TestBlockBuilderAddLocalTx(t *testing.T) {
Ctx: &snow.Context{
Log: logging.NoLog{},
},
Config: &config.Config{
EUpgradeTime: mockable.MaxTime,
},
Codec: parser.Codec(),
}

Expand Down
9 changes: 6 additions & 3 deletions vms/avm/block/executor/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ava-labs/avalanchego/vms/avm/state"
"github.com/ava-labs/avalanchego/vms/avm/txs"
"github.com/ava-labs/avalanchego/vms/avm/txs/executor"
"github.com/ava-labs/avalanchego/vms/avm/txs/fee"
"github.com/ava-labs/avalanchego/vms/avm/txs/mempool"
)

Expand Down Expand Up @@ -939,9 +940,11 @@ func defaultTestBackend(bootstrapped bool, sharedMemory atomic.SharedMemory) *ex
Log: logging.NoLog{},
},
Config: &config.Config{
EUpgradeTime: mockable.MaxTime,
TxFee: 0,
CreateAssetTxFee: 0,
StaticConfig: fee.StaticConfig{
TxFee: 0,
CreateAssetTxFee: 0,
},
EUpgradeTime: mockable.MaxTime,
},
}
}
12 changes: 6 additions & 6 deletions vms/avm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

package config

import "time"
import (
"time"

"github.com/ava-labs/avalanchego/vms/avm/txs/fee"
)

// Struct collecting all the foundational parameters of the AVM
type Config struct {
// Fee that is burned by every non-asset creating transaction
TxFee uint64

// Fee that must be burned by every asset creating transaction
CreateAssetTxFee uint64
fee.StaticConfig

// Time of the E network upgrade
EUpgradeTime time.Time
Expand Down
9 changes: 6 additions & 3 deletions vms/avm/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ava-labs/avalanchego/vms/avm/config"
"github.com/ava-labs/avalanchego/vms/avm/fxs"
"github.com/ava-labs/avalanchego/vms/avm/txs"
"github.com/ava-labs/avalanchego/vms/avm/txs/fee"
"github.com/ava-labs/avalanchego/vms/avm/txs/txstest"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/nftfx"
Expand Down Expand Up @@ -230,9 +231,11 @@ func setup(tb testing.TB, c *envConfig) *environment {

func staticConfig(tb testing.TB, f fork) config.Config {
c := config.Config{
TxFee: testTxFee,
CreateAssetTxFee: testTxFee,
EUpgradeTime: mockable.MaxTime,
StaticConfig: fee.StaticConfig{
TxFee: testTxFee,
CreateAssetTxFee: testTxFee,
},
EUpgradeTime: mockable.MaxTime,
}

switch f {
Expand Down
96 changes: 30 additions & 66 deletions vms/avm/txs/executor/syntactic_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/vms/avm/txs"
"github.com/ava-labs/avalanchego/vms/avm/txs/fee"
"github.com/ava-labs/avalanchego/vms/components/avax"
)

Expand Down Expand Up @@ -51,18 +52,7 @@ type SyntacticVerifier struct {
}

func (v *SyntacticVerifier) BaseTx(tx *txs.BaseTx) error {
if err := tx.BaseTx.Verify(v.Ctx); err != nil {
return err
}

err := avax.VerifyTx(
v.Config.TxFee,
v.FeeAssetID,
[][]*avax.TransferableInput{tx.Ins},
[][]*avax.TransferableOutput{tx.Outs},
v.Codec,
)
if err != nil {
if err := v.verifyBaseTx(tx, nil, nil); err != nil {
return err
}

Expand Down Expand Up @@ -114,18 +104,7 @@ func (v *SyntacticVerifier) CreateAssetTx(tx *txs.CreateAssetTx) error {
}
}

if err := tx.BaseTx.BaseTx.Verify(v.Ctx); err != nil {
return err
}

err := avax.VerifyTx(
v.Config.CreateAssetTxFee,
v.FeeAssetID,
[][]*avax.TransferableInput{tx.Ins},
[][]*avax.TransferableOutput{tx.Outs},
v.Codec,
)
if err != nil {
if err := v.verifyBaseTx(&tx.BaseTx, nil, nil); err != nil {
return err
}

Expand Down Expand Up @@ -162,18 +141,7 @@ func (v *SyntacticVerifier) OperationTx(tx *txs.OperationTx) error {
return errNoOperations
}

if err := tx.BaseTx.BaseTx.Verify(v.Ctx); err != nil {
return err
}

err := avax.VerifyTx(
v.Config.TxFee,
v.FeeAssetID,
[][]*avax.TransferableInput{tx.Ins},
[][]*avax.TransferableOutput{tx.Outs},
v.Codec,
)
if err != nil {
if err := v.verifyBaseTx(&tx.BaseTx, nil, nil); err != nil {
return err
}

Expand Down Expand Up @@ -222,21 +190,7 @@ func (v *SyntacticVerifier) ImportTx(tx *txs.ImportTx) error {
return errNoImportInputs
}

if err := tx.BaseTx.BaseTx.Verify(v.Ctx); err != nil {
return err
}

err := avax.VerifyTx(
v.Config.TxFee,
v.FeeAssetID,
[][]*avax.TransferableInput{
tx.Ins,
tx.ImportedIns,
},
[][]*avax.TransferableOutput{tx.Outs},
v.Codec,
)
if err != nil {
if err := v.verifyBaseTx(&tx.BaseTx, tx.ImportedIns, nil); err != nil {
return err
}

Expand Down Expand Up @@ -264,21 +218,7 @@ func (v *SyntacticVerifier) ExportTx(tx *txs.ExportTx) error {
return errNoExportOutputs
}

if err := tx.BaseTx.BaseTx.Verify(v.Ctx); err != nil {
return err
}

err := avax.VerifyTx(
v.Config.TxFee,
v.FeeAssetID,
[][]*avax.TransferableInput{tx.Ins},
[][]*avax.TransferableOutput{
tx.Outs,
tx.ExportedOuts,
},
v.Codec,
)
if err != nil {
if err := v.verifyBaseTx(&tx.BaseTx, nil, tx.ExportedOuts); err != nil {
return err
}

Expand All @@ -300,3 +240,27 @@ func (v *SyntacticVerifier) ExportTx(tx *txs.ExportTx) error {

return nil
}

func (v *SyntacticVerifier) verifyBaseTx(
bTx *txs.BaseTx,
importedIns []*avax.TransferableInput,
exportedOuts []*avax.TransferableOutput,
) error {
if err := bTx.BaseTx.Verify(v.Ctx); err != nil {
return err
}

feeCalculator := fee.NewStaticCalculator(v.Backend.Config.StaticConfig)
fee, err := feeCalculator.CalculateFee(v.Tx)
if err != nil {
return err
}

return avax.VerifyTx(
fee,
v.FeeAssetID,
[][]*avax.TransferableInput{bTx.Ins, importedIns},
[][]*avax.TransferableOutput{bTx.Outs, exportedOuts},
v.Codec,
)
}
9 changes: 6 additions & 3 deletions vms/avm/txs/executor/syntactic_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ava-labs/avalanchego/vms/avm/config"
"github.com/ava-labs/avalanchego/vms/avm/fxs"
"github.com/ava-labs/avalanchego/vms/avm/txs"
"github.com/ava-labs/avalanchego/vms/avm/txs/fee"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
Expand All @@ -28,9 +29,11 @@ import (
var (
keys = secp256k1.TestKeys()
feeConfig = config.Config{
TxFee: 2,
CreateAssetTxFee: 3,
EUpgradeTime: mockable.MaxTime,
StaticConfig: fee.StaticConfig{
TxFee: 2,
CreateAssetTxFee: 3,
},
EUpgradeTime: mockable.MaxTime,
}
)

Expand Down
11 changes: 11 additions & 0 deletions vms/avm/txs/fee/calculator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package fee

import "github.com/ava-labs/avalanchego/vms/avm/txs"

// Calculator is the interfaces that any fee Calculator must implement
type Calculator interface {
CalculateFee(tx *txs.Tx) (uint64, error)
}
93 changes: 93 additions & 0 deletions vms/avm/txs/fee/calculator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action required) Should this be static_calculator_test.go?

// See the file LICENSE for licensing terms.

package fee

import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/avm/txs"
)

func TestTxFees(t *testing.T) {
feeTestsDefaultCfg := StaticConfig{
TxFee: 1 * units.Avax,
CreateAssetTxFee: 2 * units.Avax,
}

// chain times needed to have specific upgrades active
eUpgradeTime := time.Unix(1713945427, 0)
preEUpgradeTime := eUpgradeTime.Add(-1 * time.Second)

tests := []struct {
name string
chainTime time.Time
unsignedTx func() txs.UnsignedTx
expected uint64
}{
{
name: "BaseTx pre EUpgrade",
chainTime: preEUpgradeTime,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action required) Why is this parameter suggested for inclusion in the test case struct if it never varies?

unsignedTx: baseTx,
expected: feeTestsDefaultCfg.TxFee,
},
{
name: "CreateAssetTx pre EUpgrade",
chainTime: preEUpgradeTime,
unsignedTx: createAssetTx,
expected: feeTestsDefaultCfg.CreateAssetTxFee,
},
{
name: "OperationTx pre EUpgrade",
chainTime: preEUpgradeTime,
unsignedTx: operationTx,
expected: feeTestsDefaultCfg.TxFee,
},
{
name: "ImportTx pre EUpgrade",
chainTime: preEUpgradeTime,
unsignedTx: importTx,
expected: feeTestsDefaultCfg.TxFee,
},
{
name: "ExportTx pre EUpgrade",
chainTime: preEUpgradeTime,
unsignedTx: exportTx,
expected: feeTestsDefaultCfg.TxFee,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
uTx := tt.unsignedTx()
fc := NewStaticCalculator(feeTestsDefaultCfg)
haveFee, err := fc.CalculateFee(&txs.Tx{Unsigned: uTx})
require.NoError(t, err)
require.Equal(t, tt.expected, haveFee)
})
}
}

func baseTx() txs.UnsignedTx {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action required) Maybe just inline these values given that they aren't used anywhere else?

return &txs.BaseTx{}
}

func createAssetTx() txs.UnsignedTx {
return &txs.CreateAssetTx{}
}

func operationTx() txs.UnsignedTx {
return &txs.OperationTx{}
}

func importTx() txs.UnsignedTx {
return &txs.ImportTx{}
}

func exportTx() txs.UnsignedTx {
return &txs.ExportTx{}
}
Loading
Loading