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

P-Chain: Block-level fee Calculator #3032

Merged
merged 210 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
210 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
e01eb83
introduced fees calculator in P-chain
abi87 Feb 2, 2024
62ab6d0
upgraded codec for dynamic fees
abi87 Feb 2, 2024
9af11ca
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
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
af2c721
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
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
e27e938
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
abi87 Feb 8, 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
0dfe25a
Merge branch 'codec_upgrades_dynamic_fees' into p-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
5e09b5e
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
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
da5df60
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
abi87 Feb 15, 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
9c4a2b3
Merge branch 'codec_upgrades_dynamic_fees' into p-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
56343d3
Merge branch 'codec_upgrades_dynamic_fees' into p-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
59348c7
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
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
3bcb51a
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
abi87 Feb 22, 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
e375a83
Merge branch 'codec_upgrades_dynamic_fees' into p-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
cf039ed
Merge branch 'codec_upgrades_dynamic_fees' into p-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
4c674f0
Merge branch 'codec_upgrades_dynamic_fees' into p-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
9265060
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
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
d82f588
Merge branch 'codec_upgrades_dynamic_fees' into p-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
2e4e469
Merge branch 'codec_upgrades_dynamic_fees' into p-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
287dbb5
Merge branch 'codec_upgrades_dynamic_fees' into p-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
210bac8
Merge branch 'codec_upgrades_dynamic_fees' into p-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
1c7f823
Merge branch 'codec_upgrades_dynamic_fees' into p-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
9646588
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
abi87 Mar 18, 2024
ee6bd99
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 19, 2024
65b11b7
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
abi87 Mar 19, 2024
cede533
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 20, 2024
7aff1c8
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
abi87 Mar 20, 2024
d2772ec
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 22, 2024
d03e145
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
abi87 Mar 22, 2024
50e75f9
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 25, 2024
b391c11
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
abi87 Mar 25, 2024
6f36d2e
Merge branch 'master' into codec_upgrades_dynamic_fees
abi87 Mar 26, 2024
9111a95
Merge branch 'codec_upgrades_dynamic_fees' into p-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
326a6d5
Merge branch 'codec_upgrades_dynamic_fees' into p-chain_introducing-f…
abi87 Mar 27, 2024
4a8141a
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Mar 27, 2024
b979b51
reduced diff
abi87 Mar 27, 2024
d09f885
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Mar 28, 2024
e43c69f
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Mar 29, 2024
b5962db
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Mar 29, 2024
c313a0f
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 2, 2024
5c22480
introduced fee StaticCalculator constructor
abi87 Apr 2, 2024
23060c5
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 2, 2024
0ffc651
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 3, 2024
fed7e67
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 4, 2024
231b2eb
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 8, 2024
6b72744
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 9, 2024
ced3f8d
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 11, 2024
c00888c
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 12, 2024
465f97d
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 15, 2024
4a1f2fe
nit
abi87 Apr 15, 2024
c078f1d
simplified p-chain config
abi87 Apr 15, 2024
c81c85e
added UTs
abi87 Apr 15, 2024
1867461
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 16, 2024
3d45cc4
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 17, 2024
ab782a5
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 21, 2024
8358f84
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 23, 2024
4583289
P chain introducing fees calculators fee config (#2960)
abi87 Apr 23, 2024
095a8f6
nits to address code reviews comments
abi87 Apr 24, 2024
796fc2f
minor renaming
abi87 Apr 24, 2024
6bc3091
simplified unit tests
abi87 Apr 24, 2024
eea8069
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 24, 2024
73cc339
Fee Calculator Refactor (#2964)
joshua-kim Apr 24, 2024
f008446
nit
abi87 Apr 25, 2024
dda8de7
Merge branch 'p-chain_introducing-fees-calculators' of github.com:ava…
abi87 Apr 25, 2024
2776ea7
nit
abi87 Apr 26, 2024
7bcd8f7
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 26, 2024
a104358
nit
abi87 Apr 26, 2024
cbc99ee
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 Apr 29, 2024
2b4cdbc
nits
abi87 Apr 29, 2024
54d05d7
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 2, 2024
09cfe24
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 6, 2024
eb98d60
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 7, 2024
62fc922
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 9, 2024
bf2d5e9
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 10, 2024
db597d3
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 13, 2024
6bc5f25
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 13, 2024
66ef59c
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 14, 2024
1747485
repackaged upgrades times into upgrade package
abi87 May 14, 2024
c1d8df8
Merge branch 'p-chain_repack_config' into p-chain_introducing-fees-ca…
abi87 May 14, 2024
8cbc4e2
simplified fee unit test setup
abi87 May 14, 2024
8a268b0
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 14, 2024
8852376
nits
abi87 May 14, 2024
10176c9
nit
abi87 May 15, 2024
530084e
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 16, 2024
c815178
nit
abi87 May 16, 2024
3fd10bc
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 20, 2024
eee5aba
drop duplicated fields
abi87 May 20, 2024
be373e2
replaced genesis.TxFeeConfig with fee.StaticConfig
abi87 May 20, 2024
34631c6
moved FeeCalculator instatiation to block level
abi87 May 20, 2024
32e26d5
feeding chainTime to fee Calculator to ctor
abi87 May 20, 2024
e2f8809
nit
abi87 May 21, 2024
0fe0367
Merge branch 'master' into p-chain_introducing-fees-calculators
abi87 May 21, 2024
1956713
Merge branch 'p-chain_introducing-fees-calculators' into p-chain_bloc…
abi87 May 21, 2024
2e4cbf6
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 May 21, 2024
708bb36
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 May 21, 2024
c402171
nit
abi87 May 21, 2024
59165aa
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 May 29, 2024
ecb9090
nits
abi87 May 29, 2024
09baf61
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 Jun 3, 2024
eb023ee
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 Jun 7, 2024
7594ec7
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 Jun 7, 2024
2e4ccad
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 Jun 10, 2024
b549906
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 Jun 10, 2024
11a4ef8
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 Jun 17, 2024
34aa429
Merge branch 'master' into p-chain_block_level_fee_calculator
abi87 Jun 24, 2024
ac5b00c
restructured p-chain calculator
abi87 Jun 24, 2024
e88298c
restructured fee calculator API
abi87 Jun 24, 2024
13017be
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jun 24, 2024
1c68b9a
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jun 24, 2024
da722bc
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jun 24, 2024
71bf522
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jun 27, 2024
9a9beff
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jun 27, 2024
e65b33c
consolidated fee Calculator creation
abi87 Jun 27, 2024
dc138ad
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jun 28, 2024
25e931a
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jun 28, 2024
cecf0fd
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jul 1, 2024
dd2b382
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jul 1, 2024
e5f0fd3
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jul 1, 2024
2a6bdeb
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jul 3, 2024
fc95471
nits
abi87 Jul 3, 2024
99c930e
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jul 3, 2024
9937663
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jul 4, 2024
b18ef30
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jul 4, 2024
2aab1a4
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jul 5, 2024
a74536e
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jul 5, 2024
4c764d4
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jul 9, 2024
89d9726
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jul 10, 2024
4d6f679
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jul 12, 2024
ccb5943
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jul 12, 2024
493305e
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jul 13, 2024
999a468
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jul 13, 2024
db0cdfd
Merge branch 'master' into p-chain_improved_fee_calculator_structure
abi87 Jul 15, 2024
f6c3a49
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jul 15, 2024
0a2715f
reduce diff
StephenButtolph Jul 15, 2024
1fc03ef
Merge branch 'p-chain_improved_fee_calculator_structure' into p-chain…
abi87 Jul 15, 2024
6b9a309
merged
StephenButtolph Jul 15, 2024
d06a87f
Merge branch 'p-chain_block_level_fee_calculator' of github.com:ava-l…
StephenButtolph Jul 15, 2024
1a1dcc2
merged
StephenButtolph Jul 15, 2024
46442c9
nits
StephenButtolph Jul 15, 2024
d288bb5
nit
StephenButtolph Jul 15, 2024
885bea0
nit
StephenButtolph Jul 15, 2024
0941ecb
nit
StephenButtolph Jul 15, 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
13 changes: 9 additions & 4 deletions vms/platformvm/block/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,15 @@ func packBlockTxs(
return nil, err
}

feeCalculator, err := state.PickFeeCalculator(backend.Config, stateDiff)
if err != nil {
return nil, err
}

var (
blockTxs []*txs.Tx
inputs set.Set[ids.ID]
)

for {
tx, exists := mempool.Peek()
if !exists {
Expand All @@ -355,9 +359,10 @@ func packBlockTxs(
}

executor := &txexecutor.StandardTxExecutor{
Backend: backend,
State: txDiff,
Tx: tx,
Backend: backend,
State: txDiff,
FeeCalculator: feeCalculator,
marun marked this conversation as resolved.
Show resolved Hide resolved
Tx: tx,
}

err = tx.Unsigned.Visit(executor)
Expand Down
11 changes: 8 additions & 3 deletions vms/platformvm/block/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,20 @@ func addSubnet(t *testing.T, env *environment) {
stateDiff, err := state.NewDiff(genesisID, env.blkManager)
require.NoError(err)

feeCalculator, err := state.PickFeeCalculator(env.config, stateDiff)
require.NoError(err)

executor := txexecutor.StandardTxExecutor{
Backend: &env.backend,
State: stateDiff,
Tx: testSubnet1,
Backend: &env.backend,
State: stateDiff,
FeeCalculator: feeCalculator,
Tx: testSubnet1,
}
require.NoError(testSubnet1.Unsigned.Visit(&executor))

stateDiff.AddTx(testSubnet1, status.Committed)
require.NoError(stateDiff.Apply(env.state))
require.NoError(env.state.Commit())
}

func defaultState(
Expand Down
14 changes: 11 additions & 3 deletions vms/platformvm/block/executor/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,16 @@ func addSubnet(env *environment) {
if err != nil {
panic(err)
}
feeCalculator, err := state.PickFeeCalculator(env.config, stateDiff)
if err != nil {
panic(err)
}

executor := executor.StandardTxExecutor{
Backend: env.backend,
State: stateDiff,
Tx: testSubnet1,
Backend: env.backend,
State: stateDiff,
FeeCalculator: feeCalculator,
Tx: testSubnet1,
}
err = testSubnet1.Unsigned.Visit(&executor)
if err != nil {
Expand All @@ -295,6 +300,9 @@ func addSubnet(env *environment) {
if err := stateDiff.Apply(env.state); err != nil {
panic(err)
}
if err := env.state.Commit(); err != nil {
panic(err)
}
}

func defaultState(
Expand Down
12 changes: 9 additions & 3 deletions vms/platformvm/block/executor/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,16 @@ func (m *manager) VerifyTx(tx *txs.Tx) error {
return err
}

feeCalculator, err := state.PickFeeCalculator(m.txExecutorBackend.Config, stateDiff)
if err != nil {
return err
}

return tx.Unsigned.Visit(&executor.StandardTxExecutor{
Backend: m.txExecutorBackend,
State: stateDiff,
Tx: tx,
Backend: m.txExecutorBackend,
State: stateDiff,
FeeCalculator: feeCalculator,
Tx: tx,
})
}

Expand Down
52 changes: 43 additions & 9 deletions vms/platformvm/block/executor/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/status"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
)

var (
Expand Down Expand Up @@ -66,7 +67,17 @@ func (v *verifier) BanffProposalBlock(b *block.BanffProposalBlock) error {
return err
}

inputs, atomicRequests, onAcceptFunc, err := v.processStandardTxs(b.Transactions, onDecisionState, b.Parent())
feeCalculator, err := state.PickFeeCalculator(v.txExecutorBackend.Config, onDecisionState)
if err != nil {
return err
}

inputs, atomicRequests, onAcceptFunc, err := v.processStandardTxs(
b.Transactions,
feeCalculator,
onDecisionState,
b.Parent(),
)
if err != nil {
return err
}
Expand All @@ -86,6 +97,7 @@ func (v *verifier) BanffProposalBlock(b *block.BanffProposalBlock) error {
onDecisionState,
onCommitState,
onAbortState,
feeCalculator,
inputs,
atomicRequests,
onAcceptFunc,
Expand Down Expand Up @@ -119,7 +131,11 @@ func (v *verifier) BanffStandardBlock(b *block.BanffStandardBlock) error {
return errBanffStandardBlockWithoutChanges
}

return v.standardBlock(&b.ApricotStandardBlock, onAcceptState)
feeCalculator, err := state.PickFeeCalculator(v.txExecutorBackend.Config, onAcceptState)
if err != nil {
return err
}
return v.standardBlock(&b.ApricotStandardBlock, feeCalculator, onAcceptState)
}

func (v *verifier) ApricotAbortBlock(b *block.ApricotAbortBlock) error {
Expand Down Expand Up @@ -151,7 +167,13 @@ func (v *verifier) ApricotProposalBlock(b *block.ApricotProposalBlock) error {
return err
}

return v.proposalBlock(b, nil, onCommitState, onAbortState, nil, nil, nil)
var (
staticFeeConfig = v.txExecutorBackend.Config.StaticFeeConfig
upgradeConfig = v.txExecutorBackend.Config.UpgradeConfig
timestamp = onCommitState.GetTimestamp() // Equal to parent timestamp
feeCalculator = fee.NewStaticCalculator(staticFeeConfig, upgradeConfig, timestamp)
)
return v.proposalBlock(b, nil, onCommitState, onAbortState, feeCalculator, nil, nil, nil)
}

func (v *verifier) ApricotStandardBlock(b *block.ApricotStandardBlock) error {
Expand All @@ -165,7 +187,13 @@ func (v *verifier) ApricotStandardBlock(b *block.ApricotStandardBlock) error {
return err
}

return v.standardBlock(b, onAcceptState)
var (
staticFeeConfig = v.txExecutorBackend.Config.StaticFeeConfig
upgradeConfig = v.txExecutorBackend.Config.UpgradeConfig
timestamp = onAcceptState.GetTimestamp() // Equal to parent timestamp
feeCalculator = fee.NewStaticCalculator(staticFeeConfig, upgradeConfig, timestamp)
)
return v.standardBlock(b, feeCalculator, onAcceptState)
}

func (v *verifier) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error {
Expand All @@ -187,8 +215,10 @@ func (v *verifier) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error {
)
}

feeCalculator := fee.NewStaticCalculator(v.txExecutorBackend.Config.StaticFeeConfig, v.txExecutorBackend.Config.UpgradeConfig, currentTimestamp)
atomicExecutor := executor.AtomicTxExecutor{
Backend: v.txExecutorBackend,
FeeCalculator: feeCalculator,
ParentID: parentID,
StateVersions: v,
Tx: b.Tx,
Expand Down Expand Up @@ -356,6 +386,7 @@ func (v *verifier) proposalBlock(
onDecisionState state.Diff,
onCommitState state.Diff,
onAbortState state.Diff,
feeCalculator fee.Calculator,
inputs set.Set[ids.ID],
atomicRequests map[ids.ID]*atomic.Requests,
onAcceptFunc func(),
Expand All @@ -364,6 +395,7 @@ func (v *verifier) proposalBlock(
OnCommitState: onCommitState,
OnAbortState: onAbortState,
Backend: v.txExecutorBackend,
FeeCalculator: feeCalculator,
Tx: b.Tx,
}

Expand Down Expand Up @@ -403,9 +435,10 @@ func (v *verifier) proposalBlock(
// standardBlock populates the state of this block if [nil] is returned
func (v *verifier) standardBlock(
b *block.ApricotStandardBlock,
feeCalculator fee.Calculator,
onAcceptState state.Diff,
) error {
inputs, atomicRequests, onAcceptFunc, err := v.processStandardTxs(b.Transactions, onAcceptState, b.Parent())
inputs, atomicRequests, onAcceptFunc, err := v.processStandardTxs(b.Transactions, feeCalculator, onAcceptState, b.Parent())
if err != nil {
return err
}
Expand All @@ -426,7 +459,7 @@ func (v *verifier) standardBlock(
return nil
}

func (v *verifier) processStandardTxs(txs []*txs.Tx, state state.Diff, parentID ids.ID) (
func (v *verifier) processStandardTxs(txs []*txs.Tx, feeCalculator fee.Calculator, state state.Diff, parentID ids.ID) (
set.Set[ids.ID],
map[ids.ID]*atomic.Requests,
func(),
Expand All @@ -440,9 +473,10 @@ func (v *verifier) processStandardTxs(txs []*txs.Tx, state state.Diff, parentID
)
for _, tx := range txs {
txExecutor := executor.StandardTxExecutor{
Backend: v.txExecutorBackend,
State: state,
Tx: tx,
Backend: v.txExecutorBackend,
State: state,
FeeCalculator: feeCalculator,
Tx: tx,
}
if err := tx.Unsigned.Visit(&txExecutor); err != nil {
txID := tx.ID()
Expand Down
6 changes: 3 additions & 3 deletions vms/platformvm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/state"
"github.com/ava-labs/avalanchego/vms/platformvm/status"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/txstest"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
Expand Down Expand Up @@ -376,8 +375,9 @@ func TestGetBalance(t *testing.T) {
require := require.New(t)
service, _, _ := defaultService(t)

feeCalc := fee.NewStaticCalculator(service.vm.Config.StaticFeeConfig, service.vm.Config.UpgradeConfig, service.vm.clock.Time())
createSubnetFee, err := feeCalc.CalculateFee(&txs.Tx{Unsigned: &txs.CreateSubnetTx{}})
feeCalculator, err := state.PickFeeCalculator(&service.vm.Config, service.vm.state)
require.NoError(err)
createSubnetFee, err := feeCalculator.CalculateFee(&txs.Tx{Unsigned: &txs.CreateSubnetTx{}})
require.NoError(err)

// Ensure GetStake is correct for each of the genesis validators
Expand Down
11 changes: 11 additions & 0 deletions vms/platformvm/state/chain_time_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/vms/platformvm/config"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
)

func NextBlockTime(state Chain, clk *mockable.Clock) (time.Time, bool, error) {
Expand Down Expand Up @@ -68,3 +70,12 @@ func GetNextStakerChangeTime(state Chain) (time.Time, error) {
return time.Time{}, database.ErrNotFound
}
}

// PickFeeCalculator creates either a static or a dynamic fee calculator,
// depending on the active upgrade.
//
// PickFeeCalculator does not modify [state].
func PickFeeCalculator(cfg *config.Config, state Chain) (fee.Calculator, error) {
timestamp := state.GetTimestamp()
return fee.NewStaticCalculator(cfg.StaticFeeConfig, cfg.UpgradeConfig, timestamp), nil
}
Loading
Loading