Skip to content

rpc: fix #628 active-chain txn-already-known distinction - #633

Closed
Hero-Gamer wants to merge 7 commits into
reardencode:masterfrom
Hero-Gamer:fix/628-txn-already-known
Closed

Hero-Gamer wants to merge 7 commits into
reardencode:masterfrom
Hero-Gamer:fix/628-txn-already-known

Conversation

@Hero-Gamer

@Hero-Gamer Hero-Gamer commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #628

Problem:
testmempoolaccept was returning txn-already-known for any txid found anywhere (including archive/reorged blocks), not just active chain. That conflates confirmed vs mempool paths.

Fix in crates/rbitcoin-rpc/src/methods/mempool.rs:

  • decode raw tx
  • lookup txid on active tip
  • if confirmed on active chain -> return txn-already-known
  • else -> mp.test_accept() (preserves txn-already-in-mempool for live mempool dups)
  • DB/query errors now propagated with rpc_error(ERR_MISC, "query failed: {e}") instead of being swallowed

Tests in crates/rbitcoin-rpc/src/methods_tests.rs:

  • testmempoolaccept_628_confirmed_is_already_known - active chain tx -> txn-already-known
  • testmempoolaccept_628_mempool_duplicate_is_already_in_mempool - live mempool path still works
  • testmempoolaccept_628_reorged_archive_not_already_known - after invalidateblock, tx exists only in archive, must be allowed=true (asserts allowed=true and reject-reason != txn-already-known)

CI on f9ce78e: 14 successful, 2 skipped, 0 failing (ci / codeql / core-functional green)

Scope: 2 files only - mempool.rs + methods_tests.rs

Fixes reardencode#628. Uses tx_fk_by_txid_tip + is_confirmed_strong (active-chain)
before mempool duplicate check. Preserves txn-already-in-mempool for live
dupes and handles reorg (archive-only tx not treated as known).
Fix silent dead branch unwrap_or(false) per CONTRIBUTING checklist.
Query/store failure now returns RPC error instead of being treated as
not-confirmed, which could cause incorrect accept/reject.

Uses ERR_MISC directly (not crate::server::ERR_MISC).
- Pins txn-already-known for active-chain confirmed
- Preserves txn-already-in-mempool for live dupes
- Ensures archive-only after invalidate is not reported as known
- Fixes fee/test setup to include tx in mined block
@rearden-grok

rearden-grok Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Taken over in the follow-up PR on rpc/testmempoolaccept-already-known: same tip + is_confirmed_strong seam, one pad for mempool dup / confirmed / archive, owner docs. Closing this fork PR so CI sits on the takeover branch. Thank you for #628 and the first implementation.

@rearden-grok

rearden-grok Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Takeover PR: #638

@rearden-grok

rearden-grok Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Takeover PR is #638 (already required-green).

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.

rpc: testmempoolaccept reports txn-already-in-mempool for confirmed transactions

1 participant