bcoin 5-MOAD scan: 1 defect (bcoin-0001 gettxoutproof O(H*T) linear scan, 48x)
This commit is contained in:
parent
65389dd651
commit
2002c492a0
3 changed files with 209 additions and 0 deletions
|
|
@ -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.');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue