-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration skeleton of parallel-executor (#2617)
## Description This PR is the first one of a sequel of PR that will introduce the `parallel-executor` to the codebase. The goal of this first PR is to create the new module and showcase the smooth integration with the existing codebase. The instantiation of the `parallel-executor` has been commented to pass the tests with `--all-features` however I want to keep them to showcase what the integration looks like and will be uncommented when real code exists. ## Checklist - [x] Breaking changes are clearly marked as such in the PR description and changelog - [x] New behavior is reflected in tests - [x] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [x] I have reviewed the code myself - [x] I have created follow-up issues caused by this PR and linked them here
- Loading branch information
1 parent
1e852a3
commit b501db2
Showing
15 changed files
with
213 additions
and
5 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "fuel-core-parallel-executor" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
keywords = ["blockchain", "fuel", "fuel-vm", "parallel"] | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
description = "Fuel Block Parallel Executor" | ||
|
||
[dependencies] | ||
fuel-core-storage = { workspace = true, features = ["std"] } | ||
fuel-core-types = { workspace = true, features = ["std"] } | ||
fuel-core-upgradable-executor = { workspace = true, features = ["std"] } | ||
tokio = { workspace = true, features = ["rt-multi-thread"] } | ||
|
||
[features] | ||
wasm-executor = ["fuel-core-upgradable-executor/wasm-executor"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use fuel_core_upgradable_executor::config::Config as ExecutorConfig; | ||
use std::num::NonZeroUsize; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Config { | ||
/// The number of cores to use for the block execution. | ||
pub number_of_cores: NonZeroUsize, | ||
/// See [`fuel_core_upgradable_executor::config::Config`]. | ||
pub executor_config: ExecutorConfig, | ||
} | ||
|
||
impl Default for Config { | ||
fn default() -> Self { | ||
Self { | ||
number_of_cores: NonZeroUsize::new(1).expect("The value is not zero; qed"), | ||
executor_config: Default::default(), | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use crate::config::Config; | ||
use fuel_core_storage::transactional::Changes; | ||
use fuel_core_types::{ | ||
blockchain::block::Block, | ||
fuel_tx::Transaction, | ||
services::{ | ||
block_producer::Components, | ||
executor::{ | ||
ExecutionResult, | ||
Result as ExecutorResult, | ||
TransactionExecutionStatus, | ||
ValidationResult, | ||
}, | ||
Uncommitted, | ||
}, | ||
}; | ||
use fuel_core_upgradable_executor::{ | ||
executor::Executor as UpgradableExecutor, | ||
native_executor::ports::TransactionsSource, | ||
}; | ||
use std::{ | ||
num::NonZeroUsize, | ||
sync::{ | ||
Arc, | ||
RwLock, | ||
}, | ||
}; | ||
use tokio::runtime::Runtime; | ||
|
||
#[cfg(feature = "wasm-executor")] | ||
use fuel_core_upgradable_executor::error::UpgradableError; | ||
|
||
#[cfg(feature = "wasm-executor")] | ||
use fuel_core_types::fuel_merkle::common::Bytes32; | ||
|
||
pub struct Executor<S, R> { | ||
_executor: Arc<RwLock<UpgradableExecutor<S, R>>>, | ||
runtime: Option<Runtime>, | ||
_number_of_cores: NonZeroUsize, | ||
} | ||
|
||
// Shutdown the tokio runtime to avoid panic if executor is already | ||
// used from another tokio runtime | ||
impl<S, R> Drop for Executor<S, R> { | ||
fn drop(&mut self) { | ||
if let Some(runtime) = self.runtime.take() { | ||
runtime.shutdown_background(); | ||
} | ||
} | ||
} | ||
|
||
impl<S, R> Executor<S, R> { | ||
pub fn new( | ||
storage_view_provider: S, | ||
relayer_view_provider: R, | ||
config: Config, | ||
) -> Self { | ||
let executor = UpgradableExecutor::new( | ||
storage_view_provider, | ||
relayer_view_provider, | ||
config.executor_config, | ||
); | ||
let runtime = tokio::runtime::Builder::new_multi_thread() | ||
.worker_threads(config.number_of_cores.get()) | ||
.enable_all() | ||
.build() | ||
.unwrap(); | ||
let number_of_cores = config.number_of_cores; | ||
|
||
Self { | ||
_executor: Arc::new(RwLock::new(executor)), | ||
runtime: Some(runtime), | ||
_number_of_cores: number_of_cores, | ||
} | ||
} | ||
} | ||
|
||
impl<S, R> Executor<S, R> { | ||
/// Produces the block and returns the result of the execution without committing the changes. | ||
pub fn produce_without_commit_with_source<TxSource>( | ||
&self, | ||
_components: Components<TxSource>, | ||
) -> ExecutorResult<Uncommitted<ExecutionResult, Changes>> | ||
where | ||
TxSource: TransactionsSource + Send + Sync + 'static, | ||
{ | ||
unimplemented!("Not implemented yet"); | ||
} | ||
|
||
pub fn validate( | ||
&self, | ||
_block: &Block, | ||
) -> ExecutorResult<Uncommitted<ValidationResult, Changes>> { | ||
unimplemented!("Not implemented yet"); | ||
} | ||
|
||
#[cfg(feature = "wasm-executor")] | ||
pub fn validate_uploaded_wasm( | ||
&self, | ||
_wasm_root: &Bytes32, | ||
) -> Result<(), UpgradableError> { | ||
unimplemented!("Not implemented yet"); | ||
} | ||
|
||
/// Executes the block and returns the result of the execution without committing | ||
/// the changes in the dry run mode. | ||
pub fn dry_run( | ||
&self, | ||
_component: Components<Vec<Transaction>>, | ||
_utxo_validation: Option<bool>, | ||
) -> ExecutorResult<Vec<TransactionExecutionStatus>> { | ||
unimplemented!("Not implemented yet"); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod config; | ||
pub mod executor; |
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