mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 20:09:18 +01:00
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:
parent
ad4b9204ab
commit
4c57d44252
4 changed files with 9 additions and 5 deletions
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue