xmr-btc-swap icon indicating copy to clipboard operation
xmr-btc-swap copied to clipboard

Fix edge case for enc sig and BTC redeem phase

Open pokkst opened this issue 2 years ago • 10 comments

I encountered a weird situation during testing on stagenet, where both a sudden surge of transactions and blocks came in within a short time frame (i.e. dozens of blocks within a few minutes). It seemed to have caused my swap program to crash, leaving me in the state XmrLocked, however I seemed to have actually sent Alice the encrypted signature and Alice was able to redeem the BTC.

Because I was stuck in XmrLocked state, I couldn't watch for the redemption transaction, meaning I could never redeem the XMR. Adding this to the XmrLocked state for Bob fixed the issue, and allowed me to redeem the XMR.

pokkst avatar Aug 13 '23 03:08 pokkst

This seems like a hack. I don't want to merge this without before trying to really find the root cause of this issue. How did swap crash?

binarybaron avatar Aug 13 '23 13:08 binarybaron

I'm not entirely sure and I no longer have the log on hand. I was running it, Alice submitted XMR lock tx proof, and the swap client was monitoring the transaction, then a sudden rush of blocks on stagenet came in (I'm talking like 20 blocks within ~5 minutes or so), and the swap client crashed shortly after with Alice having redeemed the BTC, but we were stuck in XmrLocked state in the database.

pokkst avatar Aug 13 '23 15:08 pokkst

After further investigation, I believe it might be due to some failure during sending of the encrypted signature. Alice seems to receive it, but Bob does not get confirmation of that. He is then in XmrLocked state until the cancel timelock expires, which he then tries to broadcast the cancel tx.

pokkst avatar Aug 13 '23 18:08 pokkst

Yes that might be. I believe we encountered this issue before. Because Alice will only sent the confirmation of receiving the end sig once, after that further requests b Bob will be ignored.

binarybaron avatar Aug 13 '23 18:08 binarybaron

Thanks @pokkst, I'd really love to see this covered by a test if it's possible. Let me know if you can look into it

delta1 avatar Aug 14 '23 11:08 delta1

@pokkst any update? Would love to get this merged

binarybaron avatar Aug 31 '23 12:08 binarybaron

Hi, sorry, been really busy. I will go over this again soon.

pokkst avatar Sep 29 '23 13:09 pokkst

I've taken a look, and I'm not the most experienced with Rust, so do you guys think you can go over where exactly I should put the test, how to structure it, etc.? Assuming it's even possible to write a test for.

pokkst avatar Sep 29 '23 16:09 pokkst

I'm not sure either but I will take a look!

binarybaron avatar Oct 05 '23 09:10 binarybaron

Any update? Did you get a chance to take a look?

pokkst avatar Dec 16 '23 14:12 pokkst

I'm gonna review this again tommorow. I think this is also a fix for https://github.com/comit-network/xmr-btc-swap/issues/1063

binarybaron avatar Jun 03 '24 21:06 binarybaron

Is it possible to have a test covering this?

delta1 avatar Jun 04 '24 06:06 delta1

Is it possible to have a test covering this?

Perhaps for one of the cases yet. The other one I can't replicate unfortunatelym

binarybaron avatar Jun 04 '24 07:06 binarybaron

Is it possible to have a test covering this?

I added an integration test. It passes on this branch and doesn't pass on master.

binarybaron avatar Jun 04 '24 09:06 binarybaron

Ready to merge? @delta1

binarybaron avatar Jun 04 '24 09:06 binarybaron

Ready to merge? @delta1

some CI failing, and just give me a few mins to test

delta1 avatar Jun 04 '24 09:06 delta1

Oh I see the linter is complaining.

Also I just realized we might want to distinguish between "Transaction was not found" and we failed to fetch the transaction.

binarybaron avatar Jun 04 '24 09:06 binarybaron

@binarybaron pushed 2 commits to fix lint and add the new test to CI

but there was also an rpc_tests failure?

delta1 avatar Jun 04 '24 09:06 delta1

That's odd. Probably a timeout or something along those lines...

binarybaron avatar Jun 04 '24 09:06 binarybaron

awesome thank you! I'm so glad we got found a fix for https://github.com/comit-network/xmr-btc-swap/issues/1063

binarybaron avatar Jun 04 '24 10:06 binarybaron