Skip to content

Commit

Permalink
fix: add logs to sunset fork events and avoid to many delegation unbo…
Browse files Browse the repository at this point in the history
…und in a day
  • Loading branch information
j75689 committed Jan 2, 2024
1 parent 2b34b1a commit 4debe28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion x/ibc/endblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func closeChannelOnSideChanAndKeeper(ctx sdk.Context, k Keeper,
var events sdk.Events
_, err := k.sideKeeper.SaveChannelSettingChangeToIbc(ctx, destChainID, channelID, sdk.ChannelForbidden)
if err != nil {
ctx.Logger().Error("failed to save ibc channel change", "err", err.Error())
ctx.Logger().Error("failed to save ibc channel change after FinalSunsetFork",
"sideChainId", destChainID, "channelId", channelID, "err", err.Error())
events.AppendEvent(sdk.NewEvent(EventTypeSaveIBCChannelSettingFailed,
sdk.NewAttribute(AttributeKeySideChainId, fmt.Sprint(destChainID)),
sdk.NewAttribute(AttributeKeyChannelId, fmt.Sprint(channelID)),
Expand All @@ -77,5 +78,7 @@ func closeChannelOnSideChanAndKeeper(ctx sdk.Context, k Keeper,
))
// close bc side chain channel
k.sideKeeper.SetChannelSendPermission(ctx, destChainID, channelID, sdk.ChannelForbidden)

ctx.Logger().Info("close side chain channel after FinalSunsetFork", "sideChainId", destChainID, "channelId", channelID)
return events
}
16 changes: 15 additions & 1 deletion x/stake/endblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func handleMatureUnbondingDelegations(k keeper.Keeper, ctx sdk.Context) ([]types

const (
maxProcessedRefundCount = 10
maxUnboundPerDay = 100
)

func handleRefundStake(ctx sdk.Context, sideChainPrefix []byte, k keeper.Keeper) sdk.Events {
Expand All @@ -281,19 +282,32 @@ func handleRefundStake(ctx sdk.Context, sideChainPrefix []byte, k keeper.Keeper)
count := 0
boundDenom := k.BondDenom(sideChainCtx)

unBoundingDelegation := k.DequeueAllMatureUnbondingQueue(sideChainCtx, ctx.BlockHeader().Time)
if len(unBoundingDelegation) >= maxUnboundPerDay {
ctx.Logger().Info("unBoundingDelegation exceed the maxUnboundPerDay")
return refundEvents
}

for ; iterator.Valid(); iterator.Next() {
delegation := types.MustUnmarshalDelegation(k.CDC(), iterator.Key(), iterator.Value())
if delegation.CrossStake {
ctx = ctx.WithCrossStake(true)
}
bscSideChainId := k.ScKeeper.BscSideChainId(ctx)
result := handleMsgSideChainUndelegate(ctx, types.MsgSideChainUndelegate{
DelegatorAddr: delegation.DelegatorAddr,
ValidatorAddr: delegation.ValidatorAddr,
Amount: sdk.NewCoin(boundDenom, delegation.GetShares().RawInt()),
SideChainId: k.ScKeeper.BscSideChainId(ctx),
SideChainId: bscSideChainId,
}, k)
refundEvents = refundEvents.AppendEvents(result.Events)

ctx.Logger().Info("handleRefundStake after SecondSunsetFork",
"delegator", delegation.DelegatorAddr.String(),
"validator", delegation.ValidatorAddr.String(),
"amount", delegation.GetShares().String(),
"sideChainId", bscSideChainId,
)
count++
if count >= maxProcessedRefundCount {
break
Expand Down

0 comments on commit 4debe28

Please sign in to comment.