KomodoPlatform / komodo-defi-framework

This is the official Komodo DeFi Framework repository
https://komodoplatform.com/en/docs/komodo-defi-framework/
97 stars 88 forks source link

Swap fails with MakerPaymentSpendFailed error after taker node went offline and restarted while swap in progress #2111

Closed dimxy closed 1 month ago

dimxy commented 1 month ago

Bug description A utxo to utxo swap fails with MM2 error MakerPaymentSpendFailed and mandatory-script-verify-flag-failed script error. This happens after the Taker node was offline for some time and restarted while the swap was in progress.

This issue was found when running a test which fails:

docker_tests::swap_watcher_tests::test_taker_completes_swap_after_restart' panicked at 'assertion failed: actual_events.iter().all(|item| success_events.contains(item))', /home/ubuntu/komodo-defi-framework/mm2src/mm2_test_helpers/src/for_tests.rs:2358:5

Enabling taker swap error log https://github.com/KomodoPlatform/komodo-defi-framework/blob/a0d87236369996ac02369e48e7c766c789cee6e2/mm2src/mm2_main/src/lp_swap/taker_swap.rs#L476 showed an additional error:

error: Response(http://127.0.0.1:8000, Object({\"result\": Null, \"error\": Object({\"code\": Number(-26), \"message\": String(\"16: mandatory-script-verify-flag-failed (Script failed an OP_EQUALVERIFY operation)\")}), \"id\": String(\"43\")})) })" })

Decoding the scriptSig showed that the secret was all zeros: 0000000000000000000000000000000000000000000000000000000000000000

MM2 Version Commit: 2462d9a6d6b42b583808737922feb5e7c47d80ff

Cause of the bug and proposed solution The problem is that on restart taker finds missed its payment spending but does not process it correctly:

The solution is to call TakerSwap::apply_event for the events discovered inside get_command_based_on_watcher_activity fn

shamardy commented 1 month ago

Fixed in https://github.com/KomodoPlatform/komodo-defi-framework/pull/2114