Sigil documentation
ReferenceRust referencesigil-network

sigil-network · scoring

Source declarations, signatures and documentation for scoring.

Source: sigil/node/sigil-network/src/scoring.rs. SHA-256: bc855b75485303729177aa3d046d562b905c3eaa5456c5556812b05b744ce16d.

This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.

scoring::PeerScoring

Peer scoring state combining gossipsub behaviour and OATS reputation.

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PeerScoring {
/// Base score that all peers start with.

pub base_score: f64,
/// Accumulated score from delivering valid messages.

pub message_delivery_score: f64,
/// Accumulated score from being the first to deliver messages.

pub first_delivery_score: f64,
/// Accumulated penalty for delivering invalid messages.

pub invalid_message_penalty: f64,
/// Bonus score derived from the peer's OATS reputation.

pub oats_reputation_bonus: f64
}

Source line: 30.

scoring::GossipRateLimitConfig

Message-rate limits applied before forwarding or processing gossip.

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GossipRateLimitConfig {
/// Max messages per peer per one-second window.

pub per_peer_per_sec: u32,
/// Max messages per source IP per one-second window.

pub per_ip_per_sec: u32,
/// Max messages per `(peer, topic)` per one-second window.

pub per_topic_per_sec: u32
}

Source line: 45.

scoring::GossipRateLimiter

Deterministic per-peer and per-topic gossip flood limiter.

#[derive(Debug, Clone)]
pub struct GossipRateLimiter {

}

Source line: 87.

scoring::GossipRateLimiter::new

pub fn new(config: GossipRateLimitConfig) -> Self;

Source line: 95.

scoring::GossipRateLimiter::record

Record one inbound message and return an error if it exceeds a cap.

now_unix_secs is supplied by the caller to keep tests deterministic and avoid binding this crate to a specific async runtime clock.

pub fn record(
        &mut self,
        peer_id: &str,
        topic: GossipTopic,
        now_unix_secs: u64,
    ) -> NetworkResult<()>;

Source line: 108.

scoring::GossipRateLimiter::record_from_ip

Record one inbound message and rate-limit by both peer ID and source IP.

pub fn record_from_ip(
        &mut self,
        peer_id: &str,
        source_ip: Option<&str>,
        topic: GossipTopic,
        now_unix_secs: u64,
    ) -> NetworkResult<()>;

Source line: 118.

scoring::PeerScoring::new

Create a new scoring instance with default base score.

pub fn new() -> Self;

Source line: 181.

scoring::PeerScoring::with_base_score

Create a scoring instance with a custom base score.

pub fn with_base_score(base_score: f64) -> Self;

Source line: 186.

scoring::PeerScoring::compute_score

Compute the aggregate score for this peer.

The formula is: base + delivery + first_delivery - invalid_penalty + oats_bonus

pub fn compute_score(&self) -> f64;

Source line: 197.

scoring::PeerScoring::record_valid_message

Record that this peer delivered a valid message.

pub fn record_valid_message(&mut self);

Source line: 204.

scoring::PeerScoring::record_invalid_message

Record that this peer delivered an invalid message (penalize).

pub fn record_invalid_message(&mut self);

Source line: 209.

scoring::PeerScoring::record_first_delivery

Record that this peer was the first to deliver a message.

pub fn record_first_delivery(&mut self);

Source line: 214.

scoring::PeerScoring::set_oats_reputation

Update the OATS reputation bonus from the on-chain reputation score.

The score parameter should be in the range [0.0, 1.0] and is scaled to a bonus range of [0.0, 50.0].

pub fn set_oats_reputation(&mut self, score: f64);

Source line: 222.

scoring::PeerScoring::decay

Apply time-based decay to volatile score components.

factor should be in (0.0, 1.0) — e.g. 0.95 preserves 95% of accumulated scores per decay tick.

pub fn decay(&mut self, factor: f64);

Source line: 230.

scoring::PeerScoring::should_ban

Returns true if this peer's score is below the ban threshold.

pub fn should_ban(&self) -> bool;

Source line: 239.

On this page