Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c6be9e5
expunge legacy code from polkadot-network
rphmeier Feb 20, 2020
953e292
mostly rip out old legacy protocol from service
rphmeier Feb 24, 2020
7a19620
ensure validation work is spawned by incoming messages
rphmeier Feb 24, 2020
134f3e5
decouple availabliity store from network logic; clean up data flow
rphmeier Feb 25, 2020
eaef68f
av_store: test helpers and use futures-abort
rphmeier Feb 26, 2020
4e1feb8
update polkadot-validation to pass n_validators when submitting chunks
rphmeier Feb 26, 2020
bf4443c
fallible erasure-chunk fetching
rphmeier Feb 26, 2020
697c136
implement `ErasureNetworking` for new network prot
rphmeier Feb 26, 2020
3416863
API for registering availability store in network
rphmeier Feb 26, 2020
457d406
fully integrate new network service into service
rphmeier Feb 26, 2020
8c65487
fix validation tests
rphmeier Feb 27, 2020
81ecaef
scaffolding for porting collator over to new network
rphmeier Feb 29, 2020
f86c52e
track connected validators' peer IDs and distribute collators' collat…
rphmeier Mar 2, 2020
bbef84c
helper in network for fetching all checked statements
rphmeier Mar 2, 2020
8bf595f
Merge branch 'master' into rh-remove-legacy-network
rphmeier Mar 2, 2020
16b79f2
fix adder-collator
rphmeier Mar 2, 2020
22c97dd
actually register notifications protocol
rphmeier Mar 3, 2020
0f53937
Update service/src/lib.rs
rphmeier Mar 5, 2020
9e76603
Make needed changes to service
expenses Mar 5, 2020
71a2d56
Merge two companion PRs.
gavofyork Mar 5, 2020
a4696ca
Some effort towards compilation
gavofyork Mar 5, 2020
20da96b
Fix
gavofyork Mar 5, 2020
85accd3
Merge remote-tracking branch 'origin/rh-remove-legacy-network' into g…
gavofyork Mar 5, 2020
99c63ea
Merge branch 'master' into gav-upsub
rphmeier Mar 5, 2020
da6dab4
remove `NetworkSpecialization` references from network
rphmeier Mar 5, 2020
de2dde0
fix compilation errors in service and collator
rphmeier Mar 5, 2020
3bf1967
ensure protocol name is valid
rphmeier Mar 5, 2020
80adf68
Fixes
gavofyork Mar 5, 2020
3b7d923
Fix
gavofyork Mar 5, 2020
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
Next Next commit
expunge legacy code from polkadot-network
  • Loading branch information
rphmeier committed Feb 26, 2020
commit c6be9e54ad9a3ccbf833e426333932a4ec77bc2f
6 changes: 3 additions & 3 deletions network/src/legacy/gossip/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ use polkadot_primitives::Hash;
use std::collections::{HashMap, HashSet};

use log::warn;
use crate::legacy::router::attestation_topic;

use super::{cost, benefit, MAX_CHAIN_HEADS, LeavesVec,
ChainContext, Known, MessageValidationData, GossipStatement
use super::{
cost, benefit, attestation_topic, MAX_CHAIN_HEADS, LeavesVec,
ChainContext, Known, MessageValidationData, GossipStatement,
};

// knowledge about attestations on a single parent-hash.
Expand Down
116 changes: 33 additions & 83 deletions network/src/legacy/gossip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

use sp_runtime::traits::{BlakeTwo256, Hash as HashT};
use sp_blockchain::Error as ClientError;
use sc_network::{config::Roles, Context, PeerId, ReputationChange};
use sc_network::{config::Roles, PeerId, ReputationChange};
use sc_network::{NetworkService as SubstrateNetworkService, specialization::NetworkSpecialization};
use sc_network_gossip::{
ValidationResult as GossipValidationResult,
Expand All @@ -73,7 +73,7 @@ use arrayvec::ArrayVec;
use futures::prelude::*;
use parking_lot::RwLock;

use crate::legacy::{GossipMessageStream, NetworkService, GossipService, PolkadotProtocol, router::attestation_topic};
use crate::legacy::{GossipMessageStream, GossipService};

use attestation::{View as AttestationView, PeerData as AttestationPeerData};

Expand Down Expand Up @@ -254,6 +254,15 @@ impl<F, P> ChainContext for (F, P) where
}
}


/// Compute the gossip topic for attestations on the given parent hash.
pub(crate) fn attestation_topic(parent_hash: Hash) -> Hash {
let mut v = parent_hash.as_ref().to_vec();
v.extend(b"attestations");

BlakeTwo256::hash(&v[..])
}

/// Register a gossip validator on the network service.
// NOTE: since RegisteredMessageValidator is meant to be a type-safe proof
// that we've actually done the registration, this should be the only way
Expand Down Expand Up @@ -353,22 +362,6 @@ impl<S: NetworkSpecialization<Block>> Clone for RegisteredMessageValidator<S> {
}
}

impl RegisteredMessageValidator<crate::legacy::PolkadotProtocol> {
#[cfg(test)]
pub(crate) fn new_test<C: ChainContext + 'static>(
chain: C,
report_handle: Box<dyn Fn(&PeerId, ReputationChange) + Send + Sync>,
) -> Self {
let validator = Arc::new(MessageValidator::new_test(chain, report_handle));

RegisteredMessageValidator {
inner: validator as _,
service: None,
gossip_engine: None,
}
}
}

impl<S: NetworkSpecialization<Block>> RegisteredMessageValidator<S> {
pub fn register_availability_store(&mut self, availability_store: av_store::Store) {
self.inner.inner.write().availability_store = Some(availability_store);
Expand Down Expand Up @@ -457,18 +450,6 @@ impl<S: NetworkSpecialization<Block>> GossipService for RegisteredMessageValidat
}
}

impl NetworkService for RegisteredMessageValidator<crate::legacy::PolkadotProtocol> {
fn with_spec<F: Send + 'static>(&self, with: F)
where F: FnOnce(&mut PolkadotProtocol, &mut dyn Context<Block>)
{
if let Some(service) = self.service.as_ref() {
service.with_spec(with)
} else {
log::error!("Called with_spec on a test engine");
}
}
}

/// The data needed for validating gossip messages.
#[derive(Default)]
pub(crate) struct MessageValidationData {
Expand Down Expand Up @@ -726,8 +707,6 @@ mod tests {
use sp_core::sr25519::Signature as Sr25519Signature;
use polkadot_validation::GenericStatement;

use crate::legacy::tests::TestChainContext;

#[derive(PartialEq, Clone, Debug)]
enum ContextEvent {
BroadcastTopic(Hash, bool),
Expand Down Expand Up @@ -762,6 +741,28 @@ mod tests {
}
}

#[derive(Default)]
struct TestChainContext {
known_map: HashMap<Hash, Known>,
ingress_roots: HashMap<Hash, Vec<Hash>>,
}

impl ChainContext for TestChainContext {
fn is_known(&self, block_hash: &Hash) -> Option<Known> {
self.known_map.get(block_hash).map(|x| x.clone())
}

fn leaf_unrouted_roots(&self, leaf: &Hash, with_queue_root: &mut dyn FnMut(&Hash))
-> Result<(), sp_blockchain::Error>
{
for root in self.ingress_roots.get(leaf).into_iter().flat_map(|roots| roots) {
with_queue_root(root)
}

Ok(())
}
}

#[test]
fn message_allowed() {
let (tx, _rx) = mpsc::channel();
Expand Down Expand Up @@ -953,55 +954,4 @@ mod tests {
assert!(message_allowed(&peer_a, MessageIntent::Broadcast, &topic_a, &encoded[..]));
}
}

#[test]
fn multicasts_icmp_queues_when_building_on_new_leaf() {
let (tx, _rx) = mpsc::channel();
let tx = Mutex::new(tx);
let report_handle = Box::new(move |peer: &PeerId, cb: ReputationChange| tx.lock().send((peer.clone(), cb)).unwrap());

let hash_a = [1u8; 32].into();
let root_a = [11u8; 32].into();

let chain = {
let mut chain = TestChainContext::default();
chain.known_map.insert(hash_a, Known::Leaf);
chain.ingress_roots.insert(hash_a, vec![root_a]);
chain
};

let validator = RegisteredMessageValidator::new_test(chain, report_handle);

let peer_a = PeerId::random();
let peer_b = PeerId::random();

let mut validator_context = MockValidatorContext::default();
validator.inner.new_peer(&mut validator_context, &peer_a, Roles::FULL);
validator.inner.new_peer(&mut validator_context, &peer_b, Roles::FULL);
assert!(validator_context.events.is_empty());
validator_context.clear();


{
let message = GossipMessage::from(NeighborPacket {
chain_heads: vec![hash_a],
}).encode();
let res = validator.inner.validate(
&mut validator_context,
&peer_a,
&message[..],
);

match res {
GossipValidationResult::Discard => {},
_ => panic!("wrong result"),
}
assert_eq!(
validator_context.events,
vec![
ContextEvent::SendTopic(peer_a.clone(), attestation_topic(hash_a), false),
],
);
}
}
}
Loading