Skip to content
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

add delay between xmr auto-funding reattempts #733

Conversation

Lederstrumpf
Copy link
Member

On #707, the only non-intentional refunds I've found so far have been from xmr auto-funding.
Unless due to insufficient unlocked money, they've typically been down to temporary monerod irresponsiveness.

We reattempt autofunding for monero as of #686.
When excluding insufficient unlocked money, last week's swaps' statistical distribution of auto-funding reattempts until success (or resignation, if 10 attempts didn't suffice) is the following:

auto-funding-failures

So we're succeeding about 1/3rd of the time on the first reattempt, else it most likely simply fails. Right now, we're reattempting the call right away, so it mostly occurs within a few milliseconds of the last. But based on the statistical distribution, I suspect we'd do much better by introducing a delay, similar as done for transaction polling.

I'm using a gradually increasing delay amount here to better capture the tail end of failures.

Failure example:
farcasterd:

[2022-10-04T18:48:16Z INFO  farcaster_node::swapd::syncer_client] 0x097e…99a0 | Watching Accordant Lock on address 5ATxBnRrsJvEiBpG9B2fb7ExzrDr5KW7KWUCJjDiw1DzKzF47kdDDywXBd48ez7Mtf8aHzjdBVqcFMFXShZeUBhvH9TFSRu
[2022-10-04T18:48:16Z INFO  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Attempting to auto-fund Monero
[2022-10-04T18:48:16Z WARN  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 9 retries left
[2022-10-04T18:48:16Z WARN  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 8 retries left
[2022-10-04T18:48:16Z WARN  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 7 retries left
[2022-10-04T18:48:16Z WARN  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 6 retries left
[2022-10-04T18:48:16Z WARN  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 5 retries left
[2022-10-04T18:48:16Z WARN  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 4 retries left
[2022-10-04T18:48:16Z WARN  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 3 retries left
[2022-10-04T18:48:16Z WARN  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 2 retries left
[2022-10-04T18:48:16Z WARN  farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 1 retries left
[2022-10-04T18:48:16Z ERROR farcaster_node::farcasterd::trade_state_machine] 0x097e…99a0 | Auto-funding Monero transaction failed, pushing to cli, use `swap-cli needs-funding Monero` to retrieve address and amount
[2022-10-04T19:29:24Z WARN  farcaster_node::swapd::runtime] 0x097e…99a0 | Alice, the swap may be cancelled soon. Do not fund anymore

monero-wallet-rpc:

2022-10-04 18:48:14.919 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_transaction_pool_hashes.bin
2022-10-04 18:48:14.919 E Exception at while refreshing, what=no connection to daemon
2022-10-04 18:48:16.059 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.059 E no connection to daemon
2022-10-04 18:48:16.059 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.061 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.061 E no connection to daemon
2022-10-04 18:48:16.062 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.063 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.063 E no connection to daemon
2022-10-04 18:48:16.064 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.065 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.065 E no connection to daemon
2022-10-04 18:48:16.066 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.067 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.067 E no connection to daemon
2022-10-04 18:48:16.068 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.069 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.069 E no connection to daemon
2022-10-04 18:48:16.070 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.071 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.071 E no connection to daemon
2022-10-04 18:48:16.072 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.073 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.073 E no connection to daemon
2022-10-04 18:48:16.074 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.075 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.075 E no connection to daemon
2022-10-04 18:48:16.076 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.077 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.077 E no connection to daemon
2022-10-04 18:48:16.078 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = /get_output_distribution.bin
2022-10-04 18:48:16.110 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_txpool_backlog
2022-10-04 18:48:16.110 E no connection to daemon
2022-10-04 19:57:11.588 W /home/ubuntu/build/monero/src/wallet/wallet2.cpp:14410:N5tools5error23no_connection_to_daemonE: no connection to daemon, request = get_transaction_pool_hashes.bin
2022-10-04 19:57:11.588 E Exception at while refreshing, what=no connection to daemon

@@ -1137,6 +1137,7 @@ fn attempt_transition_to_end(
break;
} else {
warn!("{} | Auto-funding Monero transaction failed with {}, retrying, {} retries left", &swap_id.bright_blue_italic(), err, retries);
tokio::time::sleep(std::time::Duration::from_secs(retries)).await;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear this introduces too much of a delay. In the worst case, it blocks the entire daemon for 55 seconds. If you really need this, I would at the least lower this to either 10's or 100's of ms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the worst case, it blocks the entire daemon for 55 seconds.

Don't exaggerate: it's only 45! :P

Reduced to 10ms increments in 82764f4, so upper bound 450 ms. If this catches most failures within the first two retries, let's cut by another order of magnitude.

@h4sh3d
Copy link
Member

h4sh3d commented Dec 23, 2022

@Lederstrumpf do we still want to add some delays, or did the recent refactors also helped on this?

@TheCharlatan TheCharlatan merged commit f182ec1 into farcaster-project:main Dec 29, 2022
@Lederstrumpf
Copy link
Member Author

@Lederstrumpf do we still want to add some delays, or did the recent refactors also helped on this?

stats from last run:

[2022-12-28T18:46:35Z INFO  farcaster_node::farcasterd::stats] Swapped(4241) | Refunded(33) / Punished(0) | Aborted(0) | Initialized(4314) / AwaitingFundingXMR(0) / AwaitingFundingBTC(0) / FundedXMR(2125) / FundedBTC(2150) / FundingCanceledXMR(8) / FundingCanceledBTC(0)

Autofunding reattempt stats (journalctl _SYSTEMD_INVOCATION_ID=systemctl show -p InvocationID --value farcasterd.service | rg "Auto-funding Monero transaction failed.+" -o | sort -n | uniq -c):

      2 Auto-funding Monero transaction failed, pushing to cli, use `swap-cli needs-funding Monero` to retrieve address and amount
      1 Auto-funding Monero transaction failed with Server error: Failed to get height, retrying, 1 retries left
      1 Auto-funding Monero transaction failed with Server error: Failed to get height, retrying, 2 retries left
      1 Auto-funding Monero transaction failed with Server error: Failed to get height, retrying, 3 retries left
      1 Auto-funding Monero transaction failed with Server error: Failed to get height, retrying, 4 retries left
      1 Auto-funding Monero transaction failed with Server error: Failed to get height, retrying, 5 retries left
      1 Auto-funding Monero transaction failed with Server error: Failed to get height, retrying, 6 retries left
      1 Auto-funding Monero transaction failed with Server error: Failed to get height, retrying, 7 retries left
      1 Auto-funding Monero transaction failed with Server error: Failed to get height, retrying, 8 retries left
      9 Auto-funding Monero transaction failed with Server error: Failed to get height, retrying, 9 retries left
      2 Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 1 retries left
      2 Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 2 retries left
      3 Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 3 retries left
      3 Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 4 retries left
      3 Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 5 retries left
      3 Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 6 retries left
      4 Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 7 retries left
      4 Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 8 retries left
      4 Auto-funding Monero transaction failed with Server error: failed to get output distribution, retrying, 9 retries left

So of the 13 reattempt sequences, 2 failures weren't caught by current reattempts and ended up in a refund. That's 0.05% of the swaps of the run, or 6% of failures. As @TheCharlatan observed, adding a delay on order of seconds can lead to massive congestion for all running swaps. The failure rate's too low to warrant this, but also high enough to warrant at least some delay, imo (lest liquidity providers run an external autofunding monitor, which I think is too much if we can handle with small fc daemon delay).

I've decreased the delay hundredfold and will add to next fc.dev run. If it catches most failures, we can try another order of magnitude decrease in the delay. If it doesn't catch most failures, imo PR should be closed, and liquidity providers handle externally if need be.

@Lederstrumpf
Copy link
Member Author

well: this asynced & @TheCharlatan already merged ^^. Will revert if delay doesn't address the autofund failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants