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

feat: Add re-registration on expiry for p2p node #685

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

aidan46
Copy link
Contributor

@aidan46 aidan46 commented Jan 21, 2025

Description

Add a TTL for the registration node and auto re-register when the registration expires. The re-registration is achieved using an Interval that ticks at expiry.

Something that does not seem right to me is when re-registering, the port of the node registering changes, see the logs below. I have tried unregistering first but this messes up the connection. I have also tried adding a delay but this does not solve it either. I have looked into the code of the rendezvous server register event and the Registrations add method, these seem to indicate that the old registration does get booted.

The above issue has been fixed by adding the external address only once. Adding the external address every time we register makes it change.

Logs from bootstrap node INFO full: Peer 12D3KooWEs4rKaEAmcYpnjiPf834DTMfefeKe3SfFydepwANGWrx registered for namespace 'polka-storage' for 5 seconds Peer Addresses: [/ip4/127.0.0.1/tcp/54401] INFO full: Registration for peer 12D3KooWEs4rKaEAmcYpnjiPf834DTMfefeKe3SfFydepwANGWrx expired in namespace polka-storage INFO full: Connected to 12D3KooWEs4rKaEAmcYpnjiPf834DTMfefeKe3SfFydepwANGWrx INFO full: Peer 12D3KooWEs4rKaEAmcYpnjiPf834DTMfefeKe3SfFydepwANGWrx registered for namespace 'polka-storage' for 5 seconds Peer Addresses: [/ip4/127.0.0.1/tcp/54402, /ip4/127.0.0.1/tcp/54401]
Logs from discovery node INFO discover: New peer entered with addresses [ /ip4/127.0.0.1/tcp/54838, ] peer_id=12D3KooWEs4rKaEAmcYpnjiPf834DTMfefeKe3SfFydepwANGWrx INFO discover: Peer updated peer_id=12D3KooWEs4rKaEAmcYpnjiPf834DTMfefeKe3SfFydepwANGWrx address=/ip4/127.0.0.1/tcp/54841 INFO discover: Peer updated peer_id=12D3KooWEs4rKaEAmcYpnjiPf834DTMfefeKe3SfFydepwANGWrx address=/ip4/127.0.0.1/tcp/54842

@aidan46 aidan46 self-assigned this Jan 21, 2025
@aidan46 aidan46 added the enhancement New feature or request label Jan 21, 2025
@aidan46 aidan46 linked an issue Jan 21, 2025 that may be closed by this pull request
@aidan46 aidan46 added this to the Phase 3 milestone Jan 21, 2025
@aidan46 aidan46 added ready for review Review is needed and removed ready for review Review is needed labels Jan 21, 2025
docs/src/storage-provider-cli/server.md Outdated Show resolved Hide resolved
storage-provider/server/src/p2p/mod.rs Outdated Show resolved Hide resolved
storage-provider/server/src/p2p/register.rs Outdated Show resolved Hide resolved
storage-provider/server/src/config.rs Outdated Show resolved Hide resolved
rendezvous::server::Event::RegistrationExpired(registration),
)) => {
tracing::info!(
"Registration for peer {} expired in namespace {}",
Copy link
Contributor

Choose a reason for hiding this comment

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

What do we do when the registration expires? What does it mean for the node to be registered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the registration expires the registration node re-registers automatically.
A node being registered means that they have identified themselves with the bootstrap node and shared their Registration with them. This Registration holds information like their Peer ID and multiaddr.

@aidan46 aidan46 added ready for review Review is needed and removed ready for review Review is needed labels Jan 22, 2025
storage-provider/server/src/p2p/register.rs Outdated Show resolved Hide resolved
storage-provider/server/src/p2p/register.rs Outdated Show resolved Hide resolved
storage-provider/server/src/p2p/register.rs Show resolved Hide resolved
storage-provider/server/src/p2p/mod.rs Show resolved Hide resolved
/// TTL of the p2p registration in seconds
#[serde(default = "default_registration_ttl")]
#[arg(long, default_value_t = DEFAULT_REGISTRATION_TTL)]
pub(crate) registration_ttl: u64,
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better if we use Duration here. That way the reader can immediately see how the duration is parsed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the tick it makes sense but we re-use this value for the register call in the swarm which expects a Option<u64>

Copy link
Contributor

Choose a reason for hiding this comment

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

It's ok as is, but for reference, you can always just .as_secs

@aidan46 aidan46 requested a review from cernicc January 23, 2025 05:03
@aidan46 aidan46 added ready for review Review is needed and removed ready for review Review is needed labels Jan 23, 2025
registration.namespace
);
}
other => tracing::debug!("Encountered event: {other:?}"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this catch the previous ConnectionEstablished and ConnectionClosed events?

// Poll tick every TTL to re-register.
// First tick completes immediately.
_ = register_tick.tick() => {
tracing::info!("Registering with p2p node");
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 @cernicc knows a bit more than me on this, but I think these logs should be contained inside an #[instrument] or a span to keep context

return Err(P2PError::RegistrationFailed(rendezvous_node));
}
other => tracing::debug!("Encountered event: {other:?}"),
}
Ok(())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A docstring would be appreciated

Copy link
Contributor

@jmg-duarte jmg-duarte left a comment

Choose a reason for hiding this comment

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

It's ok as is, but there's just a bit of room for improvement

Copy link
Contributor

@jmg-duarte jmg-duarte left a comment

Choose a reason for hiding this comment

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

(I meant to approve)

@@ -158,11 +164,10 @@ pub async fn run_register_node(
},
_ = token.cancelled() => {
tracing::info!("P2P node has been stopped by the cancellation token...");
tracker.close();
tracker.wait().await;
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for using TaskTracker here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, I don't even see what task this is tracking. I think this might be a leftover from an experiment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready for review Review is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(polka-storage-provider): Add re-registration for p2p node
4 participants