Skip to content

fix(trp): adjust interface to match available mempool data#910

Merged
scarmuega merged 1 commit intomainfrom
dolos-mempool-confirms
Feb 17, 2026
Merged

fix(trp): adjust interface to match available mempool data#910
scarmuega merged 1 commit intomainfrom
dolos-mempool-confirms

Conversation

@scarmuega
Copy link
Member

@scarmuega scarmuega commented Feb 17, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced transaction status reporting with new confirmation count and confirmation timestamp tracking
    • Improved transaction state labeling for better clarity in transaction lifecycle visibility
    • Transaction logs now include detailed staging information and non-confirmation counts
  • Tests

    • Added comprehensive integration tests covering mempool transaction confirmation and drop policies

@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

This PR adds comprehensive integration tests for mempool confirm/drop policies, removes redundant unit tests, and extends transaction tracking structures with confirmation and stage information to support improved state reporting.

Changes

Cohort / File(s) Summary
Manifest & Test Setup
Cargo.toml
Added dev-dependency on dolos-redb3 and registered new integration test target mempool.
Unit Test Cleanup
crates/redb3/src/mempool.rs
Removed five unit tests (test_apply_seen, test_apply_unseen_rollback, test_finalize, test_finalize_below_threshold, test_drop_by_non_confirmations) to consolidate testing at integration level.
Data Structure Enhancements
crates/trp/src/methods.rs
Added stage and non_confirmations fields to LogEntry; added confirmations and confirmed_at fields to InflightTxInfo. Updated stage mapping for RolledBack from "pending" to "rolled_back". Updated serialization logic in trp_dump_logs and trp_peek_inflight to populate new fields.
Integration Test Suite
tests/mempool.rs
Comprehensive integration tests validating mempool finalization and drop policies across EphemeralMempool and RedbMempool implementations. Tests cover threshold boundaries, confirmations, rollbacks, and mixed-state scenarios using production threshold constants.

Sequence Diagram

sequenceDiagram
    participant Test as Integration Test
    participant Mempool as EphemeralMempool/<br/>RedbMempool
    participant TxState as Transaction State

    Test->>Mempool: Create transaction
    Mempool->>TxState: Store in pending state
    Test->>Mempool: Call acknowledge()
    Mempool->>TxState: Transition to acknowledged
    Test->>Mempool: Advance block N times
    Mempool->>TxState: Increment non_confirmations
    alt Threshold Met (≥6 blocks)
        Mempool->>TxState: Mark as finalized
    else Below Threshold
        Mempool->>TxState: Remain in pending state
    end
    Test->>Mempool: Verify finalized log / status
    Mempool-->>Test: Return transaction state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Possibly related PRs

  • txpipe/dolos#798 — Migrates workspace code to use the dolos-redb3 crate, complementing this PR's integration testing against it.

Poem

🐰 Hopping through the blocks with glee,
Finalization thresholds, six we see!
Tests confirm what mempool knows,
State tracked true where transaction goes. 🌸

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adjusting the TRP interface to expose mempool data like stage and confirmation counts that were previously unavailable.
Docstring Coverage ✅ Passed Docstring coverage is 96.88% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 dolos-mempool-confirms

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.

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 (2)
tests/mempool.rs (2)

413-495: Consider a macro to reduce test boilerplate.

The 16 test functions follow an identical pattern (create store, call assertion). A simple macro could cut the repetition:

macro_rules! mempool_tests {
    ($name:ident, $store_expr:expr) => {
        paste::paste! {
            #[test]
            fn [<$name _finalize_after_threshold>]() {
                assert_finalize_after_threshold(&$store_expr);
            }
            #[test]
            fn [<$name _drop_after_threshold>]() {
                assert_drop_after_threshold(&$store_expr);
            }
            // ... etc.
        }
    };
}

mempool_tests!(ephemeral, EphemeralMempool::new());
mempool_tests!(redb, RedbMempool::in_memory().unwrap());

This is entirely optional — the current explicit form is also perfectly readable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/mempool.rs` around lines 413 - 495, The tests repeat identical patterns
for EphemeralMempool and RedbMempool; introduce a macro (e.g., macro_rules!
mempool_tests) that takes a base name and a store expression and generates the
set of #[test] functions calling assert_finalize_after_threshold,
assert_drop_after_threshold, assert_confirm_resets_non_confirmations,
assert_rollback_to_pending, assert_re_confirm_after_rollback,
assert_not_finalized_before_threshold, assert_not_dropped_before_threshold, and
assert_mixed_confirm for that store; use paste::paste (or another
identifier-concatenation helper) inside the macro to create unique test function
names, then replace the 16 explicit tests with two macro invocations like
mempool_tests!(ephemeral, EphemeralMempool::new()) and mempool_tests!(redb,
RedbMempool::in_memory().unwrap()).

12-14: Production threshold constants are private and cannot be imported directly.

The constants MEMPOOL_FINALIZE_THRESHOLD and MEMPOOL_DROP_THRESHOLD in crates/core/src/sync.rs are not publicly exported, so the suggested import is not feasible without first making them public in the core crate.

The duplication concern remains valid: if production thresholds change, these tests will silently use stale values. Either:

  1. Make the constants public in dolos_core and import them here, OR
  2. Keep them duplicated but add a runtime assertion that compares against production values where possible, OR
  3. Document the coupling explicitly to prevent undetected drift.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/mempool.rs` around lines 12 - 14, The test duplicates production
thresholds that are private in crates/core/src/sync.rs; make the production
constants MEMPOOL_FINALIZE_THRESHOLD and MEMPOOL_DROP_THRESHOLD pub (e.g.,
change their declarations to pub const in sync.rs) and then import and use those
symbols in tests/mempool.rs instead of hardcoding FINALIZE_THRESHOLD /
DROP_THRESHOLD; alternatively, if you prefer not to change visibility, add a
runtime assertion in tests/mempool.rs that explicitly documents the coupling and
compares the test constants against the authoritative values (exposed via a new
accessor function or debug-only pub fn) so test drift is detected.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/trp/src/methods.rs`:
- Line 126: The serialized string for the enum variant
dolos_core::MempoolTxStage::RolledBack was changed to "rolled_back", causing a
breaking API change; revert the mapping in the serialization logic back to the
previous value (e.g., "pending") or, if the intent is to introduce the new
value, update all downstream consumers and documentation accordingly — locate
the match/serialization code that maps MempoolTxStage::RolledBack and either
restore the original string literal used previously or coordinate updating
clients and docs to accept "rolled_back".

---

Nitpick comments:
In `@tests/mempool.rs`:
- Around line 413-495: The tests repeat identical patterns for EphemeralMempool
and RedbMempool; introduce a macro (e.g., macro_rules! mempool_tests) that takes
a base name and a store expression and generates the set of #[test] functions
calling assert_finalize_after_threshold, assert_drop_after_threshold,
assert_confirm_resets_non_confirmations, assert_rollback_to_pending,
assert_re_confirm_after_rollback, assert_not_finalized_before_threshold,
assert_not_dropped_before_threshold, and assert_mixed_confirm for that store;
use paste::paste (or another identifier-concatenation helper) inside the macro
to create unique test function names, then replace the 16 explicit tests with
two macro invocations like mempool_tests!(ephemeral, EphemeralMempool::new())
and mempool_tests!(redb, RedbMempool::in_memory().unwrap()).
- Around line 12-14: The test duplicates production thresholds that are private
in crates/core/src/sync.rs; make the production constants
MEMPOOL_FINALIZE_THRESHOLD and MEMPOOL_DROP_THRESHOLD pub (e.g., change their
declarations to pub const in sync.rs) and then import and use those symbols in
tests/mempool.rs instead of hardcoding FINALIZE_THRESHOLD / DROP_THRESHOLD;
alternatively, if you prefer not to change visibility, add a runtime assertion
in tests/mempool.rs that explicitly documents the coupling and compares the test
constants against the authoritative values (exposed via a new accessor function
or debug-only pub fn) so test drift is detected.

dolos_core::MempoolTxStage::Finalized => "finalized",
dolos_core::MempoolTxStage::Dropped => "dropped",
dolos_core::MempoolTxStage::RolledBack => "pending",
dolos_core::MempoolTxStage::RolledBack => "rolled_back",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Breaking API change: RolledBack stage string changed.

This changes the serialized representation from (presumably) "pending" to "rolled_back". Any API consumer checking the stage field for rolled-back transactions will see a different value. Make sure downstream clients and documentation are updated accordingly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/trp/src/methods.rs` at line 126, The serialized string for the enum
variant dolos_core::MempoolTxStage::RolledBack was changed to "rolled_back",
causing a breaking API change; revert the mapping in the serialization logic
back to the previous value (e.g., "pending") or, if the intent is to introduce
the new value, update all downstream consumers and documentation accordingly —
locate the match/serialization code that maps MempoolTxStage::RolledBack and
either restore the original string literal used previously or coordinate
updating clients and docs to accept "rolled_back".

@scarmuega scarmuega merged commit f2ed245 into main Feb 17, 2026
12 checks passed
@scarmuega scarmuega deleted the dolos-mempool-confirms branch February 17, 2026 15:40
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