<p><strong>Problem description:</strong><br>
A trade will fail if the deposit transaction is received via the mempool before it is received via P2P messaging protocols.</p>
<p>During initial trade protocol messaging, the deposit transaction is received at the buyer via two possible paths: a P2P message <code>DepositTxAndDelayedPayoutTxMessage</code>, or received in the mempool.<br>
Receiving via P2P message is much more likely, but in rare cases when received via the mempool first, we get the following error:</p>
<p><strong>Log of broken version:</strong></p>
<div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="Aug-30 07:52:20.383 [JavaFX Application Thread] INFO  b.c.btc.wallet.WalletService: depositTx received from network:
Aug-30 07:52:36.318 [JavaFX Application Thread] INFO  b.c.t.p.FluentProtocol$Condition: We received a DepositTxAndDelayedPayoutTxMessage at phase DEPOSIT_PUBLISHED and state BUYER_SAW_DEPOSIT_TX_IN_NETWORK
Aug-30 07:52:36.319 [JavaFX Application Thread] WARN  b.c.t.protocol.BuyerProtocol: We with a DepositTxAndDelayedPayoutTxMessage but we have already processed the deposit and delayed payout tx so we ignore the message. This can happen if the ACK message to the peer did not arrive and the peer repeats sending us the message. We send another ACK msg. 
Aug-30 07:52:36.319 [JavaFX Application Thread] INFO  b.c.t.protocol.TradeProtocol: Send AckMessage for DepositTxAndDelayedPayoutTxMessage to peer 
Aug-30 07:52:36.321 [JavaFX Application Thread] INFO  b.c.t.protocol.TradeProtocol: Remove DepositTxAndDelayedPayoutTxMessage from the P2P network. 
Aug-30 07:52:36.321 [JavaFX Application Thread] WARN  b.c.t.protocol.TradeProtocol: PreConditions not met. preConditions=[false]
Aug-30 07:52:36.321 [JavaFX Application Thread] ERROR b.c.t.protocol.TradeProtocol: Task runner failed with error PreConditions not met. preConditions=[false],
... followed by missing payment instructions and the trade cannot be completed.
Aug-30 07:59:02.876 [JavaFX Application Thread] ERROR b.d.m.p.p.s.b.BuyerStep2View: Not supported PaymentMethod:
"><pre><code>Aug-30 07:52:20.383 [JavaFX Application Thread] INFO  b.c.btc.wallet.WalletService: depositTx received from network:
Aug-30 07:52:36.318 [JavaFX Application Thread] INFO  b.c.t.p.FluentProtocol$Condition: We received a DepositTxAndDelayedPayoutTxMessage at phase DEPOSIT_PUBLISHED and state BUYER_SAW_DEPOSIT_TX_IN_NETWORK
Aug-30 07:52:36.319 [JavaFX Application Thread] WARN  b.c.t.protocol.BuyerProtocol: We with a DepositTxAndDelayedPayoutTxMessage but we have already processed the deposit and delayed payout tx so we ignore the message. This can happen if the ACK message to the peer did not arrive and the peer repeats sending us the message. We send another ACK msg. 
Aug-30 07:52:36.319 [JavaFX Application Thread] INFO  b.c.t.protocol.TradeProtocol: Send AckMessage for DepositTxAndDelayedPayoutTxMessage to peer 
Aug-30 07:52:36.321 [JavaFX Application Thread] INFO  b.c.t.protocol.TradeProtocol: Remove DepositTxAndDelayedPayoutTxMessage from the P2P network. 
Aug-30 07:52:36.321 [JavaFX Application Thread] WARN  b.c.t.protocol.TradeProtocol: PreConditions not met. preConditions=[false]
Aug-30 07:52:36.321 [JavaFX Application Thread] ERROR b.c.t.protocol.TradeProtocol: Task runner failed with error PreConditions not met. preConditions=[false],
... followed by missing payment instructions and the trade cannot be completed.
Aug-30 07:59:02.876 [JavaFX Application Thread] ERROR b.d.m.p.p.s.b.BuyerStep2View: Not supported PaymentMethod:
</code></pre></div>
<p>The handling of the P2P message is not carried out because it erroneously thinks it has been handled before.  The preconditions are incorrect.</p>
<p>Preconditions are changed via this PR, checking if the payment account payload has already been received.  If not, then the P2P message will be processed.</p>
<p><strong>Log of fixed version:</strong></p>
<div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="Aug-30 08:45:44.418 [JavaFX Application Thread] INFO  b.c.btc.wallet.WalletService: depositTx received from network:
Aug-30 08:46:04.643 [JavaFX Application Thread] INFO  b.c.t.p.FluentProtocol$Condition: We received a DepositTxAndDelayedPayoutTxMessage at phase DEPOSIT_PUBLISHED and state BUYER_SAW_DEPOSIT_TX_IN_NETWORK
Aug-30 08:46:04.643 [JavaFX Application Thread] INFO  b.c.btc.wallet.WalletService: depositTx received from peer:
Aug-30 08:46:04.648 [JavaFX Application Thread] INFO  b.common.taskrunner.TaskRunner: Run task: ApplyFilter 
Aug-30 08:46:04.648 [JavaFX Application Thread] INFO  b.common.taskrunner.TaskRunner: Run task: VerifyPeersAccountAgeWitness 
Aug-30 08:46:04.649 [JavaFX Application Thread] INFO  b.common.taskrunner.TaskRunner: Run task: BuyerSendsShareBuyerPaymentAccountMessage 
Aug-30 08:46:04.649 [JavaFX Application Thread] INFO  b.c.t.p.t.SendMailboxMessageTask: Send ShareBuyerPaymentAccountMessage to peer 
"><pre><code>Aug-30 08:45:44.418 [JavaFX Application Thread] INFO  b.c.btc.wallet.WalletService: depositTx received from network:
Aug-30 08:46:04.643 [JavaFX Application Thread] INFO  b.c.t.p.FluentProtocol$Condition: We received a DepositTxAndDelayedPayoutTxMessage at phase DEPOSIT_PUBLISHED and state BUYER_SAW_DEPOSIT_TX_IN_NETWORK
Aug-30 08:46:04.643 [JavaFX Application Thread] INFO  b.c.btc.wallet.WalletService: depositTx received from peer:
Aug-30 08:46:04.648 [JavaFX Application Thread] INFO  b.common.taskrunner.TaskRunner: Run task: ApplyFilter 
Aug-30 08:46:04.648 [JavaFX Application Thread] INFO  b.common.taskrunner.TaskRunner: Run task: VerifyPeersAccountAgeWitness 
Aug-30 08:46:04.649 [JavaFX Application Thread] INFO  b.common.taskrunner.TaskRunner: Run task: BuyerSendsShareBuyerPaymentAccountMessage 
Aug-30 08:46:04.649 [JavaFX Application Thread] INFO  b.c.t.p.t.SendMailboxMessageTask: Send ShareBuyerPaymentAccountMessage to peer 
</code></pre></div>
<p>This PR was a collaboration between myself (analysis & test), and <a class="user-mention" data-hovercard-type="user" data-hovercard-url="/users/chimp1984/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/chimp1984">@chimp1984</a> (suggested code fix).<br>
The problem has been replicated on mainnet, and the fix tested on mainnet.</p>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/bisq-network/bisq/pull/5679'>https://github.com/bisq-network/bisq/pull/5679</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>Fix race between mempool notify / P2P notify causing failed trade</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/5679/files#diff-d4c89979aab87127dc4fa5a1f8ad12286d2dc443a57f2f7353faa097b1cdabc6">core/src/main/java/bisq/core/trade/protocol/BuyerProtocol.java</a>
    (11)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/bisq-network/bisq/pull/5679.patch'>https://github.com/bisq-network/bisq/pull/5679.patch</a></li>
  <li><a href='https://github.com/bisq-network/bisq/pull/5679.diff'>https://github.com/bisq-network/bisq/pull/5679.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/bisq-network/bisq/pull/5679">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJFFTNUVPK5ZFENXHARC24TT7OMXPANCNFSM5DCCF7ZQ">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub">Android</a>.
<img src="https://github.com/notifications/beacon/AJFFTNTLCRWJYIJLEDJVJFLT7OMXPA5CNFSM5DCCF7Z2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4OUVYNRQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/bisq-network/bisq/pull/5679",
"url": "https://github.com/bisq-network/bisq/pull/5679",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>