Skip to content

fix: hook mempool config to sync pipeline#904

Merged
scarmuega merged 1 commit intomainfrom
fix/hook-mempool-confirm
Feb 16, 2026
Merged

fix: hook mempool config to sync pipeline#904
scarmuega merged 1 commit intomainfrom
fix/hook-mempool-confirm

Conversation

@scarmuega
Copy link
Member

@scarmuega scarmuega commented Feb 16, 2026

Summary by CodeRabbit

  • New Features
    • Added mempool update tracking to monitor transaction states as blocks are processed.
    • Introduced mempool synchronization with configurable finalization and drop thresholds to enable proper confirmation and cleanup of mempool transactions.

@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

This change introduces mempool update tracking across the cardano crate. A new MempoolUpdate struct captures chain points and transaction hashes, added as a method to the WorkUnit trait. The RollWorkUnit implementation extracts seen transactions from blocks, and the sync layer wires these updates into mempool confirmation logic with configurable thresholds.

Changes

Cohort / File(s) Summary
Core trait and type definitions
crates/core/src/work_unit.rs
Introduced public MempoolUpdate struct with point and seen_txs fields. Added mempool_updates() method to WorkUnit trait with default implementation returning empty vector.
Public API exports
crates/core/src/lib.rs, crates/cardano/src/lib.rs
Updated public re-exports to include MempoolUpdate alongside WorkUnit in core prelude; replaced MempoolTx with MempoolUpdate in cardano public imports.
RollWorkUnit implementation
crates/cardano/src/roll/work_unit.rs
Implemented mempool_updates() for RollWorkUnit, extracting transaction hashes from blocks in live mode; returns empty vector in non-live mode.
Sync layer integration
crates/core/src/sync.rs
Added private update_mempool() function processing mempool updates with MEMPOOL_FINALIZE_THRESHOLD and MEMPOOL_DROP_THRESHOLD constants. Integrated into execute_work_unit flow with error handling and warning logs.

Sequence Diagram(s)

sequenceDiagram
    participant sync as Sync Layer
    participant wu as WorkUnit
    participant domain as Domain
    participant mempool as Mempool Store

    sync->>wu: execute_work_unit()
    wu->>wu: process blocks
    sync->>wu: mempool_updates()
    wu-->>sync: Vec<MempoolUpdate>
    sync->>domain: update_mempool(updates)
    loop for each MempoolUpdate
        domain->>mempool: confirm(point, seen_txs,<br/>FINALIZE_THRESHOLD,<br/>DROP_THRESHOLD)
    end
    mempool-->>domain: result
    alt on error
        domain->>domain: emit warning
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Trp debug #901: Modifies mempool surface and core APIs by introducing/using MempoolUpdate and wiring mempool store confirmation operations.

Poem

🐰 A fuzzy-tailed update hops through the chain,
Tracking mempool txs sunshine and rain,
From blocks we extract what's been seen,
Confirm and finalize with thresholds keen,
The ledger now knows what's pristine! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: hook mempool config to sync pipeline' accurately describes the main objective of the changeset, which integrates mempool update handling into the synchronization pipeline.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ 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 fix/hook-mempool-confirm

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

🤖 Fix all issues with AI agents
In `@crates/core/src/sync.rs`:
- Around line 114-126: The call in update_mempool uses a hardcoded empty slice
for the unseen_txs parameter to domain.mempool().confirm because MempoolUpdate
currently only exposes seen_txs; fix this by either (A) documenting the API
limitation on MempoolUpdate and adding a clear comment in update_mempool
explaining why &[] is used, or (B) extending the MempoolUpdate type to include
an unseen_txs field and thread that through: add unseen_txs to the MempoolUpdate
struct, update any constructors/parsers producing MempoolUpdate, change
work.mempool_updates() consumers to return the new field, and replace the &[]
with &update.unseen_txs when calling domain.mempool().confirm in update_mempool.
🧹 Nitpick comments (2)
crates/core/src/work_unit.rs (1)

10-14: Consider adding #[derive(Debug)] to MempoolUpdate.

Other core types in this crate derive Debug. Without it, any code that needs to log or inspect a MempoolUpdate (e.g., via tracing's ? formatting) won't compile.

Proposed fix
 /// An update for the mempool based on a confirmed block.
+#[derive(Debug)]
 pub struct MempoolUpdate {
     pub point: ChainPoint,
     pub seen_txs: Vec<TxHash>,
 }
crates/core/src/sync.rs (1)

16-17: Consider adding threshold values to mempool configuration.

The PR mentions "hook mempool config to sync pipeline," but MEMPOOL_FINALIZE_THRESHOLD (6) and MEMPOOL_DROP_THRESHOLD (2) remain hardcoded constants. While the confirm() method signature supports configurable thresholds (as shown in tests with varying values), there's no way to adjust them without modifying code. If the intent is to fully hook mempool configuration, these thresholds could be added to RedbMempoolConfig (or a new mempool behavior config section) and read during sync.

Comment on lines +114 to +126
fn update_mempool<D: Domain>(domain: &D, work: &D::WorkUnit) {
for update in work.mempool_updates() {
if let Err(e) = domain.mempool().confirm(
&update.point,
&update.seen_txs,
&[],
MEMPOOL_FINALIZE_THRESHOLD,
MEMPOOL_DROP_THRESHOLD,
) {
warn!(?e, point = %update.point, "mempool confirm failed");
}
}
}
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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find the confirm function definition in Rust files
rg -n "fn confirm" --type=rust -B2 -A10 | head -80

Repository: txpipe/dolos

Length of output: 4924


🏁 Script executed:

#!/bin/bash
# Find mempool_updates definition and other confirm calls
echo "=== Searching for mempool_updates ===" 
rg -n "mempool_updates" --type=rust -B2 -A5 | head -100

echo -e "\n=== Searching for all confirm() calls ===" 
rg -n "\.confirm\(" --type=rust -B2 -A2 | head -150

Repository: txpipe/dolos

Length of output: 9057


🏁 Script executed:

#!/bin/bash
# Find MempoolUpdate structure definition
rg -n "struct MempoolUpdate" --type=rust -A10
rg -n "pub struct MempoolUpdate" --type=rust -A10

Repository: txpipe/dolos

Length of output: 1525


Clarify the design constraint for the empty unseen_txs parameter or enhance MempoolUpdate to support it.

The &[] passed as unseen_txs to confirm() is unavoidable with the current API design: MempoolUpdate only provides seen_txs, not unseen_txs. Either document this architectural limitation or extend MempoolUpdate to include unseen_txs if this data becomes available in the future.

🤖 Prompt for AI Agents
In `@crates/core/src/sync.rs` around lines 114 - 126, The call in update_mempool
uses a hardcoded empty slice for the unseen_txs parameter to
domain.mempool().confirm because MempoolUpdate currently only exposes seen_txs;
fix this by either (A) documenting the API limitation on MempoolUpdate and
adding a clear comment in update_mempool explaining why &[] is used, or (B)
extending the MempoolUpdate type to include an unseen_txs field and thread that
through: add unseen_txs to the MempoolUpdate struct, update any
constructors/parsers producing MempoolUpdate, change work.mempool_updates()
consumers to return the new field, and replace the &[] with &update.unseen_txs
when calling domain.mempool().confirm in update_mempool.

@scarmuega scarmuega merged commit d581c09 into main Feb 16, 2026
12 checks passed
@scarmuega scarmuega deleted the fix/hook-mempool-confirm branch February 16, 2026 19:39
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

Comments