bcoin 5-MOAD scan: 1 defect (bcoin-0001 gettxoutproof O(H*T) linear scan, 48x)

This commit is contained in:
russell@unturf.com 2026-03-31 09:12:53 -04:00
parent 65389dd651
commit 2002c492a0
3 changed files with 209 additions and 0 deletions

View file

@ -0,0 +1,19 @@
--- 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.');
}