Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't return incorrect_or_unknown_payment_details from htlc_accepted #4070

Closed
fiatjaf opened this issue Sep 21, 2020 · 3 comments · Fixed by #4084
Closed

Can't return incorrect_or_unknown_payment_details from htlc_accepted #4070

fiatjaf opened this issue Sep 21, 2020 · 3 comments · Fixed by #4084
Assignees
Labels
state::fixed These issues should have been addressed. Pending confirmation by OP, will close soon otherwise

Comments

@fiatjaf
Copy link
Contributor

fiatjaf commented Sep 21, 2020

Issue and Steps to Reproduce

I'm returning failure code 16399 from htlc_accepted (which corresponds to INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS), but this message is showing up in the logs:

**BROKEN** lightningd: htlc_accepted_hook plugin returned failure_code 16399, turning to WIRE_TEMPORARY_NODE_FAILURE

I must return that error specifically because it is expected by a bunch of softly-malicious wallets that perform pre-payment probes automatically on every payment using unknown hashes and expect that exact failure code in order to continue with the payment proper.

getinfo output

{
   "id": "02c16cca44562b590dd279c942200bdccfd4f990c3a69fad620c10ef2f8228eaff",
   "alias": "@lntxbot",
   "color": "296683",
   "num_peers": 22,
   "num_pending_channels": 1,
   "num_active_channels": 16,
   "num_inactive_channels": 1,
   "address": [
      {
         "type": "ipv6",
         "address": "2a01:4f8:c0c:7b31::1",
         "port": 9735
      }
   ],
   "binding": [
      {
         "type": "ipv6",
         "address": "::",
         "port": 9735
      },
      {
         "type": "ipv4",
         "address": "0.0.0.0",
         "port": 3597
      }
   ],
   "version": "v0.8.0-1168-g95294e2-modded",
   "blockheight": 649312,
   "network": "bitcoin",
   "msatoshi_fees_collected": 31725172,
   "fees_collected_msat": "31725172msat",
   "lightning-dir": "/home/fiatjaf/.lightning/bitcoin"
}
@cdecker cdecker self-assigned this Sep 22, 2020
cdecker added a commit to cdecker/lightning that referenced this issue Sep 23, 2020
We added a conversion of failcodes that do not have sufficient information in
faac4b2. That means that a failcode that'd require additional information
in order to be a correct error to return in an onion is mapped to a generic
one since we can't backfill the information.

This tests that the mapping is performed correctly and replicates the
situation in ElementsProject#4070
@cdecker
Copy link
Member

cdecker commented Sep 23, 2020

I'm assuming that you are returning a {"result": "fail", "failure_code": "400F"}, which uses the deprecated failure_code key instead of the newer failure_message. If this is the case then this is working as expected:

lightningd cannot build a value error from just the failcode, since some errors require additional information (in the case of PERM|15 the payload consists of a htlc_msat and a height which is not specified by just returning the 2 byte failcode 400F). Since the error message is not specification compliant without the payload we opted to map errors with incomplete payloads to a generic NODE|2, which does not require a payload to be valid:

static u8 *convert_failcode(const tal_t *ctx,
struct lightningd *ld,
unsigned int failure_code)
{
switch (failure_code) {
case WIRE_INVALID_REALM:
return towire_invalid_realm(ctx);
case WIRE_TEMPORARY_NODE_FAILURE:
return towire_temporary_node_failure(ctx);
case WIRE_PERMANENT_NODE_FAILURE:
return towire_permanent_node_failure(ctx);
case WIRE_REQUIRED_NODE_FEATURE_MISSING:
return towire_required_node_feature_missing(ctx);
case WIRE_CHANNEL_DISABLED:
return towire_channel_disabled(ctx);
case WIRE_PERMANENT_CHANNEL_FAILURE:
return towire_permanent_channel_failure(ctx);
case WIRE_REQUIRED_CHANNEL_FEATURE_MISSING:
return towire_required_channel_feature_missing(ctx);
case WIRE_UNKNOWN_NEXT_PEER:
return towire_unknown_next_peer(ctx);
default:
log_broken(ld->log,
"htlc_accepted_hook plugin returned failure_code %u,"
" turning to WIRE_TEMPORARY_NODE_FAILURE",
failure_code);
return towire_temporary_node_failure(ctx);
}
}

If you want to return PERM|15 = 16399 you have to return {"result": "fail", "failure_code": "400F010203040506070809000102"} which is a fully valid error message with htlc_msat=0102030405060708 and height=09000102.

I added #4084 to replicate this behavior and make sure it's correct.

@cdecker cdecker added the state::fixed These issues should have been addressed. Pending confirmation by OP, will close soon otherwise label Sep 23, 2020
cdecker added a commit to cdecker/lightning that referenced this issue Sep 23, 2020
We added a conversion of failcodes that do not have sufficient information in
faac4b2. That means that a failcode that'd require additional information
in order to be a correct error to return in an onion is mapped to a generic
one since we can't backfill the information.

This tests that the mapping is performed correctly and replicates the
situation in ElementsProject#4070
@rustyrussell
Copy link
Contributor

Note that you should be doing development with 'enable-deprecated-apis=false' so you'd find such depreciation before it bites you...

rustyrussell pushed a commit that referenced this issue Sep 24, 2020
We added a conversion of failcodes that do not have sufficient information in
faac4b2. That means that a failcode that'd require additional information
in order to be a correct error to return in an onion is mapped to a generic
one since we can't backfill the information.

This tests that the mapping is performed correctly and replicates the
situation in #4070
@fiatjaf
Copy link
Contributor Author

fiatjaf commented Sep 24, 2020

Thank you very much for clarifying!

vibhaa pushed a commit to spider-pcn/lightning that referenced this issue Mar 24, 2021
We added a conversion of failcodes that do not have sufficient information in
faac4b2. That means that a failcode that'd require additional information
in order to be a correct error to return in an onion is mapped to a generic
one since we can't backfill the information.

This tests that the mapping is performed correctly and replicates the
situation in ElementsProject#4070
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state::fixed These issues should have been addressed. Pending confirmation by OP, will close soon otherwise
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants