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

Add pieces announcement through DSN. #847

Merged

Conversation

shamil-gadelshin
Copy link
Member

@shamil-gadelshin shamil-gadelshin commented Oct 3, 2022

This PR starts adding the archival storage layer support for the DSN v2. Fixes #846

Changes

  • add multihash conversion to PieceIndexHash primitive
  • add announce_piece and get_piece_providers methods to Node in the networking crate
  • change gossipsub archival data publication to Kademlia version
  • add provider support to custom_data_store in the networking crate
  • added 'announce-piece' example to the networking crate

Comments

  • custom_data_store doesn't support providers' removing yet

Code contributor checklist:

- introduce ‘announce_piece’ for Node
- introduce ‘get_piece_providers for Node
- add provider’s support for the custom_data_store
@shamil-gadelshin shamil-gadelshin added networking Subspace networking (DSN) node Node (service library/node app) labels Oct 3, 2022
@shamil-gadelshin shamil-gadelshin self-assigned this Oct 3, 2022
Copy link
Member

@nazar-pc nazar-pc left a comment

Choose a reason for hiding this comment

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

Announcement is great, but we also need to have a way to cancel announcement. What I imagine is that announce returns some guard object you need to keep around for as long as you're providing the data and once you're not anymore you just drop it and cancellation will be sent over the network.

@@ -19,6 +19,7 @@ dusk-bls12_381 = { version = "0.11", default-features = false, features = ["allo
dusk-bytes = "0.1"
dusk-plonk = { version = "0.12.0", default-features = false, features = ["alloc"], git = "https://github.com/subspace/plonk", rev = "193e68ba3d20f737d730e4b6edc757e4f639e7c3" }
hex = { version = "0.4.3", default-features = false }
libp2p = {version = "0.46.1", optional=true, default-features = false }
Copy link
Member

Choose a reason for hiding this comment

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

Hm... I think it is really quite undesirable to make subspace-core-primitives depend on libp2p 😞

Also attention to detail:

Suggested change
libp2p = {version = "0.46.1", optional=true, default-features = false }
libp2p = { version = "0.46.1", optional = true, default-features = false }

Copy link
Member Author

Choose a reason for hiding this comment

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

Last time we had this conversation, you suggested adding dependencies. We need such a conversion (PieceIndexHash -> Multihash), we'll probably need some more conversions for primitive types. An alternative would be creating explicit conversion methods in the networking crate.

Copy link
Member

Choose a reason for hiding this comment

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

Well, PieceIndexHash already has AsRef<[u8]> implemented for it. Which means all you need to write is MultihashDigest::digest(&Code::Identity, piece_index_hash.as_ref()), which depending on how frequently that is used likely not worth building libp2p, which takes non-negligible amount of time, just to have From conversion.

Copy link
Member

Choose a reason for hiding this comment

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

Also one whitespace is still missing with latest changes.

crates/subspace-networking/src/node.rs Outdated Show resolved Hide resolved
crates/subspace-service/src/dsn.rs Outdated Show resolved Hide resolved
Copy link
Member Author

@shamil-gadelshin shamil-gadelshin left a comment

Choose a reason for hiding this comment

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

I agree that we need a provider removing mechanism. I wanted to add it using Kademlia's builtin features (provider ttl and republication interval). However, I wanted this changes in the next PR closer to the new plotting, when we will have pulling pieces.

It's not a problem though, please, let me know if you want it in this PR - I'll initialize these constants and add providers' removal code to the PR.

@@ -19,6 +19,7 @@ dusk-bls12_381 = { version = "0.11", default-features = false, features = ["allo
dusk-bytes = "0.1"
dusk-plonk = { version = "0.12.0", default-features = false, features = ["alloc"], git = "https://github.com/subspace/plonk", rev = "193e68ba3d20f737d730e4b6edc757e4f639e7c3" }
hex = { version = "0.4.3", default-features = false }
libp2p = {version = "0.46.1", optional=true, default-features = false }
Copy link
Member Author

Choose a reason for hiding this comment

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

Last time we had this conversation, you suggested adding dependencies. We need such a conversion (PieceIndexHash -> Multihash), we'll probably need some more conversions for primitive types. An alternative would be creating explicit conversion methods in the networking crate.

Copy link
Member

@nazar-pc nazar-pc left a comment

Choose a reason for hiding this comment

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

TTL and republish are useful, but I believe there is also a way to explicitly remove it, which we can use for convenience. I wish there was a TODO for that, but nothing in this PR is necessarily blocking.

@@ -19,6 +19,7 @@ dusk-bls12_381 = { version = "0.11", default-features = false, features = ["allo
dusk-bytes = "0.1"
dusk-plonk = { version = "0.12.0", default-features = false, features = ["alloc"], git = "https://github.com/subspace/plonk", rev = "193e68ba3d20f737d730e4b6edc757e4f639e7c3" }
hex = { version = "0.4.3", default-features = false }
libp2p = {version = "0.46.1", optional=true, default-features = false }
Copy link
Member

Choose a reason for hiding this comment

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

Well, PieceIndexHash already has AsRef<[u8]> implemented for it. Which means all you need to write is MultihashDigest::digest(&Code::Identity, piece_index_hash.as_ref()), which depending on how frequently that is used likely not worth building libp2p, which takes non-negligible amount of time, just to have From conversion.

@@ -19,6 +19,7 @@ dusk-bls12_381 = { version = "0.11", default-features = false, features = ["allo
dusk-bytes = "0.1"
dusk-plonk = { version = "0.12.0", default-features = false, features = ["alloc"], git = "https://github.com/subspace/plonk", rev = "193e68ba3d20f737d730e4b6edc757e4f639e7c3" }
hex = { version = "0.4.3", default-features = false }
libp2p = {version = "0.46.1", optional=true, default-features = false }
Copy link
Member

Choose a reason for hiding this comment

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

Also one whitespace is still missing with latest changes.

@shamil-gadelshin
Copy link
Member Author

TTL and republish are useful, but I believe there is also a way to explicitly remove it, which we can use for convenience. I wish there was a TODO for that, but nothing in this PR is necessarily blocking.

Turns out that TTL works only for the receiving peers and doesn't work for announcing peers. So, the stop_providing is mandatory. I will add it to the next PR.

I will format Cargo.toml again, but I'm not following about libp2p as a dependency. I agree that it is a relatively heavy dependency, but we have heavy dependencies already like dusk crates.

@nazar-pc
Copy link
Member

nazar-pc commented Oct 5, 2022

I agree that it is a relatively heavy dependency, but we have heavy dependencies already like dusk crates.

Dusk crates are foundational, you'll have to write a lot of tricky code to get the same results as API provided by subspace-core-primitives. libp2p doesn't provide any new APIs, just a convenience conversion that saves you a few characters, but doesn't achieve anything substantial to justify adding it to dependencies IMHO.

@shamil-gadelshin
Copy link
Member Author

Dusk crates are foundational, you'll have to write a lot of tricky code to get the same results as API provided by subspace-core-primitives. libp2p doesn't provide any new APIs, just a convenience conversion that saves you a few characters, but doesn't achieve anything substantial to justify adding it to dependencies IMHO.

Let's wait for some issues with this code, I'm not sure we will find any but feel free to move the conversion code to the networking crate any moment you found one.

@nazar-pc
Copy link
Member

nazar-pc commented Oct 5, 2022

I mean the immediate issue is that everything (quite literally) depends on subspace-core-primitives, now everything effectively depends on libp2p and all of its numerous dependencies too, sequentializing/slowing down build times.

@shamil-gadelshin shamil-gadelshin merged commit 37e044f into subspace:main Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
networking Subspace networking (DSN) node Node (service library/node app)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DSN. Add pieces' data source on nodes
2 participants