Browse Source

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 <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
34e32978b8
  1. 33
      daemon/bitcoind.c
  2. 1
      daemon/bitcoind.h
  3. 3
      daemon/lightningd.c

33
daemon/bitcoind.c

@ -10,6 +10,8 @@
#include <ccan/io/io.h> #include <ccan/io/io.h>
#include <ccan/pipecmd/pipecmd.h> #include <ccan/pipecmd/pipecmd.h>
#include <ccan/str/hex/hex.h> #include <ccan/str/hex/hex.h>
#include <ccan/tal/grab_file/grab_file.h>
#include <ccan/tal/path/path.h>
#include <ccan/tal/str/str.h> #include <ccan/tal/str/str.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <errno.h> #include <errno.h>
@ -293,3 +295,34 @@ void bitcoind_create_payment(struct lightningd_state *dstate,
start_bitcoin_cli(dstate, process_sendtoaddress, cb, peer, start_bitcoin_cli(dstate, process_sendtoaddress, cb, peer,
"sendtoaddress", addr, amtstr, NULL); "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);
}

1
daemon/bitcoind.h

@ -43,4 +43,5 @@ void bitcoind_create_payment(struct lightningd_state *dstate,
struct peer *peer), struct peer *peer),
struct peer *peer); struct peer *peer);
void check_bitcoind_config(struct lightningd_state *dstate);
#endif /* LIGHTNING_DAEMON_BITCOIND_H */ #endif /* LIGHTNING_DAEMON_BITCOIND_H */

3
daemon/lightningd.c

@ -1,3 +1,4 @@
#include "bitcoind.h"
#include "configdir.h" #include "configdir.h"
#include "jsonrpc.h" #include "jsonrpc.h"
#include "lightningd.h" #include "lightningd.h"
@ -196,6 +197,8 @@ int main(int argc, char *argv[])
if (argc != 1) if (argc != 1)
errx(1, "no arguments accepted"); errx(1, "no arguments accepted");
check_bitcoind_config(dstate);
/* Create RPC socket (if any) */ /* Create RPC socket (if any) */
setup_jsonrpc(dstate, dstate->rpc_filename); setup_jsonrpc(dstate, dstate->rpc_filename);

Loading…
Cancel
Save