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
Fix length limit in ExternalStorage.get #241
Conversation
The gas consumption changes slightly by this. This makes sense, since every 64 KiB the Wasm code needs to grow the dynamic memory by one page, which is a Wasm instruction.
I don't rebuild the test contract now to avoid conflicts with other open PRs. But it works locally. |
100 gas to change alloc from 2kb to 128kb seems quite cheap. |
Happy if you can merge in my iterator PR and then rebuild the test contracts, then we should be good to merge. |
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.
Looks good. And nice solution to the issue.
I would adjust some of the values, but otherwise good.
packages/std/src/imports.rs
Outdated
@@ -148,8 +155,8 @@ impl Iterator for ExternalIterator { | |||
type Item = KV; | |||
|
|||
fn next(&mut self) -> Option<Self::Item> { | |||
let key_ptr = alloc(MAX_READ); | |||
let value_ptr = alloc(MAX_READ); | |||
let key_ptr = alloc(RESULT_BUFFER_LENGTH); |
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.
Key_ptr can be FAR FAR less than 128KB.
I think making another constant for this and setting it to eg 2KB is more than overkill.
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.
Is there any specific reason to make such assumptions? I mean, an application could choose to store all its data in keys with empty values. Why not? Just because this does not happen in the average case, should we make more restrictions than necessary?
In any case, I think it is good to have separate constants. Created
/// The number of bytes of the memory region we pre-allocate for the result data in ExternalIterator.next
static DB_READ_KEY_BUFFER_LENGTH: usize = 64 * KI;
now to prove the point that they are independent. Happy to change the value to something small if there is a good reason to.
d0ef4a2
to
76e1972
Compare
76e1972
to
d704f68
Compare
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.
nice work
Closes #126
ExternalStorage.get_with_result_length
. This is inconvenient by design as it is not included in the Storage trait.The usability of this change in blockchains is limited by CosmWasm/wasmvm#59