Skip to content

Wire up Meter for resource usage tracking #2230

@sanity

Description

@sanity

Summary

The Meter struct in crates/core/src/topology/meter.rs provides infrastructure for tracking resource usage (bandwidth) attributed to peers and delegates, but it's not currently wired up.

Current State

  • Meter tracks InboundBandwidthBytes and OutboundBandwidthBytes per AttributionSource (Peer or Delegate)
  • Uses running averages with configurable window sizes
  • Has caching for estimated usage rates
  • The report() method is marked #[allow(dead_code)] with // fixme: use this

Why This Matters

Resource usage tracking would enable:

  1. Fair resource allocation - identify peers/delegates consuming disproportionate bandwidth
  2. Abuse prevention - detect and throttle misbehaving actors
  3. Capacity planning - understand actual resource consumption patterns
  4. Contract storage decisions - factor resource cost into seeding/eviction (related but separate concern)

Suggested Approach

  1. Identify bandwidth consumption points in the networking code
  2. Call meter.report() at those points with appropriate attribution
  3. Expose usage metrics via the node API for monitoring
  4. Consider using the data to inform routing/throttling decisions

Related Code

  • crates/core/src/topology/meter.rs - the Meter implementation
  • crates/core/src/topology/rate.rs - Rate type used by Meter
  • crates/core/src/topology/running_average.rs - RunningAverage used internally

[AI-assisted - Claude]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-networkingArea: Networking, ring protocol, peer discoveryE-mediumExperience needed to fix/implement: Medium / intermediateT-enhancementType: Improvement to existing functionality

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions