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

Call to my_swap_status rpc or implementation function occasionally may fail #2117

Open dimxy opened 1 month ago

dimxy commented 1 month ago

Bug description Test test_taker_completes_swap_after_taker_payment_spent_while_offline may fail with error:

thread 'docker_tests::swap_watcher_tests::test_taker_completes_swap_after_taker_payment_spent_while_offline' panicked at 'called `Result::unwrap()` on an `Err` value: "!status of 35844273-888e-42dc-9652-5a35f67ff20a: {\"error\":\"rpc:215] dispatcher_legacy:141] lp_swap:1117] saved_swap:211] fs:192] Error deserializing a swap: EOF while parsing a value at line 1 column 0\"}"', /home/runner/work/komodo-defi-framework/komodo-defi-framework/mm2src/mm2_test_helpers/src/for_tests.rs:2269:53

Commit: 9a82349f14aa0acbd083f2787c1599ed7c80cbf6 Environment: Native (non-wasm)

More Information Apparently this may happen for swaps v1 due to concurrent access to the swap file: writing swap state to the swap file (while a swap in progress) and reading from the swap file by querying my_swap_status(). Example of this is test_taker_completes_swap_after_taker_payment_spent_while_offline test which waits for swap completion periodically calling my_swap_status().

Proposed Solution We have several options to fix this:

dimxy commented 1 month ago

I did an experiment and apparently the .tmp file option works okay both on linux and windows: I tried to open file.txt for reading and overwrite it with async_fs::rename() from file1.tmp to file1.txt to ensure that rename does not fail. I suggest use it for now and later get rid of swap files in favour db as we do it now for wasm