Skip to content

Commit

Permalink
add migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
omerlavanet committed Dec 4, 2024
1 parent 8f3ee81 commit b7d4c6a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion proto/lavanet/lava/dualstaking/delegate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ message Delegation {
string provider = 1; // provider receives the delegated funds
string delegator = 3; // delegator that owns the delegated funds
cosmos.base.v1beta1.Coin amount = 4 [(gogoproto.nullable) = false];
int64 timestamp = 5; // Unix timestamp of the delegation (+ month)
int64 timestamp = 5; // Unix timestamp of the last change
cosmos.base.v1beta1.Coin credit = 6 [(gogoproto.nullable) = false]; // amount of credit earned by the delegation over the period
int64 credit_timestamp = 7; // Unix timestamp of the delegation credit start
}
Expand Down
13 changes: 13 additions & 0 deletions x/dualstaking/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,16 @@ func (m Migrator) MigrateVersion5To6(ctx sdk.Context) error {

return nil
}

func (m Migrator) MigrateVersion6To7(ctx sdk.Context) error {
// set all delegations to have a timestamp of 30 days ago
allDelegations, err := m.keeper.GetAllDelegations(ctx)
if err != nil {
for _, delegation := range allDelegations {
delegation.Timestamp = ctx.BlockTime().AddDate(0, 0, -30).UTC().Unix()
m.keeper.SetDelegation(ctx, delegation)
}
}

return nil
}
6 changes: 5 additions & 1 deletion x/dualstaking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
// panic:ok: at start up, migration cannot proceed anyhow
panic(fmt.Errorf("%s: failed to register migration to v5: %w", types.ModuleName, err))
}
if err := cfg.RegisterMigration(types.ModuleName, 6, migrator.MigrateVersion6To7); err != nil {
// panic:ok: at start up, migration cannot proceed anyhow
panic(fmt.Errorf("%s: failed to register migration to v5: %w", types.ModuleName, err))
}
}

// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted)
Expand All @@ -146,7 +150,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1
func (AppModule) ConsensusVersion() uint64 { return 6 }
func (AppModule) ConsensusVersion() uint64 { return 7 }

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
Expand Down

0 comments on commit b7d4c6a

Please sign in to comment.