mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
chaintopology: add delayed_to_us, htlc, and penalty feerates
This commit is contained in:
parent
8cbc0038bc
commit
ad4bcfde53
3 changed files with 56 additions and 28 deletions
|
@ -458,6 +458,21 @@ u32 unilateral_feerate(struct chain_topology *topo)
|
|||
return try_get_feerate(topo, FEERATE_URGENT);
|
||||
}
|
||||
|
||||
u32 delayed_to_us_feerate(struct chain_topology *topo)
|
||||
{
|
||||
return try_get_feerate(topo, FEERATE_NORMAL);
|
||||
}
|
||||
|
||||
u32 htlc_resolution_feerate(struct chain_topology *topo)
|
||||
{
|
||||
return try_get_feerate(topo, FEERATE_NORMAL);
|
||||
}
|
||||
|
||||
u32 penalty_feerate(struct chain_topology *topo)
|
||||
{
|
||||
return try_get_feerate(topo, FEERATE_NORMAL);
|
||||
}
|
||||
|
||||
u32 feerate_from_style(u32 feerate, enum feerate_style style)
|
||||
{
|
||||
switch (style) {
|
||||
|
|
|
@ -146,9 +146,13 @@ u32 try_get_feerate(const struct chain_topology *topo, enum feerate feerate);
|
|||
u32 feerate_min(struct lightningd *ld, bool *unknown);
|
||||
u32 feerate_max(struct lightningd *ld, bool *unknown);
|
||||
|
||||
u32 mutual_close_feerate(struct chain_topology *topo);
|
||||
u32 opening_feerate(struct chain_topology *topo);
|
||||
u32 mutual_close_feerate(struct chain_topology *topo);
|
||||
u32 unilateral_feerate(struct chain_topology *topo);
|
||||
/* For onchain resolution. */
|
||||
u32 delayed_to_us_feerate(struct chain_topology *topo);
|
||||
u32 htlc_resolution_feerate(struct chain_topology *topo);
|
||||
u32 penalty_feerate(struct chain_topology *topo);
|
||||
|
||||
/* We always use feerate-per-ksipa, ie. perkw */
|
||||
u32 feerate_from_style(u32 feerate, enum feerate_style style);
|
||||
|
|
|
@ -457,7 +457,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
|||
struct lightningd *ld = channel->peer->ld;
|
||||
struct pubkey final_key;
|
||||
int hsmfd;
|
||||
u32 feerate;
|
||||
u32 feerates[3];
|
||||
|
||||
channel_fail_permanent(channel, "Funding transaction spent");
|
||||
|
||||
|
@ -502,33 +502,41 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
|||
bitcoin_txid(tx, &txid);
|
||||
bitcoin_txid(channel->last_tx, &our_last_txid);
|
||||
|
||||
/* We try to use normal feerate for onchaind spends. */
|
||||
feerate = try_get_feerate(ld->topology, FEERATE_NORMAL);
|
||||
if (!feerate) {
|
||||
/* We have at least one data point: the last tx's feerate. */
|
||||
struct amount_sat fee = channel->funding;
|
||||
for (size_t i = 0; i < channel->last_tx->wtx->num_outputs; i++) {
|
||||
struct amount_asset asset =
|
||||
bitcoin_tx_output_get_amount(channel->last_tx, i);
|
||||
struct amount_sat amt;
|
||||
assert(amount_asset_is_main(&asset));
|
||||
amt = amount_asset_to_sat(&asset);
|
||||
if (!amount_sat_sub(&fee, fee, amt)) {
|
||||
log_broken(channel->log, "Could not get fee"
|
||||
" funding %s tx %s",
|
||||
type_to_string(tmpctx,
|
||||
struct amount_sat,
|
||||
&channel->funding),
|
||||
type_to_string(tmpctx,
|
||||
struct bitcoin_tx,
|
||||
channel->last_tx));
|
||||
return KEEP_WATCHING;
|
||||
/* We try to get the feerate for each transaction type, 0 if estimation
|
||||
* failed. */
|
||||
feerates[0] = delayed_to_us_feerate(ld->topology);
|
||||
feerates[1] = htlc_resolution_feerate(ld->topology);
|
||||
feerates[2] = penalty_feerate(ld->topology);
|
||||
/* We check them separately but there is a high chance that if estimation
|
||||
* failed for one, it failed for all.. */
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
if (!feerates[i]) {
|
||||
/* We have at least one data point: the last tx's feerate. */
|
||||
struct amount_sat fee = channel->funding;
|
||||
for (size_t i = 0;
|
||||
i < channel->last_tx->wtx->num_outputs; i++) {
|
||||
struct amount_asset asset =
|
||||
bitcoin_tx_output_get_amount(channel->last_tx, i);
|
||||
struct amount_sat amt;
|
||||
assert(amount_asset_is_main(&asset));
|
||||
amt = amount_asset_to_sat(&asset);
|
||||
if (!amount_sat_sub(&fee, fee, amt)) {
|
||||
log_broken(channel->log, "Could not get fee"
|
||||
" funding %s tx %s",
|
||||
type_to_string(tmpctx,
|
||||
struct amount_sat,
|
||||
&channel->funding),
|
||||
type_to_string(tmpctx,
|
||||
struct bitcoin_tx,
|
||||
channel->last_tx));
|
||||
return KEEP_WATCHING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
feerate = fee.satoshis / bitcoin_tx_weight(tx); /* Raw: reverse feerate extraction */
|
||||
if (feerate < feerate_floor())
|
||||
feerate = feerate_floor();
|
||||
feerates[i] = fee.satoshis / bitcoin_tx_weight(tx); /* Raw: reverse feerate extraction */
|
||||
if (feerates[i] < feerate_floor())
|
||||
feerates[i] = feerate_floor();
|
||||
}
|
||||
}
|
||||
|
||||
msg = towire_onchain_init(channel,
|
||||
|
@ -545,7 +553,8 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
|||
* we specify theirs. */
|
||||
channel->channel_info.their_config.to_self_delay,
|
||||
channel->our_config.to_self_delay,
|
||||
feerate, feerate, feerate,
|
||||
/* delayed_to_us, htlc, and penalty. */
|
||||
feerates[0], feerates[1], feerates[2],
|
||||
channel->our_config.dust_limit,
|
||||
&our_last_txid,
|
||||
channel->shutdown_scriptpubkey[LOCAL],
|
||||
|
|
Loading…
Add table
Reference in a new issue