ChainSafe / gossamer

🕸️ Go Implementation of the Polkadot Host
https://chainsafe.github.io/gossamer
GNU Lesser General Public License v3.0
433 stars 121 forks source link

feat(statement-distribution) Implement `ReputationAggregator` #4345

Open EclesioMeloJunior opened 3 days ago

EclesioMeloJunior commented 3 days ago

Description

Reputation Aggregator is a struct that collects reputation changes and sends them in on batch to relieve network channels, needed for Statement Distributionsubsystem

This struct should be placed at parachains/utils folder since it should be available for more than one subsystem.

The struct:


type ReputationAggregator struct {
   // a function that helps the aggregator to understand if such reputation should be dispatched to network subsystems at arrival or can stay longer in the batch
   sendImmediatellyIf func(rep UnifiedReputationChange) bool 
   byPeer map[peer.ID]int32
}

// effectivelly sends the collected reputations to the network subsystem
type (r *ReputationAggregator) Send(overseerCh) {
    overseerCh <- NetworkBridgeTxMessage {
       ReportPeerMessageBatch: r.byPeer
    }

    // clear the map after sending
    r.byPeer = map[peer.ID]int32{}
}

type (r *ReputationAggregator) Modify(overseerCh, peerID, rep) {
   if r.sendImmediatellyIf(rep) {
       // send rep w/o adding to the aggregator
   }

    // add to the aggregator
}

Links

haikoschol commented 3 days ago

It is also used in bitfield distribution.