impl availability distribution

Closes #1237
This commit is contained in:
Bernhard Schuster
2020-08-10 15:02:30 +02:00
committed by GitHub
parent 0ed8cad3c3
commit 4bdfd02f93
14 changed files with 2414 additions and 201 deletions
@@ -46,9 +46,9 @@ const COST_MESSAGE_NOT_DECODABLE: ReputationChange =
ReputationChange::new(-100, "Not interested in that parent hash");
const COST_PEER_DUPLICATE_MESSAGE: ReputationChange =
ReputationChange::new(-500, "Peer sent the same message multiple times");
const GAIN_VALID_MESSAGE_FIRST: ReputationChange =
const BENEFIT_VALID_MESSAGE_FIRST: ReputationChange =
ReputationChange::new(15, "Valid message with new information");
const GAIN_VALID_MESSAGE: ReputationChange =
const BENEFIT_VALID_MESSAGE: ReputationChange =
ReputationChange::new(10, "Valid message");
/// Checked signed availability bitfield that is distributed
@@ -396,14 +396,14 @@ where
"Already received a message for validator at index {}",
validator_index
);
modify_reputation(ctx, origin, GAIN_VALID_MESSAGE).await?;
modify_reputation(ctx, origin, BENEFIT_VALID_MESSAGE).await?;
return Ok(());
}
one_per_validator.insert(validator.clone(), message.clone());
relay_message(ctx, job_data, &mut state.peer_views, validator, message).await?;
modify_reputation(ctx, origin, GAIN_VALID_MESSAGE_FIRST).await
modify_reputation(ctx, origin, BENEFIT_VALID_MESSAGE_FIRST).await
} else {
modify_reputation(ctx, origin, COST_SIGNATURE_INVALID).await
}
@@ -479,14 +479,14 @@ where
{
let current = state.peer_views.entry(origin.clone()).or_default();
let delta_vec: Vec<Hash> = (*current).difference(&view).cloned().collect();
let added: Vec<Hash> = view.difference(&*current).cloned().collect();
*current = view;
// Send all messages we've seen before and the peer is now interested
// in to that peer.
let delta_set: Vec<(ValidatorId, BitfieldGossipMessage)> = delta_vec
let delta_set: Vec<(ValidatorId, BitfieldGossipMessage)> = added
.into_iter()
.filter_map(|new_relay_parent_interest| {
if let Some(job_data) = (&*state).per_relay_parent.get(&new_relay_parent_interest) {
@@ -558,7 +558,7 @@ where
{
fn start(self, ctx: C) -> SpawnedSubsystem {
SpawnedSubsystem {
name: "bitfield-distribution",
name: "bitfield-distribution-subsystem",
future: Box::pin(async move { Self::run(ctx) }.map(|_| ())),
}
}
@@ -870,7 +870,7 @@ mod test {
NetworkBridgeMessage::ReportPeer(peer, rep)
) => {
assert_eq!(peer, peer_b);
assert_eq!(rep, GAIN_VALID_MESSAGE_FIRST)
assert_eq!(rep, BENEFIT_VALID_MESSAGE_FIRST)
}
);
@@ -887,7 +887,7 @@ mod test {
NetworkBridgeMessage::ReportPeer(peer, rep)
) => {
assert_eq!(peer, peer_a);
assert_eq!(rep, GAIN_VALID_MESSAGE)
assert_eq!(rep, BENEFIT_VALID_MESSAGE)
}
);
@@ -993,7 +993,7 @@ mod test {
NetworkBridgeMessage::ReportPeer(peer, rep)
) => {
assert_eq!(peer, peer_b);
assert_eq!(rep, GAIN_VALID_MESSAGE_FIRST)
assert_eq!(rep, BENEFIT_VALID_MESSAGE_FIRST)
}
);