Skip to content

Commit

Permalink
node: Fix bug in flow cancel mechanism where the wrong values were be…
Browse files Browse the repository at this point in the history
…ing used for tokenEntry (wormhole-foundation#3990)

* node: add more unit tests for flow cancel

* node: Fix tokenEntry indexing issue in Governor flow cancel logic

- Indexes the tokenEntry for flow cancel tokens properly (using the
  token's origin chain and origin address
- Add many more tests to check flow cancel logic in more detail and at
  the resolution of the ProcessMsgForTime method.

Big thanks to Max for helping to debug the issue and the unit tests.

* node: add check to ensure the governor usage is not zero

* node: Change flow cancel test so that origin and emitter chain are different

* node: Add unit test for partial flow cancel

Add additional test for flow cancel mechanism where the numbers do not
cleanly cancel out.

* node: fix lint issues in governor test
  • Loading branch information
johnsaigle committed Jun 24, 2024
1 parent 627faa7 commit dc3a6cf
Show file tree
Hide file tree
Showing 2 changed files with 501 additions and 14 deletions.
7 changes: 6 additions & 1 deletion node/pkg/governor/governor.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ func (gov *ChainGovernor) ProcessMsg(msg *common.MessagePublication) bool {
}

// ProcessMsgForTime handles an incoming message (transfer) and registers it in the chain entries for the Governor.
// Returns true if:
// - the message is not governed
// - the transfer is complete and has already been observed
// - the transfer does not trigger any error conditions (happy path)
// Validation:
// - ensure MessagePublication is not nil
// - check that the MessagePublication is governed
Expand Down Expand Up @@ -567,7 +571,8 @@ func (gov *ChainGovernor) ProcessMsgForTime(msg *common.MessagePublication, now
emitterChainEntry.transfers = append(emitterChainEntry.transfers, transfer)

// Add inverse transfer to destination chain entry if this asset can cancel flows.
key := tokenKey{chain: msg.EmitterChain, addr: msg.EmitterAddress}
key := tokenKey{chain: token.token.chain, addr: token.token.addr}

tokenEntry := gov.tokens[key]
if tokenEntry != nil {
// Mandatory check to ensure that the token should be able to reduce the Governor limit.
Expand Down
Loading

0 comments on commit dc3a6cf

Please sign in to comment.