Skip to content

swap: fix missing nil redemption check#494

Closed
chappjc wants to merge 2 commits into
decred:masterfrom
chappjc:txmonitored-redeem-nil
Closed

swap: fix missing nil redemption check#494
chappjc wants to merge 2 commits into
decred:masterfrom
chappjc:txmonitored-redeem-nil

Conversation

@chappjc
Copy link
Copy Markdown
Member

@chappjc chappjc commented Jun 16, 2020

No description provided.

Comment thread server/swap/swap.go
// Taker either has not redeemed or the redemption has not reached
// the required confirmations. If the txid matches the immature
// redeem, it is considered monitored.
return takerStatus.redemption != nil && takerStatus.redemption.TxID() == txid
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redeemStatus and makerRedeemStatus were checking swapStatus.redeemTime.IsZero() before attempting to dereference swapStatus.redemption. This PR adds a redemption != nil before checking takerStatus.redemption.TxID()

Comment thread server/swap/swap.go Outdated
_, takerRedeemDone := s.redeemStatus(makerStatus, takerStatus)
if takerRedeemDone {
// Taker has a redemption that has reached required confirms.
return false // so no longer monitored?
Copy link
Copy Markdown
Member Author

@chappjc chappjc Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't follow the reasoning for considering it not monitored if we know about the redemption and it has reached the required confirms, but considering it monitored if it has not reached the required confirms. @buck54321 Thoughts about why we don't just consider a tx monitored if it corresponds to a redemption regardless of the confirmations? After all, if it is found in the Swapper.matches map, the swap is still active. If it is not found, the user would be subject to the usual FundConf requirement.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've got it right, but I'll note that the matches map is being pruned in processBlocks, so TxMonitored won't hit after MatchComplete anyway. We either need the full DB solution, or Swapper should hang onto matches until FundConf on the redemptions.

Copy link
Copy Markdown
Member Author

@chappjc chappjc Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I'll note that the matches map is being pruned in processBlocks, so TxMonitored won't hit after MatchComplete anyway

That's what I was getting at with "if it is found in the Swapper.matches map, the swap is still active". In case it's not found the user will just have to wait for FundConf.

A DB powered solution has been on the table for a while, although I'm super hesitant to load the DB for with a check of all matches for each order placed that is funded by coins with < FundConf confirms, so the alternative you mentioned of Swapper hanging on to matches until FundConf sounds more appealing.

Anyway, on this current implementation, I think I'll remove the redeemStatus/makerRedeemStatus function calls from TxMonitored since I think we agree that it makes no sense to consider the tx not monitored because the redeem has reached SwapConf. Correct?

In (*Swapper).TxMonitored, redemptions were being considered not
monitored once they reached SwapConf even though they were still
active swaps (in Swapper.matches map). This removes the confirms
check entirely from TxMonitored, instead indicating if there is an
active swap with the txid as a known contract or redeem.

Also reduce excessive locking in TxMonitored.

Eliminate extra "redeem status" functions.
@chappjc chappjc marked this pull request as ready for review June 16, 2020 16:36
Comment thread server/swap/swap_test.go
// Confirm both redeem txns up to SwapConf so they are no longer monitored.
matchInfo.db.makerRedeem.coin.setConfs(int64(rig.abc.SwapConf))
matchInfo.db.takerRedeem.coin.setConfs(int64(rig.xyz.SwapConf))
sendBlock(rig.abcNode) // trigger process block to remove them
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this change in behavior. Now the match needs to be pruned from the matches map before it is no longer found by TxMonitored. Meeting the confirmations threshold no longer makes it not monitored.

Copy link
Copy Markdown
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closes #490

@chappjc chappjc added the server server components label Jun 18, 2020
@chappjc
Copy link
Copy Markdown
Member Author

chappjc commented Jun 19, 2020

Replaced by #499

@chappjc chappjc closed this Jun 19, 2020
@chappjc chappjc deleted the txmonitored-redeem-nil branch October 22, 2020 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server server components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants