Skip to content

Commit

Permalink
Addressed comments. Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed Mar 21, 2024
1 parent 2698382 commit a0d99e1
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 18 deletions.
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.

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 @@ -131,6 +131,7 @@ impl RunnableService for SyncTask {

#[async_trait::async_trait]
impl RunnableTask for SyncTask {
#[allow(clippy::blocks_in_conditions)]
#[tracing::instrument(level = "debug", skip_all, err, ret)]
async fn run(&mut self, watcher: &mut StateWatcher) -> anyhow::Result<bool> {
let mut should_continue = true;
Expand Down
1 change: 0 additions & 1 deletion crates/services/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ where
// TODO: Make this module private after moving unit tests from `fuel-core` here.
pub mod block_component {
use super::*;
use fuel_core_types::fuel_tx::field::MintGasPrice;

pub struct PartialBlockComponent<'a, TxSource> {
pub empty_block: &'a mut PartialFuelBlock,
Expand Down
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)]
#[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)]
#[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: 2 additions & 8 deletions crates/services/txpool/src/mock_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,7 @@ impl MockDb {

impl TxPoolDb for MockDb {
fn utxo(&self, utxo_id: &UtxoId) -> StorageResult<Option<CompressedCoin>> {
Ok(self
.data
.lock()
.unwrap()
.coins
.get(utxo_id)
.map(Clone::clone))
Ok(self.data.lock().unwrap().coins.get(utxo_id).cloned())
}

fn contract_exist(&self, contract_id: &ContractId) -> StorageResult<bool> {
Expand All @@ -88,7 +82,7 @@ impl TxPoolDb for MockDb {
}

fn message(&self, id: &Nonce) -> StorageResult<Option<Message>> {
Ok(self.data.lock().unwrap().messages.get(id).map(Clone::clone))
Ok(self.data.lock().unwrap().messages.get(id).cloned())
}

fn is_message_spent(&self, id: &Nonce) -> StorageResult<bool> {
Expand Down
7 changes: 3 additions & 4 deletions crates/services/upgradable-executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::config::Config;
use fuel_core_executor::{
executor::{
ExecutionBlockWithSource,
ExecutionInstance,
ExecutionOptions,
OnceTransactionsSource,
},
Expand Down Expand Up @@ -40,7 +39,7 @@ use fuel_core_types::{
use std::sync::Arc;

/// The upgradable executor supports the WASM version of the state transition function.
/// If the block allows it, the executor uses a native state transition function.
/// If the block has a version the same as a native executor, we will use it.
/// If not, the WASM version of the state transition function will be used
/// (if the database has a corresponding bytecode).
pub struct Executor<S, R> {
Expand Down Expand Up @@ -254,7 +253,7 @@ where
instance.run(&self.module)
}

#[allow(dead_code)]
#[cfg(not(feature = "wasm-executor"))]
fn native_execute_inner<TxSource>(
&self,
block: ExecutionBlockWithSource<TxSource>,
Expand All @@ -270,7 +269,7 @@ where
.take()
.unwrap_or_else(|| self.config.consensus_parameters.clone());

let instance = ExecutionInstance {
let instance = fuel_core_executor::executor::ExecutionInstance {
relayer,
database: storage,
consensus_params,
Expand Down
8 changes: 4 additions & 4 deletions crates/services/upgradable-executor/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'a> CallerHelper for Caller<'a, ExecutionState> {
struct ExecutionState {
/// The memory used by the WASM module.
memory: Option<Memory>,
next_transaction: HashMap<u32, Vec<Vec<u8>>>,
next_transactions: HashMap<u32, Vec<Vec<u8>>>,
relayer_events: HashMap<DaBlockHeight, Value>,
}

Expand Down Expand Up @@ -92,7 +92,7 @@ impl Instance {
engine,
ExecutionState {
memory: None,
next_transaction: Default::default(),
next_transactions: Default::default(),
relayer_events: Default::default(),
},
),
Expand Down Expand Up @@ -184,7 +184,7 @@ impl Instance<Created> {

caller
.data_mut()
.next_transaction
.next_transactions
.entry(encoded_size)
.or_default()
.push(encoded_txs);
Expand All @@ -201,7 +201,7 @@ impl Instance<Created> {
-> anyhow::Result<()> {
let encoded = caller
.data_mut()
.next_transaction
.next_transactions
.get_mut(&output_size)
.and_then(|vector| vector.pop())
.unwrap_or_default();
Expand Down
3 changes: 3 additions & 0 deletions crates/services/upgradable-executor/wasm-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ fuel-core-storage = { workspace = true, default-features = false }
fuel-core-types = { workspace = true, default-features = false }
postcard = { workspace = true }

[dev-dependencies]
proptest = { workspace = true }

[features]
default = ["std"]
std = []
30 changes: 30 additions & 0 deletions crates/services/upgradable-executor/wasm-executor/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,33 @@ pub fn unpack_exists_size_result(val: u64) -> (bool, u32, u16) {
pub type InputType = ExecutionBlockWithSource<()>;

pub type ReturnType = ExecutorResult<Uncommitted<ExecutionResult, Changes>>;

#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::prop::*;

proptest::proptest! {
#[test]
fn can_pack_any_values(exists: bool, size: u32, result: u16) {
pack_exists_size_result(exists, size, result);
}

#[test]
fn can_unpack_any_values(value: u64) {
let _ = unpack_exists_size_result(value);
}


#[test]
fn unpacks_packed_values(exists: bool, size: u32, result: u16) {
let packed = pack_exists_size_result(exists, size, result);
let (unpacked_exists, unpacked_size, unpacked_result) =
unpack_exists_size_result(packed);

proptest::prop_assert_eq!(exists, unpacked_exists);
proptest::prop_assert_eq!(size, unpacked_size);
proptest::prop_assert_eq!(result, unpacked_result);
}
}
}
1 change: 0 additions & 1 deletion crates/types/src/blockchain/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use derive_more::{
UpperHex,
};
use secrecy::{
zeroize,
CloneableSecret,
DebugSecret,
};
Expand Down

0 comments on commit a0d99e1

Please sign in to comment.