Skip to content

Commit

Permalink
matching: add predicate for self chan balance version
Browse files Browse the repository at this point in the history
We add a matching predicate that makes sure the asker's node is
up-to-date and knows how to account for the self channel
balance feature of bid orders. Old asker nodes wouldn't correctly calculate
an account's diff (and also not open the channel correctly) if they didn't
know of the self channel balance feature. Therefore we need to make sure we
exclude old asker clients from being matched with bid orders that have a self
channel balance set.
  • Loading branch information
guggero committed Mar 16, 2021
1 parent fcc7e0e commit e5625d7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions venue/matching/match_predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
MatchPredicateFunc(DifferentNodesPredicate),
MatchPredicateFunc(AskRateSmallerOrEqualPredicate),
MatchPredicateFunc(AskDurationGreaterOrEqualPredicate),
MatchPredicateFunc(SelfChanBalanceEnabledPredicate),
}
)

Expand Down Expand Up @@ -70,6 +71,18 @@ func AskDurationGreaterOrEqualPredicate(ask *order.Ask, bid *order.Bid) bool {
return ask.LeaseDuration() >= bid.LeaseDuration()
}

// SelfChanBalanceEnabledPredicate is a matching predicate that makes sure the
// asker's node is up-to-date and knows how to account for the self channel
// balance feature of bid orders. Old asker nodes wouldn't correctly calculate
// an account's diff (and also not open the channel correctly) if they didn't
// know of the self channel balance feature. Therefore we need to make sure we
// exclude old asker clients from being matched with bid orders that have a self
// channel balance set.
func SelfChanBalanceEnabledPredicate(ask *order.Ask, bid *order.Bid) bool {
return bid.SelfChanBalance == 0 ||
ask.Version >= orderT.VersionSelfChanBalance
}

// MinPartialMatchPredicate is a matching predicate that returns true if the
// bid's and ask's supply each satisfy the other's minimum units to match.
// Matchmaking keeps track of each order's unfulfilled supply in-memory, which
Expand Down

0 comments on commit e5625d7

Please sign in to comment.