mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
channeld: hoist make_failmsg above send_fail_or_fulfill.
Move only. Needed for next patch. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
6e9ae98e1e
commit
e92f244b80
@ -800,6 +800,110 @@ static u8 *gossipd_wait_sync_reply(const tal_t *ctx,
|
||||
GOSSIP_FD, &peer->from_gossipd, "gossipd");
|
||||
}
|
||||
|
||||
static u8 *foreign_channel_update(const tal_t *ctx,
|
||||
struct peer *peer,
|
||||
const struct short_channel_id *scid)
|
||||
{
|
||||
u8 *msg, *update;
|
||||
|
||||
msg = towire_gossip_get_update(NULL, scid);
|
||||
msg = gossipd_wait_sync_reply(tmpctx, peer, take(msg),
|
||||
WIRE_GOSSIP_GET_UPDATE_REPLY);
|
||||
if (!fromwire_gossip_get_update_reply(ctx, msg, &update))
|
||||
status_failed(STATUS_FAIL_GOSSIP_IO,
|
||||
"Invalid update reply");
|
||||
return update;
|
||||
}
|
||||
|
||||
static u8 *make_failmsg(const tal_t *ctx,
|
||||
struct peer *peer,
|
||||
const struct htlc *htlc,
|
||||
enum onion_type failcode,
|
||||
const struct short_channel_id *scid)
|
||||
{
|
||||
u8 *msg, *channel_update = NULL;
|
||||
u32 cltv_expiry = abs_locktime_to_blocks(&htlc->expiry);
|
||||
|
||||
switch (failcode) {
|
||||
case WIRE_INVALID_REALM:
|
||||
msg = towire_invalid_realm(ctx);
|
||||
goto done;
|
||||
case WIRE_TEMPORARY_NODE_FAILURE:
|
||||
msg = towire_temporary_node_failure(ctx);
|
||||
goto done;
|
||||
case WIRE_PERMANENT_NODE_FAILURE:
|
||||
msg = towire_permanent_node_failure(ctx);
|
||||
goto done;
|
||||
case WIRE_REQUIRED_NODE_FEATURE_MISSING:
|
||||
msg = towire_required_node_feature_missing(ctx);
|
||||
goto done;
|
||||
case WIRE_TEMPORARY_CHANNEL_FAILURE:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_temporary_channel_failure(ctx, channel_update);
|
||||
goto done;
|
||||
case WIRE_CHANNEL_DISABLED:
|
||||
msg = towire_channel_disabled(ctx);
|
||||
goto done;
|
||||
case WIRE_PERMANENT_CHANNEL_FAILURE:
|
||||
msg = towire_permanent_channel_failure(ctx);
|
||||
goto done;
|
||||
case WIRE_REQUIRED_CHANNEL_FEATURE_MISSING:
|
||||
msg = towire_required_channel_feature_missing(ctx);
|
||||
goto done;
|
||||
case WIRE_UNKNOWN_NEXT_PEER:
|
||||
msg = towire_unknown_next_peer(ctx);
|
||||
goto done;
|
||||
case WIRE_AMOUNT_BELOW_MINIMUM:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_amount_below_minimum(ctx, htlc->msatoshi,
|
||||
channel_update);
|
||||
goto done;
|
||||
case WIRE_FEE_INSUFFICIENT:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_fee_insufficient(ctx, htlc->msatoshi,
|
||||
channel_update);
|
||||
goto done;
|
||||
case WIRE_INCORRECT_CLTV_EXPIRY:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_incorrect_cltv_expiry(ctx, cltv_expiry,
|
||||
channel_update);
|
||||
goto done;
|
||||
case WIRE_EXPIRY_TOO_SOON:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_expiry_too_soon(ctx, channel_update);
|
||||
goto done;
|
||||
case WIRE_EXPIRY_TOO_FAR:
|
||||
msg = towire_expiry_too_far(ctx);
|
||||
goto done;
|
||||
case WIRE_UNKNOWN_PAYMENT_HASH:
|
||||
msg = towire_unknown_payment_hash(ctx);
|
||||
goto done;
|
||||
case WIRE_INCORRECT_PAYMENT_AMOUNT:
|
||||
msg = towire_incorrect_payment_amount(ctx);
|
||||
goto done;
|
||||
case WIRE_FINAL_EXPIRY_TOO_SOON:
|
||||
msg = towire_final_expiry_too_soon(ctx);
|
||||
goto done;
|
||||
case WIRE_FINAL_INCORRECT_CLTV_EXPIRY:
|
||||
msg = towire_final_incorrect_cltv_expiry(ctx, cltv_expiry);
|
||||
goto done;
|
||||
case WIRE_FINAL_INCORRECT_HTLC_AMOUNT:
|
||||
msg = towire_final_incorrect_htlc_amount(ctx, htlc->msatoshi);
|
||||
goto done;
|
||||
case WIRE_INVALID_ONION_VERSION:
|
||||
case WIRE_INVALID_ONION_HMAC:
|
||||
case WIRE_INVALID_ONION_KEY:
|
||||
break;
|
||||
}
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Asked to create failmsg %u (%s)",
|
||||
failcode, onion_type_name(failcode));
|
||||
|
||||
done:
|
||||
tal_free(channel_update);
|
||||
return msg;
|
||||
}
|
||||
|
||||
static struct commit_sigs *calc_commitsigs(const tal_t *ctx,
|
||||
const struct peer *peer,
|
||||
u64 commit_index)
|
||||
@ -2119,110 +2223,6 @@ static void handle_preimage(struct peer *peer, const u8 *inmsg)
|
||||
abort();
|
||||
}
|
||||
|
||||
static u8 *foreign_channel_update(const tal_t *ctx,
|
||||
struct peer *peer,
|
||||
const struct short_channel_id *scid)
|
||||
{
|
||||
u8 *msg, *update;
|
||||
|
||||
msg = towire_gossip_get_update(NULL, scid);
|
||||
msg = gossipd_wait_sync_reply(tmpctx, peer, take(msg),
|
||||
WIRE_GOSSIP_GET_UPDATE_REPLY);
|
||||
if (!fromwire_gossip_get_update_reply(ctx, msg, &update))
|
||||
status_failed(STATUS_FAIL_GOSSIP_IO,
|
||||
"Invalid update reply");
|
||||
return update;
|
||||
}
|
||||
|
||||
static u8 *make_failmsg(const tal_t *ctx,
|
||||
struct peer *peer,
|
||||
const struct htlc *htlc,
|
||||
enum onion_type failcode,
|
||||
const struct short_channel_id *scid)
|
||||
{
|
||||
u8 *msg, *channel_update = NULL;
|
||||
u32 cltv_expiry = abs_locktime_to_blocks(&htlc->expiry);
|
||||
|
||||
switch (failcode) {
|
||||
case WIRE_INVALID_REALM:
|
||||
msg = towire_invalid_realm(ctx);
|
||||
goto done;
|
||||
case WIRE_TEMPORARY_NODE_FAILURE:
|
||||
msg = towire_temporary_node_failure(ctx);
|
||||
goto done;
|
||||
case WIRE_PERMANENT_NODE_FAILURE:
|
||||
msg = towire_permanent_node_failure(ctx);
|
||||
goto done;
|
||||
case WIRE_REQUIRED_NODE_FEATURE_MISSING:
|
||||
msg = towire_required_node_feature_missing(ctx);
|
||||
goto done;
|
||||
case WIRE_TEMPORARY_CHANNEL_FAILURE:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_temporary_channel_failure(ctx, channel_update);
|
||||
goto done;
|
||||
case WIRE_CHANNEL_DISABLED:
|
||||
msg = towire_channel_disabled(ctx);
|
||||
goto done;
|
||||
case WIRE_PERMANENT_CHANNEL_FAILURE:
|
||||
msg = towire_permanent_channel_failure(ctx);
|
||||
goto done;
|
||||
case WIRE_REQUIRED_CHANNEL_FEATURE_MISSING:
|
||||
msg = towire_required_channel_feature_missing(ctx);
|
||||
goto done;
|
||||
case WIRE_UNKNOWN_NEXT_PEER:
|
||||
msg = towire_unknown_next_peer(ctx);
|
||||
goto done;
|
||||
case WIRE_AMOUNT_BELOW_MINIMUM:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_amount_below_minimum(ctx, htlc->msatoshi,
|
||||
channel_update);
|
||||
goto done;
|
||||
case WIRE_FEE_INSUFFICIENT:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_fee_insufficient(ctx, htlc->msatoshi,
|
||||
channel_update);
|
||||
goto done;
|
||||
case WIRE_INCORRECT_CLTV_EXPIRY:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_incorrect_cltv_expiry(ctx, cltv_expiry,
|
||||
channel_update);
|
||||
goto done;
|
||||
case WIRE_EXPIRY_TOO_SOON:
|
||||
channel_update = foreign_channel_update(ctx, peer, scid);
|
||||
msg = towire_expiry_too_soon(ctx, channel_update);
|
||||
goto done;
|
||||
case WIRE_EXPIRY_TOO_FAR:
|
||||
msg = towire_expiry_too_far(ctx);
|
||||
goto done;
|
||||
case WIRE_UNKNOWN_PAYMENT_HASH:
|
||||
msg = towire_unknown_payment_hash(ctx);
|
||||
goto done;
|
||||
case WIRE_INCORRECT_PAYMENT_AMOUNT:
|
||||
msg = towire_incorrect_payment_amount(ctx);
|
||||
goto done;
|
||||
case WIRE_FINAL_EXPIRY_TOO_SOON:
|
||||
msg = towire_final_expiry_too_soon(ctx);
|
||||
goto done;
|
||||
case WIRE_FINAL_INCORRECT_CLTV_EXPIRY:
|
||||
msg = towire_final_incorrect_cltv_expiry(ctx, cltv_expiry);
|
||||
goto done;
|
||||
case WIRE_FINAL_INCORRECT_HTLC_AMOUNT:
|
||||
msg = towire_final_incorrect_htlc_amount(ctx, htlc->msatoshi);
|
||||
goto done;
|
||||
case WIRE_INVALID_ONION_VERSION:
|
||||
case WIRE_INVALID_ONION_HMAC:
|
||||
case WIRE_INVALID_ONION_KEY:
|
||||
break;
|
||||
}
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Asked to create failmsg %u (%s)",
|
||||
failcode, onion_type_name(failcode));
|
||||
|
||||
done:
|
||||
tal_free(channel_update);
|
||||
return msg;
|
||||
}
|
||||
|
||||
static void handle_fail(struct peer *peer, const u8 *inmsg)
|
||||
{
|
||||
u8 *msg;
|
||||
|
Loading…
Reference in New Issue
Block a user