mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
channeld: Track penalty_bases internally
`lightningd` passes in all the known penalty_bases when starting a new `channeld` instance, which tracks them internally, eventually matching them with revocations and passing them back to `lightningd` so it can create the penalty transaction. From here it is just a small step to having `channeld` also generate the penalty transaction if desired.
This commit is contained in:
parent
4af1db9ad5
commit
ce471eabe0
@ -65,6 +65,8 @@ msgdata,channel_init,remote_ann_bitcoin_sig,?secp256k1_ecdsa_signature,
|
||||
msgdata,channel_init,option_static_remotekey,bool,
|
||||
msgdata,channel_init,dev_fast_gossip,bool,
|
||||
msgdata,channel_init,dev_fail_process_onionpacket,bool,
|
||||
msgdata,channel_init,num_penalty_bases,u32,
|
||||
msgdata,channel_init,pbases,penalty_base,num_penalty_bases
|
||||
|
||||
# master->channeld funding hit new depth(funding locked if >= lock depth)
|
||||
msgtype,channel_funding_depth,1002
|
||||
|
|
@ -170,6 +170,9 @@ struct peer {
|
||||
|
||||
/* Empty commitments. Spec violation, but a minor one. */
|
||||
u64 last_empty_commitment;
|
||||
|
||||
/* Penalty bases for this channel / peer. */
|
||||
struct penalty_base **pbases;
|
||||
};
|
||||
|
||||
static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer);
|
||||
@ -1032,6 +1035,10 @@ static void send_commit(struct peer *peer)
|
||||
if (direct_outputs[LOCAL] != NULL) {
|
||||
pbase = penalty_base_new(tmpctx, peer->next_index[REMOTE],
|
||||
txs[0], direct_outputs[LOCAL]);
|
||||
|
||||
/* Add the penalty_base to our in-memory list as well, so we
|
||||
* can find it again later. */
|
||||
tal_arr_expand(&peer->pbases, tal_steal(peer, pbase));
|
||||
} else
|
||||
pbase = NULL;
|
||||
|
||||
@ -3085,6 +3092,7 @@ static void init_channel(struct peer *peer)
|
||||
secp256k1_ecdsa_signature *remote_ann_node_sig;
|
||||
secp256k1_ecdsa_signature *remote_ann_bitcoin_sig;
|
||||
bool option_static_remotekey;
|
||||
struct penalty_base *pbases;
|
||||
#if !DEVELOPER
|
||||
bool dev_fail_process_onionpacket; /* Ignored */
|
||||
#endif
|
||||
@ -3143,10 +3151,19 @@ static void init_channel(struct peer *peer)
|
||||
&remote_ann_bitcoin_sig,
|
||||
&option_static_remotekey,
|
||||
&dev_fast_gossip,
|
||||
&dev_fail_process_onionpacket)) {
|
||||
&dev_fail_process_onionpacket,
|
||||
&pbases)) {
|
||||
master_badmsg(WIRE_CHANNEL_INIT, msg);
|
||||
}
|
||||
|
||||
/* Keeping an array of pointers is better since it allows us to avoid
|
||||
* extra allocations later. */
|
||||
peer->pbases = tal_arr(peer, struct penalty_base *, 0);
|
||||
for (size_t i=0; i<tal_count(pbases); i++)
|
||||
tal_arr_expand(&peer->pbases,
|
||||
tal_dup(peer, struct penalty_base, &pbases[i]));
|
||||
tal_free(pbases);
|
||||
|
||||
/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = HSM */
|
||||
per_peer_state_set_fds(peer->pps, 3, 4, 5);
|
||||
|
||||
|
@ -385,6 +385,7 @@ void peer_start_channeld(struct channel *channel,
|
||||
bool reached_announce_depth;
|
||||
struct secret last_remote_per_commit_secret;
|
||||
secp256k1_ecdsa_signature *remote_ann_node_sig, *remote_ann_bitcoin_sig;
|
||||
struct penalty_base *pbases;
|
||||
|
||||
hsmfd = hsm_get_client_fd(ld, &channel->peer->id,
|
||||
channel->dbid,
|
||||
@ -463,6 +464,9 @@ void peer_start_channeld(struct channel *channel,
|
||||
return;
|
||||
}
|
||||
|
||||
pbases = wallet_penalty_base_load_for_channel(
|
||||
tmpctx, channel->peer->ld->wallet, channel->dbid);
|
||||
|
||||
initmsg = towire_channel_init(tmpctx,
|
||||
chainparams,
|
||||
ld->our_features,
|
||||
@ -517,7 +521,8 @@ void peer_start_channeld(struct channel *channel,
|
||||
* negotiated now! */
|
||||
channel->option_static_remotekey,
|
||||
IFDEV(ld->dev_fast_gossip, false),
|
||||
IFDEV(dev_fail_process_onionpacket, false));
|
||||
IFDEV(dev_fail_process_onionpacket, false),
|
||||
pbases);
|
||||
|
||||
/* We don't expect a response: we are triggered by funding_depth_cb. */
|
||||
subd_send_msg(channel->owner, take(initmsg));
|
||||
|
Loading…
Reference in New Issue
Block a user