From 8975fc2ceba6f525f266efaf10134ac4aa3510df Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 28 Mar 2018 13:02:39 +1030 Subject: [PATCH] libwally: use their secp context for all our daemons. I didn't convert all tests: they can still use a standalone context. It's just marginally more efficient to share the libwally one for all our daemons which link against it anyway. Signed-off-by: Rusty Russell --- channeld/test/run-full_channel.c | 5 ++--- common/subdaemon.c | 6 +++--- common/test/run-bolt11.c | 7 +++---- lightningd/lightningd.c | 5 ++--- wallet/test/run-wallet.c | 8 ++------ 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 09cac0e95..b022d3211 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -335,8 +335,7 @@ int main(void) const u8 *funding_wscript, **wscripts; size_t i; - secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY - | SECP256K1_CONTEXT_SIGN); + secp256k1_ctx = wally_get_secp_context(); setup_tmpctx(); feerate_per_kw = tal_arr(tmpctx, u32, NUM_SIDES); @@ -623,7 +622,7 @@ int main(void) } /* No memory leaks please */ - secp256k1_context_destroy(secp256k1_ctx); + wally_cleanup(0); tal_free(tmpctx); /* FIXME: Do BOLT comparison! */ diff --git a/common/subdaemon.c b/common/subdaemon.c index 220dffed9..1a91f6ee0 100644 --- a/common/subdaemon.c +++ b/common/subdaemon.c @@ -12,6 +12,7 @@ #include #include #include +#include #if BACKTRACE_SUPPORTED static struct backtrace_state *backtrace_state; @@ -75,8 +76,7 @@ void subdaemon_setup(int argc, char *argv[]) /* We handle write returning errors! */ signal(SIGPIPE, SIG_IGN); - secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY - | SECP256K1_CONTEXT_SIGN); + secp256k1_ctx = wally_get_secp_context(); setup_tmpctx(); @@ -105,5 +105,5 @@ void subdaemon_setup(int argc, char *argv[]) void subdaemon_shutdown(void) { tal_free(tmpctx); - secp256k1_context_destroy(secp256k1_ctx); + wally_cleanup(0); } diff --git a/common/test/run-bolt11.c b/common/test/run-bolt11.c index aece9b5ac..874e831f3 100644 --- a/common/test/run-bolt11.c +++ b/common/test/run-bolt11.c @@ -5,6 +5,7 @@ #include #include #include +#include /* AUTOGENERATED MOCKS START */ /* Generated stub for fromwire_pubkey */ @@ -118,8 +119,7 @@ int main(void) struct pubkey node; u64 msatoshi; - secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY - | SECP256K1_CONTEXT_SIGN); + secp256k1_ctx = wally_get_secp_context(); setup_tmpctx(); /* BOLT #11: @@ -235,8 +235,7 @@ int main(void) test_b11("lnbc20m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqscc6gd6ql3jrc5yzme8v4ntcewwz5cnw92tz0pc8qcuufvq7khhr8wpald05e92xw006sq94mg8v2ndf4sefvf9sygkshp5zfem29trqq2yxxz7", b11, "One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon"); /* FIXME: Test the others! */ - - secp256k1_context_destroy(secp256k1_ctx); + wally_cleanup(0); tal_free(tmpctx); return 0; } diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 7c4e981d4..376da2299 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -288,8 +288,7 @@ int main(int argc, char *argv[]) #endif ld = new_lightningd(NULL); - secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY - | SECP256K1_CONTEXT_SIGN); + secp256k1_ctx = wally_get_secp_context(); setup_tmpctx(); io_poll_override(debug_poll); @@ -428,6 +427,6 @@ int main(int argc, char *argv[]) memleak_cleanup(); #endif take_cleanup(); - secp256k1_context_destroy(secp256k1_ctx); + wally_cleanup(0); return 0; } diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index eccf4bc71..b2041625f 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -24,6 +24,7 @@ static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, const c #include #include #include +#include bool deprecated_apis = true; @@ -1004,11 +1005,6 @@ int main(void) take_cleanup(); tal_free(tmpctx); - - /* FIXME! https://github.com/ElementsProject/libwally-core/issues/26 */ - { - secp256k1_context *secp_ctx(void); - secp256k1_context_destroy(secp_ctx()); - } + wally_cleanup(0); return !ok; }