The FuncNotAllowed requires a target.
Since we don't really have a target when spawning, I've ended up the FuncNotCtor
Removal of Imports dependency
Initially, the Runtime expected external imports.
Back then, we thought that Global-State-related host functions would be implemented within the go-spacemesh.
Since then, the Global State has been moved to the Rust land, so we ended up with having setting empty imports as a parameter when initializing the Runtime
Moved Template Pricing to another file
I created TemplatePriceCache to act as the cache for the Template Pricing.
The Runtime expects now that cache as a dependency upon initialization.
In practice, it'd be ideal to have only a single cache used throughout the process lifetime.
Added GasTank
I thought it would make the code more readable if the repeating pattern of checking whether we've enough gas during will be less explicit and noisy in the code.
I've also added two helpers: check_gas_for_payload and check_gas_for_func.
Both expect a paramere named gas_left and its type of GasTank.
Each helper checks first whether there is any gas in the tank and returns immediately if the tank is empty.
The GasTank could have been an Option<u64>, but I think it's nicer as it's now.
Other
Renamed ProtectedMode to AccessMode (also added ImmutableOnly option for the future).
Removed in the exec function the creation of AccountStorage for the target - it seems unnecessary. If the target doesn't exist, we should fail (to be done in a separate PR)
Added more TODO under src/runtime/runtime.rs
Might be better to review src/runtime/runtime.rs in the editor.
I want to refactor the
Runtime
of SVM.Here are the changes done on this one:
Adding
RuntimeError::FuncNotCtor
The
FuncNotAllowed
requires atarget
. Since we don't really have atarget
when spawning, I've ended up theFuncNotCtor
Removal of
Imports
dependencyInitially, the
Runtime
expected external imports. Back then, we thought thatGlobal-State
-related host functions would be implemented within thego-spacemesh
. Since then, theGlobal State
has been moved to the Rust land, so we ended up with having setting emptyimports
as a parameter when initializing theRuntime
Moved
Template Pricing
to another fileI created
TemplatePriceCache
to act as the cache for theTemplate Pricing
. TheRuntime
expects now that cache as a dependency upon initialization. In practice, it'd be ideal to have only a single cache used throughout the process lifetime.Added
GasTank
I thought it would make the code more readable if the repeating pattern of checking whether we've enough gas during will be less explicit and noisy in the code.
I've also added two helpers:
check_gas_for_payload
andcheck_gas_for_func
. Both expect a paramere namedgas_left
and its type ofGasTank
. Each helper checks first whether there is anygas in the tank
and returns immediately if the tank is empty.The
GasTank
could have been anOption<u64>,
but I think it's nicer as it's now.Other
ProtectedMode
toAccessMode
(also addedImmutableOnly
option for the future).exec
function the creation ofAccountStorage
for thetarget
- it seems unnecessary. If the target doesn't exist, we should fail (to be done in a separate PR)TODO
undersrc/runtime/runtime.rs
src/runtime/runtime.rs
in the editor.