Skip to content

Commit

Permalink
Merge branch 'main' into rocksdb
Browse files Browse the repository at this point in the history
  • Loading branch information
chm-diederichs committed Dec 13, 2024
2 parents 0b01593 + 775699f commit 2e27d3b
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ on:
pull_request:
branches:
- main
env:
BRITTLE_TIMEOUT: 60000

jobs:
test:
if: ${{ !startsWith(github.ref, 'refs/tags/')}} # Already runs for the push of the commit, no need to run again for the tag
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/manual.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:
required: true
type: string

env:
BRITTLE_TIMEOUT: 60000
jobs:
deploy:
runs-on: ${{ matrix.os }}
Expand Down
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const ActiveWriters = require('./lib/active-writers')
const CorePool = require('./lib/core-pool')
const AutoWakeup = require('./lib/wakeup')

const WakeupExtension = require('./lib/extension')

const inspect = Symbol.for('nodejs.util.inspect.custom')
const INTERRUPT = new Error('Apply interrupted')

Expand Down Expand Up @@ -50,6 +52,7 @@ module.exports = class Autobase extends ReadyResource {
this.store = store
this.globalCache = store.globalCache || null
this.encrypted = handlers.encrypted || !!handlers.encryptionKey
this.encrypt = !!handlers.encrypt
this.encryptionKey = handlers.encryptionKey || null

this._tryLoadingLocal = true
Expand All @@ -66,6 +69,7 @@ module.exports = class Autobase extends ReadyResource {
this.corePool = new CorePool()
this.linearizer = null
this.updating = false
this.wakeupExtension = null

this.fastForwardEnabled = handlers.fastForward !== false
this.fastForwarding = 0
Expand Down Expand Up @@ -267,6 +271,10 @@ module.exports = class Autobase extends ReadyResource {
await this.local.setUserData('autobase/encryption', this.encryptionKey)
} else {
this.encryptionKey = await this.local.getUserData('autobase/encryption')
if (this.encrypt && this.encryptionKey === null) {
this.encryptionKey = (await this.store.createKeyPair('autobase/encryption')).secretKey.subarray(0, 32)
await this.local.setUserData('autobase/encryption', this.encryptionKey)
}
if (this.encryptionKey) {
await this.local.setEncryptionKey(this.encryptionKey)
// not needed but, just for good meassure
Expand All @@ -282,16 +290,19 @@ module.exports = class Autobase extends ReadyResource {
const ref = await this.local.getUserData('referrer')
if (ref && !b4a.equals(ref, this.local.key) && !this._primaryBootstrap) {
this._primaryBootstrap = this.store.get({ key: ref, compat: false, active: false, encryptionKey: this.encryptionKey })
this.store = this.store.namespace(this._primaryBootstrap, { detach: false })
}

await this.local.setUserData('referrer', this.key)

if (this._primaryBootstrap) {
await this._primaryBootstrap.ready()
this._primaryBootstrap.setUserData('autobase/local', this.local.key)
this.wakeupExtension = new WakeupExtension(this, this._primaryBootstrap, true)
if (this.encryptionKey) await this._primaryBootstrap.setUserData('autobase/encryption', this.encryptionKey)
} else {
this.local.setUserData('autobase/local', this.local.key)
this.wakeupExtension = new WakeupExtension(this, this.local, true)
}

const { bootstrap, system, views } = await this._loadSystemInfo()
Expand Down
9 changes: 1 addition & 8 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const Hypercore = require('hypercore')
const crypto = require('hypercore-crypto')
const assert = require('nanoassert')
const b4a = require('b4a')
const WakeupExtension = require('./extension')
const Signer = require('./signer')
const { ViewRecord } = require('./messages')

Expand Down Expand Up @@ -72,15 +71,9 @@ module.exports = class Autocore extends ReadyResource {
}

_registerSystemCore () {
this.base.wakeupExtension = this._registerWakeupExtension()
this._registerFastForwardListener()
}

_registerWakeupExtension () {
if (this.wakeupExtension && this.wakeupExtension.core === this.originalCore) return // no need to reset
return new WakeupExtension(this.base, this.originalCore)
}

_registerFastForwardListener () {
this.originalCore.removeListener('append', this._queueFastForward)
this.originalCore.on('append', this._queueFastForward)
Expand Down Expand Up @@ -212,7 +205,7 @@ module.exports = class Autocore extends ReadyResource {
await core.setUserData('referrer', this.base.key)

const buf = await core.getUserData('autobase/view')
const record = (buf !== null && buf[0] === 0) ? c.decode(ViewRecord, buf) : { name: null, migrated: null, audits: 0 }
const record = (buf !== null && buf[0] === 0) ? c.decode(ViewRecord, buf) : { name: null, migrated: null, audits: 1 }

// if (record.audits === 0) {
// // old core, audit it real quick
Expand Down
8 changes: 5 additions & 3 deletions lib/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Wakeup } = require('./messages')
const VERSION = 1

module.exports = class WakeupExtension {
constructor (base, core) {
constructor (base, core, passive) {
this.base = base
this.core = core

Expand All @@ -19,8 +19,10 @@ module.exports = class WakeupExtension {
this.extension.send(req, peer)
})

for (const peer of this.core.peers) {
this.extension.send(req, peer)
if (!passive) {
for (const peer of this.core.peers) {
this.extension.send(req, peer)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "autobase",
"version": "6.5.9",
"version": "6.5.13",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion test/autoack.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ test('autoack - simple', async t => {
t.is(binfo.views[0].length, 1)
})

test('autoack - 5 writers', async t => {
// TODO: unflake this test (skipping to avoid false positives on canary)
test.skip('autoack - 5 writers', async t => {
t.plan(21)

const ackInterval = 50
Expand Down
5 changes: 4 additions & 1 deletion test/fast-forward.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ test('fast-forward - fast forward after migrate', async t => {
t.comment('percentage: ' + (sparse / core.length * 100).toFixed(2) + '%')
})

test('fast-forward - multiple writers added', async t => {
// TODO: re-enable this test when rocks is in.
// Skipping because it is flaky: around 10% of the time it hangs forever
// (So make sure to verify that it no longer flakes when re-enabling)
test.skip('fast-forward - multiple writers added', async t => {
t.plan(2)

const MESSAGES_PER_ROUND = 40
Expand Down
2 changes: 1 addition & 1 deletion test/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ async function applyv0 (batch, view, base) {
continue
}

await view.version.append(value.version)
await view.version.append(value.version || 0)

if (value.version > 0) {
throw new Error('Upgrade required')
Expand Down

0 comments on commit 2e27d3b

Please sign in to comment.