Skip to content

Commit

Permalink
feat: Don't require Send in BoxedIter
Browse files Browse the repository at this point in the history
  • Loading branch information
netrome committed Nov 1, 2024
1 parent 79e42da commit 32993e0
Show file tree
Hide file tree
Showing 21 changed files with 185 additions and 132 deletions.
4 changes: 2 additions & 2 deletions crates/fuel-core/src/database/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};
use fuel_core_storage::{
iter::{
IntoBoxedIter,
IntoBoxedIterSend,
IterDirection,
IteratorOverTable,
},
Expand Down Expand Up @@ -68,7 +68,7 @@ impl OnChainIterableKeyValueView {
let db_block = self.storage::<FuelBlocks>().get(height)?;

if let Some(block) = db_block {
let transaction_ids = block.transactions().iter().into_boxed();
let transaction_ids = block.transactions().iter().into_boxed_send();
let txs = <Self as StorageBatchInspect<Transactions>>::get_batch(
self,
transaction_ids,
Expand Down
15 changes: 8 additions & 7 deletions crates/fuel-core/src/graphql_api/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use crate::fuel_core_graphql_api::{
use fuel_core_services::yield_stream::StreamYieldExt;
use fuel_core_storage::{
iter::{
BoxedIter,
IntoBoxedIter,
BoxedIterSend,
IntoBoxedIterSend,
IntoBoxedIterKeep,
IterDirection,
},
transactional::AtomicView,
Expand Down Expand Up @@ -205,7 +206,7 @@ impl ReadView {
&self,
height: Option<BlockHeight>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<CompressedBlock>> {
) -> BoxedIterSend<'_, StorageResult<CompressedBlock>> {
// Chain together blocks from the off-chain db and the on-chain db
// The blocks in off-chain db, if any, are from time before regenesis

Expand All @@ -218,12 +219,12 @@ impl ReadView {
.on_chain
.blocks(Some(height), direction)
.chain(self.off_chain.old_blocks(None, direction))
.into_boxed(),
.into_boxed_send(),
(false, IterDirection::Forward) => self
.off_chain
.old_blocks(Some(height), direction)
.chain(self.on_chain.blocks(None, direction))
.into_boxed(),
.into_boxed_send(),
(false, IterDirection::Reverse) => {
self.off_chain.old_blocks(Some(height), direction)
}
Expand All @@ -234,12 +235,12 @@ impl ReadView {
.off_chain
.old_blocks(None, direction)
.chain(self.on_chain.blocks(None, direction))
.into_boxed(),
.into_boxed_send(),
IterDirection::Reverse => self
.on_chain
.blocks(None, direction)
.chain(self.off_chain.old_blocks(None, direction))
.into_boxed(),
.into_boxed_send(),
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions crates/fuel-core/src/graphql_api/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use async_trait::async_trait;
use fuel_core_services::stream::BoxStream;
use fuel_core_storage::{
iter::{
BoxedIterSend,
BoxedIter,
IterDirection,
},
Expand Down Expand Up @@ -79,21 +80,21 @@ pub trait OffChainDatabase: Send + Sync {
owner: &Address,
start_coin: Option<UtxoId>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<UtxoId>>;
) -> BoxedIterSend<'_, StorageResult<UtxoId>>;

fn owned_message_ids(
&self,
owner: &Address,
start_message_id: Option<Nonce>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<Nonce>>;
) -> BoxedIterSend<'_, StorageResult<Nonce>>;

fn owned_transactions_ids(
&self,
owner: Address,
start: Option<TxPointer>,
direction: IterDirection,
) -> BoxedIter<StorageResult<(TxPointer, TxId)>>;
) -> BoxedIterSend<StorageResult<(TxPointer, TxId)>>;

fn contract_salt(&self, contract_id: &ContractId) -> StorageResult<Salt>;

Expand All @@ -103,7 +104,7 @@ pub trait OffChainDatabase: Send + Sync {
&self,
height: Option<BlockHeight>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<CompressedBlock>>;
) -> BoxedIterSend<'_, StorageResult<CompressedBlock>>;

fn old_block_consensus(&self, height: &BlockHeight) -> StorageResult<Consensus>;

Expand Down Expand Up @@ -156,7 +157,7 @@ pub trait DatabaseBlocks {
&self,
height: Option<BlockHeight>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<CompressedBlock>>;
) -> BoxedIterSend<'_, StorageResult<CompressedBlock>>;

fn latest_height(&self) -> StorageResult<BlockHeight>;

Expand All @@ -178,7 +179,7 @@ pub trait DatabaseMessages: StorageInspect<Messages, Error = StorageError> {
&self,
start_message_id: Option<Nonce>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<Message>>;
) -> BoxedIterSend<'_, StorageResult<Message>>;

fn message_batch<'a>(
&'a self,
Expand All @@ -199,7 +200,10 @@ pub trait DatabaseRelayedTransactions {
pub trait DatabaseCoins: StorageInspect<Coins, Error = StorageError> {
fn coin(&self, utxo_id: UtxoId) -> StorageResult<Coin>;

fn coins<'a>(&'a self, utxo_ids: &'a [UtxoId]) -> BoxedIter<'a, StorageResult<Coin>>;
fn coins<'a>(
&'a self,
utxo_ids: &'a [UtxoId],
) -> BoxedIter<'a, StorageResult<Coin>>;
}

/// Trait that specifies all the getters required for contract.
Expand All @@ -212,7 +216,7 @@ pub trait DatabaseContracts:
contract: ContractId,
start_asset: Option<AssetId>,
direction: IterDirection,
) -> BoxedIter<StorageResult<ContractBalance>>;
) -> BoxedIterSend<StorageResult<ContractBalance>>;
}

/// Trait that specifies all the getters required for chain metadata.
Expand Down
10 changes: 5 additions & 5 deletions crates/fuel-core/src/query/message.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::fuel_core_graphql_api::database::ReadView;
use fuel_core_storage::{
iter::{
BoxedIter,
IntoBoxedIter,
BoxedIterSend,
IntoBoxedIterKeep,
IterDirection,
},
not_found,
Expand Down Expand Up @@ -53,20 +53,20 @@ pub trait MessageQueryData: Send + Sync {
owner: &Address,
start_message_id: Option<Nonce>,
direction: IterDirection,
) -> BoxedIter<StorageResult<Nonce>>;
) -> BoxedIterSend<StorageResult<Nonce>>;

fn owned_messages(
&self,
owner: &Address,
start_message_id: Option<Nonce>,
direction: IterDirection,
) -> BoxedIter<StorageResult<Message>>;
) -> BoxedIterSend<StorageResult<Message>>;

fn all_messages(
&self,
start_message_id: Option<Nonce>,
direction: IterDirection,
) -> BoxedIter<StorageResult<Message>>;
) -> BoxedIterSend<StorageResult<Message>>;
}

impl ReadView {
Expand Down
20 changes: 11 additions & 9 deletions crates/fuel-core/src/service/adapters/graphql_api/off_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ use fuel_core_storage::{
blueprint::BlueprintInspect,
codec::Encode,
iter::{
BoxedIterSend,
BoxedIter,
IntoBoxedIter,
IntoBoxedIterSend,
IntoBoxedIterKeep,
IterDirection,
IteratorOverTable,
},
Expand Down Expand Up @@ -97,36 +99,36 @@ impl OffChainDatabase for OffChainIterableKeyValueView {
owner: &Address,
start_coin: Option<UtxoId>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<UtxoId>> {
) -> BoxedIterSend<'_, StorageResult<UtxoId>> {
self.owned_coins_ids(owner, start_coin, Some(direction))
.map(|res| res.map_err(StorageError::from))
.into_boxed()
.into_boxed_send()
}

fn owned_message_ids(
&self,
owner: &Address,
start_message_id: Option<Nonce>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<Nonce>> {
) -> BoxedIterSend<'_, StorageResult<Nonce>> {
self.owned_message_ids(owner, start_message_id, Some(direction))
.map(|result| result.map_err(StorageError::from))
.into_boxed()
.into_boxed_send()
}

fn owned_transactions_ids(
&self,
owner: Address,
start: Option<TxPointer>,
direction: IterDirection,
) -> BoxedIter<StorageResult<(TxPointer, TxId)>> {
) -> BoxedIterSend<StorageResult<(TxPointer, TxId)>> {
let start = start.map(|tx_pointer| OwnedTransactionIndexCursor {
block_height: tx_pointer.block_height(),
tx_idx: tx_pointer.tx_index(),
});
self.owned_transactions(owner, start, Some(direction))
.map(|result| result.map_err(StorageError::from))
.into_boxed()
.into_boxed_send()
}

fn contract_salt(&self, contract_id: &ContractId) -> StorageResult<Salt> {
Expand All @@ -153,10 +155,10 @@ impl OffChainDatabase for OffChainIterableKeyValueView {
&self,
height: Option<BlockHeight>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<CompressedBlock>> {
) -> BoxedIterSend<'_, StorageResult<CompressedBlock>> {
self.iter_all_by_start::<OldFuelBlocks>(height.as_ref(), Some(direction))
.map(|r| r.map(|(_, block)| block))
.into_boxed()
.into_boxed_send()
}

fn old_block_consensus(&self, height: &BlockHeight) -> StorageResult<Consensus> {
Expand Down
25 changes: 15 additions & 10 deletions crates/fuel-core/src/service/adapters/graphql_api/on_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ use crate::{
};
use fuel_core_storage::{
iter::{
BoxedIterSend,
BoxedIter,
IntoBoxedIter,
IntoBoxedIterSend,
IntoBoxedIterKeep,
IterDirection,
IteratorOverTable,
},
Expand Down Expand Up @@ -93,10 +95,10 @@ impl DatabaseBlocks for OnChainIterableKeyValueView {
&self,
height: Option<BlockHeight>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<CompressedBlock>> {
) -> BoxedIterSend<'_, StorageResult<CompressedBlock>> {
self.iter_all_by_start::<FuelBlocks>(height.as_ref(), Some(direction))
.map(|result| result.map(|(_, block)| block))
.into_boxed()
.into_boxed_send()
}

fn latest_height(&self) -> StorageResult<BlockHeight> {
Expand All @@ -116,10 +118,10 @@ impl DatabaseMessages for OnChainIterableKeyValueView {
&self,
start_message_id: Option<Nonce>,
direction: IterDirection,
) -> BoxedIter<'_, StorageResult<Message>> {
) -> BoxedIterSend<'_, StorageResult<Message>> {
self.all_messages(start_message_id, Some(direction))
.map(|result| result.map_err(StorageError::from))
.into_boxed()
.into_boxed_send()
}

fn message_batch<'a>(
Expand Down Expand Up @@ -147,12 +149,15 @@ impl DatabaseCoins for OnChainIterableKeyValueView {
Ok(coin.uncompress(utxo_id))
}

fn coins<'a>(&'a self, utxo_ids: &'a [UtxoId]) -> BoxedIter<'a, StorageResult<Coin>> {
fn coins<'a>(
&'a self,
utxo_ids: &'a [UtxoId],
) -> BoxedIter<'a, StorageResult<Coin>> {
<Self as StorageBatchInspect<Coins>>::get_batch(
self,
utxo_ids.iter().into_boxed(),
utxo_ids.iter().into_boxed_send(),
)
.zip(utxo_ids.iter().into_boxed())
.zip(utxo_ids.iter().into_boxed_send())
.map(|(res, utxo_id)| {
res.and_then(|opt| opt.ok_or(not_found!(Coins)))
.map(|coin| coin.uncompress(*utxo_id))
Expand All @@ -167,15 +172,15 @@ impl DatabaseContracts for OnChainIterableKeyValueView {
contract: ContractId,
start_asset: Option<AssetId>,
direction: IterDirection,
) -> BoxedIter<StorageResult<ContractBalance>> {
) -> BoxedIterSend<StorageResult<ContractBalance>> {
self.filter_contract_balances(contract, start_asset, Some(direction))
.map_ok(|entry| ContractBalance {
owner: *entry.key.contract_id(),
amount: entry.value,
asset_id: *entry.key.asset_id(),
})
.map(|res| res.map_err(StorageError::from))
.into_boxed()
.into_boxed_send()
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/fuel-core/src/service/genesis/importer/import_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ mod tests {
use fuel_core_storage::{
column::Column,
iter::{
BoxedIter,
BoxedIterSend,
IterDirection,
IterableStore,
},
Expand Down Expand Up @@ -551,7 +551,7 @@ mod tests {
_: Option<&[u8]>,
_: Option<&[u8]>,
_: IterDirection,
) -> BoxedIter<KVItem> {
) -> BoxedIterSend<KVItem> {
unimplemented!()
}

Expand All @@ -561,7 +561,7 @@ mod tests {
_: Option<&[u8]>,
_: Option<&[u8]>,
_: IterDirection,
) -> BoxedIter<KeyItem> {
) -> BoxedIterSend<KeyItem> {
unimplemented!()
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/fuel-core/src/state/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
};
use fuel_core_storage::{
iter::{
BoxedIterSend,
BoxedIter,
IterDirection,
IterableStore,
Expand Down Expand Up @@ -96,7 +97,7 @@ where
prefix: Option<&[u8]>,
start: Option<&[u8]>,
direction: IterDirection,
) -> BoxedIter<KVItem> {
) -> BoxedIterSend<KVItem> {
self.data.iter_store(column, prefix, start, direction)
}

Expand All @@ -106,7 +107,7 @@ where
prefix: Option<&[u8]>,
start: Option<&[u8]>,
direction: IterDirection,
) -> BoxedIter<fuel_core_storage::kv_store::KeyItem> {
) -> BoxedIterSend<fuel_core_storage::kv_store::KeyItem> {
self.data.iter_store_keys(column, prefix, start, direction)
}
}
Loading

0 comments on commit 32993e0

Please sign in to comment.