|
@ -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], |
|
|