Skip to content

Commit

Permalink
lightningd: use the standard port derivation in connect command
Browse files Browse the repository at this point in the history
Complete implementation of BOLT1 port derivation proposal lightning/bolts#968

Changelog-Added: rpc: use the standard port derivation in connect command when the port is not specified.

Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo authored and whitslack committed Oct 21, 2022
1 parent 6dd85a8 commit ff6a68b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion bitcoin/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const struct chainparams networks[] = {
0x5a, 0x08, 0x9c, 0x68, 0xd6, 0x19, 0x00,
0x00, 0x00, 0x00, 0x00}}}},
.rpc_port = 8332,
.ln_port = 9735,
.cli = "bitcoin-cli",
.cli_args = NULL,
.cli_min_supported_version = 150000,
Expand Down Expand Up @@ -67,6 +68,7 @@ const struct chainparams networks[] = {
0x33, 0x2a, 0x1f, 0xc7, 0xb2, 0xb7, 0x3c,
0xf1, 0x88, 0x91, 0x0f}}}},
.rpc_port = 18443,
.ln_port = 9735,
.cli = "bitcoin-cli",
.cli_args = "-regtest",
.cli_min_supported_version = 150000,
Expand All @@ -92,6 +94,7 @@ const struct chainparams networks[] = {
0x2c, 0x42, 0x25, 0xe9, 0x73, 0x98, 0x81,
0x08, 0x00, 0x00, 0x00}}}},
.rpc_port = 38332,
.ln_port = 39735,
.cli = "bitcoin-cli",
.cli_args = "-signet",
.cli_min_supported_version = 150000,
Expand All @@ -115,6 +118,7 @@ const struct chainparams networks[] = {
0xe9, 0x0e, 0xad, 0x01, 0xea, 0x33, 0x09,
0x00, 0x00, 0x00, 0x00}}}},
.rpc_port = 18332,
.ln_port = 19735,
.cli = "bitcoin-cli",
.cli_args = "-testnet",
.cli_min_supported_version = 150000,
Expand All @@ -138,6 +142,7 @@ const struct chainparams networks[] = {
0x1e, 0xda, 0xba, 0x59, 0x40, 0xfd, 0x1f,
0xe3, 0x65, 0xa7, 0x12}}}},
.rpc_port = 9332,
.ln_port = 9735,
.cli = "litecoin-cli",
.cli_args = NULL,
.cli_min_supported_version = 150000,
Expand All @@ -162,6 +167,7 @@ const struct chainparams networks[] = {
0x13, 0xee, 0xfd, 0xd9, 0x51, 0x28, 0x4b,
0x5a, 0x62, 0x66, 0x49}}}},
.rpc_port = 19332,
.ln_port = 9735,
.cli = "litecoin-cli",
.cli_args = "-testnet",
.cli_min_supported_version = 150000,
Expand All @@ -186,6 +192,7 @@ const struct chainparams networks[] = {
0xfe, 0x14, 0x68, 0x01, 0x16, 0x23, 0x93,
0x36, 0x42, 0x86, 0xc6}}}},
.rpc_port = 19332,
.ln_port = 9735,
.cli = "elements-cli",
.cli_args = "-chain=liquid-regtest",
.dust_limit = {546},
Expand All @@ -209,6 +216,7 @@ const struct chainparams networks[] = {
0x68, 0x8d, 0x2c, 0x37, 0x92, 0x96, 0x88,
0x8a, 0x20, 0x60, 0x03}}}},
.rpc_port = 7041,
.ln_port = 9735,
.cli = "elements-cli",
.cli_args = "-chain=liquidv1",
.dust_limit = {546},
Expand Down Expand Up @@ -261,4 +269,3 @@ const char *chainparams_get_network_names(const tal_t *ctx)
tal_append_fmt(&networks_string, ", %s", networks[i].network_name);
return networks_string;
}

8 changes: 8 additions & 0 deletions bitcoin/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ struct chainparams {
const char *bip70_name;
const struct bitcoin_blkid genesis_blockhash;
const int rpc_port;
/**
* BOLT 1: The default TCP port depends on the network used. The most common networks are:
*
* - Bitcoin mainet with port number 9735 or the corresponding hexadecimal `0x2607`;
* - Bitcoin testnet with port number 19735 (`0x4D17`);
* - Bitcoin signet with port number 39735 (`0xF87`).
*/
const int ln_port;
const char *cli;
const char *cli_args;
/* The min numeric version of cli supported */
Expand Down
3 changes: 2 additions & 1 deletion lightningd/connect_control.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "config.h"
#include <bitcoin/chainparams.h>
#include <ccan/err/err.h>
#include <ccan/tal/str/str.h>
#include <common/configdir.h>
Expand Down Expand Up @@ -140,7 +141,7 @@ static struct command_result *json_connect(struct command *cmd,
/* Is there a port? */
if (!port) {
port = tal(cmd, u32);
*port = DEFAULT_PORT;
*port = chainparams->ln_port;
}
addr = tal(cmd, struct wireaddr_internal);
if (!parse_wireaddr_internal(name, addr, *port, false,
Expand Down
2 changes: 1 addition & 1 deletion lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ int main(int argc, char *argv[])

/*~ Set the default portnum according to the used network
* similarly to what Bitcoin Core does to ports by default. */
ld->portnum = DEFAULT_PORT + chainparams->rpc_port - 8332;
ld->portnum = chainparams->ln_port;

/*~ Initialize all the plugins we just registered, so they can
* do their thing and tell us about themselves (including
Expand Down

0 comments on commit ff6a68b

Please sign in to comment.