From a2b827eef1d03cbe0f90051174bdc4bb53c36056 Mon Sep 17 00:00:00 2001 From: Mohammad Kermani Date: Thu, 12 Sep 2024 19:11:44 +0330 Subject: [PATCH] feat(rosenet-node): enable DCUtR service --- .changeset/modern-donuts-rest.md | 6 ++++ package-lock.json | 36 +++++++++++++++---- .../rosenet-node/lib/createRoseNetNode.ts | 2 ++ packages/rosenet-node/package.json | 1 + packages/rosenet-relay/lib/constants.ts | 2 ++ .../rosenet-relay/lib/createRoseNetRelay.ts | 15 +++++--- 6 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 .changeset/modern-donuts-rest.md diff --git a/.changeset/modern-donuts-rest.md b/.changeset/modern-donuts-rest.md new file mode 100644 index 0000000..668195a --- /dev/null +++ b/.changeset/modern-donuts-rest.md @@ -0,0 +1,6 @@ +--- +'@rosen-bridge/rosenet-relay': minor +'@rosen-bridge/rosenet-node': minor +--- + +Enable DCUtR service diff --git a/package-lock.json b/package-lock.json index 6909ebe..1640386 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5193,14 +5193,19 @@ "license": "ISC" }, "node_modules/interface-datastore": { - "version": "8.2.11", - "resolved": "https://registry.npmjs.org/interface-datastore/-/interface-datastore-8.2.11.tgz", - "integrity": "sha512-9E0iXehfp/j0UbZ2mvlYB4K9pP7uQBCppfuy8WHs1EHF6wLQrM9+zwyX+8Qt6HnH4GKZRyXX/CNXm6oD4+QYgA==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/interface-datastore/-/interface-datastore-8.3.0.tgz", + "integrity": "sha512-RM/rTSmRcnoCwGZIHrPm+nlGYVoT4R0lcFvNnDyhdFT4R6BuHHhfFP47UldVEjs98SfxLuMhaNMsyjI918saHw==", "dependencies": { - "interface-store": "^5.0.0", + "interface-store": "6.0.0", "uint8arrays": "^5.0.2" } }, + "node_modules/interface-datastore/node_modules/interface-store": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/interface-store/-/interface-store-6.0.0.tgz", + "integrity": "sha512-HkjsDPsjA7SKkCr+TH1elUQApAAM3X3JPwrz3vFzaf614wI+ZD6GVvwKGZCHYcbSRqeZP/uzVPqezzeISeo5kA==" + }, "node_modules/interface-store": { "version": "5.1.7", "resolved": "https://registry.npmjs.org/interface-store/-/interface-store-5.1.7.tgz", @@ -6568,9 +6573,9 @@ "license": "MIT" }, "node_modules/multiformats": { - "version": "13.1.0", - "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-13.1.0.tgz", - "integrity": "sha512-HzdtdBwxsIkzpeXzhQ5mAhhuxcHbjEHH+JQoxt7hG/2HGFjjwyolLo7hbaexcnhoEuV4e0TNJ8kkpMjiEYY4VQ==" + "version": "13.2.2", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-13.2.2.tgz", + "integrity": "sha512-RWI+nyf0q64vyOxL8LbKtjJMki0sogRL/8axvklNtiTM0iFCVtHwME9w6+0P1/v4dQvsIg8A45oT3ka1t/M/+A==" }, "node_modules/murmurhash3js-revisited": { "version": "3.0.0", @@ -9395,6 +9400,7 @@ "@chainsafe/libp2p-yamux": "^6.0.2", "@libp2p/bootstrap": "^10.1.5", "@libp2p/circuit-relay-v2": "^1.1.5", + "@libp2p/dcutr": "^1.1.5", "@libp2p/identify": "^2.1.5", "@libp2p/interface": "^1.7.0", "@libp2p/interface-internal": "^1.3.4", @@ -9484,6 +9490,22 @@ "npm": ">=7.0.0" } }, + "packages/rosenet-node/node_modules/@libp2p/dcutr": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@libp2p/dcutr/-/dcutr-1.1.5.tgz", + "integrity": "sha512-1zDhZxLxrl+yqIAG9KzyLu3gzyvOT7UYTislw4EwhcMGMviot/pgR87SSVqbT+HDpAoj1sM/3F5VUT/sCDa9WA==", + "dependencies": { + "@libp2p/interface": "^1.7.0", + "@libp2p/interface-internal": "^1.3.4", + "@libp2p/utils": "^5.4.9", + "@multiformats/multiaddr": "^12.2.3", + "@multiformats/multiaddr-matcher": "^1.2.1", + "delay": "^6.0.0", + "it-protobuf-stream": "^1.1.3", + "protons-runtime": "^5.4.0", + "uint8arraylist": "^2.4.8" + } + }, "packages/rosenet-node/node_modules/@libp2p/peer-id-factory": { "version": "4.2.4", "resolved": "https://registry.npmjs.org/@libp2p/peer-id-factory/-/peer-id-factory-4.2.4.tgz", diff --git a/packages/rosenet-node/lib/createRoseNetNode.ts b/packages/rosenet-node/lib/createRoseNetNode.ts index 25dd763..00f15c2 100644 --- a/packages/rosenet-node/lib/createRoseNetNode.ts +++ b/packages/rosenet-node/lib/createRoseNetNode.ts @@ -3,6 +3,7 @@ import { noise } from '@chainsafe/libp2p-noise'; import { yamux } from '@chainsafe/libp2p-yamux'; import { bootstrap } from '@libp2p/bootstrap'; import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'; +import { dcutr } from '@libp2p/dcutr'; import { identify } from '@libp2p/identify'; import { PeerId } from '@libp2p/interface'; import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'; @@ -129,6 +130,7 @@ const createRoseNetNode = async ({ */ maxInboundDataLength: 170_000_000, // 170MB }), + dcutr: dcutr(), restartRelayDiscovery, }, logger: libp2pLoggerFactory(logger, config.debug?.libp2pComponents ?? []), diff --git a/packages/rosenet-node/package.json b/packages/rosenet-node/package.json index bb3ab66..673b585 100644 --- a/packages/rosenet-node/package.json +++ b/packages/rosenet-node/package.json @@ -40,6 +40,7 @@ "@chainsafe/libp2p-yamux": "^6.0.2", "@libp2p/bootstrap": "^10.1.5", "@libp2p/circuit-relay-v2": "^1.1.5", + "@libp2p/dcutr": "^1.1.5", "@libp2p/identify": "^2.1.5", "@libp2p/interface": "^1.7.0", "@libp2p/interface-internal": "^1.3.4", diff --git a/packages/rosenet-relay/lib/constants.ts b/packages/rosenet-relay/lib/constants.ts index cfa8dcd..de726d3 100644 --- a/packages/rosenet-relay/lib/constants.ts +++ b/packages/rosenet-relay/lib/constants.ts @@ -1 +1,3 @@ export const DEFAULT_LISTEN_HOST = '0.0.0.0'; +export const RESERVATION_DATA_LIMIT = 1_000_000_000n; // 1GB +export const RESERVATION_DURATION_LIMIT = 60 * 60_000; // 1 hour diff --git a/packages/rosenet-relay/lib/createRoseNetRelay.ts b/packages/rosenet-relay/lib/createRoseNetRelay.ts index 9276958..8bedfce 100644 --- a/packages/rosenet-relay/lib/createRoseNetRelay.ts +++ b/packages/rosenet-relay/lib/createRoseNetRelay.ts @@ -18,7 +18,11 @@ import { import { RoseNetRelayError } from './errors'; -import { DEFAULT_LISTEN_HOST } from './constants'; +import { + DEFAULT_LISTEN_HOST, + RESERVATION_DATA_LIMIT, + RESERVATION_DURATION_LIMIT, +} from './constants'; import packageJson from '../package.json' with { type: 'json' }; @@ -74,9 +78,12 @@ const createRoseNetRelay = async ({ circuitRelay: circuitRelayServer({ reservations: { maxReservations: config.maxReservations, - defaultDurationLimit: 0, - defaultDataLimit: 0n, - applyDefaultLimit: false, + /** + * Ideally we want the connection to upgrade through DCUtR, but for + * edge cases we keep these limits a reasonably large number + */ + defaultDurationLimit: RESERVATION_DURATION_LIMIT, + defaultDataLimit: RESERVATION_DATA_LIMIT, }, }), pubsub: gossipsub({