Skip to content

Commit

Permalink
fix uncommitable batches being half written to the tx
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Feb 7, 2025
1 parent 3492ba2 commit 35a51ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ module.exports = class Core {

if (this.preupdate !== null) await this.preupdate(batch, this.header.key)

await this.state._verifyBlock(batch, bitfield, value, this.header.manifest ? null : manifest)
if (!(await this.state._verifyBlock(batch, bitfield, value, this.header.manifest ? null : manifest))) {
return false
}

if (!batch.upgraded && bitfield) {
this.replicator.onhave(bitfield.start, bitfield.length, bitfield.drop)
Expand Down
8 changes: 5 additions & 3 deletions lib/session-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ module.exports = class SessionState {
await this.mutex.lock()

try {
if (!batch.commitable()) return false
const tx = this.createWriteBatch()
this.updating = true

Expand All @@ -307,9 +308,8 @@ module.exports = class SessionState {

if (manifest) this.core._setManifest(tx, manifest, null)

if (batch.commitable()) {
batch.commit(tx)
}
assert(batch.commitable(), 'Should still be commitable')
batch.commit(tx)

const head = {
fork: batch.fork,
Expand All @@ -335,6 +335,8 @@ module.exports = class SessionState {
this.updating = false
this.mutex.unlock()
}

return true
}

async truncate (length, fork, { signature, keyPair } = {}) {
Expand Down

0 comments on commit 35a51ae

Please sign in to comment.