Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
network: Update litep2p to v0.5.0 (paritytech#4570)
Browse files Browse the repository at this point in the history
## [0.5.0] - 2023-05-24

This is a small patch release that makes the `FindNode` command a bit
more robst:

- The `FindNode` command now retains the K (replication factor) best
results.
- The `FindNode` command has been updated to handle errors and
unexpected states without panicking.

### Changed

- kad: Refactor FindNode query, keep K best results and add tests
([#114](paritytech/litep2p#114))

---------

Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv authored May 27, 2024
1 parent 2352982 commit ce3e9b7
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 46 deletions.
82 changes: 54 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion substrate/client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ sp-blockchain = { path = "../../primitives/blockchain" }
sp-core = { path = "../../primitives/core" }
sp-runtime = { path = "../../primitives/runtime" }
wasm-timer = "0.2"
litep2p = "0.4.0"
litep2p = "0.5.0"
once_cell = "1.18.0"
void = "1.0.2"
schnellru = "0.2.1"
Expand Down
15 changes: 6 additions & 9 deletions substrate/client/network/src/litep2p/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use litep2p::{
identify::{Config as IdentifyConfig, IdentifyEvent},
kademlia::{
Config as KademliaConfig, ConfigBuilder as KademliaConfigBuilder, KademliaEvent,
KademliaHandle, QueryId, Quorum, Record, RecordKey,
KademliaHandle, QueryId, Quorum, Record, RecordKey, RecordsType,
},
ping::{Config as PingConfig, PingEvent},
},
Expand Down Expand Up @@ -123,8 +123,8 @@ pub enum DiscoveryEvent {
/// Query ID.
query_id: QueryId,

/// Record.
record: Record,
/// Records.
records: RecordsType,
},

/// Record was successfully stored on the DHT.
Expand Down Expand Up @@ -460,16 +460,13 @@ impl Stream for Discovery {
peers: peers.into_iter().collect(),
}))
},
Poll::Ready(Some(KademliaEvent::GetRecordSuccess { query_id, record })) => {
Poll::Ready(Some(KademliaEvent::GetRecordSuccess { query_id, records })) => {
log::trace!(
target: LOG_TARGET,
"`GET_RECORD` succeeded for {query_id:?}: {record:?}",
"`GET_RECORD` succeeded for {query_id:?}: {records:?}",
);

return Poll::Ready(Some(DiscoveryEvent::GetRecordSuccess {
query_id,
record: record.record,
}));
return Poll::Ready(Some(DiscoveryEvent::GetRecordSuccess { query_id, records }));
},
Poll::Ready(Some(KademliaEvent::PutRecordSucess { query_id, key: _ })) =>
return Poll::Ready(Some(DiscoveryEvent::PutRecordSuccess { query_id })),
Expand Down
24 changes: 17 additions & 7 deletions substrate/client/network/src/litep2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ use litep2p::{
crypto::ed25519::Keypair,
executor::Executor,
protocol::{
libp2p::{bitswap::Config as BitswapConfig, kademlia::QueryId},
libp2p::{
bitswap::Config as BitswapConfig,
kademlia::{QueryId, RecordsType},
},
request_response::ConfigBuilder as RequestResponseConfigBuilder,
},
transport::{
Expand Down Expand Up @@ -796,23 +799,30 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkBackend<B, H> for Litep2pNetworkBac
self.peerstore_handle.add_known_peer(peer.into());
}
}
Some(DiscoveryEvent::GetRecordSuccess { query_id, record }) => {
Some(DiscoveryEvent::GetRecordSuccess { query_id, records }) => {
match self.pending_get_values.remove(&query_id) {
None => log::warn!(
target: LOG_TARGET,
"`GET_VALUE` succeeded for a non-existent query",
),
Some((_key, started)) => {
Some((key, started)) => {
log::trace!(
target: LOG_TARGET,
"`GET_VALUE` for {:?} ({query_id:?}) succeeded",
record.key,
key,
);

self.event_streams.send(Event::Dht(
DhtEvent::ValueFound(vec![
let value_found = match records {
RecordsType::LocalStore(record) => vec![
(libp2p::kad::RecordKey::new(&record.key), record.value)
])
],
RecordsType::Network(records) => records.into_iter().map(|peer_record| {
(libp2p::kad::RecordKey::new(&peer_record.record.key), peer_record.record.value)
}).collect(),
};

self.event_streams.send(Event::Dht(
DhtEvent::ValueFound(value_found)
));

if let Some(ref metrics) = self.metrics {
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/network/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ documentation = "https://docs.rs/sc-network-types"
bs58 = "0.5.0"
ed25519-dalek = "2.1"
libp2p-identity = { version = "0.1.3", features = ["ed25519", "peerid"] }
litep2p = "0.4.0"
litep2p = "0.5.0"
multiaddr = "0.17.0"
multihash = { version = "0.17.0", default-features = false, features = ["identity", "multihash-impl", "sha2", "std"] }
rand = "0.8.5"
Expand Down

0 comments on commit ce3e9b7

Please sign in to comment.