Skip to content

Commit

Permalink
Litep2p version 0.5.0 backport to 1.12.0 (#4606)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv authored May 28, 2024
1 parent d3bf1a8 commit e664e98
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 46 deletions.
83 changes: 55 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 = { git = "https://github.com/paritytech/litep2p", rev = "e03a6023882db111beeb24d8c0ceaac0721d3f0f" }
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 @@ -36,7 +36,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 @@ -124,8 +124,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 @@ -456,16 +456,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 @@ -57,7 +57,10 @@ use litep2p::{
crypto::ed25519::{Keypair, SecretKey},
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 @@ -795,23 +798,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 @@ -12,7 +12,7 @@ documentation = "https://docs.rs/sc-network-types"
[dependencies]
bs58 = "0.5.0"
libp2p-identity = { version = "0.1.3", features = ["ed25519", "peerid"] }
litep2p = { git = "https://github.com/paritytech/litep2p", rev = "e03a6023882db111beeb24d8c0ceaac0721d3f0f" }
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 e664e98

Please sign in to comment.