-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fixed some [nit]s after review the PR for fuel-core-sync
integration
#928
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,10 @@ use fuel_core_types::{ | |
SealedBlock, | ||
}, | ||
fuel_tx::Bytes32, | ||
services::{ | ||
block_importer::UncommittedResult, | ||
executor::ExecutionBlock, | ||
services::executor::{ | ||
ExecutionBlock, | ||
Result as ExecutorResult, | ||
UncommittedResult as UncommittedExecutionResult, | ||
}, | ||
}; | ||
use std::sync::Arc; | ||
|
@@ -52,38 +53,22 @@ impl BlockImporterAdapter { | |
) -> Self { | ||
Self { | ||
block_importer: Arc::new(Importer::new(config, database, executor, verifier)), | ||
execution_semaphore: Arc::new(tokio::sync::Semaphore::new(1)), | ||
} | ||
} | ||
|
||
pub async fn execute_and_commit( | ||
&self, | ||
sealed_block: SealedBlock, | ||
) -> anyhow::Result<()> { | ||
let permit = self.execution_semaphore.acquire().await?; | ||
tokio::task::spawn_blocking({ | ||
let importer = self.block_importer.clone(); | ||
move || importer.execute_and_commit(sealed_block) | ||
}) | ||
.await??; | ||
core::mem::drop(permit); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl fuel_core_poa::ports::BlockImporter for BlockImporterAdapter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
type Database = Database; | ||
|
||
fn commit_result( | ||
&self, | ||
result: UncommittedResult<StorageTransaction<Self::Database>>, | ||
) -> anyhow::Result<()> { | ||
self.block_importer | ||
.commit_result(result) | ||
.map_err(Into::into) | ||
} | ||
} | ||
|
||
impl BlockVerifier for VerifierAdapter { | ||
fn verify_block_fields( | ||
&self, | ||
|
@@ -126,14 +111,8 @@ impl Executor for ExecutorAdapter { | |
fn execute_without_commit( | ||
&self, | ||
block: ExecutionBlock, | ||
) -> Result< | ||
fuel_core_types::services::executor::UncommittedResult< | ||
StorageTransaction<Self::Database>, | ||
>, | ||
fuel_core_types::services::executor::Error, | ||
> { | ||
fuel_core_producer::ports::Executor::<Database>::execute_without_commit( | ||
self, block, | ||
) | ||
) -> ExecutorResult<UncommittedExecutionResult<StorageTransaction<Self::Database>>> | ||
{ | ||
self._execute_without_commit(block) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::{ | ||
database::Database, | ||
executor::Executor, | ||
service::adapters::ExecutorAdapter, | ||
}; | ||
use fuel_core_storage::transactional::StorageTransaction; | ||
use fuel_core_types::{ | ||
fuel_tx::Receipt, | ||
services::executor::{ | ||
ExecutionBlock, | ||
Result as ExecutorResult, | ||
UncommittedResult, | ||
}, | ||
}; | ||
|
||
impl ExecutorAdapter { | ||
pub(crate) fn _execute_without_commit( | ||
&self, | ||
block: ExecutionBlock, | ||
) -> ExecutorResult<UncommittedResult<StorageTransaction<Database>>> { | ||
let executor = Executor { | ||
database: self.database.clone(), | ||
config: self.config.clone(), | ||
}; | ||
executor.execute_without_commit(block) | ||
} | ||
|
||
pub(crate) fn _dry_run( | ||
&self, | ||
block: ExecutionBlock, | ||
utxo_validation: Option<bool>, | ||
) -> ExecutorResult<Vec<Vec<Receipt>>> { | ||
let executor = Executor { | ||
database: self.database.clone(), | ||
config: self.config.clone(), | ||
}; | ||
executor.dry_run(block, utxo_validation) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ use fuel_core_storage::Result as StorageResult; | |
use fuel_core_types::{ | ||
blockchain::{ | ||
block::Block, | ||
consensus::poa::PoAConsensus, | ||
header::BlockHeader, | ||
primitives::BlockHeight, | ||
SealedBlockHeader, | ||
}, | ||
fuel_tx::Input, | ||
fuel_types::Bytes32, | ||
|
@@ -31,32 +31,25 @@ pub trait Database { | |
fn block_header_merkle_root(&self, height: &BlockHeight) -> StorageResult<Bytes32>; | ||
} | ||
|
||
// TODO: Make this function `async` and await the synchronization with the relayer. | ||
pub fn verify_consensus( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we rename this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It lives inside of |
||
consensus_config: &ConsensusConfig, | ||
header: &SealedBlockHeader, | ||
header: &BlockHeader, | ||
consensus: &PoAConsensus, | ||
) -> bool { | ||
let SealedBlockHeader { | ||
entity: header, | ||
consensus, | ||
} = header; | ||
match consensus { | ||
fuel_core_types::blockchain::consensus::Consensus::PoA(consensus) => { | ||
match consensus_config { | ||
ConsensusConfig::PoA { signing_key } => { | ||
let id = header.id(); | ||
let m = id.as_message(); | ||
consensus | ||
.signature | ||
.recover(m) | ||
.map_or(false, |k| Input::owner(&k) == *signing_key) | ||
} | ||
} | ||
match consensus_config { | ||
ConsensusConfig::PoA { signing_key } => { | ||
let id = header.id(); | ||
let m = id.as_message(); | ||
consensus | ||
.signature | ||
.recover(m) | ||
.map_or(false, |k| Input::owner(&k) == *signing_key) | ||
} | ||
_ => true, | ||
} | ||
} | ||
|
||
pub fn verify_poa_block_fields<D: Database>( | ||
pub fn verify_block_fields<D: Database>( | ||
config: &Config, | ||
database: &D, | ||
block: &Block, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the semaphore from here for now because
Importer
already returns an error if the import process is in progress.We don't plan to import several blocks simultaneously. I think receiving an error is better than hiding it under the semaphore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be a problem in local testing if manual-block-production is enabled? I.e. maybe they have interval mode set for block time but manually trigger some blocks and there's a conflict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they face an error in the tests, it may be better to update the test=D Because if you produce more blocks during manual production than you asked, it may cause wrong test results.