Skip to content

BIP153: SENDTEMPLATE - #1937

Draft
ajtowns wants to merge 1 commit into
bitcoin:masterfrom
ajtowns:202508-sendtemplate
Draft

ajtowns wants to merge 1 commit into
bitcoin:masterfrom
ajtowns:202508-sendtemplate

Conversation

@ajtowns

@ajtowns ajtowns commented Aug 18, 2025 •

Copy link
Copy Markdown
Contributor

@jonatack

Copy link
Copy Markdown
Member

Post to bitcoindev group hasn't made it through

fixed, published

@murchandamus murchandamus left a comment

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.

Interesting idea, thanks for sharing.

Comment thread bip-ajtowns-sendtemplate.md Resolved
Comment thread bip-ajtowns-sendtemplate.md Outdated
Comment on lines +73 to +74
5. A block containing the transactions making up the payload must not
exceed four million weight units as defined in [BIP-141][BIP-141].

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.

Have you considered allowing more data than just the top block? Otherwise, would you recommend that a node requests a template after each block is found for the first few new blocks after they come online? Have you considered a reconciliation-based approach akin to Erlay?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See discussion in the delving thread.

I think having two blocks of txs could make sense, but in adversarial situations it doubles the potential memory usage and it's not immediately clear what would be a sensible way of addressing that.

My thought is that deploying a simple design and getting some real-world data to iterate on makes sense. You could update the specification to announce "SENDTEMPLATE 2" indicating you support v2, which indicates to your peers they can send you a "GETTEMPLATE 2" message requesting a 2MvB template rather than a 1MvB template, eg.

Likewise sending set differences through could make sense (and wouldn't need the complexity of minisketch since the sender knows their own previous templates), but there's still a lot of design space left, so getting real-world data also seems useful for resolving that. (Likewise an updated spec could allow SENDTEMPLATE 2D to indicate deltas are supported, and GETTEMPLATE 2 $hash could request a 2MvB template encoded as a delta against the previous template with hash $hash)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed the limit from 4M weight units to 8M weight units.

@ajtowns
ajtowns force-pushed the 202508-sendtemplate branch 2 times, most recently from 55a8927 to 4352c1b Compare August 21, 2025 04:50

@murchandamus murchandamus left a comment

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.

From an editorial perspective, this looks close to ready. I noticed that there is no Rationale section, yet. You could perhaps link to the Delving discussion as that seems to have been the most active one I saw.

@ajtowns

ajtowns commented Aug 27, 2025

Copy link
Copy Markdown
Contributor Author

Updated with post-history in metadata and some rationale

@murchandamus murchandamus left a comment

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.

Thanks, good improvements.

@ajtowns

ajtowns commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

Time to request a bip number then I guess?

@murchandamus

Copy link
Copy Markdown
Member

Let’s call this BIP 153 then!

@murchandamus murchandamus changed the title BIP Draft SENDTEMPLATE BIP 153 SENDTEMPLATE Sep 4, 2025
@murchandamus murchandamus changed the title BIP 153 SENDTEMPLATE BIP153: SENDTEMPLATE Sep 4, 2025

### `gettemplate`

1. The `gettemplate` message is defined as a message with `pchCommand ==

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason to not also allocate a message ID from the range specific in BIP 324?

The guidelines specify that if a message is sent more than once per connection then a number you be allocated (IIUC both this and the template message):

We recommend reserving 1-byte type IDs for message types that are sent more than once per direction per connection.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(I have in my backlog an idea for having these ids get determined dynamically during initial connection negotiation, which avoids the problem of BIPs attempting to assign the same id to different messages)

Comment thread bip-ajtowns-sendtemplate.md Resolved
potentially providing better privacy than if only the nodes directly
involved in the transaction would rebroadcast it.

## Specification

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I notice there's no p2p protocol version bump, why is that?. IIUC, this message is only useful if you're talking with a peer that's directly peered, or is the Bitcoin node backing a mining pool. A p2p version bump would permit nodes to seek out other nodes that meet this requirement, instead of blindly connecting out to find such nodes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you want to seek out peers that support a feature you need a service flag, not a protocol version. Using a pre-verack negotiation message gives you all the benefits of a protocol version bump, with less potential for contention where two bips developed at the same time both bump the protocol version to the same value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah yeah I meant service flag 😅.

The service flag would also allow for peers to find other supporting peers via DNS queries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm hopeful that it will eventually be widely supported enough not to need people to seek out supporting clients explicitly -- it should be pretty low overhead to just provide templates. Also, I think you'd want something more subtle than just "does the node support this protocol" when working out who to peer with -- you want templates that are about equally as diverse as miners: getting the same template from multiple peers isn't very helpful, and getting templates that don't match any miners also isn't helpful. So I think it makes more sense to get some experience with the behaviour of things before speccing out best practices or new features for peer discovery.

@murchandamus

Copy link
Copy Markdown
Member

@ajtowns: What’s your status on this one? Are you still planning changes or waiting for some people to finish their review of this PR?

@ajtowns

ajtowns commented Sep 16, 2025

Copy link
Copy Markdown
Contributor Author

I think this is fine to merge as draft, further review/changes can happen in that state as I understand it.

@jonatack jonatack left a comment

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.

I may have overlooked it, but at first glance it looks like the draft is missing important specification on how to implement the goals set forth in the Motivation section. For instance, which peers to request templates from, when/how often, and how the template data is to be used. (Perhaps also limits on memory use for storing templates and/or how this interacts with the -maxmempool limits.) Do you intend to add these to the Specification or Recommendations section, or for a separate BIP?

A few non-blocking comments follow.

Comment thread bip-0153.md Resolved
Comment thread bip-0153.md Resolved
Comment thread bip-0153.md Resolved
Comment thread bip-0153.md Resolved
Comment thread bip-0153.md Resolved
Comment thread bip-0153.md
* adding a payload to the `sendtemplate` message to indicate that the
`gettemplate` payload will be accepted

## Recommendations

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps this could use some recommendations re privacy implications?

IIRC, there was some push back augments devs re BIP 35 (mempool message), as it can be used to implement relay correlation and tagging attacks against peers. As the message enables a peer to obtain the entire mempool of another peer, it can feasibly be used by an adversary to figure out: who relayed what, which transactions may have originated directly from the node, etc.

Some related PRs from the bitcoind repo:

Also pool operators may want to filter out transactions that they received via out of band transaction submission.

@murchandamus murchandamus Sep 29, 2025 •

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.

As the message enables a peer to obtain the entire mempool of another peer, it can feasibly be used by an adversary to figure out: who relayed what, which transactions may have originated directly from the node, etc.

Are you here talking about the mempool message or this proposal? It seems to me that the top two blocks of the mempool would be significantly more difficult/expensive to exploit for fingerprinting than the whole mempool, especially if nodes repeatedly use this new peer service to synchronize their top mempool as any new transactions that are received this way would be broadcast to peers.

@ajtowns
ajtowns force-pushed the 202508-sendtemplate branch from 86d20db to 26a1f71 Compare September 18, 2025 02:14
@ajtowns

ajtowns commented Sep 18, 2025 •

Copy link
Copy Markdown
Contributor Author

I may have overlooked it, but at first glance it looks like the draft is missing important specification on how to implement the goals set forth in the Motivation section. For instance, which peers to request templates from, when/how often, and how the template data is to be used.

I see those as implementation quality issues, which would be added in the "recommendations" section, once it's more clear what those recommendations should be.

@luke-jr

luke-jr commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

I don't see how this doesn't have major privacy leaks, similar to the mempool message

@ajtowns

ajtowns commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Could the editors please clarify which of these concerns are blockers for merging this BIP in "Draft" status?

@murchandamus

Copy link
Copy Markdown
Member

Could the editors please clarify which of these concerns are blockers for merging this BIP in "Draft" status?

I don’t perceive the stated concerns as blockers, but agree that this document should be enhanced in the future with further discussion of privacy implications. I’m gonna wait for a few days to allow time for others to comment.

@ajtowns

ajtowns commented Sep 30, 2025

Copy link
Copy Markdown
Contributor Author

that this document should be enhanced in the future with further discussion of privacy implications.

That's what the "TBA" in the otherwise empty recommendations section is for (as well as efficiency implications and potentially other things)

@ajtowns

ajtowns commented Oct 2, 2025

Copy link
Copy Markdown
Contributor Author

Could the editors please clarify which of these concerns are blockers for merging this BIP in "Draft" status?

I've been told some editors are privately blocking merge of this PR despite being unwilling to identify any issues as blockers publicly. I don't think that's appropriate, or in accordance with the BIP 2 process, so I'm instead requesting this PR be merged now as-is, publishing the BIP as a draft so it can be easily referenced for further discussion and exploration.

@murchandamus

Copy link
Copy Markdown
Member

My understanding is that some fingerprinting concerns and privacy concerns have been raised here and in the Bitcoin Core pull request where this feature is being explored. According to the BIP Process, raised concerns should be addressed in the document.
I expect that in the context of the feature being proposed, the frequency at which and the context in which it is used is seen as relevant information to weigh in on the utility, viability, and privacy impact. Therefore it would be helpful for readers and reviewers, if there were at least an initial sketch how often and when it would be used.

@ajtowns
ajtowns force-pushed the 202508-sendtemplate branch from 26a1f71 to 58ebdbf Compare October 2, 2025 05:31
@ajtowns

ajtowns commented Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

This is now published as BIN25-2 so I'll be using that repo to refine the document while it's in draft.

@murchandamus murchandamus left a comment

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.

When this is picked up again, it will need some tweaks to the preamble:

Comment thread bip-0153.md
Comment on lines +2 to +14
BIP: 153
Layer: Peer Services
Title: Sharing Block Templates with Peers
Author: Anthony Towns <[email protected]>
Comments-Summary: No comments yet.
Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0153
Status: Draft
Type: Standards Track
Created: 2025-09-05
License: BSD-3-Clause
Post-History: https://gnusha.org/pi/bitcoindev/[email protected]/T/#u
https://delvingbitcoin.org/t/sharing-block-templates/1906
Requires: 141, 152

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.

Suggested change
BIP: 153
Layer: Peer Services
Title: Sharing Block Templates with Peers
Author: Anthony Towns <[email protected]>
Comments-Summary: No comments yet.
Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0153
Status: Draft
Type: Standards Track
Created: 2025-09-05
License: BSD-3-Clause
Post-History: https://gnusha.org/pi/bitcoindev/[email protected]/T/#u
https://delvingbitcoin.org/t/sharing-block-templates/1906
Requires: 141, 152
BIP: 153
Layer: Peer Services
Title: Sharing Block Templates with Peers
Authors: Anthony Towns <[email protected]>
Status: Draft
Type: Specification
Assigned: 2025-09-05
License: BSD-3-Clause
Discussion: https://gnusha.org/pi/bitcoindev/[email protected]/T/#u
https://delvingbitcoin.org/t/sharing-block-templates/1906
Requires: 141, 152

@murchandamus murchandamus left a comment

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.

Any update on this one?

@murchandamus murchandamus added the PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author label Feb 28, 2026
@murchandamus

Copy link
Copy Markdown
Member

I’m converting this PR to a PR-Draft, as it has a merge conflict and hasn’t had an update for over six months.

@murchandamus
murchandamus marked this pull request as draft May 20, 2026 17:58
@murchandamus

Copy link
Copy Markdown
Member

Synchronizing the top of the mempool still sounds like a reasonable idea to me. I was wondering whether there was progress on exploring and describing the potential fingerprinting issues.

@ajtowns

ajtowns commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Some updated spec work is at https://github.com/ajtowns/binana/blob/202602-bin25.2-template-sharing/2025/BIN-2025-0002.md

I was wondering whether there was progress on exploring and describing the potential fingerprinting issues.

The approach I took in a previous branch was to generate separate sets of templates per network-key, with outbounds getting key "0". See https://github.com/ajtowns/bitcoin/blob/fefea23da264ba53dd2f7ff7927d51c39df7950a/src/net_processing.cpp#L5562-L5572

So if an attacker sees two inbound connections from the same peer, they'll consistently see the same templates from that peer, whether the connection is ipv4 or onion or whatever; but if the attacker makes outbound connections to the same peer over ipv4 and onion, they'll see moderately different templates at different time intervals. The templates themselves will be similar, as they're produced from the same mempool, of course.

The current branch at https://github.com/ajtowns/bitcoin/tree/202603-gettmplt doesn't implement that yet.

@murchandamus

Copy link
Copy Markdown
Member

I gather that you are planning to have the templates for each network generated at different times and this causes inbound peers to receive different templates on different networks from the same node. I don’t understand why outbound peers would use the same template across networks. It seems theoretically possible to be connected to the same node on two networks and in that case, it would be preferable if the templates were differing here, too.

@ajtowns

ajtowns commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

I gather that you are planning to have the templates for each network generated at different times and this causes inbound peers to receive different templates on different networks from the same node. I don’t understand why outbound peers would use the same template across networks. It seems theoretically possible to be connected to the same node on two networks and in that case, it would be preferable if the templates were differing here, too.

It's balancing a few constraints:

  • generating templates is costly, so you don't want to do it too often; a few times a minute not a few times a second
  • to keep bandwidth low, you want the time between templates on a particular connection to be low so that you can keep the old template around to use as a basis for the new one, on the order of a minute or two, or else the old template will likely be stale and keeping it around is wasting memory
  • a node with any inbound connections will generally have many inbound connections, and managing templates from 100 inbound peers likely doesn't hold much value, so the odds of a given outbound connection actually wanting a template is probably much lower than for an inbound connection

In addition, I think it's likely that tx-relay probably (and unavoidably) makes it easy to identify that two outbound connections are from the same peer, in that you'll never see "INV tx_a; INV tx_b" in separate messages from one and "INV tx_b; INV tx_a" in separate messages from the other (maybe weird rbf arrangements could make that happen but likely not in the short term).

Two options that could be considered:

  • bucket outbound connections by network, so that instead of n+1 templates you have 2n
  • generate the outbound templates less frequently, so that instead of 2n templates you have have 1.25n, along with some additional guidelines on how to request templates from an inbound peer

@ajtowns

ajtowns commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Two options that could be considered:

Looking into this more, I think it's more fair to say that we only send out templates over connections where we self-advertise our address, so generating templates on a per-network basis (ipv4, ipv6, tor, i2p, cjdns) and then sending those templates to both inbound and outbound peers on that network seems like it should be fine.

@ajtowns

ajtowns commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Privacy section can be read at https://github.com/ajtowns/binana/blob/202602-bin25.2-template-sharing/2025/BIN-2025-0002.md#privacy-considerations

Corresponding implementation (still draft/wip) that does implement it is at https://github.com/ajtowns/bitcoin/commits/202603-gettmplt/

I've had luck pointing an llm at the spec, the bitcoin functional test suite, and the python minisketch implementation and asking it to write a client to download a template from a node:

$ python3 ./gettmplt.py --out main/ --host cornflower.erisian.com.au --chain mainnet
connected to cornflower.erisian.com.au:8333
peer version 70017 ua=/Satoshi:31.99.0/ services=0xc08 height=966113
peer feature: 'BIN25-2.4' data=empty
got verack
requesting template (gettmplt round=0, no basis)
template 5f17cf3918d074ded1e2da07015ae99746346ad466464e5f893ef06f94f3e89e
tip      00000000000000000002338168ad448de7c921026ac61282dfb829478a7df30b
nonce    11700232880397510251
basis    0000000000000000000000000000000000000000000000000000000000000000 idx=0
shortid_mask=0x00 shortids=0 sketches=4
  sketch[0] elements=895
  sketch[1] elements=879
  sketch[2] elements=899
  sketch[3] elements=845
decoded 0 shortids from round-0 gr_vec (P=None) mask=0x00
group 0: sketch.elements=895
group 1: sketch.elements=879
group 2: sketch.elements=899
group 3: sketch.elements=845
requesting round-1 shortids for groups [0, 1, 2, 3] mask=0xf
decoded 3262 shortids from round-1 gr_vec (P=34)
group 0: sketch.elements=895 known=831 missing~=64
group 0: recovered 64 shortids via minisketch
group 1: sketch.elements=879 known=815 missing~=64
group 1: recovered 64 shortids via minisketch
group 2: sketch.elements=899 known=835 missing~=64
group 2: recovered 64 shortids via minisketch
group 3: sketch.elements=845 known=781 missing~=64
group 3: recovered 64 shortids via minisketch
full shortid set: 3518 ids
  min=21357099431 max=70348536635556
requesting 3518 txs via gettmplttxn
  received 120 txs (120/3518)
  received 47 txs (167/3518)
...
  received 148 txs (3459/3518)
  received 59 txs (3518/3518)
calculated template id 5f17cf3918d074ded1e2da07015ae99746346ad466464e5f893ef06f94f3e89e match=True
wrote 3518 txs + summary.json to main2
  [0] 23c49086993ccf9a3b7d949b9e06040981ff293b278ebe6cdfadf58f48762c7c  w=557
  [1] 80e93ad4358ac9a969710fab6c19cd94faa5fe78fced3b5ddff7df783ddbb8bd  w=376
  [2] ee93021b8ea53d4d7b69262d0c4ccaa09b95cd9d01e0329a534d7a6baa5dab46  w=438
  [3] 93ee0cc5d815bde68b61d26ec1cc9151f5c004f42b05217ab5c48681d5ef1e89  w=674
  [4] 5b1d5028ba41b293d0369411d4ba28d1aad11faf1c8a33dd71864714f9109dce  w=569
  [5] fe8e0aa4b1ea0f4a03b32ca6f49206baadee9a8be7732a38025f3773a33828ed  w=557
  [6] 1ac15da49f2625107edd8d43d43a309129191e45f2fd029ed5a8b92a869bffff  w=1340
  [7] 170a10c3902b407f481ff3e2baed685d59650ac9196fa971826e08b6b2688e89  w=833
  [8] a1997605fb60f13afc9e938e3b6620fe5d99bf09c9d2d94c8f487bb3f453347c  w=437
  [9] 90b27dc221d2112f3bacd266dd145090a3ff36fa1c1f3cc77736be6f41a524de  w=561
  ... 3508 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New BIP PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants