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

bug: fix invalid accumulation time genesis validation #1550

Merged
merged 4 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [#1477] Remove legacy REST endpoints.
- [#1519] Remove required denom path parameter from hard grpc query endpoints.

### Bug Fixes

- (x/incentive) [#1550] Increase earliest valid accumulation time to 5 years ago.

## [v0.16.1]

### State Machine Breaking
Expand Down
2 changes: 1 addition & 1 deletion x/incentive/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const year = 365 * 24 * time.Hour

// EarliestValidAccumulationTime is how far behind the genesis time an accumulation time can be for it to be valid.
// It's a safety check to ensure rewards aren't accidentally accumulated for many years on the first block (eg since Jan 1970).
var EarliestValidAccumulationTime time.Duration = year
var EarliestValidAccumulationTime time.Duration = 5 * year
pirtleshell marked this conversation as resolved.
Show resolved Hide resolved

// InitGenesis initializes the store state from a genesis state.
func InitGenesis(
Expand Down
6 changes: 3 additions & 3 deletions x/incentive/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,13 @@ func (suite *GenesisTestSuite) TestExportedGenesisMatchesImported() {
suite.Equal(genesisState, exportedGenesisState)
}

func (suite *GenesisTestSuite) TestInitGenesisPanicsWhenAccumulationTimesToLongAgo() {
func (suite *GenesisTestSuite) TestInitGenesisPanicsWhenAccumulationTimesTooLongAgo() {
genesisTime := time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)
invalidRewardState := types.NewGenesisRewardState(
types.AccumulationTimes{
types.NewAccumulationTime(
"bnb",
genesisTime.Add(-23*incentive.EarliestValidAccumulationTime).Add(-time.Nanosecond),
genesisTime.Add(-4*incentive.EarliestValidAccumulationTime).Add(-time.Nanosecond),
pirtleshell marked this conversation as resolved.
Show resolved Hide resolved
),
},
types.MultiRewardIndexes{},
Expand Down Expand Up @@ -373,7 +373,7 @@ func (suite *GenesisTestSuite) TestInitGenesisPanicsWhenAccumulationTimesToLongA
)

suite.PanicsWithValue(
"found accumulation time '1975-01-06 23:59:59.999999999 +0000 UTC' more than '8760h0m0s' behind genesis time '1998-01-01 00:00:00 +0000 UTC'",
"found accumulation time '1978-01-05 23:59:59.999999999 +0000 UTC' more than '43800h0m0s' behind genesis time '1998-01-01 00:00:00 +0000 UTC'",
func() {
incentive.InitGenesis(
ctx, tApp.GetIncentiveKeeper(),
Expand Down