Skip to content

Commit

Permalink
bitcoind: warn if their bitcoin config doesn't have walletbroadcast=0.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rustyrussell committed Jan 21, 2016
1 parent c51a8d8 commit 34e3297
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions daemon/bitcoind.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <ccan/io/io.h>
#include <ccan/pipecmd/pipecmd.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/tal.h>
#include <errno.h>
Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions daemon/bitcoind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
3 changes: 3 additions & 0 deletions daemon/lightningd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "bitcoind.h"
#include "configdir.h"
#include "jsonrpc.h"
#include "lightningd.h"
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 34e3297

Please sign in to comment.