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. 63
      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); 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) u32 feerate_from_style(u32 feerate, enum feerate_style style)
{ {
switch (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_min(struct lightningd *ld, bool *unknown);
u32 feerate_max(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 opening_feerate(struct chain_topology *topo);
u32 mutual_close_feerate(struct chain_topology *topo);
u32 unilateral_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 */ /* We always use feerate-per-ksipa, ie. perkw */
u32 feerate_from_style(u32 feerate, enum feerate_style style); u32 feerate_from_style(u32 feerate, enum feerate_style style);

63
lightningd/onchain_control.c

@ -457,7 +457,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
struct lightningd *ld = channel->peer->ld; struct lightningd *ld = channel->peer->ld;
struct pubkey final_key; struct pubkey final_key;
int hsmfd; int hsmfd;
u32 feerate; u32 feerates[3];
channel_fail_permanent(channel, "Funding transaction spent"); 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(tx, &txid);
bitcoin_txid(channel->last_tx, &our_last_txid); bitcoin_txid(channel->last_tx, &our_last_txid);
/* We try to use normal feerate for onchaind spends. */ /* We try to get the feerate for each transaction type, 0 if estimation
feerate = try_get_feerate(ld->topology, FEERATE_NORMAL); * failed. */
if (!feerate) { feerates[0] = delayed_to_us_feerate(ld->topology);
/* We have at least one data point: the last tx's feerate. */ feerates[1] = htlc_resolution_feerate(ld->topology);
struct amount_sat fee = channel->funding; feerates[2] = penalty_feerate(ld->topology);
for (size_t i = 0; i < channel->last_tx->wtx->num_outputs; i++) { /* We check them separately but there is a high chance that if estimation
struct amount_asset asset = * failed for one, it failed for all.. */
bitcoin_tx_output_get_amount(channel->last_tx, i); for (size_t i = 0; i < 3; i++) {
struct amount_sat amt; if (!feerates[i]) {
assert(amount_asset_is_main(&asset)); /* We have at least one data point: the last tx's feerate. */
amt = amount_asset_to_sat(&asset); struct amount_sat fee = channel->funding;
if (!amount_sat_sub(&fee, fee, amt)) { for (size_t i = 0;
log_broken(channel->log, "Could not get fee" i < channel->last_tx->wtx->num_outputs; i++) {
" funding %s tx %s", struct amount_asset asset =
type_to_string(tmpctx, bitcoin_tx_output_get_amount(channel->last_tx, i);
struct amount_sat, struct amount_sat amt;
&channel->funding), assert(amount_asset_is_main(&asset));
type_to_string(tmpctx, amt = amount_asset_to_sat(&asset);
struct bitcoin_tx, if (!amount_sat_sub(&fee, fee, amt)) {
channel->last_tx)); log_broken(channel->log, "Could not get fee"
return KEEP_WATCHING; " 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 */ feerates[i] = fee.satoshis / bitcoin_tx_weight(tx); /* Raw: reverse feerate extraction */
if (feerate < feerate_floor()) if (feerates[i] < feerate_floor())
feerate = feerate_floor(); feerates[i] = feerate_floor();
}
} }
msg = towire_onchain_init(channel, msg = towire_onchain_init(channel,
@ -545,7 +553,8 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
* we specify theirs. */ * we specify theirs. */
channel->channel_info.their_config.to_self_delay, channel->channel_info.their_config.to_self_delay,
channel->our_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, channel->our_config.dust_limit,
&our_last_txid, &our_last_txid,
channel->shutdown_scriptpubkey[LOCAL], channel->shutdown_scriptpubkey[LOCAL],

Loading…
Cancel
Save