Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@motorina0
Copy link
Collaborator

@motorina0 motorina0 commented Apr 11, 2024

Make the funding source retry count customisable.

Under some conditions a 30 sec retry is too long.

@motorina0 motorina0 requested review from arcbtc, dni and talvasconcelos and removed request for dni April 11, 2024 14:19
@codecov
Copy link

codecov bot commented Apr 11, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 59.97%. Comparing base (e9e69d9) to head (9ee78f3).

Files Patch % Lines
lnbits/app.py 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2404      +/-   ##
==========================================
- Coverage   59.98%   59.97%   -0.01%     
==========================================
  Files          65       65              
  Lines        9433     9434       +1     
==========================================
  Hits         5658     5658              
- Misses       3775     3776       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@prusnak
Copy link
Collaborator

prusnak commented Apr 11, 2024

Under some conditions a 30 sec retry is too long.

Good practice is to use exponential backoff - 1 second, 2 seconds, 4 seconds, etc. up to MAX_RETRIES

So maybe replace:

await asyncio.sleep(sleep_time)

with

await asyncio.sleep(2 ** retry_counter)

and drop the sleep_time completely.

In that case it would be nice to document this exponential behaviour in the .env.example file as a comment explaining that setting FUNDING_SOURCE_MAX_RETRIES=5 will make LNbits retry after 1 second, 2 seconds, 4 seconds, 8 seconds and 16 seconds before stopping and defaulting to VoidWallet.

@motorina0
Copy link
Collaborator Author

Good practice is to use exponential backoff - 1 second, 2 seconds, 4 seconds, etc. up to MAX_RETRIES

True, but the server does not answer any requests until it initialises the funding source.
So better to try and fail faster to VoidWallet than to be un-responsive for a longer time.

Also, this PR is a response to #2403 that removes the retry altogether.

@prusnak
Copy link
Collaborator

prusnak commented Apr 11, 2024

So better to try and fail faster to VoidWallet than to be un-responsive for a longer time.

We can use

await asyncio.sleep(0.2 * (2 ** retry_counter))

so the wait will be 0.2, 0.4, 0.8, 1.6 and 3.2 seconds (total 6.2 seconds) for FUNDING_SOURCE_MAX_RETRIES=5

@motorina0
Copy link
Collaborator Author

motorina0 commented Apr 11, 2024

so the wait will be 0.2, 0.4, 0.8, 1.6 and 3.2 seconds (total 6.2 seconds) for FUNDING_SOURCE_MAX_RETRIES=5

Done, thank you!

image

@motorina0
Copy link
Collaborator Author

Using 0.25 leads to less awkward numbers (sorry for suggesting 0.2 first, I only later realized that 0.25 is nicer)

👍

image

@arcbtc arcbtc merged commit adb8f9b into dev Apr 11, 2024
@arcbtc arcbtc deleted the funding_source_max_retries branch April 11, 2024 16:29
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.

4 participants