From 5519717144809ac7e82482dcfa15b35ac9591273 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 22 Mar 2018 00:18:53 +0100 Subject: [PATCH] onchaind: Pass the funding spend height through when adding a UTXO This is necessary since we have onchaind tell us about the their_unilateral/to_us output, after it is already in a block. Signed-off-by: Christian Decker --- lightningd/onchain_control.c | 5 +++-- onchaind/onchain.c | 3 ++- onchaind/onchain_wire.csv | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 720e7008d..64f5270a6 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -220,6 +220,7 @@ static void handle_irrevocably_resolved(struct channel *channel, const u8 *msg) static void onchain_add_utxo(struct channel *channel, const u8 *msg) { struct utxo *u = tal(msg, struct utxo); + u32 blockheight; u->close_info = tal(u, struct unilateral_close_info); u->is_p2sh = true; @@ -227,14 +228,14 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg) u->status = output_state_available; u->close_info->channel_id = channel->dbid; u->close_info->peer_id = channel->peer->id; - u->blockheight = NULL; u->spendheight = NULL; if (!fromwire_onchain_add_utxo(msg, &u->txid, &u->outnum, &u->close_info->commitment_point, - &u->amount)) { + &u->amount, &blockheight)) { fatal("onchaind gave invalid add_utxo message: %s", tal_hex(msg, msg)); } + u->blockheight = blockheight>0?&blockheight:NULL; outpointfilter_add(channel->peer->ld->wallet->owned_outpoints, &u->txid, u->outnum); wallet_add_utxo(channel->peer->ld->wallet, u, p2wpkh); diff --git a/onchaind/onchain.c b/onchaind/onchain.c index b7f446de5..b27649f24 100644 --- a/onchaind/onchain.c +++ b/onchaind/onchain.c @@ -2039,7 +2039,8 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx, wire_sync_write(REQ_FD, towire_onchain_add_utxo( tmpctx, txid, i, remote_per_commitment_point, - tx->output[i].amount)); + tx->output[i].amount, + tx_blockheight)); continue; } if (script[REMOTE] diff --git a/onchaind/onchain_wire.csv b/onchaind/onchain_wire.csv index 91a962d1f..688d09f2b 100644 --- a/onchaind/onchain_wire.csv +++ b/onchaind/onchain_wire.csv @@ -87,3 +87,4 @@ onchain_add_utxo,,prev_out_tx,struct bitcoin_txid onchain_add_utxo,,prev_out_index,u32 onchain_add_utxo,,per_commit_point,struct pubkey onchain_add_utxo,,value,u64 +onchain_add_utxo,,blockheight,u32