Skip to content

Commit

Permalink
feat: add persistent datastore (#162)
Browse files Browse the repository at this point in the history
To make DHT lookups faster, add a persistent datastore so we can
repopulate the routing tables on startup from previous runs.
  • Loading branch information
achingbrain authored Sep 30, 2024
1 parent ffb9cb3 commit fd90738
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ RUN npm ci --quiet

ENV NODE_ENV production

COPY . ./
COPY src ./src
COPY tsconfig.json ./
RUN npm run build
RUN npm prune --omit=dev

Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
volumes:
prometheus_data: {}
grafana_data: {}
bootstrapper_datastore: {}

services:
bootstrapper:
Expand All @@ -20,7 +21,8 @@ services:
- NODE_OPTIONS="--inspect=0.0.0.0"
volumes:
- ./config.json:/config.json
command: node --config /config.json --enable-kademlia --enable-autonat --api-host=0.0.0.0
- bootstrapper_datastore:/datastore
command: node --config /config.json --enable-kademlia --enable-autonat --api-host=0.0.0.0 --datastore=/datastore

prometheus:
restart: unless-stopped
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ const options = {
default: '127.0.0.1',
type: 'string'
},
datastore: {
description: 'The path to the libp2p datastore directory',
default: 'datastore',
type: 'string'
},
help: {
description: 'Show help text',
type: 'boolean'
Expand All @@ -102,6 +107,7 @@ const {
'metrics-port': argMetricsPort,
'api-port': argApiPort,
'api-host': argApiHost,
datastore: argDatastore,
help: argHelp
} = args.values

Expand Down Expand Up @@ -154,7 +160,7 @@ if (argEnableAutonat === true) {
}

const node = await createLibp2p({
datastore: new LevelDatastore('js-libp2p-datastore'),
datastore: new LevelDatastore(argDatastore ?? options.datastore.default),
privateKey,
addresses: {
announceFilter: (addrs) => {
Expand Down

0 comments on commit fd90738

Please sign in to comment.