From a1e31654e134edcc571965843d5d452816c76dd3 Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Wed, 28 Jun 2023 16:50:45 +0200 Subject: [PATCH 1/9] Changed platformvm getMinStake service to return the correct current values --- avalanchego/vms/platformvm/service.go | 6 +- .../txs/executor/proposal_tx_executor.go | 56 +---------------- .../vms/platformvm/txs/executor/utils.go | 60 +++++++++++++++++++ 3 files changed, 66 insertions(+), 56 deletions(-) create mode 100644 avalanchego/vms/platformvm/txs/executor/utils.go diff --git a/avalanchego/vms/platformvm/service.go b/avalanchego/vms/platformvm/service.go index 164d1599..046f4bde 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/proposal_tx_executor.go b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go index 839d71dc..b5f5940b 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.Ctx.NetworkID, e.Config) switch { case tx.Validator.Wght < minValidatorStake: // Ensure validator is staking at least the minimum amount @@ -433,7 +381,7 @@ func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error { } currentTimestamp := parentState.GetTimestamp() - _, maxValidatorStake, minDelegatorStake, _, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, _ := e.getCurrentInflationSettings(currentTimestamp) + _, maxValidatorStake, minDelegatorStake, _, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, _ := GetCurrentInflationSettings(currentTimestamp, e.Ctx.NetworkID, e.Config) duration := tx.Validator.Duration() switch { diff --git a/avalanchego/vms/platformvm/txs/executor/utils.go b/avalanchego/vms/platformvm/txs/executor/utils.go new file mode 100644 index 00000000..adb07659 --- /dev/null +++ b/avalanchego/vms/platformvm/txs/executor/utils.go @@ -0,0 +1,60 @@ +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.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 + 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 config.MinValidatorStake, + config.MaxValidatorStake, + config.MinDelegatorStake, + config.MinDelegationFee, + config.MinStakeDuration, + config.MaxStakeDuration, + MaxFutureStartTime, + time.Date(1970, time.January, 1, 0, 0, 0, 0, time.UTC) + } +} From c8b1fbe0aa50a831398a72cf442550dd6291c077 Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Wed, 28 Jun 2023 16:57:04 +0200 Subject: [PATCH 2/9] Changed network id param to GetCurrentInflationSettings in proposal_tx_executor --- .../vms/platformvm/txs/executor/proposal_tx_executor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go index b5f5940b..11d34948 100644 --- a/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -79,7 +79,7 @@ func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error { } currentTimestamp := parentState.GetTimestamp() - minValidatorStake, maxValidatorStake, _, minDelegationFee, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, minStakeStartTime := GetCurrentInflationSettings(currentTimestamp, e.Ctx.NetworkID, e.Config) + 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 @@ -381,7 +381,7 @@ func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error { } currentTimestamp := parentState.GetTimestamp() - _, maxValidatorStake, minDelegatorStake, _, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, _ := GetCurrentInflationSettings(currentTimestamp, e.Ctx.NetworkID, e.Config) + _, maxValidatorStake, minDelegatorStake, _, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, _ := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config) duration := tx.Validator.Duration() switch { From 78d2b65a325a8d71560ce845f471b2b12560b563 Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Thu, 3 Aug 2023 22:45:25 +0200 Subject: [PATCH 3/9] Added inflation settings for stage 2 staking --- avalanchego/vms/platformvm/service.go | 2 +- .../{utils.go => inflation_settings.go} | 37 ++++++++++++++++++- .../txs/executor/proposal_tx_executor.go | 7 ++-- 3 files changed, 41 insertions(+), 5 deletions(-) rename avalanchego/vms/platformvm/txs/executor/{utils.go => inflation_settings.go} (56%) diff --git a/avalanchego/vms/platformvm/service.go b/avalanchego/vms/platformvm/service.go index 046f4bde..1c1424d8 100644 --- a/avalanchego/vms/platformvm/service.go +++ b/avalanchego/vms/platformvm/service.go @@ -2146,7 +2146,7 @@ type GetMinStakeReply struct { // GetMinStake returns the minimum staking amount in nAVAX. func (service *Service) GetMinStake(_ *http.Request, _ *struct{}, reply *GetMinStakeReply) error { timestamp := service.vm.state.GetTimestamp() - minValidatorStake, _, minDelegatorStake, _, _, _, _, _ := executor.GetCurrentInflationSettings(timestamp, service.vm.ctx.NetworkID, &service.vm.Config) + 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/utils.go b/avalanchego/vms/platformvm/txs/executor/inflation_settings.go similarity index 56% rename from avalanchego/vms/platformvm/txs/executor/utils.go rename to avalanchego/vms/platformvm/txs/executor/inflation_settings.go index adb07659..30d2629f 100644 --- a/avalanchego/vms/platformvm/txs/executor/utils.go +++ b/avalanchego/vms/platformvm/txs/executor/inflation_settings.go @@ -8,8 +8,21 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/config" ) +var ( + PhaseTwoStakingStartTime = time.Date(2023, time.September, 15, 0, 0, 0, 0, time.UTC) +) + // 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.Time) { +func GetCurrentInflationSettings(currentTimestamp time.Time, networkID uint32, config *config.Config) (uint64, uint64, uint64, uint32, time.Duration, time.Duration, time.Duration, uint64, time.Time) { + switch { + case currentTimestamp.Before(PhaseTwoStakingStartTime): + return getPhaseOneInflationSettings(networkID, config) + default: + return getPhaseTwoInflationSettings(networkID, config) + } +} + +func getPhaseOneInflationSettings(networkID uint32, config *config.Config) (uint64, uint64, uint64, uint32, time.Duration, time.Duration, time.Duration, uint64, time.Time) { switch networkID { case constants.FlareID: return 10 * units.MegaAvax, // minValidatorStake @@ -19,6 +32,7 @@ func GetCurrentInflationSettings(currentTimestamp time.Time, networkID uint32, c 2 * 7 * 24 * time.Hour, // minStakeDuration 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, @@ -28,6 +42,7 @@ func GetCurrentInflationSettings(currentTimestamp time.Time, networkID uint32, c 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, @@ -37,6 +52,7 @@ func GetCurrentInflationSettings(currentTimestamp time.Time, networkID uint32, c 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, @@ -46,6 +62,7 @@ func GetCurrentInflationSettings(currentTimestamp time.Time, networkID uint32, c 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, @@ -55,6 +72,24 @@ func GetCurrentInflationSettings(currentTimestamp time.Time, networkID uint32, c 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, uint64, time.Time) { + switch networkID { + case constants.FlareID: + return 100 * units.KiloAvax, // minValidatorStake + 200 * units.MegaAvax, // maxValidatorStake + 10 * units.KiloAvax, // minDelegatorStake + 0, // minDelegationFee + 2 * 7 * 24 * time.Hour, // minStakeDuration + 365 * 24 * time.Hour, // maxStakeDuration + MaxFutureStartTime, // minFutureStartTimeOffset + 15, // maxValidatorWeightFactor + time.Date(2023, time.July, 5, 15, 0, 0, 0, time.UTC) // minStakeStartTime + 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 11d34948..119bf139 100644 --- a/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -78,8 +78,9 @@ func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error { return state.ErrMissingParentState } currentTimestamp := parentState.GetTimestamp() + e.Ctx.Log.Info("Current timestamp: " + currentTimestamp.String()) - minValidatorStake, maxValidatorStake, _, minDelegationFee, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, minStakeStartTime := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config) + 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 @@ -381,7 +382,7 @@ func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error { } currentTimestamp := parentState.GetTimestamp() - _, maxValidatorStake, minDelegatorStake, _, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, _ := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config) + _, maxValidatorStake, minDelegatorStake, _, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, maxValidatorWeightFactor, _ := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config) duration := tx.Validator.Duration() switch { @@ -428,7 +429,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 } From 789b7eab837bc0b30bcc45f91f88a623c8f05c73 Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Fri, 4 Aug 2023 00:03:03 +0200 Subject: [PATCH 4/9] Changed inflation settings for stage 2 staking --- .../txs/executor/inflation_settings.go | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/avalanchego/vms/platformvm/txs/executor/inflation_settings.go b/avalanchego/vms/platformvm/txs/executor/inflation_settings.go index 30d2629f..473251f1 100644 --- a/avalanchego/vms/platformvm/txs/executor/inflation_settings.go +++ b/avalanchego/vms/platformvm/txs/executor/inflation_settings.go @@ -8,20 +8,27 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/config" ) -var ( - PhaseTwoStakingStartTime = time.Date(2023, time.September, 15, 0, 0, 0, 0, time.UTC) -) - // 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, uint64, time.Time) { switch { - case currentTimestamp.Before(PhaseTwoStakingStartTime): + 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.September, 15, 0, 0, 0, 0, time.UTC) + case constants.CostwoID: + return time.Date(2023, time.August, 15, 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, uint64, time.Time) { switch networkID { case constants.FlareID: @@ -89,6 +96,16 @@ func getPhaseTwoInflationSettings(networkID uint32, config *config.Config) (uint MaxFutureStartTime, // minFutureStartTimeOffset 15, // maxValidatorWeightFactor time.Date(2023, time.July, 5, 15, 0, 0, 0, time.UTC) // minStakeStartTime + case constants.CostwoID: + return 100 * units.KiloAvax, + 200 * units.MegaAvax, + 10 * units.KiloAvax, + 0, + 2 * 7 * 24 * time.Hour, + 365 * 24 * time.Hour, + MaxFutureStartTime, + 15, + time.Date(2023, time.May, 25, 15, 0, 0, 0, time.UTC) default: return getPhaseOneInflationSettings(networkID, config) } From de80c32c1ce2aadfbafa7e2ecd05f9c3c06d4010 Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Mon, 21 Aug 2023 23:25:12 +0200 Subject: [PATCH 5/9] Changed phase 2 staking parameters --- avalanchego/vms/platformvm/service.go | 4 +-- .../txs/executor/inflation_settings.go | 27 ++++++++++++------- .../txs/executor/proposal_tx_executor.go | 8 +++--- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/avalanchego/vms/platformvm/service.go b/avalanchego/vms/platformvm/service.go index 1c1424d8..bd9e0d3e 100644 --- a/avalanchego/vms/platformvm/service.go +++ b/avalanchego/vms/platformvm/service.go @@ -2145,8 +2145,8 @@ type GetMinStakeReply struct { // GetMinStake returns the minimum staking amount in nAVAX. func (service *Service) GetMinStake(_ *http.Request, _ *struct{}, reply *GetMinStakeReply) error { - timestamp := service.vm.state.GetTimestamp() - minValidatorStake, _, minDelegatorStake, _, _, _, _, _, _ := executor.GetCurrentInflationSettings(timestamp, service.vm.ctx.NetworkID, &service.vm.Config) + now := service.vm.clock.Time() + minValidatorStake, _, minDelegatorStake, _, _, _, _, _, _, _ := executor.GetCurrentInflationSettings(now, 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 index 473251f1..42c359e8 100644 --- a/avalanchego/vms/platformvm/txs/executor/inflation_settings.go +++ b/avalanchego/vms/platformvm/txs/executor/inflation_settings.go @@ -9,7 +9,7 @@ import ( ) // 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, uint64, time.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) @@ -29,7 +29,7 @@ func getPhaseTwoStakingStartTime(networkID uint32) time.Time { } } -func getPhaseOneInflationSettings(networkID uint32, config *config.Config) (uint64, uint64, uint64, uint32, time.Duration, time.Duration, time.Duration, uint64, time.Time) { +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 @@ -37,6 +37,7 @@ func getPhaseOneInflationSettings(networkID uint32, config *config.Config) (uint 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 @@ -47,6 +48,7 @@ func getPhaseOneInflationSettings(networkID uint32, config *config.Config) (uint 1 * units.KiloAvax, 0, 2 * 7 * 24 * time.Hour, + 2 * 7 * 24 * time.Hour, 365 * 24 * time.Hour, MaxFutureStartTime, MaxValidatorWeightFactor, @@ -57,6 +59,7 @@ func getPhaseOneInflationSettings(networkID uint32, config *config.Config) (uint 1 * units.KiloAvax, 0, 2 * 7 * 24 * time.Hour, + 2 * 7 * 24 * time.Hour, 365 * 24 * time.Hour, MaxFutureStartTime, MaxValidatorWeightFactor, @@ -67,6 +70,7 @@ func getPhaseOneInflationSettings(networkID uint32, config *config.Config) (uint 10 * units.KiloAvax, 0, 2 * 7 * 24 * time.Hour, + 2 * 7 * 24 * time.Hour, 365 * 24 * time.Hour, 24 * time.Hour, MaxValidatorWeightFactor, @@ -77,6 +81,7 @@ func getPhaseOneInflationSettings(networkID uint32, config *config.Config) (uint config.MinDelegatorStake, config.MinDelegationFee, config.MinStakeDuration, + config.MinStakeDuration, config.MaxStakeDuration, MaxFutureStartTime, MaxValidatorWeightFactor, @@ -84,28 +89,30 @@ func getPhaseOneInflationSettings(networkID uint32, config *config.Config) (uint } } -func getPhaseTwoInflationSettings(networkID uint32, config *config.Config) (uint64, uint64, uint64, uint32, time.Duration, time.Duration, time.Duration, uint64, time.Time) { +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 100 * units.KiloAvax, // minValidatorStake + return 1 * units.MegaAvax, // minValidatorStake 200 * units.MegaAvax, // maxValidatorStake - 10 * units.KiloAvax, // minDelegatorStake + 50 * units.KiloAvax, // minDelegatorStake 0, // minDelegationFee - 2 * 7 * 24 * time.Hour, // minStakeDuration + 60 * 24 * time.Hour, // minStakeDuration + 2 * 7 * 24 * time.Hour, // minDelegateDuration 365 * 24 * time.Hour, // maxStakeDuration MaxFutureStartTime, // minFutureStartTimeOffset 15, // maxValidatorWeightFactor - time.Date(2023, time.July, 5, 15, 0, 0, 0, time.UTC) // minStakeStartTime + time.Date(2023, time.September, 15, 0, 0, 0, 0, time.UTC) // minStakeStartTime case constants.CostwoID: - return 100 * units.KiloAvax, + return 1 * units.MegaAvax, 200 * units.MegaAvax, - 10 * units.KiloAvax, + 50 * units.KiloAvax, 0, + 60 * 24 * time.Hour, 2 * 7 * 24 * time.Hour, 365 * 24 * time.Hour, MaxFutureStartTime, 15, - time.Date(2023, time.May, 25, 15, 0, 0, 0, time.UTC) + time.Date(2023, time.August, 15, 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 119bf139..b4e30ace 100644 --- a/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -78,9 +78,9 @@ func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error { return state.ErrMissingParentState } currentTimestamp := parentState.GetTimestamp() - e.Ctx.Log.Info("Current timestamp: " + currentTimestamp.String()) + now := e.Clk.Time() - minValidatorStake, maxValidatorStake, _, minDelegationFee, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, _, minStakeStartTime := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config) + minValidatorStake, maxValidatorStake, _, minDelegationFee, minStakeDuration, _, maxStakeDuration, minFutureStartTimeOffset, _, minStakeStartTime := GetCurrentInflationSettings(now, e.Backend.Ctx.NetworkID, e.Config) switch { case tx.Validator.Wght < minValidatorStake: // Ensure validator is staking at least the minimum amount @@ -382,11 +382,11 @@ func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error { } currentTimestamp := parentState.GetTimestamp() - _, maxValidatorStake, minDelegatorStake, _, minStakeDuration, maxStakeDuration, minFutureStartTimeOffset, maxValidatorWeightFactor, _ := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config) + _, 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 From d4341e1b393c9a21e22e76a72ee9abd439328461 Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Mon, 21 Aug 2023 23:32:41 +0200 Subject: [PATCH 6/9] Changed current time for delegator tx --- .../vms/platformvm/txs/executor/proposal_tx_executor.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go index b4e30ace..9922cb60 100644 --- a/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -381,8 +381,9 @@ func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error { return state.ErrMissingParentState } currentTimestamp := parentState.GetTimestamp() + now := e.Clk.Time() - _, maxValidatorStake, minDelegatorStake, _, _, minDelegateDuration, maxStakeDuration, minFutureStartTimeOffset, maxValidatorWeightFactor, _ := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config) + _, maxValidatorStake, minDelegatorStake, _, _, minDelegateDuration, maxStakeDuration, minFutureStartTimeOffset, maxValidatorWeightFactor, _ := GetCurrentInflationSettings(now, e.Backend.Ctx.NetworkID, e.Config) duration := tx.Validator.Duration() switch { From 8da4310dfe39d9480046b05cccdee59836a7703a Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Tue, 22 Aug 2023 15:26:37 +0200 Subject: [PATCH 7/9] Comparison with getTimestamp instead of now --- avalanchego/vms/platformvm/service.go | 4 ++-- .../vms/platformvm/txs/executor/proposal_tx_executor.go | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/avalanchego/vms/platformvm/service.go b/avalanchego/vms/platformvm/service.go index bd9e0d3e..d09bb822 100644 --- a/avalanchego/vms/platformvm/service.go +++ b/avalanchego/vms/platformvm/service.go @@ -2145,8 +2145,8 @@ type GetMinStakeReply struct { // GetMinStake returns the minimum staking amount in nAVAX. func (service *Service) GetMinStake(_ *http.Request, _ *struct{}, reply *GetMinStakeReply) error { - now := service.vm.clock.Time() - minValidatorStake, _, minDelegatorStake, _, _, _, _, _, _, _ := executor.GetCurrentInflationSettings(now, service.vm.ctx.NetworkID, &service.vm.Config) + 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/proposal_tx_executor.go b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go index 9922cb60..dfec5efd 100644 --- a/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/avalanchego/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -78,9 +78,8 @@ func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error { return state.ErrMissingParentState } currentTimestamp := parentState.GetTimestamp() - now := e.Clk.Time() - minValidatorStake, maxValidatorStake, _, minDelegationFee, minStakeDuration, _, maxStakeDuration, minFutureStartTimeOffset, _, minStakeStartTime := GetCurrentInflationSettings(now, e.Backend.Ctx.NetworkID, e.Config) + 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 @@ -381,9 +380,8 @@ func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error { return state.ErrMissingParentState } currentTimestamp := parentState.GetTimestamp() - now := e.Clk.Time() - _, maxValidatorStake, minDelegatorStake, _, _, minDelegateDuration, maxStakeDuration, minFutureStartTimeOffset, maxValidatorWeightFactor, _ := GetCurrentInflationSettings(now, e.Backend.Ctx.NetworkID, e.Config) + _, maxValidatorStake, minDelegatorStake, _, _, minDelegateDuration, maxStakeDuration, minFutureStartTimeOffset, maxValidatorWeightFactor, _ := GetCurrentInflationSettings(currentTimestamp, e.Backend.Ctx.NetworkID, e.Config) duration := tx.Validator.Duration() switch { From 7019b2880c98dd05eb1a07f4e5a43fa3b1ffbeb1 Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Mon, 28 Aug 2023 19:36:04 +0200 Subject: [PATCH 8/9] Changed phase 2 staking start times --- .../vms/platformvm/txs/executor/inflation_settings.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/avalanchego/vms/platformvm/txs/executor/inflation_settings.go b/avalanchego/vms/platformvm/txs/executor/inflation_settings.go index 42c359e8..16b2a5f6 100644 --- a/avalanchego/vms/platformvm/txs/executor/inflation_settings.go +++ b/avalanchego/vms/platformvm/txs/executor/inflation_settings.go @@ -21,9 +21,9 @@ func GetCurrentInflationSettings(currentTimestamp time.Time, networkID uint32, c func getPhaseTwoStakingStartTime(networkID uint32) time.Time { switch networkID { case constants.FlareID: - return time.Date(2023, time.September, 15, 0, 0, 0, 0, time.UTC) + return time.Date(2023, time.October, 1, 0, 0, 0, 0, time.UTC) case constants.CostwoID: - return time.Date(2023, time.August, 15, 0, 0, 0, 0, time.UTC) + 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) } @@ -101,7 +101,7 @@ func getPhaseTwoInflationSettings(networkID uint32, config *config.Config) (uint 365 * 24 * time.Hour, // maxStakeDuration MaxFutureStartTime, // minFutureStartTimeOffset 15, // maxValidatorWeightFactor - time.Date(2023, time.September, 15, 0, 0, 0, 0, time.UTC) // minStakeStartTime + time.Date(2023, time.October, 1, 0, 0, 0, 0, time.UTC) // minStakeStartTime case constants.CostwoID: return 1 * units.MegaAvax, 200 * units.MegaAvax, @@ -112,7 +112,7 @@ func getPhaseTwoInflationSettings(networkID uint32, config *config.Config) (uint 365 * 24 * time.Hour, MaxFutureStartTime, 15, - time.Date(2023, time.August, 15, 0, 0, 0, 0, time.UTC) + time.Date(2023, time.September, 7, 0, 0, 0, 0, time.UTC) default: return getPhaseOneInflationSettings(networkID, config) } From 95c0767f5a4968cee5890638291f4bcb3f9bb00f Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Mon, 28 Aug 2023 20:35:09 +0200 Subject: [PATCH 9/9] Bumped version to 1806 --- avalanchego/version/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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,