Skip to content

Commit a8994c7

Browse files
authored
fix(dashmate)!: port conflicts with mainnet and testnet on the same host (#2829)
1 parent 7153d61 commit a8994c7

File tree

14 files changed

+118
-27
lines changed

14 files changed

+118
-27
lines changed

packages/dashmate/configs/defaults/getBaseConfigFactory.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export default function getBaseConfigFactory() {
265265
},
266266
},
267267
metrics: {
268+
enabled: false,
268269
host: '127.0.0.1',
269270
port: 9091,
270271
},

packages/dashmate/configs/defaults/getLocalConfigFactory.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export default function getLocalConfigFactory(getBaseConfig) {
3030
rpc: {
3131
port: 20002,
3232
},
33+
zmq: {
34+
port: 49998,
35+
},
3336
},
3437
platform: {
3538
gateway: {
@@ -45,6 +48,13 @@ export default function getLocalConfigFactory(getBaseConfig) {
4548
enabled: false,
4649
},
4750
},
51+
dapi: {
52+
rsDapi: {
53+
metrics: {
54+
port: 29091,
55+
},
56+
},
57+
},
4858
drive: {
4959
tenderdash: {
5060
p2p: {

packages/dashmate/configs/defaults/getTestnetConfigFactory.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export default function getTestnetConfigFactory(homeDir, getBaseConfig) {
3030
rpc: {
3131
port: 19998,
3232
},
33+
zmq: {
34+
port: 39998,
35+
},
3336
spork: {
3437
address: 'yjPtiKh2uwk3bDutTEA2q9mCtXyiZRWn55',
3538
},
@@ -153,6 +156,13 @@ export default function getTestnetConfigFactory(homeDir, getBaseConfig) {
153156
},
154157
},
155158
},
159+
dapi: {
160+
rsDapi: {
161+
metrics: {
162+
port: 19091,
163+
},
164+
},
165+
},
156166
},
157167
network: NETWORK_TESTNET,
158168
};

packages/dashmate/configs/getConfigFileMigrationsFactory.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,67 @@ export default function getConfigFileMigrationsFactory(homeDir, defaultConfigs)
12261226

12271227
return configFile;
12281228
},
1229+
'2.2.0-dev.1': (configFile) => {
1230+
Object.entries(configFile.configs)
1231+
.forEach(([name, options]) => {
1232+
const defaultConfig = getDefaultConfigByNameOrGroup(name, options.group);
1233+
if (!options.platform.dapi.rsDapi) {
1234+
options.platform.dapi.rsDapi = lodash.cloneDeep(defaultConfig.get('platform.dapi.rsDapi'));
1235+
}
1236+
1237+
const defaultMetrics = defaultConfig.get('platform.dapi.rsDapi.metrics');
1238+
const defaultZmqPort = defaultConfig.get('core.zmq.port');
1239+
const baseMetricsPort = base.get('platform.dapi.rsDapi.metrics.port');
1240+
const baseZmqPort = base.get('core.zmq.port');
1241+
1242+
if (!options.platform.dapi.rsDapi.metrics) {
1243+
options.platform.dapi.rsDapi.metrics = lodash.cloneDeep(defaultMetrics);
1244+
}
1245+
1246+
if (typeof options.platform.dapi.rsDapi.metrics.enabled === 'undefined') {
1247+
options.platform.dapi.rsDapi.metrics.enabled = defaultMetrics.enabled;
1248+
}
1249+
1250+
if (!options.core.zmq) {
1251+
options.core.zmq = lodash.cloneDeep(defaultConfig.get('core.zmq'));
1252+
} else {
1253+
options.core.zmq = lodash.cloneDeep(options.core.zmq);
1254+
}
1255+
1256+
if (typeof options.core.zmq.port === 'undefined') {
1257+
options.core.zmq.port = defaultConfig.get('core.zmq.port');
1258+
}
1259+
1260+
if (typeof options.platform.dapi.rsDapi.metrics.port === 'undefined') {
1261+
options.platform.dapi.rsDapi.metrics.port = defaultMetrics.port;
1262+
}
1263+
1264+
const targetMetricsPort = Number(defaultMetrics.port);
1265+
const targetZmqPort = Number(defaultZmqPort);
1266+
const configuredMetricsPort = Number(options.platform.dapi.rsDapi.metrics.port);
1267+
const configuredZmqPort = Number(options.core.zmq.port);
1268+
const baseMetricsPortNumber = Number(baseMetricsPort);
1269+
const baseZmqPortNumber = Number(baseZmqPort);
1270+
1271+
if (
1272+
!Number.isNaN(targetMetricsPort)
1273+
&& targetMetricsPort !== configuredMetricsPort
1274+
&& configuredMetricsPort === baseMetricsPortNumber
1275+
) {
1276+
options.platform.dapi.rsDapi.metrics.port = targetMetricsPort;
1277+
}
1278+
1279+
if (
1280+
!Number.isNaN(targetZmqPort)
1281+
&& targetZmqPort !== configuredZmqPort
1282+
&& (configuredZmqPort === baseZmqPortNumber || configuredZmqPort === 29998)
1283+
) {
1284+
options.core.zmq.port = targetZmqPort;
1285+
}
1286+
});
1287+
1288+
return configFile;
1289+
},
12291290
};
12301291
}
12311292

packages/dashmate/docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ services:
229229
expose:
230230
- 3009 # JSON-RPC
231231
- 3010 # gRPC (different from current DAPI to avoid conflict)
232-
- ${PLATFORM_DAPI_RS_DAPI_METRICS_PORT:?err} # Metrics
233-
ports:
234-
- ${PLATFORM_DAPI_RS_DAPI_METRICS_HOST:?err}:${PLATFORM_DAPI_RS_DAPI_METRICS_PORT:?err}:${PLATFORM_DAPI_RS_DAPI_METRICS_PORT:?err}
235232
profiles:
236233
- platform-dapi-rs
237234

packages/dashmate/docs/config/core.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ The `core.zmq` section configures the ZeroMQ notification interface, which provi
7373

7474
| Option | Description | Default | Example |
7575
|--------|-------------|---------|---------|
76-
| `core.zmq.port` | Port for ZMQ notifications | `29998` | `30998` |
76+
| `core.zmq.port` | Port for ZMQ notifications | `29998` (mainnet),`39998` (testnet), `49998` (local) | `30998` |
7777
| `core.zmq.host` | Host binding for Docker port mapping | `127.0.0.1` | `0.0.0.0` |
7878

7979
ZMQ settings control real-time blockchain event notifications:
8080
- ZMQ provides low-latency notifications for blocks, transactions, and other blockchain events
8181
- **host**: Controls Docker port exposure:
8282
- `127.0.0.1`: ZMQ port exposed only on localhost (local machine access)
8383
- `0.0.0.0`: ZMQ port exposed on all interfaces (public internet access - use with caution)
84-
- **port**: The port number for ZMQ notifications
84+
- **port**: The port number for ZMQ notifications. Dashmate offsets the default to prevent clashes between environments (`29998` mainnet, `39998` testnet, `49998` local presets).
8585
- DAPI uses ZMQ to receive real-time blockchain data for streaming to clients
8686
- ZMQ notifications include raw transactions, blocks, instantlocks, and chainlocks
8787
- ZMQ is always enabled in Dash Core as it's used by internal components

packages/dashmate/docs/config/dapi.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ This timeout setting controls how long DAPI will wait for state transition resul
5353
| Option | Description | Default | Example |
5454
|--------|-------------|---------|---------|
5555
| `platform.dapi.rsDapi.metrics.host` | Host interface exposed on the Docker host | `127.0.0.1` | `0.0.0.0` |
56-
| `platform.dapi.rsDapi.metrics.port` | Host port for both health checks and Prometheus metrics | `9091` | `9191` |
56+
| `platform.dapi.rsDapi.metrics.port` | Host port for both health checks and Prometheus metrics | `9091` (mainnet), `19091` (testnet), `29091` (local) | `9191` |
5757

5858
The rs-dapi metrics server exposes `/health` and `/metrics`. Prometheus-compatible metrics are served from `/metrics` on the configured port, allowing separate node instances on the same machine to use distinct ports. The `/health` endpoint aggregates dependency checks (Drive, Tenderdash, Core) and returns `503` when any upstream component is unhealthy.
5959

60+
Dashmate offsets the default metrics port per preset (mainnet 9091, testnet 19091, local 29091) to avoid clashes when running multiple environments concurrently.
61+
6062
### Logging
6163

6264
| Option | Description | Default | Example |

packages/dashmate/docs/services/core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Core exposes P2P and RPC ports for communication with other services. It also pr
3333
|----------------------|--------------|---------------|---------------------|----------------------|------------------|
3434
| **Core** | P2P | 9999 | `core.p2p.port` | 0.0.0.0 (all) | `core.p2p.host` |
3535
| | RPC | 9998 | `core.rpc.port` | 127.0.0.1 (local) | `core.rpc.host` |
36-
| | ZMQ | 29998 | `core.zmq.port` | 127.0.0.1 (local) | `core.zmq.host` |
36+
| | ZMQ | 29998 (mainnet), 39998 (testnet), 49998 (local) | `core.zmq.port` | 127.0.0.1 (local) | `core.zmq.host` |
3737
| **Insight API/UI** | HTTP | 3001 | `core.insight.port` | 127.0.0.1 (local) | (fixed) |
3838

3939
To interact with Core RPC use `dashmate core cli` command.

packages/dashmate/docs/services/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ Dashmate runs and orchestrate Dash Platform components:
7373
| Type | Ports | Default Host Binding |
7474
|---------------------|--------------------------------------------------------------|---------------------|
7575
| **Public-facing** | Core P2P (9999)<br>Tenderdash P2P (26656)<br>Gateway API (443) | 0.0.0.0 (all) |
76-
| **Configurable** | Core ZMQ (29998) | configurable (see below) |
76+
| **Configurable** | Core ZMQ (29998 mainnet / 39998 testnet / 49998 local) | configurable (see below) |
7777
| **Localhost-only** | Core RPC (9998)<br>Insight UI (3001)<br>Dashmate Helper (9100)<br>Drive ABCI Metrics (29090)<br>Drive Debug Tools (6669, 8083)<br>Tenderdash RPC (26657)<br>Tenderdash Metrics (26660)<br>Tenderdash Debug (6060)<br>Gateway Metrics (9090)<br>Gateway Admin (9901)<br>Rate Limiter Metrics (9102) | 127.0.0.1 (local) |
7878
| **Internal only** | Drive ABCI (26658)<br>Drive gRPC (26670)<br>DAPI JSON-RPC (3004)<br>DAPI gRPC (3005)<br>DAPI Streams (3006)<br>Rate Limiter gRPC (8081)<br>Rate Limiter StatsD (9125)<br>Rate Limiter Redis (6379) | (not exposed) |
7979

8080
#### Core ZMQ Exposure Configuration
8181

82-
The Core ZMQ port (29998) exposure is configurable via `core.zmq.host`:
82+
The Core ZMQ port (29998 on mainnet, 39998 on testnet, 49998 on local presets) exposure is configurable via `core.zmq.host`:
8383
- **`host: '127.0.0.1'`** (default): ZMQ port exposed on localhost only
8484
- **`host: '0.0.0.0'`**: ZMQ port exposed on all interfaces (use with caution)
8585

packages/dashmate/docs/services/platform.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ Tenderdash is the consensus engine that provides Byzantine Fault Tolerant (BFT)
154154
| **DAPI API** | JSON-RPC | 3004 | (fixed internal) | (internal) | - |
155155
| | gRPC | 3005 | (fixed internal) | (internal) | - |
156156
| **DAPI Core Streams** | gRPC Streaming | 3006 | (fixed internal) | (internal) | - |
157-
| **rs-dapi (Rust)** | Health + Metrics | 9091 | `platform.dapi.rsDapi.metrics.port` | 127.0.0.1 | `platform.dapi.rsDapi.metrics.host` |
157+
| **rs-dapi (Rust)** | Health + Metrics | 9091 (mainnet), 19091 (testnet), 29091 (local) | `platform.dapi.rsDapi.metrics.port` | 127.0.0.1 | `platform.dapi.rsDapi.metrics.host` |
158158

159-
The rs-dapi metrics server exposes health endpoints alongside Prometheus data on `/metrics` from the same port.
159+
The rs-dapi metrics server exposes health endpoints alongside Prometheus data on `/metrics` from the same port. Dashmate applies network-specific defaults (mainnet 9091, testnet 19091, local 29091) so multiple presets can coexist on a host without conflicts.

0 commit comments

Comments
 (0)