pink: Example for larger HTTP response #1281
Closed
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.
Note
Don't merge. This PR shows an example of how to handle a bigger HTTP response.
In PR #1280, we have implemented support for batch HTTP requests and increased the HTTP response limit to 2MB. The following example is based on that PR.
Things not ready yet
At present, ink uses a static buffer with a hardcoded size of 16KB to exchange data across the boundary of the wasm virtual machine. The downstream contract does not have the ability to alter this configuration. Although a customizable solution has been proposed upstream, it has yet to be implemented. While we await their completion, we can implement a temporary solution by patching ink to expand the size of this static buffer.
cargo-contract is currently rigid in that it hardcodes the maximum available memory for the output WASM as 1MB. To overcome this, we've submitted a PR upstream to allow for runtime configuration. Until that PR is merged, we can use our fork of
cargo-contract
for compilation to bypass this limitation.Steps to build this example
cargo-contract
git clone https://github.com/kvinwang/cargo-contract cd cargo-contract git checkout max-memory cargo install --path crates/cargo-contract
git clone https://github.com/Phala-Network/phala-blockchain cd phala-blockchain/e2e/contracts/check_system git checkout big-http cargo contract build --max-memory-pages 32