onchaind: fix bug when grinding feerates with multiple possibilities.

Fixes: #2820
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-08-13 16:46:48 +09:30
parent 9424477cb5
commit a7a9f1c9d3
2 changed files with 13 additions and 12 deletions

View File

@ -169,8 +169,15 @@ static bool set_htlc_timeout_fee(struct bitcoin_tx *tx,
* 1. Multiply `feerate_per_kw` by 663 and divide by 1000 (rounding
* down).
*/
if (amount_sat_eq(fee, AMOUNT_SAT(UINT64_MAX)))
return grind_htlc_tx_fee(&fee, tx, remotesig, wscript, 663);
if (amount_sat_eq(fee, AMOUNT_SAT(UINT64_MAX))) {
struct amount_sat grindfee;
if (grind_htlc_tx_fee(&grindfee, tx, remotesig, wscript, 663)) {
/* Cache this for next time */
fee = grindfee;
return true;
}
return false;
}
if (!amount_sat_sub(&amount, amount, fee))
status_failed(STATUS_FAIL_INTERNAL_ERROR,

View File

@ -85,6 +85,10 @@ bool shachain_get_secret(const struct shachain *shachain UNNEEDED,
u64 commit_num UNNEEDED,
struct secret *preimage UNNEEDED)
{ fprintf(stderr, "shachain_get_secret called!\n"); abort(); }
/* Generated stub for status_failed */
void status_failed(enum status_failreason code UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_failed called!\n"); abort(); }
/* Generated stub for status_setup_sync */
void status_setup_sync(int fd UNNEEDED)
{ fprintf(stderr, "status_setup_sync called!\n"); abort(); }
@ -228,16 +232,6 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
return tx;
}
void status_failed(enum status_failreason code UNNEEDED,
const char *fmt, ...)
{
/* FIXME! */
fprintf(stderr, "XFAIL: %s!\n", fmt);
tal_free(tmpctx);
secp256k1_context_destroy(secp256k1_ctx);
exit(0);
}
int main(void)
{
struct bitcoin_signature remotesig;