mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 01:41:03 +00:00
approval-distribution: split peer knowledge into sent and received (#2809)
* approval-distribution: split peer knowledge into sent and received * guide updates * fixes * revert doc changes
This commit is contained in:
@@ -76,10 +76,17 @@ struct Knowledge {
|
||||
known_messages: HashSet<MessageFingerprint>,
|
||||
}
|
||||
|
||||
struct PeerKnowledge {
|
||||
/// The knowledge we've sent to the peer.
|
||||
sent: Knowledge,
|
||||
/// The knowledge we've received from the peer.
|
||||
received: Knowledge,
|
||||
}
|
||||
|
||||
/// Information about blocks in our current view as well as whether peers know of them.
|
||||
struct BlockEntry {
|
||||
// Peers who we know are aware of this block and thus, the candidates within it. This maps to their knowledge of messages.
|
||||
known_by: HashMap<PeerId, Knowledge>,
|
||||
known_by: HashMap<PeerId, PeerKnowledge>,
|
||||
// The number of the block.
|
||||
number: BlockNumber,
|
||||
// The parent hash of the block.
|
||||
@@ -188,7 +195,7 @@ The algorithm is the following:
|
||||
* Load the BlockEntry using `assignment.block_hash`. If it does not exist, report the source if it is `MessageSource::Peer` and return.
|
||||
* Compute a fingerprint for the `assignment` using `claimed_candidate_index`.
|
||||
* If the source is `MessageSource::Peer(sender)`:
|
||||
* check if `peer` appears under `known_by` and whether the fingerprint is in the `known_messages` of the peer. If the peer does not know the block, report for providing data out-of-view and proceed. If the peer does know the block and the knowledge contains the fingerprint, report for providing replicate data and return.
|
||||
* check if `peer` appears under `known_by` and whether the fingerprint is in the knowledge of the peer. If the peer does not know the block, report for providing data out-of-view and proceed. If the peer does know the block and the `sent` knowledge contains the fingerprint, report for providing replicate data and return, otherwise, insert into the `received` knowledge and return.
|
||||
* If the message fingerprint appears under the `BlockEntry`'s `Knowledge`, give the peer a small positive reputation boost,
|
||||
add the fingerprint to the peer's knowledge only if it knows about the block and return.
|
||||
Note that we must do this after checking for out-of-view and if the peers knows about the block to avoid being spammed.
|
||||
@@ -215,7 +222,7 @@ Imports an approval signature referenced by block hash and candidate index:
|
||||
* Compute a fingerprint for the approval.
|
||||
* Compute a fingerprint for the corresponding assignment. If the `BlockEntry`'s knowledge does not contain that fingerprint, then report the source if it is `MessageSource::Peer` and return. All references to a fingerprint after this refer to the approval's, not the assignment's.
|
||||
* If the source is `MessageSource::Peer(sender)`:
|
||||
* check if `peer` appears under `known_by` and whether the fingerprint is in the `known_messages` of the peer. If the peer does not know the block, report for providing data out-of-view and proceed. If the peer does know the block and the knowledge contains the fingerprint, report for providing replicate data and return.
|
||||
* check if `peer` appears under `known_by` and whether the fingerprint is in the knowledge of the peer. If the peer does not know the block, report for providing data out-of-view and proceed. If the peer does know the block and the `sent` knowledge contains the fingerprint, report for providing replicate data and return, otherwise, insert into the `received` knowledge and return.
|
||||
* If the message fingerprint appears under the `BlockEntry`'s `Knowledge`, give the peer a small positive reputation boost,
|
||||
add the fingerprint to the peer's knowledge only if it knows about the block and return.
|
||||
Note that we must do this after checking for out-of-view to avoid being spammed. If we did this check earlier, a peer could provide data out-of-view repeatedly and be rewarded for it.
|
||||
|
||||
Reference in New Issue
Block a user