From 34e32978b84070d208b4aefc0bb1e48deb8577f9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jan 2016 06:41:49 +1030 Subject: [PATCH] bitcoind: warn if their bitcoin config doesn't have walletbroadcast=0. Because we use the bitcoin wallet to create the anchor transaction, we need to make sure it doesn't broadcast it; safest to check their config for the option. Signed-off-by: Rusty Russell --- daemon/bitcoind.c | 33 +++++++++++++++++++++++++++++++++ daemon/bitcoind.h | 1 + daemon/lightningd.c | 3 +++ 3 files changed, 37 insertions(+) diff --git a/daemon/bitcoind.c b/daemon/bitcoind.c index 1c7f7f0099ae..8a4795658024 100644 --- a/daemon/bitcoind.c +++ b/daemon/bitcoind.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -293,3 +295,34 @@ void bitcoind_create_payment(struct lightningd_state *dstate, start_bitcoin_cli(dstate, process_sendtoaddress, cb, peer, "sendtoaddress", addr, amtstr, NULL); } + +/* We make sure they have walletbroadcast=0, so we don't broadcast + * the anchor. */ +void check_bitcoind_config(struct lightningd_state *dstate) +{ + void *ctx = tal(dstate, char); + char *path, *config, **lines; + size_t i; + + path = path_simplify(ctx, path_join(ctx, path_cwd(ctx), + "../.bitcoin/bitcoin.conf")); + config = grab_file(ctx, path); + if (!config) { + log_unusual(dstate->base_log, "Could not open %s to check it", + path); + goto out; + } + + lines = tal_strsplit(ctx, config, "\n", STR_NO_EMPTY); + for (i = 0; lines[i]; i++) { + if (tal_strreg(ctx, lines[i], + "^[ \t]*walletbroadcast[ \t]*=[ \t]*0")) + goto out; + } + + + log_unusual(dstate->base_log, "%s does not contain walletbroadcast=0", + path); +out: + tal_free(ctx); +} diff --git a/daemon/bitcoind.h b/daemon/bitcoind.h index fe61be878e2c..2b2a9e5bb675 100644 --- a/daemon/bitcoind.h +++ b/daemon/bitcoind.h @@ -43,4 +43,5 @@ void bitcoind_create_payment(struct lightningd_state *dstate, struct peer *peer), struct peer *peer); +void check_bitcoind_config(struct lightningd_state *dstate); #endif /* LIGHTNING_DAEMON_BITCOIND_H */ diff --git a/daemon/lightningd.c b/daemon/lightningd.c index 586d20627ad8..a67bfe9f17c9 100644 --- a/daemon/lightningd.c +++ b/daemon/lightningd.c @@ -1,3 +1,4 @@ +#include "bitcoind.h" #include "configdir.h" #include "jsonrpc.h" #include "lightningd.h" @@ -196,6 +197,8 @@ int main(int argc, char *argv[]) if (argc != 1) errx(1, "no arguments accepted"); + check_bitcoind_config(dstate); + /* Create RPC socket (if any) */ setup_jsonrpc(dstate, dstate->rpc_filename);