hypercore-storage 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tx.js CHANGED
@@ -35,6 +35,10 @@ class CoreTX {
35
35
  this.changes.push([core.head(this.core.dataPointer), encode(CORE_HEAD, head), null])
36
36
  }
37
37
 
38
+ deleteHead () {
39
+ this.changes.push([core.head(this.core.dataPointer), null, null])
40
+ }
41
+
38
42
  setDependency (dep) {
39
43
  this.changes.push([core.dependency(this.core.dataPointer), encode(CORE_DEPENDENCY, dep), null])
40
44
  }
@@ -373,7 +373,27 @@ async function core (core, { version, dryRun = true, gc = true }) {
373
373
  }
374
374
 
375
375
  const oplog = await readOplog(files.oplog)
376
- if (!oplog) throw new Error('No oplog available for ' + files.oplog + ', length = ' + (head ? head.length : 0) + ', writable = ' + (!!auth.keyPair))
376
+ if (!oplog) {
377
+ const writable = !!auth.keyPair
378
+
379
+ if (writable) {
380
+ throw new Error('No oplog available writable core for ' + files.oplog + ', length = ' + (head ? head.length : 0))
381
+ }
382
+
383
+ // if not writable, just nuke it to recover, some bad state happened here, prop corruption from earlier versions
384
+ const w = core.write()
385
+
386
+ w.deleteBlockRange(0, -1)
387
+ w.deleteTreeNodeRange(0, -1)
388
+ w.deleteBitfieldPageRange(0, -1)
389
+ w.deleteHead()
390
+
391
+ await w.flush()
392
+
393
+ await commitCoreMigration(auth, core, version)
394
+ if (gc) await runGC()
395
+ return // no data
396
+ }
377
397
 
378
398
  const treeData = new TreeSlicer()
379
399
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",
@@ -252,19 +252,21 @@ const encoding9_6 = c.array(c.fixed32)
252
252
  const encoding9 = {
253
253
  preencode (state, m) {
254
254
  c.uint.preencode(state, m.version)
255
- state.end++ // max flag is 4 so always one byte
255
+ state.end++ // max flag is 8 so always one byte
256
256
  encoding4.preencode(state, m.hash)
257
257
  c.uint.preencode(state, m.quorum)
258
258
  encoding9_4.preencode(state, m.signers)
259
259
 
260
260
  if (m.prologue) encoding8.preencode(state, m.prologue)
261
261
  if (m.linked) encoding9_6.preencode(state, m.linked)
262
+ if (m.userData) c.buffer.preencode(state, m.userData)
262
263
  },
263
264
  encode (state, m) {
264
265
  const flags =
265
266
  (m.allowPatch ? 1 : 0) |
266
267
  (m.prologue ? 2 : 0) |
267
- (m.linked ? 4 : 0)
268
+ (m.linked ? 4 : 0) |
269
+ (m.userData ? 8 : 0)
268
270
 
269
271
  c.uint.encode(state, m.version)
270
272
  c.uint.encode(state, flags)
@@ -274,6 +276,7 @@ const encoding9 = {
274
276
 
275
277
  if (m.prologue) encoding8.encode(state, m.prologue)
276
278
  if (m.linked) encoding9_6.encode(state, m.linked)
279
+ if (m.userData) c.buffer.encode(state, m.userData)
277
280
  },
278
281
  decode (state) {
279
282
  const r0 = c.uint.decode(state)
@@ -286,7 +289,8 @@ const encoding9 = {
286
289
  allowPatch: (flags & 1) !== 0,
287
290
  signers: encoding9_4.decode(state),
288
291
  prologue: (flags & 2) !== 0 ? encoding8.decode(state) : null,
289
- linked: (flags & 4) !== 0 ? encoding9_6.decode(state) : null
292
+ linked: (flags & 4) !== 0 ? encoding9_6.decode(state) : null,
293
+ userData: (flags & 8) !== 0 ? c.buffer.decode(state) : null
290
294
  }
291
295
  }
292
296
  }