java-topology/defects/bcoin/patch/bcoin-0001-rpc-gettxoutproof-linear-scan.patch

20 lines
673 B
Diff

# UNDF: UNDF-2026-000000917
--- a/lib/node/rpc.js
+++ b/lib/node/rpc.js
@@ -1032,8 +1032,14 @@ class RPC extends RPCBase {
if (!block)
throw new RPCError(errs.MISC_ERROR, 'Block not found.');
- for (const hash of hashes) {
- if (!block.hasTX(hash)) {
+ // Build a hash set for O(1) membership checks instead of
+ // calling block.hasTX() which does O(T) linear scan per call.
+ const txSet = new BufferSet();
+ for (const tx of block.txs)
+ txSet.add(tx.hash());
+
+ for (const hash of hashes) {
+ if (!txSet.has(hash)) {
throw new RPCError(errs.VERIFY_ERROR,
'Block does not contain all txids.');
}