mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
coin_mvt: log events for pushes/lease_fees for leased channels
We need to stash/save the amount of the lease fees on a leased channel, we do this by re-using the 'push' amount field on channel (which is technically correct, since we're essentially pushing the fee amount to the peer). Also updates a bit of how the pushes are accounted for (pushed to now has an event; their channel will open at zero but then they'll immediately register a push event). Leases fees are treated exactly the same as pushes, except labeled differently. Required adding a 'lease_fee' field to the inflights so we keep track of the fee for the lease until the open happens.
This commit is contained in:
@@ -1079,12 +1079,13 @@ wallet_update_channel(struct lightningd *ld,
|
||||
u32 funding_feerate,
|
||||
struct wally_psbt *psbt STEALS,
|
||||
const u32 lease_expiry,
|
||||
struct amount_sat lease_fee,
|
||||
secp256k1_ecdsa_signature *lease_commit_sig STEALS,
|
||||
const u32 lease_chan_max_msat,
|
||||
const u16 lease_chan_max_ppt,
|
||||
const u32 lease_blockheight_start)
|
||||
{
|
||||
struct amount_msat our_msat;
|
||||
struct amount_msat our_msat, lease_fee_msat;
|
||||
struct channel_inflight *inflight;
|
||||
|
||||
if (!amount_sat_to_msat(&our_msat, our_funding)) {
|
||||
@@ -1092,6 +1093,11 @@ wallet_update_channel(struct lightningd *ld,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!amount_sat_to_msat(&lease_fee_msat, lease_fee)) {
|
||||
log_broken(channel->log, "Unable to convert 'lease_fee'");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
assert(channel->unsaved_dbid == 0);
|
||||
assert(channel->dbid != 0);
|
||||
|
||||
@@ -1099,6 +1105,7 @@ wallet_update_channel(struct lightningd *ld,
|
||||
channel->funding_sats = total_funding;
|
||||
channel->our_funds = our_funding;
|
||||
channel->our_msat = our_msat;
|
||||
channel->push = lease_fee_msat;
|
||||
channel->msat_to_us_min = our_msat;
|
||||
channel->msat_to_us_max = our_msat;
|
||||
channel->lease_expiry = lease_expiry;
|
||||
@@ -1134,7 +1141,8 @@ wallet_update_channel(struct lightningd *ld,
|
||||
channel->lease_commit_sig,
|
||||
channel->lease_chan_max_msat,
|
||||
channel->lease_chan_max_ppt,
|
||||
lease_blockheight_start);
|
||||
lease_blockheight_start,
|
||||
channel->push);
|
||||
wallet_inflight_add(ld->wallet, inflight);
|
||||
|
||||
return inflight;
|
||||
@@ -1157,11 +1165,12 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
struct wally_psbt *psbt STEALS,
|
||||
const u32 lease_blockheight_start,
|
||||
const u32 lease_expiry,
|
||||
const struct amount_sat lease_fee,
|
||||
secp256k1_ecdsa_signature *lease_commit_sig STEALS,
|
||||
const u32 lease_chan_max_msat,
|
||||
const u16 lease_chan_max_ppt)
|
||||
{
|
||||
struct amount_msat our_msat;
|
||||
struct amount_msat our_msat, lease_fee_msat;
|
||||
struct channel_inflight *inflight;
|
||||
|
||||
if (!amount_sat_to_msat(&our_msat, our_funding)) {
|
||||
@@ -1169,6 +1178,11 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!amount_sat_to_msat(&lease_fee_msat, lease_fee)) {
|
||||
log_broken(channel->log, "Unable to convert lease fee");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get a key to use for closing outputs from this tx */
|
||||
channel->final_key_idx = wallet_get_newindex(ld);
|
||||
if (channel->final_key_idx == -1) {
|
||||
@@ -1190,6 +1204,7 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
channel->funding_sats = total_funding;
|
||||
channel->our_funds = our_funding;
|
||||
channel->our_msat = our_msat;
|
||||
channel->push = lease_fee_msat;
|
||||
channel->msat_to_us_min = our_msat;
|
||||
channel->msat_to_us_max = our_msat;
|
||||
|
||||
@@ -1253,7 +1268,8 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
channel->lease_commit_sig,
|
||||
channel->lease_chan_max_msat,
|
||||
channel->lease_chan_max_ppt,
|
||||
lease_blockheight_start);
|
||||
lease_blockheight_start,
|
||||
channel->push);
|
||||
wallet_inflight_add(ld->wallet, inflight);
|
||||
|
||||
return inflight;
|
||||
@@ -2739,7 +2755,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
u16 lease_chan_max_ppt;
|
||||
u32 feerate_funding, feerate_commitment, lease_expiry,
|
||||
lease_chan_max_msat, lease_blockheight_start;
|
||||
struct amount_sat total_funding, funding_ours;
|
||||
struct amount_sat total_funding, funding_ours, lease_fee;
|
||||
u8 *remote_upfront_shutdown_script,
|
||||
*local_upfront_shutdown_script;
|
||||
struct penalty_base *pbase;
|
||||
@@ -2772,6 +2788,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
&remote_upfront_shutdown_script,
|
||||
&lease_blockheight_start,
|
||||
&lease_expiry,
|
||||
&lease_fee,
|
||||
&lease_commit_sig,
|
||||
&lease_chan_max_msat,
|
||||
&lease_chan_max_ppt)) {
|
||||
@@ -2817,6 +2834,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
psbt,
|
||||
lease_blockheight_start,
|
||||
lease_expiry,
|
||||
lease_fee,
|
||||
lease_commit_sig,
|
||||
lease_chan_max_msat,
|
||||
lease_chan_max_ppt))) {
|
||||
@@ -2849,6 +2867,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
feerate_funding,
|
||||
psbt,
|
||||
lease_expiry,
|
||||
lease_fee,
|
||||
lease_commit_sig,
|
||||
lease_chan_max_msat,
|
||||
lease_chan_max_ppt,
|
||||
|
||||
Reference in New Issue
Block a user