-
Notifications
You must be signed in to change notification settings - Fork 349
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
Make gas limit immutable in cosmwasm_vm::instance::Instance
#136
Conversation
The whole There is an open PR to make this much more intuitive (just As to reusing instances, I did this for performance. But actually disable the LRU by default now in We could also cache raw |
The good thing is that the mess is nicely encapsulated in
Created an issue for that: #137 |
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.
In general, the approach makes sense, but I think we need the other issue to make this work (wasmer::Instance in cache). Note the gas limit is set incorrectly after reading from cache
id: &[u8], | ||
deps: Extern<S, A>, | ||
gas_limit: u64, | ||
) -> Result<Instance<S, A>, Error> { | ||
let hash = WasmHash::generate(&id); | ||
|
||
// pop from lru cache if present |
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.
The issue with this PR, is that if I pull an Instance off the lru cache, it will have the same gas limit as the first time.
Try this, by running some code (with lru), get_instance the first time with a too low gas, and it fails. Then put it back on cache. Then try get_instance
with more than enough gas. I believe it will fail again as well.
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.
I am working on a dedicated test for the recovering after out of gas now.
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.
Done in 201829c
I guess this is unblocked by #140 Let me know if you finish it up / reimplememt |
ada2132
to
d5d0de9
Compare
d5d0de9
to
201829c
Compare
This is ready from my side |
cosmwasm_vm::instance::Instance
cosmwasm_vm::instance::Instance
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.
Lgtm
@@ -40,5 +40,10 @@ pub fn set_gas(instance: &mut Instance, limit: u64) { | |||
|
|||
pub fn get_gas(instance: &Instance) -> u64 { | |||
let used = metering::get_points_used(instance); | |||
GAS_LIMIT - used | |||
// when running out of gas, get_points_used can exceed GAS_LIMIT | |||
if used < GAS_LIMIT { |
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.
Safer for sure
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.
Without that, I got overflow crashes
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.
I did also months ago with huge values, but then just used smaller numbers and forgot about it. Good fix
deps: Extern<S, A>, | ||
gas_limit: u64, | ||
) -> Self { | ||
set_gas(&mut wasmer_instance, gas_limit); | ||
let res = Instance { |
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.
Yes. Looks proper
During review, I found it hard to follow test code that included
instance.set_gas
calls. This seems to be an unnatural use of an instance. I could easily rewrite the tests in a way that set the gas limit once and calculate diffs usingget_gas
.However, this PR does not work well together with the LRU cache. In
it is not possible to reset the gas limit due API I want to remove.
I wonder if you have a good design around this. Re-using an "instance" seems to be counter-intuitive. I was thinking about caching raw
wasmer_runtime_core::Instance
s. 👍/👎/thoughts?