channel: Along with the last_tx also remember its type

This takes the guesswork out of `drop_to_chain` and allows us to annotate the
last_tx consistently.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2019-05-28 18:06:39 +02:00 committed by Rusty Russell
parent ad4b9204ab
commit 4c57d44252
4 changed files with 9 additions and 5 deletions

View file

@ -233,6 +233,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->msat_to_us_min = msat_to_us_min;
channel->msat_to_us_max = msat_to_us_max;
channel->last_tx = tal_steal(channel, last_tx);
channel->last_tx_type = TX_UNKNOWN;
channel->last_sig = *last_sig;
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
channel->channel_info = *channel_info;
@ -331,11 +332,13 @@ struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid)
void channel_set_last_tx(struct channel *channel,
struct bitcoin_tx *tx,
const struct bitcoin_signature *sig)
const struct bitcoin_signature *sig,
txtypes txtypes)
{
channel->last_sig = *sig;
tal_free(channel->last_tx);
channel->last_tx = tal_steal(channel, tx);
channel->last_tx_type = txtypes;
}
void channel_set_state(struct channel *channel,

View file

@ -76,6 +76,7 @@ struct channel {
/* Last tx they gave us. */
struct bitcoin_tx *last_tx;
txtypes last_tx_type;
struct bitcoin_signature last_sig;
secp256k1_ecdsa_signature *last_htlc_sigs;
@ -201,7 +202,8 @@ struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid);
void channel_set_last_tx(struct channel *channel,
struct bitcoin_tx *tx,
const struct bitcoin_signature *sig);
const struct bitcoin_signature *sig,
txtypes type);
static inline bool channel_can_add_htlc(const struct channel *channel)
{

View file

@ -95,8 +95,7 @@ static void peer_received_closing_signature(struct channel *channel,
/* FIXME: Make sure signature is correct! */
if (better_closing_fee(ld, channel, tx)) {
channel_set_last_tx(channel, tx, &sig);
/* TODO(cdecker) Selectively save updated fields to DB */
channel_set_last_tx(channel, tx, &sig, TX_CHANNEL_CLOSE);
wallet_channel_save(ld->wallet, channel);
}

View file

@ -1240,7 +1240,7 @@ static bool peer_save_commitsig_received(struct channel *channel, u64 commitnum,
channel->next_index[LOCAL]++;
/* Update channel->last_sig and channel->last_tx before saving to db */
channel_set_last_tx(channel, tx, commit_sig);
channel_set_last_tx(channel, tx, commit_sig, TX_CHANNEL_UNILATERAL);
return true;
}