Browse Source

chaintopology: add delayed_to_us, htlc, and penalty feerates

travis-debug
darosior 5 years ago
committed by Rusty Russell
parent
commit
ad4bcfde53
  1. 15
      lightningd/chaintopology.c
  2. 6
      lightningd/chaintopology.h
  3. 27
      lightningd/onchain_control.c

15
lightningd/chaintopology.c

@ -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) {

6
lightningd/chaintopology.h

@ -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);

27
lightningd/onchain_control.c

@ -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,12 +502,19 @@ 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 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++) {
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;
@ -526,9 +533,10 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
}
}
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…
Cancel
Save