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

Start node announcement task after first peer #288

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

srikanth-iyengar
Copy link
Contributor

@srikanth-iyengar srikanth-iyengar commented May 2, 2024

Fixes #204

Introduced a new atomic internal state to track whether the announcement task is started or not
When we connect to some peer, and the announcement broadcast is not started yet, then we update the state and spawn the announcement_broadcast_task

@srikanth-iyengar
Copy link
Contributor Author

srikanth-iyengar commented May 13, 2024

@tnull should we include the new internal state in NodeStatus so that we can add tests or it is not required

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this!

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@srikanth-iyengar srikanth-iyengar force-pushed the feature/204 branch 2 times, most recently from 4d1b1e4 to 3c1013d Compare May 16, 2024 11:25
@@ -38,6 +41,12 @@ where
return Ok(());
}

let is_initial_connection_established =
self.is_initial_connection_established.load(Ordering::Acquire);
if !is_initial_connection_established {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can just store here, although only if we successfully connected the peer below. If you really want to check before storing, you should use compare_exchange.

Note however that we'll also have to reset the value in stop after disconnecting all peers, and probably for good measure also at the beginning of start, as otherwise would still broadcast without being connected after restart.

@@ -144,4 +153,8 @@ where
}
}
}

pub fn get_is_initial_connection_established(&self) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Avoid the get_ prefix as per Rust API Guidelines.

@@ -552,6 +553,11 @@ impl Node {
// We check every 30 secs whether our last broadcast is NODE_ANN_BCAST_INTERVAL away.
let mut interval = tokio::time::interval(Duration::from_secs(30));
loop {
let is_initial_connection_established = connect_cm.get_is_initial_connection_established();
if !is_initial_connection_established {
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would busy-wait until we actually connect which isn't ideal. Rather, we want to block the the task until the first connection came in. Likely, a tokio::sync::watch channel is preferable to an AtomicBool here, as we could just await until we get a changed() and only then enter this loop.

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.

Have first peer connection trigger announcement broadcast
2 participants