Skip to content

Commit

Permalink
Set default port according to network
Browse files Browse the repository at this point in the history
This is just a quick draft, will be thought through and
finished by the daylight.
common/wireaddr.h: Extend DEFAULT_PORT comment

With Vincenzzo's pair-programming help.

Changelog-Changed: If the port is unspecified, the default port is chosen according to used network similarly to Bitcoin Core.
  • Loading branch information
jsarenik committed Nov 3, 2021
1 parent 3d8293d commit 6ba8215
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bitcoin/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const struct chainparams networks[] = {
0x5a, 0x08, 0x9c, 0x68, 0xd6, 0x19, 0x00,
0x00, 0x00, 0x00, 0x00}}}},
.rpc_port = 8332,
.port_add = 0,
.cli = "bitcoin-cli",
.cli_args = NULL,
.cli_min_supported_version = 150000,
Expand Down Expand Up @@ -64,6 +65,7 @@ const struct chainparams networks[] = {
0x33, 0x2a, 0x1f, 0xc7, 0xb2, 0xb7, 0x3c,
0xf1, 0x88, 0x91, 0x0f}}}},
.rpc_port = 18332,
.port_add = 10111,
.cli = "bitcoin-cli",
.cli_args = "-regtest",
.cli_min_supported_version = 150000,
Expand All @@ -88,6 +90,7 @@ const struct chainparams networks[] = {
0x2c, 0x42, 0x25, 0xe9, 0x73, 0x98, 0x81,
0x08, 0x00, 0x00, 0x00}}}},
.rpc_port = 38332,
.port_add = 30000,
.cli = "bitcoin-cli",
.cli_args = "-signet",
.cli_min_supported_version = 150000,
Expand All @@ -110,6 +113,7 @@ const struct chainparams networks[] = {
0xe9, 0x0e, 0xad, 0x01, 0xea, 0x33, 0x09,
0x00, 0x00, 0x00, 0x00}}}},
.rpc_port = 18332,
.port_add = 10000,
.cli = "bitcoin-cli",
.cli_args = "-testnet",
.cli_min_supported_version = 150000,
Expand Down
1 change: 1 addition & 0 deletions bitcoin/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct chainparams {
const char *bip70_name;
const struct bitcoin_blkid genesis_blockhash;
const int rpc_port;
const int port_add;
const char *cli;
const char *cli_args;
/* The min numeric version of cli supported */
Expand Down
3 changes: 2 additions & 1 deletion lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
* NULL. So we start with a zero-length array. */
ld->proposed_wireaddr = tal_arr(ld, struct wireaddr_internal, 0);
ld->proposed_listen_announce = tal_arr(ld, enum addr_listen_announce, 0);
ld->portnum = DEFAULT_PORT;
ld->portnum = DEFAULT_PORT; // See also port_add later
ld->listen = true;
ld->autolisten = true;
ld->reconnect = true;
Expand Down Expand Up @@ -965,6 +965,7 @@ int main(int argc, char *argv[])

/*~ Handle options and config. */
handle_opts(ld, argc, argv);
ld->portnum = DEFAULT_PORT + chainparams->port_add;

/*~ Now create the PID file: this errors out if there's already a
* daemon running, so we call before doing almost anything else. */
Expand Down

0 comments on commit 6ba8215

Please sign in to comment.