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

fix: apply fibonacci backoff delay and threshold #663

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

cazala
Copy link
Member

@cazala cazala commented Jan 13, 2025

This PR implements a fibonacci backoff strategy for transaction polling. The changes improve the reliability of transaction status monitoring while reducing unnecessary network calls.

Core Changes (478aeda)

  • Implemented fibonacci backoff delay for transaction polling
  • Added DROPPED_TRANSACTION_THRESHOLD constant (24 hours)
  • Renamed TRANSACTION_FETCH_DELAY to INITIAL_BACKOFF_DELAY
  • Added attempt counter to track retry attempts
  • Applied fibonacci backoff in multiple transaction handlers:
    • Cross-chain transactions
    • Regular transactions
    • Replace transactions
    • Reverted transactions
  • Added expiration check for dropped transactions

Test Suite Changes (c12b2df)

  • Added comprehensive test suite for transaction polling
  • Exported internal functions and constants for testing
  • Added test cases for:
    • Fibonacci delay calculations
    • Transaction confirmation flows
    • Transaction expiration scenarios

Technical Details

The fibonacci backoff strategy increases the delay between polling attempts using the fibonacci sequence, starting with an initial delay of 2 seconds. This helps reduce network load while maintaining responsiveness for transaction status updates.

Copy link
Contributor

@LautaroPetaccio LautaroPetaccio left a comment

Choose a reason for hiding this comment

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

Great PR! I've left some comments to review

prev = current
current = next
}
return current * INITIAL_BACKOFF_DELAY
Copy link
Contributor

Choose a reason for hiding this comment

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

If we multiply the Fibonacci number with the initial backoff, we'll get double the Fibonacci number. If we want to start with a 2 seconds delay, we could start at the attempt number 2, what do you think about it?

Here we can just multiply the current Fibonacci value by 1000 to have seconds.

Suggested change
return current * INITIAL_BACKOFF_DELAY
return current * 1000

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea of that variable was to be able to configure the speed while keeping the fibonacci exponential curve. I changed the name to be more accurate BACKOFF_DELAY_MULTIPLIER and made it faster so it follows the fibonacci sequence instead of the double of the curve.

src/modules/transaction/sagas.spec.ts Outdated Show resolved Hide resolved
src/modules/transaction/sagas.spec.ts Outdated Show resolved Hide resolved
@cazala cazala force-pushed the fix/apply-fibonacci-delay-and-threshold branch from 2a56bec to eaf8a84 Compare January 14, 2025 15:29
@cazala cazala merged commit 114d360 into master Jan 14, 2025
3 checks passed
@cazala cazala deleted the fix/apply-fibonacci-delay-and-threshold branch January 14, 2025 17:51
Copy link

🎉 This PR is included in version 23.23.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants