-
Notifications
You must be signed in to change notification settings - Fork 115
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
PassAll
gas option for program to program calls
#1417
base: main
Are you sure you want to change the base?
Conversation
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 think this PR's functionality is important but I don't think a Gas
enum is the best way to do it. It seems much more intuitive to have gas be a field of context
. This way we can keep the u64 type(which is nice for dev experience and contract readability) and also have access to the actual amount of gas via the context
.
Good point @samliok ! Thanks |
Actually I'm not sure if that's totally correct. We already have the |
} | ||
} | ||
|
||
pub fn with_max_units(mut self, units: u64) -> Self { |
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 would be great if this function could only accept units that are > 0, there might be some semantic changes to do
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.
Otherwise, replicate the Gas
enum type on the go side too so that when it's the Unit
variant then it's only interpreted as "pass x units" even when it's 0 to avoid any runtime panic because of the conversion from a u64
to a NonZeroU64
.
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.
We might also want to replace the call_contract
function by a function that only accepts the Address
, function_name
, args
.
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.
To keep being explicit on the gas forwarding, having a function named with_max_units(u64)
and with_pass_all_gas()
would make sense. The default behaviour could be to use Gas::PassAll
, so the with_pass_all_gas
could be ignored.
// true if the call passes all gas | ||
PassAll bool | ||
|
||
// the maximum amount of fuel allowed to be consumed by wasm for this call | ||
Fuel uint64 |
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.
Would be interested to know if there could be a cleaner solution. Currently there is a bool and the uint64 that tells the amount of fuel passed, but since having PassAll = true
and Fuel > 0
is inconsistent state, this has to be validated through the execution. Is there a better way to simulate this rust enum:
enum Gas {
PassAll,
Units(u64)
}
Passing the units of gas to program highest-level calls to the simulator is still required. We might want to set the units of gas in the simulator initialisation but that sounds a little out of scope for this PR. |
Closes #1184
Create a new
Gas
type that replaces the current alias by an enum that can either bePassAll
orUnits(NonZeroU64)
. The newPassAll
works around the current way of spending gas, namely callingConsumeFuel
with the passedFuel
parameter and refunding any unused gas by callingAddFuel
after the execution.