Browse Source

channeld: Pass back the penalty_base when reporting a revocation

nifty/pset-pre
Christian Decker 5 years ago
committed by Rusty Russell
parent
commit
38bad4cb39
  1. 1
      channeld/channel_wire.csv
  2. 28
      channeld/channeld.c
  3. 4
      lightningd/peer_htlcs.c
  4. 2
      wallet/test/run-wallet.c

1
channeld/channel_wire.csv

@ -153,6 +153,7 @@ msgdata,channel_got_revoke,next_per_commit_point,pubkey,
msgdata,channel_got_revoke,fee_states,fee_states,
msgdata,channel_got_revoke,num_changed,u16,
msgdata,channel_got_revoke,changed,changed_htlc,num_changed
msgdata,channel_got_revoke,pbase,?penalty_base,
# Wait for reply, to make sure it's on disk before we continue
# (eg. if we sent another commitment_signed, that would implicitly ack).
msgtype,channel_got_revoke_reply,1122

Can't render this file because it has a wrong number of fields in line 9.

28
channeld/channeld.c

@ -1368,13 +1368,31 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
&commit_sig, htlc_sigs, changed_htlcs, txs[0]);
}
static u8 *got_revoke_msg(const tal_t *ctx, u64 revoke_num,
/* Pops the penalty base for the given commitnum from our internal list. There
* may not be one, in which case we return NULL and leave the list
* unmodified. */
static struct penalty_base *
penalty_base_by_commitnum(const tal_t *ctx, struct peer *peer, u64 commitnum)
{
struct penalty_base *res = NULL;
for (size_t i = 0; i < tal_count(peer->pbases); i++) {
if (peer->pbases[i]->commitment_num == commitnum) {
res = tal_steal(ctx, peer->pbases[i]);
tal_arr_remove(&peer->pbases, i);
break;
}
}
return res;
}
static u8 *got_revoke_msg(struct peer *peer, u64 revoke_num,
const struct secret *per_commitment_secret,
const struct pubkey *next_per_commit_point,
const struct htlc **changed_htlcs,
const struct fee_states *fee_states)
{
u8 *msg;
struct penalty_base *pbase;
struct changed_htlc *changed = tal_arr(tmpctx, struct changed_htlc, 0);
for (size_t i = 0; i < tal_count(changed_htlcs); i++) {
@ -1390,8 +1408,10 @@ static u8 *got_revoke_msg(const tal_t *ctx, u64 revoke_num,
tal_arr_expand(&changed, c);
}
msg = towire_channel_got_revoke(ctx, revoke_num, per_commitment_secret,
next_per_commit_point, fee_states, changed);
pbase = penalty_base_by_commitnum(tmpctx, peer, revoke_num);
msg = towire_channel_got_revoke(peer, revoke_num, per_commitment_secret,
next_per_commit_point, fee_states,
changed, pbase);
return msg;
}
@ -1448,7 +1468,7 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
status_debug("No commits outstanding after recv revoke_and_ack");
/* Tell master about things this locks in, wait for response */
msg = got_revoke_msg(NULL, peer->revocations_received++,
msg = got_revoke_msg(peer, peer->revocations_received++,
&old_commit_secret, &next_per_commit,
changed_htlcs,
peer->channel->fee_states);

4
lightningd/peer_htlcs.c

@ -1982,12 +1982,14 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
size_t i;
struct lightningd *ld = channel->peer->ld;
struct fee_states *fee_states;
struct penalty_base *pbase;
if (!fromwire_channel_got_revoke(msg, msg,
&revokenum, &per_commitment_secret,
&next_per_commitment_point,
&fee_states,
&changed)
&changed,
&pbase)
|| !fee_states_valid(fee_states, channel->opener)) {
channel_internal_error(channel, "bad fromwire_channel_got_revoke %s",
tal_hex(channel, msg));

2
wallet/test/run-wallet.c

@ -116,7 +116,7 @@ bool fromwire_channel_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEE
bool fromwire_channel_got_commitsig(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *commitnum UNNEEDED, struct fee_states **fee_states UNNEEDED, struct bitcoin_signature *signature UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, struct added_htlc **added UNNEEDED, struct fulfilled_htlc **fulfilled UNNEEDED, struct failed_htlc ***failed UNNEEDED, struct changed_htlc **changed UNNEEDED, struct bitcoin_tx **tx UNNEEDED)
{ fprintf(stderr, "fromwire_channel_got_commitsig called!\n"); abort(); }
/* Generated stub for fromwire_channel_got_revoke */
bool fromwire_channel_got_revoke(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *revokenum UNNEEDED, struct secret *per_commitment_secret UNNEEDED, struct pubkey *next_per_commit_point UNNEEDED, struct fee_states **fee_states UNNEEDED, struct changed_htlc **changed UNNEEDED)
bool fromwire_channel_got_revoke(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *revokenum UNNEEDED, struct secret *per_commitment_secret UNNEEDED, struct pubkey *next_per_commit_point UNNEEDED, struct fee_states **fee_states UNNEEDED, struct changed_htlc **changed UNNEEDED, struct penalty_base **pbase UNNEEDED)
{ fprintf(stderr, "fromwire_channel_got_revoke called!\n"); abort(); }
/* Generated stub for fromwire_channel_offer_htlc_reply */
bool fromwire_channel_offer_htlc_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *id UNNEEDED, u8 **failuremsg UNNEEDED, wirestring **failurestr UNNEEDED)

Loading…
Cancel
Save