Skip to content

Commit

Permalink
fix: allow enabling sharding (#547)
Browse files Browse the repository at this point in the history
The `--enable-sharding-experiment` causes go-ipfs to explode, instead
set it as part of the config file.
  • Loading branch information
achingbrain committed Sep 17, 2020
1 parent 14ad816 commit 39842ae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"husky": "^4.2.5",
"ipfs": "^0.49.1",
"ipfs-http-client": "^46.0.1",
"ipfs-unixfs": "^2.0.3",
"lint-staged": "^10.1.6"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/ipfsd-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Daemon {
if (opts.preload && this.opts.type === 'js') {
args.push('--enable-preload', Boolean(opts.preload.enabled))
}
if (opts.EXPERIMENTAL && opts.EXPERIMENTAL.sharding) {
if (opts.EXPERIMENTAL && opts.EXPERIMENTAL.sharding && this.opts.type === 'js') {
args.push('--enable-sharding-experiment')
}
if (opts.EXPERIMENTAL && opts.EXPERIMENTAL.ipnsPubsub) {
Expand Down
39 changes: 39 additions & 0 deletions test/factory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { expect } = require('aegir/utils/chai')
const { isNode } = require('ipfs-utils/src/env')
const pathJoin = require('ipfs-utils/src/path-join')
const { createFactory } = require('../src')
const UnixFS = require('ipfs-unixfs')

const defaultOps = {
ipfsHttpModule: require('ipfs-http-client')
Expand Down Expand Up @@ -156,4 +157,42 @@ describe('`Factory spawn()` ', function () {
})
}
})

describe('should return a node with sharding enabled', () => {
for (const opts of types) {
it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => {
const factory = await createFactory()
const node = await factory.spawn({
...opts,
ipfsOptions: {
EXPERIMENTAL: {
// enable sharding for js
sharding: true
},
config: {
// enabled sharding for go
Experimental: {
ShardingEnabled: true
}
}
}
})
expect(node).to.exist()
expect(node.api).to.exist()
expect(node.api.id).to.exist()

const { cid } = await node.api.add({ path: 'derp.txt', content: 'hello' }, {
shardSplitThreshold: 0,
wrapWithDirectory: true
})

const { value: dagNode } = await node.api.dag.get(cid)
const entry = UnixFS.unmarshal(dagNode.Data)

expect(entry.type).to.equal('hamt-sharded-directory')

await node.stop()
})
}
})
})

0 comments on commit 39842ae

Please sign in to comment.