hsmtool: fix NULL secp256k1_ctx when calling dumpcommitments

secp256k1_ctx is used by pubkey_from_node_id.  Don't try to pick and
choose where to initialize secp256k1_ctx, just always do it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2024-11-06 13:50:12 +10:30
parent 9980931208
commit dca3a8c72c

View File

@@ -366,9 +366,6 @@ static int dump_commitments_infos(struct node_id *node_id, u64 channel_id,
struct secret hsm_secret, channel_seed, per_commitment_secret;
struct pubkey per_commitment_point;
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
get_hsm_secret(&hsm_secret, hsm_secret_path);
get_channel_seed(&channel_seed, node_id, channel_id, &hsm_secret);
@@ -424,9 +421,6 @@ static int guess_to_remote(const char *address, struct node_id *node_id,
if (segwit_addr_decode(&witver, goal_pubkeyhash, &witlen, hrp, address) != 1)
errx(ERROR_USAGE, "Wrong bech32 address");
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
get_hsm_secret(&hsm_secret, hsm_secret_path);
for (u64 dbid = 1; dbid < tries ; dbid++) {
@@ -705,9 +699,6 @@ static int get_node_id(const char *hsm_secret_path)
struct privkey node_privkey;
struct pubkey node_id;
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
/* Get hsm_secret */
get_hsm_secret(&hsm_secret, hsm_secret_path);
@@ -736,15 +727,13 @@ int main(int argc, char *argv[])
setup_locale();
err_set_progname(argv[0]);
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
method = argc > 1 ? argv[1] : NULL;
if (!method)
show_usage(argv[0]);
if (sodium_init() == -1)
errx(ERROR_LIBSODIUM,
"Could not initialize libsodium. Not enough entropy ?");
if (streq(method, "decrypt")) {
if (argc < 3)
show_usage(argv[0]);