feat: pass htlc amount exceeded to exception
This commit is contained in:
parent
ec2ced192b
commit
9e98d01d02
|
@ -644,7 +644,7 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
|
||||||
|
|
||||||
add_err = channel_add_htlc(peer->channel, REMOTE, id, amount,
|
add_err = channel_add_htlc(peer->channel, REMOTE, id, amount,
|
||||||
cltv_expiry, &payment_hash,
|
cltv_expiry, &payment_hash,
|
||||||
onion_routing_packet, &htlc);
|
onion_routing_packet, &htlc, NULL);
|
||||||
if (add_err != CHANNEL_ERR_ADD_OK)
|
if (add_err != CHANNEL_ERR_ADD_OK)
|
||||||
peer_failed(peer->pps,
|
peer_failed(peer->pps,
|
||||||
&peer->channel_id,
|
&peer->channel_id,
|
||||||
|
@ -2532,6 +2532,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
|
||||||
enum onion_type failcode;
|
enum onion_type failcode;
|
||||||
/* Subtle: must be tal object since we marshal using tal_bytelen() */
|
/* Subtle: must be tal object since we marshal using tal_bytelen() */
|
||||||
const char *failmsg;
|
const char *failmsg;
|
||||||
|
struct amount_sat htlc_fee;
|
||||||
|
|
||||||
if (!peer->funding_locked[LOCAL] || !peer->funding_locked[REMOTE])
|
if (!peer->funding_locked[LOCAL] || !peer->funding_locked[REMOTE])
|
||||||
status_failed(STATUS_FAIL_MASTER_IO,
|
status_failed(STATUS_FAIL_MASTER_IO,
|
||||||
|
@ -2544,7 +2545,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
|
||||||
|
|
||||||
e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
|
e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
|
||||||
amount, cltv_expiry, &payment_hash,
|
amount, cltv_expiry, &payment_hash,
|
||||||
onion_routing_packet, NULL);
|
onion_routing_packet, NULL, &htlc_fee);
|
||||||
status_trace("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s",
|
status_trace("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s",
|
||||||
peer->htlc_id,
|
peer->htlc_id,
|
||||||
type_to_string(tmpctx, struct amount_msat, &amount),
|
type_to_string(tmpctx, struct amount_msat, &amount),
|
||||||
|
@ -2582,7 +2583,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
|
||||||
goto failed;
|
goto failed;
|
||||||
case CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED:
|
case CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED:
|
||||||
failcode = WIRE_TEMPORARY_CHANNEL_FAILURE;
|
failcode = WIRE_TEMPORARY_CHANNEL_FAILURE;
|
||||||
failmsg = tal_fmt(inmsg, "Capacity exceeded");
|
failmsg = tal_fmt(inmsg, "Capacity exceeded - HTLC fee: %s", fmt_amount_sat(inmsg, &htlc_fee));
|
||||||
goto failed;
|
goto failed;
|
||||||
case CHANNEL_ERR_HTLC_BELOW_MINIMUM:
|
case CHANNEL_ERR_HTLC_BELOW_MINIMUM:
|
||||||
failcode = WIRE_AMOUNT_BELOW_MINIMUM;
|
failcode = WIRE_AMOUNT_BELOW_MINIMUM;
|
||||||
|
|
|
@ -299,7 +299,8 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
||||||
const struct sha256 *payment_hash,
|
const struct sha256 *payment_hash,
|
||||||
const u8 routing[TOTAL_PACKET_SIZE],
|
const u8 routing[TOTAL_PACKET_SIZE],
|
||||||
struct htlc **htlcp,
|
struct htlc **htlcp,
|
||||||
bool enforce_aggregate_limits)
|
bool enforce_aggregate_limits,
|
||||||
|
struct amount_sat *htlc_fee)
|
||||||
{
|
{
|
||||||
struct htlc *htlc, *old;
|
struct htlc *htlc, *old;
|
||||||
struct amount_msat msat_in_htlcs, committed_msat, adding_msat, removing_msat;
|
struct amount_msat msat_in_htlcs, committed_msat, adding_msat, removing_msat;
|
||||||
|
@ -448,6 +449,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
||||||
fee = AMOUNT_SAT(0);
|
fee = AMOUNT_SAT(0);
|
||||||
|
|
||||||
assert((s64)fee.satoshis >= 0); /* Raw: explicit signedness test */
|
assert((s64)fee.satoshis >= 0); /* Raw: explicit signedness test */
|
||||||
|
if (htlc_fee) *htlc_fee = fee; /* set fee output pointer if given */
|
||||||
|
|
||||||
if (enforce_aggregate_limits) {
|
if (enforce_aggregate_limits) {
|
||||||
/* Figure out what balance sender would have after applying all
|
/* Figure out what balance sender would have after applying all
|
||||||
|
@ -520,7 +522,8 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
|
||||||
u32 cltv_expiry,
|
u32 cltv_expiry,
|
||||||
const struct sha256 *payment_hash,
|
const struct sha256 *payment_hash,
|
||||||
const u8 routing[TOTAL_PACKET_SIZE],
|
const u8 routing[TOTAL_PACKET_SIZE],
|
||||||
struct htlc **htlcp)
|
struct htlc **htlcp,
|
||||||
|
struct amount_sat *htlc_fee)
|
||||||
{
|
{
|
||||||
enum htlc_state state;
|
enum htlc_state state;
|
||||||
|
|
||||||
|
@ -530,7 +533,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
|
||||||
state = RCVD_ADD_HTLC;
|
state = RCVD_ADD_HTLC;
|
||||||
|
|
||||||
return add_htlc(channel, state, id, amount, cltv_expiry,
|
return add_htlc(channel, state, id, amount, cltv_expiry,
|
||||||
payment_hash, routing, htlcp, true);
|
payment_hash, routing, htlcp, true, htlc_fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct htlc *channel_get_htlc(struct channel *channel, enum side sender, u64 id)
|
struct htlc *channel_get_htlc(struct channel *channel, enum side sender, u64 id)
|
||||||
|
@ -1084,7 +1087,7 @@ bool channel_force_htlcs(struct channel *channel,
|
||||||
htlcs[i].id, htlcs[i].amount,
|
htlcs[i].id, htlcs[i].amount,
|
||||||
htlcs[i].cltv_expiry,
|
htlcs[i].cltv_expiry,
|
||||||
&htlcs[i].payment_hash,
|
&htlcs[i].payment_hash,
|
||||||
htlcs[i].onion_routing_packet, &htlc, false);
|
htlcs[i].onion_routing_packet, &htlc, false, NULL);
|
||||||
if (e != CHANNEL_ERR_ADD_OK) {
|
if (e != CHANNEL_ERR_ADD_OK) {
|
||||||
status_trace("%s HTLC %"PRIu64" failed error %u",
|
status_trace("%s HTLC %"PRIu64" failed error %u",
|
||||||
htlc_state_owner(hstates[i]) == LOCAL
|
htlc_state_owner(hstates[i]) == LOCAL
|
||||||
|
|
|
@ -104,7 +104,8 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
|
||||||
u32 cltv_expiry,
|
u32 cltv_expiry,
|
||||||
const struct sha256 *payment_hash,
|
const struct sha256 *payment_hash,
|
||||||
const u8 routing[TOTAL_PACKET_SIZE],
|
const u8 routing[TOTAL_PACKET_SIZE],
|
||||||
struct htlc **htlcp);
|
struct htlc **htlcp,
|
||||||
|
struct amount_sat *htlc_fee);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* channel_get_htlc: find an HTLC
|
* channel_get_htlc: find an HTLC
|
||||||
|
|
|
@ -150,7 +150,7 @@ static const struct htlc **include_htlcs(struct channel *channel, enum side side
|
||||||
memset(&preimage, i, sizeof(preimage));
|
memset(&preimage, i, sizeof(preimage));
|
||||||
sha256(&hash, &preimage, sizeof(preimage));
|
sha256(&hash, &preimage, sizeof(preimage));
|
||||||
e = channel_add_htlc(channel, sender, i, msatoshi, 500+i, &hash,
|
e = channel_add_htlc(channel, sender, i, msatoshi, 500+i, &hash,
|
||||||
dummy_routing, NULL);
|
dummy_routing, NULL, NULL);
|
||||||
assert(e == CHANNEL_ERR_ADD_OK);
|
assert(e == CHANNEL_ERR_ADD_OK);
|
||||||
htlcs[i] = channel_get_htlc(channel, sender, i);
|
htlcs[i] = channel_get_htlc(channel, sender, i);
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ static void send_and_fulfill_htlc(struct channel *channel,
|
||||||
sha256(&rhash, &r, sizeof(r));
|
sha256(&rhash, &r, sizeof(r));
|
||||||
|
|
||||||
assert(channel_add_htlc(channel, sender, 1337, msatoshi, 900, &rhash,
|
assert(channel_add_htlc(channel, sender, 1337, msatoshi, 900, &rhash,
|
||||||
dummy_routing, NULL) == CHANNEL_ERR_ADD_OK);
|
dummy_routing, NULL, NULL) == CHANNEL_ERR_ADD_OK);
|
||||||
|
|
||||||
changed_htlcs = tal_arr(channel, const struct htlc *, 0);
|
changed_htlcs = tal_arr(channel, const struct htlc *, 0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue