diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 866f054f6..87ef0e31d 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -302,8 +302,15 @@ invoice_check_payment(const tal_t *ctx, * - MUST fail the HTLC. * - MUST return an `incorrect_or_unknown_payment_details` error. */ - if (!wallet_invoice_find_unpaid(ld->wallet, &invoice, payment_hash)) + if (!wallet_invoice_find_unpaid(ld->wallet, &invoice, payment_hash)) { + log_debug(ld->log, "Unknown paid invoice %s", + type_to_string(tmpctx, struct sha256, payment_hash)); + if (wallet_invoice_find_by_rhash(ld->wallet, &invoice, payment_hash)) { + log_debug(ld->log, "ALREADY paid invoice %s", + type_to_string(tmpctx, struct sha256, payment_hash)); + } return NULL; + } details = wallet_invoice_details(ctx, ld->wallet, invoice); @@ -342,11 +349,22 @@ invoice_check_payment(const tal_t *ctx, if (details->msat != NULL) { struct amount_msat twice; - if (amount_msat_less(msat, *details->msat)) + if (amount_msat_less(msat, *details->msat)) { + log_debug(ld->log, "Attept to pay %s with amount %s < %s", + type_to_string(tmpctx, struct sha256, + &details->rhash), + type_to_string(tmpctx, struct amount_msat, &msat), + type_to_string(tmpctx, struct amount_msat, details->msat)); return tal_free(details); + } if (amount_msat_add(&twice, *details->msat, *details->msat) && amount_msat_greater(msat, twice)) { + log_debug(ld->log, "Attept to pay %s with amount %s > %s", + type_to_string(tmpctx, struct sha256, + &details->rhash), + type_to_string(tmpctx, struct amount_msat, details->msat), + type_to_string(tmpctx, struct amount_msat, &twice)); /* BOLT #4: * * - if the amount paid is more than twice the amount diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 641a325b2..3d6a0eead 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -283,10 +283,13 @@ void local_fail_in_htlc_needs_update(struct htlc_in *hin, } /* Helper to create (common) WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS */ -const u8 *failmsg_incorrect_or_unknown(const tal_t *ctx, - struct lightningd *ld, - const struct htlc_in *hin) +const u8 *failmsg_incorrect_or_unknown_(const tal_t *ctx, + struct lightningd *ld, + const struct htlc_in *hin, + const char *file, int line) { + log_debug(ld->log, "WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS: %s:%u", + file, line); return towire_incorrect_or_unknown_payment_details( ctx, hin->msat, get_block_height(ld->topology)); diff --git a/lightningd/peer_htlcs.h b/lightningd/peer_htlcs.h index c24f76555..6d786c510 100644 --- a/lightningd/peer_htlcs.h +++ b/lightningd/peer_htlcs.h @@ -81,7 +81,11 @@ void json_format_forwarding_object(struct json_stream *response, const char *fie const struct forwarding *cur); /* Helper to create (common) WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS */ -const u8 *failmsg_incorrect_or_unknown(const tal_t *ctx, - struct lightningd *ld, - const struct htlc_in *hin); +#define failmsg_incorrect_or_unknown(ctx, ld, hin) \ + failmsg_incorrect_or_unknown_((ctx), (ld), (hin), __FILE__, __LINE__) + +const u8 *failmsg_incorrect_or_unknown_(const tal_t *ctx, + struct lightningd *ld, + const struct htlc_in *hin, + const char *file, int line); #endif /* LIGHTNING_LIGHTNINGD_PEER_HTLCS_H */ diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index e7d426b0c..1d8e4ba9d 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -88,11 +88,12 @@ char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED, const struct chainparams *chainparams UNNEEDED, const u8 *scriptPubkey UNNEEDED) { fprintf(stderr, "encode_scriptpubkey_to_addr called!\n"); abort(); } -/* Generated stub for failmsg_incorrect_or_unknown */ -const u8 *failmsg_incorrect_or_unknown(const tal_t *ctx UNNEEDED, - struct lightningd *ld UNNEEDED, - const struct htlc_in *hin UNNEEDED) -{ fprintf(stderr, "failmsg_incorrect_or_unknown called!\n"); abort(); } +/* Generated stub for failmsg_incorrect_or_unknown_ */ +const u8 *failmsg_incorrect_or_unknown_(const tal_t *ctx UNNEEDED, + struct lightningd *ld UNNEEDED, + const struct htlc_in *hin UNNEEDED, + const char *file UNNEEDED, int line UNNEEDED) +{ fprintf(stderr, "failmsg_incorrect_or_unknown_ called!\n"); abort(); } /* Generated stub for fatal */ void fatal(const char *fmt UNNEEDED, ...) { fprintf(stderr, "fatal called!\n"); abort(); }