Skip to content

Commit

Permalink
Merge pull request #18 from mboben/staking-params-aug2023
Browse files Browse the repository at this point in the history
Staking params aug2023
  • Loading branch information
mboben authored Sep 4, 2023
2 parents 8eba01f + 95c0767 commit cb5ff5b
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 59 deletions.
2 changes: 1 addition & 1 deletion avalanchego/version/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
Current = &Semantic{
Major: 1,
Minor: 7,
Patch: 1805,
Patch: 1806,
}
CurrentApp = &Application{
Major: Current.Major,
Expand Down
6 changes: 4 additions & 2 deletions avalanchego/vms/platformvm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2145,8 +2145,10 @@ type GetMinStakeReply struct {

// GetMinStake returns the minimum staking amount in nAVAX.
func (service *Service) GetMinStake(_ *http.Request, _ *struct{}, reply *GetMinStakeReply) error {
reply.MinValidatorStake = json.Uint64(service.vm.MinValidatorStake)
reply.MinDelegatorStake = json.Uint64(service.vm.MinDelegatorStake)
timestamp := service.vm.state.GetTimestamp()
minValidatorStake, _, minDelegatorStake, _, _, _, _, _, _, _ := executor.GetCurrentInflationSettings(timestamp, service.vm.ctx.NetworkID, &service.vm.Config)
reply.MinValidatorStake = json.Uint64(minValidatorStake)
reply.MinDelegatorStake = json.Uint64(minDelegatorStake)
return nil
}

Expand Down
119 changes: 119 additions & 0 deletions avalanchego/vms/platformvm/txs/executor/inflation_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package executor

import (
"time"

"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/platformvm/config"
)

// The value of currentTimestamp is used to return new inflation settings over time
func GetCurrentInflationSettings(currentTimestamp time.Time, networkID uint32, config *config.Config) (uint64, uint64, uint64, uint32, time.Duration, time.Duration, time.Duration, time.Duration, uint64, time.Time) {
switch {
case currentTimestamp.Before(getPhaseTwoStakingStartTime(networkID)):
return getPhaseOneInflationSettings(networkID, config)
default:
return getPhaseTwoInflationSettings(networkID, config)
}
}

func getPhaseTwoStakingStartTime(networkID uint32) time.Time {
switch networkID {
case constants.FlareID:
return time.Date(2023, time.October, 1, 0, 0, 0, 0, time.UTC)
case constants.CostwoID:
return time.Date(2023, time.September, 7, 0, 0, 0, 0, time.UTC)
default:
return time.Date(2023, time.August, 1, 0, 0, 0, 0, time.UTC)
}
}

func getPhaseOneInflationSettings(networkID uint32, config *config.Config) (uint64, uint64, uint64, uint32, time.Duration, time.Duration, time.Duration, time.Duration, uint64, time.Time) {
switch networkID {
case constants.FlareID:
return 10 * units.MegaAvax, // minValidatorStake
50 * units.MegaAvax, // maxValidatorStake
1 * units.KiloAvax, // minDelegatorStake
0, // minDelegationFee
2 * 7 * 24 * time.Hour, // minStakeDuration
2 * 7 * 24 * time.Hour, // minDelegateDuration
365 * 24 * time.Hour, // maxStakeDuration
3 * 24 * time.Hour, // minFutureStartTimeOffset
MaxValidatorWeightFactor, // maxValidatorWeightFactor
time.Date(2023, time.July, 5, 15, 0, 0, 0, time.UTC) // minStakeStartTime
case constants.CostwoID:
return 100 * units.KiloAvax,
50 * units.MegaAvax,
1 * units.KiloAvax,
0,
2 * 7 * 24 * time.Hour,
2 * 7 * 24 * time.Hour,
365 * 24 * time.Hour,
MaxFutureStartTime,
MaxValidatorWeightFactor,
time.Date(2023, time.May, 25, 15, 0, 0, 0, time.UTC)
case constants.StagingID:
return 100 * units.KiloAvax,
50 * units.MegaAvax,
1 * units.KiloAvax,
0,
2 * 7 * 24 * time.Hour,
2 * 7 * 24 * time.Hour,
365 * 24 * time.Hour,
MaxFutureStartTime,
MaxValidatorWeightFactor,
time.Date(2023, time.May, 10, 15, 0, 0, 0, time.UTC)
case constants.LocalFlareID:
return 10 * units.KiloAvax,
50 * units.MegaAvax,
10 * units.KiloAvax,
0,
2 * 7 * 24 * time.Hour,
2 * 7 * 24 * time.Hour,
365 * 24 * time.Hour,
24 * time.Hour,
MaxValidatorWeightFactor,
time.Date(2023, time.April, 10, 15, 0, 0, 0, time.UTC)
default:
return config.MinValidatorStake,
config.MaxValidatorStake,
config.MinDelegatorStake,
config.MinDelegationFee,
config.MinStakeDuration,
config.MinStakeDuration,
config.MaxStakeDuration,
MaxFutureStartTime,
MaxValidatorWeightFactor,
time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC)
}
}

func getPhaseTwoInflationSettings(networkID uint32, config *config.Config) (uint64, uint64, uint64, uint32, time.Duration, time.Duration, time.Duration, time.Duration, uint64, time.Time) {
switch networkID {
case constants.FlareID:
return 1 * units.MegaAvax, // minValidatorStake
200 * units.MegaAvax, // maxValidatorStake
50 * units.KiloAvax, // minDelegatorStake
0, // minDelegationFee
60 * 24 * time.Hour, // minStakeDuration
2 * 7 * 24 * time.Hour, // minDelegateDuration
365 * 24 * time.Hour, // maxStakeDuration
MaxFutureStartTime, // minFutureStartTimeOffset
15, // maxValidatorWeightFactor
time.Date(2023, time.October, 1, 0, 0, 0, 0, time.UTC) // minStakeStartTime
case constants.CostwoID:
return 1 * units.MegaAvax,
200 * units.MegaAvax,
50 * units.KiloAvax,
0,
60 * 24 * time.Hour,
2 * 7 * 24 * time.Hour,
365 * 24 * time.Hour,
MaxFutureStartTime,
15,
time.Date(2023, time.September, 7, 0, 0, 0, 0, time.UTC)
default:
return getPhaseOneInflationSettings(networkID, config)
}
}
60 changes: 4 additions & 56 deletions avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/units"

"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/vms/components/avax"
Expand Down Expand Up @@ -68,57 +67,6 @@ func (*ProposalTxExecutor) CreateSubnetTx(*txs.CreateSubnetTx) error { return er
func (*ProposalTxExecutor) ImportTx(*txs.ImportTx) error { return errWrongTxType }
func (*ProposalTxExecutor) ExportTx(*txs.ExportTx) error { return errWrongTxType }

// The value of currentTimestamp is used to return new inflation settings over time
func (e *ProposalTxExecutor) getCurrentInflationSettings(currentTimestamp time.Time) (uint64, uint64, uint64, uint32, time.Duration, time.Duration, time.Duration, time.Time) {
switch e.Backend.Ctx.NetworkID {
case constants.FlareID:
return 10 * units.MegaAvax, // minValidatorStake
50 * units.MegaAvax, // maxValidatorStake
1 * units.KiloAvax, // minDelegatorStake
0, // minDelegationFee
2 * 7 * 24 * time.Hour, // minStakeDuration
365 * 24 * time.Hour, // maxStakeDuration
3 * 24 * time.Hour, // minFutureStartTimeOffset
time.Date(2023, time.July, 5, 15, 0, 0, 0, time.UTC) // minStakeStartTime
case constants.CostwoID:
return 100 * units.KiloAvax,
50 * units.MegaAvax,
1 * units.KiloAvax,
0,
2 * 7 * 24 * time.Hour,
365 * 24 * time.Hour,
MaxFutureStartTime,
time.Date(2023, time.May, 25, 15, 0, 0, 0, time.UTC)
case constants.StagingID:
return 100 * units.KiloAvax,
50 * units.MegaAvax,
1 * units.KiloAvax,
0,
2 * 7 * 24 * time.Hour,
365 * 24 * time.Hour,
MaxFutureStartTime,
time.Date(2023, time.May, 10, 15, 0, 0, 0, time.UTC)
case constants.LocalFlareID:
return 10 * units.KiloAvax,
50 * units.MegaAvax,
10 * units.KiloAvax,
0,
2 * 7 * 24 * time.Hour,
365 * 24 * time.Hour,
24 * time.Hour,
time.Date(2023, time.April, 10, 15, 0, 0, 0, time.UTC)
default:
return e.Config.MinValidatorStake,
e.Config.MaxValidatorStake,
e.Config.MinDelegatorStake,
e.Config.MinDelegationFee,
e.Config.MinStakeDuration,
e.Config.MaxStakeDuration,
MaxFutureStartTime,
time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC)
}
}

func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error {
// Verify the tx is well-formed
if err := e.Tx.SyntacticVerify(e.Ctx); err != nil {
Expand All @@ -131,7 +79,7 @@ func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error {
}
currentTimestamp := parentState.GetTimestamp()

minValidatorStake, maxValidatorStake, _, minDelegationFee, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, minStakeStartTime := e.getCurrentInflationSettings(currentTimestamp)
minValidatorStake, maxValidatorStake, _, minDelegationFee, minStakeDuration, _, maxStakeDuration, minFutureStartTimeOffset, _, minStakeStartTime := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config)
switch {
case tx.Validator.Wght < minValidatorStake:
// Ensure validator is staking at least the minimum amount
Expand Down Expand Up @@ -433,11 +381,11 @@ func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error {
}
currentTimestamp := parentState.GetTimestamp()

_, maxValidatorStake, minDelegatorStake, _, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, _ := e.getCurrentInflationSettings(currentTimestamp)
_, maxValidatorStake, minDelegatorStake, _, _, minDelegateDuration, maxStakeDuration, minFutureStartTimeOffset, maxValidatorWeightFactor, _ := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config)

duration := tx.Validator.Duration()
switch {
case duration < minStakeDuration:
case duration < minDelegateDuration:
// Ensure staking length is not too short
return errStakeTooShort

Expand Down Expand Up @@ -480,7 +428,7 @@ func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error {
)
}

maximumWeight, err := math.Mul64(MaxValidatorWeightFactor, primaryNetworkValidator.Weight)
maximumWeight, err := math.Mul64(maxValidatorWeightFactor, primaryNetworkValidator.Weight)
if err != nil {
return errStakeOverflow
}
Expand Down

0 comments on commit cb5ff5b

Please sign in to comment.