Skip to content

fix(node): feed RegionAccountant on delivered node→node pulls (#858) - #886

Merged
thiras merged 5 commits into
mainfrom
fix/858-region-pulled-accounting
Jun 13, 2026
Merged

thiras merged 5 commits into
mainfrom
fix/858-region-pulled-accounting

Conversation

@yigitdot

Copy link
Copy Markdown
Contributor

Summary

Fixes #858. RegionAccountant::record_pulled had zero production callers — #831/#834 landed the node-to-node cache-miss pull orchestrator (node_origin.rs) but never wired the accountant into it. Result: bytes_in stayed 0 in admin_v1_regionStats and the periodic region_bandwidth log line even while cache.node_to_node_pull_through_enabled pulls paid for inbound bytes — exactly the surface an operator uses to reconcile pull spend by region (#750).

Change

  • Add region_accountant: Arc<RegionAccountant> to NodeOriginDeps (mirrors the required metrics field).
  • Call record_pulled(&candidate.node_id, bytes.len()) in the delivered (Ok) arm of pull_from_candidate, right after record_outcome(... Delivered ...) — the inbound counterpart of the serve path's record_served (handlers/client.rs). On a full delivery paid bytes == blob length. Partially-paid failed pulls (the Err arm) are intentionally not counted.
  • Pass the runtime's already-instantiated region_accountant into NodeOriginDeps in runtime/mod.rs.
  • Refresh the now-stale record_pulled doc comment (it still claimed "the future pull orchestrator calls this; until then bytes_in reads 0").

Tests

  • Extends the headline pull test node_origin_pull_fills_and_records_reputation to map upstream A to region DE and assert snapshot() reports bytes_in == total_bytes for that region after a delivered pull. Since record_pulled has no other production caller, this fails without the wiring.
  • Adds an injectable StubRegionResolver + provisioned_origin_with_accountant test helper; other tests use a default empty-region accountant.

Verification

  • cargo build -p decdn-node ✅
  • cargo clippy -p decdn-node --all-targets ✅ (anti-panic lints clean)
  • cargo fmt -- --check ✅
  • cargo nextest run -p decdn-node — 486 lib tests + 11 node_origin_pull + 8 region tests all pass ✅

No dependency changes (Cargo.lock untouched).

🤖 Generated with Claude Code

`RegionAccountant::record_pulled` had zero production callers: #831/#834
landed the node-to-node cache-miss pull orchestrator but never wired the
accountant into it, so `bytes_in` stayed 0 in admin_v1_regionStats and the
periodic region_bandwidth log even while paid pulls flowed — the surface
operators use to reconcile pull spend by region (#750).

Pass the runtime's existing Arc<RegionAccountant> into NodeOriginDeps and
call record_pulled(&candidate.node_id, bytes.len()) in the delivered (Ok)
arm of pull_from_candidate, mirroring the serve path's record_served. On a
full delivery paid bytes == blob length; partially-paid failed pulls are
intentionally not counted.

Extends the headline pull test to assert bytes_in accumulates for the
upstream peer's region, and refreshes the now-stale record_pulled doc.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request integrates the RegionAccountant into the node-to-node pull orchestrator (NodeOrigin). It adds region_accountant to NodeOriginDeps and records inbound bytes via record_pulled upon successful delivery from a candidate node. Additionally, the changes update relevant tests to assert that delivered pulls correctly increment the inbound byte count for the respective region. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@github-actions

github-actions Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 86.17% (was 86.17%, ● 0.00%) — 35461/41152 lines

File Coverage Lines Δ
crates/node/src/node_origin.rs 91.08% 286/314 ▲ +0.09%
crates/node/src/region_accounting.rs 93.10% 162/174 ● 0.00%
crates/node/src/runtime/mod.rs 49.52% 878/1773 ▼ 0.03%
History
Commit Total Δ vs base
93050fd 86.17% ● 0.00%
2126153 86.17% ● 0.00%
8173def (HEAD) 86.17% ● 0.00%

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes missing per-region inbound bandwidth accounting for node→node paid pull-through by wiring RegionAccountant::record_pulled into the NodeOrigin pull orchestrator, so bytes_in is correctly reflected in admin_v1_regionStats and periodic region bandwidth logs (fixes #858).

Changes:

  • Add region_accountant: Arc<RegionAccountant> to NodeOriginDeps and pass it from the runtime.
  • Record inbound bytes on successful (Ok) node→node pulls via record_pulled(&candidate.node_id, bytes.len() as u64).
  • Extend the main node-origin pull integration test to assert bytes_in is incremented for a resolvable upstream region.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/node/src/node_origin.rs Adds region_accountant to deps and records inbound bytes on delivered pulls.
crates/node/src/runtime/mod.rs Wires the runtime’s existing region_accountant into NodeOriginDeps.
crates/node/src/region_accounting.rs Updates record_pulled doc comment to reflect the now-wired production call path.
crates/node/tests/node_origin_pull.rs Adds a stub region resolver/accountant plumbing and asserts bytes_in updates after a delivered pull.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

yigitdot and others added 4 commits June 13, 2026 02:46
…ng comment

Follow-up to PR review of #858:

- Extend node_origin_pull_falls_through_a_stalled_candidate to map the
  stalled (Err-arm) and delivered (Ok-arm) candidates to distinct regions
  and assert the snapshot counts only the delivered one — guarding the
  "partially-paid failed pulls are not counted" contract and multi-candidate
  attribution in a single assertion.
- Tighten the record_pulled call-site comment: payment is incremental per
  voucher interval (the whole-blob hash check makes bytes.len() == paid
  cumulative on a full Ok delivery), and region bytes_in tracks delivered,
  not spent, bytes — so it diverges from the voucher watermark on failed
  pulls by design.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@yigitdot

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request integrates the RegionAccountant into the node-to-node pull path (NodeOrigin). Specifically, it adds region_accountant to NodeOriginDeps and records inbound bytes via record_pulled upon successful cache-miss pull-through deliveries. The tests in node_origin_pull.rs have been updated to inject stubbed region accountants and assert that inbound bytes are correctly attributed to the upstream node's region on successful deliveries, while failed or stalled pulls are excluded. There are no review comments to evaluate, and we have no further feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@thiras
thiras merged commit 29c6698 into main Jun 13, 2026
38 of 40 checks passed
@thiras
thiras deleted the fix/858-region-pulled-accounting branch June 13, 2026 12:37
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.

node: bytes_in region accounting is never fed by the pull orchestrator — regionStats and the region log report 0 inbound while paid pulls flow

3 participants