hypercore icon indicating copy to clipboard operation
hypercore copied to clipboard

Bugfix: treeHash for not-locally-available block

Open HDegroote opened this issue 11 months ago • 1 comments

Current behaviour is a low-level error, even when the required block is available from the swarm and core.length is higher:

/home/hans/holepunch/hypercore/node_modules/random-access-memory/index.js:86
      return req.callback(new Error('Could not satisfy length'), null)
                          ^

Error: Could not satisfy length
    at RAM._read (/home/hans/holepunch/hypercore/node_modules/random-access-memory/index.js:86:27)
    at Request._run (/home/hans/holepunch/hypercore/node_modules/random-access-storage/index.js:258:42)
    at RAM.run (/home/hans/holepunch/hypercore/node_modules/random-access-storage/index.js:153:14)
    at RAM.read (/home/hans/holepunch/hypercore/node_modules/random-access-storage/index.js:60:10)
    at /home/hans/holepunch/hypercore/lib/merkle-tree.js:1111:13
    at new Promise (<anonymous>)
    at getStoredNode (/home/hans/holepunch/hypercore/lib/merkle-tree.js:1110:10)
    at MerkleTree.get (/home/hans/holepunch/hypercore/lib/merkle-tree.js:470:12)
    at MerkleTree.getRoots (/home/hans/holepunch/hypercore/lib/merkle-tree.js:422:23)
    at Hypercore.treeHash (/home/hans/holepunch/hypercore/index.js:1060:40)

Note: also always running the opened-check now, because calling treeHash(...) with a specified length without awaiting ready causes a crash (this.core.tree doesn't exist yet)

HDegroote avatar Mar 18 '24 23:03 HDegroote

Converted to draft until I updated it. The clean solution is to throw a clearer error when the block is not locally available

HDegroote avatar Mar 26 '24 12:03 HDegroote