-
Notifications
You must be signed in to change notification settings - Fork 477
Modify static buffer size via features #1872
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,3 +79,13 @@ ink-debug = [] | |
|
|
||
| # Disable the ink! provided global memory allocator. | ||
| no-allocator = ["ink_allocator/no-allocator"] | ||
|
|
||
| # Configurable sizes of the static buffer | ||
| 2GB-buffer = [] | ||
| 1GB-buffer = [] | ||
| 512MB-buffer = [] | ||
| 128MB-buffer = [] | ||
| 16MB-buffer = [] | ||
| 1MB-buffer = [] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 512kB-buffer = [] | ||
| 128kB-buffer = [] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Ignore build artifacts from the local tests sub-crate. | ||
| /target/ | ||
|
|
||
| # Ignore backup files creates by cargo fmt. | ||
| **/*.rs.bk | ||
|
|
||
| # Remove Cargo.lock when creating an executable, leave it for libraries | ||
| # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
| Cargo.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| [package] | ||
| name = "static_buffer" | ||
| version = "4.2.0" | ||
| authors = ["Parity Technologies <admin@parity.io>"] | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| ink = { path = "../../crates/ink", default-features = false, features = ["512kB-buffer"]} | ||
|
|
||
| scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } | ||
| scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } | ||
|
|
||
| [dev-dependencies] | ||
| ink_e2e = { path = "../../crates/e2e" } | ||
|
|
||
| [lib] | ||
| path = "lib.rs" | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "ink/std", | ||
| "scale/std", | ||
| "scale-info/std", | ||
| ] | ||
| ink-as-dependency = [] | ||
| e2e-tests = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Static buffer configuration demo | ||
|
|
||
| This is a dummy contract illustrating how the [static buffer](/ARCHITECTURE.md#communication-with-the-pallet) | ||
| can be be configured using the crate features. | ||
|
|
||
| Right now we offer these set of sizes and their corresponding features: | ||
| ```toml | ||
| # Configurable sizes of the static buffer | ||
| 2GB-buffer = [] | ||
| 1GB-buffer = [] | ||
| 512MB-buffer = [] | ||
| 128MB-buffer = [] | ||
| 16MB-buffer = [] | ||
| 1MB-buffer = [] | ||
| 512kB-buffer = [] | ||
| 128kB-buffer = [] | ||
| ``` | ||
|
|
||
| You can configure the buffer size by using one of the features: | ||
| ```toml | ||
| ink = { path = "../../crates/ink", default-features = false, features = ["512kB-buffer"]} | ||
| ``` | ||
|
|
||
| Otherwise, the default size of 16 kB is used. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #![cfg_attr(not(feature = "std"), no_std, no_main)] | ||
|
|
||
| #[ink::contract] | ||
| pub mod static_buffer { | ||
| #[ink(storage)] | ||
| pub struct StaticBuffer { | ||
| value: bool, | ||
| } | ||
|
|
||
| impl StaticBuffer { | ||
| /// Creates a new flipper smart contract initialized with the given value. | ||
| #[ink(constructor)] | ||
| pub fn new(init_value: bool) -> Self { | ||
| Self { value: init_value } | ||
| } | ||
|
|
||
| /// Creates a new flipper smart contract initialized to `false`. | ||
| #[ink(constructor)] | ||
| pub fn new_default() -> Self { | ||
| Self::new(Default::default()) | ||
| } | ||
|
|
||
| /// Returns the configured size of the static buffer. | ||
| #[ink(message)] | ||
| pub fn get_size(&self) -> u128 { | ||
| ink::env::STATIC_BUFFER_SIZE as u128 | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[ink::test] | ||
| fn off_chain_buffer_size() { | ||
| let instance = StaticBuffer::new_default(); | ||
| let expected_size: u128 = 1 << 19; // 512 kB | ||
| assert_eq!(instance.get_size(), expected_size); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(all(test, feature = "e2e-tests"))] | ||
| mod e2e_tests { | ||
| use super::*; | ||
| use ink_e2e::ContractsBackend; | ||
|
|
||
| type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>; | ||
|
|
||
| #[ink_e2e::test] | ||
| async fn on_chain_buffer_size<Client: E2EBackend>( | ||
| mut client: Client, | ||
| ) -> E2EResult<()> { | ||
| // given | ||
| let constructor = StaticBufferRef::new(false); | ||
| let contract = client | ||
| .instantiate("static_buffer", &ink_e2e::alice(), constructor, 0, None) | ||
| .await | ||
| .expect("instantiate failed"); | ||
| let call = contract.call::<StaticBuffer>(); | ||
|
|
||
| // then | ||
| let get = call.get_size(); | ||
| let get_res = client.call_dry_run(&ink_e2e::bob(), &get, 0, None).await; | ||
| let expected_size: u128 = 1 << 19; // 512 kB | ||
| assert_eq!(get_res.return_value(), expected_size); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
| } |
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.

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.
It says that memory is to huge:
