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

[bug]: REST FundChannel Method Incorrectly Implemented as GET Instead of POST and Does Not Work #1219

Closed
V0nMis3s opened this issue Nov 27, 2024 · 1 comment · Fixed by #1220
Assignees
Labels
bug Something isn't working REST

Comments

@V0nMis3s
Copy link

Background

The FundChannel method in the REST API is currently implemented as a GET method, but this is semantically incorrect as it performs a state-changing operation (funding a channel). Moreover, the GET implementation fails to function even when used as intended, returning a malformed public key error.

This issue renders the method unusable and violates RESTful principles. The method should be implemented as a POST and accept the FundChannelRequest object in the body of the request.

Your environment

tapcli getinfo
# tapd version: 0.4.1-alpha commit=v0.4.2-0.20240815180811-2110839696cb
# lnd version: 0.18.0-beta
# network: regtest

uname -mrsv
# inux 6.8.0-49-generic #49-Ubuntu SMP x86_64

bitcoind --version
# Bitcoin Core version v27.0

Steps to reproduce

  1. Start in integrated mode, and ensure it is running.
  2. Attempt to fund a channel using a GET request with query parameters:
curl -k -X GET \
  https://{host}:{port}/v1/taproot-assets/channels/fund \
  -H "Grpc-Metadata-macaroon: $(xxd -ps -c 10000 /path/to/admin.macaroon)" \
  -H "Content-Type: application/json" \
  --data-urlencode "asset_amount=100" \
  --data-urlencode "peer_pubkey=base64_pubkey" \
  --data-urlencode "asset_id=base64_asset_id="
  1. Observe the response:
{
  "code": 2,
  "message": "error parsing peer pubkey: malformed public key: invalid length: 0",
  "details": []
}
  1. Attempt the same operation as a POST request with the request body:
curl -k -X POST \
 https://{host}:{port}/v1/taproot-assets/channels/fund \
 -H "Grpc-Metadata-macaroon: $(xxd -ps -c 10000 /path/to/admin.macaroon)" \
 -H "Content-Type: application/json" \
 -d '{
       "asset_amount": "100",
       "peer_pubkey": "base64_pubkey",
       "asset_id": "base64_asset_id="
     }'

5.Observe the response:

{
  "code": 12,
  "message": "Method Not Allowed",
  "details": []
}

Expected behavior

The FundChannel method should:

  • Be implemented as a POST REST method.
  • Accept the FundChannelRequest object in the request body.
  • Successfully process the request and return a valid response.

Actual behavior

The current implementation:

  • Uses the GET method, which is semantically incorrect for a state-changing operation.
  • Fails to parse query parameters correctly, resulting in an error: "error parsing peer pubkey: malformed public key: invalid length: 0".
  • Does not work when attempted as a POST, returning "Method Not Allowed".

Possible Cause of the Issue

Default Behavior of grpc-gateway:
The gRPC-Gateway plugin maps RPC methods to HTTP methods (GET, POST, etc.) based on the request message's fields when no explicit google.api.http annotation is provided in the .proto file. In this case, the FundChannelRequest message contains scalar fields (e.g., uint64, bytes), which can be represented as query parameters. As a result, gRPC-Gateway defaults to mapping this RPC method to GET.

@GeorgeTsagk
Copy link
Member

Hey @V0nMis3s , thanks for flagging this, created a PR that converts the endpoint to POST

@GeorgeTsagk GeorgeTsagk self-assigned this Nov 27, 2024
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in Taproot-Assets Project Board Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working REST
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants