From a7340b61d213aa5038bad9f45d56af0db7bb7ca4 Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 13 Apr 2022 17:26:43 -0600 Subject: [PATCH 01/21] Changes re-done to be more in line with things --- fuel-client/assets/schema.sdl | 1 + fuel-client/src/client.rs | 8 ++++++++ fuel-client/src/client/schema/tx.rs | 12 +++++++++++ fuel-core/src/schema/tx.rs | 16 +++++++++++++++ fuel-core/src/schema/tx/types.rs | 26 ++++++++++++++++++++++-- fuel-core/src/tx_pool.rs | 9 +++++++++ fuel-tests/tests/tx.rs | 31 ++++++++++++++++++++++++++++- 7 files changed, 100 insertions(+), 3 deletions(-) diff --git a/fuel-client/assets/schema.sdl b/fuel-client/assets/schema.sdl index 9f61128447c..995d0986296 100644 --- a/fuel-client/assets/schema.sdl +++ b/fuel-client/assets/schema.sdl @@ -222,6 +222,7 @@ type Query { chain: ChainInfo! version: String! transaction(id: TransactionId!): Transaction + dependentTransactions(id: TransactionId!): [Transaction!] transactions(first: Int, after: String, last: Int, before: String): TransactionConnection! transactionsByOwner(owner: Address!, first: Int, after: String, last: Int, before: String): TransactionConnection! """ diff --git a/fuel-client/src/client.rs b/fuel-client/src/client.rs index 993b5507d1e..268896a2aad 100644 --- a/fuel-client/src/client.rs +++ b/fuel-client/src/client.rs @@ -160,6 +160,14 @@ impl FuelClient { Ok(transaction.map(|tx| tx.try_into()).transpose()?) } + pub async fn dependent_transactions(&self, id: &str) -> io::Result> { + let query = schema::tx::TransactionQuery::build(&TxIdArgs { id: id.parse()? }); + + let transaction = self.query(query).await?.transaction; + + Ok(transaction.map(|tx| tx.try_into()).transpose()?) + } + /// Get the status of a transaction pub async fn transaction_status(&self, id: &str) -> io::Result { let query = schema::tx::TransactionQuery::build(&TxIdArgs { id: id.parse()? }); diff --git a/fuel-client/src/client/schema/tx.rs b/fuel-client/src/client/schema/tx.rs index 9e0f88c8f87..b968e5ef96a 100644 --- a/fuel-client/src/client/schema/tx.rs +++ b/fuel-client/src/client/schema/tx.rs @@ -25,6 +25,18 @@ pub struct TransactionQuery { pub transaction: Option, } +/// Retrieves the transaction in opaque form +#[derive(cynic::QueryFragment, Debug)] +#[cynic( + schema_path = "./assets/schema.sdl", + graphql_type = "Query", + argument_struct = "TxIdArgs" +)] +pub struct DependentTransactionsQuery { + #[arguments(id = &args.id)] + pub dependent_transactions: Option>, +} + #[derive(cynic::QueryFragment, Debug)] #[cynic( schema_path = "./assets/schema.sdl", diff --git a/fuel-core/src/schema/tx.rs b/fuel-core/src/schema/tx.rs index cca53a5f74f..175f784eccb 100644 --- a/fuel-core/src/schema/tx.rs +++ b/fuel-core/src/schema/tx.rs @@ -54,6 +54,22 @@ impl TxQuery { } } + async fn dependent_transactions( + &self, + ctx: &Context<'_>, + #[graphql(desc = "Locates all dependent transactions")] id: TransactionId, + ) -> async_graphql::Result>> { + + let tx_pool = ctx.data::>().unwrap(); + + let found_tx = tx_pool.dependent_transactions(id).await.unwrap(); // TODO Fix this ugly unwrap + + // Converts from Transaction enum to type, similar naming makes this confusing though + let returnable_txs = found_tx.into_iter().map(|tx| Transaction(tx)).collect(); + + Ok(Some(returnable_txs)) + } + async fn transactions( &self, ctx: &Context<'_>, diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index e295062d37f..b0dc997bf94 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -10,7 +10,12 @@ use async_graphql::{Context, Enum, Object, Union}; use chrono::{DateTime, Utc}; use fuel_core_interfaces::db::KvStoreError; use fuel_storage::Storage; +use fuel_core_interfaces::txpool::TxPoolDb; +use fuel_core_interfaces::txpool::TxPool; use fuel_types::bytes::SerializableVec; +use fuel_txpool::Config; +use std::sync::Arc; +use fuel_txpool::TxPoolService; use fuel_vm::prelude::ProgramState as VmProgramState; pub struct ProgramState { @@ -214,8 +219,25 @@ impl Transaction { async fn status(&self, ctx: &Context<'_>) -> async_graphql::Result> { let db = ctx.data_unchecked::(); - let status = db.get_tx_status(&self.0.id())?; - Ok(status.map(Into::into)) + + let tx_pooldb = Box::new(db.clone()) as Box; + + let txpool = TxPoolService::new(tx_pooldb, Arc::new(Config::default())); + + let self_id = self.0.id(); + + let do_i_exist = txpool.find(&[self_id]).await; + + let result = do_i_exist.get(0).unwrap().is_some(); + + if result { + // TODO, fix this part where submitted time is lied about + let time = chrono::Utc::now(); + Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time)))) + } else { + let status = db.get_tx_status(&self.0.id())?; + Ok(status.map(Into::into)) + } } async fn receipts(&self, ctx: &Context<'_>) -> async_graphql::Result>> { diff --git a/fuel-core/src/tx_pool.rs b/fuel-core/src/tx_pool.rs index 98f0330ed2c..6c4632fea21 100644 --- a/fuel-core/src/tx_pool.rs +++ b/fuel-core/src/tx_pool.rs @@ -1,6 +1,7 @@ use crate::database::{Database, KvStoreError}; use crate::executor::{ExecutionMode, Executor}; use crate::model::fuel_block::{FuelBlock, FuelBlockHeader}; +use crate::schema::scalars::TransactionId; use crate::service::Config; use chrono::{DateTime, Utc}; use fuel_core_interfaces::txpool::{TxPool as TxPoolTrait, TxPoolDb}; @@ -149,6 +150,14 @@ impl TxPool { Ok(tx_id) } + pub async fn dependent_transactions(&self, tx_id: TransactionId) -> Result, Error> { + let dependent_txs =self.fuel_txpool.find_dependent(&[tx_id.0]).await.clone(); + + let returnable_txs = dependent_txs.into_iter().map(|transaction| Transaction::clone(&*transaction)).collect(); + + Ok(returnable_txs) + } + pub async fn run_tx(&self, tx: Transaction) -> Result, Error> { let id = self.submit_tx(tx).await?; // note: we'll need to await tx completion once it's not instantaneous diff --git a/fuel-tests/tests/tx.rs b/fuel-tests/tests/tx.rs index 0b3ccaed18c..2ef8bf41a0b 100644 --- a/fuel-tests/tests/tx.rs +++ b/fuel-tests/tests/tx.rs @@ -122,6 +122,35 @@ async fn submit() { assert_eq!(tx.id(), ret_tx.id()); } +#[tokio::test] +async fn dependent_tx() { + + + let config = Arc::new(Config::default()); + let db = DummyDB::filled(); + + let tx1_hash = *TX_ID1; + let tx5_hash = *TX_ID5; + let tx1 = Arc::new(DummyDB::dummy_tx(tx1_hash)); + let tx5 = Arc::new(DummyDB::dummy_tx(tx5_hash)); + let mut txpool = TxPool::new(config); + + let out = txpool.insert(tx1, &db).await; + assert!(out.is_ok(), "Tx1 should be Ok:{:?}", out); + let out = txpool.insert(tx5, &db).await; + assert!(out.is_ok(), "Tx5 should be Ok:{:?}", out); + + + /* + I expect that the transaction id I'm searching from is included in the response. + I expect that transactions with overlapping txo inputs and outputs will + form an ordered priority list based on their dependencies and then by gas price. + */ + + let is_sorted = dependent_txs.unwrap().unwrap().transaction; + assert_eq!(is_sorted.id(), id.0); +} + #[tokio::test] async fn submit_utxo_verified_tx() { let config = Config { @@ -533,4 +562,4 @@ fn create_mock_tx(val: u64) -> Transaction { Default::default(), Default::default(), ) -} +} \ No newline at end of file From 936dbfb0335400ed8b544c75afeb7a2f4e7ea561 Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 13 Apr 2022 18:30:01 -0600 Subject: [PATCH 02/21] Removed dependent_txs --- fuel-client/assets/schema.sdl | 1 - fuel-client/src/client.rs | 5 ++++- fuel-core/src/schema/tx.rs | 16 ---------------- fuel-core/src/schema/tx/types.rs | 8 ++++---- fuel-core/src/tx_pool.rs | 9 --------- fuel-tests/tests/tx.rs | 31 +------------------------------ 6 files changed, 9 insertions(+), 61 deletions(-) diff --git a/fuel-client/assets/schema.sdl b/fuel-client/assets/schema.sdl index 995d0986296..9f61128447c 100644 --- a/fuel-client/assets/schema.sdl +++ b/fuel-client/assets/schema.sdl @@ -222,7 +222,6 @@ type Query { chain: ChainInfo! version: String! transaction(id: TransactionId!): Transaction - dependentTransactions(id: TransactionId!): [Transaction!] transactions(first: Int, after: String, last: Int, before: String): TransactionConnection! transactionsByOwner(owner: Address!, first: Int, after: String, last: Int, before: String): TransactionConnection! """ diff --git a/fuel-client/src/client.rs b/fuel-client/src/client.rs index 268896a2aad..d28a9642147 100644 --- a/fuel-client/src/client.rs +++ b/fuel-client/src/client.rs @@ -160,7 +160,10 @@ impl FuelClient { Ok(transaction.map(|tx| tx.try_into()).transpose()?) } - pub async fn dependent_transactions(&self, id: &str) -> io::Result> { + pub async fn dependent_transactions( + &self, + id: &str, + ) -> io::Result> { let query = schema::tx::TransactionQuery::build(&TxIdArgs { id: id.parse()? }); let transaction = self.query(query).await?.transaction; diff --git a/fuel-core/src/schema/tx.rs b/fuel-core/src/schema/tx.rs index 175f784eccb..cca53a5f74f 100644 --- a/fuel-core/src/schema/tx.rs +++ b/fuel-core/src/schema/tx.rs @@ -54,22 +54,6 @@ impl TxQuery { } } - async fn dependent_transactions( - &self, - ctx: &Context<'_>, - #[graphql(desc = "Locates all dependent transactions")] id: TransactionId, - ) -> async_graphql::Result>> { - - let tx_pool = ctx.data::>().unwrap(); - - let found_tx = tx_pool.dependent_transactions(id).await.unwrap(); // TODO Fix this ugly unwrap - - // Converts from Transaction enum to type, similar naming makes this confusing though - let returnable_txs = found_tx.into_iter().map(|tx| Transaction(tx)).collect(); - - Ok(Some(returnable_txs)) - } - async fn transactions( &self, ctx: &Context<'_>, diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index b0dc997bf94..d08823550cc 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -9,14 +9,14 @@ use crate::{database::Database, schema::block::Block}; use async_graphql::{Context, Enum, Object, Union}; use chrono::{DateTime, Utc}; use fuel_core_interfaces::db::KvStoreError; -use fuel_storage::Storage; -use fuel_core_interfaces::txpool::TxPoolDb; use fuel_core_interfaces::txpool::TxPool; -use fuel_types::bytes::SerializableVec; +use fuel_core_interfaces::txpool::TxPoolDb; +use fuel_storage::Storage; use fuel_txpool::Config; -use std::sync::Arc; use fuel_txpool::TxPoolService; +use fuel_types::bytes::SerializableVec; use fuel_vm::prelude::ProgramState as VmProgramState; +use std::sync::Arc; pub struct ProgramState { return_type: ReturnType, diff --git a/fuel-core/src/tx_pool.rs b/fuel-core/src/tx_pool.rs index 6c4632fea21..98f0330ed2c 100644 --- a/fuel-core/src/tx_pool.rs +++ b/fuel-core/src/tx_pool.rs @@ -1,7 +1,6 @@ use crate::database::{Database, KvStoreError}; use crate::executor::{ExecutionMode, Executor}; use crate::model::fuel_block::{FuelBlock, FuelBlockHeader}; -use crate::schema::scalars::TransactionId; use crate::service::Config; use chrono::{DateTime, Utc}; use fuel_core_interfaces::txpool::{TxPool as TxPoolTrait, TxPoolDb}; @@ -150,14 +149,6 @@ impl TxPool { Ok(tx_id) } - pub async fn dependent_transactions(&self, tx_id: TransactionId) -> Result, Error> { - let dependent_txs =self.fuel_txpool.find_dependent(&[tx_id.0]).await.clone(); - - let returnable_txs = dependent_txs.into_iter().map(|transaction| Transaction::clone(&*transaction)).collect(); - - Ok(returnable_txs) - } - pub async fn run_tx(&self, tx: Transaction) -> Result, Error> { let id = self.submit_tx(tx).await?; // note: we'll need to await tx completion once it's not instantaneous diff --git a/fuel-tests/tests/tx.rs b/fuel-tests/tests/tx.rs index 2ef8bf41a0b..0b3ccaed18c 100644 --- a/fuel-tests/tests/tx.rs +++ b/fuel-tests/tests/tx.rs @@ -122,35 +122,6 @@ async fn submit() { assert_eq!(tx.id(), ret_tx.id()); } -#[tokio::test] -async fn dependent_tx() { - - - let config = Arc::new(Config::default()); - let db = DummyDB::filled(); - - let tx1_hash = *TX_ID1; - let tx5_hash = *TX_ID5; - let tx1 = Arc::new(DummyDB::dummy_tx(tx1_hash)); - let tx5 = Arc::new(DummyDB::dummy_tx(tx5_hash)); - let mut txpool = TxPool::new(config); - - let out = txpool.insert(tx1, &db).await; - assert!(out.is_ok(), "Tx1 should be Ok:{:?}", out); - let out = txpool.insert(tx5, &db).await; - assert!(out.is_ok(), "Tx5 should be Ok:{:?}", out); - - - /* - I expect that the transaction id I'm searching from is included in the response. - I expect that transactions with overlapping txo inputs and outputs will - form an ordered priority list based on their dependencies and then by gas price. - */ - - let is_sorted = dependent_txs.unwrap().unwrap().transaction; - assert_eq!(is_sorted.id(), id.0); -} - #[tokio::test] async fn submit_utxo_verified_tx() { let config = Config { @@ -562,4 +533,4 @@ fn create_mock_tx(val: u64) -> Transaction { Default::default(), Default::default(), ) -} \ No newline at end of file +} From 3ef1c1c6f128b36393e3f64e0a397f4bb78d85b4 Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 13 Apr 2022 21:19:25 -0600 Subject: [PATCH 03/21] Cleaned up code --- fuel-client/src/client/schema/tx.rs | 12 ------------ fuel-core/src/schema/tx/types.rs | 8 ++------ 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/fuel-client/src/client/schema/tx.rs b/fuel-client/src/client/schema/tx.rs index b968e5ef96a..9e0f88c8f87 100644 --- a/fuel-client/src/client/schema/tx.rs +++ b/fuel-client/src/client/schema/tx.rs @@ -25,18 +25,6 @@ pub struct TransactionQuery { pub transaction: Option, } -/// Retrieves the transaction in opaque form -#[derive(cynic::QueryFragment, Debug)] -#[cynic( - schema_path = "./assets/schema.sdl", - graphql_type = "Query", - argument_struct = "TxIdArgs" -)] -pub struct DependentTransactionsQuery { - #[arguments(id = &args.id)] - pub dependent_transactions: Option>, -} - #[derive(cynic::QueryFragment, Debug)] #[cynic( schema_path = "./assets/schema.sdl", diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index d08823550cc..a8af09d04bc 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -224,13 +224,9 @@ impl Transaction { let txpool = TxPoolService::new(tx_pooldb, Arc::new(Config::default())); - let self_id = self.0.id(); + let transaction_in_pool = txpool.find(&[self.0.id()]).await; - let do_i_exist = txpool.find(&[self_id]).await; - - let result = do_i_exist.get(0).unwrap().is_some(); - - if result { + if transaction_in_pool.get(0).and_then(|y| y.as_ref()).is_some() { // TODO, fix this part where submitted time is lied about let time = chrono::Utc::now(); Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time)))) From dca62b0ea62e38ccbeacab89142df1a9b7f7ab6b Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 13 Apr 2022 21:32:53 -0600 Subject: [PATCH 04/21] Removed dependent_txs --- fuel-client/src/client.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/fuel-client/src/client.rs b/fuel-client/src/client.rs index d28a9642147..993b5507d1e 100644 --- a/fuel-client/src/client.rs +++ b/fuel-client/src/client.rs @@ -160,17 +160,6 @@ impl FuelClient { Ok(transaction.map(|tx| tx.try_into()).transpose()?) } - pub async fn dependent_transactions( - &self, - id: &str, - ) -> io::Result> { - let query = schema::tx::TransactionQuery::build(&TxIdArgs { id: id.parse()? }); - - let transaction = self.query(query).await?.transaction; - - Ok(transaction.map(|tx| tx.try_into()).transpose()?) - } - /// Get the status of a transaction pub async fn transaction_status(&self, id: &str) -> io::Result { let query = schema::tx::TransactionQuery::build(&TxIdArgs { id: id.parse()? }); From 601425ae2a2032d3d42fd789a2fee20f7885b18f Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 13 Apr 2022 21:34:21 -0600 Subject: [PATCH 05/21] Fmt + Clippy --- fuel-core/src/schema/tx/types.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index a8af09d04bc..47f3da33ab6 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -226,7 +226,11 @@ impl Transaction { let transaction_in_pool = txpool.find(&[self.0.id()]).await; - if transaction_in_pool.get(0).and_then(|y| y.as_ref()).is_some() { + if transaction_in_pool + .get(0) + .and_then(|tx| tx.as_ref()) + .is_some() + { // TODO, fix this part where submitted time is lied about let time = chrono::Utc::now(); Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time)))) From 5f84599dbf78529748cac6aa791a09bfb45a6a23 Mon Sep 17 00:00:00 2001 From: Johann Date: Thu, 14 Apr 2022 21:20:56 -0600 Subject: [PATCH 06/21] Fixed minor bug, test almost done --- Cargo.lock | 2 ++ fuel-core/src/schema/tx/types.rs | 17 +++++------------ fuel-tests/Cargo.toml | 2 ++ fuel-tests/tests/tx.rs | 24 +++++++++++++++++++++++- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18af12d8d47..1f46308cb7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2198,9 +2198,11 @@ version = "0.0.0" dependencies = [ "chrono", "fuel-core 0.5.0", + "fuel-core-interfaces", "fuel-gql-client 0.5.0", "fuel-storage", "fuel-tx 0.7.0", + "fuel-txpool", "fuel-types 0.3.0", "fuel-vm 0.6.0", "insta", diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index 47f3da33ab6..285953967d4 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -4,19 +4,16 @@ use super::receipt::Receipt; use crate::model::fuel_block::FuelBlockDb; use crate::schema::contract::Contract; use crate::schema::scalars::{AssetId, Bytes32, HexString, Salt, TransactionId, U64}; +use crate::schema::tx::Arc; use crate::tx_pool::TransactionStatus as TxStatus; +use crate::tx_pool::TxPool; use crate::{database::Database, schema::block::Block}; use async_graphql::{Context, Enum, Object, Union}; use chrono::{DateTime, Utc}; use fuel_core_interfaces::db::KvStoreError; -use fuel_core_interfaces::txpool::TxPool; -use fuel_core_interfaces::txpool::TxPoolDb; use fuel_storage::Storage; -use fuel_txpool::Config; -use fuel_txpool::TxPoolService; use fuel_types::bytes::SerializableVec; use fuel_vm::prelude::ProgramState as VmProgramState; -use std::sync::Arc; pub struct ProgramState { return_type: ReturnType, @@ -220,17 +217,13 @@ impl Transaction { async fn status(&self, ctx: &Context<'_>) -> async_graphql::Result> { let db = ctx.data_unchecked::(); - let tx_pooldb = Box::new(db.clone()) as Box; - - let txpool = TxPoolService::new(tx_pooldb, Arc::new(Config::default())); + let txpool = ctx.data::>().unwrap().pool(); let transaction_in_pool = txpool.find(&[self.0.id()]).await; - if transaction_in_pool - .get(0) - .and_then(|tx| tx.as_ref()) - .is_some() + if transaction_in_pool.get(0).unwrap().is_some() && db.get_tx_status(&self.0.id()).is_err() { + println!("{:?}", db.get_tx_status(&self.0.id())?); // TODO, fix this part where submitted time is lied about let time = chrono::Utc::now(); Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time)))) diff --git a/fuel-tests/Cargo.toml b/fuel-tests/Cargo.toml index d2d8c780656..a93166f36dd 100644 --- a/fuel-tests/Cargo.toml +++ b/fuel-tests/Cargo.toml @@ -21,6 +21,8 @@ chrono = { version = "0.4", features = ["serde"] } fuel-core = { path = "../fuel-core", features = ["test-helpers"], default-features = false } fuel-gql-client = { path = "../fuel-client", features = ["test-helpers"] } fuel-storage = "0.1" +fuel-txpool = { path = "../fuel-txpool"} +fuel-core-interfaces = { path = "../fuel-core-interfaces" } fuel-tx = { version = "0.7", features = ["serde-types"] } fuel-types = { version = "0.3", features = ["serde-types"] } fuel-vm = { version = "0.6", features = ["serde-types", "random"] } diff --git a/fuel-tests/tests/tx.rs b/fuel-tests/tests/tx.rs index 0b3ccaed18c..1f3c1696ef3 100644 --- a/fuel-tests/tests/tx.rs +++ b/fuel-tests/tests/tx.rs @@ -6,13 +6,19 @@ use fuel_core::{ executor::Executor, service::{Config, FuelService}, }; +use fuel_core_interfaces::db::helpers::*; +use fuel_core_interfaces::txpool::TxPool; use fuel_gql_client::client::types::TransactionStatus; use fuel_gql_client::client::{FuelClient, PageDirection, PaginationRequest}; +use fuel_tx::Transaction; +use fuel_txpool::Config as TxPoolConfig; +use fuel_txpool::TxPoolService; use fuel_vm::util::test_helpers::TestBuilder as TxBuilder; use fuel_vm::{consts::*, prelude::*}; use itertools::Itertools; use rand::{rngs::StdRng, Rng, SeedableRng}; use std::io; +use std::sync::Arc; #[test] fn basic_script_snapshot() { @@ -155,7 +161,6 @@ async fn submit_utxo_verified_tx() { if let TransactionStatus::Success { block_id, .. } = transaction_result.clone() { let block_exists = client.block(&block_id).await.unwrap(); - assert!(block_exists.is_some()); } @@ -166,6 +171,23 @@ async fn submit_utxo_verified_tx() { } } +#[tokio::test] +async fn test_tx_status_submitted() { + let config = Arc::new(TxPoolConfig::default()); + let db = Box::new(DummyDB::filled()); + + let new_pool = TxPoolService::new(db, config); + + let transactions = (1..10 + 1) + .into_iter() + .map(|i| TxBuilder::new(2322u64).gas_limit(i * 1000).build()) + .collect_vec(); + + for tx in transactions { + let result = new_pool.insert(vec![Arc::new(tx)]).await; + } +} + #[tokio::test] async fn receipts() { let transaction = fuel_tx::Transaction::default(); From c07af7fd454110741edab3fc04e27d8747293d58 Mon Sep 17 00:00:00 2001 From: Johann Date: Mon, 18 Apr 2022 16:33:50 -0600 Subject: [PATCH 07/21] cleanup and remove test --- Cargo.lock | 2 -- fuel-core/src/schema/tx/types.rs | 1 - fuel-core/src/tx_pool.rs | 2 ++ fuel-tests/Cargo.toml | 2 -- fuel-tests/tests/tx.rs | 24 +----------------------- 5 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f46308cb7c..18af12d8d47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2198,11 +2198,9 @@ version = "0.0.0" dependencies = [ "chrono", "fuel-core 0.5.0", - "fuel-core-interfaces", "fuel-gql-client 0.5.0", "fuel-storage", "fuel-tx 0.7.0", - "fuel-txpool", "fuel-types 0.3.0", "fuel-vm 0.6.0", "insta", diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index 285953967d4..c7d5072ba8e 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -223,7 +223,6 @@ impl Transaction { if transaction_in_pool.get(0).unwrap().is_some() && db.get_tx_status(&self.0.id()).is_err() { - println!("{:?}", db.get_tx_status(&self.0.id())?); // TODO, fix this part where submitted time is lied about let time = chrono::Utc::now(); Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time)))) diff --git a/fuel-core/src/tx_pool.rs b/fuel-core/src/tx_pool.rs index 98f0330ed2c..751978d3d25 100644 --- a/fuel-core/src/tx_pool.rs +++ b/fuel-core/src/tx_pool.rs @@ -141,11 +141,13 @@ impl TxPool { }, transactions: includable_txs, }; + // immediately execute block self.executor .execute(&mut block, ExecutionMode::Production) .await .map_err(Error::Execution)?; + Ok(tx_id) } diff --git a/fuel-tests/Cargo.toml b/fuel-tests/Cargo.toml index a93166f36dd..d2d8c780656 100644 --- a/fuel-tests/Cargo.toml +++ b/fuel-tests/Cargo.toml @@ -21,8 +21,6 @@ chrono = { version = "0.4", features = ["serde"] } fuel-core = { path = "../fuel-core", features = ["test-helpers"], default-features = false } fuel-gql-client = { path = "../fuel-client", features = ["test-helpers"] } fuel-storage = "0.1" -fuel-txpool = { path = "../fuel-txpool"} -fuel-core-interfaces = { path = "../fuel-core-interfaces" } fuel-tx = { version = "0.7", features = ["serde-types"] } fuel-types = { version = "0.3", features = ["serde-types"] } fuel-vm = { version = "0.6", features = ["serde-types", "random"] } diff --git a/fuel-tests/tests/tx.rs b/fuel-tests/tests/tx.rs index 1f3c1696ef3..0b3ccaed18c 100644 --- a/fuel-tests/tests/tx.rs +++ b/fuel-tests/tests/tx.rs @@ -6,19 +6,13 @@ use fuel_core::{ executor::Executor, service::{Config, FuelService}, }; -use fuel_core_interfaces::db::helpers::*; -use fuel_core_interfaces::txpool::TxPool; use fuel_gql_client::client::types::TransactionStatus; use fuel_gql_client::client::{FuelClient, PageDirection, PaginationRequest}; -use fuel_tx::Transaction; -use fuel_txpool::Config as TxPoolConfig; -use fuel_txpool::TxPoolService; use fuel_vm::util::test_helpers::TestBuilder as TxBuilder; use fuel_vm::{consts::*, prelude::*}; use itertools::Itertools; use rand::{rngs::StdRng, Rng, SeedableRng}; use std::io; -use std::sync::Arc; #[test] fn basic_script_snapshot() { @@ -161,6 +155,7 @@ async fn submit_utxo_verified_tx() { if let TransactionStatus::Success { block_id, .. } = transaction_result.clone() { let block_exists = client.block(&block_id).await.unwrap(); + assert!(block_exists.is_some()); } @@ -171,23 +166,6 @@ async fn submit_utxo_verified_tx() { } } -#[tokio::test] -async fn test_tx_status_submitted() { - let config = Arc::new(TxPoolConfig::default()); - let db = Box::new(DummyDB::filled()); - - let new_pool = TxPoolService::new(db, config); - - let transactions = (1..10 + 1) - .into_iter() - .map(|i| TxBuilder::new(2322u64).gas_limit(i * 1000).build()) - .collect_vec(); - - for tx in transactions { - let result = new_pool.insert(vec![Arc::new(tx)]).await; - } -} - #[tokio::test] async fn receipts() { let transaction = fuel_tx::Transaction::default(); From b8ccda61e606307e748260bd32f0049045677bff Mon Sep 17 00:00:00 2001 From: Johann Date: Mon, 18 Apr 2022 16:34:42 -0600 Subject: [PATCH 08/21] last fix --- fuel-core/src/tx_pool.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/fuel-core/src/tx_pool.rs b/fuel-core/src/tx_pool.rs index 751978d3d25..98f0330ed2c 100644 --- a/fuel-core/src/tx_pool.rs +++ b/fuel-core/src/tx_pool.rs @@ -141,13 +141,11 @@ impl TxPool { }, transactions: includable_txs, }; - // immediately execute block self.executor .execute(&mut block, ExecutionMode::Production) .await .map_err(Error::Execution)?; - Ok(tx_id) } From b3a430cf04f1949ae44834119c0cd13ca1a5c957 Mon Sep 17 00:00:00 2001 From: Johann Date: Tue, 19 Apr 2022 17:04:57 -0600 Subject: [PATCH 09/21] Test todo!() --- fuel-tests/tests/tx.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fuel-tests/tests/tx.rs b/fuel-tests/tests/tx.rs index 0b3ccaed18c..accd754bb46 100644 --- a/fuel-tests/tests/tx.rs +++ b/fuel-tests/tests/tx.rs @@ -166,6 +166,17 @@ async fn submit_utxo_verified_tx() { } } +#[ignore] +#[tokio::test] +async fn transaction_status_submitted() { + // This test should ensure a transaction's status is Submitted while it is in the mempool + // This test should also ensure a transaction's time of submission is correct in the returned status + // Currently blocked until https://github.com/FuelLabs/fuel-core/issues/50 is resolved + // as execution must be seperate from submission for a tx to persist inside of the txpool + // Merge with the submit_utxo_verified_tx test once utxo_verification is the default + todo!(); +} + #[tokio::test] async fn receipts() { let transaction = fuel_tx::Transaction::default(); From 69897501541d3d9a3baae64e1fd8fac8d7fe6f93 Mon Sep 17 00:00:00 2001 From: Johann Date: Tue, 19 Apr 2022 17:05:52 -0600 Subject: [PATCH 10/21] Test annotation --- fuel-tests/tests/tx.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/fuel-tests/tests/tx.rs b/fuel-tests/tests/tx.rs index accd754bb46..48d9645332c 100644 --- a/fuel-tests/tests/tx.rs +++ b/fuel-tests/tests/tx.rs @@ -159,6 +159,7 @@ async fn submit_utxo_verified_tx() { assert!(block_exists.is_some()); } + // Once https://github.com/FuelLabs/fuel-core/issues/50 is resolved this should rely on the Submitted Status rather than Success assert!(matches!( transaction_result, TransactionStatus::Success { .. } From 750812bece27ffdbf516d50a4a53647feb5ce473 Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 20 Apr 2022 21:05:03 -0600 Subject: [PATCH 11/21] minor fix --- fuel-core/src/schema/tx/types.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index 343813e4263..d1410ed12bb 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -14,6 +14,7 @@ use fuel_core_interfaces::db::KvStoreError; use fuel_storage::Storage; use fuel_types::bytes::SerializableVec; use fuel_vm::prelude::ProgramState as VmProgramState; +use fuel_txpool::TxPoolService; pub struct ProgramState { return_type: ReturnType, @@ -219,9 +220,9 @@ impl Transaction { let txpool = ctx.data::>().unwrap().pool(); - let transaction_in_pool = txpool.find(&[self.0.id()]).await; + let transaction_in_pool = txpool.find_one(&self.0.id()).await; - if transaction_in_pool.get(0).unwrap().is_some() && db.get_tx_status(&self.0.id()).is_err() + if transaction_in_pool.is_some() && db.get_tx_status(&self.0.id()).is_err() { // TODO, fix this part where submitted time is lied about let time = chrono::Utc::now(); From de9b918fe1cc95b8f341126e968df861a6fb8ec9 Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 20 Apr 2022 21:24:57 -0600 Subject: [PATCH 12/21] fmt --- fuel-core/src/schema/tx/types.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index d1410ed12bb..d739e070ce9 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -12,9 +12,9 @@ use async_graphql::{Context, Enum, Object, Union}; use chrono::{DateTime, Utc}; use fuel_core_interfaces::db::KvStoreError; use fuel_storage::Storage; +use fuel_txpool::TxPoolService; use fuel_types::bytes::SerializableVec; use fuel_vm::prelude::ProgramState as VmProgramState; -use fuel_txpool::TxPoolService; pub struct ProgramState { return_type: ReturnType, @@ -222,8 +222,7 @@ impl Transaction { let transaction_in_pool = txpool.find_one(&self.0.id()).await; - if transaction_in_pool.is_some() && db.get_tx_status(&self.0.id()).is_err() - { + if transaction_in_pool.is_some() && db.get_tx_status(&self.0.id()).is_err() { // TODO, fix this part where submitted time is lied about let time = chrono::Utc::now(); Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time)))) From 20d05cddfabc5a054b4372c4d483a15f9266bb2c Mon Sep 17 00:00:00 2001 From: Johann Date: Fri, 22 Apr 2022 12:37:30 -0600 Subject: [PATCH 13/21] Use find_one, use correct time, TxInfo refactor, ArcTx Move, also status api finally working --- fuel-core-interfaces/src/lib.rs | 1 + fuel-core-interfaces/src/txpool.rs | 5 ++-- fuel-core/src/schema/tx.rs | 2 +- fuel-core/src/schema/tx/types.rs | 3 +-- fuel-txpool/src/containers.rs | 1 - fuel-txpool/src/containers/dependency.rs | 4 +-- fuel-txpool/src/containers/info.rs | 34 ------------------------ fuel-txpool/src/containers/price_sort.rs | 1 + fuel-txpool/src/service.rs | 17 +++++------- fuel-txpool/src/subscribers.rs | 3 ++- fuel-txpool/src/txpool.rs | 3 ++- fuel-txpool/src/types.rs | 2 -- 12 files changed, 19 insertions(+), 57 deletions(-) delete mode 100644 fuel-txpool/src/containers/info.rs diff --git a/fuel-core-interfaces/src/lib.rs b/fuel-core-interfaces/src/lib.rs index 1dccaf2392a..6dbb27a85fd 100644 --- a/fuel-core-interfaces/src/lib.rs +++ b/fuel-core-interfaces/src/lib.rs @@ -1,3 +1,4 @@ pub mod db; +pub mod info; pub mod model; pub mod txpool; diff --git a/fuel-core-interfaces/src/txpool.rs b/fuel-core-interfaces/src/txpool.rs index e1b04db809a..6f5c07ac28f 100644 --- a/fuel-core-interfaces/src/txpool.rs +++ b/fuel-core-interfaces/src/txpool.rs @@ -7,6 +7,7 @@ use thiserror::Error; use crate::{ db::{Error as DbStateError, KvStoreError}, + info::TxInfo, model::Coin, }; use fuel_storage::Storage; @@ -50,10 +51,10 @@ pub trait TxPool: Send + Sync { -> Vec>>>; /// find all tx by their hash - async fn find(&self, hashes: &[TxId]) -> Vec>>; + async fn find(&self, hashes: &[TxId]) -> Vec>; /// find one tx by its hash - async fn find_one(&self, hash: &TxId) -> Option>; + async fn find_one(&self, hash: &TxId) -> Option; /// find all dependent tx and return them with requsted dependencies in one list sorted by Price. async fn find_dependent(&self, hashes: &[TxId]) -> Vec>; diff --git a/fuel-core/src/schema/tx.rs b/fuel-core/src/schema/tx.rs index 9574e51676b..2b1ffd0eac3 100644 --- a/fuel-core/src/schema/tx.rs +++ b/fuel-core/src/schema/tx.rs @@ -47,7 +47,7 @@ impl TxQuery { let found_tx = tx_pool.pool().find(&[key]).await; if let Some(Some(transaction)) = found_tx.get(0) { - Ok(Some(Transaction((transaction.deref()).clone()))) + Ok(Some(Transaction((transaction.tx().deref()).clone()))) } else { Ok(Storage::::get(db, &key)? .map(|tx| Transaction(tx.into_owned()))) diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index d739e070ce9..e9c50d808ab 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -12,7 +12,6 @@ use async_graphql::{Context, Enum, Object, Union}; use chrono::{DateTime, Utc}; use fuel_core_interfaces::db::KvStoreError; use fuel_storage::Storage; -use fuel_txpool::TxPoolService; use fuel_types::bytes::SerializableVec; use fuel_vm::prelude::ProgramState as VmProgramState; @@ -224,7 +223,7 @@ impl Transaction { if transaction_in_pool.is_some() && db.get_tx_status(&self.0.id()).is_err() { // TODO, fix this part where submitted time is lied about - let time = chrono::Utc::now(); + let time = transaction_in_pool.unwrap().submited_time(); Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time)))) } else { let status = db.get_tx_status(&self.0.id())?; diff --git a/fuel-txpool/src/containers.rs b/fuel-txpool/src/containers.rs index a8b92fdca78..e9493b7969e 100644 --- a/fuel-txpool/src/containers.rs +++ b/fuel-txpool/src/containers.rs @@ -1,3 +1,2 @@ pub mod dependency; -pub mod info; pub mod price_sort; diff --git a/fuel-txpool/src/containers/dependency.rs b/fuel-txpool/src/containers/dependency.rs index 2c4337f1cf6..ab5f367e5ed 100644 --- a/fuel-txpool/src/containers/dependency.rs +++ b/fuel-txpool/src/containers/dependency.rs @@ -1,5 +1,7 @@ use crate::{types::*, Error}; use anyhow::anyhow; +use fuel_core_interfaces::info::ArcTx; +use fuel_core_interfaces::info::TxInfo; use fuel_core_interfaces::{ model::{Coin, CoinStatus}, txpool::TxPoolDb, @@ -7,8 +9,6 @@ use fuel_core_interfaces::{ use fuel_tx::{Input, Output, UtxoId}; use std::collections::{HashMap, HashSet}; -use super::info::TxInfo; - /// Check and hold dependency between inputs and outputs. Be mindful /// about depth of connection #[derive(Debug, Clone)] diff --git a/fuel-txpool/src/containers/info.rs b/fuel-txpool/src/containers/info.rs deleted file mode 100644 index 40ba8cba8e3..00000000000 --- a/fuel-txpool/src/containers/info.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::ops::Deref; - -use crate::types::ArcTx; -use chrono::{DateTime, Utc}; - -#[derive(Debug, Clone)] -pub struct TxInfo { - tx: ArcTx, - submited_time: DateTime, -} - -impl TxInfo { - pub fn new(tx: ArcTx) -> Self { - Self { - tx, - submited_time: Utc::now(), - } - } - - pub fn tx(&self) -> &ArcTx { - &self.tx - } - - pub fn submited_time(&self) -> DateTime { - self.submited_time - } -} - -impl Deref for TxInfo { - type Target = ArcTx; - fn deref(&self) -> &Self::Target { - &self.tx - } -} diff --git a/fuel-txpool/src/containers/price_sort.rs b/fuel-txpool/src/containers/price_sort.rs index 26079d10b53..7d4fa9277f2 100644 --- a/fuel-txpool/src/containers/price_sort.rs +++ b/fuel-txpool/src/containers/price_sort.rs @@ -1,4 +1,5 @@ use crate::types::*; +use fuel_core_interfaces::info::ArcTx; use std::{cmp, collections::BTreeMap}; #[derive(Debug, Clone)] diff --git a/fuel-txpool/src/service.rs b/fuel-txpool/src/service.rs index e995bc7fada..367bff79b0b 100644 --- a/fuel-txpool/src/service.rs +++ b/fuel-txpool/src/service.rs @@ -3,9 +3,9 @@ use std::sync::Arc; use crate::Error; use crate::{subscribers::MultiSubscriber, types::*, Config, TxPool as TxPoolImpl}; -use fuel_core_interfaces::txpool::{Subscriber, TxPool, TxPoolDb}; - use async_trait::async_trait; +use fuel_core_interfaces::info::{ArcTx, TxInfo}; +use fuel_core_interfaces::txpool::{Subscriber, TxPool, TxPoolDb}; use std::collections::HashMap; use tokio::sync::RwLock; @@ -56,22 +56,17 @@ impl TxPool for TxPoolService { } /// find all tx by its hash - async fn find(&self, hashes: &[TxId]) -> Vec> { + async fn find(&self, hashes: &[TxId]) -> Vec> { let mut res = Vec::with_capacity(hashes.len()); let pool = self.txpool.read().await; for hash in hashes { - res.push(pool.txs().get(hash).map(|info| info.tx().clone())); + res.push(pool.txs().get(hash).cloned()); } res } - async fn find_one(&self, hash: &TxId) -> Option { - self.txpool - .read() - .await - .txs() - .get(hash) - .map(|info| info.tx().clone()) + async fn find_one(&self, hash: &TxId) -> Option { + self.txpool.read().await.txs().get(hash).cloned() } /// find all dependent tx and return them with requsted dependencies in one list sorted by Price. diff --git a/fuel-txpool/src/subscribers.rs b/fuel-txpool/src/subscribers.rs index f7d40e7fe57..0e688ed8db8 100644 --- a/fuel-txpool/src/subscribers.rs +++ b/fuel-txpool/src/subscribers.rs @@ -1,7 +1,8 @@ use std::sync::Arc; -use crate::{types::ArcTx, Error}; +use crate::Error; use async_trait::async_trait; +use fuel_core_interfaces::info::ArcTx; use fuel_core_interfaces::txpool::Subscriber; use parking_lot::RwLock; diff --git a/fuel-txpool/src/txpool.rs b/fuel-txpool/src/txpool.rs index 54b5e435452..8fabed9af5d 100644 --- a/fuel-txpool/src/txpool.rs +++ b/fuel-txpool/src/txpool.rs @@ -1,7 +1,8 @@ use crate::containers::dependency::Dependency; -use crate::containers::info::TxInfo; use crate::Error; use crate::{containers::price_sort::PriceSort, types::*, Config}; +use fuel_core_interfaces::info::ArcTx; +use fuel_core_interfaces::info::TxInfo; use fuel_core_interfaces::txpool::TxPoolDb; use std::collections::HashMap; use std::sync::Arc; diff --git a/fuel-txpool/src/types.rs b/fuel-txpool/src/types.rs index 58b99d3d35b..838356648ef 100644 --- a/fuel-txpool/src/types.rs +++ b/fuel-txpool/src/types.rs @@ -1,7 +1,5 @@ pub use fuel_tx::ContractId; pub use fuel_tx::{Transaction, TxId}; use fuel_types::Word; -use std::sync::Arc; -pub type ArcTx = Arc; pub type GasPrice = Word; From 32e0059df8b8e8198265aebf28d76c98e05ed56e Mon Sep 17 00:00:00 2001 From: Johann Date: Fri, 22 Apr 2022 15:43:52 -0600 Subject: [PATCH 14/21] Weird fmt fix --- fuel-core-interfaces/src/lib.rs | 2 +- fuel-core/src/schema/tx/types.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/fuel-core-interfaces/src/lib.rs b/fuel-core-interfaces/src/lib.rs index 6dbb27a85fd..d701984945b 100644 --- a/fuel-core-interfaces/src/lib.rs +++ b/fuel-core-interfaces/src/lib.rs @@ -1,4 +1,4 @@ pub mod db; pub mod info; pub mod model; -pub mod txpool; +pub mod txpool; \ No newline at end of file diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index e9c50d808ab..c44c948f3de 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -222,7 +222,6 @@ impl Transaction { let transaction_in_pool = txpool.find_one(&self.0.id()).await; if transaction_in_pool.is_some() && db.get_tx_status(&self.0.id()).is_err() { - // TODO, fix this part where submitted time is lied about let time = transaction_in_pool.unwrap().submited_time(); Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time)))) } else { From f2d29bb56b3d97006d77e02d9b8d32e42693fc4b Mon Sep 17 00:00:00 2001 From: Johann Date: Fri, 22 Apr 2022 15:48:40 -0600 Subject: [PATCH 15/21] forgot git add --- fuel-core-interfaces/src/info.rs | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 fuel-core-interfaces/src/info.rs diff --git a/fuel-core-interfaces/src/info.rs b/fuel-core-interfaces/src/info.rs new file mode 100644 index 00000000000..62bd170bce7 --- /dev/null +++ b/fuel-core-interfaces/src/info.rs @@ -0,0 +1,37 @@ +use std::ops::Deref; + +use chrono::{DateTime, Utc}; +use fuel_tx::Transaction; +use std::sync::Arc; + +pub type ArcTx = Arc; + +#[derive(Debug, Clone)] +pub struct TxInfo { + tx: ArcTx, + submited_time: DateTime, +} + +impl TxInfo { + pub fn new(tx: ArcTx) -> Self { + Self { + tx, + submited_time: Utc::now(), + } + } + + pub fn tx(&self) -> &ArcTx { + &self.tx + } + + pub fn submited_time(&self) -> DateTime { + self.submited_time + } +} + +impl Deref for TxInfo { + type Target = ArcTx; + fn deref(&self) -> &Self::Target { + &self.tx + } +} From 33c54bca2744d7d55655abe81276924304989f2c Mon Sep 17 00:00:00 2001 From: Johann Date: Fri, 22 Apr 2022 15:51:51 -0600 Subject: [PATCH 16/21] mod fmt is hard --- fuel-core-interfaces/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuel-core-interfaces/src/lib.rs b/fuel-core-interfaces/src/lib.rs index d701984945b..6dbb27a85fd 100644 --- a/fuel-core-interfaces/src/lib.rs +++ b/fuel-core-interfaces/src/lib.rs @@ -1,4 +1,4 @@ pub mod db; pub mod info; pub mod model; -pub mod txpool; \ No newline at end of file +pub mod txpool; From 844f40e63da1e4b2ac33726d8b2d064aa7bb4316 Mon Sep 17 00:00:00 2001 From: Johann Date: Sat, 23 Apr 2022 18:33:40 -0600 Subject: [PATCH 17/21] rename+mv file --- fuel-core-interfaces/src/info.rs | 37 ------------------------ fuel-core-interfaces/src/lib.rs | 1 - fuel-core-interfaces/src/model.rs | 2 ++ fuel-core-interfaces/src/txpool.rs | 2 +- fuel-txpool/src/containers/dependency.rs | 4 +-- fuel-txpool/src/containers/price_sort.rs | 2 +- fuel-txpool/src/service.rs | 2 +- fuel-txpool/src/subscribers.rs | 2 +- fuel-txpool/src/txpool.rs | 3 +- 9 files changed, 8 insertions(+), 47 deletions(-) delete mode 100644 fuel-core-interfaces/src/info.rs diff --git a/fuel-core-interfaces/src/info.rs b/fuel-core-interfaces/src/info.rs deleted file mode 100644 index 62bd170bce7..00000000000 --- a/fuel-core-interfaces/src/info.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::ops::Deref; - -use chrono::{DateTime, Utc}; -use fuel_tx::Transaction; -use std::sync::Arc; - -pub type ArcTx = Arc; - -#[derive(Debug, Clone)] -pub struct TxInfo { - tx: ArcTx, - submited_time: DateTime, -} - -impl TxInfo { - pub fn new(tx: ArcTx) -> Self { - Self { - tx, - submited_time: Utc::now(), - } - } - - pub fn tx(&self) -> &ArcTx { - &self.tx - } - - pub fn submited_time(&self) -> DateTime { - self.submited_time - } -} - -impl Deref for TxInfo { - type Target = ArcTx; - fn deref(&self) -> &Self::Target { - &self.tx - } -} diff --git a/fuel-core-interfaces/src/lib.rs b/fuel-core-interfaces/src/lib.rs index 6dbb27a85fd..1dccaf2392a 100644 --- a/fuel-core-interfaces/src/lib.rs +++ b/fuel-core-interfaces/src/lib.rs @@ -1,4 +1,3 @@ pub mod db; -pub mod info; pub mod model; pub mod txpool; diff --git a/fuel-core-interfaces/src/model.rs b/fuel-core-interfaces/src/model.rs index e76e3ebe19f..9fcc77aa7a3 100644 --- a/fuel-core-interfaces/src/model.rs +++ b/fuel-core-interfaces/src/model.rs @@ -1,7 +1,9 @@ mod block; mod block_height; mod coin; +mod txpool; pub use block::{FuelBlock, FuelBlockDb, FuelBlockHeader}; pub use block_height::BlockHeight; pub use coin::{Coin, CoinStatus}; +pub use txpool::{ArcTx, TxInfo}; diff --git a/fuel-core-interfaces/src/txpool.rs b/fuel-core-interfaces/src/txpool.rs index 6f5c07ac28f..a1a145c8d68 100644 --- a/fuel-core-interfaces/src/txpool.rs +++ b/fuel-core-interfaces/src/txpool.rs @@ -7,8 +7,8 @@ use thiserror::Error; use crate::{ db::{Error as DbStateError, KvStoreError}, - info::TxInfo, model::Coin, + model::TxInfo, }; use fuel_storage::Storage; use fuel_vm::prelude::Contract; diff --git a/fuel-txpool/src/containers/dependency.rs b/fuel-txpool/src/containers/dependency.rs index ab5f367e5ed..5245e0ab869 100644 --- a/fuel-txpool/src/containers/dependency.rs +++ b/fuel-txpool/src/containers/dependency.rs @@ -1,9 +1,7 @@ use crate::{types::*, Error}; use anyhow::anyhow; -use fuel_core_interfaces::info::ArcTx; -use fuel_core_interfaces::info::TxInfo; use fuel_core_interfaces::{ - model::{Coin, CoinStatus}, + model::{ArcTx, Coin, CoinStatus, TxInfo}, txpool::TxPoolDb, }; use fuel_tx::{Input, Output, UtxoId}; diff --git a/fuel-txpool/src/containers/price_sort.rs b/fuel-txpool/src/containers/price_sort.rs index 7d4fa9277f2..5646768e8fa 100644 --- a/fuel-txpool/src/containers/price_sort.rs +++ b/fuel-txpool/src/containers/price_sort.rs @@ -1,5 +1,5 @@ use crate::types::*; -use fuel_core_interfaces::info::ArcTx; +use fuel_core_interfaces::model::ArcTx; use std::{cmp, collections::BTreeMap}; #[derive(Debug, Clone)] diff --git a/fuel-txpool/src/service.rs b/fuel-txpool/src/service.rs index 367bff79b0b..2f5a3364e4b 100644 --- a/fuel-txpool/src/service.rs +++ b/fuel-txpool/src/service.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use crate::Error; use crate::{subscribers::MultiSubscriber, types::*, Config, TxPool as TxPoolImpl}; use async_trait::async_trait; -use fuel_core_interfaces::info::{ArcTx, TxInfo}; +use fuel_core_interfaces::model::{ArcTx, TxInfo}; use fuel_core_interfaces::txpool::{Subscriber, TxPool, TxPoolDb}; use std::collections::HashMap; use tokio::sync::RwLock; diff --git a/fuel-txpool/src/subscribers.rs b/fuel-txpool/src/subscribers.rs index 0e688ed8db8..f9c87ec1fa1 100644 --- a/fuel-txpool/src/subscribers.rs +++ b/fuel-txpool/src/subscribers.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use crate::Error; use async_trait::async_trait; -use fuel_core_interfaces::info::ArcTx; +use fuel_core_interfaces::model::ArcTx; use fuel_core_interfaces::txpool::Subscriber; use parking_lot::RwLock; diff --git a/fuel-txpool/src/txpool.rs b/fuel-txpool/src/txpool.rs index 8fabed9af5d..0adad368fca 100644 --- a/fuel-txpool/src/txpool.rs +++ b/fuel-txpool/src/txpool.rs @@ -1,8 +1,7 @@ use crate::containers::dependency::Dependency; use crate::Error; use crate::{containers::price_sort::PriceSort, types::*, Config}; -use fuel_core_interfaces::info::ArcTx; -use fuel_core_interfaces::info::TxInfo; +use fuel_core_interfaces::model::{ArcTx, TxInfo}; use fuel_core_interfaces::txpool::TxPoolDb; use std::collections::HashMap; use std::sync::Arc; From a3b972e8686cfa0e9323ec5beccbb4fcd6627d91 Mon Sep 17 00:00:00 2001 From: Johann Date: Sat, 23 Apr 2022 18:33:48 -0600 Subject: [PATCH 18/21] rename+mv file --- fuel-core-interfaces/src/model/txpool.rs | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 fuel-core-interfaces/src/model/txpool.rs diff --git a/fuel-core-interfaces/src/model/txpool.rs b/fuel-core-interfaces/src/model/txpool.rs new file mode 100644 index 00000000000..62bd170bce7 --- /dev/null +++ b/fuel-core-interfaces/src/model/txpool.rs @@ -0,0 +1,37 @@ +use std::ops::Deref; + +use chrono::{DateTime, Utc}; +use fuel_tx::Transaction; +use std::sync::Arc; + +pub type ArcTx = Arc; + +#[derive(Debug, Clone)] +pub struct TxInfo { + tx: ArcTx, + submited_time: DateTime, +} + +impl TxInfo { + pub fn new(tx: ArcTx) -> Self { + Self { + tx, + submited_time: Utc::now(), + } + } + + pub fn tx(&self) -> &ArcTx { + &self.tx + } + + pub fn submited_time(&self) -> DateTime { + self.submited_time + } +} + +impl Deref for TxInfo { + type Target = ArcTx; + fn deref(&self) -> &Self::Target { + &self.tx + } +} From 6c063e434fb962f5c297f0d1a9e6bfaa1ffce6dc Mon Sep 17 00:00:00 2001 From: Johann Date: Tue, 26 Apr 2022 18:10:52 -0600 Subject: [PATCH 19/21] Fixed import --- fuel-core/src/schema/tx/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index c44c948f3de..b81c1cfdb48 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -4,7 +4,6 @@ use super::receipt::Receipt; use crate::model::FuelBlockDb; use crate::schema::contract::Contract; use crate::schema::scalars::{AssetId, Bytes32, HexString, Salt, TransactionId, U64}; -use crate::schema::tx::Arc; use crate::tx_pool::TransactionStatus as TxStatus; use crate::tx_pool::TxPool; use crate::{database::Database, schema::block::Block}; @@ -14,6 +13,7 @@ use fuel_core_interfaces::db::KvStoreError; use fuel_storage::Storage; use fuel_types::bytes::SerializableVec; use fuel_vm::prelude::ProgramState as VmProgramState; +use std::sync::Arc; pub struct ProgramState { return_type: ReturnType, From 7ab9b57e185c2212402d68f4d9766aa11b0d974a Mon Sep 17 00:00:00 2001 From: ControlCplusControlV <44706811+ControlCplusControlV@users.noreply.github.com> Date: Tue, 26 Apr 2022 18:13:15 -0600 Subject: [PATCH 20/21] Remove redundant check Co-authored-by: Brandon Kite --- fuel-core/src/schema/tx/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuel-core/src/schema/tx/types.rs b/fuel-core/src/schema/tx/types.rs index b81c1cfdb48..94bd368a001 100644 --- a/fuel-core/src/schema/tx/types.rs +++ b/fuel-core/src/schema/tx/types.rs @@ -221,7 +221,7 @@ impl Transaction { let transaction_in_pool = txpool.find_one(&self.0.id()).await; - if transaction_in_pool.is_some() && db.get_tx_status(&self.0.id()).is_err() { + if transaction_in_pool.is_some() { let time = transaction_in_pool.unwrap().submited_time(); Ok(Some(TransactionStatus::Submitted(SubmittedStatus(time)))) } else { From 74104afb18a03b56afedad461a190032d2488ec2 Mon Sep 17 00:00:00 2001 From: Johann Date: Wed, 27 Apr 2022 13:20:19 -0600 Subject: [PATCH 21/21] Fixed Remove bug --- fuel-txpool/src/txpool.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fuel-txpool/src/txpool.rs b/fuel-txpool/src/txpool.rs index 0adad368fca..9e92f7880ed 100644 --- a/fuel-txpool/src/txpool.rs +++ b/fuel-txpool/src/txpool.rs @@ -98,8 +98,8 @@ impl TxPool { /// remove transaction from pool needed on user demand. Low priority pub fn remove_by_tx_id(&mut self, tx_id: &TxId) -> Vec { - if let Some(tx) = self.by_hash.get(tx_id) { - self.by_gas_price.remove(tx); + if let Some(tx) = self.by_hash.remove(tx_id) { + self.by_gas_price.remove(tx.tx()); return self .by_dependency .recursively_remove_all_dependencies(&self.by_hash, tx.tx().clone());