Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(consensus)!: mutate validator fee substate using deposit/withdrawal #1313

Open
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

sdbondi
Copy link
Member

@sdbondi sdbondi commented Feb 27, 2025

Description

Updates the latest vnfp change as per the current chain according to withdrawal(s) from a claim fee transaction
Fixed a bug with determining shard involvement for a transaction to account for the global shard.

Motivation and Context

As a leader gains fees from a block, it DOWN->UP the vnfp substate. However this substate could be locked by a transaction. When this transaction is committed, the diff DOWNs the previously locked substate which is invalid.

This PR collects validator withdrawals and fee deposits within a block and, "flattens" these fee pool updates into one state change for the block. It uses the latest state change as per the current uncommitted chain and updates it according to a withdrawal. Only one transaction may lock the vnfp (as with any other write lock), since validators only increase the vnfp substate value, this guarantees that the amount locked is less than the amount available within the vnfp substate (will cause a crash if not).

How Has This Been Tested?

New unit test,
Manually - running a tariswap test while claiming fees which previously broke the VN

What process can a PR reviewer use to test or verify this change?

As above

Breaking Changes

  • None
  • Requires data directory to be deleted
  • Other - Please specify

Summary by CodeRabbit

  • New Features

    • Introduced direct deposit/withdrawal operations in validator fee management.
    • Added support for processing validator fee claims during transaction execution.
  • Improvements

    • Enhanced fee display and formatting in wallet interfaces.
    • Streamlined transaction processing and consensus state updates.
    • Refined template matching for improved configuration handling.
  • Chores

    • Removed deprecated modules and simplified internal module organization for better maintainability.

Copy link

coderabbitai bot commented Feb 27, 2025

Walkthrough

The changes span multiple modules and components, refactoring how fee amounts and fee withdrawal data are accessed and handled. Direct field accesses were replaced with method calls across CLI and daemon commands. Import paths were simplified, redundant methods removed, and new helper methods and types (such as for validator fee withdrawals) added. Consensus, engine, and storage components were also refactored to incorporate fee withdrawal support, along with corresponding updates in the test harness and module reorganization.

Changes

Files Change Summary
applications/…/tari_dan_wallet_cli/src/command/transaction.rs, applications/…/tari_dan_wallet_daemon/src/handlers/validator.rs, applications/…/tari_validator_node_cli/src/command/transaction.rs Replaced direct fee and public key property accesses with method calls, encapsulating associated logic.
bindings/src/helpers/helpers.ts, bindings/src/index.ts, bindings/src/types/SubstateDiff.ts, bindings/src/types/ValidatorFeeWithdrawal.ts, bindings/src/types/wallet-daemon-client/WebauthnFinishRegisterResponse.ts Enhanced helper functions and types: allowed string substate IDs, exported the new ValidatorFeeWithdrawal, extended SubstateDiff with a fee_withdrawals field, and redefined WebauthnFinishRegisterResponse to an empty alias.
dan_layer/common_types/src/committee.rs, dan_layer/common_types/src/fee_pool.rs, dan_layer/common_types/src/shard_group.rs, dan_layer/common_types/src/substate_type.rs, dan_layer/common_types/src/versioned_substate_id.rs Removed redundant address-checking methods, updated ValidatorFeePoolAddress imports, and introduced new checks such as is_all_local and contains_or_global.
dan_layer/consensus/src/hotstuff/… (block_change_set.rs, common.rs, on_propose.rs, on_ready_to_vote_on_local_block.rs, substate_store/error.rs, substate_store/pending_store.rs, transaction_manager/manager.rs) Refactored consensus flow: renamed methods (e.g., insert_record to insert, up to up_substate), centralized transaction preparation via local_prepare_transaction, streamlined error handling, and integrated validator fee withdrawal processing.
dan_layer/consensus_tests/src/… (consensus.rs, support/epoch_manager.rs, support/executions_store.rs, support/harness.rs, support/transaction.rs, support/transaction_executor.rs, support/validator/builder.rs) Augmented test utilities with validator fee withdrawal fields, added key pair generation functions, and updated validator and transaction executor setups to support fee claim parameters.
dan_layer/engine/src/runtime/… (impl.rs, mod.rs, tracker.rs, working_state.rs) Simplified fee claim logic and import paths while integrating fee withdrawal tracking into state finalization and working state management.
dan_layer/engine_types/src/… (indexed_value.rs, instruction.rs, lib.rs, substate.rs, substate_serde.rs, validator_fee.rs) Reorganized module exports and imports; extended substate functionality with fee withdrawal methods; and added direct deposit/withdraw methods to ValidatorFeePool along with a new ValidatorFeeWithdrawal struct.
dan_layer/storage/src/consensus_models/… (block.rs, block_diff.rs, lock_intent.rs, substate_change.rs) Optimized commit and filtering logic for block diffs, renamed methods for clarity, implemented AsRef for lock intents, and removed obsolete substate change accessors.
dan_layer/template_lib/src/models/amount.rs, dan_layer/transaction/src/builder.rs, utilities/tariswap_test_bench/src/runner.rs, utilities/tariswap_test_bench/src/templates.rs Added a Neg trait implementation for Amount, refined ValidatorFeePoolAddress import paths, and adjusted template matching to be case-insensitive (with added clarifying comments).
dan_layer/static_epoch_oracle/… (Cargo.toml, src/config.rs, src/lib.rs, src/oracle.rs) Removed the static epoch oracle package along with its configuration and oracle modules, eliminating unused functionality.

Sequence Diagram(s)

sequenceDiagram
    participant TX as Transaction
    participant OP as OnPropose
    participant PS as PendingStore
    participant WS as WorkingState
    participant SD as SubstateDiff

    TX->>OP: Receive transaction
    OP->>OP: Execute local_prepare_transaction(tx)
    OP->>PS: Call update_in_place(substate_id, updater, creator)
    PS->>WS: Trigger withdraw_all_fees_from_pool(address)
    WS->>WS: Record fee withdrawal details
    WS->>SD: Generate substate diff (include fee_withdrawals)
    SD-->>OP: Return updated block diff
Loading

Possibly related PRs

Suggested reviewers

  • mrnaveira
  • stringhandler

Poem

I’m a nimble rabbit, hopping through code so bright,
With fee pools refined and methods taking flight,
Fields turned to functions with gentle precision,
Refactors and tests mark our clever decision.
In each commit, a new beat in our digital song,
I nibble these changes—coding magic all along! 🐰
Happy trails in every line we write!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
dan_layer/consensus/src/hotstuff/common.rs (1)

370-410: 🛠️ Refactor suggestion

Gracefully handle invalid leader fee values without panicking.
The protective assert for a negative or zero total_leader_fee might cause a crash if any unexpected input arises during production. Consider returning an error or early exit instead of an assert to preserve system stability. Also, returning an error from deposit_direct (rather than a boolean) could help identify and handle deposit failures more precisely.

- assert!(
-     total_leader_fee.is_positive(),
-     ...
- );
- if total_leader_fee.is_zero() { ... }

+ if total_leader_fee <= Amount::zero() {
+     return Err(HotStuffError::InvariantError(format!(
+         "Leader fee must be greater than 0, got {}",
+         total_leader_fee
+     )));
+ }
🧹 Nitpick comments (16)
dan_layer/common_types/src/shard_group.rs (2)

94-99: Add documentation for the new method

The implementation of contains_or_global is clear and follows a logical pattern, but it lacks inline documentation. Consider adding a doc comment to explain the purpose and behavior of this method, similar to other methods in this file.

+    /// Returns true if the shard is global or is contained within this shard group's range.
     pub fn contains_or_global(&self, shard: &Shard) -> bool {
         if shard.is_global() {
             return true;
         }
         self.contains(shard)
     }

94-99: Add unit tests for new method

The new contains_or_global method should have unit tests to ensure it works correctly for all scenarios: global shards, contained shards, and non-contained shards.

Consider adding a test like this to the test module:

#[test]
fn contains_or_global_works_correctly() {
    let sg = ShardGroup::new(10, 20);
    
    // Test with a global shard
    let global_shard = Shard::global(); // Assuming this constructor exists
    assert!(sg.contains_or_global(&global_shard));
    
    // Test with a contained shard
    let contained_shard = Shard::from(15);
    assert!(sg.contains_or_global(&contained_shard));
    
    // Test with a non-contained shard
    let non_contained_shard = Shard::from(30);
    assert!(!sg.contains_or_global(&non_contained_shard));
}
utilities/tariswap_test_bench/src/templates.rs (1)

21-21: Improved template name matching robustness.

Switching from exact case matching to case-insensitive matching improves the robustness of template retrieval. This change helps prevent issues where the template name might have different capitalization than expected.

dan_layer/storage/src/consensus_models/substate_change.rs (2)

16-17: TODO comment regarding transaction_id field.

Consider addressing this TODO as part of this PR or creating a follow-up task to evaluate if this field is necessary.


23-24: TODO comment regarding transaction_id field in Down variant.

Same TODO appears in both variants - consider addressing both TODOs together for consistency.

dan_layer/consensus_tests/src/support/transaction.rs (3)

39-39: Confirm if a borrowed type might simplify usage.
The function signature now takes validator_fee_withdrawals: Vec<ValidatorFeeWithdrawal>. If the call sites only need read access, consider accepting a slice reference (&[ValidatorFeeWithdrawal]) to avoid unnecessary cloning. Otherwise, this usage is fine.


90-99: Avoid hardcoded large constant in tests unless absolutely needed.
The amount: 100_000.into() is likely only for test scaffolding. Keeping it hardcoded is acceptable for quick testing, but allowing a configurable test constant might be more flexible for expanded test coverage.


102-103: Revise panic message for naming consistency.
The message references “vn fee” but the struct is named ValidatorFeePool. For clarity, consider adjusting the wording to “validator fee pool output.”

- "create_execution_result_for_transaction: Test harness only supports generating component, vn fee, and template outputs."
+ "create_execution_result_for_transaction: Test harness only supports generating component, validator fee pool, and template outputs."
dan_layer/consensus_tests/src/support/epoch_manager.rs (1)

95-122: Fluent interface pattern adoption.
Returning &Self from add_committees enhances chained usage. This is a neat approach, but consider adding unit tests to ensure method chaining works as intended.

dan_layer/engine/src/runtime/working_state.rs (3)

85-86: Field addition for validator_fee_withdrawals.
Storing attempted or completed fee withdrawals directly in WorkingState improves traceability of validator fee flows. Ensure that any concurrency or multi-transaction scenarios are well-handled.

Also applies to: 118-119


770-770: Minor rename in error context.
Renaming the function reference to StateTracker::withdraw_all_fees_from_pool can help pinpoint the correct scope in logs or debug traces.


775-778: Recording the withdrawal.
Appending the ValidatorFeeWithdrawal to an internal vector is simple and robust. It might be beneficial to also log these events for operational visibility.

dan_layer/engine_types/src/validator_fee.rs (1)

124-156: New direct deposit/withdraw methods.
These methods extend the fee pool’s functionality. The checks for negative or insufficient amounts are correct. If you anticipate large integer calculations, consider additional checks for overflow beyond checked_add and checked_sub_positive.

dan_layer/engine_types/src/substate.rs (1)

872-881: Single-Set Method for Fee Withdrawals
The assertion helps ensure this field is set exactly once. However, an assertion will panic at runtime if the field is unexpectedly set again.

Consider handling this scenario more gracefully (e.g., returning an error) instead of panicking. For instance:

 pub fn set_once_fee_withdrawals(&mut self, withdrawals: Vec<ValidatorFeeWithdrawal>) -> Result<&mut Self, SomeError> {
-    assert!(self.fee_withdrawals.is_empty(), "Fee withdrawals set more than once");
+    if !self.fee_withdrawals.is_empty() {
+        return Err(SomeError::AlreadySet);
+    }
     self.fee_withdrawals = withdrawals;
     Ok(self)
 }
dan_layer/consensus/src/hotstuff/substate_store/pending_store.rs (1)

94-172: In-Place Substate Update
Adding update_in_place simplifies or centralizes modifications to an existing substate. This approach helps consolidate creation vs. update logic.

To improve resilience, consider providing partial rollback or explicit error handling for the scenario where FUpdate fails after partial modifications, ensuring no inconsistent states are left in memory.

dan_layer/consensus/src/hotstuff/on_propose.rs (1)

741-829: Commented-Out End-Epoch Helper
This large block is currently commented out.

Consider removing or annotating why this code is kept commented. Dead code can lead to confusion or maintenance overhead.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 619c78e and 4cee108.

⛔ Files ignored due to path filters (7)
  • bindings/dist/helpers/helpers.d.ts is excluded by !**/dist/**
  • bindings/dist/index.d.ts is excluded by !**/dist/**
  • bindings/dist/index.js is excluded by !**/dist/**
  • bindings/dist/types/SubstateDiff.d.ts is excluded by !**/dist/**
  • bindings/dist/types/ValidatorFeeWithdrawal.d.ts is excluded by !**/dist/**
  • bindings/dist/types/ValidatorFeeWithdrawal.js is excluded by !**/dist/**
  • bindings/dist/types/validator-node-client/ValidatorNodeChange.d.ts is excluded by !**/dist/**
📒 Files selected for processing (53)
  • applications/tari_dan_wallet_cli/src/command/transaction.rs (1 hunks)
  • applications/tari_dan_wallet_daemon/src/handlers/validator.rs (1 hunks)
  • applications/tari_validator_node/src/p2p/services/mempool/service.rs (2 hunks)
  • applications/tari_validator_node_cli/src/command/transaction.rs (1 hunks)
  • bindings/src/helpers/helpers.ts (1 hunks)
  • bindings/src/index.ts (1 hunks)
  • bindings/src/types/SubstateDiff.ts (1 hunks)
  • bindings/src/types/ValidatorFeeWithdrawal.ts (1 hunks)
  • bindings/src/types/validator-node-client/ValidatorNodeChange.ts (1 hunks)
  • clients/wallet_daemon_client/src/types.rs (1 hunks)
  • dan_layer/common_types/src/committee.rs (2 hunks)
  • dan_layer/common_types/src/fee_pool.rs (1 hunks)
  • dan_layer/common_types/src/shard_group.rs (1 hunks)
  • dan_layer/common_types/src/substate_type.rs (2 hunks)
  • dan_layer/common_types/src/versioned_substate_id.rs (1 hunks)
  • dan_layer/consensus/src/hotstuff/block_change_set.rs (1 hunks)
  • dan_layer/consensus/src/hotstuff/common.rs (3 hunks)
  • dan_layer/consensus/src/hotstuff/on_propose.rs (9 hunks)
  • dan_layer/consensus/src/hotstuff/on_ready_to_vote_on_local_block.rs (1 hunks)
  • dan_layer/consensus/src/hotstuff/substate_store/error.rs (1 hunks)
  • dan_layer/consensus/src/hotstuff/substate_store/pending_store.rs (9 hunks)
  • dan_layer/consensus/src/hotstuff/transaction_manager/manager.rs (3 hunks)
  • dan_layer/consensus_tests/src/consensus.rs (11 hunks)
  • dan_layer/consensus_tests/src/support/epoch_manager.rs (5 hunks)
  • dan_layer/consensus_tests/src/support/executions_store.rs (2 hunks)
  • dan_layer/consensus_tests/src/support/harness.rs (9 hunks)
  • dan_layer/consensus_tests/src/support/transaction.rs (4 hunks)
  • dan_layer/consensus_tests/src/support/transaction_executor.rs (2 hunks)
  • dan_layer/consensus_tests/src/support/validator/builder.rs (4 hunks)
  • dan_layer/engine/src/runtime/impl.rs (2 hunks)
  • dan_layer/engine/src/runtime/mod.rs (1 hunks)
  • dan_layer/engine/src/runtime/tracker.rs (1 hunks)
  • dan_layer/engine/src/runtime/working_state.rs (7 hunks)
  • dan_layer/engine_types/src/indexed_value.rs (1 hunks)
  • dan_layer/engine_types/src/instruction.rs (1 hunks)
  • dan_layer/engine_types/src/lib.rs (1 hunks)
  • dan_layer/engine_types/src/substate.rs (6 hunks)
  • dan_layer/engine_types/src/substate_serde.rs (1 hunks)
  • dan_layer/engine_types/src/validator_fee.rs (4 hunks)
  • dan_layer/state_store_sqlite/migrations/2023-06-08-091819_create_state_store/up.sql (1 hunks)
  • dan_layer/state_store_sqlite/src/schema.rs (2 hunks)
  • dan_layer/static_epoch_oracle/Cargo.toml (0 hunks)
  • dan_layer/static_epoch_oracle/src/config.rs (0 hunks)
  • dan_layer/static_epoch_oracle/src/lib.rs (0 hunks)
  • dan_layer/static_epoch_oracle/src/oracle.rs (0 hunks)
  • dan_layer/storage/src/consensus_models/block.rs (2 hunks)
  • dan_layer/storage/src/consensus_models/block_diff.rs (2 hunks)
  • dan_layer/storage/src/consensus_models/lock_intent.rs (1 hunks)
  • dan_layer/storage/src/consensus_models/substate_change.rs (2 hunks)
  • dan_layer/template_lib/src/models/amount.rs (3 hunks)
  • dan_layer/transaction/src/builder.rs (1 hunks)
  • utilities/tariswap_test_bench/src/runner.rs (1 hunks)
  • utilities/tariswap_test_bench/src/templates.rs (1 hunks)
💤 Files with no reviewable changes (4)
  • dan_layer/static_epoch_oracle/src/config.rs
  • dan_layer/static_epoch_oracle/src/lib.rs
  • dan_layer/static_epoch_oracle/Cargo.toml
  • dan_layer/static_epoch_oracle/src/oracle.rs
✅ Files skipped from review due to trivial changes (12)
  • dan_layer/engine_types/src/indexed_value.rs
  • dan_layer/common_types/src/fee_pool.rs
  • dan_layer/engine/src/runtime/mod.rs
  • dan_layer/transaction/src/builder.rs
  • clients/wallet_daemon_client/src/types.rs
  • utilities/tariswap_test_bench/src/runner.rs
  • bindings/src/types/ValidatorFeeWithdrawal.ts
  • dan_layer/engine_types/src/instruction.rs
  • dan_layer/state_store_sqlite/migrations/2023-06-08-091819_create_state_store/up.sql
  • dan_layer/consensus/src/hotstuff/block_change_set.rs
  • dan_layer/engine_types/src/substate_serde.rs
  • dan_layer/consensus/src/hotstuff/on_ready_to_vote_on_local_block.rs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test
  • GitHub Check: clippy
  • GitHub Check: check nightly
  • GitHub Check: check stable
🔇 Additional comments (101)
applications/tari_dan_wallet_cli/src/command/transaction.rs (1)

550-550: Method call change aligns with validator fee pool encapsulation pattern.

The change from direct field access to method call (pool.amount()) is part of a broader refactoring effort around validator fee pools, providing better encapsulation and allowing for additional logic in the getter method.

bindings/src/types/SubstateDiff.ts (1)

4-4: New fee withdrawal tracking supports the validator fee management improvements.

The addition of the ValidatorFeeWithdrawal import and the new fee_withdrawals property to the SubstateDiff interface aligns with the PR's objective to improve validator fee substate management, particularly for tracking withdrawals from claim fee transactions.

Also applies to: 9-9

dan_layer/common_types/src/versioned_substate_id.rs (1)

258-262: API improvement with AsRef implementation.

This new implementation allows SubstateRequirementRef to be used with functions that accept AsRef<SubstateId>, making the API more flexible and consistent with Rust's standard patterns.

bindings/src/index.ts (1)

123-123: Exported ValidatorFeeWithdrawal completes the public API.

Exporting the ValidatorFeeWithdrawal type makes it available to consumers of the library, which is necessary since it's now used in the SubstateDiff interface.

bindings/src/types/validator-node-client/ValidatorNodeChange.ts (2)

3-3: New import added for SubstateAddress.

The import of SubstateAddress has been added to support the new field in the ValidatorNodeChange type.


6-6: Added shard_key field to ValidatorNodeChange Add operation.

The ValidatorNodeChange.Add operation now includes a shard_key field of type SubstateAddress, which enables better identification of the validator node's location within the sharding structure. This change aligns with the PR objective to improve validator fee management across shards.

dan_layer/storage/src/consensus_models/lock_intent.rs (1)

142-146: Good addition of AsRef trait implementation.

Implementing AsRef<SubstateId> for VersionedSubstateIdLockIntent improves interoperability with Rust components that expect AsRef traits. This follows Rust's best practices for enabling more ergonomic and generic code.

The implementation correctly delegates to the existing substate_id() method, which maintains code consistency and avoids duplication.

dan_layer/state_store_sqlite/src/schema.rs (2)

545-553: New table added for tracking validator fee changes.

The addition of the validator_fee_changes table is a critical part of this PR's objective to better handle validator fee deposits and withdrawals. This table will store records of fee changes, enabling proper tracking and reconciliation of fee movements.

The schema includes all necessary fields:

  • Primary key (id)
  • Block identifier (block_id)
  • Fee pool address (address)
  • Change amount (amount)
  • Timestamp (created_at)

607-607: Table properly registered for queries.

The validator_fee_changes table has been correctly added to the allow_tables_to_appear_in_same_query! macro, enabling it to be joined with other tables in queries.

utilities/tariswap_test_bench/src/templates.rs (1)

28-28: Consistent case-insensitive matching for TestFaucet template.

Using case-insensitive matching here as well ensures consistent behavior throughout the template matching logic.

applications/tari_dan_wallet_daemon/src/handlers/validator.rs (1)

92-92: Appropriate field access encapsulation.

The change from direct field access to method call (p.amount() instead of likely p.amount) follows good object-oriented practices by encapsulating the internal representation of the validator fee pool. This provides flexibility for future implementation changes without modifying the API contract.

dan_layer/consensus_tests/src/support/executions_store.rs (2)

11-11: LGTM: Appropriate import update.

The import has been correctly updated to include ValidatorFeeWithdrawal for the new field being added.


45-45: Fee withdrawals field added to support the PR objectives.

This new field aligns with the PR description of collecting validator withdrawals within a block and consolidating them into a single state change. This ensures proper tracking of fee withdrawals during test executions, which is essential for validating the new behavior.

dan_layer/template_lib/src/models/amount.rs (3)

23-23: Import correctly updated for Neg trait.

The import has been updated to include the Neg trait which is implemented below.


35-35: Serialization support added conditionally.

The addition of borsh::BorshSerialize support is properly guarded by a feature flag, maintaining backward compatibility.


163-169:

❓ Verification inconclusive

Neg trait implementation enables crucial fee withdrawal functionality.

This implementation supports the PR's key objective of handling validator fee withdrawals by allowing Amount instances to be negated. This is essential for representing withdrawals as negative amounts, which simplifies the math operations when consolidating fee deposits and withdrawals.

Consider adding tests to verify the negation behavior works as expected.


🏁 Script executed:

#!/bin/bash
# Check if tests for Amount negation exist
rg -A 2 -B 2 "fn.*neg" --glob "*.rs" | grep -i "test"

Length of output: 53


Neg trait implementation is vital for the fee withdrawal logic, but no tests currently verify its behavior.

The implementation in dan_layer/template_lib/src/models/amount.rs (lines 163-169) cleanly inverts the underlying value, fulfilling the PR's objective for handling validator fee withdrawals. However, our searches did not reveal any tests that verify this behavior. Please add comprehensive tests to confirm that negating an Amount consistently produces the expected negative value.

dan_layer/common_types/src/substate_type.rs (2)

7-7: LGTM: Import correctly updated.

The import has been updated to include Substate which is used in the new implementation below.


59-63: Useful convenience implementation for type conversion.

This implementation provides a direct conversion from &Substate to SubstateType, allowing for more concise code when determining substate types. It appropriately leverages the existing conversion from SubstateValue to SubstateType.

This supports the PR objective by making it easier to work with validator fee pool substates in the updated consensus logic.

dan_layer/consensus/src/hotstuff/substate_store/error.rs (1)

22-23: New error variant looks good for invariant violations.

This addition provides a clear way to report invariant errors with specific details, which is valuable for debugging and error handling.

dan_layer/engine_types/src/lib.rs (1)

37-39: Good refactoring of validator fee module.

The reorganization from vn_fee_pool to validator_fee makes sense, and the public re-export ensures backward compatibility.

applications/tari_validator_node_cli/src/command/transaction.rs (1)

390-391: Improved encapsulation by replacing field access with method calls.

Changing from direct field access to method calls is a good practice for better encapsulation and supports the PR's objectives for fee pool management.

dan_layer/engine/src/runtime/impl.rs (2)

47-47: Import update aligns with module reorganization.

Updated import path for ValidatorFeePoolAddress is consistent with the module changes in engine_types.


2243-2244: Simplified return statement.

Minor code improvement that maintains the same functionality while making the code cleaner.

dan_layer/engine/src/runtime/tracker.rs (1)

305-306:

✅ Verification successful

Integrate validator fee withdrawals in substate diff generation.

This change adds support for collecting validator fee withdrawals in the finalize process, passing them to the generate_substate_diff method. This aligns with the PR objective of consolidating validator fee updates into a single state change.


🏁 Script executed:

#!/bin/bash
# Check how fee_withdrawals is used in related files
rg -A 5 -B 5 "generate_substate_diff.*fee_withdrawals" --type rust

Length of output: 1039


Integration Confirmed: Validator Fee Withdrawals in Substate Diff Generation

The updated code correctly captures validator fee withdrawals and passes them to generate_substate_diff. The shell script output confirms that the following changes are present in dan_layer/engine/src/runtime/tracker.rs:

  • Retrieving the fee withdrawals with state.take_validator_fee_withdrawals()
  • Passing these withdrawals into state.generate_substate_diff along with the transaction receipt and substates.

This implementation meets the PR objective by consolidating validator fee updates into a single state change process.

bindings/src/helpers/helpers.ts (1)

76-80: Expanded the function signature to accept string-type substate IDs.

The function now accepts string substate IDs in addition to SubstateId objects, making it more flexible for various call sites.

dan_layer/consensus_tests/src/support/validator/builder.rs (4)

36-36: Added fee claim public key field to ValidatorBuilder.

This new field supports the validator fee claim functionality, allowing validators to authenticate when claiming fees.


52-52: Initialized fee_claim_public_key with default value.

Properly initializes the new field with a default value in the constructor.


81-84: Added method to set custom fee claim public key.

This builder method follows the same pattern as other setter methods in the class, allowing custom configuration of the fee claim public key.


127-127: Pass fee claim public key to epoch manager.

Ensures the fee claim public key is properly passed to the epoch manager when spawning a validator.

dan_layer/storage/src/consensus_models/substate_change.rs (2)

79-84:

❓ Verification inconclusive

Added mutable access to substates.

This new method replaces the previous down() method with one that provides mutable access to the substate in the Up variant. This is a significant change in functionality that supports the PR objective of managing validator fee substates when locked.


🏁 Script executed:

#!/bin/bash
# Check for any remaining usages of the old down method
rg "\.down\(\)" --type rust

# Check how the new up_mut method is used
rg "\.up_mut\(\)" --type rust

Length of output: 61


Action: Confirm the replacement of down() with up_mut() and manually verify dependent code usage.

  • The new method up_mut() correctly provides mutable access to the substate in the Up variant.
  • A repository-wide search did not find any remaining calls to the old down() method, and no obvious usages of up_mut() were detected.
  • Please manually verify that no downstream code expects the previous behavior of down() and that the transition to up_mut() aligns with the PR’s objective of managing validator fee substates when locked.

72-77:

✅ Verification successful

Renamed method for better clarity.

The method rename from up to up_substate makes the purpose clearer and helps distinguish from the new up_mut method.


🏁 Script executed:

#!/bin/bash
# Check for any remaining usages of the old method name
rg "\.up\(\)" --type rust

Length of output: 27


Method rename verified. The renaming from up to up_substate clearly enhances code clarity, and our verification did not find any residual usages of the old .up() method in the repository.

  • Verified file: dan_layer/storage/src/consensus_models/substate_change.rs shows the correct implementation of up_substate.
  • No instances of .up() were found throughout the codebase.
applications/tari_validator_node/src/p2p/services/mempool/service.rs (2)

23-23: Import simplification

The removal of the iter module from the imports is a clean simplification, as it's no longer needed with the updated implementation at line 251-255.


251-255: Code simplification and improved efficiency

Changed from using iter::once() with includes_any_address to directly using includes_substate_address. This is a more direct and efficient approach that avoids creating an intermediate iterator for a single item.

dan_layer/consensus/src/hotstuff/transaction_manager/manager.rs (2)

199-199: API improvement for local input checks

Replaced specific address checking with the more efficient is_all_local method that works directly with transaction inputs. This aligns with the PR's goal of improving fee substate handling by streamlining the approach to determining transaction locality.


255-255: API improvement for output locality checks

Similar to the change at line 199, this replaces complex address-based checking with a direct is_all_local call on transaction outputs. This provides a more consistent and efficient approach to determining if a transaction's outputs are all within the local shard.

dan_layer/storage/src/consensus_models/block_diff.rs (3)

39-39: Parameter name clarification

Renamed parameter from info to committee, improving code readability by more accurately reflecting the parameter's purpose and type.


45-45: Improved filter logic for substates

Changed from checking individual substate IDs to checking if the committee's shard group contains or is global to the change's shard. This is a significant improvement that aligns with the PR's goal of better handling validator fee substates across shards.

The new approach focuses on the shard relationship rather than individual substates, which should provide more accurate filtering when processing validator fee deposits and withdrawals that span multiple shards.


64-64: Method name simplification

Renamed method from insert_record to insert, making the API more concise while maintaining its functionality. This is a good cleanup that follows naming conventions of similar operations.

dan_layer/storage/src/consensus_models/block.rs (2)

641-645: Enhanced type flexibility with generic constraints

Added clearer generic constraints to commit_diff requiring both write capabilities and the ability to dereference to a read transaction. This enhancement supports the PR's goal of properly managing validator fee substates by ensuring the method has appropriate access for both reading current state and writing consolidated changes.


669-671: Cleaner block diff destructuring

Improved the code by directly destructuring block_diff into its components, making the subsequent iteration over changes cleaner and more direct.

dan_layer/consensus_tests/src/support/transaction.rs (2)

17-18: Imports look consistent with new validator fee functionality.
These imports are correctly introduced and align with the introduced usage of ValidatorFeePool and ValidatorFeeWithdrawal.


123-123: Ensure no double-writing of fee withdrawals.
Calling set_once_fee_withdrawals is correct, but verify that no other code attempts to override these withdrawals later. The “once” naming suggests it should only be called once; confirm the logical flow so it’s never inadvertently called multiple times, resulting in an overwrite or partial application.

dan_layer/consensus_tests/src/support/transaction_executor.rs (2)

110-117: Handle unmatched validator fee withdrawals explicitly.
The .filter_map(...) approach silently skips any withdrawal with no matching input. If those withdrawals should never be missing a corresponding input, consider raising an error instead of ignoring them, to detect misconfigurations early.


126-126: Signature change properly passes validator fee withdrawals.
Forwarding spec.validator_fee_withdrawals to create_execution_result_for_transaction is well-aligned with the new logic. Ensure test coverage validates this pipeline fully.

dan_layer/consensus/src/hotstuff/common.rs (3)

43-43: New import aligns with substate and fee functionality.
Importing substate::SubstateDiff, template_models::Amount, and ValidatorFeePool is consistent with the changes below.


51-51: Importing LeaderStrategy is properly aligned with usage.
This import is consistent with references to leader-based logic introduced in this file.


313-332: Filter fee withdrawals by committee.
In filter_diff_for_committee, calling set_once_fee_withdrawals to include only relevant validator fee withdrawals enhances consistency with how up/down items are filtered. Confirm that partial filtering of withdrawals is intended when multiple committees are involved.

dan_layer/consensus_tests/src/consensus.rs (7)

15-18: New imports look good.

They are used for the new functionality (e.g., to_public_key_bytes), and no issues or unused imports are apparent.


21-22: Relevant imports for fee pool logic and key pair generation.

These are clearly utilized in the new fee-claim test scenario, and the usage appears consistent.


41-41: ValidatorFeeWithdrawal import is consistent.

The import aligns with the new fee-withdrawal logic, ensuring the struct is accessible for test usage.


919-919: Added validator_fee_withdrawals field in ExecuteSpec initialization.

Setting an empty vector here is appropriate for transactions that do not claim fees.


927-927: Repeated addition of validator_fee_withdrawals.

Similar usage; no issues. Ensures future fee withdrawals can be handled without modifying existing transaction logic.


1189-1189: Validator fee withdrawals for single_shard_unversioned_inputs.

Maintaining a default empty vector avoids unexpected side effects in tests that do not involve fee claims.


1597-1684: New multishard_validator_fee_claim test.

This test correctly demonstrates claiming validator fees from a cross-committee scenario. However, you may wish to:

  • Verify the final deducted balance of the fee pool to ensure the withdrawal is reflected, thus fully confirming the claim logic.

Would you like a script to inspect the final substate value post-claim and confirm the deducted balance?

dan_layer/common_types/src/committee.rs (2)

4-4: Imports for RangeInclusive are valid.

They support the substate address range method; usage is consistent.


257-264: Local substate check logic.

The method is_all_local correctly handles global substates in multi-committee contexts by returning false. This meets the intended design to restrict “local” to only those substates mapped to this committee.

dan_layer/consensus_tests/src/support/harness.rs (6)

14-14: New PublicKey import.

Allows the harness to handle fee claim key injection without extraneous references.


221-224: Provides constant access to TEST_NUM_PRESHARDS.

A neat approach for consistent test configuration.


225-227: num_committees getter.

Clean accessor for the test’s committee count.


543-543: Optional claim_keys field on TestBuilder.

Allows specifying a fee claim key and VN destination.


601-604: Builder method for claim key.

Cleanly sets up the claim_keys tuple for test usage.


666-667: Fee claim public key injection in validator.

Ensures the validator is aware of the claim key during startup.

dan_layer/consensus_tests/src/support/epoch_manager.rs (4)

20-25: Imports look clean and consistent.
No immediate concerns here; the introduction of TestVnDestination alongside the other utility imports appears correct and aligned with the new usage below.


65-71: Method signature enhancement.
Adding fee_claim_pk as a parameter is a logical extension. Ensure all call sites are adjusted to pass this new argument to avoid errors.

Would you like a script to detect any references to clone_for without the updated signature?


80-81: Correct usage of fee_claim_public_key.
Setting fee_claim_public_key in both branches ensures that the newly-cloned ValidatorNode always has the intended claim key. This is good for consistency.

Also applies to: 89-90


123-132: New set_claim_keys method.
The method is straightforward and maintains the chaining pattern. Confirm that callers properly handle scenarios where no validator nodes match the destination.

dan_layer/engine/src/runtime/working_state.rs (5)

31-32: New imports for validator fee types.
Importing ValidatorFeePoolAddress and ValidatorFeeWithdrawal is logical for the new fee-handling functionality.


753-764: Ownership check and usage.
This block correctly checks ownership for fee withdrawal (require_ownership). The pattern aligns with the existing approach to validating privileged operations. Good job ensuring that any direct substate references are consistent with engine-level checks.


838-840: Retrieving fee withdrawals.
Exposing a take_validator_fee_withdrawals method neatly encapsulates the data handover. This approach avoids partial reads and helps maintain consistent state.


1136-1141: Substate diffusion of fee withdrawals.
Passing fee_withdrawals into generate_substate_diff and setting them on the diff is a clean design choice, making the final SubstateDiff more comprehensive.


1142-1145: Downing existing substates before upserting new ones.
This approach is consistent with the usual "down then up" pattern for substate changes. Ensure any unrelated changed lines keep that pattern.

dan_layer/engine_types/src/validator_fee.rs (6)

1-2: License header update.
The updated year aligns with the current timeline.


11-12: Serialization import.
Introducing serde for serialization and deserialization is consistent with the rest of the codebase.


157-159: Adding amount() accessor.
Using a dedicated getter clarifies usage and preserves the invariants of the struct’s state field.


161-163: Getter for claim public key.
Good alignment with the typical Rust pattern of providing an owned or borrowed accessor.


165-165: Retain existing withdraw_all logic.
No changes needed, as the method still handles the complete removal of funds. The inline docstring reaffirms usage in the engine.


185-196: Introducing ValidatorFeeWithdrawal struct.
A well-defined structure for capturing withdrawal events. This paves the way for robust tracking and auditing.

dan_layer/engine_types/src/substate.rs (9)

57-59: Imports for Validator Fee Pool Components
These newly added imports properly align with the subsequent usage of ValidatorFeePool, ValidatorFeePoolAddress, and ValidatorFeeWithdrawal.


181-186: Accessor for Validator Fee Pool Address
The new as_validator_fee_pool_address function is consistent with the code pattern used for other substate variants. It provides a convenient way to retrieve the ValidatorFeePoolAddress.


292-295: Checker for Validator Fee Pool IDs
Adding is_validator_fee_pool complements the existing checks for other substate types. It improves clarity when working with validator fee pool substates.


764-769: Converter to Validator Fee Pool
The into_validator_fee_pool method for SubstateValue mirrors the existing conversion patterns. Logic and naming appear consistent.


857-857: New Field for Fee Withdrawals
The fee_withdrawals vector in SubstateDiff allows consolidating validator fee withdrawal records, aligning with the larger fee management refactor.


861-861: Initialize Fee Withdrawals Vector
Initializing fee_withdrawals to an empty vector follows the established pattern for newly added fields.


869-871: 'up' Method for SubstateDiff
Adding a separate up method for pushing substates is consistent and keeps the code organized. No concerns found.


888-889: 'down' Method for SubstateDiff
This straightforward helper adds a down-substate pair to the internal collection, consistent with the existing pattern.


909-912: Getter for Validator Fee Withdrawals
Returning a slice reference is memory-efficient and matches the rest of the API style.

dan_layer/consensus/src/hotstuff/substate_store/pending_store.rs (8)

11-11: Import of SubstateType
Including the substate_type::SubstateType import appears to prepare usage for substate classification or debugging.


26-26: Engine Types Substate Imports
Bringing Substate, SubstateDiff, SubstateId, and SubstateValue into scope is consistent with the changes that handle fee withdrawals and in-place updates.


67-92: Retrieving the Latest Change from Store
This helper function consolidates logic for obtaining the most recent up/down state from both the pending block diff and the underlying store. Looks logically sound.

Please confirm that all relevant edge cases (like multiple block diffs, stale references, or concurrency issues) are handled correctly in higher layers.


183-189: Handling an 'Up' Substate in get
Returning the cloned substate if present is consistent with typical up-substate logic.


232-234: Skipping Validator Fee Pools for Down Iteration
if id.is_validator_fee_pool() { continue; } ensures that fee pool substates are treated separately from standard up/down logic, matching the new approach.


245-249: Skipping Validator Fee Pools for Up Iteration
Similarly bypassing fee pool updates here avoids standard substate flow, aligning with specialized handling for validator fees.


261-295: Applying Validator Fee Withdrawals
The in-place update calls value_mut.as_validator_fee_pool_mut() and checks for balance sufficiency, ensuring correct invariants. Good defensive coding.


695-696: Exposing get_latest_lock_by_id Publicly
Making this method public allows external code to retrieve lock details for a substate when necessary. The logic inside remains consistent.

dan_layer/consensus/src/hotstuff/on_propose.rs (7)

419-419: Adding can_propose_epoch_end Parameter
Renaming or adding this parameter clarifies when the code can produce an epoch-ending block rather than everyday transitions.


434-443: Conditional Logic for Epoch-End vs. Normal Batch
Reading from can_propose_epoch_end ensures correct branching for either standard transaction proposals or an end-of-epoch scenario.


446-449: Instantiating PendingSubstateStore
Setting up the store with parent block ID and preshards is consistent with the new fee management approach.


452-461: Commands for Epoch End
When can_propose_epoch_end is true, it immediately inserts the EndEpoch command. This approach is straightforward and clear.


1212-1223: Utility for Non-Local Shards
Collecting shards not belonging to the local committee is essential for foreign proposal logic. Straightforward approach.


1231-1231: New commands Field in ProposalBatch
Storing commands alongside foreign proposals, burnt UTXOs, etc., aligns with the block-building flow.


1239-1243: Extended Display Output
Including the number of new commands in the fmt output improves logging and observability of the batch’s contents.

Copy link

github-actions bot commented Feb 27, 2025

Test Results (CI)

17 tests   16 ✅  1m 1s ⏱️
 1 suites   0 💤
 1 files     1 ❌

For more details on these failures, see this check.

Results for commit ec82ad2.

♻️ This comment has been updated with latest results.

@sdbondi sdbondi force-pushed the consensus-validator-fees-fix branch from 769038c to 3441d23 Compare February 27, 2025 13:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 769038c and 6c1f29f.

📒 Files selected for processing (4)
  • dan_layer/common_types/src/shard_group.rs (2 hunks)
  • dan_layer/consensus/src/hotstuff/block_change_set.rs (2 hunks)
  • dan_layer/consensus/src/hotstuff/on_propose.rs (9 hunks)
  • dan_layer/storage/src/consensus_models/substate_change.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • dan_layer/consensus/src/hotstuff/block_change_set.rs
  • dan_layer/consensus/src/hotstuff/on_propose.rs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test
  • GitHub Check: check stable
  • GitHub Check: clippy
  • GitHub Check: check nightly
🔇 Additional comments (3)
dan_layer/common_types/src/shard_group.rs (2)

94-99: LGTM - Clear implementation of special case handling for global shards

The contains_or_global method elegantly handles the special case of global shards while still leveraging the existing contains method for standard shard checks. The method name clearly describes its purpose and the implementation follows the single responsibility principle.


204-219: Good test coverage for all scenarios

The test properly validates all three important scenarios for the contains_or_global method:

  1. Global shard returns true (regardless of range)
  2. Contained shard returns true
  3. Non-contained shard returns false

This ensures the method works correctly across all expected use cases.

dan_layer/storage/src/consensus_models/substate_change.rs (1)

16-17:

❓ Verification inconclusive

Consider investigating these TODO comments about transaction_id fields.

There are TODO comments questioning whether the transaction_id fields are needed in both the Up and Down variants. These fields are currently used in the transaction_id() method and in the Display implementation. If they're not needed elsewhere, consider removing them to reduce memory overhead and simplify the data structure.

Also applies to: 23-24


🏁 Script executed:

#!/bin/bash
# Check other usages of transaction_id in SubstateChange across the codebase
rg "SubstateChange.*transaction_id" --type rust

Length of output: 315


Action Required: Evaluate necessity of the transaction_id field in both variants.

After verification, the transaction_id field is used only in the two locations within SubstateChange (in pattern matching for both the Up and Down variants) as well as in the transaction_id() method and in the Display implementation. Please review if maintaining the field in both variants is justified. If it turns out that the field isn’t needed elsewhere (for example, if its value can be derived or managed more efficiently), consider removing it to minimize memory overhead and simplify the structure.

  • File(s): dan_layer/storage/src/consensus_models/substate_change.rs
  • Location: Lines 16-17 and 23-24

Comment on lines +72 to 77
pub fn up_substate(&self) -> Option<&Substate> {
match self {
SubstateChange::Up { substate, .. } => Some(substate),
_ => None,
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider the redundancy between substate() and up_substate() methods.

The newly renamed method up_substate() appears to have identical functionality to the existing substate() method (lines 43-48). Both return Option<&Substate> for the Up variant and None for the Down variant. This redundancy could cause confusion for developers. Consider:

  1. Deprecating one of these methods
  2. Updating documentation to clarify the distinction between them
  3. Removing one if they are truly redundant

The renaming from up() to up_substate() improves clarity about what is being returned, but the duplication of functionality is concerning.

@sdbondi sdbondi force-pushed the consensus-validator-fees-fix branch from 6c1f29f to ec82ad2 Compare February 28, 2025 10:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
dan_layer/consensus_tests/src/support/epoch_manager.rs (1)

123-132: New set_claim_keys method for fee claim public key management

This new method allows updating fee claim public keys for multiple validator nodes based on a destination criteria. It supports the PR objective of managing validator fee withdrawals.

Consider adding documentation to explain the purpose of this method and how it integrates with the broader validator fee management functionality. The method is well-designed to allow for method chaining with the return of &Self.

+/// Updates the fee claim public key for validator nodes matching the specified destination.
+/// This allows for controlling which public key is authorized to claim fees for specific validators.
+/// Returns a reference to self to enable method chaining.
 pub async fn set_claim_keys(&self, dest: TestVnDestination, claim_key: PublicKey) -> &Self {
dan_layer/engine_types/src/validator_fee.rs (1)

1-2: Copyright year should be verified.

The copyright year is set to 2025 - should this be the current year (2024) or is this intentional for future-dating?

-//   Copyright 2025 The Tari Project
+//   Copyright 2024 The Tari Project
dan_layer/common_types/src/committee.rs (1)

257-265: Add documentation for the special case behavior with global substates.

The implementation correctly checks if all provided substate IDs are local to this committee. However, there's a special case where global substates are considered "local" when there's only one committee (num_committees <= 1).

Consider adding a doc comment to clarify this behavior:

+    /// Checks if all provided substate IDs are local to this committee.
+    /// 
+    /// Returns:
+    /// - `false` if any ID is global and there is more than one committee
+    /// - `false` if any ID is not included in this committee's shard range
+    /// - `true` otherwise (including the case where a global ID exists but there's only one committee)
     pub fn is_all_local<T: AsRef<SubstateId>, I: IntoIterator<Item = T>>(&self, substate_ids: I) -> bool {
         substate_ids.into_iter().all(|substate_id| {
             let substate_id = substate_id.as_ref();
             if substate_id.is_global() && self.num_committees > 1 {
                 return false;
             }
             self.includes_substate_id(substate_id)
         })
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c1f29f and ec82ad2.

⛔ Files ignored due to path filters (7)
  • bindings/dist/helpers/helpers.d.ts is excluded by !**/dist/**
  • bindings/dist/index.d.ts is excluded by !**/dist/**
  • bindings/dist/index.js is excluded by !**/dist/**
  • bindings/dist/types/SubstateDiff.d.ts is excluded by !**/dist/**
  • bindings/dist/types/ValidatorFeeWithdrawal.d.ts is excluded by !**/dist/**
  • bindings/dist/types/ValidatorFeeWithdrawal.js is excluded by !**/dist/**
  • bindings/dist/types/wallet-daemon-client/WebauthnFinishRegisterResponse.d.ts is excluded by !**/dist/**
📒 Files selected for processing (52)
  • applications/tari_dan_wallet_cli/src/command/transaction.rs (1 hunks)
  • applications/tari_dan_wallet_daemon/src/handlers/validator.rs (1 hunks)
  • applications/tari_validator_node/src/p2p/services/mempool/service.rs (2 hunks)
  • applications/tari_validator_node_cli/src/command/transaction.rs (1 hunks)
  • bindings/src/helpers/helpers.ts (1 hunks)
  • bindings/src/index.ts (1 hunks)
  • bindings/src/types/SubstateDiff.ts (1 hunks)
  • bindings/src/types/ValidatorFeeWithdrawal.ts (1 hunks)
  • bindings/src/types/wallet-daemon-client/WebauthnFinishRegisterResponse.ts (1 hunks)
  • clients/wallet_daemon_client/src/types.rs (1 hunks)
  • dan_layer/common_types/src/committee.rs (2 hunks)
  • dan_layer/common_types/src/fee_pool.rs (1 hunks)
  • dan_layer/common_types/src/shard_group.rs (2 hunks)
  • dan_layer/common_types/src/substate_type.rs (2 hunks)
  • dan_layer/common_types/src/versioned_substate_id.rs (1 hunks)
  • dan_layer/consensus/src/hotstuff/block_change_set.rs (2 hunks)
  • dan_layer/consensus/src/hotstuff/common.rs (3 hunks)
  • dan_layer/consensus/src/hotstuff/on_propose.rs (9 hunks)
  • dan_layer/consensus/src/hotstuff/on_ready_to_vote_on_local_block.rs (1 hunks)
  • dan_layer/consensus/src/hotstuff/substate_store/error.rs (1 hunks)
  • dan_layer/consensus/src/hotstuff/substate_store/pending_store.rs (9 hunks)
  • dan_layer/consensus/src/hotstuff/transaction_manager/manager.rs (3 hunks)
  • dan_layer/consensus_tests/src/consensus.rs (11 hunks)
  • dan_layer/consensus_tests/src/support/epoch_manager.rs (5 hunks)
  • dan_layer/consensus_tests/src/support/executions_store.rs (2 hunks)
  • dan_layer/consensus_tests/src/support/harness.rs (9 hunks)
  • dan_layer/consensus_tests/src/support/transaction.rs (4 hunks)
  • dan_layer/consensus_tests/src/support/transaction_executor.rs (2 hunks)
  • dan_layer/consensus_tests/src/support/validator/builder.rs (4 hunks)
  • dan_layer/engine/src/runtime/impl.rs (2 hunks)
  • dan_layer/engine/src/runtime/mod.rs (1 hunks)
  • dan_layer/engine/src/runtime/tracker.rs (1 hunks)
  • dan_layer/engine/src/runtime/working_state.rs (7 hunks)
  • dan_layer/engine_types/src/indexed_value.rs (1 hunks)
  • dan_layer/engine_types/src/instruction.rs (1 hunks)
  • dan_layer/engine_types/src/lib.rs (1 hunks)
  • dan_layer/engine_types/src/substate.rs (6 hunks)
  • dan_layer/engine_types/src/substate_serde.rs (1 hunks)
  • dan_layer/engine_types/src/validator_fee.rs (4 hunks)
  • dan_layer/state_store_sqlite/migrations/2023-06-08-091819_create_state_store/up.sql (1 hunks)
  • dan_layer/static_epoch_oracle/Cargo.toml (0 hunks)
  • dan_layer/static_epoch_oracle/src/config.rs (0 hunks)
  • dan_layer/static_epoch_oracle/src/lib.rs (0 hunks)
  • dan_layer/static_epoch_oracle/src/oracle.rs (0 hunks)
  • dan_layer/storage/src/consensus_models/block.rs (2 hunks)
  • dan_layer/storage/src/consensus_models/block_diff.rs (2 hunks)
  • dan_layer/storage/src/consensus_models/lock_intent.rs (1 hunks)
  • dan_layer/storage/src/consensus_models/substate_change.rs (2 hunks)
  • dan_layer/template_lib/src/models/amount.rs (3 hunks)
  • dan_layer/transaction/src/builder.rs (1 hunks)
  • utilities/tariswap_test_bench/src/runner.rs (1 hunks)
  • utilities/tariswap_test_bench/src/templates.rs (1 hunks)
💤 Files with no reviewable changes (4)
  • dan_layer/static_epoch_oracle/src/lib.rs
  • dan_layer/static_epoch_oracle/src/config.rs
  • dan_layer/static_epoch_oracle/Cargo.toml
  • dan_layer/static_epoch_oracle/src/oracle.rs
🚧 Files skipped from review as they are similar to previous changes (39)
  • applications/tari_dan_wallet_cli/src/command/transaction.rs
  • dan_layer/storage/src/consensus_models/lock_intent.rs
  • bindings/src/types/ValidatorFeeWithdrawal.ts
  • bindings/src/index.ts
  • utilities/tariswap_test_bench/src/runner.rs
  • applications/tari_dan_wallet_daemon/src/handlers/validator.rs
  • utilities/tariswap_test_bench/src/templates.rs
  • dan_layer/consensus/src/hotstuff/substate_store/error.rs
  • dan_layer/engine_types/src/indexed_value.rs
  • dan_layer/engine/src/runtime/tracker.rs
  • dan_layer/common_types/src/fee_pool.rs
  • dan_layer/common_types/src/versioned_substate_id.rs
  • applications/tari_validator_node/src/p2p/services/mempool/service.rs
  • dan_layer/engine_types/src/substate_serde.rs
  • dan_layer/transaction/src/builder.rs
  • dan_layer/engine_types/src/lib.rs
  • dan_layer/template_lib/src/models/amount.rs
  • clients/wallet_daemon_client/src/types.rs
  • dan_layer/storage/src/consensus_models/substate_change.rs
  • dan_layer/engine/src/runtime/mod.rs
  • applications/tari_validator_node_cli/src/command/transaction.rs
  • dan_layer/consensus/src/hotstuff/transaction_manager/manager.rs
  • dan_layer/consensus/src/hotstuff/on_ready_to_vote_on_local_block.rs
  • dan_layer/consensus_tests/src/support/executions_store.rs
  • dan_layer/consensus_tests/src/support/validator/builder.rs
  • dan_layer/engine/src/runtime/impl.rs
  • dan_layer/consensus_tests/src/support/transaction_executor.rs
  • dan_layer/consensus_tests/src/support/transaction.rs
  • dan_layer/storage/src/consensus_models/block_diff.rs
  • dan_layer/consensus/src/hotstuff/block_change_set.rs
  • dan_layer/consensus/src/hotstuff/common.rs
  • bindings/src/helpers/helpers.ts
  • dan_layer/state_store_sqlite/migrations/2023-06-08-091819_create_state_store/up.sql
  • dan_layer/storage/src/consensus_models/block.rs
  • dan_layer/consensus/src/hotstuff/on_propose.rs
  • dan_layer/consensus/src/hotstuff/substate_store/pending_store.rs
  • dan_layer/consensus_tests/src/support/harness.rs
  • bindings/src/types/SubstateDiff.ts
  • dan_layer/engine_types/src/instruction.rs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test
  • GitHub Check: clippy
  • GitHub Check: check nightly
🔇 Additional comments (39)
dan_layer/common_types/src/shard_group.rs (2)

94-99: Clear implementation of global or local shard check.

The method provides a useful abstraction by combining the global shard check with the existing contains logic, which will help simplify code that needs to handle both global and local shards.


204-219: Comprehensive test coverage for the new method.

The test effectively covers all three possible scenarios: global shard, contained shard, and non-contained shard, ensuring the method behaves correctly in all cases.

dan_layer/consensus_tests/src/consensus.rs (6)

15-18: Improved import organization.

The import update from tari_consensus demonstrates better organization by importing specific modules rather than using the entire namespace.


21-22: Added support for key generation from seeds.

This addition of create_key_pair_from_seed is necessary for the new validator fee claim test where deterministic key generation is needed.


41-41: Added ValidatorFeeWithdrawal type.

This import supports the new functionality for validator fee management, essential for the new withdrawal system.


919-920: Added validator fee withdrawals field.

The new field in ExecuteSpec supports the PR objective of tracking fee withdrawals.


927-928: Consistently added validator fee withdrawals field.

All instances of ExecuteSpec have been consistently updated with the new field, maintaining the structure's integrity across the codebase.

Also applies to: 1189-1190, 1273-1274, 1284-1285, 1374-1375, 1385-1386, 1560-1561


1597-1684: Comprehensive test implementation for validator fee claims.

This new test is crucial for validating the PR's core functionality - handling validator fee withdrawals across multiple shards. The test:

  1. Sets up committees across multiple shards
  2. Creates a deterministic key pair for claiming
  3. Creates a fee pool address based on the claim key
  4. Builds and executes a claim transaction with appropriate withdrawals
  5. Verifies the transaction is committed and fee pool exists

The test effectively validates the entire lifecycle of validator fee withdrawals, which directly addresses the PR objective.

dan_layer/consensus_tests/src/support/epoch_manager.rs (3)

20-25: Import addition of TestVnDestination

The codebase imports TestVnDestination which is now used in the new set_claim_keys method. This aligns with the PR objectives of managing validator fee withdrawals.


65-71: Breaking change to clone_for method signature

The clone_for method now requires a new fee_claim_pk parameter which is used to set the fee_claim_public_key field of the ValidatorNode struct. This is a breaking change that supports the PR objective of updating validator fee substate management.

Make sure all calling code has been updated to provide this additional parameter. This change is consistent with the PR description that mentions this is a breaking change requiring data directory deletion.

Also applies to: 80-80, 89-89


95-121: Modified add_committees to enable method chaining

The add_committees method now returns &Self and has an explicit return statement, enabling method chaining for a more fluent API.

dan_layer/engine/src/runtime/working_state.rs (7)

31-32: New imports look appropriate.

The imports for ValidatorFeePoolAddress and ValidatorFeeWithdrawal are correctly added to support the new fee withdrawal tracking functionality.


85-85: Good addition of withdrawal tracking.

New field to track validator fee withdrawals aligns well with the PR objective of managing validator fee substate (vnfp) effectively.


118-118: Proper initialization of the new field.

The validator_fee_withdrawals vector is correctly initialized as empty in the constructor.


748-780: Authorization and withdrawal tracking implemented correctly.

The function properly checks ownership before allowing withdrawal and tracks the withdrawn amount with the appropriate validator address. This change aligns with the PR objective of improving how withdrawals are handled when the vnfp substate is locked.


838-840: Efficient implementation of withdrawal collection.

Using mem::take is a good pattern here as it efficiently replaces the vector with an empty one while returning the original contents, avoiding unnecessary allocations.


1132-1141: Updated to include fee withdrawals in substate diff.

The method now correctly accepts fee withdrawals as a parameter and properly integrates them into the substate diff. This supports the PR objective of consolidating updates into a single state change.


1142-1155: Maintain correct handling of versioning and substates.

The loop has been slightly restructured but maintains the same logic for handling versioning of substates, special cases for empty fee pools, and correctly upserting substates into the diff.

dan_layer/engine_types/src/validator_fee.rs (7)

11-12: Import simplification looks good.

The imports have been simplified to use serde directly and tari_bor specifically for BorTag, which improves code clarity.


124-137: Direct withdrawal implementation is well-designed.

The withdraw_direct method properly validates that the withdrawal amount is valid before updating the pool amount, using checked_sub_positive to prevent underflow. The warning comment about not using this in the engine is important and the #[must_use] attribute ensures the caller checks the return value.


139-155: Direct deposit handles negative amounts correctly.

The deposit_direct method properly validates the deposit amount, ensuring it's not negative before attempting to add it to the pool. It uses checked_add to prevent overflow and returns a boolean to indicate success, which is marked with #[must_use] to ensure callers check the result.


157-159: Accessor pattern implementation is good.

Adding the amount() method is a good practice to encapsulate direct field access, which will make future refactoring easier.


161-163: Consistent accessor pattern.

The claim_public_key() accessor method matches the accessor pattern for amount(), providing consistent API design.


165-168: Updated docstring provides clearer context.

The updated docstring clarifies that withdraw_all is used in the engine to withdraw funds and create a Bucket, which differentiates it from the new withdraw_direct method.


186-195: New withdrawal data structure appropriately designed.

The ValidatorFeeWithdrawal struct is properly designed with serialization support and appropriate fields for address and amount. The TypeScript export configuration will ensure bindings are correctly generated.

dan_layer/engine_types/src/substate.rs (10)

57-59: New imports are properly referenced.

The new imports for ValidatorFeePool, ValidatorFeePoolAddress, and ValidatorFeeWithdrawal are correctly added to support the new functionality.


181-186: Accessor method implementation is complete.

The as_validator_fee_pool_address method correctly handles extraction of the validator fee pool address from the SubstateId enum, following the established pattern for other substate types.


292-294: Type checking method implementation is correct.

The is_validator_fee_pool method follows the same pattern as other type checking methods in the class, using the matches! macro for a clean implementation.


764-769: Conversion method added for API completeness.

The into_validator_fee_pool method correctly implements the conversion from SubstateValue to ValidatorFeePool, following the same pattern as other conversion methods, which maintains API consistency.


857-857: New field added to track fee withdrawals.

The fee_withdrawals field is correctly added to the SubstateDiff struct to track validator fee withdrawals, which is a key part of the PR objectives to consolidate fee updates.


865-865: Proper initialization of the new field.

The fee_withdrawals vector is properly initialized as empty in the constructor, ensuring consistent behavior with other fields.


869-871: Method renaming improves clarity.

Renaming the parameter from address to id better reflects that it's a SubstateId type, which improves code readability and clarity.


874-881: Set-once method has appropriate safeguards.

The set_once_fee_withdrawals method correctly includes an assertion to ensure it's only called once, which prevents accidental overwriting of withdrawal data. The return of &mut self allows for method chaining.


888-889: Parameter renaming maintained for consistency.

The down method parameter was also renamed from address to id for consistency with the up method, which is a good practice.


909-911: Accessor method for fee withdrawals is properly implemented.

The validator_fee_withdrawals method correctly returns a slice reference to the fee withdrawals, allowing read-only access to the data.

dan_layer/common_types/src/substate_type.rs (2)

7-7: Updated import to include the Substate type.

The import statement has been updated to include Substate alongside SubstateValue, which is needed for the new From implementation below.


59-63: LGTM: Added convenient From implementation for &Substate.

This implementation elegantly converts from &Substate to SubstateType by leveraging the existing conversion from SubstateValue. This is a useful enhancement that makes it more convenient to work with substates in the codebase.

dan_layer/common_types/src/committee.rs (2)

4-4: Updated imports for the new functionality.

Added RangeInclusive to the imports, which is used in the existing to_substate_address_range method.


257-265:

✅ Verification successful

Verify this method's usage in transaction manager.

According to the PR summary, this change is part of fixing how validator fee substate changes are handled when locked by transactions. Let's verify that this method provides the necessary functionality for the transaction manager.


🏁 Script executed:

#!/bin/bash
# Check how the new is_all_local method is used in the transaction manager
rg -A 5 "is_all_local" dan_layer/consensus/src/hotstuff/transaction_manager/

Length of output: 1758


Verification of is_all_local Usage in Transaction Manager

The usage of is_all_local in the transaction manager appears to be correct. The method is invoked both on transaction inputs (via transaction.transaction.all_inputs_iter()) and on resulting outputs (via execution.resulting_outputs()), ensuring that checks for local-only processing are appropriately applied. This aligns with the PR summary intent of correctly handling validator fee substate changes when transaction locks are involved.

  • Location: dan_layer/consensus/src/hotstuff/transaction_manager/manager.rs
    • Confirmed usage on transaction inputs.
    • Confirmed usage on transaction outputs.
  • Outcome: The functionality provided by is_all_local is effectively integrated into the transaction management logic, and no discrepancies were identified during verification.

export interface WebauthnFinishRegisterResponse {
success: boolean;
}
export type WebauthnFinishRegisterResponse = Record<string, never>;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Breaking change: WebauthnFinishRegisterResponse no longer contains a success property

This change modifies WebauthnFinishRegisterResponse from an interface with a success: boolean property to an empty record type (Record<string, never>). This is a breaking change that will affect any client code that was previously accessing the success property.

Since this is auto-generated from Rust code via ts-rs, ensure that:

  1. Client TypeScript/JavaScript code has been updated to handle this new structure
  2. Consumers of this API are aware of the change
  3. This breaking change is mentioned in release notes or migration guides

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants