-
Notifications
You must be signed in to change notification settings - Fork 64
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
base: main
Are you sure you want to change the base?
Start node announcement task after first peer #288
Conversation
f2be3ad
to
836e986
Compare
@tnull should we include the new internal state in NodeStatus so that we can add tests or it is not required |
There was a problem hiding this 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!
4d1b1e4
to
3c1013d
Compare
3c1013d
to
0573890
Compare
@@ -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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
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