Skip to content
Snippets Groups Projects
Commit dde9f3aa authored by Eridanus (9R)'s avatar Eridanus (9R) Committed by Pluto (9R)
Browse files

Eridanus/fix requeue dangling action

parent 8f2c4b03
No related branches found
No related tags found
Loading
Pipeline #1057102080 passed
......@@ -178,6 +178,93 @@ func refundDroppedSwapOutFromRUNEV106(ctx cosmos.Context, mgr *Mgrs, droppedTx D
return nil
}
// When an ObservedTxInVoter has dangling Actions items swallowed by the vaults, requeue
// them. This updates the func to the original func (requeueDanglingActionsV108) the
// voter.OutboundHeight should be set so that the outbound is not considered "expired",
// which causes the nodes to be slashed and requeed outbound to remain in the outbound
// queue. Reference:
// https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/handler_common_outbound.go?ref_type=heads#L97-105
// trunk-ignore(golangci-lint/deadcode)
func requeueDanglingActionsV124(ctx cosmos.Context, mgr *Mgrs, txIDs []common.TxID) {
// Select the least secure ActiveVault Asgard for all outbounds.
// Even if it fails (as in if the version changed upon the keygens-complete block of a churn),
// updating the voter's FinalisedHeight allows another MaxOutboundAttempts for LackSigning vault selection.
activeAsgards, err := mgr.Keeper().GetAsgardVaultsByStatus(ctx, ActiveVault)
if err != nil || len(activeAsgards) == 0 {
ctx.Logger().Error("fail to get active asgard vaults", "error", err)
return
}
if len(activeAsgards) > 1 {
signingTransactionPeriod := mgr.GetConstants().GetInt64Value(constants.SigningTransactionPeriod)
activeAsgards = mgr.Keeper().SortBySecurity(ctx, activeAsgards, signingTransactionPeriod)
}
vaultPubKey := activeAsgards[0].PubKey
for _, txID := range txIDs {
voter, err := mgr.Keeper().GetObservedTxInVoter(ctx, txID)
if err != nil {
ctx.Logger().Error("fail to get observed tx voter", "error", err)
continue
}
if len(voter.OutTxs) >= len(voter.Actions) {
log := fmt.Sprintf("(%d) OutTxs present for (%s), despite expecting fewer than the (%d) Actions.", len(voter.OutTxs), txID.String(), len(voter.Actions))
ctx.Logger().Debug(log)
continue
}
var indices []int
for i := range voter.Actions {
if isActionsItemDangling(voter, i) {
indices = append(indices, i)
}
}
if len(indices) == 0 {
log := fmt.Sprintf("No dangling Actions item found for (%s)", txID.String())
ctx.Logger().Debug(log)
continue
}
if len(voter.Actions)-len(voter.OutTxs) != len(indices) {
log := fmt.Sprintf("(%d) Actions and (%d) OutTxs present for (%s), yet there appeared to be (%d) dangling Actions.", len(voter.Actions), len(voter.OutTxs), txID.String(), len(indices))
ctx.Logger().Debug(log)
continue
}
// Update the voter's FinalisedHeight to give another MaxOutboundAttempts.
voter.FinalisedHeight = ctx.BlockHeight()
voter.OutboundHeight = ctx.BlockHeight()
for _, index := range indices {
// Use a pointer to update the voter as well.
actionItem := &voter.Actions[index]
// Update the vault pubkey.
actionItem.VaultPubKey = vaultPubKey
// Update the Actions item's MaxGas and GasRate.
// Note that nothing in this function should require a GasManager BeginBlock.
gasCoin, err := mgr.GasMgr().GetMaxGas(ctx, actionItem.Chain)
if err != nil {
ctx.Logger().Error("fail to get max gas", "chain", actionItem.Chain, "error", err)
continue
}
actionItem.MaxGas = common.Gas{gasCoin}
actionItem.GasRate = int64(mgr.GasMgr().GetGasRate(ctx, actionItem.Chain).Uint64())
// UnSafeAddTxOutItem is used to queue the txout item directly, without for instance deducting another fee.
err = mgr.TxOutStore().UnSafeAddTxOutItem(ctx, mgr, *actionItem)
if err != nil {
ctx.Logger().Error("fail to add outbound tx", "error", err)
continue
}
}
// Having requeued all dangling Actions items, set the updated voter.
mgr.Keeper().SetObservedTxInVoter(ctx, voter)
}
}
// When an ObservedTxInVoter has dangling Actions items swallowed by the vaults, requeue them.
// This is an update to the original func (requeueDanglingActionsV108) with one small change:
// - The voter's OutboundHeight is not overwritten, as this should be the earliest outbound
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment