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

Add dynamic fees config #3250

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 17 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ import (
"github.com/ava-labs/avalanchego/utils/timer"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
"github.com/ava-labs/avalanchego/vms/proposervm"

feecomponent "github.com/ava-labs/avalanchego/vms/components/fee"
txfee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
)

const (
Expand Down Expand Up @@ -766,7 +768,7 @@ func getTxFeeConfig(v *viper.Viper, networkID uint32) genesis.TxFeeConfig {
if networkID != constants.MainnetID && networkID != constants.FujiID {
return genesis.TxFeeConfig{
CreateAssetTxFee: v.GetUint64(CreateAssetTxFeeKey),
StaticFeeConfig: fee.StaticConfig{
StaticFeeConfig: txfee.StaticConfig{
TxFee: v.GetUint64(TxFeeKey),
CreateSubnetTxFee: v.GetUint64(CreateSubnetTxFeeKey),
TransformSubnetTxFee: v.GetUint64(TransformSubnetTxFeeKey),
Expand All @@ -776,6 +778,19 @@ func getTxFeeConfig(v *viper.Viper, networkID uint32) genesis.TxFeeConfig {
AddSubnetValidatorFee: v.GetUint64(AddSubnetValidatorFeeKey),
AddSubnetDelegatorFee: v.GetUint64(AddSubnetDelegatorFeeKey),
},
DynamicFeeConfig: feecomponent.Config{
Weights: feecomponent.Dimensions{
feecomponent.Bandwidth: v.GetUint64(DynamicFeesBandwidthWeightKey),
feecomponent.DBRead: v.GetUint64(DynamicFeesDBReadWeightKey),
feecomponent.DBWrite: v.GetUint64(DynamicFeesDBWriteWeightKey),
feecomponent.Compute: v.GetUint64(DynamicFeesComputeWeightKey),
},
MaxGasCapacity: feecomponent.Gas(v.GetUint64(DynamicFeesMaxGasCapacityKey)),
MaxGasPerSecond: feecomponent.Gas(v.GetUint64(DynamicFeesMaxGasPerSecondKey)),
TargetGasPerSecond: feecomponent.Gas(v.GetUint64(DynamicFeesTargetGasPerSecondKey)),
MinGasPrice: feecomponent.GasPrice(v.GetUint64(DynamicFeesMinGasPriceKey)),
ExcessConversionConstant: feecomponent.Gas(v.GetUint64(DynamicFeesExcessConversionConstantKey)),
},
}
}
return genesis.GetTxFeeConfig(networkID)
Expand Down
14 changes: 13 additions & 1 deletion config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ava-labs/avalanchego/utils/dynamicip"
"github.com/ava-labs/avalanchego/utils/ulimit"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/components/fee"
)

const (
Expand Down Expand Up @@ -98,7 +99,18 @@ func addNodeFlags(fs *pflag.FlagSet) {
fs.IntSlice(ACPSupportKey, nil, "ACPs to support adoption")
fs.IntSlice(ACPObjectKey, nil, "ACPs to object adoption")

// AVAX fees
// AVAX fees:
// Dynamic fees:
fs.Uint64(DynamicFeesBandwidthWeightKey, genesis.LocalParams.DynamicFeeConfig.Weights[fee.Bandwidth], "Complexity multiplier used to convert Bandwidth into Gas")
fs.Uint64(DynamicFeesDBReadWeightKey, genesis.LocalParams.DynamicFeeConfig.Weights[fee.DBRead], "Complexity multiplier used to convert DB Reads into Gas")
fs.Uint64(DynamicFeesDBWriteWeightKey, genesis.LocalParams.DynamicFeeConfig.Weights[fee.DBWrite], "Complexity multiplier used to convert DB Writes into Gas")
fs.Uint64(DynamicFeesComputeWeightKey, genesis.LocalParams.DynamicFeeConfig.Weights[fee.Compute], "Complexity multiplier used to convert Compute into Gas")
fs.Uint64(DynamicFeesMaxGasCapacityKey, uint64(genesis.LocalParams.DynamicFeeConfig.MaxGasCapacity), "Maximum amount of Gas the chain is allowed to store for future use")
fs.Uint64(DynamicFeesMaxGasPerSecondKey, uint64(genesis.LocalParams.DynamicFeeConfig.MaxGasPerSecond), "Rate at which Gas is stored for future use")
fs.Uint64(DynamicFeesTargetGasPerSecondKey, uint64(genesis.LocalParams.DynamicFeeConfig.TargetGasPerSecond), "Target rate of Gas usage")
fs.Uint64(DynamicFeesMinGasPriceKey, uint64(genesis.LocalParams.DynamicFeeConfig.MinGasPrice), "Minimum Gas price")
fs.Uint64(DynamicFeesExcessConversionConstantKey, uint64(genesis.LocalParams.DynamicFeeConfig.ExcessConversionConstant), "Constant to convert excess Gas to the Gas price")
// Static fees:
fs.Uint64(TxFeeKey, genesis.LocalParams.StaticFeeConfig.TxFee, "Transaction fee, in nAVAX")
fs.Uint64(CreateAssetTxFeeKey, genesis.LocalParams.CreateAssetTxFee, "Transaction fee, in nAVAX, for transactions that create new assets")
fs.Uint64(CreateSubnetTxFeeKey, genesis.LocalParams.StaticFeeConfig.CreateSubnetTxFee, "Transaction fee, in nAVAX, for transactions that create new subnets")
Expand Down
101 changes: 55 additions & 46 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,61 @@ package config
const HTTPWriteTimeoutKey = "http-write-timeout" // #nosec G101

const (
DataDirKey = "data-dir"
ConfigFileKey = "config-file"
ConfigContentKey = "config-file-content"
ConfigContentTypeKey = "config-file-content-type"
VersionKey = "version"
VersionJSONKey = "version-json"
GenesisFileKey = "genesis-file"
GenesisFileContentKey = "genesis-file-content"
NetworkNameKey = "network-id"
ACPSupportKey = "acp-support"
ACPObjectKey = "acp-object"
TxFeeKey = "tx-fee"
CreateAssetTxFeeKey = "create-asset-tx-fee"
CreateSubnetTxFeeKey = "create-subnet-tx-fee"
TransformSubnetTxFeeKey = "transform-subnet-tx-fee"
CreateBlockchainTxFeeKey = "create-blockchain-tx-fee"
AddPrimaryNetworkValidatorFeeKey = "add-primary-network-validator-fee"
AddPrimaryNetworkDelegatorFeeKey = "add-primary-network-delegator-fee"
AddSubnetValidatorFeeKey = "add-subnet-validator-fee"
AddSubnetDelegatorFeeKey = "add-subnet-delegator-fee"
UptimeRequirementKey = "uptime-requirement"
MinValidatorStakeKey = "min-validator-stake"
MaxValidatorStakeKey = "max-validator-stake"
MinDelegatorStakeKey = "min-delegator-stake"
MinDelegatorFeeKey = "min-delegation-fee"
MinStakeDurationKey = "min-stake-duration"
MaxStakeDurationKey = "max-stake-duration"
StakeMaxConsumptionRateKey = "stake-max-consumption-rate"
StakeMinConsumptionRateKey = "stake-min-consumption-rate"
StakeMintingPeriodKey = "stake-minting-period"
StakeSupplyCapKey = "stake-supply-cap"
DBTypeKey = "db-type"
DBReadOnlyKey = "db-read-only"
DBPathKey = "db-dir"
DBConfigFileKey = "db-config-file"
DBConfigContentKey = "db-config-file-content"
PublicIPKey = "public-ip"
PublicIPResolutionFreqKey = "public-ip-resolution-frequency"
PublicIPResolutionServiceKey = "public-ip-resolution-service"
HTTPHostKey = "http-host"
HTTPPortKey = "http-port"
HTTPSEnabledKey = "http-tls-enabled"
HTTPSKeyFileKey = "http-tls-key-file"
HTTPSKeyContentKey = "http-tls-key-file-content"
HTTPSCertFileKey = "http-tls-cert-file"
HTTPSCertContentKey = "http-tls-cert-file-content"
DataDirKey = "data-dir"
ConfigFileKey = "config-file"
ConfigContentKey = "config-file-content"
ConfigContentTypeKey = "config-file-content-type"
VersionKey = "version"
VersionJSONKey = "version-json"
GenesisFileKey = "genesis-file"
GenesisFileContentKey = "genesis-file-content"
NetworkNameKey = "network-id"
ACPSupportKey = "acp-support"
ACPObjectKey = "acp-object"
DynamicFeesBandwidthWeightKey = "dynamic-fees-bandwidth-weight"
DynamicFeesDBReadWeightKey = "dynamic-fees-db-read-weight"
DynamicFeesDBWriteWeightKey = "dynamic-fees-db-write-weight"
DynamicFeesComputeWeightKey = "dynamic-fees-compute-weight"
DynamicFeesMaxGasCapacityKey = "dynamic-fees-max-gas-capacity"
DynamicFeesMaxGasPerSecondKey = "dynamic-fees-max-gas-per-second"
DynamicFeesTargetGasPerSecondKey = "dynamic-fees-target-gas-per-second"
DynamicFeesMinGasPriceKey = "dynamic-fees-min-gas-price"
DynamicFeesExcessConversionConstantKey = "dynamic-fees-excess-conversion-constant"
TxFeeKey = "tx-fee"
CreateAssetTxFeeKey = "create-asset-tx-fee"
CreateSubnetTxFeeKey = "create-subnet-tx-fee"
TransformSubnetTxFeeKey = "transform-subnet-tx-fee"
CreateBlockchainTxFeeKey = "create-blockchain-tx-fee"
AddPrimaryNetworkValidatorFeeKey = "add-primary-network-validator-fee"
AddPrimaryNetworkDelegatorFeeKey = "add-primary-network-delegator-fee"
AddSubnetValidatorFeeKey = "add-subnet-validator-fee"
AddSubnetDelegatorFeeKey = "add-subnet-delegator-fee"
UptimeRequirementKey = "uptime-requirement"
MinValidatorStakeKey = "min-validator-stake"
MaxValidatorStakeKey = "max-validator-stake"
MinDelegatorStakeKey = "min-delegator-stake"
MinDelegatorFeeKey = "min-delegation-fee"
MinStakeDurationKey = "min-stake-duration"
MaxStakeDurationKey = "max-stake-duration"
StakeMaxConsumptionRateKey = "stake-max-consumption-rate"
StakeMinConsumptionRateKey = "stake-min-consumption-rate"
StakeMintingPeriodKey = "stake-minting-period"
StakeSupplyCapKey = "stake-supply-cap"
DBTypeKey = "db-type"
DBReadOnlyKey = "db-read-only"
DBPathKey = "db-dir"
DBConfigFileKey = "db-config-file"
DBConfigContentKey = "db-config-file-content"
PublicIPKey = "public-ip"
PublicIPResolutionFreqKey = "public-ip-resolution-frequency"
PublicIPResolutionServiceKey = "public-ip-resolution-service"
HTTPHostKey = "http-host"
HTTPPortKey = "http-port"
HTTPSEnabledKey = "http-tls-enabled"
HTTPSKeyFileKey = "http-tls-key-file"
HTTPSKeyContentKey = "http-tls-key-file-content"
HTTPSCertFileKey = "http-tls-cert-file"
HTTPSCertContentKey = "http-tls-cert-file-content"

HTTPAllowedOrigins = "http-allowed-origins"
HTTPAllowedHostsKey = "http-allowed-hosts"
Expand Down
20 changes: 18 additions & 2 deletions genesis/genesis_fuji.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (

"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"

feecomponent "github.com/ava-labs/avalanchego/vms/components/fee"
txfee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
)

var (
Expand All @@ -21,7 +23,7 @@ var (
FujiParams = Params{
TxFeeConfig: TxFeeConfig{
CreateAssetTxFee: 10 * units.MilliAvax,
StaticFeeConfig: fee.StaticConfig{
StaticFeeConfig: txfee.StaticConfig{
TxFee: units.MilliAvax,
CreateSubnetTxFee: 100 * units.MilliAvax,
TransformSubnetTxFee: 1 * units.Avax,
Expand All @@ -31,6 +33,20 @@ var (
AddSubnetValidatorFee: units.MilliAvax,
AddSubnetDelegatorFee: units.MilliAvax,
},
// TODO: Set these values to something more reasonable
DynamicFeeConfig: feecomponent.Config{
Weights: feecomponent.Dimensions{
feecomponent.Bandwidth: 1,
feecomponent.DBRead: 1,
feecomponent.DBWrite: 1,
feecomponent.Compute: 1,
},
MaxGasCapacity: 1_000_000,
MaxGasPerSecond: 1_000,
TargetGasPerSecond: 500,
MinGasPrice: 1,
ExcessConversionConstant: 1,
},
},
StakingConfig: StakingConfig{
UptimeRequirement: .8, // 80%
Expand Down
20 changes: 18 additions & 2 deletions genesis/genesis_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"

feecomponent "github.com/ava-labs/avalanchego/vms/components/fee"
txfee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
)

// PrivateKey-vmRQiZeXEXYMyJhEiqdC2z5JhuDbxL8ix9UVvjgMu2Er1NepE => P-local1g65uqn6t77p656w64023nh8nd9updzmxyymev2
Expand All @@ -39,7 +41,7 @@ var (
LocalParams = Params{
TxFeeConfig: TxFeeConfig{
CreateAssetTxFee: units.MilliAvax,
StaticFeeConfig: fee.StaticConfig{
StaticFeeConfig: txfee.StaticConfig{
TxFee: units.MilliAvax,
CreateSubnetTxFee: 100 * units.MilliAvax,
TransformSubnetTxFee: 100 * units.MilliAvax,
Expand All @@ -49,6 +51,20 @@ var (
AddSubnetValidatorFee: units.MilliAvax,
AddSubnetDelegatorFee: units.MilliAvax,
},
// TODO: Set these values to something more reasonable
DynamicFeeConfig: feecomponent.Config{
Weights: feecomponent.Dimensions{
feecomponent.Bandwidth: 1,
feecomponent.DBRead: 1,
feecomponent.DBWrite: 1,
feecomponent.Compute: 1,
},
MaxGasCapacity: 1_000_000,
MaxGasPerSecond: 1_000,
TargetGasPerSecond: 500,
MinGasPrice: 1,
ExcessConversionConstant: 1,
},
},
StakingConfig: StakingConfig{
UptimeRequirement: .8, // 80%
Expand Down
20 changes: 18 additions & 2 deletions genesis/genesis_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (

"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"

feecomponent "github.com/ava-labs/avalanchego/vms/components/fee"
txfee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
)

var (
Expand All @@ -21,7 +23,7 @@ var (
MainnetParams = Params{
TxFeeConfig: TxFeeConfig{
CreateAssetTxFee: 10 * units.MilliAvax,
StaticFeeConfig: fee.StaticConfig{
StaticFeeConfig: txfee.StaticConfig{
TxFee: units.MilliAvax,
CreateSubnetTxFee: 1 * units.Avax,
TransformSubnetTxFee: 10 * units.Avax,
Expand All @@ -31,6 +33,20 @@ var (
AddSubnetValidatorFee: units.MilliAvax,
AddSubnetDelegatorFee: units.MilliAvax,
},
// TODO: Set these values to something more reasonable
DynamicFeeConfig: feecomponent.Config{
Weights: feecomponent.Dimensions{
feecomponent.Bandwidth: 1,
feecomponent.DBRead: 1,
feecomponent.DBWrite: 1,
feecomponent.Compute: 1,
},
MaxGasCapacity: 1_000_000,
MaxGasPerSecond: 1_000,
TargetGasPerSecond: 500,
MinGasPrice: 1,
ExcessConversionConstant: 1,
},
},
StakingConfig: StakingConfig{
UptimeRequirement: .8, // 80%
Expand Down
9 changes: 6 additions & 3 deletions genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (

"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"

feecomponent "github.com/ava-labs/avalanchego/vms/components/fee"
txfee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
)

type StakingConfig struct {
Expand All @@ -35,8 +37,9 @@ type StakingConfig struct {
}

type TxFeeConfig struct {
CreateAssetTxFee uint64 `json:"createAssetTxFee"`
StaticFeeConfig fee.StaticConfig `json:"staticFeeConfig"`
CreateAssetTxFee uint64 `json:"createAssetTxFee"`
StaticFeeConfig txfee.StaticConfig `json:"staticFeeConfig"`
DynamicFeeConfig feecomponent.Config `json:"dynamicFeeConfig"`
}

type Params struct {
Expand Down
1 change: 1 addition & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ func (n *Node) initVMs() error {
TrackedSubnets: n.Config.TrackedSubnets,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
StaticFeeConfig: n.Config.StaticFeeConfig,
DynamicFeeConfig: n.Config.DynamicFeeConfig,
UptimePercentage: n.Config.UptimeRequirement,
MinValidatorStake: n.Config.MinValidatorStake,
MaxValidatorStake: n.Config.MaxValidatorStake,
Expand Down
11 changes: 8 additions & 3 deletions vms/platformvm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
"github.com/ava-labs/avalanchego/vms/platformvm/upgrade"

feecomponent "github.com/ava-labs/avalanchego/vms/components/fee"
txfee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
)

// Struct collecting all foundational parameters of PlatformVM
Expand All @@ -31,9 +33,12 @@ type Config struct {
// calling VM.Initialize.
Validators validators.Manager

// All static fees config active before E-upgrade
// Static fees are active before the E-upgrade
CreateAssetTxFee uint64 // Override for CreateSubnet and CreateChain before AP3
StaticFeeConfig fee.StaticConfig
StaticFeeConfig txfee.StaticConfig

// Dynamic fees are active after the E-upgrade
DynamicFeeConfig feecomponent.Config

// Provides access to the uptime manager as a thread safe data structure
UptimeLockedCalculator uptime.LockedCalculator
Expand Down
Loading