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

Commit ce3e9b7

Browse files
authored
network: Update litep2p to v0.5.0 (paritytech#4570)
## [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]>
1 parent 2352982 commit ce3e9b7

File tree

5 files changed

+79
-46
lines changed

5 files changed

+79
-46
lines changed

Cargo.lock

Lines changed: 54 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/client/network/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ sp-blockchain = { path = "../../primitives/blockchain" }
5959
sp-core = { path = "../../primitives/core" }
6060
sp-runtime = { path = "../../primitives/runtime" }
6161
wasm-timer = "0.2"
62-
litep2p = "0.4.0"
62+
litep2p = "0.5.0"
6363
once_cell = "1.18.0"
6464
void = "1.0.2"
6565
schnellru = "0.2.1"

substrate/client/network/src/litep2p/discovery.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use litep2p::{
3434
identify::{Config as IdentifyConfig, IdentifyEvent},
3535
kademlia::{
3636
Config as KademliaConfig, ConfigBuilder as KademliaConfigBuilder, KademliaEvent,
37-
KademliaHandle, QueryId, Quorum, Record, RecordKey,
37+
KademliaHandle, QueryId, Quorum, Record, RecordKey, RecordsType,
3838
},
3939
ping::{Config as PingConfig, PingEvent},
4040
},
@@ -123,8 +123,8 @@ pub enum DiscoveryEvent {
123123
/// Query ID.
124124
query_id: QueryId,
125125

126-
/// Record.
127-
record: Record,
126+
/// Records.
127+
records: RecordsType,
128128
},
129129

130130
/// Record was successfully stored on the DHT.
@@ -460,16 +460,13 @@ impl Stream for Discovery {
460460
peers: peers.into_iter().collect(),
461461
}))
462462
},
463-
Poll::Ready(Some(KademliaEvent::GetRecordSuccess { query_id, record })) => {
463+
Poll::Ready(Some(KademliaEvent::GetRecordSuccess { query_id, records })) => {
464464
log::trace!(
465465
target: LOG_TARGET,
466-
"`GET_RECORD` succeeded for {query_id:?}: {record:?}",
466+
"`GET_RECORD` succeeded for {query_id:?}: {records:?}",
467467
);
468468

469-
return Poll::Ready(Some(DiscoveryEvent::GetRecordSuccess {
470-
query_id,
471-
record: record.record,
472-
}));
469+
return Poll::Ready(Some(DiscoveryEvent::GetRecordSuccess { query_id, records }));
473470
},
474471
Poll::Ready(Some(KademliaEvent::PutRecordSucess { query_id, key: _ })) =>
475472
return Poll::Ready(Some(DiscoveryEvent::PutRecordSuccess { query_id })),

substrate/client/network/src/litep2p/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ use litep2p::{
5656
crypto::ed25519::Keypair,
5757
executor::Executor,
5858
protocol::{
59-
libp2p::{bitswap::Config as BitswapConfig, kademlia::QueryId},
59+
libp2p::{
60+
bitswap::Config as BitswapConfig,
61+
kademlia::{QueryId, RecordsType},
62+
},
6063
request_response::ConfigBuilder as RequestResponseConfigBuilder,
6164
},
6265
transport::{
@@ -796,23 +799,30 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkBackend<B, H> for Litep2pNetworkBac
796799
self.peerstore_handle.add_known_peer(peer.into());
797800
}
798801
}
799-
Some(DiscoveryEvent::GetRecordSuccess { query_id, record }) => {
802+
Some(DiscoveryEvent::GetRecordSuccess { query_id, records }) => {
800803
match self.pending_get_values.remove(&query_id) {
801804
None => log::warn!(
802805
target: LOG_TARGET,
803806
"`GET_VALUE` succeeded for a non-existent query",
804807
),
805-
Some((_key, started)) => {
808+
Some((key, started)) => {
806809
log::trace!(
807810
target: LOG_TARGET,
808811
"`GET_VALUE` for {:?} ({query_id:?}) succeeded",
809-
record.key,
812+
key,
810813
);
811814

812-
self.event_streams.send(Event::Dht(
813-
DhtEvent::ValueFound(vec![
815+
let value_found = match records {
816+
RecordsType::LocalStore(record) => vec![
814817
(libp2p::kad::RecordKey::new(&record.key), record.value)
815-
])
818+
],
819+
RecordsType::Network(records) => records.into_iter().map(|peer_record| {
820+
(libp2p::kad::RecordKey::new(&peer_record.record.key), peer_record.record.value)
821+
}).collect(),
822+
};
823+
824+
self.event_streams.send(Event::Dht(
825+
DhtEvent::ValueFound(value_found)
816826
));
817827

818828
if let Some(ref metrics) = self.metrics {

substrate/client/network/types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ documentation = "https://docs.rs/sc-network-types"
1313
bs58 = "0.5.0"
1414
ed25519-dalek = "2.1"
1515
libp2p-identity = { version = "0.1.3", features = ["ed25519", "peerid"] }
16-
litep2p = "0.4.0"
16+
litep2p = "0.5.0"
1717
multiaddr = "0.17.0"
1818
multihash = { version = "0.17.0", default-features = false, features = ["identity", "multihash-impl", "sha2", "std"] }
1919
rand = "0.8.5"

0 commit comments

Comments
 (0)