diff --git a/avalanchego/version/constants.go b/avalanchego/version/constants.go index e77210b3..ab2809fd 100644 --- a/avalanchego/version/constants.go +++ b/avalanchego/version/constants.go @@ -14,7 +14,7 @@ var ( Current = &Semantic{ Major: 1, Minor: 7, - Patch: 1805, + Patch: 1806, } CurrentApp = &Application{ Major: Current.Major, diff --git a/avalanchego/vms/platformvm/service.go b/avalanchego/vms/platformvm/service.go index 164d1599..d09bb822 100644 --- a/avalanchego/vms/platformvm/service.go +++ b/avalanchego/vms/platformvm/service.go @@ -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 } diff --git a/avalanchego/vms/platformvm/txs/executor/inflation_settings.go b/avalanchego/vms/platformvm/txs/executor/inflation_settings.go new file mode 100644 index 00000000..16b2a5f6 --- /dev/null +++ b/avalanchego/vms/platformvm/txs/executor/inflation_settings.go @@ -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) + } +} diff --git a/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go index 839d71dc..dfec5efd 100644 --- a/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -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" @@ -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 { @@ -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 @@ -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 @@ -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 }