Browse Source

channeld: use wirestring for failure strings.

I think this code predated wirestring.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
parent
commit
ddce5573c7
  1. 3
      channeld/channel_wire.csv
  2. 17
      channeld/channeld.c
  3. 7
      lightningd/peer_htlcs.c
  4. 2
      wallet/test/run-wallet.c

3
channeld/channel_wire.csv

@ -88,8 +88,7 @@ msgtype,channel_offer_htlc_reply,1104
msgdata,channel_offer_htlc_reply,id,u64, msgdata,channel_offer_htlc_reply,id,u64,
# Zero failure code means success., # Zero failure code means success.,
msgdata,channel_offer_htlc_reply,failure_code,u16, msgdata,channel_offer_htlc_reply,failure_code,u16,
msgdata,channel_offer_htlc_reply,failurestrlen,u16, msgdata,channel_offer_htlc_reply,failurestr,wirestring,
msgdata,channel_offer_htlc_reply,failurestr,u8,failurestrlen
# Main daemon found out the preimage for an HTLC # Main daemon found out the preimage for an HTLC
#include <bitcoin/preimage.h> #include <bitcoin/preimage.h>

Can't render this file because it has a wrong number of fields in line 8.

17
channeld/channeld.c

@ -2608,8 +2608,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
u8 onion_routing_packet[TOTAL_PACKET_SIZE]; u8 onion_routing_packet[TOTAL_PACKET_SIZE];
enum channel_add_err e; enum channel_add_err e;
enum onion_type failcode; enum onion_type failcode;
/* Subtle: must be tal object since we marshal using tal_bytelen() */ const char *failstr;
const char *failmsg;
struct amount_sat htlc_fee; struct amount_sat htlc_fee;
if (!peer->funding_locked[LOCAL] || !peer->funding_locked[REMOTE]) if (!peer->funding_locked[LOCAL] || !peer->funding_locked[REMOTE])
@ -2641,13 +2640,13 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
start_commit_timer(peer); start_commit_timer(peer);
/* Tell the master. */ /* Tell the master. */
msg = towire_channel_offer_htlc_reply(NULL, peer->htlc_id, msg = towire_channel_offer_htlc_reply(NULL, peer->htlc_id,
0, NULL); 0, "");
wire_sync_write(MASTER_FD, take(msg)); wire_sync_write(MASTER_FD, take(msg));
peer->htlc_id++; peer->htlc_id++;
return; return;
case CHANNEL_ERR_INVALID_EXPIRY: case CHANNEL_ERR_INVALID_EXPIRY:
failcode = WIRE_INCORRECT_CLTV_EXPIRY; failcode = WIRE_INCORRECT_CLTV_EXPIRY;
failmsg = tal_fmt(inmsg, "Invalid cltv_expiry %u", cltv_expiry); failstr = tal_fmt(inmsg, "Invalid cltv_expiry %u", cltv_expiry);
goto failed; goto failed;
case CHANNEL_ERR_DUPLICATE: case CHANNEL_ERR_DUPLICATE:
case CHANNEL_ERR_DUPLICATE_ID_DIFFERENT: case CHANNEL_ERR_DUPLICATE_ID_DIFFERENT:
@ -2656,30 +2655,30 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
case CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED: case CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED:
failcode = WIRE_REQUIRED_CHANNEL_FEATURE_MISSING; failcode = WIRE_REQUIRED_CHANNEL_FEATURE_MISSING;
failmsg = tal_fmt(inmsg, "Mini mode: maximum value exceeded"); failstr = "Mini mode: maximum value exceeded";
goto failed; goto failed;
/* FIXME: Fuzz the boundaries a bit to avoid probing? */ /* FIXME: Fuzz the boundaries a bit to avoid probing? */
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 - HTLC fee: %s", fmt_amount_sat(inmsg, &htlc_fee)); failstr = 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;
failmsg = tal_fmt(inmsg, "HTLC too small (%s minimum)", failstr = tal_fmt(inmsg, "HTLC too small (%s minimum)",
type_to_string(tmpctx, type_to_string(tmpctx,
struct amount_msat, struct amount_msat,
&peer->channel->config[REMOTE].htlc_minimum)); &peer->channel->config[REMOTE].htlc_minimum));
goto failed; goto failed;
case CHANNEL_ERR_TOO_MANY_HTLCS: case CHANNEL_ERR_TOO_MANY_HTLCS:
failcode = WIRE_TEMPORARY_CHANNEL_FAILURE; failcode = WIRE_TEMPORARY_CHANNEL_FAILURE;
failmsg = tal_fmt(inmsg, "Too many HTLCs"); failstr = "Too many HTLCs";
goto failed; goto failed;
} }
/* Shouldn't return anything else! */ /* Shouldn't return anything else! */
abort(); abort();
failed: failed:
msg = towire_channel_offer_htlc_reply(NULL, 0, failcode, (u8*)failmsg); msg = towire_channel_offer_htlc_reply(NULL, 0, failcode, failstr);
wire_sync_write(MASTER_FD, take(msg)); wire_sync_write(MASTER_FD, take(msg));
} }

7
lightningd/peer_htlcs.c

@ -364,7 +364,7 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU
struct htlc_out *hout) struct htlc_out *hout)
{ {
u16 failure_code; u16 failure_code;
u8 *failurestr; char *failurestr;
struct lightningd *ld = subd->ld; struct lightningd *ld = subd->ld;
if (!fromwire_channel_offer_htlc_reply(msg, msg, if (!fromwire_channel_offer_htlc_reply(msg, msg,
@ -380,10 +380,9 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU
if (failure_code) { if (failure_code) {
hout->failcode = (enum onion_type) failure_code; hout->failcode = (enum onion_type) failure_code;
if (hout->am_origin) { if (hout->am_origin) {
char *localfail = tal_fmt(msg, "%s: %.*s", char *localfail = tal_fmt(msg, "%s: %s",
onion_type_name(failure_code), onion_type_name(failure_code),
(int)tal_count(failurestr), failurestr);
(const char *)failurestr);
payment_failed(ld, hout, localfail); payment_failed(ld, hout, localfail);
} else if (hout->in) { } else if (hout->in) {

2
wallet/test/run-wallet.c

@ -103,7 +103,7 @@ bool fromwire_channel_got_commitsig(const tal_t *ctx UNNEEDED, const void *p UNN
bool fromwire_channel_got_revoke(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *revokenum UNNEEDED, struct secret *per_commitment_secret UNNEEDED, struct pubkey *next_per_commit_point UNNEEDED, struct fee_states **fee_states UNNEEDED, struct changed_htlc **changed UNNEEDED) bool fromwire_channel_got_revoke(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *revokenum UNNEEDED, struct secret *per_commitment_secret UNNEEDED, struct pubkey *next_per_commit_point UNNEEDED, struct fee_states **fee_states UNNEEDED, struct changed_htlc **changed UNNEEDED)
{ fprintf(stderr, "fromwire_channel_got_revoke called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_got_revoke called!\n"); abort(); }
/* Generated stub for fromwire_channel_offer_htlc_reply */ /* Generated stub for fromwire_channel_offer_htlc_reply */
bool fromwire_channel_offer_htlc_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *id UNNEEDED, u16 *failure_code UNNEEDED, u8 **failurestr UNNEEDED) bool fromwire_channel_offer_htlc_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *id UNNEEDED, u16 *failure_code UNNEEDED, wirestring **failurestr UNNEEDED)
{ fprintf(stderr, "fromwire_channel_offer_htlc_reply called!\n"); abort(); } { fprintf(stderr, "fromwire_channel_offer_htlc_reply called!\n"); abort(); }
/* Generated stub for fromwire_channel_sending_commitsig */ /* Generated stub for fromwire_channel_sending_commitsig */
bool fromwire_channel_sending_commitsig(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *commitnum UNNEEDED, struct fee_states **fee_states UNNEEDED, struct changed_htlc **changed UNNEEDED, struct bitcoin_signature *commit_sig UNNEEDED, secp256k1_ecdsa_signature **htlc_sigs UNNEEDED) bool fromwire_channel_sending_commitsig(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *commitnum UNNEEDED, struct fee_states **fee_states UNNEEDED, struct changed_htlc **changed UNNEEDED, struct bitcoin_signature *commit_sig UNNEEDED, secp256k1_ecdsa_signature **htlc_sigs UNNEEDED)

Loading…
Cancel
Save