Skip to content

Commit

Permalink
Add additional fee configs for new staker transactions (ava-labs#1911)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Sep 1, 2022
1 parent 98ae7fc commit 47ffeab
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 95 deletions.
40 changes: 26 additions & 14 deletions api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ type Info struct {
}

type Parameters struct {
Version *version.Application
NodeID ids.NodeID
NetworkID uint32
TxFee uint64
CreateAssetTxFee uint64
CreateSubnetTxFee uint64
TransformSubnetTxFee uint64
CreateBlockchainTxFee uint64
VMManager vms.Manager
Version *version.Application
NodeID ids.NodeID
NetworkID uint32
TxFee uint64
CreateAssetTxFee uint64
CreateSubnetTxFee uint64
TransformSubnetTxFee uint64
CreateBlockchainTxFee uint64
AddPrimaryNetworkValidatorFee uint64
AddPrimaryNetworkDelegatorFee uint64
AddSubnetValidatorFee uint64
AddSubnetDelegatorFee uint64
VMManager vms.Manager
}

// NewService returns a new admin API service
Expand Down Expand Up @@ -278,11 +282,15 @@ func (service *Info) Uptime(_ *http.Request, _ *struct{}, reply *UptimeResponse)
type GetTxFeeResponse struct {
TxFee json.Uint64 `json:"txFee"`
// TODO: remove [CreationTxFee] after enough time for dependencies to update
CreationTxFee json.Uint64 `json:"creationTxFee"`
CreateAssetTxFee json.Uint64 `json:"createAssetTxFee"`
CreateSubnetTxFee json.Uint64 `json:"createSubnetTxFee"`
TransformSubnetTxFee json.Uint64 `json:"transformSubnetTxFee"`
CreateBlockchainTxFee json.Uint64 `json:"createBlockchainTxFee"`
CreationTxFee json.Uint64 `json:"creationTxFee"`
CreateAssetTxFee json.Uint64 `json:"createAssetTxFee"`
CreateSubnetTxFee json.Uint64 `json:"createSubnetTxFee"`
TransformSubnetTxFee json.Uint64 `json:"transformSubnetTxFee"`
CreateBlockchainTxFee json.Uint64 `json:"createBlockchainTxFee"`
AddPrimaryNetworkValidatorFee json.Uint64 `json:"addPrimaryNetworkValidatorFee"`
AddPrimaryNetworkDelegatorFee json.Uint64 `json:"addPrimaryNetworkDelegatorFee"`
AddSubnetValidatorFee json.Uint64 `json:"addSubnetValidatorFee"`
AddSubnetDelegatorFee json.Uint64 `json:"addSubnetDelegatorFee"`
}

// GetTxFee returns the transaction fee in nAVAX.
Expand All @@ -293,6 +301,10 @@ func (service *Info) GetTxFee(_ *http.Request, args *struct{}, reply *GetTxFeeRe
reply.CreateSubnetTxFee = json.Uint64(service.CreateSubnetTxFee)
reply.TransformSubnetTxFee = json.Uint64(service.TransformSubnetTxFee)
reply.CreateBlockchainTxFee = json.Uint64(service.CreateBlockchainTxFee)
reply.AddPrimaryNetworkValidatorFee = json.Uint64(service.AddPrimaryNetworkValidatorFee)
reply.AddPrimaryNetworkDelegatorFee = json.Uint64(service.AddPrimaryNetworkDelegatorFee)
reply.AddSubnetValidatorFee = json.Uint64(service.AddSubnetValidatorFee)
reply.AddSubnetDelegatorFee = json.Uint64(service.AddSubnetDelegatorFee)
return nil
}

Expand Down
14 changes: 9 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,15 @@ func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, err
func getTxFeeConfig(v *viper.Viper, networkID uint32) genesis.TxFeeConfig {
if networkID != constants.MainnetID && networkID != constants.FujiID {
return genesis.TxFeeConfig{
TxFee: v.GetUint64(TxFeeKey),
CreateAssetTxFee: v.GetUint64(CreateAssetTxFeeKey),
CreateSubnetTxFee: v.GetUint64(CreateSubnetTxFeeKey),
TransformSubnetTxFee: v.GetUint64(TransformSubnetTxFeeKey),
CreateBlockchainTxFee: v.GetUint64(CreateBlockchainTxFeeKey),
TxFee: v.GetUint64(TxFeeKey),
CreateAssetTxFee: v.GetUint64(CreateAssetTxFeeKey),
CreateSubnetTxFee: v.GetUint64(CreateSubnetTxFeeKey),
TransformSubnetTxFee: v.GetUint64(TransformSubnetTxFeeKey),
CreateBlockchainTxFee: v.GetUint64(CreateBlockchainTxFeeKey),
AddPrimaryNetworkValidatorFee: v.GetUint64(AddPrimaryNetworkValidatorFeeKey),
AddPrimaryNetworkDelegatorFee: v.GetUint64(AddPrimaryNetworkDelegatorFeeKey),
AddSubnetValidatorFee: v.GetUint64(AddSubnetValidatorFeeKey),
AddSubnetDelegatorFee: v.GetUint64(AddSubnetDelegatorFeeKey),
}
}
return genesis.GetTxFeeConfig(networkID)
Expand Down
4 changes: 4 additions & 0 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func addNodeFlags(fs *flag.FlagSet) {
fs.Uint64(CreateSubnetTxFeeKey, genesis.LocalParams.CreateSubnetTxFee, "Transaction fee, in nAVAX, for transactions that create new subnets")
fs.Uint64(TransformSubnetTxFeeKey, genesis.LocalParams.TransformSubnetTxFee, "Transaction fee, in nAVAX, for transactions that transform subnets")
fs.Uint64(CreateBlockchainTxFeeKey, genesis.LocalParams.CreateBlockchainTxFee, "Transaction fee, in nAVAX, for transactions that create new blockchains")
fs.Uint64(AddPrimaryNetworkValidatorFeeKey, genesis.LocalParams.AddPrimaryNetworkValidatorFee, "Transaction fee, in nAVAX, for transactions that add new primary network validators")
fs.Uint64(AddPrimaryNetworkDelegatorFeeKey, genesis.LocalParams.AddPrimaryNetworkDelegatorFee, "Transaction fee, in nAVAX, for transactions that add new primary network delegators")
fs.Uint64(AddSubnetValidatorFeeKey, genesis.LocalParams.AddSubnetValidatorFee, "Transaction fee, in nAVAX, for transactions that add new subnet validators")
fs.Uint64(AddSubnetDelegatorFeeKey, genesis.LocalParams.AddSubnetDelegatorFee, "Transaction fee, in nAVAX, for transactions that add new subnet delegators")

// Database
fs.String(DBTypeKey, leveldb.Name, fmt.Sprintf("Database type to use. Should be one of {%s, %s}", leveldb.Name, memdb.Name))
Expand Down
4 changes: 4 additions & 0 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const (
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"
Expand Down
14 changes: 9 additions & 5 deletions genesis/genesis_fuji.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ var (
// FujiParams are the params used for the fuji testnet
FujiParams = Params{
TxFeeConfig: TxFeeConfig{
TxFee: units.MilliAvax,
CreateAssetTxFee: 10 * units.MilliAvax,
CreateSubnetTxFee: 100 * units.MilliAvax,
TransformSubnetTxFee: 100 * units.MilliAvax,
CreateBlockchainTxFee: 100 * units.MilliAvax,
TxFee: units.MilliAvax,
CreateAssetTxFee: 10 * units.MilliAvax,
CreateSubnetTxFee: 100 * units.MilliAvax,
TransformSubnetTxFee: 100 * units.MilliAvax,
CreateBlockchainTxFee: 100 * units.MilliAvax,
AddPrimaryNetworkValidatorFee: 0,
AddPrimaryNetworkDelegatorFee: 0,
AddSubnetValidatorFee: units.MilliAvax,
AddSubnetDelegatorFee: units.MilliAvax,
},
StakingConfig: StakingConfig{
UptimeRequirement: .8, // 80%
Expand Down
14 changes: 9 additions & 5 deletions genesis/genesis_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ var (
// LocalParams are the params used for local networks
LocalParams = Params{
TxFeeConfig: TxFeeConfig{
TxFee: units.MilliAvax,
CreateAssetTxFee: units.MilliAvax,
CreateSubnetTxFee: 100 * units.MilliAvax,
TransformSubnetTxFee: 100 * units.MilliAvax,
CreateBlockchainTxFee: 100 * units.MilliAvax,
TxFee: units.MilliAvax,
CreateAssetTxFee: units.MilliAvax,
CreateSubnetTxFee: 100 * units.MilliAvax,
TransformSubnetTxFee: 100 * units.MilliAvax,
CreateBlockchainTxFee: 100 * units.MilliAvax,
AddPrimaryNetworkValidatorFee: 0,
AddPrimaryNetworkDelegatorFee: 0,
AddSubnetValidatorFee: units.MilliAvax,
AddSubnetDelegatorFee: units.MilliAvax,
},
StakingConfig: StakingConfig{
UptimeRequirement: .8, // 80%
Expand Down
14 changes: 9 additions & 5 deletions genesis/genesis_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ var (
// MainnetParams are the params used for mainnet
MainnetParams = Params{
TxFeeConfig: TxFeeConfig{
TxFee: units.MilliAvax,
CreateAssetTxFee: 10 * units.MilliAvax,
CreateSubnetTxFee: 1 * units.Avax,
TransformSubnetTxFee: 1 * units.Avax,
CreateBlockchainTxFee: 1 * units.Avax,
TxFee: units.MilliAvax,
CreateAssetTxFee: 10 * units.MilliAvax,
CreateSubnetTxFee: 1 * units.Avax,
TransformSubnetTxFee: 1 * units.Avax,
CreateBlockchainTxFee: 1 * units.Avax,
AddPrimaryNetworkValidatorFee: 0,
AddPrimaryNetworkDelegatorFee: 0,
AddSubnetValidatorFee: units.MilliAvax,
AddSubnetDelegatorFee: units.MilliAvax,
},
StakingConfig: StakingConfig{
UptimeRequirement: .8, // 80%
Expand Down
8 changes: 8 additions & 0 deletions genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ type TxFeeConfig struct {
TransformSubnetTxFee uint64 `json:"transformSubnetTxFee"`
// Transaction fee for create blockchain transactions
CreateBlockchainTxFee uint64 `json:"createBlockchainTxFee"`
// Transaction fee for adding a primary network validator
AddPrimaryNetworkValidatorFee uint64 `json:"addPrimaryNetworkValidatorFee"`
// Transaction fee for adding a primary network delegator
AddPrimaryNetworkDelegatorFee uint64 `json:"addPrimaryNetworkDelegatorFee"`
// Transaction fee for adding a subnet validator
AddSubnetValidatorFee uint64 `json:"addSubnetValidatorFee"`
// Transaction fee for adding a subnet delegator
AddSubnetDelegatorFee uint64 `json:"addSubnetDelegatorFee"`
}

type Params struct {
Expand Down
70 changes: 39 additions & 31 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,28 +767,32 @@ func (n *Node) initVMs() error {
errs.Add(
vmRegisterer.Register(constants.PlatformVMID, &platformvm.Factory{
Config: config.Config{
Chains: n.chainManager,
Validators: vdrs,
SubnetTracker: n.Net,
UptimeLockedCalculator: n.uptimeCalculator,
StakingEnabled: n.Config.EnableStaking,
WhitelistedSubnets: n.Config.WhitelistedSubnets,
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
CreateSubnetTxFee: n.Config.CreateSubnetTxFee,
TransformSubnetTxFee: n.Config.TransformSubnetTxFee,
CreateBlockchainTxFee: n.Config.CreateBlockchainTxFee,
UptimePercentage: n.Config.UptimeRequirement,
MinValidatorStake: n.Config.MinValidatorStake,
MaxValidatorStake: n.Config.MaxValidatorStake,
MinDelegatorStake: n.Config.MinDelegatorStake,
MinDelegationFee: n.Config.MinDelegationFee,
MinStakeDuration: n.Config.MinStakeDuration,
MaxStakeDuration: n.Config.MaxStakeDuration,
RewardConfig: n.Config.RewardConfig,
ApricotPhase3Time: version.GetApricotPhase3Time(n.Config.NetworkID),
ApricotPhase5Time: version.GetApricotPhase5Time(n.Config.NetworkID),
BlueberryTime: version.GetBlueberryTime(n.Config.NetworkID),
Chains: n.chainManager,
Validators: vdrs,
SubnetTracker: n.Net,
UptimeLockedCalculator: n.uptimeCalculator,
StakingEnabled: n.Config.EnableStaking,
WhitelistedSubnets: n.Config.WhitelistedSubnets,
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
CreateSubnetTxFee: n.Config.CreateSubnetTxFee,
TransformSubnetTxFee: n.Config.TransformSubnetTxFee,
CreateBlockchainTxFee: n.Config.CreateBlockchainTxFee,
AddPrimaryNetworkValidatorFee: n.Config.AddPrimaryNetworkValidatorFee,
AddPrimaryNetworkDelegatorFee: n.Config.AddPrimaryNetworkDelegatorFee,
AddSubnetValidatorFee: n.Config.AddSubnetValidatorFee,
AddSubnetDelegatorFee: n.Config.AddSubnetDelegatorFee,
UptimePercentage: n.Config.UptimeRequirement,
MinValidatorStake: n.Config.MinValidatorStake,
MaxValidatorStake: n.Config.MaxValidatorStake,
MinDelegatorStake: n.Config.MinDelegatorStake,
MinDelegationFee: n.Config.MinDelegationFee,
MinStakeDuration: n.Config.MinStakeDuration,
MaxStakeDuration: n.Config.MaxStakeDuration,
RewardConfig: n.Config.RewardConfig,
ApricotPhase3Time: version.GetApricotPhase3Time(n.Config.NetworkID),
ApricotPhase5Time: version.GetApricotPhase5Time(n.Config.NetworkID),
BlueberryTime: version.GetBlueberryTime(n.Config.NetworkID),
},
}),
vmRegisterer.Register(constants.AVMID, &avm.Factory{
Expand Down Expand Up @@ -960,15 +964,19 @@ func (n *Node) initInfoAPI() error {
primaryValidators, _ := n.vdrs.GetValidators(constants.PrimaryNetworkID)
service, err := info.NewService(
info.Parameters{
Version: version.CurrentApp,
NodeID: n.ID,
NetworkID: n.Config.NetworkID,
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
CreateSubnetTxFee: n.Config.CreateSubnetTxFee,
TransformSubnetTxFee: n.Config.TransformSubnetTxFee,
CreateBlockchainTxFee: n.Config.CreateBlockchainTxFee,
VMManager: n.Config.VMManager,
Version: version.CurrentApp,
NodeID: n.ID,
NetworkID: n.Config.NetworkID,
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
CreateSubnetTxFee: n.Config.CreateSubnetTxFee,
TransformSubnetTxFee: n.Config.TransformSubnetTxFee,
CreateBlockchainTxFee: n.Config.CreateBlockchainTxFee,
AddPrimaryNetworkValidatorFee: n.Config.AddPrimaryNetworkValidatorFee,
AddPrimaryNetworkDelegatorFee: n.Config.AddPrimaryNetworkDelegatorFee,
AddSubnetValidatorFee: n.Config.AddSubnetValidatorFee,
AddSubnetDelegatorFee: n.Config.AddSubnetDelegatorFee,
VMManager: n.Config.VMManager,
},
n.Log,
n.chainManager,
Expand Down
15 changes: 12 additions & 3 deletions vms/platformvm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ type Config struct {
// Set of subnets that this node is validating
WhitelistedSubnets ids.Set

// Fee that must be burned by every create staker transaction
AddStakerTxFee uint64

// Fee that is burned by every non-state creating transaction
TxFee uint64

Expand All @@ -54,6 +51,18 @@ type Config struct {
// Fee that must be burned by every blockchain creating transaction after AP3
CreateBlockchainTxFee uint64

// Transaction fee for adding a primary network validator
AddPrimaryNetworkValidatorFee uint64

// Transaction fee for adding a primary network delegator
AddPrimaryNetworkDelegatorFee uint64

// Transaction fee for adding a subnet validator
AddSubnetValidatorFee uint64

// Transaction fee for adding a subnet delegator
AddSubnetDelegatorFee uint64

// The minimum amount of tokens one must bond to be a validator
MinValidatorStake uint64

Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (b *builder) NewAddValidatorTx(
keys []*crypto.PrivateKeySECP256K1R,
changeAddr ids.ShortID,
) (*txs.Tx, error) {
ins, unstakedOuts, stakedOuts, signers, err := b.Spend(keys, stakeAmount, b.cfg.AddStakerTxFee, changeAddr)
ins, unstakedOuts, stakedOuts, signers, err := b.Spend(keys, stakeAmount, b.cfg.AddPrimaryNetworkValidatorFee, changeAddr)
if err != nil {
return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err)
}
Expand Down Expand Up @@ -477,7 +477,7 @@ func (b *builder) NewAddDelegatorTx(
keys []*crypto.PrivateKeySECP256K1R,
changeAddr ids.ShortID,
) (*txs.Tx, error) {
ins, unlockedOuts, lockedOuts, signers, err := b.Spend(keys, stakeAmount, b.cfg.AddStakerTxFee, changeAddr)
ins, unlockedOuts, lockedOuts, signers, err := b.Spend(keys, stakeAmount, b.cfg.AddPrimaryNetworkDelegatorFee, changeAddr)
if err != nil {
return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions vms/platformvm/txs/executor/staker_tx_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func verifyAddValidatorTx(
outs,
sTx.Creds,
map[ids.ID]uint64{
backend.Ctx.AVAXAssetID: backend.Config.AddStakerTxFee,
backend.Ctx.AVAXAssetID: backend.Config.AddPrimaryNetworkValidatorFee,
},
); err != nil {
return nil, fmt.Errorf("%w: %s", errFlowCheckFailed, err)
Expand Down Expand Up @@ -212,7 +212,7 @@ func verifyAddSubnetValidatorTx(
tx.Outs,
baseTxCreds,
map[ids.ID]uint64{
backend.Ctx.AVAXAssetID: backend.Config.TxFee,
backend.Ctx.AVAXAssetID: backend.Config.AddSubnetValidatorFee,
},
); err != nil {
return fmt.Errorf("%w: %s", errFlowCheckFailed, err)
Expand Down Expand Up @@ -379,7 +379,7 @@ func verifyAddDelegatorTx(
outs,
sTx.Creds,
map[ids.ID]uint64{
backend.Ctx.AVAXAssetID: backend.Config.AddStakerTxFee,
backend.Ctx.AVAXAssetID: backend.Config.AddPrimaryNetworkDelegatorFee,
},
); err != nil {
return nil, fmt.Errorf("%w: %s", errFlowCheckFailed, err)
Expand Down
14 changes: 10 additions & 4 deletions wallet/chain/p/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,12 @@ func (b *builder) NewAddValidatorTx(
shares uint32,
options ...common.Option,
) (*txs.AddValidatorTx, error) {
toBurn := map[ids.ID]uint64{}
avaxAssetID := b.backend.AVAXAssetID()
toBurn := map[ids.ID]uint64{
avaxAssetID: b.backend.AddPrimaryNetworkValidatorFee(),
}
toStake := map[ids.ID]uint64{
b.backend.AVAXAssetID(): vdr.Wght,
avaxAssetID: vdr.Wght,
}
ops := common.NewOptions(options)
inputs, baseOutputs, stakeOutputs, err := b.spend(toBurn, toStake, ops)
Expand Down Expand Up @@ -318,7 +321,7 @@ func (b *builder) NewAddSubnetValidatorTx(
options ...common.Option,
) (*txs.AddSubnetValidatorTx, error) {
toBurn := map[ids.ID]uint64{
b.backend.AVAXAssetID(): b.backend.BaseTxFee(),
b.backend.AVAXAssetID(): b.backend.AddSubnetValidatorFee(),
}
toStake := map[ids.ID]uint64{}
ops := common.NewOptions(options)
Expand Down Expand Up @@ -384,7 +387,10 @@ func (b *builder) NewAddDelegatorTx(
rewardsOwner *secp256k1fx.OutputOwners,
options ...common.Option,
) (*txs.AddDelegatorTx, error) {
toBurn := map[ids.ID]uint64{}
avaxAssetID := b.backend.AVAXAssetID()
toBurn := map[ids.ID]uint64{
avaxAssetID: b.backend.AddPrimaryNetworkDelegatorFee(),
}
toStake := map[ids.ID]uint64{
b.backend.AVAXAssetID(): vdr.Wght,
}
Expand Down
Loading

0 comments on commit 47ffeab

Please sign in to comment.