Skip to content

Commit

Permalink
node: Fix issue where transfers that were loaded from the DB did not add
Browse files Browse the repository at this point in the history
a flow-cancel transfer on the TargetChain

Flow-canceling is done in the `ProcessMsgForTime` loop when a new
message occurs. However, this was not done when a node restarted and
reloaded transfers from the past 24 hours. As a result it was possible
for the node to calculate a result that showed that the outgoing
transfers for an emitter chain exceeded the daily limit. In effect this
is true but only with the condition that there was incoming flow to
allow this to happen. This appeared to violate an invariant and so the
node did not start properly.
  • Loading branch information
johnsaigle committed Jul 2, 2024
1 parent d146f82 commit 0e986be
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions node/pkg/governor/governor_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ func (gov *ChainGovernor) reloadPendingTransfer(pending *db.PendingTransfer) {
zap.String("Hash", hash),
)

// Note: no flow cancel added here. We only want to add an inverse, flow-cancel transfer when the transfer is
// released from the pending queue, not when it's added.
ce.pending = append(ce.pending, &pendingEntry{token: token, amount: payload.Amount, hash: hash, dbData: *pending})
gov.msgsSeen[hash] = transferEnqueued
}
Expand Down Expand Up @@ -233,5 +235,27 @@ func (gov *ChainGovernor) reloadTransfer(xfer *db.Transfer) error {
return err
}
ce.transfers = append(ce.transfers, transfer)

// Reload flow-cancel transfers for the TargetChain. This is important when node restarts so that a corresponding,
// inverse transfer is added to the TargetChain. This is already done during the `ProcessMsgForTime` loop but
// that function does not capture flow-cancelling when the node is restarted.
tokenEntry := gov.tokens[tk]
if tokenEntry != nil {
// Mandatory check to ensure that the token should be able to reduce the Governor limit.
if tokenEntry.flowCancels {
if destinationChainEntry, ok := gov.chains[xfer.TargetChain]; ok {
if err := destinationChainEntry.addFlowCancelTransferFromDbTransfer(xfer); err != nil {
return err
}
} else {
gov.logger.Warn("tried to cancel flow but chain entry for target chain does not exist",
zap.String("msgID", xfer.MsgID),
zap.Stringer("token chain", xfer.OriginChain),
zap.Stringer("token address", xfer.OriginAddress),
zap.Stringer("target chain", xfer.TargetChain),
)
}
}
}
return nil
}

0 comments on commit 0e986be

Please sign in to comment.