lightninglabs / lightninglabs/aperture
L402: streaming response gRPC calls don't support creating L402 token
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 268
- Forks
- 78
- Avg merge
- 22h 25m
- Merged PRs (30d)
- 1
Description
For some reason, when the server sends back the `402 payment required` response code if the user doesn't already have an L402 token, the [client interceptor code](https://github.com/lightninglabs/aperture/blob/709463fe5b01b0aa4c0c60b3a8eabdfbe6db4ee6/l402/client_interceptor.go#L172) doesn't detect that properly and doesn't attempt to create a token, resulting in a terminal error.
It is yet unclear where exactly the problem lies, the following possibilities come to mind:
- The server's response status fields aren't set correctly for the client interceptor to recognize: https://github.com/lightninglabs/aperture/blob/b1b0dc557071fffd1580772a006037e8a4f6203b/proxy/proxy.go#L466. Perhaps the gRPC/HTTP/2 specific trailer fields need to be used?
- The client library just doesn't look for the response code [in the right place](https://github.com/lightninglabs/aperture/blob/709463fe5b01b0aa4c0c60b3a8eabdfbe6db4ee6/l402/client_interceptor.go#L195) (it interprets the error from the stream interceptor, but perhaps it needs to look at response header/trailer fields?)
- This is a limitation of the gRPC Golang library itself and cannot be fixed easily.
In any case, it should be pretty straightforward to set up a new unit test (taking https://github.com/lightninglabs/aperture/blob/b1b0dc557071fffd1580772a006037e8a4f6203b/proxy/proxy_test.go#L322 as a template) that executes the streaming case and allows for local debugging of the issue.
## Workarounds
The current workaround in most Lightning Labs application is to make sure we call a non-streaming (unary) gRPC method first, which then triggers the L402 token creation and allows subsequent streaming gRPC methods to work.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the client interceptor in l402/client_interceptor.go and the response handling in proxy/proxy.go, then use proxy/proxy_test.go around the referenced test as a template for a streaming case. Debug where the 402 status is exposed to the interceptor; done means a streaming call without an L402 token detects the response and creates one instead of returning a terminal error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, grpc
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100