Skip to content

Commit

Permalink
update parameter migration script to keep old brokerAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
jelysn committed May 14, 2024
1 parent 0ea34fb commit aa7e0fa
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 28 deletions.
18 changes: 18 additions & 0 deletions proto/elys/parameter/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,21 @@ message Params {
string broker_address = 4;
int64 total_blocks_per_year = 5;
}

message LegacyParams {
option (gogoproto.goproto_stringer) = false;

string min_commission_rate = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string max_voting_power = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string min_self_delegation = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string broker_address = 4;
}
13 changes: 13 additions & 0 deletions x/parameter/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,16 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
b := k.cdc.MustMarshal(&params)
store.Set([]byte(types.ParamsKey), b)
}

// GetParams get all parameters as types.Params
func (k Keeper) GetLegacyParams(ctx sdk.Context) (params types.LegacyParams) {
store := ctx.KVStore(k.storeKey)

b := store.Get([]byte(types.ParamsKey))
if b == nil {
return
}

k.cdc.MustUnmarshal(b, &params)
return
}
11 changes: 6 additions & 5 deletions x/parameter/migrations/v3_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (

func (m Migrator) V3Migration(ctx sdk.Context) error {
// reset params
legacy := m.keeper.GetLegacyParams(ctx)
params := types.NewParams(
sdk.NewDecWithPrec(5, 2), // min commission 0.05
sdk.NewDecWithPrec(66, 2), // max voting power 0.66
sdk.NewInt(1), // min self delegation
"elys1m3hduhk4uzxn8mxuvpz02ysndxfwgy5mq60h4c34qqn67xud584qeee3m4", // broker address
6307200, // total blocks per year
legacy.MinCommissionRate, // min commission 0.05
legacy.MaxVotingPower, // max voting power 0.66
legacy.MinSelfDelegation, // min self delegation
legacy.BrokerAddress, // broker address
6307200, // total blocks per year
)
m.keeper.SetParams(ctx, params)

Expand Down
6 changes: 6 additions & 0 deletions x/parameter/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,9 @@ func validateBrokerAddress(i interface{}) error {
}
return nil
}

// String implements the Stringer interface.
func (p LegacyParams) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
Loading

0 comments on commit aa7e0fa

Please sign in to comment.