From 2fe7bb61fcbbae045cd2829fd77031fc73a6bc46 Mon Sep 17 00:00:00 2001 From: green Date: Fri, 11 Oct 2024 19:31:29 +0200 Subject: [PATCH 1/3] Prepare the GraphQL service for the switching to `async` methods --- crates/fuel-core/src/coins_query.rs | 2 - crates/fuel-core/src/graphql_api/database.rs | 114 +++++++----------- crates/fuel-core/src/query.rs | 8 -- crates/fuel-core/src/query/balance.rs | 22 +--- .../src/query/balance/asset_query.rs | 8 +- crates/fuel-core/src/query/blob.rs | 16 +-- crates/fuel-core/src/query/block.rs | 49 +------- crates/fuel-core/src/query/chain.rs | 13 -- crates/fuel-core/src/query/coin.rs | 40 +----- crates/fuel-core/src/query/contract.rs | 61 ++-------- crates/fuel-core/src/query/message.rs | 102 ++++++++-------- crates/fuel-core/src/query/message/test.rs | 11 +- crates/fuel-core/src/query/tx.rs | 45 +------ crates/fuel-core/src/query/upgrades.rs | 26 ++-- crates/fuel-core/src/schema/balance.rs | 1 - crates/fuel-core/src/schema/blob.rs | 1 - crates/fuel-core/src/schema/block.rs | 6 - crates/fuel-core/src/schema/chain.rs | 4 - crates/fuel-core/src/schema/coins.rs | 5 +- crates/fuel-core/src/schema/contract.rs | 3 +- crates/fuel-core/src/schema/da_compressed.rs | 1 - crates/fuel-core/src/schema/gas_price.rs | 4 - crates/fuel-core/src/schema/message.rs | 6 +- crates/fuel-core/src/schema/relayed_tx.rs | 7 +- crates/fuel-core/src/schema/tx.rs | 4 - crates/fuel-core/src/schema/tx/types.rs | 5 - crates/fuel-core/src/schema/upgrades.rs | 1 - 27 files changed, 146 insertions(+), 419 deletions(-) delete mode 100644 crates/fuel-core/src/query/chain.rs diff --git a/crates/fuel-core/src/coins_query.rs b/crates/fuel-core/src/coins_query.rs index 532b67a1bb5..07ca65bd5d6 100644 --- a/crates/fuel-core/src/coins_query.rs +++ b/crates/fuel-core/src/coins_query.rs @@ -1002,7 +1002,6 @@ mod tests { } pub fn owned_coins(&self, owner: &Address) -> Vec { - use crate::query::CoinQueryData; let query = self.service_database(); let query = query.test_view(); query @@ -1013,7 +1012,6 @@ mod tests { } pub fn owned_messages(&self, owner: &Address) -> Vec { - use crate::query::MessageQueryData; let query = self.service_database(); let query = query.test_view(); query diff --git a/crates/fuel-core/src/graphql_api/database.rs b/crates/fuel-core/src/graphql_api/database.rs index 418e14c1318..dfaabd42733 100644 --- a/crates/fuel-core/src/graphql_api/database.rs +++ b/crates/fuel-core/src/graphql_api/database.rs @@ -1,12 +1,6 @@ use crate::fuel_core_graphql_api::{ database::arc_wrapper::ArcWrapper, ports::{ - DatabaseBlocks, - DatabaseChain, - DatabaseContracts, - DatabaseMessageProof, - DatabaseMessages, - DatabaseRelayedTransactions, OffChainDatabase, OnChainDatabase, }, @@ -72,8 +66,6 @@ use std::{ sync::Arc, }; -use super::ports::DatabaseDaCompressedBlocks; - mod arc_wrapper; /// The on-chain view of the database used by the [`ReadView`] to fetch on-chain data. @@ -132,13 +124,13 @@ impl ReadDatabase { #[derive(Clone)] pub struct ReadView { - genesis_height: BlockHeight, - on_chain: OnChainView, - off_chain: OffChainView, + pub(crate) genesis_height: BlockHeight, + pub(crate) on_chain: OnChainView, + pub(crate) off_chain: OffChainView, } -impl DatabaseBlocks for ReadView { - fn transaction(&self, tx_id: &TxId) -> StorageResult { +impl ReadView { + pub fn transaction(&self, tx_id: &TxId) -> StorageResult { let result = self.on_chain.transaction(tx_id); if result.is_not_found() { if let Some(tx) = self.old_transaction(tx_id)? { @@ -151,7 +143,7 @@ impl DatabaseBlocks for ReadView { } } - fn block(&self, height: &BlockHeight) -> StorageResult { + pub fn block(&self, height: &BlockHeight) -> StorageResult { if *height >= self.genesis_height { self.on_chain.block(height) } else { @@ -159,7 +151,7 @@ impl DatabaseBlocks for ReadView { } } - fn blocks( + pub fn blocks( &self, height: Option, direction: IterDirection, @@ -202,11 +194,11 @@ impl DatabaseBlocks for ReadView { } } - fn latest_height(&self) -> StorageResult { + pub fn latest_height(&self) -> StorageResult { self.on_chain.latest_height() } - fn consensus(&self, id: &BlockHeight) -> StorageResult { + pub fn consensus(&self, id: &BlockHeight) -> StorageResult { if *id >= self.genesis_height { self.on_chain.consensus(id) } else { @@ -215,45 +207,34 @@ impl DatabaseBlocks for ReadView { } } -impl DatabaseDaCompressedBlocks for ReadView { - fn da_compressed_block(&self, id: &BlockHeight) -> StorageResult> { - self.off_chain.da_compressed_block(id) - } - - fn latest_height(&self) -> StorageResult { - self.on_chain.latest_height() - } -} - -impl StorageInspect for ReadView -where - M: Mappable, - dyn OnChainDatabase: StorageInspect, -{ +impl StorageInspect for ReadView { type Error = StorageError; - fn get(&self, key: &M::Key) -> StorageResult>> { - self.on_chain.get(key) + fn get( + &self, + key: &::Key, + ) -> StorageResult::OwnedValue>>> { + StorageInspect::::get(self.on_chain.as_ref(), key) } - fn contains_key(&self, key: &M::Key) -> StorageResult { - self.on_chain.contains_key(key) + fn contains_key(&self, key: &::Key) -> StorageResult { + StorageInspect::::contains_key(self.on_chain.as_ref(), key) } } impl StorageSize for ReadView { fn size_of_value(&self, key: &BlobId) -> Result, Self::Error> { - self.on_chain.size_of_value(key) + StorageSize::::size_of_value(self.on_chain.as_ref(), key) } } impl StorageRead for ReadView { fn read(&self, key: &BlobId, buf: &mut [u8]) -> Result, Self::Error> { - self.on_chain.read(key, buf) + StorageRead::::read(self.on_chain.as_ref(), key, buf) } fn read_alloc(&self, key: &BlobId) -> Result>, Self::Error> { - self.on_chain.read_alloc(key) + StorageRead::::read_alloc(self.on_chain.as_ref(), key) } } @@ -263,8 +244,8 @@ impl PredicateStorageRequirements for ReadView { } } -impl DatabaseMessages for ReadView { - fn all_messages( +impl ReadView { + pub fn all_messages( &self, start_message_id: Option, direction: IterDirection, @@ -272,23 +253,18 @@ impl DatabaseMessages for ReadView { self.on_chain.all_messages(start_message_id, direction) } - fn message_exists(&self, nonce: &Nonce) -> StorageResult { + pub fn message_exists(&self, nonce: &Nonce) -> StorageResult { self.on_chain.message_exists(nonce) } -} -impl DatabaseRelayedTransactions for ReadView { - fn transaction_status( + pub fn relayed_transaction_status( &self, id: Bytes32, ) -> StorageResult> { - let maybe_status = self.off_chain.relayed_tx_status(id)?; - Ok(maybe_status) + self.off_chain.relayed_tx_status(id) } -} -impl DatabaseContracts for ReadView { - fn contract_balances( + pub fn contract_balances( &self, contract: ContractId, start_asset: Option, @@ -297,16 +273,12 @@ impl DatabaseContracts for ReadView { self.on_chain .contract_balances(contract, start_asset, direction) } -} -impl DatabaseChain for ReadView { - fn da_height(&self) -> StorageResult { + pub fn da_height(&self) -> StorageResult { self.on_chain.da_height() } -} -impl DatabaseMessageProof for ReadView { - fn block_history_proof( + pub fn block_history_proof( &self, message_block_height: &BlockHeight, commit_block_height: &BlockHeight, @@ -316,22 +288,20 @@ impl DatabaseMessageProof for ReadView { } } -impl OnChainDatabase for ReadView {} - -impl OffChainDatabase for ReadView { - fn block_height(&self, block_id: &BlockId) -> StorageResult { +impl ReadView { + pub fn block_height(&self, block_id: &BlockId) -> StorageResult { self.off_chain.block_height(block_id) } - fn da_compressed_block(&self, height: &BlockHeight) -> StorageResult> { + pub fn da_compressed_block(&self, height: &BlockHeight) -> StorageResult> { self.off_chain.da_compressed_block(height) } - fn tx_status(&self, tx_id: &TxId) -> StorageResult { + pub fn tx_status(&self, tx_id: &TxId) -> StorageResult { self.off_chain.tx_status(tx_id) } - fn owned_coins_ids( + pub fn owned_coins_ids( &self, owner: &Address, start_coin: Option, @@ -340,7 +310,7 @@ impl OffChainDatabase for ReadView { self.off_chain.owned_coins_ids(owner, start_coin, direction) } - fn owned_message_ids( + pub fn owned_message_ids( &self, owner: &Address, start_message_id: Option, @@ -350,7 +320,7 @@ impl OffChainDatabase for ReadView { .owned_message_ids(owner, start_message_id, direction) } - fn owned_transactions_ids( + pub fn owned_transactions_ids( &self, owner: Address, start: Option, @@ -360,15 +330,15 @@ impl OffChainDatabase for ReadView { .owned_transactions_ids(owner, start, direction) } - fn contract_salt(&self, contract_id: &ContractId) -> StorageResult { + pub fn contract_salt(&self, contract_id: &ContractId) -> StorageResult { self.off_chain.contract_salt(contract_id) } - fn old_block(&self, height: &BlockHeight) -> StorageResult { + pub fn old_block(&self, height: &BlockHeight) -> StorageResult { self.off_chain.old_block(height) } - fn old_blocks( + pub fn old_blocks( &self, height: Option, direction: IterDirection, @@ -376,25 +346,25 @@ impl OffChainDatabase for ReadView { self.off_chain.old_blocks(height, direction) } - fn old_block_consensus(&self, height: &BlockHeight) -> StorageResult { + pub fn old_block_consensus(&self, height: &BlockHeight) -> StorageResult { self.off_chain.old_block_consensus(height) } - fn old_transaction( + pub fn old_transaction( &self, id: &TxId, ) -> StorageResult> { self.off_chain.old_transaction(id) } - fn relayed_tx_status( + pub fn relayed_tx_status( &self, id: Bytes32, ) -> StorageResult> { self.off_chain.relayed_tx_status(id) } - fn message_is_spent(&self, nonce: &Nonce) -> StorageResult { + pub fn message_is_spent(&self, nonce: &Nonce) -> StorageResult { self.off_chain.message_is_spent(nonce) } } diff --git a/crates/fuel-core/src/query.rs b/crates/fuel-core/src/query.rs index fc2dc79ea9b..0dc744bcec0 100644 --- a/crates/fuel-core/src/query.rs +++ b/crates/fuel-core/src/query.rs @@ -1,7 +1,6 @@ mod balance; mod blob; mod block; -mod chain; mod coin; mod contract; mod message; @@ -13,12 +12,5 @@ pub mod da_compressed; // TODO: Remove reexporting of everything pub use balance::*; -pub use blob::*; -pub use block::*; -pub use chain::*; -pub use coin::*; -pub use contract::*; pub use message::*; pub(crate) use subscriptions::*; -pub use tx::*; -pub use upgrades::*; diff --git a/crates/fuel-core/src/query/balance.rs b/crates/fuel-core/src/query/balance.rs index ecbc47620bd..34e7d5c8d95 100644 --- a/crates/fuel-core/src/query/balance.rs +++ b/crates/fuel-core/src/query/balance.rs @@ -27,24 +27,8 @@ use std::{ pub mod asset_query; -pub trait BalanceQueryData: Send + Sync { - fn balance( - &self, - owner: Address, - asset_id: AssetId, - base_asset_id: AssetId, - ) -> StorageResult; - - fn balances( - &self, - owner: Address, - direction: IterDirection, - base_asset_id: AssetId, - ) -> BoxedIter>; -} - -impl BalanceQueryData for ReadView { - fn balance( +impl ReadView { + pub fn balance( &self, owner: Address, asset_id: AssetId, @@ -75,7 +59,7 @@ impl BalanceQueryData for ReadView { }) } - fn balances( + pub fn balances( &self, owner: Address, direction: IterDirection, diff --git a/crates/fuel-core/src/query/balance/asset_query.rs b/crates/fuel-core/src/query/balance/asset_query.rs index 57225b07930..e9ecf206aed 100644 --- a/crates/fuel-core/src/query/balance/asset_query.rs +++ b/crates/fuel-core/src/query/balance/asset_query.rs @@ -1,10 +1,4 @@ -use crate::{ - graphql_api::database::ReadView, - query::{ - CoinQueryData, - MessageQueryData, - }, -}; +use crate::graphql_api::database::ReadView; use fuel_core_storage::{ iter::IterDirection, Error as StorageError, diff --git a/crates/fuel-core/src/query/blob.rs b/crates/fuel-core/src/query/blob.rs index a3987c4ff10..6c7f9e7de8d 100644 --- a/crates/fuel-core/src/query/blob.rs +++ b/crates/fuel-core/src/query/blob.rs @@ -1,7 +1,4 @@ -use crate::graphql_api::ports::{ - OffChainDatabase, - OnChainDatabase, -}; +use crate::fuel_core_graphql_api::database::ReadView; use fuel_core_storage::{ not_found, tables::BlobData, @@ -10,17 +7,12 @@ use fuel_core_storage::{ }; use fuel_core_types::fuel_tx::BlobId; -pub trait BlobQueryData: Send + Sync { - fn blob_exists(&self, id: BlobId) -> StorageResult; - fn blob_bytecode(&self, id: BlobId) -> StorageResult>; -} - -impl BlobQueryData for D { - fn blob_exists(&self, id: BlobId) -> StorageResult { +impl ReadView { + pub fn blob_exists(&self, id: BlobId) -> StorageResult { self.storage::().contains_key(&id) } - fn blob_bytecode(&self, id: BlobId) -> StorageResult> { + pub fn blob_bytecode(&self, id: BlobId) -> StorageResult> { let blob = self .storage::() .get(&id)? diff --git a/crates/fuel-core/src/query/block.rs b/crates/fuel-core/src/query/block.rs index 9c365a3ef26..6ef7cf38afa 100644 --- a/crates/fuel-core/src/query/block.rs +++ b/crates/fuel-core/src/query/block.rs @@ -1,4 +1,4 @@ -use crate::fuel_core_graphql_api::ports::DatabaseBlocks; +use crate::fuel_core_graphql_api::database::ReadView; use fuel_core_storage::{ iter::{ BoxedIter, @@ -7,61 +7,24 @@ use fuel_core_storage::{ Result as StorageResult, }; use fuel_core_types::{ - blockchain::{ - block::CompressedBlock, - consensus::Consensus, - }, + blockchain::block::CompressedBlock, fuel_types::BlockHeight, }; -pub trait SimpleBlockData: Send + Sync { - fn block(&self, id: &BlockHeight) -> StorageResult; -} - -impl SimpleBlockData for D -where - D: DatabaseBlocks + ?Sized + Send + Sync, -{ - fn block(&self, id: &BlockHeight) -> StorageResult { - self.block(id) - } -} - -pub trait BlockQueryData: Send + Sync + SimpleBlockData { - fn latest_block_height(&self) -> StorageResult; - - fn latest_block(&self) -> StorageResult; - - fn compressed_blocks( - &self, - height: Option, - direction: IterDirection, - ) -> BoxedIter>; - - fn consensus(&self, id: &BlockHeight) -> StorageResult; -} - -impl BlockQueryData for D -where - D: DatabaseBlocks + ?Sized + Send + Sync, -{ - fn latest_block_height(&self) -> StorageResult { +impl ReadView { + pub fn latest_block_height(&self) -> StorageResult { self.latest_height() } - fn latest_block(&self) -> StorageResult { + pub fn latest_block(&self) -> StorageResult { self.block(&self.latest_block_height()?) } - fn compressed_blocks( + pub fn compressed_blocks( &self, height: Option, direction: IterDirection, ) -> BoxedIter> { self.blocks(height, direction) } - - fn consensus(&self, id: &BlockHeight) -> StorageResult { - self.consensus(id) - } } diff --git a/crates/fuel-core/src/query/chain.rs b/crates/fuel-core/src/query/chain.rs deleted file mode 100644 index aebf442cf30..00000000000 --- a/crates/fuel-core/src/query/chain.rs +++ /dev/null @@ -1,13 +0,0 @@ -use crate::fuel_core_graphql_api::ports::OnChainDatabase; -use fuel_core_storage::Result as StorageResult; -use fuel_core_types::blockchain::primitives::DaBlockHeight; - -pub trait ChainQueryData: Send + Sync { - fn da_height(&self) -> StorageResult; -} - -impl ChainQueryData for D { - fn da_height(&self) -> StorageResult { - self.da_height() - } -} diff --git a/crates/fuel-core/src/query/coin.rs b/crates/fuel-core/src/query/coin.rs index 171a88168bd..fc944a623f5 100644 --- a/crates/fuel-core/src/query/coin.rs +++ b/crates/fuel-core/src/query/coin.rs @@ -1,7 +1,4 @@ -use crate::fuel_core_graphql_api::ports::{ - OffChainDatabase, - OnChainDatabase, -}; +use crate::fuel_core_graphql_api::database::ReadView; use fuel_core_storage::{ iter::{ BoxedIter, @@ -19,27 +16,11 @@ use fuel_core_types::{ fuel_types::Address, }; -pub trait CoinQueryData: Send + Sync { - fn coin(&self, utxo_id: UtxoId) -> StorageResult; - - fn owned_coins_ids( - &self, - owner: &Address, - start_coin: Option, - direction: IterDirection, - ) -> BoxedIter>; - - fn owned_coins( - &self, - owner: &Address, - start_coin: Option, - direction: IterDirection, - ) -> BoxedIter>; -} - -impl CoinQueryData for D { - fn coin(&self, utxo_id: UtxoId) -> StorageResult { +impl ReadView { + pub fn coin(&self, utxo_id: UtxoId) -> StorageResult { let coin = self + .on_chain + .as_ref() .storage::() .get(&utxo_id)? .ok_or(not_found!(Coins))? @@ -48,16 +29,7 @@ impl CoinQueryData for D { Ok(coin.uncompress(utxo_id)) } - fn owned_coins_ids( - &self, - owner: &Address, - start_coin: Option, - direction: IterDirection, - ) -> BoxedIter> { - self.owned_coins_ids(owner, start_coin, direction) - } - - fn owned_coins( + pub fn owned_coins( &self, owner: &Address, start_coin: Option, diff --git a/crates/fuel-core/src/query/contract.rs b/crates/fuel-core/src/query/contract.rs index 3311fec5dd9..fa75e05a874 100644 --- a/crates/fuel-core/src/query/contract.rs +++ b/crates/fuel-core/src/query/contract.rs @@ -1,12 +1,5 @@ -use crate::fuel_core_graphql_api::ports::{ - OffChainDatabase, - OnChainDatabase, -}; +use crate::fuel_core_graphql_api::database::ReadView; use fuel_core_storage::{ - iter::{ - BoxedIter, - IterDirection, - }, not_found, tables::{ ContractsAssets, @@ -20,38 +13,21 @@ use fuel_core_types::{ AssetId, ContractId, }, - fuel_vm::Salt, services::graphql_api::ContractBalance, }; -pub trait ContractQueryData: Send + Sync { - fn contract_exists(&self, id: ContractId) -> StorageResult; - - fn contract_bytecode(&self, id: ContractId) -> StorageResult>; - - fn contract_salt(&self, id: ContractId) -> StorageResult; - - fn contract_balance( - &self, - contract_id: ContractId, - asset_id: AssetId, - ) -> StorageResult; - - fn contract_balances( - &self, - contract_id: ContractId, - start_asset: Option, - direction: IterDirection, - ) -> BoxedIter>; -} - -impl ContractQueryData for D { - fn contract_exists(&self, id: ContractId) -> StorageResult { - self.storage::().contains_key(&id) +impl ReadView { + pub fn contract_exists(&self, id: ContractId) -> StorageResult { + self.on_chain + .as_ref() + .storage::() + .contains_key(&id) } - fn contract_bytecode(&self, id: ContractId) -> StorageResult> { + pub fn contract_bytecode(&self, id: ContractId) -> StorageResult> { let contract = self + .on_chain + .as_ref() .storage::() .get(&id)? .ok_or(not_found!(ContractsRawCode))? @@ -60,16 +36,14 @@ impl ContractQueryData for D { Ok(contract.into()) } - fn contract_salt(&self, id: ContractId) -> StorageResult { - self.contract_salt(&id) - } - - fn contract_balance( + pub fn contract_balance( &self, contract_id: ContractId, asset_id: AssetId, ) -> StorageResult { let amount = self + .on_chain + .as_ref() .storage::() .get(&(&contract_id, &asset_id).into())? .ok_or(not_found!(ContractsAssets))? @@ -81,13 +55,4 @@ impl ContractQueryData for D { asset_id, }) } - - fn contract_balances( - &self, - contract_id: ContractId, - start_asset: Option, - direction: IterDirection, - ) -> BoxedIter> { - self.contract_balances(contract_id, start_asset, direction) - } } diff --git a/crates/fuel-core/src/query/message.rs b/crates/fuel-core/src/query/message.rs index ece4a93fec7..aedadd47949 100644 --- a/crates/fuel-core/src/query/message.rs +++ b/crates/fuel-core/src/query/message.rs @@ -1,19 +1,6 @@ -use crate::{ - fuel_core_graphql_api::{ - ports::{ - DatabaseBlocks, - DatabaseMessageProof, - DatabaseMessages, - OffChainDatabase, - OnChainDatabase, - }, - IntoApiResult, - }, - query::{ - SimpleBlockData, - SimpleTransactionData, - TransactionQueryData, - }, +use crate::fuel_core_graphql_api::{ + database::ReadView, + IntoApiResult, }; use fuel_core_storage::{ iter::{ @@ -39,6 +26,7 @@ use fuel_core_types::{ fuel_tx::{ input::message::compute_message_id, Receipt, + Transaction, TxId, }, fuel_types::{ @@ -80,24 +68,17 @@ pub trait MessageQueryData: Send + Sync { ) -> BoxedIter>; } -impl MessageQueryData for D { - fn message(&self, id: &Nonce) -> StorageResult { - self.storage::() +impl ReadView { + pub fn message(&self, id: &Nonce) -> StorageResult { + self.on_chain + .as_ref() + .storage::() .get(id)? .ok_or(not_found!(Messages)) .map(Cow::into_owned) } - fn owned_message_ids( - &self, - owner: &Address, - start_message_id: Option, - direction: IterDirection, - ) -> BoxedIter> { - self.owned_message_ids(owner, start_message_id, direction) - } - - fn owned_messages( + pub fn owned_messages( &self, owner: &Address, start_message_id: Option, @@ -107,37 +88,61 @@ impl MessageQueryData for D { .map(|result| result.and_then(|id| self.message(&id))) .into_boxed() } - - fn all_messages( - &self, - start_message_id: Option, - direction: IterDirection, - ) -> BoxedIter> { - self.all_messages(start_message_id, direction) - } } /// Trait that specifies all the data required by the output message query. -pub trait MessageProofData: - Send + Sync + SimpleBlockData + SimpleTransactionData + DatabaseMessageProof -{ +pub trait MessageProofData { + /// Get the block. + fn block(&self, id: &BlockHeight) -> StorageResult; + + /// Get the transaction. + fn transaction(&self, transaction_id: &TxId) -> StorageResult; + + /// Return all receipts in the given transaction. + fn receipts(&self, transaction_id: &TxId) -> StorageResult>; + /// Get the status of a transaction. fn transaction_status( &self, transaction_id: &TxId, ) -> StorageResult; + + /// Gets the [`MerkleProof`] for the message block at `message_block_height` height + /// relatively to the commit block where message block <= commit block. + fn block_history_proof( + &self, + message_block_height: &BlockHeight, + commit_block_height: &BlockHeight, + ) -> StorageResult; } -impl MessageProofData for D -where - D: OnChainDatabase + DatabaseBlocks + OffChainDatabase + ?Sized, -{ +impl MessageProofData for ReadView { + fn block(&self, id: &BlockHeight) -> StorageResult { + self.block(id) + } + + fn transaction(&self, transaction_id: &TxId) -> StorageResult { + self.transaction(transaction_id) + } + + fn receipts(&self, transaction_id: &TxId) -> StorageResult> { + self.receipts(transaction_id) + } + fn transaction_status( &self, transaction_id: &TxId, ) -> StorageResult { self.status(transaction_id) } + + fn block_history_proof( + &self, + message_block_height: &BlockHeight, + commit_block_height: &BlockHeight, + ) -> StorageResult { + self.block_history_proof(message_block_height, commit_block_height) + } } /// Generate an output proof. @@ -282,13 +287,10 @@ fn message_receipts_proof( } } -pub fn message_status( - database: &T, +pub fn message_status( + database: &ReadView, message_nonce: Nonce, -) -> StorageResult -where - T: OffChainDatabase + DatabaseMessages + ?Sized, -{ +) -> StorageResult { if database.message_is_spent(&message_nonce)? { Ok(MessageStatus::spent()) } else if database.message_exists(&message_nonce)? { diff --git a/crates/fuel-core/src/query/message/test.rs b/crates/fuel-core/src/query/message/test.rs index 3078f3a7de9..d49f173370b 100644 --- a/crates/fuel-core/src/query/message/test.rs +++ b/crates/fuel-core/src/query/message/test.rs @@ -57,24 +57,15 @@ fn receipt(i: Option) -> Receipt { mockall::mock! { pub ProofDataStorage {} - impl SimpleBlockData for ProofDataStorage { + impl MessageProofData for ProofDataStorage { fn block(&self, height: &BlockHeight) -> StorageResult; - } - - impl DatabaseMessageProof for ProofDataStorage { fn block_history_proof( &self, message_block_height: &BlockHeight, commit_block_height: &BlockHeight, ) -> StorageResult; - } - - impl SimpleTransactionData for ProofDataStorage { fn transaction(&self, transaction_id: &TxId) -> StorageResult; fn receipts(&self, transaction_id: &TxId) -> StorageResult>; - } - - impl MessageProofData for ProofDataStorage { fn transaction_status(&self, transaction_id: &TxId) -> StorageResult; } } diff --git a/crates/fuel-core/src/query/tx.rs b/crates/fuel-core/src/query/tx.rs index 1d2f1531363..894d05d9c6f 100644 --- a/crates/fuel-core/src/query/tx.rs +++ b/crates/fuel-core/src/query/tx.rs @@ -1,8 +1,4 @@ -use crate::fuel_core_graphql_api::ports::{ - DatabaseBlocks, - OffChainDatabase, - OnChainDatabase, -}; +use crate::fuel_core_graphql_api::database::ReadView; use fuel_core_storage::{ iter::{ @@ -25,23 +21,8 @@ use fuel_core_types::{ services::txpool::TransactionStatus, }; -pub trait SimpleTransactionData: Send + Sync { - /// Return all receipts in the given transaction. - fn receipts(&self, transaction_id: &TxId) -> StorageResult>; - - /// Get the transaction. - fn transaction(&self, transaction_id: &TxId) -> StorageResult; -} - -impl SimpleTransactionData for D -where - D: OnChainDatabase + DatabaseBlocks + OffChainDatabase + ?Sized, -{ - fn transaction(&self, tx_id: &TxId) -> StorageResult { - self.transaction(tx_id) - } - - fn receipts(&self, tx_id: &TxId) -> StorageResult> { +impl ReadView { + pub fn receipts(&self, tx_id: &TxId) -> StorageResult> { let status = self.status(tx_id)?; let receipts = match status { @@ -51,28 +32,12 @@ where }; receipts.ok_or(not_found!(Transactions)) } -} - -pub trait TransactionQueryData: Send + Sync + SimpleTransactionData { - fn status(&self, tx_id: &TxId) -> StorageResult; - - fn owned_transactions( - &self, - owner: Address, - start: Option, - direction: IterDirection, - ) -> BoxedIter>; -} -impl TransactionQueryData for D -where - D: OnChainDatabase + DatabaseBlocks + OffChainDatabase + ?Sized, -{ - fn status(&self, tx_id: &TxId) -> StorageResult { + pub fn status(&self, tx_id: &TxId) -> StorageResult { self.tx_status(tx_id) } - fn owned_transactions( + pub fn owned_transactions( &self, owner: Address, start: Option, diff --git a/crates/fuel-core/src/query/upgrades.rs b/crates/fuel-core/src/query/upgrades.rs index 4a53edbe12a..850b7e6973f 100644 --- a/crates/fuel-core/src/query/upgrades.rs +++ b/crates/fuel-core/src/query/upgrades.rs @@ -1,3 +1,4 @@ +use crate::fuel_core_graphql_api::database::ReadView; use fuel_core_storage::{ not_found, tables::{ @@ -13,27 +14,14 @@ use fuel_core_types::{ fuel_vm::UploadedBytecode, }; -use crate::graphql_api::ports::OnChainDatabase; - -pub trait UpgradeQueryData: Send + Sync { - fn state_transition_bytecode_root( - &self, - version: StateTransitionBytecodeVersion, - ) -> StorageResult; - - fn state_transition_bytecode(&self, root: Bytes32) - -> StorageResult; -} - -impl UpgradeQueryData for D -where - D: OnChainDatabase + ?Sized, -{ - fn state_transition_bytecode_root( +impl ReadView { + pub fn state_transition_bytecode_root( &self, version: StateTransitionBytecodeVersion, ) -> StorageResult { let merkle_root = self + .on_chain + .as_ref() .storage::() .get(&version)? .ok_or(not_found!(StateTransitionBytecodeVersions))? @@ -42,11 +30,13 @@ where Ok(merkle_root) } - fn state_transition_bytecode( + pub fn state_transition_bytecode( &self, root: Bytes32, ) -> StorageResult { let bytecode = self + .on_chain + .as_ref() .storage::() .get(&root)? .ok_or(not_found!(UploadedBytecodes))? diff --git a/crates/fuel-core/src/schema/balance.rs b/crates/fuel-core/src/schema/balance.rs index 6f83a831449..7c43e3a9509 100644 --- a/crates/fuel-core/src/schema/balance.rs +++ b/crates/fuel-core/src/schema/balance.rs @@ -3,7 +3,6 @@ use crate::{ api_service::ConsensusProvider, QUERY_COSTS, }, - query::BalanceQueryData, schema::{ scalars::{ Address, diff --git a/crates/fuel-core/src/schema/blob.rs b/crates/fuel-core/src/schema/blob.rs index 938c2a6a1f3..93974346f1f 100644 --- a/crates/fuel-core/src/schema/blob.rs +++ b/crates/fuel-core/src/schema/blob.rs @@ -1,7 +1,6 @@ use crate::{ fuel_core_graphql_api::QUERY_COSTS, graphql_api::IntoApiResult, - query::BlobQueryData, schema::{ scalars::{ BlobId, diff --git a/crates/fuel-core/src/schema/block.rs b/crates/fuel-core/src/schema/block.rs index 81a9bf3c0af..cebd04989b6 100644 --- a/crates/fuel-core/src/schema/block.rs +++ b/crates/fuel-core/src/schema/block.rs @@ -7,16 +7,10 @@ use crate::{ fuel_core_graphql_api::{ api_service::ConsensusModule, database::ReadView, - ports::OffChainDatabase, Config as GraphQLConfig, IntoApiResult, QUERY_COSTS, }, - query::{ - BlockQueryData, - SimpleBlockData, - SimpleTransactionData, - }, schema::{ scalars::{ BlockId, diff --git a/crates/fuel-core/src/schema/chain.rs b/crates/fuel-core/src/schema/chain.rs index 16ec77b1e46..643902cc0c5 100644 --- a/crates/fuel-core/src/schema/chain.rs +++ b/crates/fuel-core/src/schema/chain.rs @@ -4,10 +4,6 @@ use crate::{ QUERY_COSTS, }, graphql_api::Config, - query::{ - BlockQueryData, - ChainQueryData, - }, schema::{ block::Block, scalars::{ diff --git a/crates/fuel-core/src/schema/coins.rs b/crates/fuel-core/src/schema/coins.rs index 0d0abc97da2..3610c152e6b 100644 --- a/crates/fuel-core/src/schema/coins.rs +++ b/crates/fuel-core/src/schema/coins.rs @@ -8,10 +8,7 @@ use crate::{ QUERY_COSTS, }, graphql_api::api_service::ConsensusProvider, - query::{ - asset_query::AssetSpendTarget, - CoinQueryData, - }, + query::asset_query::AssetSpendTarget, schema::{ scalars::{ Address, diff --git a/crates/fuel-core/src/schema/contract.rs b/crates/fuel-core/src/schema/contract.rs index 2abc0e53a06..a8fe6dea693 100644 --- a/crates/fuel-core/src/schema/contract.rs +++ b/crates/fuel-core/src/schema/contract.rs @@ -3,7 +3,6 @@ use crate::{ IntoApiResult, QUERY_COSTS, }, - query::ContractQueryData, schema::{ scalars::{ AssetId, @@ -60,7 +59,7 @@ impl Contract { async fn salt(&self, ctx: &Context<'_>) -> async_graphql::Result { let query = ctx.read_view()?; query - .contract_salt(self.0) + .contract_salt(&self.0) .map(Into::into) .map_err(Into::into) } diff --git a/crates/fuel-core/src/schema/da_compressed.rs b/crates/fuel-core/src/schema/da_compressed.rs index 3af336f8ba9..9badfb1b8c1 100644 --- a/crates/fuel-core/src/schema/da_compressed.rs +++ b/crates/fuel-core/src/schema/da_compressed.rs @@ -7,7 +7,6 @@ use crate::{ IntoApiResult, QUERY_COSTS, }, - query::da_compressed::DaCompressedBlockData, schema::scalars::U32, }; use async_graphql::{ diff --git a/crates/fuel-core/src/schema/gas_price.rs b/crates/fuel-core/src/schema/gas_price.rs index f1ded5fc106..d2a80d67f9d 100644 --- a/crates/fuel-core/src/schema/gas_price.rs +++ b/crates/fuel-core/src/schema/gas_price.rs @@ -7,10 +7,6 @@ use crate::{ api_service::GasPriceProvider, QUERY_COSTS, }, - query::{ - BlockQueryData, - SimpleTransactionData, - }, schema::ReadViewProvider, }; use async_graphql::{ diff --git a/crates/fuel-core/src/schema/message.rs b/crates/fuel-core/src/schema/message.rs index 8ba18784bf8..05416623934 100644 --- a/crates/fuel-core/src/schema/message.rs +++ b/crates/fuel-core/src/schema/message.rs @@ -11,12 +11,8 @@ use super::{ ReadViewProvider, }; use crate::{ - fuel_core_graphql_api::{ - ports::OffChainDatabase, - QUERY_COSTS, - }, + fuel_core_graphql_api::QUERY_COSTS, graphql_api::IntoApiResult, - query::MessageQueryData, schema::scalars::{ BlockId, U32, diff --git a/crates/fuel-core/src/schema/relayed_tx.rs b/crates/fuel-core/src/schema/relayed_tx.rs index 1bc915df1bf..850c67cda4b 100644 --- a/crates/fuel-core/src/schema/relayed_tx.rs +++ b/crates/fuel-core/src/schema/relayed_tx.rs @@ -1,8 +1,5 @@ use crate::{ - fuel_core_graphql_api::{ - ports::DatabaseRelayedTransactions, - QUERY_COSTS, - }, + fuel_core_graphql_api::QUERY_COSTS, schema::{ scalars::{ RelayedTransactionId, @@ -33,7 +30,7 @@ impl RelayedTransactionQuery { #[graphql(desc = "The id of the relayed tx")] id: RelayedTransactionId, ) -> async_graphql::Result> { let query = ctx.read_view()?; - let status = query.transaction_status(id.0)?.map(|status| status.into()); + let status = query.relayed_tx_status(id.0)?.map(|status| status.into()); Ok(status) } } diff --git a/crates/fuel-core/src/schema/tx.rs b/crates/fuel-core/src/schema/tx.rs index d0a1474340a..89b20101db0 100644 --- a/crates/fuel-core/src/schema/tx.rs +++ b/crates/fuel-core/src/schema/tx.rs @@ -6,7 +6,6 @@ use crate::{ ConsensusProvider, TxPool, }, - ports::OffChainDatabase, IntoApiResult, QUERY_COSTS, }, @@ -16,9 +15,6 @@ use crate::{ }, query::{ transaction_status_change, - BlockQueryData, - SimpleTransactionData, - TransactionQueryData, TxnStatusChangeState, }, schema::{ diff --git a/crates/fuel-core/src/schema/tx/types.rs b/crates/fuel-core/src/schema/tx/types.rs index 820271430e2..097d6f06fdd 100644 --- a/crates/fuel-core/src/schema/tx/types.rs +++ b/crates/fuel-core/src/schema/tx/types.rs @@ -13,11 +13,6 @@ use crate::{ IntoApiResult, QUERY_COSTS, }, - query::{ - SimpleBlockData, - SimpleTransactionData, - TransactionQueryData, - }, schema::{ block::Block, scalars::{ diff --git a/crates/fuel-core/src/schema/upgrades.rs b/crates/fuel-core/src/schema/upgrades.rs index d9e62906a1e..4df3efddf72 100644 --- a/crates/fuel-core/src/schema/upgrades.rs +++ b/crates/fuel-core/src/schema/upgrades.rs @@ -4,7 +4,6 @@ use crate::{ IntoApiResult, QUERY_COSTS, }, - query::UpgradeQueryData, schema::{ chain::ConsensusParameters, scalars::HexString, From ab5e940ffed387f165bd4b7c94204c7169bc71c6 Mon Sep 17 00:00:00 2001 From: green Date: Fri, 11 Oct 2024 19:40:54 +0200 Subject: [PATCH 2/3] Updated CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e5da278c28..35b21a83e99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed + +- [2334](https://github.com/FuelLabs/fuel-core/pull/2334): Prepare the GraphQL service for the switching to `async` methods. + ## [Version 0.39.0] ### Added From 5a752bc0b7f08b507077aa0bb1953c7faee80da0 Mon Sep 17 00:00:00 2001 From: green Date: Mon, 14 Oct 2024 09:08:39 +0200 Subject: [PATCH 3/3] Fix flakiness --- crates/services/src/async_processor.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/services/src/async_processor.rs b/crates/services/src/async_processor.rs index 6a5b43f395f..383bfc150c2 100644 --- a/crates/services/src/async_processor.rs +++ b/crates/services/src/async_processor.rs @@ -287,6 +287,7 @@ mod tests { // Then while broadcast_receiver.recv().await.is_ok() {} + tokio::task::yield_now().await; assert!(instant.elapsed() <= Duration::from_secs(2)); let duration = Duration::from_nanos(heavy_task_processor.metric.busy.get()); assert_eq!(duration.as_secs(), 0);