Skip to content

Add new test mempool accept method#1212

Open
arminsabouri wants to merge 1 commit intoromanz:masterfrom
arminsabouri:test-mempool-accept
Open

Add new test mempool accept method#1212
arminsabouri wants to merge 1 commit intoromanz:masterfrom
arminsabouri:test-mempool-accept

Conversation

@arminsabouri
Copy link
Copy Markdown

@arminsabouri arminsabouri commented Aug 14, 2025

This commits adds a new rpc method
(blockchain.transaction.testmempoolaccept) which proxies to Bitcoin'd testmempoolaccept


Seeking a concept Ack/Nack here. My motivation for this PR comes from wanting to use Payjoin on wallets that use electrum as their primary block source. More info here.

Usage example

printf '{"id": 1, "method": "blockchain.transaction.testmempoolaccept", "params": ["020000000001015ca6f32bfb04a38c4aae9537986bd9c813def7199c06a421dfdaec18d9bad2050100000000fdffffff02a08601000000000016001465982603ab037608de3e476f0840bf4989758ab34656f405000000002200203165bfb4cc98db8126d5a7fe8ed11428766a10ad2cec56a216567e82d36ac63002473044022012caf070e368b64657fea0456812abd833e0f6c27c0861a6df7964cd1e8d8b7502207d002fdadc60d9177d8ad7bdec3eb6a3222373cb5b18f63df5c32552b93cd529014421022c2b9f1a1bd2d6856c4a111913479b4d836f8f4d09fe953e0ffa806a86482721ac736476a914466f377a02381abaaef42e599229047a3336b02e88ad0374cd00b26859020000"]}\n' | nc 127.0.0.1 60401

This commits adds a new rpc method
(`blockchain.transaction.testmempoolaccept`) which proxies to Bitcoind's
[testmempoolaccept](https://developer.bitcoin.org/reference/rpc/testmempoolaccept.html)
Copy link
Copy Markdown

@kwsantiago kwsantiago left a comment

Choose a reason for hiding this comment

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

Concept ACK.

Main issue is missing tests for this new RPC method. There should be basic test coverage for valid/invalid transaction scenarios at the minimum.

Comment thread src/daemon.rs
.context("failed to broadcast transaction")
}

pub(crate) fn test_mempool_accept(&self, tx: &Transaction) -> Result<bool> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider returning the full test result instead of just the allowed bool.

Comment thread src/electrum.rs
let tx_bytes = Vec::from_hex(tx_hex).context("non-hex transaction")?;
let tx = deserialize(&tx_bytes).context("invalid transaction")?;
let accepted = self.daemon.test_mempool_accept(&tx)?;
Ok(json!(accepted))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

May want to add something like:
Ok(json!({"allowed": accepted, "reject_reason": ...}))
Currently clients will get no diagnostic info when a tx is rejected.

Comment thread src/electrum.rs
"blockchain.scripthash.subscribe" => Params::ScriptHashSubscribe(convert(params)?),
"blockchain.scripthash.unsubscribe" => Params::ScriptHashUnsubscribe(convert(params)?),
"blockchain.transaction.broadcast" => Params::TransactionBroadcast(convert(params)?),
"blockchain.transaction.testmempoolaccept" => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this method name match Electrum protocol spec, or is this a custom extension? May want to document if the latter.

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.

2 participants