-
Notifications
You must be signed in to change notification settings - Fork 0
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 P2P functionality #666
base: develop
Are you sure you want to change the base?
Conversation
Add P2P bootstrap and register behaviour to the polka-storage-provider-server.
13fb051
to
a3e3803
Compare
storage-provider/server/src/p2p.rs
Outdated
@@ -52,24 +55,29 @@ pub enum P2PError { | |||
P2PTransportError(#[from] libp2p::TransportError<std::io::Error>), | |||
} | |||
|
|||
fn create_keypair<P: AsRef<Path> + std::fmt::Debug>(path: P) -> Result<Keypair, P2PError> { | |||
pub fn create_keypair<P: AsRef<Path> + std::fmt::Debug>(path: P) -> Result<Keypair, P2PError> { |
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.
Does it need to be a P2P error? Or do they wrap around something more specific we could use?
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.
Could we also support the @ dialect or its not practical?
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.
In this function the P2P error wraps around ed25519_dalek::pkcs8::Error
and libp2p::identity::DecodingError
.
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.
Do you mean support to @ dialect when using a PEM file and otherwise put the private key straight into the config file?
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.
In this function the P2P error wraps around
ed25519_dalek::pkcs8::Error
andlibp2p::identity::DecodingError
.
We could probably use the lower one for more accurate errors? Not sure, not super important
Do you mean support to @ dialect when using a PEM file and otherwise put the private key straight into the config file?
Yes
@@ -0,0 +1,3 @@ | |||
keypair = "@storage-provider/server/p2p-example-config/private.pem" |
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.
wrong path, should be to the '@examples`
@@ -198,7 +198,7 @@ impl pallet_storage_provider::Config for Test { | |||
type RuntimeEvent = RuntimeEvent; | |||
type Randomness = DummyRandomnessGenerator<Self>; | |||
type AuthorVrfHistory = DummyRandomnessGenerator<Self>; | |||
type PeerId = BoundedVec<u8, ConstU32<32>>; // Max length of SHA256 hash | |||
type PeerId = BoundedVec<u8, ConstU32<42>>; // https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#peer-ids |
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 guess it should be a const
in primitives
?
token: CancellationToken, | ||
) -> Result<(), P2PError> { | ||
info!("Starting P2P bootstrap node"); | ||
let tracker = TaskTracker::new(); |
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.
What's the reason for using tracker here? Can't we just spawn the task and await it in a select?
rendezvous_point, | ||
rendezvous_point_address, | ||
None, | ||
Namespace::from_static("polka-storage"), |
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.
const
|
||
/// Register the peer with the rendezvous point. | ||
/// The ttl is how long the peer will remain registered in seconds. | ||
async fn register( |
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 don't understand why we need to have two different swarms :( I'll need to read up on that.
Description
This PR adds bootstrap and registration p2p node functionality to the polka-storage-provider-server. The node type is selected by passing the node-type argument into the CLI (bootstrap or registration). Configuration is read from a TOML file, see the example in the p2p-example-config folder. The P2P network supports an ED25519 private key in PEM file format.
The
generate-peer-id
command has been added to the polka-storage-provider-client. This command generates a peer ID from an ED25519 public key PEM file and writes it to a file or stdout, depending on the--file
argument.Note:
I have not added any P2P discovery, this will be implemented in the fetching application. I can add a discovery example if needed.