-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add RewardsPerSecond param to community * Update rewards per second param to int * Add rewards_per_second to protonet genesis * Use default rewards per second of 744191 * Include value if negative in Validate error * Rename RewardsPerSecond param to StakingRewardsPerSecond * Add changelog entry * Add param migration, update consensus version to 2 * Update proto docs
- Loading branch information
Showing
14 changed files
with
309 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
v2 "github.com/kava-labs/kava/x/community/migrations/v2" | ||
) | ||
|
||
// Migrator is a struct for handling in-place store migrations. | ||
type Migrator struct { | ||
keeper Keeper | ||
} | ||
|
||
// NewMigrator returns a new Migrator. | ||
func NewMigrator(keeper Keeper) Migrator { | ||
return Migrator{ | ||
keeper: keeper, | ||
} | ||
} | ||
|
||
// Migrate1to2 migrates from version 1 to 2. | ||
func (m Migrator) Migrate1to2(ctx sdk.Context) error { | ||
return v2.Migrate( | ||
ctx, | ||
ctx.KVStore(m.keeper.key), | ||
m.keeper.cdc, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package v2 | ||
|
||
import ( | ||
"time" | ||
|
||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/kava-labs/kava/x/community/types" | ||
) | ||
|
||
const ( | ||
ModuleName = "mint" | ||
) | ||
|
||
// Migrate migrates the x/community module state from the consensus version 1 to | ||
// version 2. Specifically, sets new parameters in the module state. | ||
func Migrate( | ||
ctx sdk.Context, | ||
store storetypes.KVStore, | ||
cdc codec.BinaryCodec, | ||
) error { | ||
params := types.NewParams( | ||
// 2023-11-01T00:00:00Z | ||
time.Date(2023, 11, 1, 0, 0, 0, 0, time.UTC), | ||
sdk.NewInt(744191), | ||
) | ||
|
||
if err := params.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
bz := cdc.MustMarshal(¶ms) | ||
store.Set(types.ParamsKey, bz) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package v2_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/testutil" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/kava-labs/kava/app" | ||
v2 "github.com/kava-labs/kava/x/community/migrations/v2" | ||
"github.com/kava-labs/kava/x/community/types" | ||
) | ||
|
||
func TestMigrateStore(t *testing.T) { | ||
tApp := app.NewTestApp() | ||
cdc := tApp.AppCodec() | ||
storeKey := sdk.NewKVStoreKey("community") | ||
ctx := testutil.DefaultContext(storeKey, sdk.NewTransientStoreKey("transient_test")) | ||
store := ctx.KVStore(storeKey) | ||
|
||
require.Nil( | ||
t, | ||
store.Get(types.ParamsKey), | ||
"params shouldn't exist in store before migration", | ||
) | ||
|
||
require.NoError(t, v2.Migrate(ctx, store, cdc)) | ||
|
||
paramsBytes := store.Get(types.ParamsKey) | ||
require.NotNil(t, paramsBytes, "params should be in store after migration") | ||
|
||
var params types.Params | ||
cdc.MustUnmarshal(paramsBytes, ¶ms) | ||
|
||
t.Logf("params: %+v", params) | ||
|
||
require.Equal( | ||
t, | ||
types.NewParams( | ||
time.Date(2023, 11, 1, 0, 0, 0, 0, time.UTC), | ||
sdk.NewInt(744191), | ||
), | ||
params, | ||
"params should be correct after migration", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,47 @@ | ||
package types | ||
|
||
import "time" | ||
import ( | ||
"errors" | ||
fmt "fmt" | ||
"time" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
) | ||
|
||
var ( | ||
DefaultUpgradeTimeDisableInflation = time.Time{} | ||
// DefaultStakingRewardsPerSecond is ~4.6 KAVA per block, 6.3s block time | ||
DefaultStakingRewardsPerSecond = sdkmath.NewInt(744191) | ||
) | ||
|
||
// NewParams returns a new params object | ||
func NewParams(upgradeTime time.Time) Params { | ||
func NewParams( | ||
upgradeTime time.Time, | ||
stakingRewardsPerSecond sdkmath.Int, | ||
) Params { | ||
return Params{ | ||
UpgradeTimeDisableInflation: upgradeTime, | ||
StakingRewardsPerSecond: stakingRewardsPerSecond, | ||
} | ||
} | ||
|
||
// DefaultParams returns default params | ||
func DefaultParams() Params { | ||
return NewParams( | ||
DefaultUpgradeTimeDisableInflation, | ||
DefaultStakingRewardsPerSecond, | ||
) | ||
} | ||
|
||
// Validate checks the params are valid | ||
func (p Params) Validate() error { | ||
if p.StakingRewardsPerSecond.IsNil() { | ||
return errors.New("StakingRewardsPerSecond should not be nil") | ||
} | ||
|
||
if p.StakingRewardsPerSecond.IsNegative() { | ||
return fmt.Errorf("StakingRewardsPerSecond should not be negative: %s", p.StakingRewardsPerSecond) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.