-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(legacy-swap): wait for confirmation of taker spend maker payment #2206
Conversation
… method in taker_swap.rs
@cipig is it possible for you to test recreate the issue and test the solution? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- taker now waits for one confirmation on makerpaymentspend
- if EVM tx is reverted (out of gas), swap is marked as failed and recoverable
- if you click on "Recover Funds" in Desktop app, it shows success in spending maker payment, even though that tx is reverted too (still out of gas)... this is fine, else we would need to wait here too for a confirmation before showing a result, which can take some time on slow UTXO chains
- after fixing the problem (increased gas limit) and clicking on "Recover Funds" taker successfully spends maker payment
The thing is that legacy taker swap doesnt have On maker I believe GUI follows backend events: spend taker payment success-> spend taker payment confirmed or failed.
On utxo case it will be same, if taker tx spend maker payment was broadcasted, it will be marked as successful. But then taker will have to wait for this tx confirmation, just couldn't see confirmation started->confirmed, as we dont have it on taker. And yes it could take some time to see Finished. |
I suppose this also fixes the below issue reported by @cipig on DM
The reason was that the RPC probably didn't broadcast the transaction to the network, this fixes such issues as taker will now wait for the transaction that spends the maker payment to confirm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! 2 minor comments :)
let confirm_maker_payment_spend_input = ConfirmPaymentInput { | ||
payment_tx: transaction.tx_hex(), | ||
confirmations, | ||
requires_nota: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use maker_payment_requires_nota
here with unwrap_or(false)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, thanks for the catch
done 9827b54
), | ||
])); | ||
} | ||
info!("Maker payment spend confirmed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add the number of confirmations in the logs too, might be useful who knows.
@laruh one problem with adding confirmation to
About this, I think we should at least check that transaction is not reverted (for EVM only, so this should not be done in swaps code), this will not take time and doesn't require waiting for confirmations. For TPU/Swaps v2, I guess you will fix this in another PR, right? You can fix it here as well as it's not related to ETH TPU. This is where we need to check for confirmations instead of changing state to completed straight away. komodo-defi-framework/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs Lines 2189 to 2198 in 7723b50
|
@shamardy thanks for the feedback
Do you mean we should come back to this approach https://github.com/KomodoPlatform/komodo-defi-framework/pull/2199/files with additional
I actually wanted to add new state with new In TPUV2 there is the same issue as in legacy protocol, that we have step to confirm that taker payment was spent ( komodo-defi-framework/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs Lines 1686 to 1691 in f73b5de
But we dont wait for Note: I didnt add it to swap v2 states yet. I suppose we could call komodo-defi-framework/mm2src/mm2_main/src/lp_swap/taker_swap_v2.rs Lines 2189 to 2198 in 7723b50
But on the one hand its a bit awkward, that we will have both
Do you really want to call |
@shamardy but you can check was it reverted or not during waiting for confirmations. You broadcast transaction to spend payment, if it was successfully broadcasted you will see log info |
I guess questions here #2206 (comment) have been resolved in DM. About this #2206 (comment)
Original comment from cipi was about recover funds, which is trying another transaction where we also don't check if it was reverted or not. It's a different case and can be worked on in another PR but this issue #2175 (comment) shouldn't be closed until it's resolved. Code reference: komodo-defi-framework/mm2src/mm2_main/src/lp_swap/taker_swap.rs Lines 2177 to 2212 in 17a5fab
komodo-defi-framework/mm2src/mm2_main/src/lp_swap/taker_swap.rs Lines 2248 to 2251 in 17a5fab
komodo-defi-framework/mm2src/mm2_main/src/lp_swap/taker_swap.rs Lines 2290 to 2300 in 17a5fab
So basically for any broadcasted ethereum transaction, we have to make sure it's not reverted. One way is to add a check at the end of komodo-defi-framework/mm2src/coins/eth.rs Line 3606 in 8b1170d
|
ee0ab4c
to
98afd06
Compare
…-spend-maker-confirmation
// we should wait for only one confirmation to make sure spend maker payment transaction is not failed | ||
let confirm_maker_payment_spend_input = ConfirmPaymentInput { | ||
payment_tx: transaction.tx_hex(), | ||
confirmations: std::cmp::min(1, self.r().data.maker_payment_confirmations), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to involve 'maker_payment_confirmations' if we always want exactly 1 conf?
(And what would be if maker_payment_confirmations set to 0? Like if someone wants to run the whole swap with no confs at all?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If we do not want to wait until the payment spending tx is confirmed, we may just try to read it with eth_getTransactionByHash rpc which returns the tx at least in 'pending' state (I guess we also need to ensure we read the tx from the same eth node or it may not have time to propagate to other nodes yet). I believe the tx in the pending state does not guarantee it won't be reverted but ensures it is valid and the sender has sufficient funds to pay for it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! only two notes
@@ -2257,7 +2257,7 @@ impl MarketCoinOps for EthCoin { | |||
} | |||
} | |||
|
|||
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> { | |||
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not u8
or u16
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too keep consistence with the field pub confirmations: u64,
@@ -2581,7 +2581,8 @@ impl MarketCoinOps for TendermintCoin { | |||
|
|||
if let Some(tx_status_code) = tx_status_code { | |||
return match tx_status_code { | |||
cosmrs::tendermint::abci::Code::Ok => Ok(()), | |||
// Tendermint uses Byzantine Fault Tolerance (BFT), achieve instant finality once a block is committed. | |||
cosmrs::tendermint::abci::Code::Ok => Ok(1u64), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better this function wait_for_confirmations
return Optional u8 or 16 and we can return None for tendermint
. cc @onur-ozkan
@laruh please close this PR so no else wastes time reviewing it. If we find we need this we will re-open it and close the other one, but looking at the other one there are no backward compatibility issues found yet :) |
reason: see this #2206 (comment) pls |
fixes this issue #2175 (comment)
Currently in legacy swap protocol we dont check transaction "taker spend maker payment" confirmation and just mark Swap on taker side as successfully finished, while on maker side we have taker payment spend confirmation check.
Current PR is a solution approach suggested here #2199 (comment)