Skip to content

Commit 809081e

Browse files
Simplify static fee calculations (#3240)
1 parent a0f7e42 commit 809081e

File tree

23 files changed

+333
-448
lines changed

23 files changed

+333
-448
lines changed

api/info/service.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"go.uber.org/zap"
1414

1515
"github.com/ava-labs/avalanchego/chains"
16+
"github.com/ava-labs/avalanchego/genesis"
1617
"github.com/ava-labs/avalanchego/ids"
1718
"github.com/ava-labs/avalanchego/network"
1819
"github.com/ava-labs/avalanchego/network/peer"
@@ -46,20 +47,12 @@ type Info struct {
4647
}
4748

4849
type Parameters struct {
49-
Version *version.Application
50-
NodeID ids.NodeID
51-
NodePOP *signer.ProofOfPossession
52-
NetworkID uint32
53-
TxFee uint64
54-
CreateAssetTxFee uint64
55-
CreateSubnetTxFee uint64
56-
TransformSubnetTxFee uint64
57-
CreateBlockchainTxFee uint64
58-
AddPrimaryNetworkValidatorFee uint64
59-
AddPrimaryNetworkDelegatorFee uint64
60-
AddSubnetValidatorFee uint64
61-
AddSubnetDelegatorFee uint64
62-
VMManager vms.Manager
50+
Version *version.Application
51+
NodeID ids.NodeID
52+
NodePOP *signer.ProofOfPossession
53+
NetworkID uint32
54+
TxFeeConfig genesis.TxFeeConfig
55+
VMManager vms.Manager
6356
}
6457

6558
func NewService(
@@ -404,15 +397,15 @@ func (i *Info) GetTxFee(_ *http.Request, _ *struct{}, reply *GetTxFeeResponse) e
404397
zap.String("method", "getTxFee"),
405398
)
406399

407-
reply.TxFee = json.Uint64(i.TxFee)
408-
reply.CreateAssetTxFee = json.Uint64(i.CreateAssetTxFee)
409-
reply.CreateSubnetTxFee = json.Uint64(i.CreateSubnetTxFee)
410-
reply.TransformSubnetTxFee = json.Uint64(i.TransformSubnetTxFee)
411-
reply.CreateBlockchainTxFee = json.Uint64(i.CreateBlockchainTxFee)
412-
reply.AddPrimaryNetworkValidatorFee = json.Uint64(i.AddPrimaryNetworkValidatorFee)
413-
reply.AddPrimaryNetworkDelegatorFee = json.Uint64(i.AddPrimaryNetworkDelegatorFee)
414-
reply.AddSubnetValidatorFee = json.Uint64(i.AddSubnetValidatorFee)
415-
reply.AddSubnetDelegatorFee = json.Uint64(i.AddSubnetDelegatorFee)
400+
reply.TxFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.TxFee)
401+
reply.CreateAssetTxFee = json.Uint64(i.TxFeeConfig.CreateAssetTxFee)
402+
reply.CreateSubnetTxFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.CreateSubnetTxFee)
403+
reply.TransformSubnetTxFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.TransformSubnetTxFee)
404+
reply.CreateBlockchainTxFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.CreateBlockchainTxFee)
405+
reply.AddPrimaryNetworkValidatorFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.AddPrimaryNetworkValidatorFee)
406+
reply.AddPrimaryNetworkDelegatorFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.AddPrimaryNetworkDelegatorFee)
407+
reply.AddSubnetValidatorFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee)
408+
reply.AddSubnetDelegatorFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.AddSubnetDelegatorFee)
416409
return nil
417410
}
418411

config/config.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -762,18 +762,20 @@ func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, err
762762
return config, nil
763763
}
764764

765-
func getTxFeeConfig(v *viper.Viper, networkID uint32) fee.StaticConfig {
765+
func getTxFeeConfig(v *viper.Viper, networkID uint32) genesis.TxFeeConfig {
766766
if networkID != constants.MainnetID && networkID != constants.FujiID {
767-
return fee.StaticConfig{
768-
TxFee: v.GetUint64(TxFeeKey),
769-
CreateAssetTxFee: v.GetUint64(CreateAssetTxFeeKey),
770-
CreateSubnetTxFee: v.GetUint64(CreateSubnetTxFeeKey),
771-
TransformSubnetTxFee: v.GetUint64(TransformSubnetTxFeeKey),
772-
CreateBlockchainTxFee: v.GetUint64(CreateBlockchainTxFeeKey),
773-
AddPrimaryNetworkValidatorFee: v.GetUint64(AddPrimaryNetworkValidatorFeeKey),
774-
AddPrimaryNetworkDelegatorFee: v.GetUint64(AddPrimaryNetworkDelegatorFeeKey),
775-
AddSubnetValidatorFee: v.GetUint64(AddSubnetValidatorFeeKey),
776-
AddSubnetDelegatorFee: v.GetUint64(AddSubnetDelegatorFeeKey),
767+
return genesis.TxFeeConfig{
768+
CreateAssetTxFee: v.GetUint64(CreateAssetTxFeeKey),
769+
StaticFeeConfig: fee.StaticConfig{
770+
TxFee: v.GetUint64(TxFeeKey),
771+
CreateSubnetTxFee: v.GetUint64(CreateSubnetTxFeeKey),
772+
TransformSubnetTxFee: v.GetUint64(TransformSubnetTxFeeKey),
773+
CreateBlockchainTxFee: v.GetUint64(CreateBlockchainTxFeeKey),
774+
AddPrimaryNetworkValidatorFee: v.GetUint64(AddPrimaryNetworkValidatorFeeKey),
775+
AddPrimaryNetworkDelegatorFee: v.GetUint64(AddPrimaryNetworkDelegatorFeeKey),
776+
AddSubnetValidatorFee: v.GetUint64(AddSubnetValidatorFeeKey),
777+
AddSubnetDelegatorFee: v.GetUint64(AddSubnetDelegatorFeeKey),
778+
},
777779
}
778780
}
779781
return genesis.GetTxFeeConfig(networkID)
@@ -1329,7 +1331,7 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
13291331
nodeConfig.FdLimit = v.GetUint64(FdLimitKey)
13301332

13311333
// Tx Fee
1332-
nodeConfig.StaticConfig = getTxFeeConfig(v, nodeConfig.NetworkID)
1334+
nodeConfig.TxFeeConfig = getTxFeeConfig(v, nodeConfig.NetworkID)
13331335

13341336
// Genesis Data
13351337
genesisStakingCfg := nodeConfig.StakingConfig.StakingConfig

config/flags.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ func addNodeFlags(fs *pflag.FlagSet) {
9999
fs.IntSlice(ACPObjectKey, nil, "ACPs to object adoption")
100100

101101
// AVAX fees
102-
fs.Uint64(TxFeeKey, genesis.LocalParams.TxFee, "Transaction fee, in nAVAX")
102+
fs.Uint64(TxFeeKey, genesis.LocalParams.StaticFeeConfig.TxFee, "Transaction fee, in nAVAX")
103103
fs.Uint64(CreateAssetTxFeeKey, genesis.LocalParams.CreateAssetTxFee, "Transaction fee, in nAVAX, for transactions that create new assets")
104-
fs.Uint64(CreateSubnetTxFeeKey, genesis.LocalParams.CreateSubnetTxFee, "Transaction fee, in nAVAX, for transactions that create new subnets")
105-
fs.Uint64(TransformSubnetTxFeeKey, genesis.LocalParams.TransformSubnetTxFee, "Transaction fee, in nAVAX, for transactions that transform subnets")
106-
fs.Uint64(CreateBlockchainTxFeeKey, genesis.LocalParams.CreateBlockchainTxFee, "Transaction fee, in nAVAX, for transactions that create new blockchains")
107-
fs.Uint64(AddPrimaryNetworkValidatorFeeKey, genesis.LocalParams.AddPrimaryNetworkValidatorFee, "Transaction fee, in nAVAX, for transactions that add new primary network validators")
108-
fs.Uint64(AddPrimaryNetworkDelegatorFeeKey, genesis.LocalParams.AddPrimaryNetworkDelegatorFee, "Transaction fee, in nAVAX, for transactions that add new primary network delegators")
109-
fs.Uint64(AddSubnetValidatorFeeKey, genesis.LocalParams.AddSubnetValidatorFee, "Transaction fee, in nAVAX, for transactions that add new subnet validators")
110-
fs.Uint64(AddSubnetDelegatorFeeKey, genesis.LocalParams.AddSubnetDelegatorFee, "Transaction fee, in nAVAX, for transactions that add new subnet delegators")
104+
fs.Uint64(CreateSubnetTxFeeKey, genesis.LocalParams.StaticFeeConfig.CreateSubnetTxFee, "Transaction fee, in nAVAX, for transactions that create new subnets")
105+
fs.Uint64(TransformSubnetTxFeeKey, genesis.LocalParams.StaticFeeConfig.TransformSubnetTxFee, "Transaction fee, in nAVAX, for transactions that transform subnets")
106+
fs.Uint64(CreateBlockchainTxFeeKey, genesis.LocalParams.StaticFeeConfig.CreateBlockchainTxFee, "Transaction fee, in nAVAX, for transactions that create new blockchains")
107+
fs.Uint64(AddPrimaryNetworkValidatorFeeKey, genesis.LocalParams.StaticFeeConfig.AddPrimaryNetworkValidatorFee, "Transaction fee, in nAVAX, for transactions that add new primary network validators")
108+
fs.Uint64(AddPrimaryNetworkDelegatorFeeKey, genesis.LocalParams.StaticFeeConfig.AddPrimaryNetworkDelegatorFee, "Transaction fee, in nAVAX, for transactions that add new primary network delegators")
109+
fs.Uint64(AddSubnetValidatorFeeKey, genesis.LocalParams.StaticFeeConfig.AddSubnetValidatorFee, "Transaction fee, in nAVAX, for transactions that add new subnet validators")
110+
fs.Uint64(AddSubnetDelegatorFeeKey, genesis.LocalParams.StaticFeeConfig.AddSubnetDelegatorFee, "Transaction fee, in nAVAX, for transactions that add new subnet delegators")
111111

112112
// Database
113113
fs.String(DBTypeKey, leveldb.Name, fmt.Sprintf("Database type to use. Must be one of {%s, %s, %s}", leveldb.Name, memdb.Name, pebbledb.Name))

genesis/genesis_fuji.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ var (
1919

2020
// FujiParams are the params used for the fuji testnet
2121
FujiParams = Params{
22-
StaticConfig: fee.StaticConfig{
23-
TxFee: units.MilliAvax,
24-
CreateAssetTxFee: 10 * units.MilliAvax,
25-
CreateSubnetTxFee: 100 * units.MilliAvax,
26-
TransformSubnetTxFee: 1 * units.Avax,
27-
CreateBlockchainTxFee: 100 * units.MilliAvax,
28-
AddPrimaryNetworkValidatorFee: 0,
29-
AddPrimaryNetworkDelegatorFee: 0,
30-
AddSubnetValidatorFee: units.MilliAvax,
31-
AddSubnetDelegatorFee: units.MilliAvax,
22+
TxFeeConfig: TxFeeConfig{
23+
CreateAssetTxFee: 10 * units.MilliAvax,
24+
StaticFeeConfig: fee.StaticConfig{
25+
TxFee: units.MilliAvax,
26+
CreateSubnetTxFee: 100 * units.MilliAvax,
27+
TransformSubnetTxFee: 1 * units.Avax,
28+
CreateBlockchainTxFee: 100 * units.MilliAvax,
29+
AddPrimaryNetworkValidatorFee: 0,
30+
AddPrimaryNetworkDelegatorFee: 0,
31+
AddSubnetValidatorFee: units.MilliAvax,
32+
AddSubnetDelegatorFee: units.MilliAvax,
33+
},
3234
},
3335
StakingConfig: StakingConfig{
3436
UptimeRequirement: .8, // 80%

genesis/genesis_local.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ var (
3737

3838
// LocalParams are the params used for local networks
3939
LocalParams = Params{
40-
StaticConfig: fee.StaticConfig{
41-
TxFee: units.MilliAvax,
42-
CreateAssetTxFee: units.MilliAvax,
43-
CreateSubnetTxFee: 100 * units.MilliAvax,
44-
TransformSubnetTxFee: 100 * units.MilliAvax,
45-
CreateBlockchainTxFee: 100 * units.MilliAvax,
46-
AddPrimaryNetworkValidatorFee: 0,
47-
AddPrimaryNetworkDelegatorFee: 0,
48-
AddSubnetValidatorFee: units.MilliAvax,
49-
AddSubnetDelegatorFee: units.MilliAvax,
40+
TxFeeConfig: TxFeeConfig{
41+
CreateAssetTxFee: units.MilliAvax,
42+
StaticFeeConfig: fee.StaticConfig{
43+
TxFee: units.MilliAvax,
44+
CreateSubnetTxFee: 100 * units.MilliAvax,
45+
TransformSubnetTxFee: 100 * units.MilliAvax,
46+
CreateBlockchainTxFee: 100 * units.MilliAvax,
47+
AddPrimaryNetworkValidatorFee: 0,
48+
AddPrimaryNetworkDelegatorFee: 0,
49+
AddSubnetValidatorFee: units.MilliAvax,
50+
AddSubnetDelegatorFee: units.MilliAvax,
51+
},
5052
},
5153
StakingConfig: StakingConfig{
5254
UptimeRequirement: .8, // 80%

genesis/genesis_mainnet.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ var (
1919

2020
// MainnetParams are the params used for mainnet
2121
MainnetParams = Params{
22-
StaticConfig: fee.StaticConfig{
23-
TxFee: units.MilliAvax,
24-
CreateAssetTxFee: 10 * units.MilliAvax,
25-
CreateSubnetTxFee: 1 * units.Avax,
26-
TransformSubnetTxFee: 10 * units.Avax,
27-
CreateBlockchainTxFee: 1 * units.Avax,
28-
AddPrimaryNetworkValidatorFee: 0,
29-
AddPrimaryNetworkDelegatorFee: 0,
30-
AddSubnetValidatorFee: units.MilliAvax,
31-
AddSubnetDelegatorFee: units.MilliAvax,
22+
TxFeeConfig: TxFeeConfig{
23+
CreateAssetTxFee: 10 * units.MilliAvax,
24+
StaticFeeConfig: fee.StaticConfig{
25+
TxFee: units.MilliAvax,
26+
CreateSubnetTxFee: 1 * units.Avax,
27+
TransformSubnetTxFee: 10 * units.Avax,
28+
CreateBlockchainTxFee: 1 * units.Avax,
29+
AddPrimaryNetworkValidatorFee: 0,
30+
AddPrimaryNetworkDelegatorFee: 0,
31+
AddSubnetValidatorFee: units.MilliAvax,
32+
AddSubnetDelegatorFee: units.MilliAvax,
33+
},
3234
},
3335
StakingConfig: StakingConfig{
3436
UptimeRequirement: .8, // 80%

genesis/params.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,26 @@ type StakingConfig struct {
3434
RewardConfig reward.Config `json:"rewardConfig"`
3535
}
3636

37+
type TxFeeConfig struct {
38+
CreateAssetTxFee uint64 `json:"createAssetTxFee"`
39+
StaticFeeConfig fee.StaticConfig `json:"staticFeeConfig"`
40+
}
41+
3742
type Params struct {
3843
StakingConfig
39-
fee.StaticConfig
44+
TxFeeConfig
4045
}
4146

42-
func GetTxFeeConfig(networkID uint32) fee.StaticConfig {
47+
func GetTxFeeConfig(networkID uint32) TxFeeConfig {
4348
switch networkID {
4449
case constants.MainnetID:
45-
return MainnetParams.StaticConfig
50+
return MainnetParams.TxFeeConfig
4651
case constants.FujiID:
47-
return FujiParams.StaticConfig
52+
return FujiParams.TxFeeConfig
4853
case constants.LocalID:
49-
return LocalParams.StaticConfig
54+
return LocalParams.TxFeeConfig
5055
default:
51-
return LocalParams.StaticConfig
56+
return LocalParams.TxFeeConfig
5257
}
5358
}
5459

node/config.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/ava-labs/avalanchego/utils/profiler"
2424
"github.com/ava-labs/avalanchego/utils/set"
2525
"github.com/ava-labs/avalanchego/utils/timer"
26-
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
2726
)
2827

2928
type APIIndexerConfig struct {
@@ -123,13 +122,13 @@ type DatabaseConfig struct {
123122

124123
// Config contains all of the configurations of an Avalanche node.
125124
type Config struct {
126-
HTTPConfig `json:"httpConfig"`
127-
IPConfig `json:"ipConfig"`
128-
StakingConfig `json:"stakingConfig"`
129-
fee.StaticConfig `json:"txFeeConfig"`
130-
StateSyncConfig `json:"stateSyncConfig"`
131-
BootstrapConfig `json:"bootstrapConfig"`
132-
DatabaseConfig `json:"databaseConfig"`
125+
HTTPConfig `json:"httpConfig"`
126+
IPConfig `json:"ipConfig"`
127+
StakingConfig `json:"stakingConfig"`
128+
genesis.TxFeeConfig `json:"txFeeConfig"`
129+
StateSyncConfig `json:"stateSyncConfig"`
130+
BootstrapConfig `json:"bootstrapConfig"`
131+
DatabaseConfig `json:"databaseConfig"`
133132

134133
// Genesis information
135134
GenesisBytes []byte `json:"-"`

node/node.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,8 @@ func (n *Node) initVMs() error {
12271227
SybilProtectionEnabled: n.Config.SybilProtectionEnabled,
12281228
PartialSyncPrimaryNetwork: n.Config.PartialSyncPrimaryNetwork,
12291229
TrackedSubnets: n.Config.TrackedSubnets,
1230-
StaticFeeConfig: n.Config.StaticConfig,
1230+
CreateAssetTxFee: n.Config.CreateAssetTxFee,
1231+
StaticFeeConfig: n.Config.StaticFeeConfig,
12311232
UptimePercentage: n.Config.UptimeRequirement,
12321233
MinValidatorStake: n.Config.MinValidatorStake,
12331234
MaxValidatorStake: n.Config.MaxValidatorStake,
@@ -1249,7 +1250,7 @@ func (n *Node) initVMs() error {
12491250
}),
12501251
n.VMManager.RegisterFactory(context.TODO(), constants.AVMID, &avm.Factory{
12511252
Config: avmconfig.Config{
1252-
TxFee: n.Config.TxFee,
1253+
TxFee: n.Config.StaticFeeConfig.TxFee,
12531254
CreateAssetTxFee: n.Config.CreateAssetTxFee,
12541255
EUpgradeTime: eUpgradeTime,
12551256
},
@@ -1421,20 +1422,12 @@ func (n *Node) initInfoAPI() error {
14211422

14221423
service, err := info.NewService(
14231424
info.Parameters{
1424-
Version: version.CurrentApp,
1425-
NodeID: n.ID,
1426-
NodePOP: signer.NewProofOfPossession(n.Config.StakingSigningKey),
1427-
NetworkID: n.Config.NetworkID,
1428-
TxFee: n.Config.TxFee,
1429-
CreateAssetTxFee: n.Config.CreateAssetTxFee,
1430-
CreateSubnetTxFee: n.Config.CreateSubnetTxFee,
1431-
TransformSubnetTxFee: n.Config.TransformSubnetTxFee,
1432-
CreateBlockchainTxFee: n.Config.CreateBlockchainTxFee,
1433-
AddPrimaryNetworkValidatorFee: n.Config.AddPrimaryNetworkValidatorFee,
1434-
AddPrimaryNetworkDelegatorFee: n.Config.AddPrimaryNetworkDelegatorFee,
1435-
AddSubnetValidatorFee: n.Config.AddSubnetValidatorFee,
1436-
AddSubnetDelegatorFee: n.Config.AddSubnetDelegatorFee,
1437-
VMManager: n.VMManager,
1425+
Version: version.CurrentApp,
1426+
NodeID: n.ID,
1427+
NodePOP: signer.NewProofOfPossession(n.Config.StakingSigningKey),
1428+
NetworkID: n.Config.NetworkID,
1429+
TxFeeConfig: n.Config.TxFeeConfig,
1430+
VMManager: n.VMManager,
14381431
},
14391432
n.Log,
14401433
n.vdrs,

tests/antithesis/avalanchego/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (w *workload) issueXToPTransfer(ctx context.Context) {
412412
xBaseTxFee = xContext.BaseTxFee
413413
pBuilder = pWallet.Builder()
414414
pContext = pBuilder.Context()
415-
pBaseTxFee = pContext.BaseTxFee
415+
pBaseTxFee = pContext.StaticFeeConfig.TxFee
416416
txFees = xBaseTxFee + pBaseTxFee
417417
neededBalance = txFees + units.Avax
418418
)
@@ -484,7 +484,7 @@ func (w *workload) issuePToXTransfer(ctx context.Context) {
484484
pContext = pBuilder.Context()
485485
avaxAssetID = pContext.AVAXAssetID
486486
avaxBalance = balances[avaxAssetID]
487-
pBaseTxFee = pContext.BaseTxFee
487+
pBaseTxFee = pContext.StaticFeeConfig.TxFee
488488
xBaseTxFee = xContext.BaseTxFee
489489
txFees = pBaseTxFee + xBaseTxFee
490490
neededBalance = txFees + units.Schmeckle

0 commit comments

Comments
 (0)