mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
peer: give more sensible error if anchor is too large.
Currently we get the odd message "Own anchor has insufficient funds". Reported-by: Christian Decker Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
13593d4cbf
commit
7b5806fef2
@ -120,6 +120,12 @@ static bool change_funding(uint64_t anchor_satoshis,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool anchor_too_large(uint64_t anchor_satoshis)
|
||||
{
|
||||
/* Anchor must fit in 32 bit. */
|
||||
return anchor_satoshis >= (1ULL << 32) / 1000;
|
||||
}
|
||||
|
||||
struct channel_state *initial_cstate(const tal_t *ctx,
|
||||
uint64_t anchor_satoshis,
|
||||
uint64_t fee_rate,
|
||||
@ -134,8 +140,7 @@ struct channel_state *initial_cstate(const tal_t *ctx,
|
||||
cstate->num_nondust = 0;
|
||||
|
||||
/* Anchor must fit in 32 bit. */
|
||||
if (anchor_satoshis >= (1ULL << 32) / 1000)
|
||||
return tal_free(cstate);
|
||||
assert(!anchor_too_large(anchor_satoshis));
|
||||
|
||||
fee_msat = calculate_fee_msat(0, fee_rate);
|
||||
if (fee_msat > anchor_satoshis * 1000)
|
||||
|
@ -133,6 +133,12 @@ bool force_fee(struct channel_state *cstate, uint64_t fee);
|
||||
*/
|
||||
uint64_t fee_by_feerate(size_t txsize, uint64_t fee_rate);
|
||||
|
||||
/**
|
||||
* anchor_too_large: does anchor amount fit in 32-bits of millisatoshi.
|
||||
* @anchor_satoshis: amount in satoshis
|
||||
*/
|
||||
bool anchor_too_large(uint64_t anchor_satoshis);
|
||||
|
||||
/* Routines to db to force HTLC changes out-of-order which may wrap. */
|
||||
void force_add_htlc(struct channel_state *cstate, const struct htlc *htlc);
|
||||
void force_fail_htlc(struct channel_state *cstate, const struct htlc *htlc);
|
||||
|
@ -343,6 +343,9 @@ Pkt *accept_pkt_anchor(struct peer *peer, const Pkt *pkt)
|
||||
assert(peer->local.offer_anchor == CMD_OPEN_WITHOUT_ANCHOR);
|
||||
assert(peer->remote.offer_anchor == CMD_OPEN_WITH_ANCHOR);
|
||||
|
||||
if (anchor_too_large(a->amount))
|
||||
return pkt_err(peer, "Anchor millisatoshis exceeds 32 bits");
|
||||
|
||||
proto_to_sha256(a->txid, &peer->anchor.txid.sha);
|
||||
peer->anchor.index = a->output_index;
|
||||
peer->anchor.satoshis = a->amount;
|
||||
|
@ -2862,6 +2862,11 @@ static void json_connect(struct command *cmd,
|
||||
|
||||
connect->input->index = output;
|
||||
connect->input->amount = tx->output[output].amount;
|
||||
if (anchor_too_large(connect->input->amount)) {
|
||||
command_fail(cmd, "Amount %"PRIu64" is too large",
|
||||
connect->input->amount);
|
||||
return;
|
||||
}
|
||||
if (!dns_resolve_and_connect(cmd->dstate, connect->name, connect->port,
|
||||
peer_connected_out, peer_failed, connect)) {
|
||||
command_fail(cmd, "DNS failed");
|
||||
|
Loading…
Reference in New Issue
Block a user