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 - Multidimensional Dynamic Fees #2682

Closed
wants to merge 301 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
301 commits
Select commit Hold shift + click to select a range
498112d
Merge branch 'e-fork-scaffolding' into p-chain_dynamic-fees
abi87 Jan 17, 2024
0d5b618
added p-chain fees calculator
abi87 Jan 17, 2024
8623d08
added x-chain fees calculator
abi87 Jan 17, 2024
dea17c0
Merge branch 'introducing-fees-calculators' into p-chain_dynamic-fees
abi87 Jan 17, 2024
ed2875c
extended codec size
abi87 Jan 17, 2024
14f914b
Merge branch 'e-fork-scaffolding' into introducing-fees-calculators
abi87 Jan 18, 2024
1b1cc99
nits
abi87 Jan 18, 2024
3efc606
Merge branch 'introducing-fees-calculators' into codec-upgrades-for-d…
abi87 Jan 18, 2024
504f6c7
added UT
abi87 Jan 18, 2024
8dcc8e8
Merge branch 'codec-upgrades-for-dynamic-fees' of github.com:ava-labs…
abi87 Jan 18, 2024
8dd8879
Merge branch 'codec-upgrades-for-dynamic-fees' into p-chain_dynamic-fees
abi87 Jan 18, 2024
524631c
reduced diff
abi87 Jan 18, 2024
9e668d5
nit
abi87 Jan 18, 2024
8819964
Merge branch 'codec-upgrades-for-dynamic-fees' into p-chain_dynamic-fees
abi87 Jan 18, 2024
01b51a9
Merge branch 'e-fork-scaffolding' into introducing-fees-calculators
abi87 Jan 22, 2024
460395f
Merge branch 'introducing-fees-calculators' into codec-upgrades-for-d…
abi87 Jan 22, 2024
b881e92
Merge branch 'codec-upgrades-for-dynamic-fees' into p-chain_dynamic-fees
abi87 Jan 22, 2024
057a4e4
exported p-chain unit fees via API
abi87 Jan 22, 2024
27eb36d
exported p-chain block units cap via API
abi87 Jan 22, 2024
e9c440b
wip: restructured fees calculator
abi87 Jan 22, 2024
b417546
wip: moving multidimensional fees configs to state
abi87 Jan 22, 2024
02c6084
cleanup
abi87 Jan 22, 2024
9ed258d
wip: multifee tx construction in wallet
abi87 Jan 22, 2024
9c123f0
wip: multifee tx construction in wallet
abi87 Jan 22, 2024
cbe4b04
added builder backend mock
abi87 Jan 23, 2024
456cde9
wip adding UTs for dynamic fees builder
abi87 Jan 23, 2024
e0490ae
Merge branch 'p-chain_dynamic-fees' of github.com:ava-labs/avalancheg…
abi87 Jan 23, 2024
4170845
wip: adding UTs for dynamic fees builder
abi87 Jan 23, 2024
5b32e72
wip: fixing UTs
abi87 Jan 24, 2024
03d1829
moved wallet mocks
abi87 Jan 24, 2024
5854363
expanded UTXOs list
abi87 Jan 24, 2024
d78aeb3
wip: adding txs to dynamic fees builder
abi87 Jan 24, 2024
f7a7912
wip: adding some more txs to dynamic fees builder
abi87 Jan 24, 2024
c5182e8
added ExportTx to dynamic fees builder
abi87 Jan 25, 2024
728d8db
added BaseTx to dynamic fees builder
abi87 Jan 25, 2024
c76445d
fixed Add/RemoveFees
abi87 Jan 25, 2024
226e8db
added ImportTx to dynamic fees builder
abi87 Jan 26, 2024
c5f083b
integrated dynamic fees builder into wallet
abi87 Jan 26, 2024
0d90f0f
enabled E fork in testnet + minor fixes
abi87 Jan 26, 2024
67f0dcf
Merge branch 'e-fork-scaffolding' into introducing-fees-calculators
abi87 Jan 26, 2024
dd086bd
Merge branch 'introducing-fees-calculators' into codec-upgrades-for-d…
abi87 Jan 26, 2024
b4f44c1
Merge branch 'codec-upgrades-for-dynamic-fees' into p-chain_dynamic-fees
abi87 Jan 26, 2024
d984b3b
fixed merge
abi87 Jan 26, 2024
48e6939
Merge branch 'introducing-fees-calculators' into codec-upgrades-for-d…
abi87 Jan 26, 2024
f2b6b9b
Merge branch 'codec-upgrades-for-dynamic-fees' into p-chain_dynamic-fees
abi87 Jan 26, 2024
77e5779
fixed merge
abi87 Jan 26, 2024
5b35ad3
leftover from previous merge
abi87 Jan 26, 2024
7a2a673
wip: fixing e2e tests
abi87 Jan 26, 2024
9b32bb0
moved X-chain changes to different branch
abi87 Jan 26, 2024
921a7dd
fixed p-chain workflow e2e test
abi87 Jan 26, 2024
36399f4
nit
abi87 Jan 26, 2024
cb46cdf
nit
abi87 Jan 26, 2024
5bad537
leftover
abi87 Jan 26, 2024
93fff34
improved utxos selection to finance txs in wallet
abi87 Jan 29, 2024
1f3cece
fix CI compilation
abi87 Jan 29, 2024
7415a58
consolidated code in wallet
abi87 Jan 29, 2024
8197e72
fixed e2e test to account for fees
abi87 Jan 29, 2024
332789d
Merge branch 'e-fork-scaffolding' into introducing-fees-calculators
abi87 Jan 29, 2024
25b9424
reduced diffs
abi87 Jan 29, 2024
3328f8c
Merge branch 'introducing-fees-calculators' into codec-upgrades-for-d…
abi87 Jan 29, 2024
9e83485
Merge branch 'codec-upgrades-for-dynamic-fees' into p-chain_dynamic-fees
abi87 Jan 29, 2024
d28afdf
restored x-chain fee calculator
abi87 Jan 29, 2024
ddce06a
added dynamic fees builder for x-chain wallet
abi87 Jan 29, 2024
c40fe2b
added some more txs to x-chain dynamic fees builder
abi87 Jan 30, 2024
68b3c8c
introduced fees tracking window
abi87 Jan 31, 2024
81b4cf8
wip:drafting unit fees update mechs
abi87 Jan 31, 2024
4e4e3ec
added windows UTs
abi87 Jan 31, 2024
6bb5796
added ComputeNext fee manager UTs
abi87 Jan 31, 2024
cff5c2c
nit
abi87 Jan 31, 2024
80b9186
passed windows in fee manager ctor
abi87 Jan 31, 2024
1606c83
wip: persisting dynamic unit fees and windows
abi87 Jan 31, 2024
6644311
wip: introducing dynamic fees config
abi87 Feb 1, 2024
2315dc1
wip: introducing unit fees update
abi87 Feb 1, 2024
a279f4e
wip: persist unit fees and fee windows
abi87 Feb 1, 2024
744c41e
nits
abi87 Feb 1, 2024
6ab718d
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 6, 2024
b5d6cfe
nit
abi87 Feb 6, 2024
088cc53
fixed P-chain api with GetFeeWindows
abi87 Feb 6, 2024
97f4897
nit
abi87 Feb 6, 2024
0217214
added UT
abi87 Feb 6, 2024
4dc0983
nit
abi87 Feb 6, 2024
353883f
fix merge
abi87 Feb 6, 2024
6fa51c5
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 9, 2024
8b7c4f1
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 9, 2024
bf4d6c8
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 9, 2024
1667847
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 10, 2024
a610687
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 13, 2024
f215e77
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 15, 2024
be27aeb
fix fees getters
abi87 Feb 16, 2024
0704b2e
nit
abi87 Feb 18, 2024
f864735
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 18, 2024
d6865bc
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 18, 2024
e1e19bf
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 19, 2024
e345bfa
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 22, 2024
a19ed88
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 25, 2024
2dd8f6a
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 26, 2024
ecfe65a
fixed changedDenom handling
abi87 Feb 29, 2024
f86b854
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Feb 29, 2024
e682735
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 4, 2024
ec6c32f
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 7, 2024
bbc92f1
fee rates exponential updates
abi87 Mar 9, 2024
4a93921
nits
abi87 Mar 10, 2024
6d28d7a
nit + minor UT fix
abi87 Mar 10, 2024
003b2c8
another exponential fee update approximation
abi87 Mar 11, 2024
72784b8
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 11, 2024
d25205c
fixed block building post e upgrade
abi87 Mar 11, 2024
3175c7d
exponential fees update stability
abi87 Mar 11, 2024
8fda18e
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 11, 2024
173de68
fixed merge
abi87 Mar 11, 2024
0f067dd
wip: refactored feeConfig getter
abi87 Mar 11, 2024
915ac05
wip: added custom dynamic fees config
abi87 Mar 11, 2024
935f031
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 12, 2024
90b095b
wip: fixed dynamic fee config loading
abi87 Mar 12, 2024
377967f
fixed fee windows update
abi87 Mar 14, 2024
0cb4969
refactored GetUnitFees api
abi87 Mar 14, 2024
5cfc639
consolidated fees config
abi87 Mar 14, 2024
65d87da
simplified feeManager
abi87 Mar 14, 2024
a18732f
fixed unit fees update
abi87 Mar 14, 2024
0c0a237
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 15, 2024
373fda8
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 18, 2024
8a01461
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 18, 2024
a3ae61a
removed floats from fee update algo
abi87 Mar 18, 2024
311e9aa
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 19, 2024
703e362
fixed unitFees initialization in state package
abi87 Mar 20, 2024
1f3bf48
wip: adding dynamic fees e2e test
abi87 Mar 20, 2024
3412187
increased block target units to avoid e2e failures
abi87 Mar 21, 2024
7bb357d
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 21, 2024
39eac30
futher increase of block target units
abi87 Mar 21, 2024
db73933
dynamic fees e2e test, added checks
abi87 Mar 21, 2024
38cbc9c
restructured fee rate update algo
abi87 Mar 21, 2024
442f745
dropped fee windows
abi87 Mar 21, 2024
9c1d8df
some more renaming to improve clarity
abi87 Mar 21, 2024
32350c8
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 21, 2024
0ee197d
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 21, 2024
b93e5f0
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 21, 2024
432c17b
minor refactoring
abi87 Mar 21, 2024
1daf5e3
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 22, 2024
a87bb02
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 25, 2024
ab3be3b
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 26, 2024
3971b7f
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 26, 2024
4f00e66
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 26, 2024
e55425b
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 27, 2024
faaa96e
fixed merge
abi87 Mar 27, 2024
42f513c
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 27, 2024
453dcac
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 29, 2024
6a0806d
fixed txBuilder dynamic fees time
abi87 Mar 29, 2024
2be79a0
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Mar 29, 2024
e8692e8
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 2, 2024
6fb4d6b
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 2, 2024
057a727
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 2, 2024
b0fc43b
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 3, 2024
e4b750d
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 4, 2024
17d5a87
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 8, 2024
aa9a264
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 8, 2024
99492ab
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 8, 2024
1335c60
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 8, 2024
3b36ce0
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 8, 2024
09e3305
nit
abi87 Apr 8, 2024
c2b4c85
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 9, 2024
28a8569
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 11, 2024
7cb7a3a
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 12, 2024
e2c801b
tuned update fee algo parameters
abi87 Apr 18, 2024
2f7179d
added UTs showing update fee rate not currently working (due to integ…
abi87 Apr 18, 2024
38d0ac0
wip: solving update fees numerical precision issues
abi87 Apr 18, 2024
2de2d4a
wip: another approximation, still with some numerical errors
abi87 Apr 18, 2024
ace5379
fixing update fees algo
abi87 Apr 19, 2024
d64d30e
some more fixes for the decrease side
abi87 Apr 19, 2024
9edcabe
fix
abi87 Apr 21, 2024
039306c
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 21, 2024
807c304
Merge branch 'p-chain_update_fee_mech_fix' into p-chain_units-fees-up…
abi87 Apr 21, 2024
22916d5
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 23, 2024
86b3e5e
repackaged P-chain fork times
abi87 Apr 15, 2024
059384d
moved static configs to fee package
abi87 Apr 23, 2024
f8ab1c0
Merge branch 'p-chain_introducing-fees-calculators-fee_config' into p…
abi87 Apr 23, 2024
ee79269
Merge branch 'p-chain_meter_fees-fee_config' into p-chain_units-fees-…
abi87 Apr 23, 2024
e4ccaea
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 23, 2024
4701d3b
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 24, 2024
922b381
Merge
abi87 Apr 24, 2024
00c8515
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 26, 2024
be52f21
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 26, 2024
3effa53
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Apr 29, 2024
16dedd0
fix update algo + tune P-chain params
abi87 May 2, 2024
940c1cc
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 May 2, 2024
136609a
fixed e2e test config
abi87 May 2, 2024
7d721d8
adding UTs for exponential fee approximation
abi87 May 6, 2024
a8cdbaa
restructured exponential update + UTs
abi87 May 6, 2024
fa7824f
added piecewise linear approximation for exponential update
abi87 May 6, 2024
00b1246
nits
abi87 May 6, 2024
65fa693
wip: experimenting with exponential fee update algos
abi87 May 7, 2024
d18b51d
improved coverage of piecewise linear approximation
abi87 May 7, 2024
cf0628e
nit
abi87 May 9, 2024
e4b4ff4
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 May 9, 2024
ca01838
fixed UT
abi87 May 9, 2024
9673259
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 May 10, 2024
fecda6c
improved e2e test
abi87 May 10, 2024
1011563
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 May 14, 2024
994f1f3
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 May 15, 2024
db7467a
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 May 21, 2024
7a38e49
reduced diff
abi87 May 22, 2024
e3a2fd3
moved UpdateFeeManager to state package
abi87 May 22, 2024
b9ca2b7
nit
abi87 May 22, 2024
9a4822d
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 May 23, 2024
b007fa1
nit
abi87 May 23, 2024
c734535
nit
abi87 May 23, 2024
0d7b317
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 May 29, 2024
6073e0e
wip: removed block fee rates from state
abi87 Jun 3, 2024
1494168
wip: changed update fee algo
abi87 Jun 4, 2024
50181f3
wip: fixing UTs
abi87 Jun 7, 2024
72b76eb
fixed dynamic fees config validation
abi87 Jun 7, 2024
5acb8dd
fixed GetNextFeeRates APIs
abi87 Jun 7, 2024
d947839
nit
abi87 Jun 10, 2024
677945f
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 10, 2024
30513a8
fixed race in UT
abi87 Jun 10, 2024
287c37e
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 11, 2024
f6d0a68
nit
abi87 Jun 11, 2024
7f453c0
WIP: Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 17, 2024
a2c4e73
wip: reworked fee manager
abi87 Jun 17, 2024
4da1199
simplified dimensions
abi87 Jun 18, 2024
0ebb318
minor refactoring
abi87 Jun 18, 2024
0a75dee
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 18, 2024
6e6bc94
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 18, 2024
eeb625d
fixed GetNextGasData API
abi87 Jun 18, 2024
16189e7
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 18, 2024
72f8f15
fixed block building
abi87 Jun 18, 2024
338db53
fixed UTs
abi87 Jun 19, 2024
792a13f
nit
abi87 Jun 19, 2024
8a83454
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 20, 2024
079e47e
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 20, 2024
ee67adc
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 20, 2024
263ad2d
nit
abi87 Jun 20, 2024
e5e57ff
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 20, 2024
b884ccb
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 24, 2024
5b6224c
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 24, 2024
2f82b15
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jun 27, 2024
020198d
nit
abi87 Jun 27, 2024
13a3f10
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jul 1, 2024
dcd056a
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jul 3, 2024
c2c784b
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jul 4, 2024
9e87dbf
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 Jul 10, 2024
ec8b45b
P chain units fees update rescale gas - V2 (#3181)
abi87 Jul 10, 2024
f71cbb9
improved UT + fixed linter failing
abi87 Jul 11, 2024
aa0934a
nit
abi87 Jul 11, 2024
6451b3e
Add/Remove fees consolidation
abi87 Jul 11, 2024
60fb893
added gas caps UTs
abi87 Jul 11, 2024
9e75263
TestTxFees cleanup
abi87 Jul 12, 2024
174185b
nits
abi87 Jul 12, 2024
db7ba77
nits
abi87 Jul 12, 2024
45e8044
nit
abi87 Jul 12, 2024
383f69a
Merge branch 'p-chain_units-fees-update' of github.com:ava-labs/avala…
abi87 Jul 12, 2024
0b01620
Merge branch 'p-chainin_meter_fees' into p-chain_units-fees-update
abi87 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
140 changes: 140 additions & 0 deletions tests/e2e/p/dynamic_fees.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build test

package p

import (
"fmt"

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

commonfee "github.com/ava-labs/avalanchego/vms/components/fee"
ginkgo "github.com/onsi/ginkgo/v2"
)

var _ = ginkgo.Describe("[Dynamic Fees]", func() {
require := require.New(ginkgo.GinkgoT())

ginkgo.It("should ensure that the dynamic multifees are affected by load", func() {
customDynamicFeesConfig := commonfee.DynamicFeesConfig{
MinGasPrice: commonfee.GasPrice(1),
UpdateDenominator: commonfee.Gas(5),

// BlockUnitsTarget are set to cause an increase of fees while simple transactions are issued
GasTargetRate: commonfee.Gas(120),
}

ginkgo.By("creating a new private network to ensure isolation from other tests")
privateNetwork := &tmpnet.Network{
Owner: "avalanchego-e2e-dynamic-fees",
ChainConfigs: map[string]tmpnet.FlagsMap{
"P": {
"dynamic-fees-config": customDynamicFeesConfig,
},
},
}
e2e.Env.StartPrivateNetwork(privateNetwork)

ginkgo.By("setup a wallet and a P-chain client")
node := privateNetwork.Nodes[0]
nodeURI := tmpnet.NodeURI{
NodeID: node.NodeID,
URI: node.URI,
}
keychain := secp256k1fx.NewKeychain(privateNetwork.PreFundedKeys...)
baseWallet := e2e.NewWallet(keychain, nodeURI)
pWallet := baseWallet.P()
pChainClient := platformvm.NewClient(nodeURI.URI)

// retrieve initial balances
pBuilder := pWallet.Builder()
pContext := pBuilder.Context()
avaxAssetID := pContext.AVAXAssetID
pBalances, err := pWallet.Builder().GetBalance()
require.NoError(err)
pStartBalance := pBalances[avaxAssetID]
tests.Outf("{{blue}} P-chain balance before P->X export: %d {{/}}\n", pStartBalance)

ginkgo.By("checking that initial fee values match with configured ones", func() {
nextFeeRates, _, err := pChainClient.GetNextGasData(e2e.DefaultContext())
require.NoError(err)
require.Equal(customDynamicFeesConfig.MinGasPrice, nextFeeRates)
})

ginkgo.By("issue expensive transactions so to increase the fee rates to be paid for accepting the transactons",
func() {
initialOwner := &secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{
keychain.Keys[0].Address(),
},
}

var subnetID ids.ID
ginkgo.By("create a permissioned subnet", func() {
subnetTx, err := pWallet.IssueCreateSubnetTx(
initialOwner,
e2e.WithDefaultContext(),
)
require.NoError(err)

subnetID = subnetTx.ID()
})

nextFeeRates, _, err := pChainClient.GetNextGasData(e2e.DefaultContext())
require.NoError(err)
tests.Outf("{{blue}} next fee rates: %v {{/}}\n", nextFeeRates)

ginkgo.By("repeatedly change the permissioned subnet owner to increase fee rates", func() {
txsCount := 10
for i := 0; i < txsCount; i++ {
nextOwner := &secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{
keychain.Keys[1].Address(),
},
}

_, err = pWallet.IssueTransferSubnetOwnershipTx(
subnetID,
nextOwner,
e2e.WithDefaultContext(),
)
require.NoError(err)

updatedFeeRates, _, err := pChainClient.GetNextGasData(e2e.DefaultContext())
require.NoError(err)
tests.Outf("{{blue}} current fee rates: %v {{/}}\n", updatedFeeRates)

ginkgo.By("check that fee rates components have increased")
require.GreaterOrEqual(nextFeeRates, updatedFeeRates,
fmt.Sprintf("previous fee rates %v, current fee rates %v", nextFeeRates, updatedFeeRates),
)
nextFeeRates = updatedFeeRates
}
})

ginkgo.By("wait for the fee rates to decrease", func() {
initialFeeRates := nextFeeRates
e2e.Eventually(func() bool {
var err error
nextFeeRates, _, err = pChainClient.GetNextGasData(e2e.DefaultContext())
require.NoError(err)
tests.Outf("{{blue}} next fee rates: %v {{/}}\n", nextFeeRates)
return nextFeeRates < initialFeeRates
}, e2e.DefaultTimeout, e2e.DefaultPollingInterval, "failed to see gas price decrease before timeout")
tests.Outf("\n{{blue}}fee rates have decreased to %v{{/}}\n", nextFeeRates)
})
},
)
})
})
78 changes: 78 additions & 0 deletions vms/components/fee/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package fee
import (
"errors"
"fmt"
"math"
"math/big"
"time"

safemath "github.com/ava-labs/avalanchego/utils/math"
)
Expand All @@ -31,6 +34,10 @@ type Calculator struct {
// latestTxComplexity tracks complexity of latest tx being processed.
// latestTxComplexity is especially helpful while building a tx.
latestTxComplexity Dimensions

// currentExcessGas stores current excess gas, cumulated over time
// to be updated once a block is accepted with cumulatedGas
currentExcessGas Gas
}

func NewCalculator(feeWeights Dimensions, gasPrice GasPrice, gasCap Gas) *Calculator {
Expand All @@ -41,6 +48,45 @@ func NewCalculator(feeWeights Dimensions, gasPrice GasPrice, gasCap Gas) *Calcul
}
}

func NewUpdatedManager(
feesConfig DynamicFeesConfig,
gasCap, currentExcessGas Gas,
parentBlkTime, childBlkTime time.Time,
) (*Calculator, error) {
res := &Calculator{
feeWeights: feesConfig.FeeDimensionWeights,
gasCap: gasCap,
currentExcessGas: currentExcessGas,
}

targetGas, err := TargetGas(feesConfig, parentBlkTime, childBlkTime)
if err != nil {
return nil, fmt.Errorf("failed calculating target gas: %w", err)
}

if currentExcessGas > targetGas {
currentExcessGas -= targetGas
} else {
currentExcessGas = ZeroGas
}

res.gasPrice = fakeExponential(feesConfig.MinGasPrice, currentExcessGas, feesConfig.UpdateDenominator)
return res, nil
}

func TargetGas(feesConfig DynamicFeesConfig, parentBlkTime, childBlkTime time.Time) (Gas, error) {
if parentBlkTime.Compare(childBlkTime) > 0 {
return ZeroGas, fmt.Errorf("unexpected block times, parentBlkTim %v, childBlkTime %v", parentBlkTime, childBlkTime)
}

elapsedTime := uint64(childBlkTime.Unix() - parentBlkTime.Unix())
targetGas, over := safemath.Mul64(uint64(feesConfig.GasTargetRate), elapsedTime)
if over != nil {
targetGas = math.MaxUint64
}
return Gas(targetGas), nil
}

func (c *Calculator) GetGasPrice() GasPrice {
return c.gasPrice
}
Expand All @@ -57,6 +103,14 @@ func (c *Calculator) GetGasCap() Gas {
return c.gasCap
}

func (c *Calculator) GetExcessGas() (Gas, error) {
g, err := safemath.Add64(uint64(c.currentExcessGas), uint64(c.cumulatedGas))
if err != nil {
return ZeroGas, err
}
return Gas(g), nil
}

// AddFeesFor updates latest tx complexity. It should be called once when tx is being verified
// and may be called multiple times when tx is being built (and tx components are added in time).
// AddFeesFor checks that gas cap is not breached. It also returns the updated tx fee for convenience.
Expand Down Expand Up @@ -117,3 +171,27 @@ func (c *Calculator) GetLatestTxFee() (uint64, error) {
}
return safemath.Mul64(uint64(c.gasPrice), uint64(gas))
}

// fakeExponential approximates factor * e ** (numerator / denominator) using
// Taylor expansion.
func fakeExponential(f GasPrice, n, d Gas) GasPrice {
var (
factor = new(big.Int).SetUint64(uint64(f))
numerator = new(big.Int).SetUint64(uint64(n))
denominator = new(big.Int).SetUint64(uint64(d))
output = new(big.Int)
accum = new(big.Int).Mul(factor, denominator)
)
for i := 1; accum.Sign() > 0; i++ {
output.Add(output, accum)

accum.Mul(accum, numerator)
accum.Div(accum, denominator)
accum.Div(accum, big.NewInt(int64(i)))
}
output = output.Div(output, denominator)
if !output.IsUint64() {
return math.MaxUint64
}
return GasPrice(output.Uint64())
}
Loading
Loading