Updates the libp2p to the second newest commit => Allow only one topic per message (#1819)

As @AgeManning mentioned the newest libp2p version had some problems and got downgraded again on lighthouse master. This is an intermediate version that makes no problems and only adds a small change of allowing only one topic per message.
This commit is contained in:
blacktemplar 2020-10-24 01:05:37 +00:00
parent 7870b81ade
commit 1644289a08
4 changed files with 64 additions and 84 deletions

30
Cargo.lock generated
View File

@ -3037,7 +3037,7 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a"
[[package]] [[package]]
name = "libp2p" name = "libp2p"
version = "0.29.0" version = "0.29.0"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"atomic", "atomic",
"bytes 0.5.6", "bytes 0.5.6",
@ -3054,7 +3054,7 @@ dependencies = [
"libp2p-tcp", "libp2p-tcp",
"libp2p-websocket", "libp2p-websocket",
"multihash", "multihash",
"parity-multiaddr 0.9.3 (git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c)", "parity-multiaddr 0.9.3 (git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669)",
"parking_lot 0.11.0", "parking_lot 0.11.0",
"pin-project 0.4.27", "pin-project 0.4.27",
"smallvec 1.4.2", "smallvec 1.4.2",
@ -3098,7 +3098,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-core" name = "libp2p-core"
version = "0.22.2" version = "0.22.2"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"asn1_der", "asn1_der",
"bs58", "bs58",
@ -3112,7 +3112,7 @@ dependencies = [
"log 0.4.11", "log 0.4.11",
"multihash", "multihash",
"multistream-select 0.8.3", "multistream-select 0.8.3",
"parity-multiaddr 0.9.3 (git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c)", "parity-multiaddr 0.9.3 (git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669)",
"parking_lot 0.11.0", "parking_lot 0.11.0",
"pin-project 0.4.27", "pin-project 0.4.27",
"prost", "prost",
@ -3131,7 +3131,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-core-derive" name = "libp2p-core-derive"
version = "0.20.2" version = "0.20.2"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"quote", "quote",
"syn", "syn",
@ -3140,7 +3140,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-dns" name = "libp2p-dns"
version = "0.22.0" version = "0.22.0"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"futures 0.3.6", "futures 0.3.6",
"libp2p-core 0.22.2", "libp2p-core 0.22.2",
@ -3150,7 +3150,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-gossipsub" name = "libp2p-gossipsub"
version = "0.22.1" version = "0.22.1"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"base64 0.12.3", "base64 0.12.3",
"byteorder", "byteorder",
@ -3174,7 +3174,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-identify" name = "libp2p-identify"
version = "0.22.0" version = "0.22.0"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"futures 0.3.6", "futures 0.3.6",
"libp2p-core 0.22.2", "libp2p-core 0.22.2",
@ -3189,7 +3189,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-mplex" name = "libp2p-mplex"
version = "0.23.0" version = "0.23.0"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"bytes 0.5.6", "bytes 0.5.6",
"fnv", "fnv",
@ -3204,7 +3204,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-noise" name = "libp2p-noise"
version = "0.24.1" version = "0.24.1"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"bytes 0.5.6", "bytes 0.5.6",
"curve25519-dalek", "curve25519-dalek",
@ -3225,7 +3225,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-swarm" name = "libp2p-swarm"
version = "0.22.0" version = "0.22.0"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"either", "either",
"futures 0.3.6", "futures 0.3.6",
@ -3240,7 +3240,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-tcp" name = "libp2p-tcp"
version = "0.22.0" version = "0.22.0"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"futures 0.3.6", "futures 0.3.6",
"futures-timer", "futures-timer",
@ -3255,7 +3255,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-websocket" name = "libp2p-websocket"
version = "0.23.1" version = "0.23.1"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"async-tls", "async-tls",
"either", "either",
@ -3680,7 +3680,7 @@ dependencies = [
[[package]] [[package]]
name = "multistream-select" name = "multistream-select"
version = "0.8.3" version = "0.8.3"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"bytes 0.5.6", "bytes 0.5.6",
"futures 0.3.6", "futures 0.3.6",
@ -4005,7 +4005,7 @@ dependencies = [
[[package]] [[package]]
name = "parity-multiaddr" name = "parity-multiaddr"
version = "0.9.3" version = "0.9.3"
source = "git+https://github.com/sigp/rust-libp2p?rev=a731aa803d986977c25a77ed2b002d9578f7377c#a731aa803d986977c25a77ed2b002d9578f7377c" source = "git+https://github.com/sigp/rust-libp2p?rev=8c6ce6eb1228de568568f6cd72fb134dea5f9669#8c6ce6eb1228de568568f6cd72fb134dea5f9669"
dependencies = [ dependencies = [
"arrayref", "arrayref",
"bs58", "bs58",

View File

@ -42,7 +42,7 @@ regex = "1.3.9"
[dependencies.libp2p] [dependencies.libp2p]
#version = "0.23.0" #version = "0.23.0"
git = "https://github.com/sigp/rust-libp2p" git = "https://github.com/sigp/rust-libp2p"
rev = "a731aa803d986977c25a77ed2b002d9578f7377c" rev = "8c6ce6eb1228de568568f6cd72fb134dea5f9669"
default-features = false default-features = false
features = ["websocket", "identify", "mplex", "noise", "gossipsub", "dns", "tcp-tokio"] features = ["websocket", "identify", "mplex", "noise", "gossipsub", "dns", "tcp-tokio"]

View File

@ -90,8 +90,8 @@ pub enum BehaviourEvent<TSpec: EthSpec> {
id: MessageId, id: MessageId,
/// The peer from which we received this message, not the peer that published it. /// The peer from which we received this message, not the peer that published it.
source: PeerId, source: PeerId,
/// The topics that this message was sent on. /// The topic that this message was sent on.
topics: Vec<TopicHash>, topic: TopicHash,
/// The message itself. /// The message itself.
message: PubsubMessage<TSpec>, message: PubsubMessage<TSpec>,
}, },
@ -537,7 +537,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
} => { } => {
// Note: We are keeping track here of the peer that sent us the message, not the // Note: We are keeping track here of the peer that sent us the message, not the
// peer that originally published the message. // peer that originally published the message.
match PubsubMessage::decode(&gs_msg.topics, gs_msg.data()) { match PubsubMessage::decode(&gs_msg.topic, gs_msg.data()) {
Err(e) => { Err(e) => {
debug!(self.log, "Could not decode gossipsub message"; "error" => e); debug!(self.log, "Could not decode gossipsub message"; "error" => e);
//reject the message //reject the message
@ -554,7 +554,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
self.add_event(BehaviourEvent::PubsubMessage { self.add_event(BehaviourEvent::PubsubMessage {
id, id,
source: propagation_source, source: propagation_source,
topics: gs_msg.topics, topic: gs_msg.topic,
message: msg, message: msg,
}); });
} }

View File

@ -94,24 +94,13 @@ impl<T: EthSpec> PubsubMessage<T> {
} }
} }
/// This decodes `data` into a `PubsubMessage` given a list of topics. /// This decodes `data` into a `PubsubMessage` given a topic.
///
/// The topics are checked
/// in order and as soon as one topic matches the decoded data, we return the data.
/* Note: This is assuming we are not hashing topics. If we choose to hash topics, these will /* Note: This is assuming we are not hashing topics. If we choose to hash topics, these will
* need to be modified. * need to be modified.
*
* Also note that a message can be associated with many topics. As soon as one of the topics is
* known we match. If none of the topics are known we return an unknown state.
*/ */
pub fn decode(topics: &[TopicHash], data: &MessageData) -> Result<Self, String> { pub fn decode(topic: &TopicHash, data: &MessageData) -> Result<Self, String> {
let mut unknown_topics = Vec::new();
for topic in topics {
match GossipTopic::decode(topic.as_str()) { match GossipTopic::decode(topic.as_str()) {
Err(_) => { Err(_) => Err(format!("Unknown gossipsub topic: {:?}", topic)),
unknown_topics.push(topic);
continue;
}
Ok(gossip_topic) => { Ok(gossip_topic) => {
let decompressed_data = match gossip_topic.encoding() { let decompressed_data = match gossip_topic.encoding() {
GossipEncoding::SSZSnappy => data.decompressed.as_ref()?.as_slice(), GossipEncoding::SSZSnappy => data.decompressed.as_ref()?.as_slice(),
@ -122,51 +111,42 @@ impl<T: EthSpec> PubsubMessage<T> {
let agg_and_proof = let agg_and_proof =
SignedAggregateAndProof::from_ssz_bytes(decompressed_data) SignedAggregateAndProof::from_ssz_bytes(decompressed_data)
.map_err(|e| format!("{:?}", e))?; .map_err(|e| format!("{:?}", e))?;
return Ok(PubsubMessage::AggregateAndProofAttestation(Box::new( Ok(PubsubMessage::AggregateAndProofAttestation(Box::new(
agg_and_proof, agg_and_proof,
))); )))
} }
GossipKind::Attestation(subnet_id) => { GossipKind::Attestation(subnet_id) => {
let attestation = Attestation::from_ssz_bytes(decompressed_data) let attestation = Attestation::from_ssz_bytes(decompressed_data)
.map_err(|e| format!("{:?}", e))?; .map_err(|e| format!("{:?}", e))?;
return Ok(PubsubMessage::Attestation(Box::new(( Ok(PubsubMessage::Attestation(Box::new((
*subnet_id, *subnet_id,
attestation, attestation,
)))); ))))
} }
GossipKind::BeaconBlock => { GossipKind::BeaconBlock => {
let beacon_block = SignedBeaconBlock::from_ssz_bytes(decompressed_data) let beacon_block = SignedBeaconBlock::from_ssz_bytes(decompressed_data)
.map_err(|e| format!("{:?}", e))?; .map_err(|e| format!("{:?}", e))?;
return Ok(PubsubMessage::BeaconBlock(Box::new(beacon_block))); Ok(PubsubMessage::BeaconBlock(Box::new(beacon_block)))
} }
GossipKind::VoluntaryExit => { GossipKind::VoluntaryExit => {
let voluntary_exit = let voluntary_exit = SignedVoluntaryExit::from_ssz_bytes(decompressed_data)
SignedVoluntaryExit::from_ssz_bytes(decompressed_data)
.map_err(|e| format!("{:?}", e))?; .map_err(|e| format!("{:?}", e))?;
return Ok(PubsubMessage::VoluntaryExit(Box::new(voluntary_exit))); Ok(PubsubMessage::VoluntaryExit(Box::new(voluntary_exit)))
} }
GossipKind::ProposerSlashing => { GossipKind::ProposerSlashing => {
let proposer_slashing = let proposer_slashing = ProposerSlashing::from_ssz_bytes(decompressed_data)
ProposerSlashing::from_ssz_bytes(decompressed_data)
.map_err(|e| format!("{:?}", e))?; .map_err(|e| format!("{:?}", e))?;
return Ok(PubsubMessage::ProposerSlashing(Box::new( Ok(PubsubMessage::ProposerSlashing(Box::new(proposer_slashing)))
proposer_slashing,
)));
} }
GossipKind::AttesterSlashing => { GossipKind::AttesterSlashing => {
let attester_slashing = let attester_slashing = AttesterSlashing::from_ssz_bytes(decompressed_data)
AttesterSlashing::from_ssz_bytes(decompressed_data)
.map_err(|e| format!("{:?}", e))?; .map_err(|e| format!("{:?}", e))?;
return Ok(PubsubMessage::AttesterSlashing(Box::new( Ok(PubsubMessage::AttesterSlashing(Box::new(attester_slashing)))
attester_slashing,
)));
} }
} }
} }
} }
} }
Err(format!("Unknown gossipsub topics: {:?}", unknown_topics))
}
/// Encodes a `PubsubMessage` based on the topic encodings. The first known encoding is used. If /// Encodes a `PubsubMessage` based on the topic encodings. The first known encoding is used. If
/// no encoding is known, and error is returned. /// no encoding is known, and error is returned.