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

Connect the block importer with outside world #915

Merged
merged 43 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
393b5a7
- Added the main logic of the block importer.
xgreenx Jan 18, 2023
a6d835e
Tested `commit_result`
xgreenx Jan 18, 2023
0b71b7f
Make clippy happy
xgreenx Jan 18, 2023
d7d7a6c
Added tests for `verify_and_execute_block` part of the importer
xgreenx Jan 19, 2023
d60971a
Added test for lock for `verify_and_execute_block`
xgreenx Jan 19, 2023
aa720f3
Update crates/services/importer/src/importer.rs
xgreenx Jan 19, 2023
7e3ba96
Make fmt happy
xgreenx Jan 19, 2023
3be7239
Added verifeir for the block
xgreenx Jan 18, 2023
f90e026
Fixed merge conflicts
xgreenx Jan 18, 2023
7d21d6b
Fix test to use Validator role
xgreenx Jan 18, 2023
d9cade3
add unit tests to verify genesis
freesig Jan 19, 2023
d67e729
add unit tests to verify poa block
freesig Jan 19, 2023
5a16bc0
Linked TODO to the issue
xgreenx Jan 19, 2023
838a716
Added one more test for geensis
xgreenx Jan 19, 2023
e7e1835
- Removed `CHAIN_HEIGHT_KEY`, because now we have a genesis block to …
xgreenx Jan 18, 2023
637f02e
Checked that there are no panic.
xgreenx Jan 18, 2023
ab8c5fd
Fix compilation error
xgreenx Jan 19, 2023
016a389
test manual block production
freesig Jan 20, 2023
42c890e
check workspace
freesig Jan 20, 2023
4f1e02d
had flag around the wrong way
freesig Jan 20, 2023
27020e1
Renamed generics.
xgreenx Jan 20, 2023
950fb3c
Merge branch 'feature/block-importer' into featue/block-verifier
xgreenx Jan 20, 2023
6b9065f
Merge branch 'featue/block-verifier' into featue/connect-block-importer
xgreenx Jan 20, 2023
fa14327
Remvoe TODO
xgreenx Jan 20, 2023
21cc173
Merge branch 'master' into featue/block-verifier
xgreenx Jan 20, 2023
85c6707
Merge branch 'featue/block-verifier' into featue/connect-block-importer
xgreenx Jan 20, 2023
c2913b9
Removed `BlockProduction` from `ChainConfig`.
xgreenx Jan 21, 2023
21cf872
Merge branch 'master' into featue/block-verifier
xgreenx Jan 21, 2023
a0ef9a3
Replace `poa_config` with `into`
xgreenx Jan 21, 2023
a195c56
Push new snapshots
xgreenx Jan 21, 2023
cb30cd8
Applied suggestions from the PR
xgreenx Jan 23, 2023
8de4be2
Merge branch 'featue/block-verifier' into featue/connect-block-importer
xgreenx Jan 23, 2023
872d461
Merge with verifier
xgreenx Jan 23, 2023
3966ad3
Removed "humantime-serde"
xgreenx Jan 23, 2023
028627e
Merge branch 'featue/block-verifier' into featue/connect-block-importer
ControlCplusControlV Jan 23, 2023
f692b3d
upgrade clap in fuel-core cli, improve cli interface for consensus args
Voxelot Jan 23, 2023
eda254e
fix lockfile
Voxelot Jan 23, 2023
13bab2c
cargo lint
Voxelot Jan 23, 2023
457102f
add readme instructions for disabling block production
Voxelot Jan 23, 2023
9552a24
Merge branch 'featue/block-verifier' into featue/connect-block-importer
xgreenx Jan 23, 2023
11f9f6d
Make clippy happy
xgreenx Jan 23, 2023
09dfafe
Merge branch 'featue/block-verifier' into featue/connect-block-importer
xgreenx Jan 23, 2023
f687d69
Merge branch 'master' into featue/connect-block-importer
Voxelot Jan 23, 2023
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ jobs:
include:
- command: clippy
args: --all-targets --all-features
- command: check
args: --all-targets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything caught by this that isn't already caught?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep it catches running cargo check --all-targets at the workspace root which nothing else does. It has a different feature set the all-features or running the command at each crate level like the make command does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I guess we can remove it, because cargo test --all-features --workspace do the same)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to remove it then since CI times are already pretty long

- command: make
args: check --locked
- command: test
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/chain-config/src/config/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl StateConfig {
coins: db.get_coin_config()?,
contracts: db.get_contract_config()?,
messages: db.get_message_config()?,
height: db.get_block_height()?,
height: Some(db.get_block_height()?),
})
}
}
Expand All @@ -57,5 +57,5 @@ pub trait ChainConfigDb {
/// Returns *all* unspent message configs available in the database.
fn get_message_config(&self) -> StorageResult<Option<Vec<MessageConfig>>>;
/// Returns the last available block height.
fn get_block_height(&self) -> StorageResult<Option<BlockHeight>>;
fn get_block_height(&self) -> StorageResult<BlockHeight>;
freesig marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions crates/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ clap = { version = "4.1", features = ["derive"] }
derive_more = { version = "0.99" }
enum-iterator = "1.2"
fuel-core-chain-config = { path = "../chain-config", version = "0.15.1" }
fuel-core-consensus-module = { path = "../../crates/services/consensus_module", version = "0.15.1" }
fuel-core-database = { path = "../database", version = "0.15.1" }
fuel-core-executor = { path = "../services/executor", version = "0.15.1" }
fuel-core-importer = { path = "../services/importer", version = "0.15.1" }
Expand Down
110 changes: 15 additions & 95 deletions crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,20 @@ use fuel_core_chain_config::{
MessageConfig,
};
use fuel_core_executor::refs::ContractStorageTrait;
use fuel_core_poa::ports::BlockDb;
use fuel_core_producer::ports::BlockProducerDatabase;
use fuel_core_storage::{
not_found,
tables::{
FuelBlocks,
SealedBlockConsensus,
transactional::{
StorageTransaction,
Transactional,
},
Error as StorageError,
Result as StorageResult,
StorageAsMut,
StorageAsRef,
};
use fuel_core_types::blockchain::{
block::CompressedBlock,
consensus::Consensus,
primitives::{
BlockHeight,
BlockId,
},
};
use fuel_core_types::blockchain::primitives::BlockHeight;
use serde::{
de::DeserializeOwned,
Serialize,
};
use std::{
borrow::Cow,
fmt::{
self,
Debug,
Expand All @@ -59,23 +46,6 @@ type DatabaseResult<T> = Result<T>;

#[cfg(feature = "rocksdb")]
use crate::state::rocks_db::RocksDb;
use fuel_core_storage::tables::{
Coins,
ContractsRawCode,
Messages,
};
use fuel_core_txpool::ports::TxPoolDb;
use fuel_core_types::{
entities::{
coin::CompressedCoin,
message::Message,
},
fuel_tx::UtxoId,
fuel_types::{
ContractId,
MessageId,
},
};
#[cfg(feature = "rocksdb")]
use std::path::Path;
#[cfg(feature = "rocksdb")]
Expand All @@ -98,6 +68,7 @@ mod state;

pub mod balances;
pub mod metadata;
pub mod storage;
// TODO: Rename in a separate PR into `transaction`
pub mod transactional;
pub mod transactions;
Expand Down Expand Up @@ -143,6 +114,8 @@ pub enum Column {
OwnedMessageIds = 15,
/// The column that stores the consensus metadata associated with a finalized fuel block
FuelBlockConsensus = 16,
/// The column that stores the BMT MMR roots of the block headers
BlockHeaderMerkle = 17,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -286,6 +259,12 @@ impl Database {
}
}

impl Transactional<Database> for Database {
fn transaction(&self) -> StorageTransaction<Database> {
StorageTransaction::new(self.transaction())
}
}

impl AsRef<Database> for Database {
fn as_ref(&self) -> &Database {
self
Expand Down Expand Up @@ -328,65 +307,6 @@ impl Default for Database {
}
}

impl BlockDb for Database {
fn block_height(&self) -> anyhow::Result<BlockHeight> {
Ok(self.latest_height()?.unwrap_or_default())
}

fn seal_block(
&mut self,
block_id: BlockId,
consensus: Consensus,
) -> anyhow::Result<()> {
self.storage::<SealedBlockConsensus>()
.insert(&block_id, &consensus)
.map(|_| ())
.map_err(Into::into)
}
}

impl TxPoolDb for Database {
fn utxo(&self, utxo_id: &UtxoId) -> StorageResult<Option<CompressedCoin>> {
self.storage::<Coins>()
.get(utxo_id)
.map(|t| t.map(|t| t.as_ref().clone()))
}

fn contract_exist(&self, contract_id: &ContractId) -> StorageResult<bool> {
self.storage::<ContractsRawCode>().contains_key(contract_id)
}

fn message(&self, message_id: &MessageId) -> StorageResult<Option<Message>> {
self.storage::<Messages>()
.get(message_id)
.map(|t| t.map(|t| t.as_ref().clone()))
}

fn current_block_height(&self) -> StorageResult<BlockHeight> {
self.latest_height()
.map(|h| h.unwrap_or_default())
.map_err(Into::into)
}
}

impl BlockProducerDatabase for Database {
fn get_block(
&self,
fuel_height: BlockHeight,
) -> StorageResult<Option<Cow<CompressedBlock>>> {
let id = self
.get_block_id(fuel_height)?
.ok_or(not_found!("BlockId"))?;
self.storage::<FuelBlocks>().get(&id).map_err(Into::into)
}

fn current_block_height(&self) -> StorageResult<BlockHeight> {
self.latest_height()
.map(|h| h.unwrap_or_default())
.map_err(Into::into)
}
}

/// Implement `ChainConfigDb` so that `Database` can be passed to
/// `StateConfig's` `generate_state_config()` method
impl ChainConfigDb for Database {
Expand All @@ -402,7 +322,7 @@ impl ChainConfigDb for Database {
Self::get_message_config(self).map_err(Into::into)
}

fn get_block_height(&self) -> StorageResult<Option<BlockHeight>> {
Self::latest_height(self).map_err(Into::into)
fn get_block_height(&self) -> StorageResult<BlockHeight> {
Self::latest_height(self)
}
}
20 changes: 8 additions & 12 deletions crates/fuel-core/src/database/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
database::{
storage::ToDatabaseKey,
Column,
Database,
Error as DatabaseError,
Expand Down Expand Up @@ -85,15 +86,10 @@ impl StorageMutate<FuelBlocks> for Database {
}

impl Database {
pub fn latest_height(&self) -> DatabaseResult<Option<BlockHeight>> {
let id = self.ids_of_latest_block()?;
// if no blocks, check if chain was configured with a base height
let id = match id {
Some((id, _)) => Some(id),
None => self.get_starting_chain_height()?,
};

Ok(id)
pub fn latest_height(&self) -> StorageResult<BlockHeight> {
self.ids_of_latest_block()?
.map(|(height, _)| height)
.ok_or(not_found!("BlockHeight"))
ControlCplusControlV marked this conversation as resolved.
Show resolved Hide resolved
}

/// Get the current block at the head of the chain.
Expand All @@ -105,7 +101,7 @@ impl Database {
}
}

pub fn block_time(&self, height: BlockHeight) -> StorageResult<Tai64> {
pub fn block_time(&self, height: &BlockHeight) -> StorageResult<Tai64> {
let id = self.get_block_id(height)?.unwrap_or_default();
let block = self
.storage::<FuelBlocks>()
Expand All @@ -114,8 +110,8 @@ impl Database {
Ok(block.header().time().to_owned())
}

pub fn get_block_id(&self, height: BlockHeight) -> StorageResult<Option<BlockId>> {
Database::get(self, &height.to_bytes()[..], Column::FuelBlockIds)
pub fn get_block_id(&self, height: &BlockHeight) -> StorageResult<Option<BlockId>> {
Database::get(self, height.database_key().as_ref(), Column::FuelBlockIds)
.map_err(Into::into)
}

Expand Down
14 changes: 0 additions & 14 deletions crates/fuel-core/src/database/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use crate::database::{
Result as DatabaseResult,
};
use fuel_core_chain_config::ChainConfig;
use fuel_core_types::blockchain::primitives::BlockHeight;

pub(crate) const DB_VERSION_KEY: &[u8] = b"version";
pub(crate) const CHAIN_NAME_KEY: &[u8] = b"chain_name";
pub(crate) const CHAIN_HEIGHT_KEY: &[u8] = b"chain_height";
#[cfg(feature = "relayer")]
pub(crate) const FINALIZED_DA_HEIGHT_KEY: &[u8] = b"finalized_da_height";

Expand All @@ -28,23 +26,11 @@ impl Database {
}
})?;

let chain_height = config
.initial_state
.as_ref()
.and_then(|c| c.height)
.unwrap_or_default();

let _: Option<u32> = self.insert(DB_VERSION_KEY, Column::Metadata, DB_VERSION)?;
let _: Option<BlockHeight> =
self.insert(CHAIN_HEIGHT_KEY, Column::Metadata, chain_height)?;
Ok(())
}

pub fn get_chain_name(&self) -> DatabaseResult<Option<String>> {
self.get(CHAIN_NAME_KEY, Column::Metadata)
}

pub fn get_starting_chain_height(&self) -> DatabaseResult<Option<BlockHeight>> {
self.get(CHAIN_HEIGHT_KEY, Column::Metadata)
}
}
2 changes: 1 addition & 1 deletion crates/fuel-core/src/database/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use fuel_core_types::blockchain::{
impl P2pDb for Database {
async fn get_sealed_block(
&self,
height: BlockHeight,
height: &BlockHeight,
) -> StorageResult<Option<SealedBlock>> {
self.get_sealed_block_by_height(height)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/database/sealed_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Database {
/// Reusable across different trait implementations
pub fn get_sealed_block_by_height(
&self,
height: BlockHeight,
height: &BlockHeight,
) -> StorageResult<Option<SealedBlock>> {
let block_id = self.get_block_id(height)?.ok_or(not_found!("BlockId"))?;
self.get_sealed_block_by_id(&block_id)
Expand Down
Loading