Skip to content

Commit 39842ae

Browse files
authored
fix: allow enabling sharding (#547)
The `--enable-sharding-experiment` causes go-ipfs to explode, instead set it as part of the config file.
1 parent 14ad816 commit 39842ae

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"husky": "^4.2.5",
7070
"ipfs": "^0.49.1",
7171
"ipfs-http-client": "^46.0.1",
72+
"ipfs-unixfs": "^2.0.3",
7273
"lint-staged": "^10.1.6"
7374
},
7475
"peerDependencies": {

src/ipfsd-daemon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class Daemon {
170170
if (opts.preload && this.opts.type === 'js') {
171171
args.push('--enable-preload', Boolean(opts.preload.enabled))
172172
}
173-
if (opts.EXPERIMENTAL && opts.EXPERIMENTAL.sharding) {
173+
if (opts.EXPERIMENTAL && opts.EXPERIMENTAL.sharding && this.opts.type === 'js') {
174174
args.push('--enable-sharding-experiment')
175175
}
176176
if (opts.EXPERIMENTAL && opts.EXPERIMENTAL.ipnsPubsub) {

test/factory.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { expect } = require('aegir/utils/chai')
55
const { isNode } = require('ipfs-utils/src/env')
66
const pathJoin = require('ipfs-utils/src/path-join')
77
const { createFactory } = require('../src')
8+
const UnixFS = require('ipfs-unixfs')
89

910
const defaultOps = {
1011
ipfsHttpModule: require('ipfs-http-client')
@@ -156,4 +157,42 @@ describe('`Factory spawn()` ', function () {
156157
})
157158
}
158159
})
160+
161+
describe('should return a node with sharding enabled', () => {
162+
for (const opts of types) {
163+
it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => {
164+
const factory = await createFactory()
165+
const node = await factory.spawn({
166+
...opts,
167+
ipfsOptions: {
168+
EXPERIMENTAL: {
169+
// enable sharding for js
170+
sharding: true
171+
},
172+
config: {
173+
// enabled sharding for go
174+
Experimental: {
175+
ShardingEnabled: true
176+
}
177+
}
178+
}
179+
})
180+
expect(node).to.exist()
181+
expect(node.api).to.exist()
182+
expect(node.api.id).to.exist()
183+
184+
const { cid } = await node.api.add({ path: 'derp.txt', content: 'hello' }, {
185+
shardSplitThreshold: 0,
186+
wrapWithDirectory: true
187+
})
188+
189+
const { value: dagNode } = await node.api.dag.get(cid)
190+
const entry = UnixFS.unmarshal(dagNode.Data)
191+
192+
expect(entry.type).to.equal('hamt-sharded-directory')
193+
194+
await node.stop()
195+
})
196+
}
197+
})
159198
})

0 commit comments

Comments
 (0)