-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
multi: add BuildOnion, SendOnion, and TrackOnion RPCs #8907
base: master
Are you sure you want to change the base?
multi: add BuildOnion, SendOnion, and TrackOnion RPCs #8907
Conversation
Important Review skippedAuto reviews are limited to specific labels. Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
These will be used by the SendOnion RPC to communicate information about HTLCSwitch errors to RPC callers. Remote instantiations of the ChannelRouter will rely on error information via RPC to reconstruct error types needed during error handling. NOTE: This may move to an existing package eventually. Also, maybe there is a better way to do this?
Add RPC for dispatching payments via onions. The payment route and onion are computed by the caller and the onion is delivered to the server for forwarding. NOTE: The server does NOT process or peel the onion so it assumed that the onion will be constructed such that the first hop is encrypted to one of the server's channel partners.
Add RPC which constructs a sphinx onion packet for the given payment route. NOTE: This is added primarily to aid with the itests added later.
Allow the switch to defer error handling when callers of GetAttemptResult do not provide an error decrypter.
Add RPC to lookup the status of a previously forwarded onion. Allow callers of the TrackOnion rpc to indicate whether they would like to handle errors themselves or delegate error decryption to the server.
e6ef062
to
5b183a3
Compare
cc @starius |
|
||
// A code representing the type of error that occurred. This can be used | ||
// to programmatically distinguish between different kinds of errors. | ||
string error_code = 3; |
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.
Does it make sense to add an enum for this?
@@ -442,6 +449,46 @@ message SendToRouteResponse { | |||
lnrpc.Failure failure = 2; | |||
} | |||
|
|||
message SendOnionRequest { |
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 found a similar RPC in core-lightning: https://github.com/ElementsProject/lightning/blob/v24.08rc2/cln-grpc/proto/node.proto#L859-L872
Does it make sense to unify the APIs? Some fields have different names and some of core-lightning's fields do not exist in LND.
|
||
// HTLCSwitch contains shared logic between this sub server and the | ||
// main rpc server. | ||
// HtlcSwitch *htlcswitch.Switch |
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.
This line seems to be a commented code.
@@ -622,6 +626,76 @@ func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, attemptID uint64, | |||
return link.handleSwitchPacket(packet) | |||
} | |||
|
|||
// TranslateErrorForRPC converts an error from the underlying HTLC switch to | |||
// a form that we can package for delivery to SendOnion rpc clients. | |||
func TranslateErrorForRPC(err error) (string, string) { |
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.
Please add a unit test for the function.
|
||
// ParseForwardingError converts an error from the format in SendOnion rpc | ||
// protos to a forwarding error type. | ||
func ParseForwardingError(errStr string) (*ForwardingError, error) { |
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.
Please add a unit test for the function.
// key? This is untrusted input received via RPC. | ||
sessionKey, _ := btcec.PrivKeyFromBytes(sessionKeyBytes) | ||
|
||
var pubKeys []*btcec.PublicKey |
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 propose to preallocate the slice.
routesReq := &lnrpc.QueryRoutesRequest{ | ||
PubKey: dave.PubKeyStr, | ||
Amt: paymentAmt, | ||
// AmtMsat: paymentAmt, |
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.
Commented code.
Can we test with millisatoshis resolution?
Timelock: route.TotalTimeLock, | ||
PaymentHash: paymentHash, | ||
OnionBlob: onionResp.OnionBlob, | ||
AttemptId: 0, |
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 propose to use some other value just to check that it is passed correctly (0 is the default for integer types).
// resp, err := alice.RPC.SendOnion(onionReq) | ||
// require.NoError(ht, err, "unable to send payment via onion") |
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.
Commented code.
+1 for the suggestion in the note.
PaymentHash: paymentHash, | ||
SessionKey: onionResp.SessionKey, | ||
HopPubkeys: onionResp.HopPubkeys, | ||
// SharedSecrets: [][]byte, |
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.
IIUC SharedSecrets is not covered by any itest (this test and test testTrackOnion
).
I propose to add a test scenario testing this field.
Amount: lnwire.MilliSatoshi(req.Amount), | ||
Expiry: req.Timelock, | ||
PaymentHash: hash, | ||
OnionBlob: [1366]byte(req.OnionBlob), |
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 propose to replace 1366 with lnwire.OnionPacketSize.
return nil, status.Error(codes.InvalidArgument, | ||
"onion blob is required") | ||
} | ||
if len(req.OnionBlob) > lnwire.OnionPacketSize { |
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.
Is it ok for req.OnionBlob to be shorter than lnwire.OnionPacketSize? IIUC in our use case it is always exactly lnwire.OnionPacketSize. Can we check for exact length match (== lnwire.OnionPacketSize)?
@sputn1ck: review reminder |
Change Description
Initial exploration into possible approach for the addition of new SendOnion (and associated construction and tracking) RPCs to the daemon.
NOTE: This version of a SendOnion style RPC was influenced heavily by its intended use. How might the RPC change if it was to be utilized by users running a "normal" lnd deployment? Would the data persisted surrounding the forwarding of onions change (eg: perhaps the ControlTower would be involved in the flow)? What about with respect to error handling?
TODO
short_channel_id
on the server. Messed around with some htlcswitch package interfaces for this to try and keep access to link functionality limited and it might be worthy of another pass to consider the options here.