Skip to content

Commit

Permalink
Move VmPool to fuel-vm, use it for predicates as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Dentosal committed May 10, 2024
1 parent 5caec42 commit 6340785
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 239 deletions.
259 changes: 119 additions & 140 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use fuel_core_types::{
InterpreterParams,
ReceiptsCtx,
},
pool::test_pool,
*,
},
};
Expand Down Expand Up @@ -454,9 +455,9 @@ impl TryFrom<VmBench> for VmBenchPrepared {
.maturity(maturity)
.with_params(params.clone())
.finalize();
tx.estimate_predicates(&CheckPredicateParams::from(&params))
tx.estimate_predicates(&CheckPredicateParams::from(&params), test_pool())
.unwrap();
let tx = tx.into_checked(height, &params).unwrap();
let tx = tx.into_checked(height, &params, test_pool()).unwrap();
let interpreter_params = InterpreterParams::new(gas_price, &params);

let mut txtor = Transactor::new(db, interpreter_params);
Expand Down
3 changes: 2 additions & 1 deletion crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ mod tests {
EstimatePredicates,
},
interpreter::ExecutableTransaction,
pool::test_pool,
script_with_data_offset,
util::test_helpers::TestBuilder as TxBuilder,
Call,
Expand Down Expand Up @@ -2686,7 +2687,7 @@ mod tests {
asset_id: Default::default(),
})
.finalize();
tx.estimate_predicates(&consensus_parameters.clone().into())
tx.estimate_predicates(&consensus_parameters.clone().into(), test_pool())
.unwrap();
let db = &mut Database::default();

Expand Down
18 changes: 12 additions & 6 deletions crates/fuel-core/src/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ use fuel_core_types::{
},
fuel_types,
fuel_types::canonical::Deserialize,
fuel_vm::checked_transaction::{
CheckPredicateParams,
EstimatePredicates,
fuel_vm::{
checked_transaction::{
CheckPredicateParams,
EstimatePredicates,
},
pool::VmPool,
},
services::txpool,
};
Expand Down Expand Up @@ -214,9 +217,12 @@ impl TxQuery {
.data_unchecked::<ConsensusProvider>()
.latest_consensus_params();

tx.estimate_predicates_async::<TokioWithRayon>(&CheckPredicateParams::from(
params.as_ref(),
))
let vm_pool = ctx.data_unchecked::<VmPool>().clone();

tx.estimate_predicates_async::<TokioWithRayon>(
&CheckPredicateParams::from(params.as_ref()),
vm_pool,
)
.await
.map_err(|err| anyhow::anyhow!("{:?}", err))?;

Expand Down
2 changes: 2 additions & 0 deletions crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::{
},
};
use fuel_core_poa::Trigger;
use fuel_core_types::fuel_vm::pool::VmPool;
use std::sync::Arc;
use tokio::sync::Mutex;

Expand Down Expand Up @@ -169,6 +170,7 @@ pub fn init_sub_services(
last_height,
gas_price_provider.clone(),
consensus_parameters_provider.clone(),
VmPool::default(),
);
let tx_pool_adapter = TxPoolAdapter::new(txpool.shared.clone());

Expand Down
1 change: 1 addition & 0 deletions crates/services/consensus_module/poa/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl RunnableService for SyncTask {
}
}

#[allow(clippy::blocks_in_conditions)]
#[async_trait::async_trait]
impl RunnableTask for SyncTask {
#[tracing::instrument(level = "debug", skip_all, err, ret)]
Expand Down
19 changes: 13 additions & 6 deletions crates/services/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
TransactionsSource,
},
refs::ContractRef,
vm_pool,
};
use core::mem;
use fuel_core_storage::{
Expand Down Expand Up @@ -104,8 +103,8 @@ use fuel_core_types::{
ContractId,
MessageId,
},
fuel_vm,
fuel_vm::{
self,
checked_transaction::{
CheckPredicateParams,
CheckPredicates,
Expand All @@ -119,6 +118,7 @@ use fuel_core_types::{
ExecutableTransaction,
InterpreterParams,
},
pool::VmPool,
state::StateTransition,
Backtrace as FuelBacktrace,
Interpreter,
Expand Down Expand Up @@ -338,7 +338,7 @@ pub struct BlockExecutor<R> {
relayer: R,
consensus_params: ConsensusParameters,
options: ExecutionOptions,
vm_pool: vm_pool::VmPool,
vm_pool: VmPool,
}

impl<R> BlockExecutor<R> {
Expand Down Expand Up @@ -802,6 +802,7 @@ where
relayed_tx,
block_height,
&self.consensus_params,
self.vm_pool.clone(),
);
match checked_tx_res {
Ok(checked_tx) => {
Expand Down Expand Up @@ -832,6 +833,7 @@ where
relayed_tx: RelayedTransaction,
block_height: BlockHeight,
consensus_params: &ConsensusParameters,
vm_pool: VmPool,
) -> Result<CheckedTransaction, ForcedTransactionFailure> {
let parsed_tx = Self::parse_tx_bytes(&relayed_tx)?;
Self::tx_is_valid_variant(&parsed_tx)?;
Expand All @@ -840,7 +842,8 @@ where
&relayed_tx,
consensus_params,
)?;
let checked_tx = Self::get_checked_tx(parsed_tx, block_height, consensus_params)?;
let checked_tx =
Self::get_checked_tx(parsed_tx, block_height, consensus_params, vm_pool)?;
Ok(CheckedTransaction::from(checked_tx))
}

Expand All @@ -857,9 +860,10 @@ where
tx: Transaction,
height: BlockHeight,
consensus_params: &ConsensusParameters,
vm_pool: VmPool,
) -> Result<Checked<Transaction>, ForcedTransactionFailure> {
let checked_tx = tx
.into_checked(height, consensus_params)
.into_checked(height, consensus_params, vm_pool)
.map_err(ForcedTransactionFailure::CheckError)?;
Ok(checked_tx)
}
Expand Down Expand Up @@ -1372,7 +1376,10 @@ where
T: KeyValueInspect<Column = Column>,
{
checked_tx = checked_tx
.check_predicates(&CheckPredicateParams::from(&self.consensus_params))
.check_predicates(
&CheckPredicateParams::from(&self.consensus_params),
self.vm_pool.clone(),
)
.map_err(|e| {
ExecutorError::TransactionValidity(TransactionValidityError::Validation(
e,
Expand Down
1 change: 0 additions & 1 deletion crates/services/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
pub mod executor;
pub mod ports;
pub mod refs;
mod vm_pool;

#[cfg(test)]
fuel_core_trace::enable_tracing!();
52 changes: 0 additions & 52 deletions crates/services/executor/src/vm_pool.rs

This file was deleted.

2 changes: 2 additions & 0 deletions crates/services/sync/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ where
E: BlockImporterPort + Send + Sync + 'static,
C: ConsensusPort + Send + Sync + 'static,
{
#[allow(clippy::blocks_in_conditions)] // false positive
#[tracing::instrument(level = "debug", skip_all, err, ret)]
async fn run(&mut self, _: &mut StateWatcher) -> anyhow::Result<bool> {
Ok(self.sync_heights.sync().await.is_some())
Expand Down Expand Up @@ -175,6 +176,7 @@ where
E: BlockImporterPort + Send + Sync + 'static,
C: ConsensusPort + Send + Sync + 'static,
{
#[allow(clippy::blocks_in_conditions)] // false positive
#[tracing::instrument(level = "debug", skip_all, err, ret)]
async fn run(&mut self, watcher: &mut StateWatcher) -> anyhow::Result<bool> {
self.0.import(watcher).await
Expand Down
10 changes: 9 additions & 1 deletion crates/services/txpool/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use fuel_core_types::{
BlockHeight,
Bytes32,
},
fuel_vm::pool::VmPool,
services::{
block_importer::SharedImportResult,
p2p::{
Expand Down Expand Up @@ -127,6 +128,7 @@ pub struct SharedState<P2P, ViewProvider, GasPriceProvider, ConsensusProvider> {
current_height: Arc<ParkingMutex<BlockHeight>>,
consensus_parameters_provider: Arc<ConsensusProvider>,
gas_price_provider: Arc<GasPriceProvider>,
vm_pool: VmPool,
}

impl<P2P, ViewProvider, GasPriceProvider, ConsensusProvider> Clone
Expand All @@ -141,6 +143,7 @@ impl<P2P, ViewProvider, GasPriceProvider, ConsensusProvider> Clone
current_height: self.current_height.clone(),
consensus_parameters_provider: self.consensus_parameters_provider.clone(),
gas_price_provider: self.gas_price_provider.clone(),
vm_pool: self.vm_pool.clone(),
}
}
}
Expand Down Expand Up @@ -245,7 +248,8 @@ where
current_height,
self.tx_pool_shared_state.utxo_validation,
params.as_ref(),
&self.tx_pool_shared_state.gas_price_provider
&self.tx_pool_shared_state.gas_price_provider,
self.tx_pool_shared_state.vm_pool.clone(),
).await;

let acceptance = match checked_tx {
Expand Down Expand Up @@ -402,6 +406,7 @@ where
self.utxo_validation,
params.as_ref(),
&self.gas_price_provider,
self.vm_pool.clone(),
)
.await;

Expand Down Expand Up @@ -479,6 +484,7 @@ pub enum TxStatusMessage {
FailedStatus,
}

#[allow(clippy::too_many_arguments)]
pub fn new_service<P2P, Importer, ViewProvider, GasPriceProvider, ConsensusProvider>(
config: Config,
provider: ViewProvider,
Expand All @@ -487,6 +493,7 @@ pub fn new_service<P2P, Importer, ViewProvider, GasPriceProvider, ConsensusProvi
current_height: BlockHeight,
gas_price_provider: GasPriceProvider,
consensus_parameters_provider: ConsensusProvider,
vm_pool: VmPool,
) -> Service<P2P, ViewProvider, GasPriceProvider, ConsensusProvider>
where
Importer: BlockImporter,
Expand Down Expand Up @@ -521,6 +528,7 @@ where
current_height: Arc::new(ParkingMutex::new(current_height)),
consensus_parameters_provider: Arc::new(consensus_parameters_provider),
gas_price_provider: Arc::new(gas_price_provider),
vm_pool,
},
ttl_timer,
};
Expand Down
2 changes: 2 additions & 0 deletions crates/services/txpool/src/service/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use fuel_core_types::{
TransactionBuilder,
Word,
},
fuel_vm::pool::test_pool,
services::{
block_importer::ImportResult,
p2p::GossipsubMessageAcceptance,
Expand Down Expand Up @@ -257,6 +258,7 @@ impl TestContextBuilder {
Default::default(),
gas_price_provider,
consensus_parameters_provider,
test_pool(),
);

TestContext {
Expand Down
18 changes: 13 additions & 5 deletions crates/services/txpool/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ use fuel_core_types::{
AssetId,
Word,
},
fuel_vm::checked_transaction::EstimatePredicates,
fuel_vm::{
checked_transaction::EstimatePredicates,
pool::VmPool,
},
};

// use some arbitrary large amount, this shouldn't affect the txpool logic except for covering
Expand Down Expand Up @@ -187,20 +190,25 @@ impl UnsetInput {
}

pub trait IntoEstimated {
#[cfg(feature = "test-helpers")]
fn into_default_estimated(self) -> Self;
fn into_estimated(self, params: &ConsensusParameters) -> Self;
fn into_estimated(self, params: &ConsensusParameters, vm_pool: VmPool) -> Self;
}

impl IntoEstimated for Input {
#[cfg(feature = "test-helpers")]
fn into_default_estimated(self) -> Self {
self.into_estimated(&Default::default())
self.into_estimated(
&Default::default(),
fuel_core_types::fuel_vm::pool::test_pool(),
)
}

fn into_estimated(self, params: &ConsensusParameters) -> Self {
fn into_estimated(self, params: &ConsensusParameters, vm_pool: VmPool) -> Self {
let mut tx = TransactionBuilder::script(vec![], vec![])
.add_input(self)
.finalize();
let _ = tx.estimate_predicates(&params.into());
let _ = tx.estimate_predicates(&params.into(), vm_pool);
tx.inputs()[0].clone()
}
}
Loading

0 comments on commit 6340785

Please sign in to comment.