Open binarybaron opened 2 years ago
Possibly related to this https://github.com/comit-network/xmr-btc-swap/issues/828 issue by @rishflab
The same issue occurs when Bob locks his BTC and Alice then goes offline. Bob will not automatically refund because the cli will crash.
In the issue description you mention that the CLI is restarted and you
Resume the swap -> Error occurs. Swap is not automatically refunded. Bob will get punished and loose his funds.
Is this a "permanent" error, where both resume
and cancel
+refund
fail and the swap cannot be recovered?
I think the code you linked in https://github.com/comit-network/xmr-btc-swap/issues/929#issuecomment-1102582623 should be fine:
If the timelock is expired state.expired_timelock(bitcoin_wallet).await?
will evaluate to Some
, which will go into the else
path and transition to BobState::CancelTimelockExpired(state.cancel())
unless I missed something.
One thing that I can see in the code linked is, that if Bob fails to send the encsig
the loop will just exit and a manual refund after the timelock expiry will be necessary (i.e. the user has to ensure to resume
/cancel
after the cancel
timelock expired). But that's not the problem you are referring to.
Is this a "permanent" error, where both
resume
andcancel
+refund
fail and the swap cannot be recovered?
I suspect that the swap can be recovered using the cancel + refund
command. However, in this case Bob has already been punished. Therefore, the swap will never be able to be completed.
$ ./swap --testnet cancel --swap-id 2a3f6f15-862f-440a-8215-a5798a7b9d52
Manually cancelling swap swap_id=2a3f6f15-862f-440a-8215-a5798a7b9d52
Error: Failed to broadcast Bitcoin cancel transaction 947da247f8589a6e4162bee6426106b1de1093e5fc88ad036ae38c2c0d33506f
Caused by:
Electrum(Protocol(String("sendrawtransaction RPC error: {\"code\":-25,\"message\":\"bad-txns-inputs-missingorspent\"}")))
$ ./swap --testnet refund --swap-id 2a3f6f15-862f-440a-8215-a5798a7b9d52
Error: Failed to broadcast Bitcoin refund transaction 74514eaa8040c57934784be50d64151c3e46a336913b387eed2d443728a2b1dd
Caused by:
Electrum(Protocol(String("sendrawtransaction RPC error: {\"code\":-25,\"message\":\"bad-txns-inputs-missingorspent\"}")))
One thing that I can see in the code linked is, that if Bob fails to send the encsig the loop will just exit and a manual refund > after the timelock expiry will be necessary (i.e. the user has to ensure to resume/cancel after the cancel timelock expired). But that's not the problem you are referring to.
No, I think you are correct. This is the problem here. I've added the error message that is thrown to the log above. When Bob sends the "encsig", Alice ignores it because she has already punished Bob and in her view the swap has been completed. Bob will error out, bail and exit the cli.
If the timelock is expired state.expired_timelock(bitcoin_wallet).await? will evaluate to Some, which will go into the else path and transition to BobState::CancelTimelockExpired(state.cancel()) unless I missed something.
This should happen, but apparently doesn't. There must be a problem with the detection of the confirmations. I don't have a record of it, but I remember when debugging this issue, I set a breakpoint somewhere and found that the timelock state was reported as ExpiredTimelocks::None
, which caused the CLI to not cancel and refund.
If you could give me some guidance on how to tackle this, I would be happy to try to file a PR to fix this problem. It seems very important to me, because we don't want users to lose funds (even if they could refund manually).
https://github.com/comit-network/xmr-btc-swap/issues/1063 is probably related. There seems to be an underlying issue with how we detect expired timelocks.
Same issue here. If the CLI can't receive the transfer proof it will bail and not refund automatically.
{"timestamp":"Jul 26 16:42:43.052","level":"DEBUG","fields":{"message":"Using existing sqlite database."}}
{"timestamp":"Jul 26 16:42:43.057","level":"DEBUG","fields":{"message":"Reading in seed from /Users/***/Library/Application Support/xmr-btc-swap/cli/testnet/seed.pem"}}
{"timestamp":"Jul 26 16:42:45.188","level":"DEBUG","fields":{"message":"Starting monero-wallet-rpc","port":"55810"}}
{"timestamp":"Jul 26 16:42:48.717","level":"DEBUG","fields":{"message":"Opened Monero wallet","monero_wallet_name":"swap-tool-blockchain-monitoring-wallet"}}
{"timestamp":"Jul 26 16:42:48.723","level":"DEBUG","fields":{"message":"Network layer initialized","peer_id":"12D3KooWSQLCbtoDWAQzo11JwKmsp3EXfVygZDv7sgdu6sns65tQ"}}
{"timestamp":"Jul 26 16:42:48.723","level":"DEBUG","fields":{"message":"Requesting quote"}}
{"timestamp":"Jul 26 16:42:48.819","level":"INFO","fields":{"message":"Connected to Alice at /dns4/asb.unstoppableswap.net/tcp/9939/p2p/12D3KooWJS3D2aN2Y4MNbDm66jCfkUSVpqW1u2TdURSqriny2CfX"}}
{"timestamp":"Jul 26 16:42:48.842","level":"INFO","fields":{"message":"Received quote","price":"0.00705942 BTC","minimum_amount":"0.00010000 BTC","maximum_amount":"0.04647365 BTC"}}
{"timestamp":"Jul 26 16:42:48.842","level":"INFO","fields":{"message":"Waiting for Bitcoin deposit","deposit_address":"tb1qvs45emcmahelyu3ewuks5kccc0fm0a6aeu7acz","max_giveable":"0.00000000 BTC","minimum_amount":"0.00010000 BTC","maximum_amount":"0.04647365 BTC"}}
{"timestamp":"Jul 26 16:43:09.645","level":"INFO","fields":{"message":"Received Bitcoin","new_balance":"0.00011000 BTC","max_giveable":"0.00010878 BTC"}}
{"timestamp":"Jul 26 16:43:09.646","level":"INFO","fields":{"message":"Determined swap amount","amount":"0.00010878 BTC","fees":"0.00000122 BTC"}}
{"timestamp":"Jul 26 16:43:09.651","level":"DEBUG","fields":{"message":"Advancing state","state":"quote has been requested"}}
{"timestamp":"Jul 26 16:43:09.899","level":"DEBUG","fields":{"message":"Estimated fee for transaction","weight":"548","fee_rate":"1","sats_per_vbyte":"137.0"}}
{"timestamp":"Jul 26 16:43:09.899","level":"WARN","fields":{"message":"Estimated fee of 137.0 is smaller than the min relay fee, defaulting to min relay fee 1000"}}
{"timestamp":"Jul 26 16:43:10.151","level":"DEBUG","fields":{"message":"Estimated fee for transaction","weight":"596","fee_rate":"1","sats_per_vbyte":"149.0"}}
{"timestamp":"Jul 26 16:43:10.151","level":"WARN","fields":{"message":"Estimated fee of 149.0 is smaller than the min relay fee, defaulting to min relay fee 1000"}}
{"timestamp":"Jul 26 16:43:12.161","level":"INFO","fields":{"message":"Starting new swap","swap_id":"c9186b1b-a363-489b-8842-99ab1c4cbd6d"}}
{"timestamp":"Jul 26 16:43:12.163","level":"DEBUG","fields":{"message":"Advancing state","state":"execution setup done"}}
{"timestamp":"Jul 26 16:43:12.292","level":"INFO","fields":{"message":"Published Bitcoin transaction","txid":"e1250965ed0c77dda92d883152d83061bc5b9bebbcbd34f1829e9a0a359c2994","kind":"lock"}}
{"timestamp":"Jul 26 16:43:12.293","level":"DEBUG","fields":{"message":"Advancing state","state":"btc is locked"}}
{"timestamp":"Jul 26 16:43:12.293","level":"INFO","fields":{"message":"Waiting for Alice to lock Monero"}}
{"timestamp":"Jul 26 16:43:17.169","level":"DEBUG","fields":{"message":"Found relevant Bitcoin transaction","txid":"e1250965ed0c77dda92d883152d83061bc5b9bebbcbd34f1829e9a0a359c2994","status":"unseen"}}
{"timestamp":"2022-07-27 13:51:15","level":"DEBUG","fields":{"message":"Using existing sqlite database."}}
{"timestamp":"2022-07-27 13:51:15","level":"DEBUG","fields":{"message":"Reading in seed from /Users/***/Library/Application Support/xmr-btc-swap/cli/testnet/seed.pem"}}
{"timestamp":"2022-07-27 13:51:17","level":"DEBUG","fields":{"message":"Starting monero-wallet-rpc","port":"60629"}}
{"timestamp":"2022-07-27 13:51:20","level":"DEBUG","fields":{"message":"Opened Monero wallet","monero_wallet_name":"swap-tool-blockchain-monitoring-wallet"}}
{"timestamp":"2022-07-27 13:51:20","level":"DEBUG","fields":{"message":"Network layer initialized","peer_id":"12D3KooWSQLCbtoDWAQzo11JwKmsp3EXfVygZDv7sgdu6sns65tQ"}}
{"timestamp":"2022-07-27 13:51:20","level":"DEBUG","fields":{"message":"Advancing state","state":"btc is locked"}}
{"timestamp":"2022-07-27 13:51:20","level":"INFO","fields":{"message":"Waiting for Alice to lock Monero"}}
{"timestamp":"2022-07-27 13:51:20","level":"INFO","fields":{"message":"Connected to Alice at /dns4/asb.unstoppableswap.net/tcp/9939/p2p/12D3KooWJS3D2aN2Y4MNbDm66jCfkUSVpqW1u2TdURSqriny2CfX"}}
{"timestamp":"2022-07-27 13:51:25","level":"DEBUG","fields":{"message":"Found relevant Bitcoin transaction","txid":"e1250965ed0c77dda92d883152d83061bc5b9bebbcbd34f1829e9a0a359c2994","status":"unseen"}}
{"timestamp":"2022-07-27 13:51:30","level":"WARN","fields":{"message":"Communication error: /comit/xmr/btc/bid-quote/1.0.0 failed because of an inbound timeout","peer":"12D3KooWJS3D2aN2Y4MNbDm66jCfkUSVpqW1u2TdURSqriny2CfX"}}
Error: Failed to receive transfer proof
Caused by:
request channel closed
Describe the bug How to reproduce:
Lost/trapped Funds Could potentially result in Bob not automatically refunding when the timelock has expired.
Debug logs CLI logs:
ASB Logs:
Platform (please complete the following information):