Skip to content

fix(electrum): do not pick unindexed outputs for history lookup#2195

Open
zoedberg wants to merge 1 commit intobitcoindevkit:masterfrom
zoedberg:fix_populate_with_txids
Open

fix(electrum): do not pick unindexed outputs for history lookup#2195
zoedberg wants to merge 1 commit intobitcoindevkit:masterfrom
zoedberg:fix_populate_with_txids

Conversation

@zoedberg
Copy link
Copy Markdown

@zoedberg zoedberg commented Apr 29, 2026

Description

BdkElectrumClient::populate_with_txids queries each transaction's confirmation status by calling script_get_history on the script of one of its outputs. It currently picks the first output unconditionally. This breaks for transactions which first output is an OP_RETURN, because Electrum servers don't index OP_RETURN scripts and will return an empty history. This is a real-world scenario: protocols like RGB place an OP_RETURN commitment as the first output of every transaction.

Notes to the reviewers

The fix selects the first output which script is not OP_RETURN or a OP_FALSE OP_RETURN. If a transaction has only OP_RETURN/OP_FALSE OP_RETURN outputs, we fall back to the script of any input's previous output to query history. The only case still skipped is a coinbase with all unindexed outputs, since coinbases have no parent to fall back on.

Changelog notice

Fixed:
- `BdkElectrumClient::sync` now correctly retrieves confirmation status for transactions which first output is an `OP_RETURN` or `OP_FALSE OP_RETURN`

Checklists

All Submissions:

Copy link
Copy Markdown
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

Good catch!

Also, can you rebase on master to fix CI.

.expect("tx must have an output")
.clone();
.iter()
.find(|txo| !txo.script_pubkey.is_op_return())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should also filter out OP_FALSE OP_RETURN since that's used in ephemeral anchors and is excluded from the ElectrumX index.

https://github.com/spesmilo/electrumx/blob/24865dc3a8ac8d360e467df704777c1bbef72706/src/electrumx/lib/script.py#L75-L77

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

you're right, sorry I missed that, fixed!

@zoedberg zoedberg force-pushed the fix_populate_with_txids branch from 85c2bfe to 6d689c9 Compare April 29, 2026 11:46
@zoedberg zoedberg changed the title fix(electrum): do not pick OP_RETURN outputs for history lookup fix(electrum): do not pick unindexed outputs for history lookup Apr 29, 2026
@zoedberg
Copy link
Copy Markdown
Author

@evanlinjin Fixed and rebased

.then(|| script.clone())
}) {
Some(spk) => spk,
None => continue,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This means some txs will not be fetched even though they are provided by txids and they exist.

We may need to fetch a parent tx in order to obtain a spk that we can fetch history with.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it makes sense, thanks for the suggestion. please check if the fix is ok now

@zoedberg zoedberg force-pushed the fix_populate_with_txids branch from 6d689c9 to 88b1354 Compare April 29, 2026 12:23
Copy link
Copy Markdown
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

cACK 88b1354

Comment thread crates/electrum/src/bdk_electrum_client.rs Outdated
@zoedberg zoedberg force-pushed the fix_populate_with_txids branch from 88b1354 to 2e3d52e Compare April 30, 2026 08:56
Copy link
Copy Markdown
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

ACK 2e3d52e

@oleonardolima oleonardolima moved this to Needs Review in BDK Chain Apr 30, 2026
@oleonardolima oleonardolima added the bug Something isn't working label Apr 30, 2026
@oleonardolima oleonardolima added this to the Chain 0.24.0 milestone Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

3 participants