Skip to content

private broadcast: show finished transactions in getprivatebroadcastinfo - #36477

Open
vasild wants to merge 1 commit into
bitcoin:masterfrom
vasild:pb_show_concluded
Open

vasild wants to merge 1 commit into
bitcoin:masterfrom
vasild:pb_show_concluded

Conversation

@vasild

@vasild vasild commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

For finished transactions, this allows the inspection of when and to whom the transaction was sent as well as when/if it was echoed from the network.

@DrahtBot

DrahtBot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK optout21

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36607 (private broadcast: Extra guard against unintended non-private broadcast of private transactions by optout21)
  • #36429 ([RFC] Scheduled transaction broadcast, minimal by optout21)
  • #35502 (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@frankomosh frankomosh left a comment

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 guess this is a continuation of #34707. Could you share what was added or left out compared to it?

Comment thread src/private_broadcast.cpp
if (it->second.send_statuses.size() < m_max_send_attempts) return AddResult::AlreadyPresent;
auto& state{it->second};

if (!IsFinished(state)) { // We are still trying

@frankomosh frankomosh Oct 19, 2026 •

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.

A tx that used all its send attempts, but never came back from the network, can no longer be sent again. Now Add() can only restarts a tx that is resolved. But GetStale() skips such a tx, so nothing marks it resolved.

Are we getting rid of the 'retry' feature..?

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.

No, that was not intentional. Fixed. Please double check again, this has become non-trivial.

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.

Related, what happens when a previously-finished transaction is requested to be private-broadcast again?

  • Add() sees it finished, and clears received_by_us and resolved
  • It is sent out again (to 3 peers)
  • It never gets re-added to our mempool, as it already there. MarkResolved is not called again.
  • The transaction may be taken as failed
  • Final state reported in RPC: attempts_remaining 0 and no received_by_us

Is this intended this way?

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.

It never gets re-added to our mempool, as it already there. MarkResolved is not called again.

Note that MarkResolved() is called after we receive the transaction but before we try to put it in the mempool:

if (m_tx_for_private_broadcast.MarkResolved(ptx)) {

const MempoolAcceptResult result = m_chainman.ProcessTransaction(ptx);

So, it will be marked as resolved if we receive it, even if it wouldn't enter the mempool because it is already there.

But... would we receive it (a second time)? After the initial receive we would send it to all peers. So all of them know we have it. They wouldn't INV it to us anymore and even if they do we wouldn't request it (with GETDATA) because we have it in our mempool already.

So, yes, there is no reliable way to know if the second broadcast succeeded. This is the same in master right now. There may be new peers in the meantime that are unaware that we have the transaction and they will INV it to us (if it even starts propagating a second time through the network). Something to consider, separately from this PR. I do not think this PR changes the behavior.

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.

True, upon a re-request there new new relay will happen. Other nodes and this node will have the TX already in their mempool. As a result, "received_by_us" will never be set, and it will be not possible to decide/observe the success of the second broadcast.

My point was, that if the TX is already in our mempool, and for some strange reason it is relayed back to us after the re-request, our node will not request GETDATA (because TX is in the mempool), the handler will not be called, and the "receive" flags will remain empty.

The behavior on master is the same, except that the "received_by_us" flag is a new addition.

I can see these cases:

  1. Already in the mempool, and no re-relay happens (the likely case): The "received_by_us" stays empty
  2. Already in the mempool, but re-relay happens: The "received_by_us" stays empty -- AlreadyHaveTx is true, so no GETDATA is sent, no TX arrives, and the TX handler (MarkResolved) is never called.
  3. Not in the mempool and re-relay happens: "received_by_us" is set.

Case 2. could be argued about, but I think it's fine. The root of the issue is that upon re-request there will be no new relay.

One idea that we could consider though: upon a re-request don't clean the "received" flag if the TX is already in the mempool (persist that info that we have received it previously; and do perform the new sendouts).

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.

No, that was not intentional. Fixed. Please double check again, this has become non-trivial.

Looks good now.

Also noticed a good side effect: a tx that used all its attempts can now be removed when the queue is full. Before, it blocked the queue.

@vasild vasild Nov 4, 2026 •

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.

One idea that we could consider though: upon a re-request don't clean the "received" flag if the TX is already in the mempool (persist that info that we have received it previously; and do perform the new sendouts)

I like this. However there would be inconsistency between the rest of the statuses and received_by_us. For example it would look that we have sent it to nobody and we have received it. I imagine we could keep all statuses: original time added, all peers we have sent to and the received by us. Then we would replace the global m_max_send_attempts (1000) with a per-transaction one and whenever a transaction is re-added, bump its max from 1000 to 2000 and increment planned_sends with INITIAL_CONNECTION_COUNT (3) instead of resetting it to 3.

This way all the history from before and from after the re-add will be visible. Maybe an overkill?

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.

Maybe an overkill?

I tend to agree..., one cost to keep in mind: today, each tx keeps at most 1000 send records. In #35680 (comment) I measured the worst-case getprivatebroadcastinfo output at about 1.15 GiB.

With a limit that grows on every re-add, a tx that is re-sent many times would keep growing with no cap. So if we go this way, maybe we still need a cap on the history

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.

Ok, then what to do with received_by_us in the case of re-add? I tend to lean towards resetting it as it is now in this PR because not resetting it would leave it inconsistent with the other fields.

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.

After reconsidering, I'm also for keeping the current logic. My suggestion would add further complexity, and would not solve all inconsistencies. The root cause is that a submission can be repeated, but he hearing back will likely not. Resubmission is not a regular use case, but if it's done, the user has to know that the received info will only be valid since the resubmission.
So for me it's fine like this.

Comment thread src/private_broadcast.cpp Resolved
@vasild

vasild commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

bce73a17fd2754f5fad9248bdcd13b3bad0ae023...0aa81936cf2d51f55eeaca26fd036ad8d5fdc09f: rebase and address suggestions from @frankomosh and https://review.fish.foo/traces/36477-bce73a17fd2754f5fad9248bdcd13b3bad0ae023-991-2.html

PS

I guess this is a continuation of #34707. Could you share what was added or left out compared to it?

I am unsure. Better review this one as a fresh new unrelated one.

@optout21

Copy link
Copy Markdown
Contributor

Concept ACK
Keeping info about completed transaction is useful for the user.
This info may be useful for the feature implementation as well (e.g. see #36607 for a proposal how to refuse non-private broadcast of private transactions).

@optout21 optout21 left a comment

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.

Performed a review pass (0aa8193), looks good generally; left some comments.

Comment thread src/rpc/mempool.cpp Resolved
Comment thread src/rpc/mempool.cpp Resolved
Comment thread src/private_broadcast.cpp
if (it->second.send_statuses.size() < m_max_send_attempts) return AddResult::AlreadyPresent;
auto& state{it->second};

if (!IsFinished(state)) { // We are still trying

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.

Related, what happens when a previously-finished transaction is requested to be private-broadcast again?

  • Add() sees it finished, and clears received_by_us and resolved
  • It is sent out again (to 3 peers)
  • It never gets re-added to our mempool, as it already there. MarkResolved is not called again.
  • The transaction may be taken as failed
  • Final state reported in RPC: attempts_remaining 0 and no received_by_us

Is this intended this way?

@vasild
vasild force-pushed the pb_show_concluded branch from 0aa8193 to 295c961 Compare October 23, 2026 15:00
@vasild

vasild commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

0aa81936cf2d51f55eeaca26fd036ad8d5fdc09f...295c961c1f156bdbbddfa0f961751d5aa371a62b: address suggestions

@optout21 optout21 left a comment

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.

Reviewed again, left some nits. I'm happy to revisit soon!
Friendly reminder one previous question of mine has not been fully addressed yet.

Comment thread src/private_broadcast.h Resolved
Comment thread src/private_broadcast.h Resolved
Comment thread src/test/fuzz/private_broadcast.cpp Resolved
Comment thread src/private_broadcast.cpp Resolved
For finished transactions, this allows the inspection of when and to
whom the transaction was sent as well as when/if it was echoed from
the network.

Co-authored-by: Vasil Dimov <[email protected]>
@vasild
vasild force-pushed the pb_show_concluded branch from 295c961 to 95cc8ad Compare November 5, 2026 13:29
@vasild

vasild commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

295c961c1f156bdbbddfa0f961751d5aa371a62b...95cc8adddec6d686f7eeea9a8da3d851a1bbde54: rebase due to conflicts and address suggestions.

Still in discussion: #36477 (comment)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants