Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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