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
33 commits
Select commit Hold shift + click to select a range
c23a13c
introduce candidatedescriptor type
rphmeier Jul 2, 2020
7a2be24
add PoVDistribution message type
rphmeier Jul 2, 2020
55e1b5a
loosen bound on PoV Distribution to account for equivocations
rphmeier Jul 2, 2020
1db4f3c
re-export some types from the messages module
rphmeier Jul 2, 2020
f6641c4
begin PoV Distribution subsystem
rphmeier Jul 2, 2020
fe005b7
remove redundant index from PoV distribution
rphmeier Jul 3, 2020
27da7ef
define state machine for pov distribution
rphmeier Jul 3, 2020
2cdcefd
handle overseer signals
rphmeier Jul 3, 2020
e66e063
set up control flow
rphmeier Jul 3, 2020
6197058
remove `ValidatorStatement` section
rphmeier Jul 3, 2020
623db00
implement PoV fetching
rphmeier Jul 3, 2020
86d1cf0
implement distribution logic
rphmeier Jul 3, 2020
8557778
add missing `
rphmeier Jul 3, 2020
fa86b24
implement some network bridge event handlers
rphmeier Jul 3, 2020
8b4a7b0
stub for message processing, handle our view change
rphmeier Jul 3, 2020
0b82a0c
control flow for handling messages
rphmeier Jul 3, 2020
a45e58e
handle `awaiting` message
rphmeier Jul 3, 2020
a768179
handle any incoming PoVs and redistribute
rphmeier Jul 3, 2020
d47905d
actually provide a subsystem implementation
rphmeier Jul 3, 2020
bb31777
remove set-builder notation
rphmeier Jul 6, 2020
24d6278
begin testing PoV distribution
rphmeier Jul 7, 2020
5202b3d
test that we send awaiting messages only to peers with same view
rphmeier Jul 7, 2020
3d9d000
ensure we distribute awaited PoVs to peers on view changes
rphmeier Jul 7, 2020
df4a1f1
test that peers can complete fetch and are rewarded
rphmeier Jul 7, 2020
f2c9bfb
test some reporting logic
rphmeier Jul 7, 2020
7923146
ensure peer is reported for flooding
rphmeier Jul 7, 2020
43d610d
test punishing peers diverging from awaited protocol
rphmeier Jul 7, 2020
57f133f
test that we eagerly complete peers' awaited PoVs based on what we re…
rphmeier Jul 7, 2020
7d26c53
test that we prune the awaited set after receiving
rphmeier Jul 7, 2020
6406423
Merge branch 'master' into rh-pov-distribution
rphmeier Jul 7, 2020
0ff3988
expand pov-distribution in guide to match a change I made
rphmeier Jul 7, 2020
8cc66a7
Merge branch 'master' into rh-pov-distribution
rphmeier Jul 7, 2020
f506a91
remove unneeded import
rphmeier Jul 7, 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
stub for message processing, handle our view change
  • Loading branch information
rphmeier committed Jul 3, 2020
commit 8b4a7b04124b73d6ec2ecff2842b57c8a7741e81
42 changes: 34 additions & 8 deletions node/network/pov-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use std::sync::Arc;

const COST_APPARENT_FLOOD: Rep = Rep::new(-500, "Peer appears to be flooding us with PoV requests");
const COST_UNEXPECTED_POV: Rep = Rep::new(-500, "Peer sent us an unexpected PoV");
const COST_MALFORMED_MESSAGE: Rep = Rep::new(-500, "Peer sent us a malformed message");

const BENEFIT_FRESH_POV: Rep = Rep::new(25, "Peer supplied us with an awaited PoV");
const BENEFIT_LATE_POV: Rep = Rep::new(10, "Peer supplied us with an awaited PoV, \
Expand Down Expand Up @@ -82,7 +83,8 @@ struct PeerState {
awaited: HashMap<Hash, HashSet<Hash>>,
}

// Handles the signal. If successful, returns `true` if the subsystem should conclude, `false` otherwise.
/// Handles the signal. If successful, returns `true` if the subsystem should conclude,
/// `false` otherwise.
async fn handle_signal(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
Expand Down Expand Up @@ -113,9 +115,9 @@ async fn handle_signal(
}
}

// Notify peers that we are awaiting a given PoV hash.
//
// This only notifies peers who have the relay parent in their view.
/// Notify peers that we are awaiting a given PoV hash.
///
/// This only notifies peers who have the relay parent in their view.
async fn notify_we_are_awaiting(
peers: &mut HashMap<PeerId, PeerState>,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
Expand All @@ -142,7 +144,7 @@ async fn notify_we_are_awaiting(
))).await
}

// Distribute a PoV to peers who are awaiting it.
/// Distribute a PoV to peers who are awaiting it.
async fn distribute_to_awaiting(
peers: &mut HashMap<PeerId, PeerState>,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
Expand Down Expand Up @@ -174,7 +176,7 @@ async fn distribute_to_awaiting(
))).await
}

// Handles a `FetchPoV` message.
/// Handles a `FetchPoV` message.
async fn handle_fetch(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
Expand Down Expand Up @@ -220,7 +222,7 @@ async fn handle_fetch(
).await
}

// Handles a `DistributePoV` message.
/// Handles a `DistributePoV` message.
async fn handle_distribute(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
Expand Down Expand Up @@ -254,7 +256,16 @@ async fn handle_distribute(
).await
}

// Handles a network bridge update.
/// Report a reputation change for a peer.
async fn report_peer(
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
peer: PeerId,
rep: Rep,
) -> SubsystemResult<()> {
ctx.send_message(AllMessages::NetworkBridge(NetworkBridgeMessage::ReportPeer(peer, rep))).await
}

/// Handles a network bridge update.
async fn handle_network_update(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
Expand Down Expand Up @@ -282,6 +293,21 @@ async fn handle_network_update(

Ok(())
}
NetworkBridgeEvent::PeerMessage(peer, bytes) => {
let _ = match WireMessage::decode(&mut &bytes[..]) {
Ok(msg) => msg,
Err(_) => {
report_peer(ctx, peer, COST_MALFORMED_MESSAGE).await?;
return Ok(());
}
};

Ok(())
}
NetworkBridgeEvent::OurViewChange(view) => {
state.our_view = view;
Ok(())
}
_ => Ok(()), // TODO [now] exhaustive match
}
}
Expand Down