Skip to content

fix(client): evict completed DHT block statistics - #962

Merged
aterentic-ethernal merged 1 commit into
availproject:mainfrom
zloglevel:main
Sep 14, 2026
Merged

aterentic-ethernal merged 1 commit into
availproject:mainfrom
zloglevel:main

Conversation

@zloglevel

Copy link
Copy Markdown
Contributor

Summary

Evict completed DHT block statistics from active_blocks in both the light client and fat client.

Problem

Each DHT PUT task creates or updates a BlockStat entry keyed by block height. When all PUT operations for a block complete, the clients record the success rate and duration but never remove the completed block from active_blocks.

For long-running clients, this causes the map to retain statistics for every block that has performed a DHT PUT operation.

Additionally, remaining_counter -= 1 can underflow if libp2p emits a duplicate or late completion event. This can panic in debug builds and wrap to a large value in release builds.

Fix

  • Calculate completion metrics while holding the mutable block borrow.
  • End the borrow before removing the completed block from active_blocks.
  • Remove completed block statistics from both success and failure paths.
  • Replace unchecked counter decrement with checked_sub.
  • Return an explicit error for unknown, duplicate, or late completion events.
  • Add regression tests for successful, mixed, parallel, duplicate, and reused block-statistics cycles.

Tests

cargo test -p avail-light-client --bin avail-light-client
cargo test -p avail-light-client --no-default-features --bin avail-light-client
cargo test -p avail-light-fat --bin avail-light-fat
cargo test -p avail-light-fat --no-default-features --bin avail-light-fat
cargo clippy -p avail-light-client --no-default-features --bin avail-light-client -- -D warnings
cargo clippy -p avail-light-fat --no-default-features --bin avail-light-fat -- -D warnings

@zloglevel

Copy link
Copy Markdown
Contributor Author

@aterentic-ethernal Hi, Could you please review this PR at your convenience? Thank you very much.

@aterentic-ethernal aterentic-ethernal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for contribution :)

Signed-off-by: zloglevel <loglevel@outlook.com>
@zloglevel

Copy link
Copy Markdown
Contributor Author

Looks good, thank you for contribution :)

I have resolved the clippy warning. Please review it again.

@aterentic-ethernal Thanks.

@aterentic-ethernal
aterentic-ethernal merged commit 3deddbb into availproject:main Sep 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants