Skip to content

Commit

Permalink
all batch sigs are unslabbed always and unslab root hash
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Jul 26, 2024
1 parent eba20ef commit b45bfec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const hypercoreCrypto = require('hypercore-crypto')
const b4a = require('b4a')
const unslab = require('unslab')
const Oplog = require('./oplog')
const BigHeader = require('./big-header')
const Mutex = require('./mutex')
Expand Down Expand Up @@ -184,7 +185,7 @@ module.exports = class Core {
if (e.treeUpgrade) {
const batch = await tree.truncate(e.treeUpgrade.length, e.treeUpgrade.fork)
batch.ancestors = e.treeUpgrade.ancestors
batch.signature = e.treeUpgrade.signature
batch.signature = e.treeUpgrade.signature === null ? null : unslab(e.treeUpgrade.signature)
addReorgHint(header.hints.reorgs, tree, batch)
batch.commit()

Expand Down
10 changes: 5 additions & 5 deletions lib/merkle-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class MerkleTreeBatch {
}

hash () {
if (this.hashCached === null) this.hashCached = this.tree.crypto.tree(this.roots)
if (this.hashCached === null) this.hashCached = unslab(this.tree.crypto.tree(this.roots))
return this.hashCached
}

Expand Down Expand Up @@ -260,7 +260,7 @@ class MerkleTreeBatch {
this.tree.length = this.length
this.tree.byteLength = this.byteLength
this.tree.fork = this.fork
this.tree.signature = this.signature !== null ? unslab(this.signature) : null
this.tree.signature = this.signature
}

seek (bytes, padding) {
Expand Down Expand Up @@ -430,7 +430,7 @@ module.exports = class MerkleTree {
this.roots = roots
this.length = roots.length ? totalSpan(roots) / 2 : 0
this.byteLength = totalSize(roots)
this.signature = signature !== null ? unslab(signature) : null
this.signature = signature
this.prologue = prologue

this.storage = storage
Expand Down Expand Up @@ -471,7 +471,7 @@ module.exports = class MerkleTree {
}

hash () {
return this.crypto.tree(this.roots)
return unslab(this.crypto.tree(this.roots))
}

signable (namespace) {
Expand Down Expand Up @@ -982,7 +982,7 @@ function verifyUpgrade ({ fork, upgrade }, blockRoot, batch) {
ite.sibling()
}

batch.signature = upgrade.signature
batch.signature = upgrade.signature !== null ? unslab(upgrade.signature) : null
batch.fork = fork

return q.extra === null
Expand Down
2 changes: 1 addition & 1 deletion lib/verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function defaultQuorum (man) {
}

function generateUpgrade (patch, start, length) {
const upgrade = { start, length, nodes: null, additionalNodes: [] }
const upgrade = { start, length, nodes: null, additionalNodes: [], signature: null }

const from = start * 2
const to = from + length * 2
Expand Down

0 comments on commit b45bfec

Please sign in to comment.