opts: Remove --regtest flag and pass chainparams to bitcoind

This commit is contained in:
Christian Decker 2017-07-10 10:59:15 +02:00 committed by Rusty Russell
parent cf16b5faea
commit 843e21826a
7 changed files with 14 additions and 28 deletions

View File

@ -30,18 +30,9 @@ static char **gather_args(struct bitcoind *bitcoind,
size_t n = 0;
char **args = tal_arr(ctx, char *, 3);
args[n++] = BITCOIN_CLI;
switch (bitcoind->testmode) {
case BITCOIND_REGTEST:
args[n++] = "-regtest=1";
break;
case BITCOIND_TESTNET:
args[n++] = "-testnet=1";
break;
case BITCOIND_MAINNET:
args[n++] = "-testnet=0";
break;
}
args[n++] = bitcoind->chainparams->cli;
args[n++] = bitcoind->chainparams->cli_args;
if (bitcoind->datadir) {
args[n++] = tal_fmt(args, "-datadir=%s", bitcoind->datadir);
tal_resize(&args, n + 1);
@ -458,7 +449,8 @@ struct bitcoind *new_bitcoind(const tal_t *ctx, struct log *log)
{
struct bitcoind *bitcoind = tal(ctx, struct bitcoind);
bitcoind->testmode = BITCOIND_TESTNET;
/* Use testnet by default, change later if we want another network */
bitcoind->chainparams = chainparams_for_network("testnet");
bitcoind->datadir = NULL;
bitcoind->log = log;
bitcoind->req_running = false;

View File

@ -1,6 +1,7 @@
#ifndef LIGHTNING_DAEMON_BITCOIND_H
#define LIGHTNING_DAEMON_BITCOIND_H
#include "config.h"
#include <bitcoin/chainparams.h>
#include <ccan/list/list.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
@ -21,9 +22,6 @@ enum bitcoind_mode {
};
struct bitcoind {
/* What mode are we in. */
enum bitcoind_mode testmode;
/* -datadir arg for bitcoin-cli. */
char *datadir;
@ -35,6 +33,9 @@ struct bitcoind {
/* Pending requests. */
struct list_head pending;
/* What network are we on? */
const struct chainparams *chainparams;
};
struct bitcoind *new_bitcoind(const tal_t *ctx, struct log *log);

View File

@ -13,6 +13,7 @@
#include "secrets.h"
#include "timeout.h"
#include "utils.h"
#include <bitcoin/chainparams.h>
#include <ccan/container_of/container_of.h>
#include <ccan/err/err.h>
#include <ccan/io/io.h>
@ -82,6 +83,7 @@ int main(int argc, char *argv[])
dstate->topology = new_topology(dstate, dstate->base_log);
dstate->bitcoind = new_bitcoind(dstate, dstate->base_log);
dstate->bitcoind->chainparams = chainparams_for_network("regtest");
/* Handle options and config; move to .lightningd */
register_opts(dstate);

View File

@ -153,25 +153,18 @@ static void opt_show_u16(char buf[OPT_SHOW_LEN], const u16 *u)
snprintf(buf, OPT_SHOW_LEN, "%u", *u);
}
static char *opt_set_regtest(struct bitcoind *bitcoind)
{
bitcoind->testmode = BITCOIND_REGTEST;
return NULL;
}
static char *opt_set_network(const char *arg, struct lightningd *ld)
{
ld->chainparams = chainparams_for_network(arg);
if (!ld->chainparams)
return tal_fmt(NULL, "Unknown network name '%s'", arg);
ld->dstate.testnet = ld->chainparams->testnet;
ld->bitcoind->chainparams = ld->chainparams;
return NULL;
}
static void config_register_opts(struct lightningd_state *dstate)
{
opt_register_noarg("--bitcoind-regtest", opt_set_regtest,
dstate->bitcoind,
"Bitcoind is in regtest mode");
opt_register_arg("--locktime-blocks", opt_set_u32, opt_show_u32,
&dstate->config.locktime_blocks,
"Blocks before peer can unilaterally spend funds");

View File

@ -112,7 +112,6 @@ setup_lightning()
cat > $DIR1/config <<EOF
disable-irc
log-level=debug
bitcoind-regtest
bitcoind-poll=5s
deadline-blocks=5
min-htlc-expiry=6

View File

@ -130,7 +130,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->dstate.announce = NULL;
ld->topology = ld->dstate.topology = new_topology(ld, ld->log);
ld->bitcoind = ld->dstate.bitcoind = new_bitcoind(ld, ld->log);
ld->bitcoind->testmode = ld->dstate.testnet?BITCOIND_TESTNET:BITCOIND_MAINNET;
ld->chainparams = chainparams_for_network("testnet");
/* FIXME: Move into invoice daemon. */
ld->dstate.invoices = invoices_init(&ld->dstate);

View File

@ -214,7 +214,6 @@ class LightningD(TailableProc):
'--lightning-dir={}'.format(lightning_dir),
'--port={}'.format(port),
'--disable-irc',
'--bitcoind-regtest',
]
self.cmd_line += ["--{}={}".format(k, v) for k, v in LIGHTNINGD_CONFIG.items()]