Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add channel_id and commitnum to commitment_revocation hook #4760

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,9 @@ The payload consists of the following information:
```json
{
"commitment_txid": "58eea2cf538cfed79f4d6b809b920b40bb6b35962c4bb4cc81f5550a7728ab05",
"penalty_tx": "02000000000101...ac00000000"
"penalty_tx": "02000000000101...ac00000000",
"channel_id": "fb16398de93e8690c665873715ef590c038dfac5dd6c49a9d4b61dccfcedc2fb",
"commitnum": 21
}
```

Expand Down
10 changes: 7 additions & 3 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2048,8 +2048,9 @@ struct commitment_revocation_payload {
struct bitcoin_txid commitment_txid;
const struct bitcoin_tx *penalty_tx;
struct wallet *wallet;
u64 channel_id;
u64 channel_dbid;
u64 commitnum;
struct channel_id channel_id;
};

static void commitment_revocation_hook_serialize(
Expand All @@ -2058,11 +2059,13 @@ static void commitment_revocation_hook_serialize(
{
json_add_txid(stream, "commitment_txid", &payload->commitment_txid);
json_add_tx(stream, "penalty_tx", payload->penalty_tx);
json_add_channel_id(stream, "channel_id", &payload->channel_id);
json_add_u64(stream, "commitnum", payload->commitnum);
}

static void
commitment_revocation_hook_cb(struct commitment_revocation_payload *p STEALS){
wallet_penalty_base_delete(p->wallet, p->channel_id, p->commitnum);
wallet_penalty_base_delete(p->wallet, p->channel_dbid, p->commitnum);
}

static bool
Expand Down Expand Up @@ -2209,8 +2212,9 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
payload->commitment_txid = pbase->txid;
payload->penalty_tx = tal_steal(payload, penalty_tx);
payload->wallet = ld->wallet;
payload->channel_id = channel->dbid;
payload->channel_dbid = channel->dbid;
payload->commitnum = pbase->commitment_num;
payload->channel_id = channel->cid;
plugin_hook_call_commitment_revocation(ld, payload);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/watchtower.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


@plugin.hook('commitment_revocation')
def on_commitment_revocation(commitment_txid, penalty_tx, plugin, **kwargs):
def on_commitment_revocation(commitment_txid, penalty_tx, channel_id, commitnum, plugin, **kwargs):
with open('watchtower.csv', 'a') as f:
f.write("{}, {}\n".format(commitment_txid, penalty_tx))
f.write("{}, {}, {}, {}\n".format(commitment_txid, penalty_tx, channel_id, commitnum))


plugin.run()
7 changes: 6 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,7 @@ def test_watchtower(node_factory, bitcoind, directory, chainparams):
2,
opts=[{'may_fail': True, 'allow_broken_log': True}, {'plugin': p}]
)
channel_id = l1.rpc.listpeers()['peers'][0]['channels'][0]['channel_id']

# Force a new commitment
l1.rpc.pay(l2.rpc.invoice(25000000, 'lbl1', 'desc1')['bolt11'])
Expand All @@ -1821,8 +1822,12 @@ def test_watchtower(node_factory, bitcoind, directory, chainparams):
)

cheat_tx = bitcoind.rpc.decoderawtransaction(tx)
lastcommitnum = 0
for l in open(wt_file, 'r'):
txid, penalty = l.strip().split(', ')
txid, penalty, channel_id_hook, commitnum = l.strip().split(', ')
assert lastcommitnum == int(commitnum)
assert channel_id_hook == channel_id
lastcommitnum += 1
if txid == cheat_tx['txid']:
# This one should succeed, since it is a response to the cheat_tx
bitcoind.rpc.sendrawtransaction(penalty)
Expand Down