mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
rpc: avoid copying unbroadcast transaction IDs just to count them #36349
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36349
Loading…
Reference in a new issue
No description provided.
Delete branch "rpc-unbroadcast-count"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #35923.
getmempoolinfocurrently callsGetUnbroadcastTxs().size()to reportunbroadcastcount. The getter returns the set by value, so every call copies its entries under the mempool lock and immediately discards the copy after reading its size.Fix: Add
GetUnbroadcastTxCount()and use it in the RPC to read the size under the same lock without allocating a temporary set. This is a separate accessor because broadcast retry and persistence still need the transaction IDs returned by the existingGetUnbroadcastTxs().I also searched for similar cases nearby: the ancestor/descendant count helpers and the cluster-count path build vectors just to read their sizes, while the mining RPC uses
GetDust(...).empty()to check whether any dust outputs exist. These could potentially use count-only or boolean helpers, but would require separate changes to the graph and policy code, so I left them out of this PR.Added a temporary bench_bitcoin benchmark on my branch, comparing both getters.
Results below are medians from five runs on an Apple M5, using Apple clang 17/libc++ with
-O2:GetUnbroadcastTxs().size()(ns/query)GetUnbroadcastTxCount()(ns/query)The copy cost grew with the set size, while the count accessor stayed approximately constant.
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.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
No conflicts as of last run.
lightly tested ACK
fef74dd296This avoids copying the unbroadcast set on every
getmempoolinfocall.The other two callers use the txids after releasing the mempool lock, so avoiding their copies is less straightforward.
Given that this caused a confusion before:
The comment just rewords the method name, I don't think it's useful
Base:
66776840beb558f7e84451c2c55457f0e06242f0Head:
052cf121ab0a5373d1753564d90075f1997f4610No verified findings are available from this partial review.
Review coverage was incomplete. The adversarial_glm review did not complete.
Full review report
crACK
github.com/bitcoin/bitcoin@fef74dd296Thanks for the review @l0rinc and @davidgumberg.
Force pushed 052cf12 and improved docs as suggested by @l0rinc.
Fixed. Thanks.
Removed the comment.
lgtm ACK
052cf121abACK
052cf121abcrACK
github.com/bitcoin/bitcoin@052cf121abACK
052cf121ab