-
Notifications
You must be signed in to change notification settings - Fork 45
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
probe payment as sanity check #260
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da1fe17
policy: be able to set MinSwapAmountMsat
YusukeShimizu da8ecf3
test: swap in StuckChannels
YusukeShimizu e5cbb6b
swap: probe payment as sanity check
YusukeShimizu 5c30387
testframework: verify that route is constructed
YusukeShimizu dbec5bb
swap: restored sanity check
YusukeShimizu a6af654
cln: uses the exact channel to probe payment
YusukeShimizu 52e2ff3
cln: Fix typo in probe payment
YusukeShimizu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,35 +259,6 @@ func (cl *ClightningClient) getMaxHtlcAmtMsat(scid, nodeId string) (uint64, erro | |
return htlcMaximumMilliSatoshis, nil | ||
} | ||
|
||
// SpendableMsat returns an estimate of the total we could send through the | ||
// channel with given scid. Falls back to the owned amount in the channel. | ||
func (cl *ClightningClient) SpendableMsat(scid string) (uint64, error) { | ||
scid = lightning.Scid(scid).ClnStyle() | ||
var res ListPeerChannelsResponse | ||
err := cl.glightning.Request(ListPeerChannelsRequest{}, &res) | ||
if err != nil { | ||
return 0, err | ||
} | ||
for _, ch := range res.Channels { | ||
if ch.ShortChannelId == scid { | ||
if err = cl.checkChannel(ch); err != nil { | ||
return 0, err | ||
} | ||
maxHtlcAmtMsat, err := cl.getMaxHtlcAmtMsat(scid, cl.nodeId) | ||
if err != nil { | ||
return 0, err | ||
} | ||
// since the max htlc limit is not always set reliably, | ||
// the check is skipped if it is not set. | ||
if maxHtlcAmtMsat == 0 { | ||
return ch.GetSpendableMsat(), nil | ||
} | ||
return min(maxHtlcAmtMsat, ch.GetSpendableMsat()), nil | ||
} | ||
} | ||
return 0, fmt.Errorf("could not find a channel with scid: %s", scid) | ||
} | ||
|
||
func min(x, y uint64) uint64 { | ||
if x < y { | ||
return x | ||
|
@@ -619,6 +590,63 @@ func (cl *ClightningClient) GetPeers() []string { | |
return peerlist | ||
} | ||
|
||
// ProbePayment trying to pay via a route with a random payment hash | ||
// that the receiver doesn't have the preimage of. | ||
// The receiver node aren't able to settle the payment. | ||
// When the probe is successful, the receiver will return | ||
// a incorrect_or_unknown_payment_details error to the sender. | ||
func (cl *ClightningClient) ProbePayment(scid string, amountMsat uint64) (bool, string, error) { | ||
var res ListPeerChannelsResponse | ||
err := cl.glightning.Request(ListPeerChannelsRequest{}, &res) | ||
if err != nil { | ||
return false, "", fmt.Errorf("ListPeerChannelsRequest() %w", err) | ||
} | ||
var channel PeerChannel | ||
for _, ch := range res.Channels { | ||
if ch.ShortChannelId == lightning.Scid(scid).ClnStyle() { | ||
if err := cl.checkChannel(ch); err != nil { | ||
return false, "", err | ||
} | ||
channel = ch | ||
} | ||
} | ||
|
||
route, err := cl.glightning.GetRoute(channel.PeerId, amountMsat, 1, 0, cl.nodeId, 0, nil, 1) | ||
if err != nil { | ||
return false, "", fmt.Errorf("GetRoute() %w", err) | ||
} | ||
preimage, err := lightning.GetPreimage() | ||
if err != nil { | ||
return false, "", fmt.Errorf("GetPreimage() %w", err) | ||
} | ||
paymentHash := preimage.Hash().String() | ||
_, err = cl.glightning.SendPay( | ||
route, | ||
paymentHash, | ||
"", | ||
amountMsat, | ||
"", | ||
"", | ||
0, | ||
) | ||
if err != nil { | ||
return false, "", fmt.Errorf("SendPay() %w", err) | ||
} | ||
_, err = cl.glightning.WaitSendPay(paymentHash, 0) | ||
if err != nil { | ||
pe, ok := err.(*glightning.PaymentError) | ||
if !ok { | ||
return false, "", fmt.Errorf("WaitSendPay() %w", err) | ||
} | ||
faiCodeWireIncorrectOrUnknownPaymentDetails := 203 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: typo |
||
if pe.RpcError.Code != faiCodeWireIncorrectOrUnknownPaymentDetails { | ||
log.Debugf("send pay would be failed. reason:%w", err) | ||
return false, pe.Error(), nil | ||
} | ||
} | ||
return true, "", nil | ||
} | ||
|
||
type Glightninglogger struct { | ||
plugin *glightning.Plugin | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I fail to see the reason in choosing a route that core lightning constructs for us? Should we not construct the route that uses the exact channel for probing that we also use for the payment?
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.
Yes, I agree with your suggestion.
Like
PayInvoiceViaChannel
, I have modified to ensure that invoice payments are probed through a direct channel to peers.