Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 11 additions & 39 deletions crates/services/producer/src/block_producer.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,33 @@
use crate::{
Config,
block_producer::gas_price::{
ChainStateInfoProvider,
GasPriceProvider as GasPriceProviderConstraint,
ChainStateInfoProvider, GasPriceProvider as GasPriceProviderConstraint,
},
ports::{
self,
BlockProducerDatabase,
RelayerBlockInfo,
},
};
use anyhow::{
Context,
anyhow,
};
use fuel_core_storage::transactional::{
AtomicView,
Changes,
HistoricalView,
ports::{self, BlockProducerDatabase, RelayerBlockInfo},
};
use anyhow::{Context, anyhow};
use fuel_core_storage::transactional::{AtomicView, Changes, HistoricalView};
use fuel_core_types::{
blockchain::{
block::Block,
header::{
ApplicationHeader,
ConsensusHeader,
ConsensusParametersVersion,
PartialBlockHeader,
StateTransitionBytecodeVersion,
ApplicationHeader, ConsensusHeader, ConsensusParametersVersion,
PartialBlockHeader, StateTransitionBytecodeVersion,
},
primitives::DaBlockHeight,
},
fuel_tx::{
Transaction,
field::{
InputContract,
MintGasPrice,
},
},
fuel_types::{
BlockHeight,
Bytes32,
field::{InputContract, MintGasPrice},
},
fuel_types::{BlockHeight, Bytes32},
services::{
block_producer::Components,
executor::{
DryRunResult,
StorageReadReplayEvent,
UncommittedResult,
},
executor::{DryRunResult, StorageReadReplayEvent, UncommittedResult},
},
tai64::Tai64,
};
use std::{
future::Future,
sync::Arc,
};
use std::{future::Future, sync::Arc};
use tokio::sync::Mutex;
use tracing::debug;

Expand Down Expand Up @@ -157,7 +129,7 @@ where
height,
previous_block: latest_height,
}
.into())
.into());
}

let maybe_mint_tx = transactions_source.pop();
Expand Down
95 changes: 29 additions & 66 deletions crates/services/producer/src/block_producer/tests.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,30 @@
#![allow(non_snake_case)]

use crate::{
Config,
Producer,
Config, Producer,
block_producer::{
Bytes32,
Error,
gas_price::{
GasPriceProvider,
MockChainStateInfoProvider,
},
},
mocks::{
FailingMockExecutor,
MockDb,
MockExecutor,
MockExecutorWithCapture,
MockRelayer,
MockTxPool,
Bytes32, Error,
gas_price::{GasPriceProvider, MockChainStateInfoProvider},
},
mocks::{MockDb, MockExecutor, MockExecutorWithCapture, MockRelayer, MockTxPool},
};
use fuel_core_producer as _;
use fuel_core_types::{
blockchain::{
block::{
Block,
CompressedBlock,
PartialFuelBlock,
},
header::{
ApplicationHeader,
ConsensusHeader,
PartialBlockHeader,
},
block::{Block, CompressedBlock, PartialFuelBlock},
header::{ApplicationHeader, ConsensusHeader, PartialBlockHeader},
primitives::DaBlockHeight,
},
fuel_tx,
fuel_tx::{
ConsensusParameters,
Mint,
Script,
Transaction,
field::InputContract,
},
fuel_tx::{ConsensusParameters, Mint, Script, Transaction, field::InputContract},
fuel_types::BlockHeight,
services::executor::Error as ExecutorError,
tai64::Tai64,
};
use rand::{
Rng,
SeedableRng,
rngs::StdRng,
};
use rand::{Rng, SeedableRng, rngs::StdRng};
use std::{
collections::HashMap,
sync::{
Arc,
Mutex,
},
sync::{Arc, Mutex},
};

pub struct MockProducerGasPrice {
Expand Down Expand Up @@ -518,9 +485,13 @@ mod produce_and_execute_block_txpool {

#[tokio::test]
async fn production_fails_on_execution_error() {
let ctx = TestContext::default_from_executor(FailingMockExecutor(Mutex::new(
Some(ExecutorError::TransactionIdCollision(Default::default())),
)));
let db = TestContext::<MockExecutor>::default_db();
let ctx = TestContext::default_from_executor(
crate::mocks::create_failing_mock_executor(
ExecutorError::TransactionIdCollision(Default::default()),
db,
),
);
Comment thread
raushan728 marked this conversation as resolved.

let producer = ctx.producer();

Expand Down Expand Up @@ -843,10 +814,7 @@ mod dry_run {
}

use fuel_core_types::fuel_tx::field::MintGasPrice;
use proptest::{
prop_compose,
proptest,
};
use proptest::{prop_compose, proptest};

prop_compose! {
fn arb_block()(height in 1..255u8, da_height in 1..255u64, gas_price: u64, coinbase_recipient: [u8; 32], num_txs in 0..100u32) -> Block {
Expand Down Expand Up @@ -1015,7 +983,7 @@ impl TestContext<MockExecutor> {
}

pub fn default_from_db(db: MockDb) -> Self {
let executor = MockExecutor(db.clone());
let executor = crate::mocks::create_mock_executor(db.clone());
Self::default_from_db_and_executor(db, executor)
}
}
Expand All @@ -1039,8 +1007,9 @@ impl<Executor> TestContext<Executor> {
}

pub fn default_from_db_and_executor(db: MockDb, executor: Executor) -> Self {
let txpool = MockTxPool::default();
let relayer = MockRelayer::default();
let txpool = crate::mocks::create_mock_txpool(vec![]);
let relayer =
crate::mocks::create_mock_relayer(DaBlockHeight::default(), HashMap::new());
let config = Config::default();
let gas_price = Some(0);
Self {
Expand Down Expand Up @@ -1229,13 +1198,10 @@ impl TestContextBuilder {
fn build(self) -> TestContext<MockExecutor> {
let block_gas_limit = self.block_gas_limit.unwrap_or_default();

let mock_relayer = MockRelayer {
latest_block_height: self.latest_block_height,
latest_da_blocks_with_costs_and_transactions_number: self
.blocks_with_gas_costs_and_transactions_number
.clone(),
..Default::default()
};
let mock_relayer = crate::mocks::create_mock_relayer(
self.latest_block_height,
self.blocks_with_gas_costs_and_transactions_number.clone(),
);

let db = MockDb {
blocks: self.pre_existing_blocks(),
Expand All @@ -1253,13 +1219,10 @@ impl TestContextBuilder {
fn build_with_executor<Ex>(self, executor: Ex) -> TestContext<Ex> {
let block_gas_limit = self.block_gas_limit.unwrap_or_default();

let mock_relayer = MockRelayer {
latest_block_height: self.latest_block_height,
latest_da_blocks_with_costs_and_transactions_number: self
.blocks_with_gas_costs_and_transactions_number
.clone(),
..Default::default()
};
let mock_relayer = crate::mocks::create_mock_relayer(
self.latest_block_height,
self.blocks_with_gas_costs_and_transactions_number.clone(),
);

let db = MockDb {
blocks: self.pre_existing_blocks(),
Expand Down
Loading