Add p2p_node_id configuration setting and make node-id argument optional with fallback chain
- Add p2p_node_id field to ChainSettings with empty string default
- Add p2p_node_id to .env.example configuration file
- Change --node-id argument from required to optional with default empty string
- Add node_id resolution with fallback chain: args.node_id -> settings.p2p_node_id -> settings.proposer_id
- Add validation to raise ValueError if no node_id can be resolved
- Update systemd service to use ${
This commit is contained in:
@@ -10,6 +10,7 @@ rpc_bind_port=8006
|
||||
# Network
|
||||
p2p_bind_host=0.0.0.0
|
||||
p2p_bind_port=8001
|
||||
p2p_node_id=aitbc1-node
|
||||
|
||||
proposer_id=aitbc1-proposer
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ class ChainSettings(BaseSettings):
|
||||
|
||||
p2p_bind_host: str = "0.0.0.0"
|
||||
p2p_bind_port: int = 8001
|
||||
p2p_node_id: str = ""
|
||||
|
||||
proposer_id: str = ""
|
||||
proposer_key: Optional[str] = None
|
||||
|
||||
@@ -683,7 +683,7 @@ def main():
|
||||
parser = argparse.ArgumentParser(description="AITBC Direct TCP P2P Mesh Network")
|
||||
parser.add_argument("--host", default="0.0.0.0", help="Bind host")
|
||||
parser.add_argument("--port", type=int, default=7070, help="Bind port")
|
||||
parser.add_argument("--node-id", required=True, help="Node identifier (required for handshake)")
|
||||
parser.add_argument("--node-id", default="", help="Node identifier (defaults to settings.p2p_node_id)")
|
||||
parser.add_argument("--peers", default="", help="Comma separated list of initial peers to dial (ip:port)")
|
||||
|
||||
args = parser.parse_args()
|
||||
@@ -708,8 +708,12 @@ def main():
|
||||
max_size=settings.mempool_max_size,
|
||||
min_fee=settings.min_fee
|
||||
)
|
||||
|
||||
asyncio.run(run_p2p_service(args.host, args.port, args.node_id, args.peers))
|
||||
|
||||
node_id = args.node_id or settings.p2p_node_id or settings.proposer_id
|
||||
if not node_id:
|
||||
raise ValueError("p2p node_id is required")
|
||||
|
||||
asyncio.run(run_p2p_service(args.host, args.port, node_id, args.peers))
|
||||
except KeyboardInterrupt:
|
||||
logger.info("P2P service stopped by user")
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ WorkingDirectory=/opt/aitbc/apps/blockchain-node
|
||||
Environment=PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=PYTHONPATH=/opt/aitbc/apps/blockchain-node/src:/opt/aitbc/apps/blockchain-node/scripts
|
||||
EnvironmentFile=/etc/aitbc/blockchain.env
|
||||
ExecStart=/opt/aitbc/venv/bin/python -m aitbc_chain.p2p_network --host ${p2p_bind_host} --port ${p2p_bind_port} --peers ${p2p_peers} --node-id ${proposer_id}
|
||||
ExecStart=/opt/aitbc/venv/bin/python -m aitbc_chain.p2p_network --host ${p2p_bind_host} --port ${p2p_bind_port} --peers ${p2p_peers} --node-id ${p2p_node_id}
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardOutput=journal
|
||||
|
||||
Reference in New Issue
Block a user