From 9aa5859c01bbbe0ac26e94d0d2cef5eaa44669cf Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Thu, 10 Oct 2024 16:58:45 +0100 Subject: [PATCH 1/2] tree length reflects prologue --- lib/merkle-tree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/merkle-tree.js b/lib/merkle-tree.js index 89829b2d..07f902fb 100644 --- a/lib/merkle-tree.js +++ b/lib/merkle-tree.js @@ -428,7 +428,7 @@ module.exports = class MerkleTree { this.crypto = crypto this.fork = fork this.roots = roots - this.length = roots.length ? totalSpan(roots) / 2 : 0 + this.length = roots.length ? totalSpan(roots) / 2 : prologue ? prologue.length : 0 this.byteLength = totalSize(roots) this.signature = signature this.prologue = prologue From 67c6a79565e084793bc9b3cbc7eec206078bdee4 Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Thu, 10 Oct 2024 17:24:45 +0100 Subject: [PATCH 2/2] replication factors in prologue length --- lib/merkle-tree.js | 2 +- lib/replicator.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/merkle-tree.js b/lib/merkle-tree.js index 07f902fb..89829b2d 100644 --- a/lib/merkle-tree.js +++ b/lib/merkle-tree.js @@ -428,7 +428,7 @@ module.exports = class MerkleTree { this.crypto = crypto this.fork = fork this.roots = roots - this.length = roots.length ? totalSpan(roots) / 2 : prologue ? prologue.length : 0 + this.length = roots.length ? totalSpan(roots) / 2 : 0 this.byteLength = totalSize(roots) this.signature = signature this.prologue = prologue diff --git a/lib/replicator.js b/lib/replicator.js index 510ab2da..a8f8f9ce 100644 --- a/lib/replicator.js +++ b/lib/replicator.js @@ -1189,7 +1189,7 @@ class Peer { } _requestBlock (b) { - const { length, fork } = this.core.tree + const { prologue, length, fork } = this.core.tree if (this._remoteHasBlock(b.index) === false || fork !== this.remoteFork) { this._maybeWant(b.index) @@ -1200,7 +1200,9 @@ class Peer { return false } - const req = this._makeRequest(b.index >= length, b.priority, b.index + 1) + const treeLength = (prologue && prologue.length > length) ? prologue.length : length + + const req = this._makeRequest(b.index >= treeLength, b.priority, b.index + 1) if (req === null) return false this._sendBlockRequest(req, b)