Skip to content

Commit 6ed56b5

Browse files
Merge pull request #61 from p2plabsxyz/perf/helia
perf(helia): optimize IPFS storage with LevelDB and improve upload reliability
2 parents 9310b7a + 4de79e5 commit 6ed56b5

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,14 @@
122122
]
123123
},
124124
"dependencies": {
125-
"@chainsafe/libp2p-quic": "^1.1.1",
126125
"@helia/ipns": "^8.2.3",
127126
"@helia/unixfs": "^5.0.3",
128127
"@libp2p/webtransport": "^5.0.47",
129128
"b4a": "^1.6.7",
130-
"blockstore-fs": "^2.0.2",
129+
"blockstore-level": "^2.0.3",
131130
"content-hash": "^2.5.2",
132131
"content-type": "^1.0.5",
133-
"datastore-fs": "^10.0.2",
132+
"datastore-level": "^11.0.3",
134133
"electron-find": "^1.0.7",
135134
"electron-log": "^5.3.0",
136135
"electron-updater": "^6.2.1",

src/protocols/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { app } from "electron";
2+
import { LevelBlockstore } from "blockstore-level";
3+
import { LevelDatastore } from "datastore-level";
24
import path from "path";
35
import fs from "fs-extra";
46
import crypto from "hypercore-crypto";
5-
import { FsBlockstore } from "blockstore-fs";
6-
import { FsDatastore } from "datastore-fs";
77
import { getDefaultChainList } from "web3protocol/chains";
88
import { generateKeyPair, privateKeyFromProtobuf, privateKeyToProtobuf } from "@libp2p/crypto/keys";
99

@@ -82,8 +82,8 @@ export async function ipfsOptions() {
8282
await fs.ensureDir(DATASTORE_PATH);
8383
return {
8484
repo: DEFAULT_IPFS_DIR,
85-
blockstore: new FsBlockstore(BLOCKSTORE_PATH),
86-
datastore: new FsDatastore(DATASTORE_PATH),
85+
blockstore: new LevelBlockstore(BLOCKSTORE_PATH),
86+
datastore: new LevelDatastore(DATASTORE_PATH),
8787
};
8888
}
8989

src/protocols/helia/helia.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { noise } from "@chainsafe/libp2p-noise";
66
import { yamux } from "@chainsafe/libp2p-yamux";
77
import { mdns } from "@libp2p/mdns";
88
import { tcp } from "@libp2p/tcp";
9-
import { quic } from '@chainsafe/libp2p-quic'
109
import { webRTC, webRTCDirect } from "@libp2p/webrtc";
1110
import { webSockets } from "@libp2p/websockets";
1211
import { webTransport } from '@libp2p/webtransport'
@@ -60,14 +59,11 @@ export async function createNode() {
6059
'/ip4/0.0.0.0/tcp/0/ws',
6160
'/ip4/0.0.0.0/udp/0/webrtc-direct',
6261
'/ip6/::/udp/0/webrtc-direct',
63-
'/ip4/0.0.0.0/udp/0/quic-v1',
64-
'/ip4/0.0.0.0/udp/0/quic-v1/webtransport',
6562
'/p2p-circuit'
6663
],
6764
},
6865
transports: [
6966
tcp(),
70-
quic(),
7167
webSockets(),
7268
webRTC(),
7369
webRTCDirect(),
@@ -90,7 +86,11 @@ export async function createNode() {
9086
validators: { ipns: ipnsValidator },
9187
selectors: { ipns: ipnsSelector },
9288
peerInfoMapper: removePrivateAddressesMapper,
93-
reprovide: { concurrency: 10 }
89+
reprovide: {
90+
concurrency: 10,
91+
interval: 60 * 60 * 1000,
92+
threshold: 12 * 60 * 60 * 1000
93+
}
9494
}),
9595
identify: identify(),
9696
identifyPush: identifyPush(),

src/protocols/ipfs-handler.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ export async function createHandler(ipfsOptions, session) {
137137
console.log(`Providing ${rootCid} with ${peerCount} peers connected`);
138138

139139
// Provide the root CID to the DHT in the background
140-
node.libp2p.contentRouting.provide(rootCid, {
141-
signal: AbortSignal.timeout(30000),
142-
}).then(() => {
140+
node.libp2p.contentRouting.provide(rootCid).then(() => {
143141
console.log(`Provided ${rootCid} to DHT in ${Date.now() - startTime}ms`);
144-
}).catch(err => console.log('Error providing:', err));
142+
}).catch(err => {
143+
console.log('Error providing to DHT (non-critical):', err.message);
144+
});
145145

146146
console.log("Files uploaded with root CID:", rootCid.toString());
147147
} catch (e) {
@@ -174,7 +174,7 @@ export async function createHandler(ipfsOptions, session) {
174174
const resolutionResult = await name.resolve(peerId, {
175175
signal: AbortSignal.timeout(10000),
176176
});
177-
177+
178178
let resolvedCID = resolutionResult.cid;
179179
if (!(resolvedCID instanceof CID)) {
180180
// If cid is a string, parse it

0 commit comments

Comments
 (0)