Skip to content

Commit

Permalink
fix: revert immediate sidechain undelegation and handle undelegation …
Browse files Browse the repository at this point in the history
…in endblock (#365)
  • Loading branch information
j75689 authored Jan 4, 2024
1 parent fdcabf6 commit 9e0aa25
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
16 changes: 3 additions & 13 deletions x/stake/cross_stake/cross_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,9 @@ func (app *CrossStakeApp) handleUndelegate(ctx sdk.Context, pack *types.CrossSta
}, errCode, nil
}

if sdk.IsUpgrade(sdk.FirstSunsetFork) {
// unbound the delegation directly, do not wait for the breathe block
// this is to prevent too many user get the coins back in the breathe block

_, _, err := app.stakeKeeper.UnboundDelegation(ctx.WithCrossStake(true), delAddr, pack.Validator, shares)
if err != nil {
return sdk.ExecuteResult{}, errCode, err
}
} else {
_, err := app.stakeKeeper.BeginUnbonding(ctx.WithCrossStake(true), delAddr, pack.Validator, shares, true)
if err != nil {
return sdk.ExecuteResult{}, errCode, err
}
_, err := app.stakeKeeper.BeginUnbonding(ctx.WithCrossStake(true), delAddr, pack.Validator, shares, true)
if err != nil {
return sdk.ExecuteResult{}, errCode, err
}

// publish undelegate event
Expand Down
9 changes: 9 additions & 0 deletions x/stake/endblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) (validatorUpdates []abci.Valid
}
}

if len(storePrefixes) > 0 && sdk.IsUpgrade(sdk.FirstSunsetFork) {
for i := range storePrefixes {
sideChainCtx := ctx.WithSideChainKeyPrefix(storePrefixes[i])
_, unBoundedEvents := handleMatureUnbondingDelegations(k, sideChainCtx)

events = append(events, unBoundedEvents...)
}
}

if sdk.IsUpgrade(sdk.BEP153) {
events = events.AppendEvents(csEvents)
}
Expand Down
16 changes: 3 additions & 13 deletions x/stake/handler_sidechain.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,9 @@ func handleMsgSideChainUndelegate(ctx sdk.Context, msg MsgSideChainUndelegate, k
events sdk.Events
)

if sdk.IsUpgrade(sdk.FirstSunsetFork) {
// unbound the delegation directly, do not wait for the breathe block
// this is to prevent too many user get the coins back in the breathe block

ubd, events, err = k.UnboundDelegation(ctx, msg.DelegatorAddr, msg.ValidatorAddr, shares)
if err != nil {
return err.Result()
}
} else {
ubd, err = k.BeginUnbonding(ctx, msg.DelegatorAddr, msg.ValidatorAddr, shares, true)
if err != nil {
return err.Result()
}
ubd, err = k.BeginUnbonding(ctx, msg.DelegatorAddr, msg.ValidatorAddr, shares, true)
if err != nil {
return err.Result()
}

finishTime := types.MsgCdc.MustMarshalBinaryLengthPrefixed(ubd.MinTime)
Expand Down

0 comments on commit 9e0aa25

Please sign in to comment.