Skip to content

Conversation

tejasbadadare
Copy link
Contributor

@tejasbadadare tejasbadadare commented Jun 25, 2025

Summary

Implemented multiple Fortuna replica support with modulo-based request assignment and configurable backup delays.

Rationale

We want to improve Fortuna's reliability through redundancy, but naively running multiple Fortuna instances caused race conditions and gas waste. Now we distribute requests to specific replicas via sequence_number % total_replicas. All replicas still see all requests, so if a replica doesn't fulfill its assigned request, the others will try to fulfill it after the set delay.

The replica assignment & delay is implemented in process_event_with_backoff, which plays well with the block delay and retry mechanisms. It kicks in after the block delay has already elapsed, so the effective latency for requests missed by their assigned replica is block delay + replica delay.

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

Tested manually, works well on monad testnet. Stress tested it a bit with the load tester script and both instances were happy. Tested out killing one of them and the other one picks up the requests after the delay as expected.

devin-ai-integration bot and others added 4 commits June 24, 2025 21:59
- Add configurable time delay before backup replicas check request status
- Backup replicas now wait backup_delay_seconds before attempting fulfillment
- Add backup_delay_seconds field to ReplicaConfig with default of 30 seconds
- Improves reliability by reducing race conditions between replicas

Co-Authored-By: Tejas Badadare <[email protected]>
- Add Multiple Replica Setup section to README.md with modulo assignment explanation
- Add replica_config examples to config.sample.yaml for 2, 3, and 5 replica setups
- Include deployment considerations, failover behavior, and wallet separation requirements
- Add validation for backup_delay_seconds > 0 to prevent race conditions

Co-Authored-By: Tejas Badadare <[email protected]>
Copy link

vercel bot commented Jun 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 5:46pm
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 5:46pm
developer-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 5:46pm
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 5:46pm
entropy-explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 5:46pm
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 5:46pm
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 5:46pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 5:46pm

…processing

- Updated config.sample.yaml by removing unnecessary blank lines.
- Changed backup_delay_seconds in README.md from 45 to 30 for consistency.
- Refactored run_keeper_threads to accept KeeperConfig directly instead of private_key.
- Enhanced run function to handle keeper configuration more effectively.
- Added comments in process_event_with_backoff to clarify primary and backup replica logic.
@vercel vercel bot temporarily deployed to Preview – insights June 26, 2025 00:41 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference June 26, 2025 00:41 Inactive
@vercel vercel bot temporarily deployed to Preview – staking June 26, 2025 00:41 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-debugger June 26, 2025 00:41 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals June 26, 2025 00:41 Inactive
Copy link
Contributor

@m30m m30m left a comment

Choose a reason for hiding this comment

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

If you are planning to deploy these changes, please bump the Cargo version too.

}
}
}
// If no replica config we are running standalone, process all requests directly
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put this comment at the top of this block. I generally expect comments to describe the next block or line but this seems to be a comment for a non-existent else block

tracing::debug!("Processing request as primary replica");
} else {
tracing::debug!("Processing request as backup replica");

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can merge these 2 logs

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