-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Surface module cache for reuse. (#1506)
The goals of this PR are: 1. Surface the `ModuleCache` from inside soroban to its embedding environment. 2. Allow a module cache to _outlive_ the soroban `Host`, and be reused from one `Host` to the next. 3. Allow the `ModuleCache` to be _pre-populated_ from before the lifetime of a single `Host`, (eg. by stellar-core, with all the non-archived contracts currently live in the ledger, at startup or such.) These goals are accomplished by the following structural changes: 1. Factoring out error-handling / error-mapping functionality of `Host` into a separate trait `ErrorHandler` that `Host` implements, and adding a new trait `CompilationContext` that extends both `ErrorHandler + AsBudget`. This abstracts the services the `ModuleCache` _needs_ from the `Host`, such that the embedding environment can provide its own `CompilationContext` in the times pre- or post-`Host` lifetime. 2. Modifying the internal map that stores `Module`s inside the `ModuleCache` to use a refcounted-shared-mutable `std::map::BtreeMap` that can be incrementally and efficiently added-to or removed-from, and is _not_ metered. 3. `Module` storage and arguments that were `Rc<>` are made `Arc<>` and the whole `ModuleCache` is made `Send+Sync`. This is mainly because we want to work with the reusable `ModuleCache` across C++ threads, and while Rust has no idea about C++ threads it at least helps us shoot ourselves in the foot less if all the Rust code that works with it preserves the sense of "this would be threadsafe in Rust if Rust was making the threads". 4. There is also a bit of gratuitous churn where things get renamed from `foo` => `wasmi_foo` and `Foo` => `wasmi::Foo`. This is because this change was done as part of (and there'll be a followup PR including) work equipping the `Vm` and `ModuleCache` with an experimental wasmtime/winch backend. It turns out this PR's work (on just the `ModuleCache` reuse part) is high enough value, and agnostic enough to which backend it's using, that we want to split this work out, move it up in the schedule and explore getting it into as early a release as possible. But I didn't bother reverting-out the `wasmi_`-qualification since it's intertwined with other changes here and harmless to keep. This PR is a continuation of #1511 and should be merged after it. This PR implements [CAP-0065](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0065.md)
- Loading branch information
Showing
307 changed files
with
17,526 additions
and
17,378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.