Skip to content

Fallback chains #100

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

Merged
merged 15 commits into from
May 7, 2025
Merged

Fallback chains #100

merged 15 commits into from
May 7, 2025

Conversation

thewhaleking
Copy link
Collaborator

@thewhaleking thewhaleking commented Apr 25, 2025

Adds subclasses of SubstrateInterface and AsyncSubstrateInterface that allow for handling chain failures by using backup chains. If a sustained network failure is encountered on a chain endpoint, the object will initialize a new connection on the next chain in the fallback_chains list. If the retry_forever flag is set, upon reaching the last chain in fallback_chains, the connection will attempt to iterate over the list (starting with url) again.

E.g.

substrate = RetrySyncSubstrate(
    "wss://entrypoint-finney.opentensor.ai:443",
    fallback_chains=["ws://127.0.0.1:9946"]
)

In this case, if there is a failure on entrypoint-finney, the connection will next attempt to hit localhost. If this
also fails, a MaxRetriesExceeded exception will be raised.

substrate = RetrySyncSubstrate(
    "wss://entrypoint-finney.opentensor.ai:443",
    fallback_chains=["ws://127.0.0.1:9946"],
    retry_forever=True
)

In this case, rather than a MaxRetriesExceeded exception being raised upon failure of the second chain (localhost), the object will again being to initialize a new connection on entrypoint-finney, and then localhost, and so on and so forth.

@thewhaleking thewhaleking marked this pull request as ready for review May 6, 2025 18:53
@thewhaleking thewhaleking changed the title [WIP] fallback chains Fallback chains May 6, 2025
@thewhaleking thewhaleking requested a review from a team May 6, 2025 18:53
Copy link
Contributor

@basfroman basfroman left a comment

Choose a reason for hiding this comment

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

we shouldn't release it without minimum tests coverage of retry behavior

@thewhaleking thewhaleking requested a review from a team May 6, 2025 19:44
@thewhaleking
Copy link
Collaborator Author

thewhaleking commented May 6, 2025

we shouldn't release it without minimum tests coverage of retry behavior

Yeah. Testing it (in an automated, repeatable way) is difficult. Will work on it.

@basfroman
Copy link
Contributor

we shouldn't release it without minimum tests coverage of retry behavior

Yeah. Testing it (in an automated, repeatable way) is difficult. Will work on it.

I think a simple e2e test will be enough for a start:

  1. Start a localnet (fast-blocks enough)
  2. Create a subnet (using regular Substrate class instance), publish some data (for example, a classic commitment)
  3. Recreate the connection with the list ["ws://127.0.0.111:9944", "ws://127.0.0.1:9944"]. The first will give an error, the second will connect successfully
  4. Get a commitment from the subnet and assert it

@thewhaleking thewhaleking merged commit c009d95 into staging May 7, 2025
12 checks passed
@thewhaleking thewhaleking deleted the feat/thewhaleking/fallback-chains branch May 7, 2025 20:18
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.

2 participants