Skip to content

Commit

Permalink
Fix a clonning of the TxPool
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed Feb 7, 2023
1 parent c159dce commit 42df1b5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
8 changes: 6 additions & 2 deletions crates/fuel-core/src/graphql_api/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use crate::{
CoreSchema,
CoreSchemaBuilder,
},
service::metrics::metrics,
service::{
adapters::P2PAdapter,
metrics::metrics,
},
};
use async_graphql::{
extensions::Tracing,
Expand Down Expand Up @@ -76,7 +79,8 @@ pub type BlockProducer = crate::service::adapters::BlockProducerAdapter;
// TODO: When the port of TxPool will exist we need to replace it with
// `Box<dyn TxPoolPort>. In the future GraphQL should not be aware of `TxPool`. It should
// use only `Database` to receive all information about
pub type TxPool = crate::service::sub_services::TxPoolService;
pub type TxPool =
fuel_core_txpool::service::SharedState<P2PAdapter, crate::database::Database>;

#[derive(Clone)]
pub struct SharedState {
Expand Down
5 changes: 2 additions & 3 deletions crates/fuel-core/src/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl TxQuery {
let id = id.0;
let txpool = ctx.data_unchecked::<TxPool>();

if let Some(transaction) = txpool.shared.find_one(id) {
if let Some(transaction) = txpool.find_one(id) {
Ok(Some(Transaction(transaction.tx().clone().deref().into())))
} else {
query.transaction(&id).into_api_result()
Expand Down Expand Up @@ -210,7 +210,6 @@ impl TxMutation {
let mut tx = FuelTx::from_bytes(&tx.0)?;
tx.precompute();
let _: Vec<_> = txpool
.shared
.insert(vec![Arc::new(tx.clone())])
.into_iter()
.try_collect()?;
Expand Down Expand Up @@ -249,7 +248,7 @@ impl TxStatusSubscription {
) -> impl Stream<Item = async_graphql::Result<TransactionStatus>> + 'a {
let txpool = ctx.data_unchecked::<TxPool>().clone();
let db = ctx.data_unchecked::<Database>();
let rx = BroadcastStream::new(txpool.shared.tx_update_subscribe());
let rx = BroadcastStream::new(txpool.tx_update_subscribe());
let state = StreamState { txpool, db };

transaction_status_change(state, rx.boxed(), id.into())
Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/schema/tx/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ pub(super) async fn get_tx_status(
.into_api_result::<txpool::TransactionStatus, StorageError>()?
{
Some(status) => Ok(Some(status.into())),
None => match txpool.shared.find_one(id) {
None => match txpool.find_one(id) {
Some(transaction_in_pool) => {
let time = transaction_in_pool.submitted_time();
Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time))))
Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub fn init_sub_services(
Box::new(database.clone()),
schema,
producer_adapter,
txpool.clone(),
txpool.shared.clone(),
Box::new(poa_adapter),
)?;

Expand Down

0 comments on commit 42df1b5

Please sign in to comment.