autobee 2.9.0 → 2.9.2

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/index.js CHANGED
@@ -1039,7 +1039,7 @@ module.exports = class Autobee extends ReadyResource {
1039
1039
 
1040
1040
  const anchor = { key: core.key, length: core.length }
1041
1041
 
1042
- this.emit('anchor', anchor, core)
1042
+ this.emit('anchor', anchor, { key, length })
1043
1043
 
1044
1044
  await core.close()
1045
1045
 
@@ -1172,8 +1172,8 @@ module.exports = class Autobee extends ReadyResource {
1172
1172
  if (!this.writers.writable) return false
1173
1173
 
1174
1174
  if (this.writers.localWriter.pending !== null) return false
1175
-
1176
1175
  if ((await this._flushesBehind()) < this._ackThreshold) return false
1176
+ if (await this._allHeadsTrusted()) return false
1177
1177
 
1178
1178
  const links = this.system.getLinks(this.local.key)
1179
1179
  const t = Math.max(this._now(), this.system.timestamp)
@@ -1182,6 +1182,22 @@ module.exports = class Autobee extends ReadyResource {
1182
1182
  return true
1183
1183
  }
1184
1184
 
1185
+ async _allHeadsTrusted() {
1186
+ const heads = this.system.heads.slice()
1187
+ if (!heads.length) return false
1188
+
1189
+ const promises = []
1190
+ for (const head of heads) {
1191
+ promises.push(this.trusted.isTrusted(head.key, this._workingView.view))
1192
+ }
1193
+
1194
+ for (const isTrusted of await Promise.all(promises)) {
1195
+ if (!isTrusted) return false
1196
+ }
1197
+
1198
+ return true
1199
+ }
1200
+
1185
1201
  async _flushesBehind() {
1186
1202
  if (this._ackFlushes === -1) {
1187
1203
  const latest = await this.writers.getLatestLocalOplog()
package/lib/encoding.js CHANGED
@@ -13,6 +13,8 @@ const SystemWriter = getEncoding('@autobee/system-writer')
13
13
  const ManifestData = getEncoding('@autobee/manifest-data')
14
14
  const AutobaseBootRecord = getEncoding('@autobase-compat/boot-record')
15
15
 
16
+ const LEGACY_TIME = 1789460100000
17
+
16
18
  exports.OPLOG_VERSION = OPLOG_VERSION
17
19
 
18
20
  exports.Oplog = Oplog
@@ -155,7 +157,7 @@ function decodeOplog(buf) {
155
157
  if (m.version <= LEGACY_OPLOG_VERSION) {
156
158
  return {
157
159
  version: m.version,
158
- timestamp: 0,
160
+ timestamp: LEGACY_TIME,
159
161
  links: m.node.heads,
160
162
  batch: { start: 0, end: m.node.batch - 1 },
161
163
  views: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autobee",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
4
4
  "description": "Bee based autobase",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc.",