Skip to content

fix(onchain): return canonical txid for already-known raw broadcasts#123

Open
coreyphillips wants to merge 2 commits into
masterfrom
fix/broadcast-return-known-txid
Open

fix(onchain): return canonical txid for already-known raw broadcasts#123
coreyphillips wants to merge 2 commits into
masterfrom
fix/broadcast-return-known-txid

Conversation

@coreyphillips

Copy link
Copy Markdown
Collaborator

Summary

Retrying an already-accepted raw broadcast previously could not recover the txid. broadcast_raw_tx now computes the transaction's canonical txid locally and returns it on success. When Electrum reports the transaction is already known (already in a block, in the mempool, or otherwise accepted), that response is treated as success and the same locally computed txid is returned.

This lets the native apps complete Blocktank funding bookkeeping after an ambiguous network failure without relying on TrezorSignedTx.txid, which is intentionally unset during pure hardware signing. The change is self-contained in the onchain module, has no dependency on trezor-connect-rs, and makes no FFI API shape change.

Changes

  • Add decode_and_compute_txid: decodes hex, validates the transaction, and computes the canonical txid (returns the txid, never the wtxid).
  • Add is_already_known_broadcast_error: a focused, case-insensitive classifier for duplicate/already-accepted Electrum responses. It does not turn relay-policy or invalid-transaction rejections into success.
  • Rewrite broadcast_raw_tx to return the locally computed txid on a fresh broadcast and on an already-known response. Connectivity failures, unrelated broadcast rejections, invalid hex, and invalid transaction data keep their existing typed BroadcastError variants.
  • Bump to 0.4.1 and regenerate bindings (no generated source changes; FFI shape unchanged).

Handled already-known responses (case-insensitive): already in block chain, already in blockchain, already in mempool, already-in-block-chain, already-in-mempool, txn-already-known, transaction already exists.

Tests

  • Valid legacy transaction returns its canonical txid.
  • Valid SegWit transaction returns the txid, not the wtxid.
  • Each supported already-known response is classified as success.
  • Unrelated relay-policy, invalid-transaction, and connectivity errors remain failures.
  • Existing invalid-hex and invalid-transaction typed-error tests retained.

cargo test, cargo clippy, and cargo fmt pass.

Related

broadcast_raw_tx now computes the transaction's canonical txid locally and
returns it on success. Electrum "already known / already in mempool / already
in block chain" responses are treated as success and return that same txid, so
apps that broadcast separately from Trezor signing can complete funding
bookkeeping when retrying after an ambiguous network failure, without relying
on a signer-provided txid.

Duplicate-response classification is a focused, case-insensitive helper that
does not turn relay-policy or invalid-transaction rejections into success.
Connectivity failures, unrelated broadcast rejections, invalid hex, and invalid
transaction data keep their existing typed BroadcastError variants. There is no
FFI signature change.

Refs #122
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@coreyphillips

Copy link
Copy Markdown
Collaborator Author

Release created for testing here.

@coreyphillips coreyphillips requested a review from piotr-iohk July 10, 2026 17:00
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.

Return txid for already-known raw broadcasts

1 participant