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

Add a "How-To" example for performing HTTP requests #3509

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

jvff
Copy link
Contributor

@jvff jvff commented Mar 8, 2025

Motivation

Performing HTTP requests from applications is an important feature for Linera. There are a few different ways for applications to perform them, and there are tradeoffs between these ways. Therefore, this feature should be documented and a "How-To" example demonstrating how to use and test the feature would be useful.

Proposal

Add an example that performs HTTP requests in all different ways, and test them.

Test Plan

Unit and integration tests were added to test not just the application, but also to serve as testing examples and to also test the HTTP allow-list.

Release Plan

  • Nothing to do, because this is just a new example being added to the repository.

Links

jvff added a commit that referenced this pull request Mar 9, 2025
## Motivation

For security reasons, we would like to initially limit the hosts that
applications can send HTTP requests to.

## Proposal

Add an allow-list of hosts to the `ResourceControlPolicy` configured by
a committee. Only perform HTTP requests in the execution state actor if
the target host is in the list.

## Test Plan

Tests that exercise the allow list were added in PR #3509.

## Release Plan

- Nothing to do / These changes follow the usual release cycle, because
this is a new feature that should be included in the next release and
testnet.

## Links

- [reviewer
checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
jvff added 3 commits March 9, 2025 03:45
For now it's an empty application with service support for GraphQL.
Allow the URL to use for the HTTP requests to be specified when the
application is created.
Allow the client to run the service in order to perform an HTTP request.
The status code is checked to be OK, the response headers discarded and
the response body returned to the caller.
@jvff jvff force-pushed the how-to-perform-http-requests-example branch from 2d7b1b5 to f6778af Compare March 9, 2025 03:52
@jvff jvff self-assigned this Mar 9, 2025
@jvff jvff added the enhancement New feature or request label Mar 9, 2025
@jvff jvff added this to the Testnet #2 milestone Mar 9, 2025
jvff added 3 commits March 9, 2025 04:07
Ensure that it returns the expected response.
Randomness is not supported inside pure Wasm targets.
Ensure that the service returns an error if the HTTP response is not OK.
@jvff jvff force-pushed the how-to-perform-http-requests-example branch from f6778af to 971dcb8 Compare March 9, 2025 04:22
jvff added 17 commits March 9, 2025 04:26
Use an ephemeral local HTTP server to test if the service can reach it.
Ensure that the service receives an error if it attempts to send an HTTP
request to a host that's not in the allow list.
Show the pattern where the contract verifies if an HTTP response
provided by an operation is valid.
The contract should successfully execute an operation with a valid
off-chain HTTP response.
Ensure that the contract panics if the off-chain HTTP response can't be
trusted.
The received response is sent to the contract to validate.
Ensure that the service schedules the operation with a received HTTP
response.
Ensure that it forwards the received HTTP response to the contract to
verify.
Ensure that if the service reaches an untrusted HTTP server, the
contract rejects the HTTP response.
Demonstrate how an HTTP request is made in the contract.
Add a unit test showing how to mock the response.
Ensure that the response is being verified.
Allow the service to request the contract to perform an HTTP request.
Ensure that the mutation schedules the operation for the contract.
And that it is accepted if the response is valid.
It should reject a response that it does not trust.
Request the service to perform an HTTP request for the contract,
returning only the relevant deterministic output.
jvff added 7 commits March 9, 2025 04:26
Demonstrate how to mock the expected service query.
A reminder that the oracle's HTTP response also needs to be verified.
Provide a mutation to create an operation that uses the service as an
oracle.
Ensure that it produces the operation for the contract to use the
service as an oracle.
Ensure that the service performs an HTTP request when it is called as an
oracle.
A reminder that the oracle's HTTP response also needs to be verified.
Describe the different ways HTTP requests can be made, and compare their
usages.
@jvff jvff force-pushed the how-to-perform-http-requests-example branch from 971dcb8 to ce3adba Compare March 9, 2025 04:26
@jvff jvff requested review from MathieuDutSik, ma2bd, afck, deuszx and Twey and removed request for MathieuDutSik March 9, 2025 04:59
@jvff jvff marked this pull request as ready for review March 9, 2025 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant