Skip to content

fix(minibf): adjust /network endpoint mappings - #773

Merged
scarmuega merged 1 commit into
mainfrom
fix/minibf-network
Oct 27, 2025
Merged

fix(minibf): adjust /network endpoint mappings#773
scarmuega merged 1 commit into
mainfrom
fix/minibf-network

Conversation

@scarmuega

@scarmuega scarmuega commented Oct 27, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added active stake tracking capability to complement existing live stake metrics, enabling distinction between current and epoch-specific stake values.
  • Chores

    • Updated reserve and treasury data initialization and network stake aggregation logic.

@coderabbitai

coderabbitai Bot commented Oct 27, 2025

Copy link
Copy Markdown

Walkthrough

The changes introduce active stake tracking alongside live stake in the account and network models, add explicit initialization for network reserves and treasury fields, and implement aggregation logic to compute network-level stake metrics from individual account states.

Changes

Cohort / File(s) Summary
Active Stake Method
crates/cardano/src/model.rs
Added pub fn active_stake(&self) -> u64 method to AccountState that computes active stake using epoch-specific go() value, complementing the existing live_stake() accessor.
Account Route Fields
crates/minibf/src/routes/accounts.rs
Updated account content construction to initialize reserves_sum and treasury_sum with explicit "0" strings instead of Default::default().
Network Stake Aggregation
crates/minibf/src/routes/network.rs
Added AccountState import; added live_stake: u64 and active_stake: u64 fields to NetworkModelBuilder; changed locked field computation from initial_pots.obligations() to initial_pots.utxos; implemented aggregation logic to sum live_stake() and active_stake() across all account states for network-level stake data.

Sequence Diagram(s)

sequenceDiagram
    participant Network as Network Model Builder
    participant Accounts as Account States
    participant Aggregator as Aggregation Logic
    participant Output as Final Response

    Network->>Accounts: iterate all AccountState entities
    Accounts->>Aggregator: provide live_stake() and active_stake()
    Aggregator->>Aggregator: sum live_stake() across all accounts
    Aggregator->>Aggregator: sum active_stake() across all accounts
    Aggregator->>Network: return aggregated totals
    Network->>Network: populate NetworkModelBuilder fields
    Network->>Output: build network response with aggregated stake
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • crates/minibf/src/routes/network.rs: Multiple interconnected changes affecting data flow; verify that stake aggregation logic correctly sums across all accounts and that the transition from initial_pots.obligations() to initial_pots.utxos is intentional.
  • crates/cardano/src/model.rs: Confirm that active_stake() correctly implements the distinction between epoch-specific and live stake semantics.
  • crates/minibf/src/routes/accounts.rs: Verify the reason for changing field initialization from Default::default() to explicit "0" strings and ensure this change is semantically equivalent.

Poem

🐰 A new stake awakens, both active and live,
From epochs and builders, the accounts now give,
Their values aggregated with care and precision,
The network now shines with computational vision! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix(minibf): adjust /network endpoint mappings" is directly related to the main changes in the pull request. The primary modifications are in crates/minibf/src/routes/network.rs, where significant adjustments are made to how stake data (live_stake and active_stake) are computed and populated in the network endpoint. The title correctly identifies both the affected crate (minibf) and the specific endpoint (/network), making it clear and specific enough for a developer scanning the history to understand this is about network endpoint adjustments. While the title could be slightly more specific about the nature of the adjustments (e.g., stake calculation), it is sufficiently descriptive and directly relevant to the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/minibf-network

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
crates/minibf/src/routes/network.rs (1)

259-272: Consider performance implications of iterating all accounts.

This aggregation iterates over every AccountState entity on each request to the /network endpoint. For networks with many accounts, this could become a performance bottleneck. Consider:

  • Caching the aggregated totals
  • Precomputing during epoch transitions
  • Using a separate aggregate tracking mechanism
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6977ee and 4bb47b1.

📒 Files selected for processing (3)
  • crates/cardano/src/model.rs (1 hunks)
  • crates/minibf/src/routes/accounts.rs (1 hunks)
  • crates/minibf/src/routes/network.rs (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
crates/minibf/src/routes/network.rs (2)
crates/cardano/src/model.rs (6)
  • new (150-159)
  • new (548-558)
  • new (743-759)
  • new (1496-1506)
  • live_stake (560-562)
  • active_stake (564-566)
crates/core/src/state.rs (1)
  • new (212-218)
crates/cardano/src/model.rs (3)
crates/cardano/src/rewards/mocking.rs (1)
  • active_stake (213-219)
crates/cardano/src/rupd/loading.rs (1)
  • active_stake (267-269)
crates/cardano/src/rewards/mod.rs (1)
  • active_stake (323-323)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Test (macos-14)
  • GitHub Check: Test (ubuntu-latest)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Test (macos-13)
🔇 Additional comments (3)
crates/minibf/src/routes/accounts.rs (1)

119-120: LGTM: Explicit initialization improves clarity.

The explicit "0".to_string() is clearer than Default::default() and makes the intent more obvious to readers.

crates/cardano/src/model.rs (1)

564-566: LGTM: Consistent implementation of active stake accessor.

The active_stake() method correctly mirrors live_stake() but uses the go() snapshot (epoch - 3), providing access to historically active stake. This is used by the network aggregation logic to compute network-level totals.

crates/minibf/src/routes/network.rs (1)

237-237: Verify the semantic change from obligations() to utxos for the locked field.

This changes what's reported as "locked" in the network supply response. Ensure this aligns with the intended semantics and verify against expected behavior or documentation.

@scarmuega
scarmuega merged commit 7e61c72 into main Oct 27, 2025
12 checks passed
@scarmuega
scarmuega deleted the fix/minibf-network branch October 27, 2025 12:33
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.

1 participant