-
Notifications
You must be signed in to change notification settings - Fork 895
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
Different error when trying to pay an invoice from another network #3100
Conversation
In theory, there may exist some node that bridges different networks and (if the networks use different assets) offer cross-asset swaps, so we cannot rule out the possibility that we can, in fact, pay the invoice of another network from our own network. Though I suppose in a practical sense, since it is not practically doable yet, we could indeed just do this check.
|
Yeah, my goal is actually to code a demo for multi-chain payments. The idea for the first demo is quite simple:
EDIT: this is kind of similar to "Trampoline Payments" from the little a know about them.
Thanks, I guess that's another possibility. I was thinking on just doing the same check there if I can somehow call get_blockchains from there. |
7351919
to
72592b5
Compare
Technically, we are doing this wrong. What is encoded on the A counterargument to doing this in Perhaps a better way would be to expose the supported currencies by adding a |
We should still allow decodepay to decode the invoice, even if for a different network. However, for simplicity, we should simply reject the invoice if the currency does not match our current one. @ZmnSCPxj makes a valid point, but we'd need to revisit this entirely if we were to allow such transparent cross-chain swaps. |
ie. the change is a one-liner in json_pay in if (b11->chain != chainparams)
return command_fail(cmd, PAY_ROUTE_NOT_FOUND, "Invoice is for another network %s", b11->chain->network_name); |
Well, the confidence will be reflected in the BTC:LBTC exchange rate. Perfect confidence would mean I guess 1:1, but it could deviate from that for other reasons. But I think that's out of scope for this. I think invoices in liquid should use some other bip173 prefix simply because it is another chain, otherwise the chain would need Yes, also there's chains like those created with elements that can have multiple assets.
That make sense. I don't know what place would be best to check whether the invoice is for the chain supported by this node or not, before trying to route anything.
or other prefixes for other chains, they're not currencies, they're chains, and the prefixes are already in: https://github.com/ElementsProject/lightning/blob/master/bitcoin/chainparams.c I mean, if there's any other PR on supporting multiple currencies, even if it is within a single chain, by all means ping me for review and testing. |
Sorry, @rustyrussell for some reason I didn't see your comments. Moved the check from json_decodepay in invoice.c to plugins/pay.c as originally intended and suggested by rusty. |
1692d4f
to
5b6d2a1
Compare
@@ -1043,6 +1043,10 @@ static struct command_result *json_pay(struct command *cmd, | |||
"Invalid bolt11: %s", fail); | |||
} | |||
|
|||
if (b11->chain != chainparams) { | |||
return command_fail(cmd, PAY_ROUTE_NOT_FOUND, "Invoice is for another network %s", b11->chain->network_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that b11->chain
may be NULL if we don't recognize the network name.
lightning/bitcoin/chainparams.c
Lines 233 to 241 in 0985c6e
const struct chainparams *chainparams_by_bip173(const char *bip173_name) | |
{ | |
for (size_t i = 0; i < ARRAY_SIZE(networks); i++) { | |
if (streq(bip173_name, networks[i].bip173_name)) { | |
return &networks[i]; | |
} | |
} | |
return NULL; | |
} |
As is a user could be tricked into parsing an invoice for an unknown network and then crash. Please use the bip173 prefix extracted from the invoice instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right, that's true.
But that would require parsing the bolt11 twice and if the chain is unknown, there's really nothing else to do.
I'm going to simply check if it's null a return an unknown network error if so, that seems simpler.
5b6d2a1
to
5008c9b
Compare
Updated fixing @cdecker 's nit, but in a different way to what he suggested. Hopefully this is fine. |
ACK 5008c9b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 5008c9b
To test this only with a bitcoind, I think it would be nice to have something like bitcoin/bitcoin#17037 merged on bitcoin core.
Or bitcoin/bitcoin#17032 :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spelling correction only
5008c9b
to
0a69c56
Compare
Fixed spelling error. |
ACK 0a69c56 |
When trying to pay an invoice from another network, I get the error message 'Could not find a route' (code 205).
That's not bad, it has to fail trying to find a route indeed.
But I think it would be nicer if it returned an error explicitly pointing out that the invoice to pay doesn't correspond with the network/chain this node is operating with.
The code I have doesn't seem to be working though, so any advice on this is very welcomed, assuming of course the concept makes sense in the first place.
I'm testing this with jtimon/multi-ln-demo#4
This is where I check the error: https://github.com/jtimon/multi-ln-demo/blob/master/multiln/bin/demo.py#L114
I don't expect people to run that, but I'm basically using the method pay() from contrib/pylightning.
I'm confused because pay seems to be a plugin and not have the normal cmd argument with which to call get_chainparams().
Again, any tips welcomed.