Browse Source

lightningd: bitcoind and topology routines take channel, not peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
0e93fb932a
  1. 1
      lightningd/bitcoind.h
  2. 38
      lightningd/chaintopology.c
  3. 10
      lightningd/chaintopology.h
  4. 184
      lightningd/peer_control.c
  5. 2
      lightningd/test/run-find_my_path.c
  6. 32
      lightningd/watch.c
  7. 44
      lightningd/watch.h
  8. 18
      wallet/test/run-wallet.c

1
lightningd/bitcoind.h

@ -16,7 +16,6 @@ struct block;
struct lightningd; struct lightningd;
struct ripemd160; struct ripemd160;
struct bitcoin_tx; struct bitcoin_tx;
struct peer;
struct bitcoin_block; struct bitcoin_block;
enum bitcoind_mode { enum bitcoind_mode {

38
lightningd/chaintopology.c

@ -210,52 +210,52 @@ static void destroy_outgoing_tx(struct outgoing_tx *otx)
list_del(&otx->list); list_del(&otx->list);
} }
static void clear_otx_peer(struct peer *peer, struct outgoing_tx *otx) static void clear_otx_channel(struct channel *channel, struct outgoing_tx *otx)
{ {
if (otx->peer != peer) if (otx->channel != channel)
fatal("peer %p, otx %p has peer %p", peer, otx, otx->peer); fatal("channel %p, otx %p has channel %p", channel, otx, otx->channel);
otx->peer = NULL; otx->channel = NULL;
} }
static void broadcast_done(struct bitcoind *bitcoind, static void broadcast_done(struct bitcoind *bitcoind,
int exitstatus, const char *msg, int exitstatus, const char *msg,
struct outgoing_tx *otx) struct outgoing_tx *otx)
{ {
/* Peer gone? Stop. */ /* Channel gone? Stop. */
if (!otx->peer) { if (!otx->channel) {
tal_free(otx); tal_free(otx);
return; return;
} }
/* No longer needs to be disconnected if peer dies. */ /* No longer needs to be disconnected if channel dies. */
tal_del_destructor2(otx->peer, clear_otx_peer, otx); tal_del_destructor2(otx->channel, clear_otx_channel, otx);
if (otx->failed && exitstatus != 0) { if (otx->failed && exitstatus != 0) {
otx->failed(otx->peer, exitstatus, msg); otx->failed(otx->channel, exitstatus, msg);
tal_free(otx); tal_free(otx);
} else { } else {
/* For continual rebroadcasting, until peer freed. */ /* For continual rebroadcasting, until channel freed. */
tal_steal(otx->peer, otx); tal_steal(otx->channel, otx);
list_add_tail(&bitcoind->ld->topology->outgoing_txs, &otx->list); list_add_tail(&bitcoind->ld->topology->outgoing_txs, &otx->list);
tal_add_destructor(otx, destroy_outgoing_tx); tal_add_destructor(otx, destroy_outgoing_tx);
} }
} }
void broadcast_tx(struct chain_topology *topo, void broadcast_tx(struct chain_topology *topo,
struct peer *peer, const struct bitcoin_tx *tx, struct channel *channel, const struct bitcoin_tx *tx,
void (*failed)(struct peer *peer, void (*failed)(struct channel *channel,
int exitstatus, const char *err)) int exitstatus, const char *err))
{ {
/* Peer might vanish: topo owns it to start with. */ /* Channel might vanish: topo owns it to start with. */
struct outgoing_tx *otx = tal(topo, struct outgoing_tx); struct outgoing_tx *otx = tal(topo, struct outgoing_tx);
const u8 *rawtx = linearize_tx(otx, tx); const u8 *rawtx = linearize_tx(otx, tx);
otx->peer = peer; otx->channel = channel;
bitcoin_txid(tx, &otx->txid); bitcoin_txid(tx, &otx->txid);
otx->hextx = tal_hex(otx, rawtx); otx->hextx = tal_hex(otx, rawtx);
otx->failed = failed; otx->failed = failed;
tal_free(rawtx); tal_free(rawtx);
tal_add_destructor2(peer, clear_otx_peer, otx); tal_add_destructor2(channel, clear_otx_channel, otx);
log_add(topo->log, " (tx %s)", log_add(topo->log, " (tx %s)",
type_to_string(ltmp, struct bitcoin_txid, &otx->txid)); type_to_string(ltmp, struct bitcoin_txid, &otx->txid));
@ -679,7 +679,7 @@ void chaintopology_mark_pointers_used(struct htable *memtable,
} }
#endif /* DEVELOPER */ #endif /* DEVELOPER */
/* On shutdown, peers get deleted last. That frees from our list, so /* On shutdown, channels get deleted last. That frees from our list, so
* do it now instead. */ * do it now instead. */
static void destroy_outgoing_txs(struct chain_topology *topo) static void destroy_outgoing_txs(struct chain_topology *topo)
{ {
@ -710,14 +710,14 @@ struct chain_topology *new_topology(struct lightningd *ld, struct log *log)
void setup_topology(struct chain_topology *topo, void setup_topology(struct chain_topology *topo,
struct timers *timers, struct timers *timers,
struct timerel poll_time, u32 first_peer_block) struct timerel poll_time, u32 first_channel_block)
{ {
memset(&topo->feerate, 0, sizeof(topo->feerate)); memset(&topo->feerate, 0, sizeof(topo->feerate));
topo->timers = timers; topo->timers = timers;
topo->poll_time = poll_time; topo->poll_time = poll_time;
/* Start one before the block we are interested in (as we won't /* Start one before the block we are interested in (as we won't
* get notifications on txs in that block). */ * get notifications on txs in that block). */
topo->first_blocknum = first_peer_block - 1; topo->first_blocknum = first_channel_block - 1;
/* Make sure bitcoind is started, and ready */ /* Make sure bitcoind is started, and ready */
wait_for_bitcoind(topo->bitcoind); wait_for_bitcoind(topo->bitcoind);

10
lightningd/chaintopology.h

@ -28,10 +28,10 @@ enum feerate {
/* Off topology->outgoing_txs */ /* Off topology->outgoing_txs */
struct outgoing_tx { struct outgoing_tx {
struct list_node list; struct list_node list;
struct peer *peer; struct channel *channel;
const char *hextx; const char *hextx;
struct bitcoin_txid txid; struct bitcoin_txid txid;
void (*failed)(struct peer *peer, int exitstatus, const char *err); void (*failed)(struct channel *channel, int exitstatus, const char *err);
}; };
struct block { struct block {
@ -145,15 +145,15 @@ u32 get_feerate(const struct chain_topology *topo, enum feerate feerate);
/* Broadcast a single tx, and rebroadcast as reqd (copies tx). /* Broadcast a single tx, and rebroadcast as reqd (copies tx).
* If failed is non-NULL, call that and don't rebroadcast. */ * If failed is non-NULL, call that and don't rebroadcast. */
void broadcast_tx(struct chain_topology *topo, void broadcast_tx(struct chain_topology *topo,
struct peer *peer, const struct bitcoin_tx *tx, struct channel *channel, const struct bitcoin_tx *tx,
void (*failed)(struct peer *peer, void (*failed)(struct channel *channel,
int exitstatus, int exitstatus,
const char *err)); const char *err));
struct chain_topology *new_topology(struct lightningd *ld, struct log *log); struct chain_topology *new_topology(struct lightningd *ld, struct log *log);
void setup_topology(struct chain_topology *topology, void setup_topology(struct chain_topology *topology,
struct timers *timers, struct timers *timers,
struct timerel poll_time, u32 first_peer_block); struct timerel poll_time, u32 first_channel_block);
void begin_topology(struct chain_topology *topo); void begin_topology(struct chain_topology *topo);

184
lightningd/peer_control.c

@ -69,7 +69,7 @@ static void peer_offer_channel(struct lightningd *ld,
u64 gossip_index, u64 gossip_index,
const u8 *gfeatures, const u8 *lfeatures, const u8 *gfeatures, const u8 *lfeatures,
int peer_fd, int gossip_fd); int peer_fd, int gossip_fd);
static bool peer_start_channeld(struct peer *peer, static bool peer_start_channeld(struct channel *channel,
const struct crypto_state *cs, const struct crypto_state *cs,
u64 gossip_index, u64 gossip_index,
int peer_fd, int gossip_fd, int peer_fd, int gossip_fd,
@ -187,7 +187,7 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel)
/* Keep broadcasting until we say stop (can fail due to dup, /* Keep broadcasting until we say stop (can fail due to dup,
* if they beat us to the broadcast). */ * if they beat us to the broadcast). */
broadcast_tx(ld->topology, channel2peer(channel), channel->last_tx, NULL); broadcast_tx(ld->topology, channel, channel->last_tx, NULL);
remove_sig(channel->last_tx); remove_sig(channel->last_tx);
} }
@ -379,7 +379,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
peer_set_owner(peer, NULL); peer_set_owner(peer, NULL);
peer->addr = addr; peer->addr = addr;
peer_start_channeld(peer, &cs, gossip_index, peer_start_channeld(channel, &cs, gossip_index,
peer_fd, gossip_fd, NULL, peer_fd, gossip_fd, NULL,
true); true);
goto connected; goto connected;
@ -816,28 +816,26 @@ struct funding_channel {
struct peer *peer; struct peer *peer;
}; };
static void funding_broadcast_failed(struct peer *peer, static void funding_broadcast_failed(struct channel *channel,
int exitstatus, const char *err) int exitstatus, const char *err)
{ {
channel_internal_error(peer2channel(peer), channel_internal_error(channel,
"Funding broadcast exited with %i: %s", "Funding broadcast exited with %i: %s",
exitstatus, err); exitstatus, err);
} }
static enum watch_result funding_announce_cb(struct peer *peer, static enum watch_result funding_announce_cb(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
unsigned int depth, unsigned int depth,
void *unused) void *unused)
{ {
struct channel *channel = peer2channel(peer);
if (depth < ANNOUNCE_MIN_DEPTH) { if (depth < ANNOUNCE_MIN_DEPTH) {
return KEEP_WATCHING; return KEEP_WATCHING;
} }
if (!channel->owner || !streq(channel->owner->name, "lightning_channeld")) { if (!channel->owner || !streq(channel->owner->name, "lightning_channeld")) {
log_debug(peer->log, log_debug(channel->log,
"Funding tx announce ready, but peer state %s" "Funding tx announce ready, but channel state %s"
" owned by %s", " owned by %s",
channel_state_name(channel), channel_state_name(channel),
channel->owner ? channel->owner->name : "none"); channel->owner ? channel->owner->name : "none");
@ -845,7 +843,7 @@ static enum watch_result funding_announce_cb(struct peer *peer,
} }
subd_send_msg(channel->owner, subd_send_msg(channel->owner,
take(towire_channel_funding_announce_depth(peer))); take(towire_channel_funding_announce_depth(channel)));
return DELETE_WATCH; return DELETE_WATCH;
} }
@ -907,7 +905,7 @@ static void handle_onchain_init_reply(struct channel *channel, const u8 *msg)
onchaind_tell_fulfill(channel); onchaind_tell_fulfill(channel);
} }
static enum watch_result onchain_tx_watched(struct peer *peer, static enum watch_result onchain_tx_watched(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
unsigned int depth, unsigned int depth,
void *unused) void *unused)
@ -916,8 +914,8 @@ static enum watch_result onchain_tx_watched(struct peer *peer,
struct bitcoin_txid txid; struct bitcoin_txid txid;
if (depth == 0) { if (depth == 0) {
log_unusual(peer->log, "Chain reorganization!"); log_unusual(channel->log, "Chain reorganization!");
peer_set_owner(peer, NULL); channel_set_owner(channel, NULL);
/* FIXME! /* FIXME!
topology_rescan(peer->ld->topology, peer->funding_txid); topology_rescan(peer->ld->topology, peer->funding_txid);
@ -928,15 +926,15 @@ static enum watch_result onchain_tx_watched(struct peer *peer,
} }
bitcoin_txid(tx, &txid); bitcoin_txid(tx, &txid);
msg = towire_onchain_depth(peer, &txid, depth); msg = towire_onchain_depth(channel, &txid, depth);
subd_send_msg(peer2channel(peer)->owner, take(msg)); subd_send_msg(channel->owner, take(msg));
return KEEP_WATCHING; return KEEP_WATCHING;
} }
static void watch_tx_and_outputs(struct peer *peer, static void watch_tx_and_outputs(struct channel *channel,
const struct bitcoin_tx *tx); const struct bitcoin_tx *tx);
static enum watch_result onchain_txo_watched(struct peer *peer, static enum watch_result onchain_txo_watched(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
size_t input_num, size_t input_num,
const struct block *block, const struct block *block,
@ -944,10 +942,10 @@ static enum watch_result onchain_txo_watched(struct peer *peer,
{ {
u8 *msg; u8 *msg;
watch_tx_and_outputs(peer, tx); watch_tx_and_outputs(channel, tx);
msg = towire_onchain_spent(peer, tx, input_num, block->height); msg = towire_onchain_spent(channel, tx, input_num, block->height);
subd_send_msg(peer2channel(peer)->owner, take(msg)); subd_send_msg(channel->owner, take(msg));
/* We don't need to keep watching: If this output is double-spent /* We don't need to keep watching: If this output is double-spent
* (reorg), we'll get a zero depth cb to onchain_tx_watched, and * (reorg), we'll get a zero depth cb to onchain_tx_watched, and
@ -956,21 +954,21 @@ static enum watch_result onchain_txo_watched(struct peer *peer,
} }
/* To avoid races, we watch the tx and all outputs. */ /* To avoid races, we watch the tx and all outputs. */
static void watch_tx_and_outputs(struct peer *peer, static void watch_tx_and_outputs(struct channel *channel,
const struct bitcoin_tx *tx) const struct bitcoin_tx *tx)
{ {
struct bitcoin_txid txid; struct bitcoin_txid txid;
struct txwatch *txw; struct txwatch *txw;
struct channel *channel = peer2channel(peer); struct lightningd *ld = channel->peer->ld;
bitcoin_txid(tx, &txid); bitcoin_txid(tx, &txid);
/* Make txwatch a parent of txo watches, so we can unwatch together. */ /* Make txwatch a parent of txo watches, so we can unwatch together. */
txw = watch_tx(channel->owner, peer->ld->topology, peer, tx, txw = watch_tx(channel->owner, ld->topology, channel, tx,
onchain_tx_watched, NULL); onchain_tx_watched, NULL);
for (size_t i = 0; i < tal_count(tx->output); i++) for (size_t i = 0; i < tal_count(tx->output); i++)
watch_txo(txw, peer->ld->topology, peer, &txid, i, watch_txo(txw, ld->topology, channel, &txid, i,
onchain_txo_watched, NULL); onchain_txo_watched, NULL);
} }
@ -984,7 +982,7 @@ static void handle_onchain_broadcast_tx(struct channel *channel, const u8 *msg)
} }
/* We don't really care if it fails, we'll respond via watch. */ /* We don't really care if it fails, we'll respond via watch. */
broadcast_tx(channel->peer->ld->topology, channel2peer(channel), tx, NULL); broadcast_tx(channel->peer->ld->topology, channel, tx, NULL);
} }
static void handle_onchain_unwatch_tx(struct channel *channel, const u8 *msg) static void handle_onchain_unwatch_tx(struct channel *channel, const u8 *msg)
@ -998,7 +996,7 @@ static void handle_onchain_unwatch_tx(struct channel *channel, const u8 *msg)
} }
/* Frees the txo watches, too: see watch_tx_and_outputs() */ /* Frees the txo watches, too: see watch_tx_and_outputs() */
txw = find_txwatch(channel->peer->ld->topology, &txid, channel2peer(channel)); txw = find_txwatch(channel->peer->ld->topology, &txid, channel);
if (!txw) if (!txw)
log_unusual(channel->log, "Can't unwatch txid %s", log_unusual(channel->log, "Can't unwatch txid %s",
type_to_string(ltmp, struct bitcoin_txid, &txid)); type_to_string(ltmp, struct bitcoin_txid, &txid));
@ -1219,7 +1217,7 @@ static bool tell_if_missing(const struct channel *channel,
/* With a reorg, this can get called multiple times; each time we'll kill /* With a reorg, this can get called multiple times; each time we'll kill
* onchaind (like any other owner), and restart */ * onchaind (like any other owner), and restart */
static enum watch_result funding_spent(struct peer *peer, static enum watch_result funding_spent(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
size_t input_num, size_t input_num,
const struct block *block, const struct block *block,
@ -1230,8 +1228,7 @@ static enum watch_result funding_spent(struct peer *peer,
s64 keyindex; s64 keyindex;
struct pubkey ourkey; struct pubkey ourkey;
struct htlc_stub *stubs; struct htlc_stub *stubs;
const tal_t *tmpctx = tal_tmpctx(peer); const tal_t *tmpctx = tal_tmpctx(channel);
struct channel *channel = peer2channel(peer);
struct lightningd *ld = channel->peer->ld; struct lightningd *ld = channel->peer->ld;
channel_fail_permanent(channel, "Funding transaction spent"); channel_fail_permanent(channel, "Funding transaction spent");
@ -1333,14 +1330,14 @@ static enum watch_result funding_spent(struct peer *peer,
subd_send_msg(channel->owner, take(msg)); subd_send_msg(channel->owner, take(msg));
} }
watch_tx_and_outputs(peer, tx); watch_tx_and_outputs(channel, tx);
tal_free(tmpctx); tal_free(tmpctx);
/* We keep watching until peer finally deleted, for reorgs. */ /* We keep watching until peer finally deleted, for reorgs. */
return KEEP_WATCHING; return KEEP_WATCHING;
} }
static enum watch_result funding_lockin_cb(struct peer *peer, static enum watch_result funding_lockin_cb(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
unsigned int depth, unsigned int depth,
void *unused) void *unused)
@ -1349,18 +1346,18 @@ static enum watch_result funding_lockin_cb(struct peer *peer,
const char *txidstr; const char *txidstr;
struct txlocator *loc; struct txlocator *loc;
bool channel_ready; bool channel_ready;
struct channel *channel = peer2channel(peer); struct lightningd *ld = channel->peer->ld;
bitcoin_txid(tx, &txid); bitcoin_txid(tx, &txid);
txidstr = type_to_string(peer, struct bitcoin_txid, &txid); txidstr = type_to_string(channel, struct bitcoin_txid, &txid);
log_debug(peer->log, "Funding tx %s depth %u of %u", log_debug(channel->log, "Funding tx %s depth %u of %u",
txidstr, depth, channel->minimum_depth); txidstr, depth, channel->minimum_depth);
tal_free(txidstr); tal_free(txidstr);
if (depth < channel->minimum_depth) if (depth < channel->minimum_depth)
return KEEP_WATCHING; return KEEP_WATCHING;
loc = locate_tx(peer, peer->ld->topology, &txid); loc = locate_tx(channel, ld->topology, &txid);
/* If we restart, we could already have peer->scid from database */ /* If we restart, we could already have peer->scid from database */
if (!channel->scid) { if (!channel->scid) {
@ -1376,7 +1373,7 @@ static enum watch_result funding_lockin_cb(struct peer *peer,
channel_ready = (channel->owner && channel->state == CHANNELD_AWAITING_LOCKIN); channel_ready = (channel->owner && channel->state == CHANNELD_AWAITING_LOCKIN);
if (!channel_ready) { if (!channel_ready) {
log_debug(channel->log, log_debug(channel->log,
"Funding tx confirmed, but peer state %s %s", "Funding tx confirmed, but channel state %s %s",
channel_state_name(channel), channel_state_name(channel),
channel->owner ? channel->owner->name : "unowned"); channel->owner ? channel->owner->name : "unowned");
} else { } else {
@ -1400,9 +1397,9 @@ static enum watch_result funding_lockin_cb(struct peer *peer,
* before. If we are at the right depth, call the callback * before. If we are at the right depth, call the callback
* directly, otherwise schedule a callback */ * directly, otherwise schedule a callback */
if (depth >= ANNOUNCE_MIN_DEPTH) if (depth >= ANNOUNCE_MIN_DEPTH)
funding_announce_cb(peer, tx, depth, NULL); funding_announce_cb(channel, tx, depth, NULL);
else else
watch_txid(peer, peer->ld->topology, peer, &txid, watch_txid(channel, ld->topology, channel, &txid,
funding_announce_cb, NULL); funding_announce_cb, NULL);
return DELETE_WATCH; return DELETE_WATCH;
} }
@ -1418,21 +1415,21 @@ static void opening_got_hsm_funding_sig(struct funding_channel *fc,
u64 change_satoshi; u64 change_satoshi;
struct json_result *response = new_json_result(fc->cmd); struct json_result *response = new_json_result(fc->cmd);
struct channel *channel = peer2channel(fc->peer); struct channel *channel = peer2channel(fc->peer);
struct lightningd *ld = channel->peer->ld;
if (!fromwire_hsm_sign_funding_reply(fc, resp, NULL, &tx)) if (!fromwire_hsm_sign_funding_reply(fc, resp, NULL, &tx))
fatal("HSM gave bad sign_funding_reply %s", fatal("HSM gave bad sign_funding_reply %s",
tal_hex(fc, resp)); tal_hex(fc, resp));
/* Send it out and watch for confirms. */ /* Send it out and watch for confirms. */
broadcast_tx(fc->peer->ld->topology, fc->peer, tx, funding_broadcast_failed); broadcast_tx(ld->topology, channel, tx, funding_broadcast_failed);
watch_tx(fc->peer, fc->peer->ld->topology, fc->peer, tx, watch_tx(channel, ld->topology, channel, tx, funding_lockin_cb, NULL);
funding_lockin_cb, NULL);
/* Extract the change output and add it to the DB */ /* Extract the change output and add it to the DB */
wallet_extract_owned_outputs(fc->peer->ld->wallet, tx, &change_satoshi); wallet_extract_owned_outputs(ld->wallet, tx, &change_satoshi);
/* FIXME: Remove arg from cb? */ /* FIXME: Remove arg from cb? */
watch_txo(fc->peer, fc->peer->ld->topology, fc->peer, watch_txo(channel, ld->topology, channel,
channel->funding_txid, channel->funding_outnum, channel->funding_txid, channel->funding_outnum,
funding_spent, NULL); funding_spent, NULL);
@ -1445,7 +1442,7 @@ static void opening_got_hsm_funding_sig(struct funding_channel *fc,
channel->opening_cmd = NULL; channel->opening_cmd = NULL;
/* Start normal channel daemon. */ /* Start normal channel daemon. */
peer_start_channeld(fc->peer, cs, gossip_index, peer_start_channeld(channel, cs, gossip_index,
peer_fd, gossip_fd, NULL, false); peer_fd, gossip_fd, NULL, false);
peer_set_condition(fc->peer, OPENINGD, CHANNELD_AWAITING_LOCKIN); peer_set_condition(fc->peer, OPENINGD, CHANNELD_AWAITING_LOCKIN);
@ -1561,12 +1558,6 @@ static void peer_got_shutdown(struct channel *channel, const u8 *msg)
wallet_channel_save(ld->wallet, channel); wallet_channel_save(ld->wallet, channel);
} }
static void peer_last_tx(struct peer *peer, struct bitcoin_tx *tx,
const secp256k1_ecdsa_signature *sig)
{
channel_set_last_tx(peer2channel(peer), tx, sig);
}
/* Is this better than the last tx we were holding? This can happen /* Is this better than the last tx we were holding? This can happen
* even without closingd misbehaving, if we have multiple, * even without closingd misbehaving, if we have multiple,
* interrupted, rounds of negotiation. */ * interrupted, rounds of negotiation. */
@ -1636,7 +1627,7 @@ static void peer_received_closing_signature(struct channel *channel,
/* FIXME: Make sure signature is correct! */ /* FIXME: Make sure signature is correct! */
if (better_closing_fee(ld, channel, tx)) { if (better_closing_fee(ld, channel, tx)) {
peer_last_tx(channel2peer(channel), tx, &sig); channel_set_last_tx(channel, tx, &sig);
/* TODO(cdecker) Selectively save updated fields to DB */ /* TODO(cdecker) Selectively save updated fields to DB */
wallet_channel_save(ld->wallet, channel); wallet_channel_save(ld->wallet, channel);
} }
@ -1891,17 +1882,16 @@ u32 feerate_max(struct lightningd *ld)
return get_feerate(ld->topology, FEERATE_IMMEDIATE) * 5; return get_feerate(ld->topology, FEERATE_IMMEDIATE) * 5;
} }
static bool peer_start_channeld(struct peer *peer, static bool peer_start_channeld(struct channel *channel,
const struct crypto_state *cs, const struct crypto_state *cs,
u64 gossip_index, u64 gossip_index,
int peer_fd, int gossip_fd, int peer_fd, int gossip_fd,
const u8 *funding_signed, const u8 *funding_signed,
bool reconnected) bool reconnected)
{ {
const tal_t *tmpctx = tal_tmpctx(peer); const tal_t *tmpctx = tal_tmpctx(channel);
u8 *msg, *initmsg; u8 *msg, *initmsg;
int hsmfd; int hsmfd;
const struct config *cfg = &peer->ld->config;
struct added_htlc *htlcs; struct added_htlc *htlcs;
enum htlc_state *htlc_states; enum htlc_state *htlc_states;
struct fulfilled_htlc *fulfilled_htlcs; struct fulfilled_htlc *fulfilled_htlcs;
@ -1911,8 +1901,8 @@ static bool peer_start_channeld(struct peer *peer,
struct short_channel_id funding_channel_id; struct short_channel_id funding_channel_id;
const u8 *shutdown_scriptpubkey; const u8 *shutdown_scriptpubkey;
u64 num_revocations; u64 num_revocations;
struct channel *channel = peer2channel(peer);
struct lightningd *ld = channel->peer->ld; struct lightningd *ld = channel->peer->ld;
const struct config *cfg = &ld->config;
/* Now we can consider balance set. */ /* Now we can consider balance set. */
if (!reconnected) { if (!reconnected) {
@ -1926,15 +1916,15 @@ static bool peer_start_channeld(struct peer *peer,
} else } else
assert(channel->our_msatoshi); assert(channel->our_msatoshi);
msg = towire_hsm_client_hsmfd(tmpctx, &peer->id, HSM_CAP_SIGN_GOSSIP | HSM_CAP_ECDH); msg = towire_hsm_client_hsmfd(tmpctx, &channel->peer->id, HSM_CAP_SIGN_GOSSIP | HSM_CAP_ECDH);
if (!wire_sync_write(peer->ld->hsm_fd, take(msg))) if (!wire_sync_write(ld->hsm_fd, take(msg)))
fatal("Could not write to HSM: %s", strerror(errno)); fatal("Could not write to HSM: %s", strerror(errno));
msg = hsm_sync_read(tmpctx, peer->ld); msg = hsm_sync_read(tmpctx, ld);
if (!fromwire_hsm_client_hsmfd_reply(msg, NULL)) if (!fromwire_hsm_client_hsmfd_reply(msg, NULL))
fatal("Bad reply from HSM: %s", tal_hex(tmpctx, msg)); fatal("Bad reply from HSM: %s", tal_hex(tmpctx, msg));
hsmfd = fdpass_recv(peer->ld->hsm_fd); hsmfd = fdpass_recv(ld->hsm_fd);
if (hsmfd < 0) if (hsmfd < 0)
fatal("Could not read fd from HSM: %s", strerror(errno)); fatal("Could not read fd from HSM: %s", strerror(errno));
@ -1947,7 +1937,7 @@ static bool peer_start_channeld(struct peer *peer,
take(&hsmfd), NULL)); take(&hsmfd), NULL));
if (!channel->owner) { if (!channel->owner) {
log_unusual(peer->log, "Could not subdaemon channel: %s", log_unusual(channel->log, "Could not subdaemon channel: %s",
strerror(errno)); strerror(errno));
channel_fail_transient(channel, "Failed to subdaemon channel"); channel_fail_transient(channel, "Failed to subdaemon channel");
tal_free(tmpctx); tal_free(tmpctx);
@ -1959,15 +1949,15 @@ static bool peer_start_channeld(struct peer *peer,
if (channel->scid) { if (channel->scid) {
funding_channel_id = *channel->scid; funding_channel_id = *channel->scid;
log_debug(peer->log, "Already have funding locked in"); log_debug(channel->log, "Already have funding locked in");
} else { } else {
log_debug(peer->log, "Waiting for funding confirmations"); log_debug(channel->log, "Waiting for funding confirmations");
memset(&funding_channel_id, 0, sizeof(funding_channel_id)); memset(&funding_channel_id, 0, sizeof(funding_channel_id));
} }
if (channel->local_shutdown_idx != -1) { if (channel->local_shutdown_idx != -1) {
shutdown_scriptpubkey shutdown_scriptpubkey
= p2wpkh_for_keyidx(tmpctx, peer->ld, = p2wpkh_for_keyidx(tmpctx, ld,
channel->local_shutdown_idx); channel->local_shutdown_idx);
} else } else
shutdown_scriptpubkey = NULL; shutdown_scriptpubkey = NULL;
@ -1975,20 +1965,19 @@ static bool peer_start_channeld(struct peer *peer,
num_revocations = revocations_received(&channel->their_shachain.chain); num_revocations = revocations_received(&channel->their_shachain.chain);
/* Warn once. */ /* Warn once. */
if (peer->ld->config.ignore_fee_limits) if (ld->config.ignore_fee_limits)
log_debug(peer->log, "Ignoring fee limits!"); log_debug(channel->log, "Ignoring fee limits!");
initmsg = towire_channel_init(tmpctx, initmsg = towire_channel_init(tmpctx,
&get_chainparams(peer->ld) &get_chainparams(ld)->genesis_blockhash,
->genesis_blockhash,
channel->funding_txid, channel->funding_txid,
channel->funding_outnum, channel->funding_outnum,
channel->funding_satoshi, channel->funding_satoshi,
&channel->our_config, &channel->our_config,
&channel->channel_info->their_config, &channel->channel_info->their_config,
channel->channel_info->feerate_per_kw, channel->channel_info->feerate_per_kw,
feerate_min(peer->ld), feerate_min(ld),
feerate_max(peer->ld), feerate_max(ld),
channel->last_sig, channel->last_sig,
cs, gossip_index, cs, gossip_index,
&channel->channel_info->remote_fundingkey, &channel->channel_info->remote_fundingkey,
@ -2003,8 +1992,8 @@ static bool peer_start_channeld(struct peer *peer,
cfg->fee_per_satoshi, cfg->fee_per_satoshi,
*channel->our_msatoshi, *channel->our_msatoshi,
&channel->seed, &channel->seed,
&peer->ld->id, &ld->id,
&peer->id, &channel->peer->id,
time_to_msec(cfg->commit_time), time_to_msec(cfg->commit_time),
cfg->cltv_expiry_delta, cfg->cltv_expiry_delta,
channel->last_was_revoke, channel->last_was_revoke,
@ -2032,11 +2021,9 @@ static bool peer_start_channeld(struct peer *peer,
return true; return true;
} }
static bool peer_commit_initial(struct peer *peer) static void channel_commit_initial(struct channel *channel)
{ {
struct channel *channel = peer2channel(peer);
channel->next_index[LOCAL] = channel->next_index[REMOTE] = 1; channel->next_index[LOCAL] = channel->next_index[REMOTE] = 1;
return true;
} }
static void opening_funder_finished(struct subd *opening, const u8 *resp, static void opening_funder_finished(struct subd *opening, const u8 *resp,
@ -2092,7 +2079,7 @@ static void opening_funder_finished(struct subd *opening, const u8 *resp,
channel_info->old_remote_per_commit = channel_info->remote_per_commit; channel_info->old_remote_per_commit = channel_info->remote_per_commit;
/* Now, keep the initial commit as our last-tx-to-broadcast. */ /* Now, keep the initial commit as our last-tx-to-broadcast. */
peer_last_tx(fc->peer, remote_commit, &remote_commit_sig); channel_set_last_tx(channel, remote_commit, &remote_commit_sig);
/* Generate the funding tx. */ /* Generate the funding tx. */
if (fc->change if (fc->change
@ -2139,13 +2126,10 @@ static void opening_funder_finished(struct subd *opening, const u8 *resp,
return; return;
} }
if (!peer_commit_initial(fc->peer)) { channel_commit_initial(channel);
channel_internal_error(channel, "Initial peer to db failed");
return;
}
/* Get HSM to sign the funding tx. */ /* Get HSM to sign the funding tx. */
log_debug(fc->peer->log, "Getting HSM to sign funding tx"); log_debug(channel->log, "Getting HSM to sign funding tx");
msg = towire_hsm_sign_funding(tmpctx, channel->funding_satoshi, msg = towire_hsm_sign_funding(tmpctx, channel->funding_satoshi,
fc->change, fc->change_keyindex, fc->change, fc->change_keyindex,
@ -2167,7 +2151,7 @@ static void opening_funder_finished(struct subd *opening, const u8 *resp,
static void opening_fundee_finished(struct subd *opening, static void opening_fundee_finished(struct subd *opening,
const u8 *reply, const u8 *reply,
const int *fds, const int *fds,
struct peer *peer) struct channel *channel)
{ {
u8 *funding_signed; u8 *funding_signed;
struct channel_info *channel_info; struct channel_info *channel_info;
@ -2175,14 +2159,14 @@ static void opening_fundee_finished(struct subd *opening,
u64 gossip_index; u64 gossip_index;
secp256k1_ecdsa_signature remote_commit_sig; secp256k1_ecdsa_signature remote_commit_sig;
struct bitcoin_tx *remote_commit; struct bitcoin_tx *remote_commit;
const tal_t *tmpctx = tal_tmpctx(peer); const tal_t *tmpctx = tal_tmpctx(channel);
struct channel *channel = peer2channel(peer); struct lightningd *ld = channel->peer->ld;
log_debug(peer->log, "Got opening_fundee_finish_response"); log_debug(channel->log, "Got opening_fundee_finish_response");
assert(tal_count(fds) == 2); assert(tal_count(fds) == 2);
/* At this point, we care about peer */ /* At this point, we care about peer */
channel->channel_info = channel_info = tal(peer, struct channel_info); channel->channel_info = channel_info = tal(channel, struct channel_info);
/* This is a new channel_info->their_config, set its ID to 0 */ /* This is a new channel_info->their_config, set its ID to 0 */
channel->channel_info->their_config.id = 0; channel->channel_info->their_config.id = 0;
@ -2220,30 +2204,27 @@ static void opening_fundee_finished(struct subd *opening,
channel_info->old_remote_per_commit = channel_info->remote_per_commit; channel_info->old_remote_per_commit = channel_info->remote_per_commit;
/* Now, keep the initial commit as our last-tx-to-broadcast. */ /* Now, keep the initial commit as our last-tx-to-broadcast. */
peer_last_tx(peer, remote_commit, &remote_commit_sig); channel_set_last_tx(channel, remote_commit, &remote_commit_sig);
if (!peer_commit_initial(peer)) { channel_commit_initial(channel);
tal_free(tmpctx);
return;
}
log_debug(peer->log, "Watching funding tx %s", log_debug(channel->log, "Watching funding tx %s",
type_to_string(reply, struct bitcoin_txid, type_to_string(reply, struct bitcoin_txid,
channel->funding_txid)); channel->funding_txid));
watch_txid(peer, peer->ld->topology, peer, channel->funding_txid, watch_txid(channel, ld->topology, channel, channel->funding_txid,
funding_lockin_cb, NULL); funding_lockin_cb, NULL);
/* FIXME: Remove arg from cb? */ /* FIXME: Remove arg from cb? */
watch_txo(peer, peer->ld->topology, peer, channel->funding_txid, watch_txo(channel, ld->topology, channel, channel->funding_txid,
channel->funding_outnum, funding_spent, NULL); channel->funding_outnum, funding_spent, NULL);
/* Unowned (will free openingd). */ /* Unowned (will free openingd). */
peer_set_owner(peer, NULL); channel_set_owner(channel, NULL);
/* On to normal operation! */ /* On to normal operation! */
peer_start_channeld(peer, &cs, gossip_index, peer_start_channeld(channel, &cs, gossip_index,
fds[0], fds[1], funding_signed, false); fds[0], fds[1], funding_signed, false);
peer_set_condition(peer, OPENINGD, CHANNELD_AWAITING_LOCKIN); channel_set_state(channel, OPENINGD, CHANNELD_AWAITING_LOCKIN);
tal_free(tmpctx); tal_free(tmpctx);
} }
@ -2363,8 +2344,8 @@ static void peer_accept_channel(struct lightningd *ld,
* 5, * 5,
open_msg); open_msg);
subd_req(peer, channel->owner, take(msg), -1, 2, subd_req(channel, channel->owner, take(msg), -1, 2,
opening_fundee_finished, peer); opening_fundee_finished, channel);
} }
static void peer_offer_channel(struct lightningd *ld, static void peer_offer_channel(struct lightningd *ld,
@ -2639,6 +2620,7 @@ static void activate_peer(struct peer *peer)
{ {
u8 *msg; u8 *msg;
struct channel *channel = peer2channel(peer); struct channel *channel = peer2channel(peer);
struct lightningd *ld = channel->peer->ld;
/* Pass gossipd any addrhints we currently have */ /* Pass gossipd any addrhints we currently have */
msg = towire_gossipctl_peer_addrhint(peer, &peer->id, &peer->addr); msg = towire_gossipctl_peer_addrhint(peer, &peer->id, &peer->addr);
@ -2652,10 +2634,10 @@ static void activate_peer(struct peer *peer)
} }
/* This may be unnecessary, but it's harmless. */ /* This may be unnecessary, but it's harmless. */
watch_txid(peer, peer->ld->topology, peer, channel->funding_txid, watch_txid(channel, ld->topology, channel, channel->funding_txid,
funding_lockin_cb, NULL); funding_lockin_cb, NULL);
watch_txo(peer, peer->ld->topology, peer, watch_txo(channel, ld->topology, channel,
channel->funding_txid, channel->funding_outnum, channel->funding_txid, channel->funding_outnum,
funding_spent, NULL); funding_spent, NULL);

2
lightningd/test/run-find_my_path.c

@ -70,7 +70,7 @@ void setup_jsonrpc(struct lightningd *ld UNNEEDED, const char *rpc_filename UNNE
/* Generated stub for setup_topology */ /* Generated stub for setup_topology */
void setup_topology(struct chain_topology *topology UNNEEDED, void setup_topology(struct chain_topology *topology UNNEEDED,
struct timers *timers UNNEEDED, struct timers *timers UNNEEDED,
struct timerel poll_time UNNEEDED, u32 first_peer_block UNNEEDED) struct timerel poll_time UNNEEDED, u32 first_channel_block UNNEEDED)
{ fprintf(stderr, "setup_topology called!\n"); abort(); } { fprintf(stderr, "setup_topology called!\n"); abort(); }
/* Generated stub for subd_shutdown */ /* Generated stub for subd_shutdown */
void subd_shutdown(struct subd *subd UNNEEDED, unsigned int seconds UNNEEDED) void subd_shutdown(struct subd *subd UNNEEDED, unsigned int seconds UNNEEDED)

32
lightningd/watch.c

@ -88,9 +88,9 @@ static void destroy_txwatch(struct txwatch *w)
struct txwatch *watch_txid_(const tal_t *ctx, struct txwatch *watch_txid_(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct peer *peer, struct channel *channel,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
enum watch_result (*cb)(struct peer *peer, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *, const struct bitcoin_tx *,
unsigned int depth, unsigned int depth,
void *arg), void *arg),
@ -102,7 +102,7 @@ struct txwatch *watch_txid_(const tal_t *ctx,
w->topo = topo; w->topo = topo;
w->depth = 0; w->depth = 0;
w->txid = *txid; w->txid = *txid;
w->peer = peer; w->channel = channel;
w->cb = cb; w->cb = cb;
w->cbdata = cb_arg; w->cbdata = cb_arg;
@ -114,17 +114,17 @@ struct txwatch *watch_txid_(const tal_t *ctx,
struct txwatch *find_txwatch(struct chain_topology *topo, struct txwatch *find_txwatch(struct chain_topology *topo,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
const struct peer *peer) const struct channel *channel)
{ {
struct txwatch_hash_iter i; struct txwatch_hash_iter i;
struct txwatch *w; struct txwatch *w;
/* We could have more than one peer watching same txid, though we /* We could have more than one channel watching same txid, though we
* don't for onchaind. */ * don't for onchaind. */
for (w = txwatch_hash_getfirst(&topo->txwatches, txid, &i); for (w = txwatch_hash_getfirst(&topo->txwatches, txid, &i);
w; w;
w = txwatch_hash_getnext(&topo->txwatches, txid, &i)) { w = txwatch_hash_getnext(&topo->txwatches, txid, &i)) {
if (w->peer == peer) if (w->channel == channel)
break; break;
} }
return w; return w;
@ -138,9 +138,9 @@ bool watching_txid(const struct chain_topology *topo,
struct txwatch *watch_tx_(const tal_t *ctx, struct txwatch *watch_tx_(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct peer *peer, struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
enum watch_result (*cb)(struct peer *peer, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *, const struct bitcoin_tx *,
unsigned int depth, unsigned int depth,
void *arg), void *arg),
@ -149,15 +149,15 @@ struct txwatch *watch_tx_(const tal_t *ctx,
struct bitcoin_txid txid; struct bitcoin_txid txid;
bitcoin_txid(tx, &txid); bitcoin_txid(tx, &txid);
return watch_txid(ctx, topo, peer, &txid, cb, cb_arg); return watch_txid(ctx, topo, channel, &txid, cb, cb_arg);
} }
struct txowatch *watch_txo_(const tal_t *ctx, struct txowatch *watch_txo_(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct peer *peer, struct channel *channel,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
unsigned int output, unsigned int output,
enum watch_result (*cb)(struct peer *peer, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
size_t input_num, size_t input_num,
const struct block *block, const struct block *block,
@ -169,7 +169,7 @@ struct txowatch *watch_txo_(const tal_t *ctx,
w->topo = topo; w->topo = topo;
w->out.txid = *txid; w->out.txid = *txid;
w->out.index = output; w->out.index = output;
w->peer = peer; w->channel = channel;
w->cb = cb; w->cb = cb;
w->cbdata = cbdata; w->cbdata = cbdata;
@ -189,12 +189,12 @@ static bool txw_fire(struct chain_topology *topo,
if (depth == txw->depth) if (depth == txw->depth)
return false; return false;
log_debug(txw->peer->log, log_debug(txw->channel->log,
"Got depth change %u->%u for %s", "Got depth change %u->%u for %s",
txw->depth, depth, txw->depth, depth,
type_to_string(ltmp, struct bitcoin_txid, &txw->txid)); type_to_string(ltmp, struct bitcoin_txid, &txw->txid));
txw->depth = depth; txw->depth = depth;
r = txw->cb(txw->peer, tx, txw->depth, txw->cbdata); r = txw->cb(txw->channel, tx, txw->depth, txw->cbdata);
switch (r) { switch (r) {
case DELETE_WATCH: case DELETE_WATCH:
tal_free(txw); tal_free(txw);
@ -229,13 +229,13 @@ void txowatch_fire(struct chain_topology *topo,
enum watch_result r; enum watch_result r;
bitcoin_txid(tx, &txid); bitcoin_txid(tx, &txid);
log_debug(txow->peer->log, log_debug(txow->channel->log,
"Got UTXO spend for %s:%u: %s", "Got UTXO spend for %s:%u: %s",
type_to_string(ltmp, struct bitcoin_txid, &txow->out.txid), type_to_string(ltmp, struct bitcoin_txid, &txow->out.txid),
txow->out.index, txow->out.index,
type_to_string(ltmp, struct bitcoin_txid, &txid)); type_to_string(ltmp, struct bitcoin_txid, &txid));
r = txow->cb(txow->peer, tx, input_num, block, txow->cbdata); r = txow->cb(txow->channel, tx, input_num, block, txow->cbdata);
switch (r) { switch (r) {
case DELETE_WATCH: case DELETE_WATCH:
tal_free(txow); tal_free(txow);

44
lightningd/watch.h

@ -25,14 +25,14 @@ struct txwatch_output {
struct txowatch { struct txowatch {
struct chain_topology *topo; struct chain_topology *topo;
/* Peer who owns us. */ /* Channel who owns us. */
struct peer *peer; struct channel *channel;
/* Output to watch. */ /* Output to watch. */
struct txwatch_output out; struct txwatch_output out;
/* A new tx. */ /* A new tx. */
enum watch_result (*cb)(struct peer *peer, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
size_t input_num, size_t input_num,
const struct block *block, const struct block *block,
@ -51,15 +51,15 @@ HTABLE_DEFINE_TYPE(struct txowatch, txowatch_keyof, txo_hash, txowatch_eq,
struct txwatch { struct txwatch {
struct chain_topology *topo; struct chain_topology *topo;
/* Peer who owns us. */ /* Channel who owns us. */
struct peer *peer; struct channel *channel;
/* Transaction to watch. */ /* Transaction to watch. */
struct bitcoin_txid txid; struct bitcoin_txid txid;
unsigned int depth; unsigned int depth;
/* A new depth (0 if kicked out, otherwise 1 = tip, etc.) */ /* A new depth (0 if kicked out, otherwise 1 = tip, etc.) */
enum watch_result (*cb)(struct peer *peer, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
unsigned int depth, unsigned int depth,
void *cbdata); void *cbdata);
@ -76,59 +76,59 @@ HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq,
struct txwatch *watch_txid_(const tal_t *ctx, struct txwatch *watch_txid_(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct peer *peer, struct channel *channel,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
enum watch_result (*cb)(struct peer *peer, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *, const struct bitcoin_tx *,
unsigned int depth, unsigned int depth,
void *), void *),
void *cbdata); void *cbdata);
#define watch_txid(ctx, topo, peer_, txid, cb, cbdata) \ #define watch_txid(ctx, topo, channel_, txid, cb, cbdata) \
watch_txid_((ctx), (topo), (peer_), (txid), \ watch_txid_((ctx), (topo), (channel_), (txid), \
typesafe_cb_preargs(enum watch_result, void *, \ typesafe_cb_preargs(enum watch_result, void *, \
(cb), (cbdata), \ (cb), (cbdata), \
struct peer *, \ struct channel *, \
const struct bitcoin_tx *, \ const struct bitcoin_tx *, \
unsigned int depth), \ unsigned int depth), \
(cbdata)) (cbdata))
struct txwatch *watch_tx_(const tal_t *ctx, struct txwatch *watch_tx_(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct peer *peer, struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
enum watch_result (*cb)(struct peer *peer, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *, const struct bitcoin_tx *,
unsigned int depth, unsigned int depth,
void *), void *),
void *cbdata); void *cbdata);
#define watch_tx(ctx, topo, peer_, tx, cb, cbdata) \ #define watch_tx(ctx, topo, channel_, tx, cb, cbdata) \
watch_tx_((ctx), (topo), (peer_), (tx), \ watch_tx_((ctx), (topo), (channel_), (tx), \
typesafe_cb_preargs(enum watch_result, void *, \ typesafe_cb_preargs(enum watch_result, void *, \
(cb), (cbdata), \ (cb), (cbdata), \
struct peer *, \ struct channel *, \
const struct bitcoin_tx *, \ const struct bitcoin_tx *, \
unsigned int depth), \ unsigned int depth), \
(cbdata)) (cbdata))
struct txowatch *watch_txo_(const tal_t *ctx, struct txowatch *watch_txo_(const tal_t *ctx,
struct chain_topology *topo, struct chain_topology *topo,
struct peer *peer, struct channel *channel,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
unsigned int output, unsigned int output,
enum watch_result (*cb)(struct peer *peer, enum watch_result (*cb)(struct channel *channel,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
size_t input_num, size_t input_num,
const struct block *block, const struct block *block,
void *), void *),
void *cbdata); void *cbdata);
#define watch_txo(ctx, topo, peer_, txid, outnum, cb, cbdata) \ #define watch_txo(ctx, topo, channel_, txid, outnum, cb, cbdata) \
watch_txo_((ctx), (topo), (peer_), (txid), (outnum), \ watch_txo_((ctx), (topo), (channel_), (txid), (outnum), \
typesafe_cb_preargs(enum watch_result, void *, \ typesafe_cb_preargs(enum watch_result, void *, \
(cb), (cbdata), \ (cb), (cbdata), \
struct peer *, \ struct channel *, \
const struct bitcoin_tx *, \ const struct bitcoin_tx *, \
size_t, \ size_t, \
const struct block *block), \ const struct block *block), \
@ -136,7 +136,7 @@ struct txowatch *watch_txo_(const tal_t *ctx,
struct txwatch *find_txwatch(struct chain_topology *topo, struct txwatch *find_txwatch(struct chain_topology *topo,
const struct bitcoin_txid *txid, const struct bitcoin_txid *txid,
const struct peer *peer); const struct channel *channel);
void txwatch_fire(struct chain_topology *topo, void txwatch_fire(struct chain_topology *topo,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,

18
wallet/test/run-wallet.c

@ -42,8 +42,8 @@ void bitcoind_gettxout(struct bitcoind *bitcoind UNNEEDED,
{ fprintf(stderr, "bitcoind_gettxout called!\n"); abort(); } { fprintf(stderr, "bitcoind_gettxout called!\n"); abort(); }
/* Generated stub for broadcast_tx */ /* Generated stub for broadcast_tx */
void broadcast_tx(struct chain_topology *topo UNNEEDED, void broadcast_tx(struct chain_topology *topo UNNEEDED,
struct peer *peer UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, struct channel *channel UNNEEDED, const struct bitcoin_tx *tx UNNEEDED,
void (*failed)(struct peer *peer UNNEEDED, void (*failed)(struct channel *channel UNNEEDED,
int exitstatus UNNEEDED, int exitstatus UNNEEDED,
const char *err)) const char *err))
{ fprintf(stderr, "broadcast_tx called!\n"); abort(); } { fprintf(stderr, "broadcast_tx called!\n"); abort(); }
@ -86,7 +86,7 @@ struct htlc_out *find_htlc_out_by_ripemd(const struct channel *channel UNNEEDED,
/* Generated stub for find_txwatch */ /* Generated stub for find_txwatch */
struct txwatch *find_txwatch(struct chain_topology *topo UNNEEDED, struct txwatch *find_txwatch(struct chain_topology *topo UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED, const struct bitcoin_txid *txid UNNEEDED,
const struct peer *peer UNNEEDED) const struct channel *channel UNNEEDED)
{ fprintf(stderr, "find_txwatch called!\n"); abort(); } { fprintf(stderr, "find_txwatch called!\n"); abort(); }
/* Generated stub for fromwire_channel_got_funding_locked */ /* Generated stub for fromwire_channel_got_funding_locked */
bool fromwire_channel_got_funding_locked(const void *p UNNEEDED, size_t *plen UNNEEDED, struct pubkey *next_per_commit_point UNNEEDED) bool fromwire_channel_got_funding_locked(const void *p UNNEEDED, size_t *plen UNNEEDED, struct pubkey *next_per_commit_point UNNEEDED)
@ -481,9 +481,9 @@ void update_per_commit_point(struct channel *channel UNNEEDED,
/* Generated stub for watch_tx_ */ /* Generated stub for watch_tx_ */
struct txwatch *watch_tx_(const tal_t *ctx UNNEEDED, struct txwatch *watch_tx_(const tal_t *ctx UNNEEDED,
struct chain_topology *topo UNNEEDED, struct chain_topology *topo UNNEEDED,
struct peer *peer UNNEEDED, struct channel *channel UNNEEDED,
const struct bitcoin_tx *tx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED,
enum watch_result (*cb)(struct peer *peer UNNEEDED, enum watch_result (*cb)(struct channel *channel UNNEEDED,
const struct bitcoin_tx * UNNEEDED, const struct bitcoin_tx * UNNEEDED,
unsigned int depth UNNEEDED, unsigned int depth UNNEEDED,
void *) UNNEEDED, void *) UNNEEDED,
@ -492,9 +492,9 @@ struct txwatch *watch_tx_(const tal_t *ctx UNNEEDED,
/* Generated stub for watch_txid_ */ /* Generated stub for watch_txid_ */
struct txwatch *watch_txid_(const tal_t *ctx UNNEEDED, struct txwatch *watch_txid_(const tal_t *ctx UNNEEDED,
struct chain_topology *topo UNNEEDED, struct chain_topology *topo UNNEEDED,
struct peer *peer UNNEEDED, struct channel *channel UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED, const struct bitcoin_txid *txid UNNEEDED,
enum watch_result (*cb)(struct peer *peer UNNEEDED, enum watch_result (*cb)(struct channel *channel UNNEEDED,
const struct bitcoin_tx * UNNEEDED, const struct bitcoin_tx * UNNEEDED,
unsigned int depth UNNEEDED, unsigned int depth UNNEEDED,
void *) UNNEEDED, void *) UNNEEDED,
@ -503,10 +503,10 @@ struct txwatch *watch_txid_(const tal_t *ctx UNNEEDED,
/* Generated stub for watch_txo_ */ /* Generated stub for watch_txo_ */
struct txowatch *watch_txo_(const tal_t *ctx UNNEEDED, struct txowatch *watch_txo_(const tal_t *ctx UNNEEDED,
struct chain_topology *topo UNNEEDED, struct chain_topology *topo UNNEEDED,
struct peer *peer UNNEEDED, struct channel *channel UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED, const struct bitcoin_txid *txid UNNEEDED,
unsigned int output UNNEEDED, unsigned int output UNNEEDED,
enum watch_result (*cb)(struct peer *peer UNNEEDED, enum watch_result (*cb)(struct channel *channel UNNEEDED,
const struct bitcoin_tx *tx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED,
size_t input_num UNNEEDED, size_t input_num UNNEEDED,
const struct block *block UNNEEDED, const struct block *block UNNEEDED,

Loading…
Cancel
Save