Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
1857cb9
[vms/platformvm] Add tracking of a Subnet manager
dhrubabasu Jun 18, 2024
4d11a29
Merge branch 'master' into store-warp-addressed-call-pair
dhrubabasu Jun 18, 2024
90a38ff
Update vms/platformvm/state/diff.go
dhrubabasu Jun 18, 2024
f60e4ea
nit
dhrubabasu Jun 18, 2024
1ca0caf
nit
dhrubabasu Jun 20, 2024
1cd2428
nit
dhrubabasu Jun 20, 2024
3587c32
nit
dhrubabasu Jun 20, 2024
ec16c11
[vms/platformvm] Cleanup execution config tests
dhrubabasu Jun 20, 2024
f52cbbe
Merge branch 'master' into cleanup-execution-config-test
dhrubabasu Jun 20, 2024
076b1f0
nit
dhrubabasu Jun 20, 2024
df5ca64
nit
dhrubabasu Jun 20, 2024
dcc056b
Merge branch 'master' into cleanup-execution-config-test
dhrubabasu Jun 20, 2024
3279764
nit
dhrubabasu Jun 21, 2024
911a167
mark as helper
dhrubabasu Jun 21, 2024
ddf3392
Merge branch 'master' into cleanup-execution-config-test
dhrubabasu Jun 21, 2024
25802a8
merged
dhrubabasu Jun 21, 2024
01b854a
reduce diff
dhrubabasu Jun 21, 2024
f79e0c7
add write
dhrubabasu Jun 24, 2024
1eda29c
merged
dhrubabasu Jun 24, 2024
3fa1306
nits
dhrubabasu Jun 25, 2024
16ffe7b
nit
dhrubabasu Jun 25, 2024
3035064
nits
dhrubabasu Jun 25, 2024
62ece94
Merge branch 'master' into store-warp-addressed-call-pair
dhrubabasu Jun 25, 2024
333a41e
fix UT
dhrubabasu Jun 25, 2024
520ac91
add UTs
dhrubabasu Jun 25, 2024
db5f197
lint
dhrubabasu Jun 25, 2024
574a120
nit
dhrubabasu Jun 26, 2024
501beb1
nit
dhrubabasu Jun 26, 2024
ab5c23b
add test for cache
dhrubabasu Jul 17, 2024
e0d0a00
Merge branch 'master' into store-warp-addressed-call-pair
dhrubabasu Jul 17, 2024
12a1969
wip
dhrubabasu Jul 22, 2024
cda1001
table tests
dhrubabasu Jul 23, 2024
2ff46f4
Merge branch 'master' into store-warp-addressed-call-pair
dhrubabasu Jul 23, 2024
e05a514
Merge branch 'store-warp-addressed-call-pair' into ConvertSubnetTx
dhrubabasu Jul 23, 2024
7ab0094
wip
dhrubabasu Jul 23, 2024
79e84b1
wip
dhrubabasu Jul 23, 2024
264a73f
merged
dhrubabasu Jul 23, 2024
1340a51
nits
dhrubabasu Jul 23, 2024
62f6d78
nits
dhrubabasu Jul 23, 2024
6e54ba7
nits
dhrubabasu Jul 23, 2024
68e621d
passing
dhrubabasu Jul 23, 2024
8e9f406
add tests
dhrubabasu Jul 23, 2024
dd08695
reduce scope
dhrubabasu Jul 23, 2024
3042de2
nit
dhrubabasu Jul 23, 2024
9b8aa4a
merged
dhrubabasu Aug 5, 2024
1d72e1b
nits
dhrubabasu Aug 5, 2024
5126df9
merged
dhrubabasu Aug 5, 2024
909a24c
Etna
dhrubabasu Aug 5, 2024
c1299c8
nit
dhrubabasu Aug 5, 2024
a2d0968
nit
dhrubabasu Aug 5, 2024
aa6b6f6
Implement SoV data struct
dhrubabasu Aug 11, 2024
be79d4c
Merge branch 'master' into disable-permissioned-subnet-txs-post-manager
dhrubabasu Aug 11, 2024
367cf42
disable CreateChainTx
dhrubabasu Aug 11, 2024
a14f140
pass CI
dhrubabasu Aug 12, 2024
eed7d1a
wire in validatorWeightDiffsDB and validatorPublicKeyDiffsDB
dhrubabasu Aug 12, 2024
30240fc
wip
dhrubabasu Aug 13, 2024
9fe5414
passing for now
dhrubabasu Aug 13, 2024
413a7a9
Merge branch 'master' into disable-permissioned-subnet-txs-post-manager
dhrubabasu Aug 13, 2024
c988391
nit
dhrubabasu Aug 13, 2024
3f49097
move write
dhrubabasu Aug 13, 2024
447e326
reduce footpring
dhrubabasu Aug 13, 2024
b23b654
nit
dhrubabasu Aug 14, 2024
952fd7f
nit
dhrubabasu Aug 14, 2024
db18027
nit
dhrubabasu Aug 14, 2024
e019360
Merge branch 'master' into disable-permissioned-subnet-txs-post-manager
dhrubabasu Aug 14, 2024
43b2b53
merged
dhrubabasu Aug 14, 2024
fe4f3d6
Merge branch 'disable-permissioned-subnet-txs-post-manager' into Conv…
dhrubabasu Aug 14, 2024
ddf94a4
RemoveSubnet
dhrubabasu Aug 14, 2024
4a5fecb
Merge branch 'disable-permissioned-subnet-txs-post-manager' into Conv…
dhrubabasu Aug 14, 2024
643ddbd
fix test
dhrubabasu Aug 14, 2024
215821f
Merge branch 'disable-permissioned-subnet-txs-post-manager' into Conv…
dhrubabasu Aug 14, 2024
bdc015d
wip e2e
dhrubabasu Aug 14, 2024
d1652c0
fix build
dhrubabasu Aug 14, 2024
4fb9e17
wip
dhrubabasu Aug 14, 2024
2555a6a
nit
dhrubabasu Aug 14, 2024
751bdea
nit
dhrubabasu Aug 14, 2024
1c91b02
nit
dhrubabasu Aug 14, 2024
82ce5d0
finish e2e
dhrubabasu Aug 14, 2024
4c2205e
nit
dhrubabasu Aug 14, 2024
0ba141d
nit
dhrubabasu Aug 14, 2024
e537d23
nit
dhrubabasu Aug 14, 2024
f18163b
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu Aug 15, 2024
35e0580
wip
dhrubabasu Aug 15, 2024
a61fb06
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu Aug 15, 2024
b42de99
merged
dhrubabasu Aug 19, 2024
4a1ca5c
minimize
dhrubabasu Aug 19, 2024
0b15984
nit
dhrubabasu Aug 19, 2024
99378b4
reduce diff
dhrubabasu Aug 19, 2024
1684fdb
cleanup e2e
dhrubabasu Aug 19, 2024
22ac121
Merge branch 'master' into ConvertSubnetTx
dhrubabasu Aug 19, 2024
a8524ba
cleanup
dhrubabasu Aug 19, 2024
b5df28b
cap address size to 4096
dhrubabasu Aug 19, 2024
bed839d
skip correctly
dhrubabasu Aug 19, 2024
4adc17e
nit
dhrubabasu Aug 19, 2024
ffeb3d3
nits
dhrubabasu Aug 20, 2024
37cbc52
linear scan... for now
dhrubabasu Aug 20, 2024
4edc421
Merge branch 'master' into ConvertSubnetTx
dhrubabasu Aug 20, 2024
67e2bef
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu Aug 20, 2024
63d5ac7
int
dhrubabasu Aug 20, 2024
ece7c2b
wip
dhrubabasu Aug 20, 2024
92a7187
cleanup complexity
dhrubabasu Aug 20, 2024
144dad2
fix
dhrubabasu Aug 20, 2024
6cc89e1
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu Aug 20, 2024
1503bd4
merged
dhrubabasu Aug 20, 2024
7dd74b5
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu Aug 20, 2024
6a0db3f
nit
dhrubabasu Aug 21, 2024
4afac28
merged
dhrubabasu Aug 22, 2024
5545958
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu Aug 22, 2024
41127c9
nit
dhrubabasu Aug 22, 2024
8b54f2f
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu Aug 22, 2024
13238f1
nit
dhrubabasu Aug 22, 2024
fdc1069
nit
dhrubabasu Aug 22, 2024
57dc1be
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu Aug 22, 2024
85ce497
nit
dhrubabasu Aug 22, 2024
33e7126
nit
dhrubabasu Aug 22, 2024
15473d5
Merge branch 'ConvertSubnetTx' into sov-data-struct
dhrubabasu Aug 22, 2024
58eebf4
nit
dhrubabasu Aug 22, 2024
f7a5558
wip
dhrubabasu Aug 29, 2024
f33f9a7
nit
dhrubabasu Aug 29, 2024
499f19c
Separate codec registries by upgrade
StephenButtolph Sep 2, 2024
dfaff2e
merged
StephenButtolph Sep 2, 2024
6b26b49
nit
StephenButtolph Sep 2, 2024
aeddd28
Merge branch 'separate-codec-by-upgrade' into ConvertSubnetTx
StephenButtolph Sep 2, 2024
3dcdcda
Update naming
StephenButtolph Sep 2, 2024
64a6c53
Use hex output
StephenButtolph Sep 2, 2024
ad664a0
Reduce diff
StephenButtolph Sep 2, 2024
186cf8d
Improve json format
StephenButtolph Sep 2, 2024
de97114
Improve tests
StephenButtolph Sep 2, 2024
40a2cae
Fix error
StephenButtolph Sep 2, 2024
b0ce060
cleanup test
StephenButtolph Sep 2, 2024
0ecfc50
remove static fee support
StephenButtolph Sep 2, 2024
06534fc
reduce diff
StephenButtolph Sep 2, 2024
a44b68a
nit
StephenButtolph Sep 2, 2024
68a6e24
fix comment
StephenButtolph Sep 2, 2024
61640da
Add builder test
StephenButtolph Sep 2, 2024
1619e79
nit
StephenButtolph Sep 2, 2024
f536353
Remove usage of mocks
StephenButtolph Sep 3, 2024
f6339b5
nit
StephenButtolph Sep 3, 2024
91338cb
fix test
StephenButtolph Sep 3, 2024
f602280
Support unmarshalling of json byte slices
StephenButtolph Sep 3, 2024
c3b076b
standardize json and add tests
StephenButtolph Sep 3, 2024
4328bac
fix marshal tests
StephenButtolph Sep 3, 2024
805ae43
fix marshal more tests
StephenButtolph Sep 3, 2024
518cf19
fix even marshal more tests
StephenButtolph Sep 3, 2024
26b3702
merged
StephenButtolph Sep 3, 2024
e1f55a5
Nit use var
StephenButtolph Sep 3, 2024
8895f27
Cleanup serialization tests
StephenButtolph Sep 4, 2024
aa7f222
Add comment
StephenButtolph Sep 4, 2024
91c8619
var block
StephenButtolph Sep 4, 2024
b5638e0
reorder
StephenButtolph Sep 4, 2024
4831205
Merge branch 'master' into ConvertSubnetTx
StephenButtolph Sep 4, 2024
df3fb4c
embed json
StephenButtolph Sep 4, 2024
8f8ebc9
Merge branch 'ConvertSubnetTx' of github.com:ava-labs/avalanchego int…
StephenButtolph Sep 4, 2024
d87a472
huh tabs are os dependent?
StephenButtolph Sep 4, 2024
ff95e5b
I misread the error, it was returns
StephenButtolph Sep 4, 2024
7aee249
Merge branch 'ConvertSubnetTx' into sov-data-struct
StephenButtolph Sep 4, 2024
1ca22eb
Merge branch 'master' into sov-data-struct
StephenButtolph Sep 4, 2024
bd52982
Implement acp-77 fee calculations
StephenButtolph Sep 6, 2024
a0af420
fix comment
StephenButtolph Sep 6, 2024
2bc3f86
fix test
StephenButtolph Sep 6, 2024
1a8e5f2
fix comment
StephenButtolph Sep 6, 2024
29af8da
comment grammer
StephenButtolph Sep 6, 2024
77a9820
Implement function
StephenButtolph Sep 6, 2024
471871f
Merge branch 'implement-acp-77-fees' into sov-data-struct
StephenButtolph Sep 6, 2024
a490641
merge fee implementation
StephenButtolph Sep 6, 2024
62a2ae1
Add CalculateExcess tests
StephenButtolph Sep 6, 2024
c780c34
Merge branch 'implement-acp-77-fees' into sov-data-struct
StephenButtolph Sep 6, 2024
5af7744
Remove validator state struct
StephenButtolph Sep 6, 2024
471b03e
Add dhruba as co-author
StephenButtolph Sep 10, 2024
8e468ab
:eyes:
StephenButtolph Sep 11, 2024
7940741
Address most suggestions
StephenButtolph Sep 11, 2024
d642d1d
add additional tests
StephenButtolph Sep 11, 2024
605aa61
Make exported structs pretty
StephenButtolph Sep 11, 2024
e5ef65d
add comment
StephenButtolph Sep 12, 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
167 changes: 167 additions & 0 deletions vms/platformvm/validators/fee/fee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package fee

import (
"math"

"github.com/ava-labs/avalanchego/vms/components/gas"

safemath "github.com/ava-labs/avalanchego/utils/math"
)

// Config contains all the static parameters of the dynamic fee mechanism.
type Config struct {
Target gas.Gas `json:"target"`
MinPrice gas.Price `json:"minPrice"`
ExcessConversionConstant gas.Gas `json:"excessConversionConstant"`
}

// State represents the current on-chain values used in the dynamic fee
// mechanism.
type State struct {
Current gas.Gas `json:"current"`
Excess gas.Gas `json:"excess"`
}

// AdvanceTime adds (s.Current - target) * seconds to Excess.
//
// If Excess would underflow, it is set to 0.
// If Excess would overflow, it is set to MaxUint64.
func (s State) AdvanceTime(target gas.Gas, seconds uint64) State {
excess := s.Excess
if s.Current < target {
excess = excess.SubPerSecond(target-s.Current, seconds)
} else if s.Current > target {
excess = excess.AddPerSecond(s.Current-target, seconds)
}
return State{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this because we were talking about functional languages? 🤣

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's actually because we might be passing these through different block states... And we definitely don't want them to be mutable there

Current: s.Current,
Excess: excess,
}
}

// CostOf calculates how much to charge based on the dynamic fee mechanism for
// [seconds].
//
// This implements the ACP-77 cost over time formula:
func (s State) CostOf(c Config, seconds uint64) uint64 {
// If the current and target are the same, the price is constant.
if s.Current == c.Target {
price := gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant)
cost, err := safemath.Mul(seconds, uint64(price))
if err != nil {
return math.MaxUint64
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll see your error and raise you an exorbitant transaction cost!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually a discount! (because this is just capping the cost at MaxUint64 if it would have overflowed)

}
return cost
}

var (
cost uint64
err error
)
for i := uint64(0); i < seconds; i++ {
s = s.AdvanceTime(c.Target, 1)

// Advancing the time is going to either hold excess constant,
// monotonically increase it, or monotonically decrease it. If it is
// equal to 0 after performing one of these operations, it is guaranteed
// to always remain 0.
if s.Excess == 0 {
secondsWithZeroExcess := seconds - i
zeroExcessCost, err := safemath.Mul(uint64(c.MinPrice), secondsWithZeroExcess)
if err != nil {
return math.MaxUint64
}

cost, err = safemath.Add(cost, zeroExcessCost)
if err != nil {
return math.MaxUint64
}
return cost
}

price := gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant)
cost, err = safemath.Add(cost, uint64(price))
if err != nil {
return math.MaxUint64
}
}
return cost
}

// SecondsUntil calculates the number of seconds that it would take to charge at
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice naming! I love code that reads like prose.

// least [targetCost] based on the dynamic fee mechanism. The result is capped
// at [maxSeconds].
func (s State) SecondsUntil(c Config, maxSeconds uint64, targetCost uint64) uint64 {
// Because this function can divide by prices, we need to sanity check the
// parameters to avoid division by 0.
if c.MinPrice == 0 {
if targetCost == 0 {
return 0
}
return maxSeconds
}

// If the current and target are the same, the price is constant.
if s.Current == c.Target {
price := gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant)
return secondsUntil(
uint64(price),
maxSeconds,
targetCost,
)
}

var (
cost uint64
seconds uint64
err error
)
for cost < targetCost && seconds < maxSeconds {
s = s.AdvanceTime(c.Target, 1)

// Advancing the time is going to either hold excess constant,
// monotonically increase it, or monotonically decrease it. If it is
// equal to 0 after performing one of these operations, it is guaranteed
// to always remain 0.
if s.Excess == 0 {
zeroExcessCost := targetCost - cost
secondsWithZeroExcess := secondsUntil(
uint64(c.MinPrice),
maxSeconds,
zeroExcessCost,
)

totalSeconds, err := safemath.Add(seconds, secondsWithZeroExcess)
if err != nil || totalSeconds >= maxSeconds {
return maxSeconds
}
return totalSeconds
}

seconds++
price := gas.CalculatePrice(c.MinPrice, s.Excess, c.ExcessConversionConstant)
cost, err = safemath.Add(cost, uint64(price))
if err != nil {
return seconds
}
}
return seconds
}

// Calculate the number of seconds that it would take to charge at least [cost]
// at [price] every second. The result is capped at [maxSeconds].
func secondsUntil(price uint64, maxSeconds uint64, cost uint64) uint64 {
// Directly rounding up could cause an overflow. Instead we round down and
// then check if we should have rounded up.
secondsRoundedDown := cost / price
if secondsRoundedDown >= maxSeconds {
return maxSeconds
}
if cost%price == 0 {
return secondsRoundedDown
}
return secondsRoundedDown + 1
}
Loading
Loading