-
Notifications
You must be signed in to change notification settings - Fork 301
feat(fortuna): Multiple replica support #2812
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
tejasbadadare
merged 11 commits into
main
from
devin/1750801144-fortuna-multiple-replicas
Jun 26, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a66fe6e
feat(fortuna): implement multiple replica support with sequence numbe…
devin-ai-integration[bot] 4801859
feat(fortuna): add delayed processing for backup replicas
devin-ai-integration[bot] 0c76fa6
docs(fortuna): add comprehensive multi-replica setup documentation
devin-ai-integration[bot] b3f630f
Merge branch 'devin/1750801144-fortuna-multiple-replicas' of https://…
devin-ai-integration[bot] 631e71d
update sample config
tejasbadadare ac5fb7a
refactor(fortuna): streamline keeper configuration and improve event …
tejasbadadare 02f280d
feat(fortuna): add provider arg to entropy load testing script
tejasbadadare 07d67bc
fix(fortuna): improve config and replica logic
tejasbadadare 3ebfbb9
fix(fortuna): names, config check
tejasbadadare 4755ce6
bump version
tejasbadadare 1a3a401
Merge branch 'main' of github.com:pyth-network/pyth-crosschain into d…
tejasbadadare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,55 @@ pub async fn process_event_with_backoff( | |
return Ok(()); | ||
} | ||
|
||
// If replica config is present, we're running with multiple instances. | ||
// The incoming request is assigned by modulo operation on the sequence number | ||
// and the total number of replicas. If our replica_id is the primary for this sequence number, | ||
// we process the request directly. If our replica_id is a backup, we wait for the delay and | ||
// then check if the request is still open. If it is, we process it as a backup replica. | ||
if let Some(replica_config) = &process_param.replica_config { | ||
let assigned_replica = event.sequence_number % replica_config.total_replicas; | ||
let is_primary_replica = assigned_replica == replica_config.replica_id; | ||
|
||
if is_primary_replica { | ||
tracing::debug!("Processing request as primary replica"); | ||
} else { | ||
tracing::debug!("Processing request as backup replica"); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can merge these 2 logs |
||
tracing::info!("Waiting before processing as backup replica"); | ||
tokio::time::sleep(tokio::time::Duration::from_secs( | ||
replica_config.backup_delay_seconds, | ||
)) | ||
.await; | ||
|
||
// Check if the request is still open after the delay. | ||
// If it is, we will process it as a backup replica. | ||
match chain_state | ||
.contract | ||
.get_request(event.provider_address, event.sequence_number) | ||
.await | ||
{ | ||
Ok(Some(_)) => { | ||
tracing::info!( | ||
delay_seconds = replica_config.backup_delay_seconds, | ||
"Request still open after delay, processing as backup replica" | ||
); | ||
} | ||
Ok(None) => { | ||
tracing::debug!( | ||
"Request already fulfilled by primary replica during delay, skipping" | ||
); | ||
return Ok(()); | ||
} | ||
Err(e) => { | ||
tracing::warn!( | ||
error = ?e, | ||
"Error checking request status after delay, processing as backup replica" | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
let account_label = AccountLabel { | ||
chain_id: chain_state.id.clone(), | ||
address: chain_state.provider_address.to_string(), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.