2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_BITCOIND_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_BITCOIND_H
|
2016-01-21 21:11:49 +01:00
|
|
|
#include "config.h"
|
2017-07-10 10:59:15 +02:00
|
|
|
#include <bitcoin/chainparams.h>
|
2017-03-02 13:21:49 +01:00
|
|
|
#include <ccan/list/list.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
#include <ccan/short_types/short_types.h>
|
2017-03-02 13:21:49 +01:00
|
|
|
#include <ccan/tal/tal.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
#include <ccan/typesafe_cb/typesafe_cb.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
#include <stdbool.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
|
|
|
|
struct sha256_double;
|
|
|
|
struct lightningd_state;
|
|
|
|
struct ripemd160;
|
|
|
|
struct bitcoin_tx;
|
2016-01-21 21:11:49 +01:00
|
|
|
struct peer;
|
2016-04-24 12:10:29 +02:00
|
|
|
struct bitcoin_block;
|
2016-01-21 21:11:49 +01:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
enum bitcoind_mode {
|
|
|
|
BITCOIND_MAINNET = 1,
|
|
|
|
BITCOIND_TESTNET,
|
|
|
|
BITCOIND_REGTEST
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bitcoind {
|
|
|
|
/* -datadir arg for bitcoin-cli. */
|
|
|
|
char *datadir;
|
|
|
|
|
|
|
|
/* Where to do logging. */
|
|
|
|
struct log *log;
|
|
|
|
|
|
|
|
/* Are we currently running a bitcoind request (it's ratelimited) */
|
|
|
|
bool req_running;
|
|
|
|
|
|
|
|
/* Pending requests. */
|
|
|
|
struct list_head pending;
|
2017-07-10 10:59:15 +02:00
|
|
|
|
|
|
|
/* What network are we on? */
|
|
|
|
const struct chainparams *chainparams;
|
2017-03-02 13:21:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bitcoind *new_bitcoind(const tal_t *ctx, struct log *log);
|
|
|
|
|
|
|
|
void bitcoind_estimate_fee_(struct bitcoind *bitcoind,
|
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
2016-04-12 05:37:03 +02:00
|
|
|
u64, void *),
|
|
|
|
void *arg);
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
#define bitcoind_estimate_fee(bitcoind_, cb, arg) \
|
|
|
|
bitcoind_estimate_fee_((bitcoind_), \
|
|
|
|
typesafe_cb_preargs(void, void *, \
|
2016-04-12 05:37:03 +02:00
|
|
|
(cb), (arg), \
|
2017-03-02 13:21:49 +01:00
|
|
|
struct bitcoind *, \
|
2016-04-12 05:37:03 +02:00
|
|
|
u64), \
|
|
|
|
(arg))
|
|
|
|
|
2017-06-20 15:34:43 +02:00
|
|
|
void bitcoind_sendrawtx_(struct bitcoind *bitcoind,
|
2016-05-04 08:33:10 +02:00
|
|
|
const char *hextx,
|
2017-03-02 13:21:49 +01:00
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
2016-11-07 13:30:02 +01:00
|
|
|
int exitstatus, const char *msg, void *),
|
2016-05-04 08:33:10 +02:00
|
|
|
void *arg);
|
|
|
|
|
2017-06-20 15:34:43 +02:00
|
|
|
#define bitcoind_sendrawtx(bitcoind_, hextx, cb, arg) \
|
|
|
|
bitcoind_sendrawtx_((bitcoind_), (hextx), \
|
2016-05-04 08:33:10 +02:00
|
|
|
typesafe_cb_preargs(void, void *, \
|
|
|
|
(cb), (arg), \
|
2017-03-02 13:21:49 +01:00
|
|
|
struct bitcoind *, \
|
2016-11-07 13:30:02 +01:00
|
|
|
int, const char *), \
|
2016-05-04 08:33:10 +02:00
|
|
|
(arg))
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
void bitcoind_get_chaintip_(struct bitcoind *bitcoind,
|
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
|
|
|
const struct sha256_double *tipid,
|
|
|
|
void *arg),
|
|
|
|
void *arg);
|
2016-04-24 12:06:13 +02:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
#define bitcoind_get_chaintip(bitcoind_, cb, arg) \
|
|
|
|
bitcoind_get_chaintip_((bitcoind_), \
|
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 06:06:39 +02:00
|
|
|
typesafe_cb_preargs(void, void *, \
|
|
|
|
(cb), (arg), \
|
2017-03-02 13:21:49 +01:00
|
|
|
struct bitcoind *, \
|
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 06:06:39 +02:00
|
|
|
const struct sha256_double *), \
|
|
|
|
(arg))
|
2016-04-24 12:06:13 +02:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
void bitcoind_getblockcount_(struct bitcoind *bitcoind,
|
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
2016-04-24 12:06:13 +02:00
|
|
|
u32 blockcount,
|
|
|
|
void *arg),
|
|
|
|
void *arg);
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
#define bitcoind_getblockcount(bitcoind_, cb, arg) \
|
|
|
|
bitcoind_getblockcount_((bitcoind_), \
|
2016-04-24 12:06:13 +02:00
|
|
|
typesafe_cb_preargs(void, void *, \
|
|
|
|
(cb), (arg), \
|
2017-03-02 13:21:49 +01:00
|
|
|
struct bitcoind *, \
|
2016-04-24 12:06:13 +02:00
|
|
|
u32 blockcount), \
|
|
|
|
(arg))
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
void bitcoind_getblockhash_(struct bitcoind *bitcoind,
|
2016-04-24 12:06:13 +02:00
|
|
|
u32 height,
|
2017-03-02 13:21:49 +01:00
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
2016-04-24 12:06:13 +02:00
|
|
|
const struct sha256_double *blkid,
|
|
|
|
void *arg),
|
|
|
|
void *arg);
|
2017-03-02 13:21:49 +01:00
|
|
|
#define bitcoind_getblockhash(bitcoind_, height, cb, arg) \
|
|
|
|
bitcoind_getblockhash_((bitcoind_), \
|
2016-04-24 12:06:13 +02:00
|
|
|
(height), \
|
|
|
|
typesafe_cb_preargs(void, void *, \
|
|
|
|
(cb), (arg), \
|
2017-03-02 13:21:49 +01:00
|
|
|
struct bitcoind *, \
|
2016-04-24 12:06:13 +02:00
|
|
|
const struct sha256_double *), \
|
|
|
|
(arg))
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
void bitcoind_getrawblock_(struct bitcoind *bitcoind,
|
2016-04-24 12:10:29 +02:00
|
|
|
const struct sha256_double *blockid,
|
2017-03-02 13:21:49 +01:00
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
2016-04-24 12:10:29 +02:00
|
|
|
struct bitcoin_block *blk,
|
|
|
|
void *arg),
|
|
|
|
void *arg);
|
2017-03-02 13:21:49 +01:00
|
|
|
#define bitcoind_getrawblock(bitcoind_, blkid, cb, arg) \
|
|
|
|
bitcoind_getrawblock_((bitcoind_), (blkid), \
|
2016-04-24 12:10:29 +02:00
|
|
|
typesafe_cb_preargs(void, void *, \
|
|
|
|
(cb), (arg), \
|
2017-03-02 13:21:49 +01:00
|
|
|
struct bitcoind *, \
|
2016-04-24 12:10:29 +02:00
|
|
|
struct bitcoin_block *), \
|
|
|
|
(arg))
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_BITCOIND_H */
|