| … | … | @@ -1,4 +1,5 @@ |
| 1 | 1 | node_modules/ |
| 2 | package-lock.json | |
| 2 | 3 | *.log |
| 3 | 4 | .DS_Store |
| 4 | 5 | # local test/dev storage |
| … | … | @@ -16,7 +16,10 @@ async function demo () { |
| 16 | 16 | const codeHash = 'square-v1' |
| 17 | 17 | const executors = { [codeHash]: async (i) => i.n * i.n } |
| 18 | 18 | |
| 19 | const node = await ComputeNode.create(undefined, null, { executors }) | |
| 19 | // corestore 7 / hypercore 11 is RocksDB-backed (no in-memory backend) — | |
| 20 | // the demo uses a throwaway temp dir. | |
| 21 | const storage = '/tmp/hypercompute-demo-' + Date.now() | |
| 22 | const node = await ComputeNode.create(storage, null, { executors }) | |
| 20 | 23 | await node.grantSelf('owner') |
| 21 | 24 | |
| 22 | 25 | const input = { n: 7 } |
| … | … | @@ -7,7 +7,6 @@ |
| 7 | 7 | // via replicateAndSync (no network). |
| 8 | 8 | |
| 9 | 9 | const Corestore = require('corestore') |
| 10 | const ram = require('random-access-memory') | |
| 11 | 10 | const b4a = require('b4a') |
| 12 | 11 | const crypto = require('hypercore-crypto') |
| 13 | 12 | const { openPool, taskId, resultKey } = require('./pool') |
| … | … | @@ -20,12 +19,11 @@ class ComputeNode { |
| 20 | 19 | this.base = openPool(store, bootstrap) |
| 21 | 20 | } |
| 22 | 21 | |
| 23 | // storage: a Corestore, a path string, or undefined (=> in-memory) | |
| 22 | // storage: a Corestore instance, or a path string (corestore 7 / hypercore 11 | |
| 23 | // is RocksDB-backed via hypercore-storage — there is no random-access-memory | |
| 24 | // backend in this era; tests/demos pass a temp dir). | |
| 24 | 25 | static async create (storage, bootstrap = null, opts = {}) { |
| 25 | let store = storage | |
| 26 | if (!(storage instanceof Corestore)) { | |
| 27 | store = new Corestore(storage || ram) | |
| 28 | } | |
| 26 | const store = storage instanceof Corestore ? storage : new Corestore(storage) | |
| 29 | 27 | const node = new ComputeNode(store, bootstrap, opts) |
| 30 | 28 | await node.base.ready() |
| 31 | 29 | return node |
| … | … | @@ -9,14 +9,14 @@ |
| 9 | 9 | "dependencies": { |
| 10 | 10 | "autobase": "^7.28.1", |
| 11 | 11 | "b4a": "^1.6.7", |
| 12 | "corestore": "^6.18.4", | |
| 12 | "corestore": "^7.10.1", | |
| 13 | 13 | "hyperbee": "^2.27.3", |
| 14 | "hypercore-crypto": "^3.6.1", | |
| 15 | "random-access-memory": "^6.2.1" | |
| 14 | "hypercore-crypto": "^3.6.1" | |
| 16 | 15 | }, |
| 17 | 16 | "devDependencies": { |
| 18 | "autobase-test-helpers": "^2.2.0", | |
| 19 | "brittle": "^3.7.0" | |
| 17 | "autobase-test-helpers": "^3.1.0", | |
| 18 | "brittle": "^3.7.0", | |
| 19 | "test-tmp": "^1.4.0" | |
| 20 | 20 | }, |
| 21 | 21 | "license": "MIT" |
| 22 | 22 | } |
| … | … | @@ -7,7 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | const test = require('brittle') |
| 9 | 9 | const Corestore = require('corestore') |
| 10 | const ram = require('random-access-memory') | |
| 10 | const tmp = require('test-tmp') | |
| 11 | 11 | const { replicateAndSync } = require('autobase-test-helpers') |
| 12 | 12 | const b4a = require('b4a') |
| 13 | 13 | const crypto = require('hypercore-crypto') |
| … | … | @@ -24,10 +24,10 @@ test('P0: submit -> execute -> result converges + memoizes', async (t) => { |
| 24 | 24 | const square = async (input) => input.n * input.n |
| 25 | 25 | const executors = { [codeHash]: square } |
| 26 | 26 | |
| 27 | const owner = await ComputeNode.create(new Corestore(ram), null, { executors }) | |
| 27 | const owner = await ComputeNode.create(new Corestore(await tmp(t)), null, { executors }) | |
| 28 | 28 | await owner.grantSelf('owner') |
| 29 | 29 | |
| 30 | const worker = await ComputeNode.create(new Corestore(ram), owner.key, { executors }) | |
| 30 | const worker = await ComputeNode.create(new Corestore(await tmp(t)), owner.key, { executors }) | |
| 31 | 31 | |
| 32 | 32 | // P0 membership: owner adds the worker as an autobase writer + grants it. |
| 33 | 33 | await owner.addWriter(worker.writerKey) |
| … | … | @@ -66,7 +66,7 @@ test('P0: a different input is a separate content-addressed chunk', async (t) => |
| 66 | 66 | const codeHash = 'square-v1' |
| 67 | 67 | const executors = { [codeHash]: async (i) => i.n * i.n } |
| 68 | 68 | |
| 69 | const owner = await ComputeNode.create(new Corestore(ram), null, { executors }) | |
| 69 | const owner = await ComputeNode.create(new Corestore(await tmp(t)), null, { executors }) | |
| 70 | 70 | await owner.grantSelf('owner') |
| 71 | 71 | |
| 72 | 72 | const ih = inputHashOf({ n: 9 }) |