@clawlabz/clawnetwork 0.1.22 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.ts CHANGED
@@ -7,7 +7,7 @@ declare function setInterval(fn: () => void, ms: number): unknown
7
7
  declare function clearInterval(id: unknown): void
8
8
  declare function fetch(url: string, init?: Record<string, unknown>): Promise<{ status: number; ok: boolean; text: () => Promise<string>; json: () => Promise<unknown> }>
9
9
 
10
- const VERSION = '0.1.22'
10
+ const VERSION = '0.1.24'
11
11
  const PLUGIN_ID = 'clawnetwork'
12
12
  const GITHUB_REPO = 'clawlabz/claw-network'
13
13
  const DEFAULT_RPC_PORT = 9710
@@ -139,7 +139,8 @@ function homePath(...segments: string[]): string {
139
139
 
140
140
  const WORKSPACE_DIR = path.join(getBaseDir(), 'workspace', 'clawnetwork')
141
141
  const BIN_DIR = path.join(getBaseDir(), 'bin')
142
- const DATA_DIR = homePath('.clawnetwork')
142
+ // Plugin uses its own chain data dir under workspace to avoid locking conflicts with other nodes
143
+ const DATA_DIR = path.join(getBaseDir(), 'workspace', 'clawnetwork', 'chain-data')
143
144
  const WALLET_PATH = path.join(WORKSPACE_DIR, 'wallet.json')
144
145
  const LOG_PATH = path.join(WORKSPACE_DIR, 'node.log')
145
146
  const UI_PORT_FILE = path.join(getBaseDir(), 'clawnetwork-ui-port')
@@ -363,7 +364,8 @@ function initNode(binaryPath: string, network: string, api: OpenClawApi): void {
363
364
  }
364
365
  api.logger?.info?.(`[clawnetwork] initializing node for ${network}...`)
365
366
  try {
366
- const output = execFileSync(binaryPath, ['init', '--network', network], {
367
+ ensureDir(DATA_DIR)
368
+ const output = execFileSync(binaryPath, ['init', '--network', network, '--data-dir', DATA_DIR], {
367
369
  encoding: 'utf8',
368
370
  timeout: 30_000,
369
371
  env: { HOME: os.homedir(), PATH: process.env.PATH || '' }, // minimal env
@@ -528,10 +530,10 @@ function findAvailablePorts(rpcPort: number, p2pPort: number, api: OpenClawApi):
528
530
  rpc++
529
531
  }
530
532
 
531
- // Find available P2P port
533
+ // Find available P2P port (must also differ from RPC port)
532
534
  for (let i = 0; i < MAX_TRIES; i++) {
533
- if (!isPortInUse(p2p)) break
534
- api.logger?.info?.(`[clawnetwork] P2P port ${p2p} in use, trying ${p2p + 1}...`)
535
+ if (!isPortInUse(p2p) && p2p !== rpc) break
536
+ api.logger?.info?.(`[clawnetwork] P2P port ${p2p} in use or conflicts with RPC, trying ${p2p + 1}...`)
535
537
  p2p++
536
538
  }
537
539
 
@@ -613,7 +615,7 @@ function startNodeProcess(binaryPath: string, cfg: PluginConfig, api: OpenClawAp
613
615
  activeRpcPort = ports.rpcPort
614
616
  activeP2pPort = ports.p2pPort
615
617
 
616
- const args = ['start', '--network', cfg.network, '--rpc-port', String(ports.rpcPort), '--p2p-port', String(ports.p2pPort), '--sync-mode', cfg.syncMode, '--allow-genesis']
618
+ const args = ['start', '--network', cfg.network, '--rpc-port', String(ports.rpcPort), '--p2p-port', String(ports.p2pPort), '--sync-mode', cfg.syncMode, '--data-dir', DATA_DIR, '--allow-genesis']
617
619
 
618
620
  // Add bootstrap peers: built-in for the network + user-configured extra peers
619
621
  const peers = [...(BOOTSTRAP_PEERS[cfg.network] ?? []), ...cfg.extraBootstrapPeers]
@@ -1518,6 +1520,7 @@ const OC_PID_FILE = path.join(OC_WORKSPACE, 'node.pid');
1518
1520
  const OC_CONFIG_PATH = path.join(OC_WORKSPACE, 'config.json');
1519
1521
  const OC_STOP_SIGNAL = path.join(OC_WORKSPACE, 'stop.signal');
1520
1522
  const OC_LOG_PATH_DEFAULT = path.join(OC_WORKSPACE, 'node.log');
1523
+ const OC_DATA_DIR = path.join(OC_WORKSPACE, 'chain-data');
1521
1524
 
1522
1525
  const PORT = parseInt(process.argv[2] || '19877', 10);
1523
1526
  const RPC_PORT = parseInt(process.argv[3] || '9710', 10);
@@ -1784,7 +1787,7 @@ async function handle(req, res) {
1784
1787
  } catch {}
1785
1788
  const bootstrapPeers = { mainnet: ['/ip4/178.156.162.162/tcp/9711', '/ip4/39.102.144.231/tcp/9711'], testnet: ['/ip4/178.156.162.162/tcp/9721', '/ip4/39.102.144.231/tcp/9721'], devnet: [] };
1786
1789
  const peers = [...(bootstrapPeers[network] || []), ...extraPeers];
1787
- const args = ['start', '--network', network, '--rpc-port', String(RPC_PORT), '--p2p-port', String(p2pPort), '--sync-mode', syncMode, '--allow-genesis'];
1790
+ const args = ['start', '--network', network, '--rpc-port', String(RPC_PORT), '--p2p-port', String(p2pPort), '--sync-mode', syncMode, '--data-dir', OC_DATA_DIR, '--allow-genesis'];
1788
1791
  for (const peer of peers) { args.push('--bootstrap', peer); }
1789
1792
  // Spawn detached
1790
1793
  const logPath = OC_LOG_PATH_DEFAULT;
@@ -1867,7 +1870,7 @@ async function handle(req, res) {
1867
1870
  } catch {}
1868
1871
  const bootstrapPeers = { mainnet: ['/ip4/178.156.162.162/tcp/9711', '/ip4/39.102.144.231/tcp/9711'], testnet: ['/ip4/178.156.162.162/tcp/9721', '/ip4/39.102.144.231/tcp/9721'], devnet: [] };
1869
1872
  const peers = [...(bootstrapPeers[network] || []), ...extraPeers];
1870
- const args = ['start', '--network', network, '--rpc-port', String(RPC_PORT), '--p2p-port', String(p2pPort), '--sync-mode', syncMode, '--allow-genesis'];
1873
+ const args = ['start', '--network', network, '--rpc-port', String(RPC_PORT), '--p2p-port', String(p2pPort), '--sync-mode', syncMode, '--data-dir', OC_DATA_DIR, '--allow-genesis'];
1871
1874
  for (const peer of peers) { args.push('--bootstrap', peer); }
1872
1875
  const logPath = OC_LOG_PATH_DEFAULT;
1873
1876
  const logFd = fs.openSync(logPath, 'a');
@@ -1982,7 +1985,7 @@ function startUiServer(cfg: PluginConfig, api: OpenClawApi): string | null {
1982
1985
  fs.writeFileSync(scriptPath, fullScript)
1983
1986
 
1984
1987
  try {
1985
- const child = fork(scriptPath, [String(cfg.uiPort), String(cfg.rpcPort), LOG_PATH], {
1988
+ const child = fork(scriptPath, [String(cfg.uiPort), String(activeRpcPort ?? cfg.rpcPort), LOG_PATH], {
1986
1989
  detached: true,
1987
1990
  stdio: 'ignore',
1988
1991
  })
@@ -2,7 +2,7 @@
2
2
  "id": "clawnetwork",
3
3
  "name": "ClawNetwork Node",
4
4
  "description": "Run a ClawNetwork blockchain node inside OpenClaw. Every agent is a node.",
5
- "version": "0.1.22",
5
+ "version": "0.1.24",
6
6
  "configSchema": {
7
7
  "type": "object",
8
8
  "additionalProperties": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawlabz/clawnetwork",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "Run a ClawNetwork blockchain node inside OpenClaw. Every agent is a blockchain node.",
5
5
  "type": "module",
6
6
  "license": "MIT",