Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow producer to produce predefined blocks #2081

Merged
merged 27 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
84ccb2e
Create new port method for producing predefined blocks
MitchTurner Aug 14, 2024
c242410
Fix test
MitchTurner Aug 14, 2024
a79c3d2
Add other part of test
MitchTurner Aug 14, 2024
062fdc9
Remove tracing stuff
MitchTurner Aug 14, 2024
2d3e3da
Remove unnecessary drop
MitchTurner Aug 14, 2024
42ca09a
Add test for producing predefined block at producer level
MitchTurner Aug 15, 2024
2216015
WIP make more resilient
MitchTurner Aug 15, 2024
1d74d13
Fix dumb test
MitchTurner Aug 15, 2024
e88f96d
Report all skipped txs in predefined blocks
MitchTurner Aug 15, 2024
1521563
Move predefined blocks stuff to a port
MitchTurner Aug 15, 2024
4c75879
Change Fake to simple impl
MitchTurner Aug 15, 2024
7c5ffa5
Update CHANGELOG
MitchTurner Aug 15, 2024
b0b17ec
Merge branch 'master' into feature/produce-predefined-blocks
MitchTurner Aug 15, 2024
7133392
Fix compilation errors upstream
MitchTurner Aug 15, 2024
3745ef9
Fix broken test
MitchTurner Aug 15, 2024
c653643
Add tests for all the important fields for predefined blocks
MitchTurner Aug 16, 2024
a1711ad
Include randomized recipient contract ids
MitchTurner Aug 16, 2024
2b50d37
Merge branch 'master' into feature/produce-predefined-blocks
MitchTurner Aug 16, 2024
ea34fb1
Remove regression
MitchTurner Aug 16, 2024
0254734
Do not include mint tx in txs source
MitchTurner Aug 16, 2024
48773ce
Appease Clippy-sama
MitchTurner Aug 16, 2024
859bf50
Include test for alternating predefined blocks
MitchTurner Aug 16, 2024
b1f3843
Improve test, early return :(, improve skipped tx reporting, return e…
MitchTurner Aug 16, 2024
ea26f63
Fix import order, early return :(
MitchTurner Aug 16, 2024
058fdc4
Fix formatting
MitchTurner Aug 16, 2024
6a2deed
Add minor optimization
MitchTurner Aug 16, 2024
0d310e5
Disable block production to avoid overflow
xgreenx Aug 16, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- [2081](https://github.com/FuelLabs/fuel-core/pull/2081): Enable producer to include predefined blocks.
- [2079](https://github.com/FuelLabs/fuel-core/pull/2079): Open unknown columns in the RocksDB for forward compatibility.

### Changed
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions crates/fuel-core/src/service/adapters/consensus_module/poa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use fuel_core_poa::{
use fuel_core_services::stream::BoxStream;
use fuel_core_storage::transactional::Changes;
use fuel_core_types::{
blockchain::block::Block,
fuel_tx::TxId,
fuel_types::BlockHeight,
services::{
Expand Down Expand Up @@ -120,6 +121,15 @@ impl fuel_core_poa::ports::BlockProducer for BlockProducerAdapter {
}
}
}

async fn produce_predefined_block(
&self,
block: &Block,
) -> anyhow::Result<UncommittedResult<Changes>> {
self.block_producer
.produce_and_execute_predefined(block)
.await
}
}

#[async_trait::async_trait]
Expand Down
5 changes: 5 additions & 0 deletions crates/fuel-core/src/service/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ impl From<&Config> for fuel_core_poa::Config {
metrics: false,
min_connected_reserved_peers: config.min_connected_reserved_peers,
time_until_synced: config.time_until_synced,
chain_id: config
.snapshot_reader
.chain_config()
.consensus_parameters
.chain_id(),
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ use fuel_core_gas_price_service::fuel_gas_price_updater::{
UpdaterMetadata,
V0Metadata,
};
use fuel_core_poa::Trigger;
use fuel_core_poa::{
ports::InMemoryPredefinedBlocks,
Trigger,
};
use fuel_core_services::{
RunnableService,
ServiceRunner,
Expand All @@ -53,13 +56,20 @@ use fuel_core_storage::{
};
#[cfg(feature = "relayer")]
use fuel_core_types::blockchain::primitives::DaBlockHeight;
use std::sync::Arc;
use std::{
collections::HashMap,
sync::Arc,
};
use tokio::sync::Mutex;

mod algorithm_updater;

pub type PoAService =
fuel_core_poa::Service<TxPoolAdapter, BlockProducerAdapter, BlockImporterAdapter>;
pub type PoAService = fuel_core_poa::Service<
TxPoolAdapter,
BlockProducerAdapter,
BlockImporterAdapter,
InMemoryPredefinedBlocks,
>;
#[cfg(feature = "p2p")]
pub type P2PService = fuel_core_p2p::service::Service<Database>;
pub type TxPoolSharedState = fuel_core_txpool::service::SharedState<
Expand Down Expand Up @@ -235,6 +245,7 @@ pub fn init_sub_services(
tracing::info!("Enabled manual block production because of `debug` flag");
}

let predefined_blocks: InMemoryPredefinedBlocks = HashMap::new().into();
let poa = (production_enabled).then(|| {
fuel_core_poa::new_service(
&last_block_header,
Expand All @@ -243,6 +254,7 @@ pub fn init_sub_services(
producer_adapter.clone(),
importer_adapter.clone(),
p2p_adapter.clone(),
predefined_blocks,
)
});
let poa_adapter = PoAAdapter::new(poa.as_ref().map(|service| service.shared.clone()));
Expand Down
3 changes: 3 additions & 0 deletions crates/services/consensus_module/poa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ fuel-core-chain-config = { workspace = true }
fuel-core-services = { workspace = true }
fuel-core-storage = { workspace = true }
fuel-core-types = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tokio-stream = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
fuel-core-poa = { path = ".", features = ["test-helpers"] }
fuel-core-services = { workspace = true, features = ["test-helpers"] }
fuel-core-storage = { path = "./../../../storage", features = ["test-helpers"] }
fuel-core-types = { path = "./../../../types", features = ["test-helpers"] }
mockall = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/services/consensus_module/poa/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fuel_core_types::{
blockchain::primitives::SecretKeyWrapper,
fuel_types::ChainId,
secrecy::Secret,
};
use tokio::time::Duration;
Expand All @@ -11,6 +12,7 @@ pub struct Config {
pub metrics: bool,
pub min_connected_reserved_peers: usize,
pub time_until_synced: Duration,
pub chain_id: ChainId,
}

#[cfg(feature = "test-helpers")]
Expand All @@ -22,6 +24,7 @@ impl Default for Config {
metrics: false,
min_connected_reserved_peers: 0,
time_until_synced: Duration::ZERO,
chain_id: ChainId::default(),
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions crates/services/consensus_module/poa/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use fuel_core_storage::{
};
use fuel_core_types::{
blockchain::{
block::Block,
header::BlockHeader,
primitives::DaBlockHeight,
},
Expand All @@ -29,6 +30,7 @@ use fuel_core_types::{
},
tai64::Tai64,
};
use std::collections::HashMap;

#[cfg_attr(test, mockall::automock)]
pub trait TransactionPool: Send + Sync {
Expand Down Expand Up @@ -59,6 +61,11 @@ pub trait BlockProducer: Send + Sync {
block_time: Tai64,
source: TransactionsSource,
) -> anyhow::Result<UncommittedExecutionResult<Changes>>;

async fn produce_predefined_block(
&self,
block: &Block,
) -> anyhow::Result<UncommittedExecutionResult<Changes>>;
}

#[cfg_attr(test, mockall::automock)]
Expand Down Expand Up @@ -108,3 +115,29 @@ pub trait SyncPort: Send + Sync {
/// await synchronization with the peers
async fn sync_with_peers(&mut self) -> anyhow::Result<()>;
}

pub trait PredefinedBlocks: Send + Sync {
fn get_block(&self, height: &BlockHeight) -> Option<Block>;
}

pub struct InMemoryPredefinedBlocks {
blocks: HashMap<BlockHeight, Block>,
}

impl From<HashMap<BlockHeight, Block>> for InMemoryPredefinedBlocks {
fn from(blocks: HashMap<BlockHeight, Block>) -> Self {
Self::new(blocks)
}
}

impl InMemoryPredefinedBlocks {
pub fn new(blocks: HashMap<BlockHeight, Block>) -> Self {
Self { blocks }
}
}

impl PredefinedBlocks for InMemoryPredefinedBlocks {
fn get_block(&self, height: &BlockHeight) -> Option<Block> {
self.blocks.get(height).cloned()
}
}
Loading
Loading