client/core: consider contract expiry before acting #1548
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Complementary to #1541, this includes client-side checks.
In particular,
(*trackedTrade).counterPartyConfirms
checks if the contract is expired and returns anexpired bool
. The callers (isSwappable
andisRedeemable
) consider the expired status in the same way they already consider spent status -- self-revoke and return false to the spendable/redeemable check. Specifically, this happens only in theorder.TakerSwapCast
&&order.Maker
condition ofisRedeemable
, and in theorder.MakerSwapCast
&&order.Taker
condition ofisSwappable
.Note that in the first scenario above of the maker deciding if the taker's contract is redeemable, it is quite important not to redeem an expired contract. This is true for either actor since the contract could also be refunded at any time, but it's absolutely critical for maker since they are revealing the secret key to the taker. That must not happen if the taker's contract is expired.
Another check added is for taker at
MakerSwapCast
when checking swappability, where it now also ensures that the taker's own contract that it would publish would not have a lock time that is already in the past.To ease readability, some order status
if
statements are converted toswitch
statements. Also, an initial order status filter is added toisSwappable
andisRedeemable
for efficiency.Finally, an minor bug with
wg.Done()
being called not at the end of a defer stack is fixed.