Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5d7f6d5
set up data types and control flow for statement distribution
rphmeier Jun 27, 2020
28f12c5
add some set-like methods to View
rphmeier Jun 27, 2020
f8992a2
implement sending to peers
rphmeier Jun 27, 2020
72b339b
start fixing equivocation handling
rphmeier Jun 29, 2020
6a16cd7
Add a section to the statement distribution subsystem on equivocation…
rphmeier Jun 30, 2020
ca3b523
fix typo and amend wording
rphmeier Jun 30, 2020
8464686
implement flood protection
rphmeier Jul 1, 2020
cac9adc
have peer knowledge tracker follow when peer first learns about a can…
rphmeier Jul 1, 2020
1be7e37
send dependents after circulating
rphmeier Jul 1, 2020
47f2df8
add another TODO
rphmeier Jul 1, 2020
cd30c21
trigger send in one more place
rphmeier Jul 1, 2020
a39ad10
refactors from review
rphmeier Jul 1, 2020
751122b
send new statements to candidate backing
rphmeier Jul 1, 2020
d413426
instantiate active head data with runtime API values
rphmeier Jul 1, 2020
7b82e1b
track our view changes and peer view changes
rphmeier Jul 1, 2020
94a69ff
apply a benefit to peers who send us statements we want
rphmeier Jul 1, 2020
a3b4b6a
remove unneeded TODO
rphmeier Jul 1, 2020
eb51e80
add some comments and improve Hash implementation
rphmeier Jul 1, 2020
b9876ae
start tests and fix `note_statement`
rphmeier Jul 2, 2020
f605ed2
test active_head seconding logic
rphmeier Jul 2, 2020
5650620
test that the per-peer tracking logic works
rphmeier Jul 2, 2020
dd00108
test per-peer knowledge tracker
rphmeier Jul 2, 2020
c93b545
test that peer view updates lead to messages being sent
rphmeier Jul 2, 2020
19ee505
test statement circulation
rphmeier Jul 2, 2020
9093736
address review comments
rphmeier Jul 2, 2020
6d18b62
have view set methods return references
rphmeier Jul 2, 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
Prev Previous commit
Next Next commit
test that peer view updates lead to messages being sent
  • Loading branch information
rphmeier committed Jul 2, 2020
commit c93b545abd19dd370c44aa5fa4109a4fb2258ef4
133 changes: 132 additions & 1 deletion node/network/statement-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ mod tests {
use node_primitives::Statement;
use polkadot_primitives::parachain::{AbridgedCandidateReceipt};
use assert_matches::assert_matches;
use futures::executor::{self, ThreadPool};

#[test]
fn active_head_accepts_only_2_seconded_per_validator() {
Expand Down Expand Up @@ -1130,7 +1131,137 @@ mod tests {

#[test]
fn peer_view_update_sends_messages() {
// TODO [now]
let hash_a = [1; 32].into();
let hash_b = [2; 32].into();
let hash_c = [3; 32].into();

let candidate = {
let mut c = AbridgedCandidateReceipt::default();
c.relay_parent = hash_c;
c.parachain_index = 1.into();
c
};
let candidate_hash = candidate.hash();

let old_view = View(vec![hash_a, hash_b]);
let new_view = View(vec![hash_b, hash_c]);

let mut active_heads = HashMap::new();
let validators = vec![
Sr25519Keyring::Alice.public().into(),
Sr25519Keyring::Bob.public().into(),
Sr25519Keyring::Charlie.public().into(),
];

let session_index = 1;
let signing_context = SigningContext {
parent_hash: hash_c,
session_index,
};

let new_head_data = {
let mut data = ActiveHeadData::new(validators, session_index);

let noted = data.note_statement(SignedFullStatement::sign(
Statement::Seconded(candidate.clone()),
&signing_context,
0,
&Sr25519Keyring::Alice.pair().into(),
));

assert_matches!(noted, NotedStatement::Fresh(_));

let noted = data.note_statement(SignedFullStatement::sign(
Statement::Valid(candidate_hash),
&signing_context,
1,
&Sr25519Keyring::Bob.pair().into(),
));

assert_matches!(noted, NotedStatement::Fresh(_));

let noted = data.note_statement(SignedFullStatement::sign(
Statement::Valid(candidate_hash),
&signing_context,
2,
&Sr25519Keyring::Charlie.pair().into(),
));

assert_matches!(noted, NotedStatement::Fresh(_));

data
};

active_heads.insert(hash_c, new_head_data);

let mut peer_data = PeerData {
view: old_view,
view_knowledge: {
let mut k = HashMap::new();

k.insert(hash_a, Default::default());
k.insert(hash_b, Default::default());

k
},
};

let pool = ThreadPool::new().unwrap();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let peer = PeerId::random();

executor::block_on(async move {
update_peer_view_and_send_unlocked(
peer.clone(),
&mut peer_data,
&mut ctx,
&active_heads,
new_view.clone(),
).await.unwrap();

assert_eq!(peer_data.view, new_view);
assert!(!peer_data.view_knowledge.contains_key(&hash_a));
assert!(peer_data.view_knowledge.contains_key(&hash_b));

let c_knowledge = peer_data.view_knowledge.get(&hash_c).unwrap();

assert!(c_knowledge.known_candidates.contains(&candidate_hash));
assert!(c_knowledge.sent_statements.contains(
&(CompactStatement::Candidate(candidate_hash), 0)
));
assert!(c_knowledge.sent_statements.contains(
&(CompactStatement::Valid(candidate_hash), 1)
));
assert!(c_knowledge.sent_statements.contains(
&(CompactStatement::Valid(candidate_hash), 2)
));

// now see if we got the 3 messages from the active head data.
let active_head = active_heads.get(&hash_c).unwrap();

// semi-fragile because hashmap iterator ordering is undefined, but in practice
// it will not change between runs of the program.
for statement in active_head.statements_about(candidate_hash) {
let message = handle.recv().await;
let expected_to = vec![peer.clone()];
let expected_protocol = PROTOCOL_V1;
let expected_payload
= WireMessage::Statement(hash_c, statement.statement.clone()).encode();

assert_matches!(
message,
AllMessages::NetworkBridge(NetworkBridgeMessage::SendMessage(
to,
protocol,
payload,
)) => {
assert_eq!(to, expected_to);
assert_eq!(protocol, expected_protocol);
assert_eq!(payload, expected_payload)
}
)
}
});
}

#[test]
Expand Down