Skip to content

Commit

Permalink
fix: CrossStakeDistributeUndelegatedSynPackageV2
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jan 12, 2024
1 parent d9499f0 commit 7a71634
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
8 changes: 8 additions & 0 deletions x/stake/cross_stake/cross_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ func (app *CrossStakeApp) ExecuteFailAckPackage(ctx sdk.Context, payload []byte)
Recipient: p.Recipient,
}
result, err = app.handleDistributeUndelegatedRefund(ctx, refundPackage)
case *types.CrossStakeDistributeUndelegatedSynPackageV2:
bcAmount := bsc.ConvertBSCAmountToBCAmount(p.Amount)
refundPackage := &types.CrossStakeRefundPackage{
EventType: types.CrossStakeTypeDistributeUndelegated,
Amount: big.NewInt(bcAmount),
Recipient: p.Recipient,
}
result, err = app.handleDistributeUndelegatedRefund(ctx, refundPackage)
default:
app.stakeKeeper.Logger(ctx).Error("unknown cross stake fail ack event type", "err", err.Error(), "package", string(payload))
return sdk.ExecuteResult{}
Expand Down
11 changes: 11 additions & 0 deletions x/stake/cross_stake/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ func DeserializeCrossStakeFailAckPackage(serializedPackage []byte) (interface{},
}
return &pack, nil
},
func(serializedPackage []byte) (interface{}, error) {
var pack types.CrossStakeDistributeUndelegatedSynPackageV2
err := rlp.DecodeBytes(serializedPackage, &pack)
if err != nil {
return nil, err
}
if pack.EventType != types.CrossStakeTypeDistributeUndelegated {
return nil, fmt.Errorf("wrong cross stake event type")
}
return &pack, nil
},
}

var pack interface{}
Expand Down
24 changes: 16 additions & 8 deletions x/stake/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,14 +889,22 @@ func (k Keeper) crossDistributeUndelegated(ctx sdk.Context, delAddr sdk.AccAddre
return sdk.Events{}, sdk.ErrInternal(err.Error())
}

transferPackage := types.CrossStakeDistributeUndelegatedSynPackage{
EventType: types.CrossStakeTypeDistributeUndelegated,
Amount: bscTransferAmount,
Recipient: recipient,
Validator: valAddr,
}
if sdk.IsUpgrade(sdk.SecondSunsetFork) {
transferPackage.IsAutoUnDelegate = k.IsAutoUnDelegate(ctx, delAddr, valAddr)
var transferPackage interface{}
if !sdk.IsUpgrade(sdk.SecondSunsetFork) {
transferPackage = types.CrossStakeDistributeUndelegatedSynPackage{
EventType: types.CrossStakeTypeDistributeUndelegated,
Amount: bscTransferAmount,
Recipient: recipient,
Validator: valAddr,
}
} else {
transferPackage = types.CrossStakeDistributeUndelegatedSynPackageV2{
EventType: types.CrossStakeTypeDistributeUndelegated,
Amount: bscTransferAmount,
Recipient: recipient,
Validator: valAddr,
IsAutoUnDelegate: k.IsAutoUnDelegate(ctx, delAddr, valAddr),
}
}

encodedPackage, err := rlp.EncodeToBytes(transferPackage)
Expand Down
7 changes: 7 additions & 0 deletions x/stake/types/cross_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ type CrossStakeDistributeRewardSynPackage struct {
}

type CrossStakeDistributeUndelegatedSynPackage struct {
EventType CrossStakeEventType
Recipient sdk.SmartChainAddress
Validator sdk.ValAddress
Amount *big.Int
}

type CrossStakeDistributeUndelegatedSynPackageV2 struct {
EventType CrossStakeEventType
Recipient sdk.SmartChainAddress
Validator sdk.ValAddress
Expand Down

0 comments on commit 7a71634

Please sign in to comment.