mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-06 15:44:21 +01:00
watchtower: Call the commitment_revoked hook every time we update
Changelog-Added: plugin: Added a new `commitment_revocation` hook that provides the plugin with penalty transactions for all revoked transactions.
This commit is contained in:
committed by
Rusty Russell
parent
38bad4cb39
commit
d1f8509060
@@ -1971,6 +1971,41 @@ void update_per_commit_point(struct channel *channel,
|
||||
ci->remote_per_commit = *per_commitment_point;
|
||||
}
|
||||
|
||||
struct commitment_revocation_payload {
|
||||
struct bitcoin_txid commitment_txid;
|
||||
const struct bitcoin_tx *penalty_tx;
|
||||
struct wallet *wallet;
|
||||
u64 channel_id;
|
||||
u64 commitnum;
|
||||
};
|
||||
|
||||
static void commitment_revocation_hook_serialize(
|
||||
struct commitment_revocation_payload *payload, struct json_stream *stream)
|
||||
{
|
||||
json_add_txid(stream, "commitment_txid", &payload->commitment_txid);
|
||||
json_add_tx(stream, "penalty_tx", payload->penalty_tx);
|
||||
}
|
||||
|
||||
static void
|
||||
commitment_revocation_hook_cb(struct commitment_revocation_payload *p STEALS){
|
||||
wallet_penalty_base_delete(p->wallet, p->channel_id, p->commitnum);
|
||||
}
|
||||
|
||||
static bool
|
||||
commitment_revocation_hook_deserialize(struct commitment_revocation_payload *p,
|
||||
const char *buffer,
|
||||
const jsmntok_t *toks)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
REGISTER_PLUGIN_HOOK(commitment_revocation,
|
||||
commitment_revocation_hook_deserialize,
|
||||
commitment_revocation_hook_cb,
|
||||
commitment_revocation_hook_serialize,
|
||||
struct commitment_revocation_payload *);
|
||||
|
||||
void peer_got_revoke(struct channel *channel, const u8 *msg)
|
||||
{
|
||||
u64 revokenum;
|
||||
@@ -1983,13 +2018,16 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
struct fee_states *fee_states;
|
||||
struct penalty_base *pbase;
|
||||
struct commitment_revocation_payload *payload;
|
||||
struct bitcoin_tx *penalty_tx;
|
||||
|
||||
if (!fromwire_channel_got_revoke(msg, msg,
|
||||
&revokenum, &per_commitment_secret,
|
||||
&next_per_commitment_point,
|
||||
&fee_states,
|
||||
&changed,
|
||||
&pbase)
|
||||
&pbase,
|
||||
&penalty_tx)
|
||||
|| !fee_states_valid(fee_states, channel->opener)) {
|
||||
channel_internal_error(channel, "bad fromwire_channel_got_revoke %s",
|
||||
tal_hex(channel, msg));
|
||||
@@ -2082,6 +2120,17 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
|
||||
: fromwire_peektype(failmsgs[i]));
|
||||
}
|
||||
wallet_channel_save(ld->wallet, channel);
|
||||
|
||||
if (penalty_tx == NULL)
|
||||
return;
|
||||
|
||||
payload = tal(tmpctx, struct commitment_revocation_payload);
|
||||
payload->commitment_txid = pbase->txid;
|
||||
payload->penalty_tx = tal_steal(payload, penalty_tx);
|
||||
payload->wallet = ld->wallet;
|
||||
payload->channel_id = channel->dbid;
|
||||
payload->commitnum = pbase->commitment_num;
|
||||
plugin_hook_call_commitment_revocation(ld, payload);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user