willygroup opened issue #3315:
Is there a way to add some fuel units to the consumed fuel?
I would like "to charge" the calls to my host functions.
Thanks a lot for your work!
willygroup edited issue #3315:
Is there a way to add some fuel units to the consumed fuel?
I would like "to charge" the calls to my host functions.
And why a function that uses an host function to store a Vec<u8> consumes about 10-20 times fuel that a function that uses another host function to load the same data
Thanks a lot for your work!
alexcrichton commented on issue #3315:
By units, do you mean a meaning to the number used to inject fuel? If so that doesn't really have any units per-se and the exact calculation of what fuel is is somewhat fuzzy. It somewhat corresponds to wasm instructions, but not always precisely so.
Fuel is not consumed by host functions, though, other than the
call
instruction used to enter host code. Different host code should always look like it consumes the same amount of fuel. Can you describe the situation in which you're seeing two host functions consume different amounts of fuel?
bjorn3 commented on issue #3315:
I think @willygroup wants different host functions to consume specific amounts of fuel determined by said host function.
alexcrichton commented on issue #3315:
Ah I think I misread. @willygroup is it accurate to say that you're basically asking for an API to manually consume fuel from the store? Something like
Store::consume_fuel(&mut self, amt: u64) -> Result<u64, Trap>
where theResult
is an error if fuel ran out and otherwise the remaining fuel is returned? (or something like that)
willygroup commented on issue #3315:
@alexcrichton yes, I was thinking just such a thing.
willygroup edited a comment on issue #3315:
@alexcrichton yes, I was thinking just such a thing.
Also I have a strange situation where I have a host function calling me a method of another wasm and I have to find a method to manage the total fuel consumption.
willygroup commented on issue #3315:
And why a function that uses an host function to store a Vec consumes about 10-20 times fuel that a function that uses another host function to load the same data
Any hints for this?
To test it, I've written a small wasm with 3 methods:
- store(data_addr: i32, data_size: i32)
- the data is stored on the memory from the host before thestore
call- load() -> i64
- return an i64 as combination of i32 address ant i32 size of the return data slicethat use 2 host function:
- store_data(key: &str, data: Vec<u8>)
- load_data(key: &str) -> Vec<u8>
Vec<u8> are passed as memory address and memory sizeThe fuel consumed by these methods is the following:
- store data: 100bytes ### FUEL CONSUMED: 6_995
- load data: 100bytes ### FUEL CONSUMED: 18_971
- store data: 50KB ### FUEL CONSUMED: 855_692
- load data: 50KB ### FUEL CONSUMED: 6_589_590
- store data: 100KB ### FUEL CONSUMED: 1_705_726
- load data: 100KB ### FUEL CONSUMED: 13_726_190
Thanks a lot!
willygroup edited a comment on issue #3315:
@alexcrichton yes, I was thinking just such a thing.
Also I have a strange situation where I have a host function calling a method of another wasm (I've implemented nested calls) and I have to find a method to manage the total fuel consumption.
alexcrichton closed issue #3315:
Is there a way to add some fuel units to the consumed fuel?
I would like "to charge" the calls to my host functions.
And why a function that uses an host function to store a Vec<u8> consumes about 10-20 times fuel that a function that uses another host function to load the same data
Thanks a lot for your work!
Last updated: Nov 22 2024 at 16:03 UTC