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

RPC as a fallback #467

Merged
merged 15 commits into from
Mar 11, 2025
Merged

RPC as a fallback #467

merged 15 commits into from
Mar 11, 2025

Conversation

DZakh
Copy link
Member

@DZakh DZakh commented Mar 7, 2025

Part 1: #464
Part 2: #465

Part 3:

  • Display rpc host in the source name
  • Stop using Ethers.js for Height checks
  • Prevent exit when fallback fails
  • Switch between sync sources on backoff error
  • Add tests

@DZakh DZakh requested a review from JonoPrest March 7, 2025 15:32
Comment on lines 307 to 331
| Source.GetItemsError(error) => {
// TODO: When we start handling fetch failures,
// we shouldn't delete the source from the set
// but keep it for retries. Still need to delete
// for cases like UnsupportedSelection which are
// not retryable
let notAlreadyDeleted = sourceManager.sources->Utils.Set.delete(source)

// In case there are multiple partitions
// failing at the same time. Log only once
if notAlreadyDeleted {
switch error {
| UnsupportedSelection({message}) => logger->Logging.childError(message)
| FailedGettingFieldSelection({message, blockNumber, logIndex})
| FailedParsingItems({message, blockNumber, logIndex}) =>
logger->Logging.childError({
"msg": message,
"blockNumber": blockNumber,
"logIndex": logIndex,
})
}
}

switch sourceManager->getNextActiveSource {
| None => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not the most robust logic, and can be improved in the future. But currently it only applies to RPC data-sources and good enough to prevent Fallback sources from killing the indexer when there are still other sources.

}
}
// TODO: Handle more error cases and hang/retry instead of throwing
| exn => exn->ErrorHandling.mkLogAndRaise(~logger, ~msg="Failed to fetch block Range")
Copy link
Member Author

Choose a reason for hiding this comment

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

HyperSync will fail as before

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I catch it and dispatchAction(ErrorExit(errHandler)) or simply throwing is fine?

@DZakh DZakh mentioned this pull request Mar 10, 2025
let backoff = if retry === 0 {
1
} else {
retry * backoffMultiplicative
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets make this exponential

Comment on lines 361 to 362
// Hang until the process is terminated
await Promise.make((_, _) => ())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets throw here

Comment on lines 766 to 768
~executeQuery=async query => {
let response = await chainFetcher.sourceManager->executeQuery(~query, ~currentBlockHeight)
dispatchAction(PartitionQueryResponse({chain, response, query}))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets keep the error exit explicit with try catch

Copy link
Collaborator

@JonoPrest JonoPrest left a comment

Choose a reason for hiding this comment

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

Great! 🥳

@DZakh DZakh changed the title RPC fallback final touches RPC as a fallback Mar 11, 2025
@DZakh DZakh changed the base branch from dz/fallback-rpc-2 to main March 11, 2025 12:20
@DZakh DZakh enabled auto-merge (squash) March 11, 2025 12:20
@DZakh DZakh merged commit 5d5162e into main Mar 11, 2025
1 check passed
@DZakh DZakh deleted the dz/fallback-rpc-3 branch March 11, 2025 12:28
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