Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Runtime Refactoring #435

merged 18 commits into from
Dec 13, 2021

Runtime Refactoring #435

merged 18 commits into from
Dec 13, 2021


Copy link

@YaronWittenstein YaronWittenstein commented Dec 9, 2021

I want to refactor the Runtime of SVM.

Here are the changes done on this one:

Adding RuntimeError::FuncNotCtor

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.


  • 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/
  • Might be better to review src/runtime/ in the editor.

@YaronWittenstein YaronWittenstein self-assigned this Dec 9, 2021
@YaronWittenstein YaronWittenstein added the dependencies Pull requests that update a dependency file label Dec 10, 2021
@YaronWittenstein YaronWittenstein changed the title Runtime refactor Runtime refactoring Dec 10, 2021
@YaronWittenstein YaronWittenstein added refactoring Refactoring and removed dependencies Pull requests that update a dependency file labels Dec 10, 2021
@YaronWittenstein YaronWittenstein marked this pull request as ready for review December 10, 2021 14:15
Copy link

@neysofu neysofu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments. LGTM!

crates/runtime-ffi/src/ Outdated Show resolved Hide resolved
crates/runtime/src/ Show resolved Hide resolved
crates/runtime/src/ Show resolved Hide resolved
@YaronWittenstein YaronWittenstein merged commit 6edb73d into master Dec 13, 2021
@YaronWittenstein YaronWittenstein deleted the runtime-refactor branch December 13, 2021 12:42
@YaronWittenstein YaronWittenstein changed the title Runtime refactoring Runtime Refactoring Jan 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
refactoring Refactoring
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants