Skip to content

Conversation

@merolish
Copy link
Contributor

Summary

  • backoff reset after several minutes (a pattern we use elsewhere)
  • use broadcast::channel instead of mpsc::channel to fan out to relayers at Ali's suggestion
  • default config file fix
  • drain pending updates vector

Rationale

How has this been tested?

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

@vercel
Copy link

vercel bot commented Jun 10, 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 10, 2025 10:35pm
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2025 10:35pm
developer-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2025 10:35pm
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2025 10:35pm
entropy-explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2025 10:35pm
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2025 10:35pm
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2025 10:35pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2025 10:35pm

let mut first_failure_time = Instant::now();
let mut failure_count = 0;

loop {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still doesn't use retry, I know. 😄

Copy link
Contributor

@darunrs darunrs left a comment

Choose a reason for hiding this comment

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

LGTM. Can wait for one more approval to merge.

@keyvankhademi keyvankhademi requested a review from Copilot June 11, 2025 16:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the relayer session and publisher to use a broadcast channel, adds a failure reset timer for backoff retries, fixes the default config file path, and ensures pending updates are drained.

  • Switch mpsc channels to broadcast channels for fan-out to multiple relayer tasks
  • Add a timer to reset backoff after 5 minutes without failures
  • Update default config path and drain pending updates instead of clearing

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/relayer_session.rs Converted to broadcast::channel, made session struct public, added backoff reset logic, handled lagged receiver errors
src/main.rs Changed default config file path to config/config.toml
src/lazer_publisher.rs Replaced custom RelayerSender with broadcast sender, drained pending updates before publishing
Comments suppressed due to low confidence (4)

pyth-lazer-agent/src/relayer_session.rs:61

  • Exposing all fields of RelayerSessionTask publicly can lead to misuse; consider adding a constructor or builder method and keeping fields private to maintain encapsulation.
pub struct RelayerSessionTask {

pyth-lazer-agent/src/relayer_session.rs:120

  • [nitpick] The variable name recv_result is generic; consider renaming to something like transaction_result for clearer intent.
recv_result = self.receiver.recv() => {

pyth-lazer-agent/src/relayer_session.rs:134

  • Add unit tests to simulate RecvError::Lagged and RecvError::Closed paths to ensure logging and bail behavior works as expected.
broadcast::error::RecvError::Lagged(skipped_count) => {

pyth-lazer-agent/src/relayer_session.rs:78

  • Consider adding tests to verify that the backoff strategy is reset after FAILURE_RESET_TIME has elapsed.
const FAILURE_RESET_TIME: Duration = Duration::from_secs(300);

return;
}
Err(e) => {
if first_failure_time.elapsed() > FAILURE_RESET_TIME {
Copy link

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

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

Currently failure_count is only reset after the timer expires; on a successful WebSocket session you should also reset failure_count (and possibly first_failure_time) so that retries start fresh after each successful connection.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A successful session will go indefinitely so I'll leave this as is.

@merolish merolish merged commit 44b0b50 into main Jun 11, 2025
9 checks passed
@merolish merolish deleted the mike/lazer-agent-2 branch June 11, 2025 20:55
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.

4 participants