core-lightning/daemon/bitcoind.h
Rusty Russell df4df8679d chaintopology: only report active chaintip.
getchaintips returns tips even if we don't have the body for them, so
we need to look for the active tip, not just the first (most-work) one.

Here's what happens in the log:

	+2849.963414597 lightningd(26779):BROKEN: bitcoin-cli getblock 0000000000000000018626ff7160bdf38a602e6650bd04ec258759ea578b106d false exited 91: 'error code: -32603
	error message:
	Can't read block from disk
	'

And here's an example problematic getchaintips output:

[
  {
    "height": 419635,
    "hash": "0000000000000000000fd32d87fce19efb7ccd07aa4ddaf1b94b9a219deec0f9",
    "branchlen": 1,
    "status": "headers-only"
  }, 
  {
    "height": 419634,
    "hash": "000000000000000002988d6512719697147cf252b2f64d247cf229266615d2bb",
    "branchlen": 0,
    "status": "active"
  }, 
  {
    "height": 416372,
    "hash": "0000000000000000004d0a54341c992ae174a91c8dd3981a9f2b3d3f6221ba59",
    "branchlen": 1,
    "status": "valid-headers"
  }, 
  {
    "height": 416231,
    "hash": "0000000000000000044d0d2c25f33cb48931540366149cde3fb0154f55b58c76",
    "branchlen": 1,
    "status": "headers-only"
  }
]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-07 13:36:39 +09:30

103 lines
3.1 KiB
C

#ifndef LIGHTNING_DAEMON_BITCOIND_H
#define LIGHTNING_DAEMON_BITCOIND_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/typesafe_cb/typesafe_cb.h>
#include <stdbool.h>
struct sha256_double;
struct lightningd_state;
struct ripemd160;
struct bitcoin_tx;
struct peer;
struct bitcoin_block;
/* -datadir arg for bitcoin-cli. */
extern char *bitcoin_datadir;
void bitcoind_estimate_fee_(struct lightningd_state *dstate,
void (*cb)(struct lightningd_state *dstate,
u64, void *),
void *arg);
#define bitcoind_estimate_fee(dstate, cb, arg) \
bitcoind_estimate_fee_((dstate), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct lightningd_state *, \
u64), \
(arg))
void bitcoind_sendrawtx_(struct lightningd_state *dstate,
const char *hextx,
void (*cb)(struct lightningd_state *dstate,
const char *msg, void *),
void *arg);
#define bitcoind_sendrawtx(dstate, hextx, cb, arg) \
bitcoind_sendrawtx_((dstate), (hextx), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct lightningd_state *, \
const char *), \
(arg))
void bitcoind_get_chaintip_(struct lightningd_state *dstate,
void (*cb)(struct lightningd_state *dstate,
const struct sha256_double *tipid,
void *arg),
void *arg);
#define bitcoind_get_chaintip(dstate, cb, arg) \
bitcoind_get_chaintip_((dstate), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct lightningd_state *, \
const struct sha256_double *), \
(arg))
void bitcoind_getblockcount_(struct lightningd_state *dstate,
void (*cb)(struct lightningd_state *dstate,
u32 blockcount,
void *arg),
void *arg);
#define bitcoind_getblockcount(dstate, cb, arg) \
bitcoind_getblockcount_((dstate), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct lightningd_state *, \
u32 blockcount), \
(arg))
void bitcoind_getblockhash_(struct lightningd_state *dstate,
u32 height,
void (*cb)(struct lightningd_state *dstate,
const struct sha256_double *blkid,
void *arg),
void *arg);
#define bitcoind_getblockhash(dstate, height, cb, arg) \
bitcoind_getblockhash_((dstate), \
(height), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct lightningd_state *, \
const struct sha256_double *), \
(arg))
void bitcoind_getrawblock_(struct lightningd_state *dstate,
const struct sha256_double *blockid,
void (*cb)(struct lightningd_state *dstate,
struct bitcoin_block *blk,
void *arg),
void *arg);
#define bitcoind_getrawblock(dstate, blkid, cb, arg) \
bitcoind_getrawblock_((dstate), (blkid), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct lightningd_state *, \
struct bitcoin_block *), \
(arg))
void check_bitcoind_config(struct lightningd_state *dstate);
#endif /* LIGHTNING_DAEMON_BITCOIND_H */