From fdb37040065e1ab88d215704148229ecfc344aa4 Mon Sep 17 00:00:00 2001 From: driftluo Date: Tue, 26 Nov 2024 14:43:41 +0800 Subject: [PATCH] feat: default listen on ws port --- ckb-bin/src/subcommand/init.rs | 7 +++++++ resource/ckb.toml | 4 ++-- util/app-config/src/tests/app_config.rs | 20 +++++++++++++++++--- util/app-config/src/tests/legacy.rs | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ckb-bin/src/subcommand/init.rs b/ckb-bin/src/subcommand/init.rs index b8a72905f8..00cb8d202c 100644 --- a/ckb-bin/src/subcommand/init.rs +++ b/ckb-bin/src/subcommand/init.rs @@ -157,11 +157,18 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> { let log_to_file = args.log_to_file.to_string(); let log_to_stdout = args.log_to_stdout.to_string(); + let ws_port = (args + .p2p_port + .parse::() + .unwrap_or_default() + .saturating_add(1)) + .to_string(); let mut context = TemplateContext::new( &args.chain, vec![ ("rpc_port", args.rpc_port.as_str()), ("p2p_port", args.p2p_port.as_str()), + ("ws_port", ws_port.as_str()), ("log_to_file", log_to_file.as_str()), ("log_to_stdout", log_to_stdout.as_str()), ("block_assembler", block_assembler.as_str()), diff --git a/resource/ckb.toml b/resource/ckb.toml index 68cf8e2fd8..d506a3bce4 100644 --- a/resource/ckb.toml +++ b/resource/ckb.toml @@ -63,8 +63,8 @@ cache_size = 268435456 options_file = "default.db-options" [network] -listen_addresses = ["/ip4/0.0.0.0/tcp/8115"] # {{ -# _ => listen_addresses = ["/ip4/0.0.0.0/tcp/{p2p_port}"] +listen_addresses = ["/ip4/0.0.0.0/tcp/8115", "/ip4/0.0.0.0/tcp/8118/ws"] # {{ +# _ => listen_addresses = ["/ip4/0.0.0.0/tcp/{p2p_port}", "/ip4/0.0.0.0/tcp/{ws_port}/ws"] # }} ### Specify the public and routable network addresses # public_addresses = [] diff --git a/util/app-config/src/tests/app_config.rs b/util/app-config/src/tests/app_config.rs index 52fcd4b163..7cdcff33a9 100644 --- a/util/app-config/src/tests/app_config.rs +++ b/util/app-config/src/tests/app_config.rs @@ -33,6 +33,7 @@ fn test_export_dev_config_files() { vec![ ("rpc_port", "7000"), ("p2p_port", "8000"), + ("ws_port", "8001"), ("log_to_file", "true"), ("log_to_stdout", "true"), ("block_assembler", ""), @@ -86,6 +87,7 @@ fn test_log_to_stdout_only() { vec![ ("rpc_port", "7000"), ("p2p_port", "8000"), + ("ws_port", "8001"), ("log_to_file", "false"), ("log_to_stdout", "true"), ("block_assembler", ""), @@ -126,6 +128,7 @@ fn test_export_testnet_config_files() { vec![ ("rpc_port", "7000"), ("p2p_port", "8000"), + ("ws_port", "8001"), ("log_to_file", "true"), ("log_to_stdout", "true"), ("block_assembler", ""), @@ -148,7 +151,10 @@ fn test_export_testnet_config_files() { ); assert_eq!( ckb_config.network.listen_addresses, - vec!["/ip4/0.0.0.0/tcp/8000".parse().unwrap()] + vec![ + "/ip4/0.0.0.0/tcp/8000".parse().unwrap(), + "/ip4/0.0.0.0/tcp/8001/ws".parse().unwrap() + ] ); assert_eq!(ckb_config.network.connect_outbound_interval_secs, 15); assert_eq!(ckb_config.rpc.listen_address, "127.0.0.1:7000"); @@ -179,6 +185,7 @@ fn test_export_integration_config_files() { vec![ ("rpc_port", "7000"), ("p2p_port", "8000"), + ("ws_port", "8001"), ("log_to_file", "true"), ("log_to_stdout", "true"), ("block_assembler", ""), @@ -200,7 +207,10 @@ fn test_export_integration_config_files() { ); assert_eq!( ckb_config.network.listen_addresses, - vec!["/ip4/0.0.0.0/tcp/8000".parse().unwrap()] + vec![ + "/ip4/0.0.0.0/tcp/8000".parse().unwrap(), + "/ip4/0.0.0.0/tcp/8001/ws".parse().unwrap() + ] ); assert_eq!(ckb_config.rpc.listen_address, "127.0.0.1:7000"); } @@ -230,6 +240,7 @@ fn test_export_dev_config_files_assembly() { vec![ ("rpc_port", "7000"), ("p2p_port", "8000"), + ("ws_port", "8001"), ("log_to_file", "true"), ("log_to_stdout", "true"), ("block_assembler", ""), @@ -252,7 +263,10 @@ fn test_export_dev_config_files_assembly() { ); assert_eq!( ckb_config.network.listen_addresses, - vec!["/ip4/0.0.0.0/tcp/8000".parse().unwrap()] + vec![ + "/ip4/0.0.0.0/tcp/8000".parse().unwrap(), + "/ip4/0.0.0.0/tcp/8001/ws".parse().unwrap() + ] ); assert_eq!(ckb_config.network.connect_outbound_interval_secs, 15); assert_eq!(ckb_config.rpc.listen_address, "127.0.0.1:7000"); diff --git a/util/app-config/src/tests/legacy.rs b/util/app-config/src/tests/legacy.rs index cc840c4b67..87bb63c1aa 100644 --- a/util/app-config/src/tests/legacy.rs +++ b/util/app-config/src/tests/legacy.rs @@ -55,6 +55,7 @@ fn no_deprecated_fields_in_bundled_ckb_app_config() { vec![ ("rpc_port", "7000"), ("p2p_port", "8000"), + ("ws_port", "8001"), ("log_to_file", "true"), ("log_to_stdout", "true"), ("block_assembler", ""),