Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Transaction Status API #263

Merged
merged 26 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a7340b6
Changes re-done to be more in line with things
ControlCplusControlV Apr 13, 2022
936dbfb
Removed dependent_txs
ControlCplusControlV Apr 14, 2022
3ef1c1c
Cleaned up code
ControlCplusControlV Apr 14, 2022
dca62b0
Removed dependent_txs
ControlCplusControlV Apr 14, 2022
601425a
Fmt + Clippy
ControlCplusControlV Apr 14, 2022
5f84599
Fixed minor bug, test almost done
ControlCplusControlV Apr 15, 2022
c07af7f
cleanup and remove test
ControlCplusControlV Apr 18, 2022
b8ccda6
last fix
ControlCplusControlV Apr 18, 2022
5173669
Merge branch 'master' into controlc/152_pt2
ControlCplusControlV Apr 18, 2022
b3a430c
Test todo!()
ControlCplusControlV Apr 19, 2022
6989750
Test annotation
ControlCplusControlV Apr 19, 2022
a1ba2dd
Merge branch 'master' into controlc/152_pt2
ControlCplusControlV Apr 19, 2022
8e68f9f
Merge remote-tracking branch 'origin/master' into controlc/152_pt2
ControlCplusControlV Apr 20, 2022
750812b
minor fix
ControlCplusControlV Apr 21, 2022
de9b918
fmt
ControlCplusControlV Apr 21, 2022
20d05cd
Use find_one, use correct time, TxInfo refactor, ArcTx Move, also sta…
ControlCplusControlV Apr 22, 2022
32e0059
Weird fmt fix
ControlCplusControlV Apr 22, 2022
f2d29bb
forgot git add
ControlCplusControlV Apr 22, 2022
33c54bc
mod fmt is hard
ControlCplusControlV Apr 22, 2022
844f40e
rename+mv file
ControlCplusControlV Apr 24, 2022
a3b972e
rename+mv file
ControlCplusControlV Apr 24, 2022
6c063e4
Fixed import
ControlCplusControlV Apr 27, 2022
7ab9b57
Remove redundant check
ControlCplusControlV Apr 27, 2022
c984ae7
Merge branch 'master' into controlc/152_pt2
ControlCplusControlV Apr 27, 2022
74104af
Fixed Remove bug
ControlCplusControlV Apr 27, 2022
19201cf
Merge branch 'master' into controlc/152_pt2
ControlCplusControlV Apr 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fuel-core-interfaces/src/model.rs
Original file line number Diff line number Diff line change
@@ -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};
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::ops::Deref;

use crate::types::ArcTx;
use chrono::{DateTime, Utc};
use fuel_tx::Transaction;
use std::sync::Arc;

pub type ArcTx = Arc<Transaction>;

#[derive(Debug, Clone)]
pub struct TxInfo {
Expand Down
5 changes: 3 additions & 2 deletions fuel-core-interfaces/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use thiserror::Error;
use crate::{
db::{Error as DbStateError, KvStoreError},
model::Coin,
model::TxInfo,
};
use fuel_storage::Storage;
use fuel_vm::prelude::Contract;
Expand Down Expand Up @@ -50,10 +51,10 @@ pub trait TxPool: Send + Sync {
-> Vec<anyhow::Result<Vec<Arc<Transaction>>>>;

/// find all tx by their hash
async fn find(&self, hashes: &[TxId]) -> Vec<Option<Arc<Transaction>>>;
async fn find(&self, hashes: &[TxId]) -> Vec<Option<TxInfo>>;

/// find one tx by its hash
async fn find_one(&self, hash: &TxId) -> Option<Arc<Transaction>>;
async fn find_one(&self, hash: &TxId) -> Option<TxInfo>;

/// find all dependent tx and return them with requsted dependencies in one list sorted by Price.
async fn find_dependent(&self, hashes: &[TxId]) -> Vec<Arc<Transaction>>;
Expand Down
2 changes: 1 addition & 1 deletion fuel-core/src/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<fuel_types::Bytes32, FuelTx>::get(db, &key)?
.map(|tx| Transaction(tx.into_owned())))
Expand Down
16 changes: 14 additions & 2 deletions fuel-core/src/schema/tx/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ 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;
ControlCplusControlV marked this conversation as resolved.
Show resolved Hide resolved
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};
Expand Down Expand Up @@ -214,8 +216,18 @@ impl Transaction {

async fn status(&self, ctx: &Context<'_>) -> async_graphql::Result<Option<TransactionStatus>> {
let db = ctx.data_unchecked::<Database>();
let status = db.get_tx_status(&self.0.id())?;
Ok(status.map(Into::into))

let txpool = ctx.data::<Arc<TxPool>>().unwrap().pool();

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() {
ControlCplusControlV marked this conversation as resolved.
Show resolved Hide resolved
let time = transaction_in_pool.unwrap().submited_time();
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<Option<Vec<Receipt>>> {
Expand Down
12 changes: 12 additions & 0 deletions fuel-tests/tests/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,25 @@ 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 { .. }
));
}
}

#[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();
Expand Down
1 change: 0 additions & 1 deletion fuel-txpool/src/containers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod dependency;
pub mod info;
pub mod price_sort;
4 changes: 1 addition & 3 deletions fuel-txpool/src/containers/dependency.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use crate::{types::*, Error};
use anyhow::anyhow;
use fuel_core_interfaces::{
model::{Coin, CoinStatus},
model::{ArcTx, Coin, CoinStatus, TxInfo},
txpool::TxPoolDb,
};
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)]
Expand Down
1 change: 1 addition & 0 deletions fuel-txpool/src/containers/price_sort.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::types::*;
use fuel_core_interfaces::model::ArcTx;
use std::{cmp, collections::BTreeMap};

#[derive(Debug, Clone)]
Expand Down
17 changes: 6 additions & 11 deletions fuel-txpool/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::model::{ArcTx, TxInfo};
use fuel_core_interfaces::txpool::{Subscriber, TxPool, TxPoolDb};
use std::collections::HashMap;
use tokio::sync::RwLock;

Expand Down Expand Up @@ -56,22 +56,17 @@ impl TxPool for TxPoolService {
}

/// find all tx by its hash
async fn find(&self, hashes: &[TxId]) -> Vec<Option<ArcTx>> {
async fn find(&self, hashes: &[TxId]) -> Vec<Option<TxInfo>> {
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<ArcTx> {
self.txpool
.read()
.await
.txs()
.get(hash)
.map(|info| info.tx().clone())
async fn find_one(&self, hash: &TxId) -> Option<TxInfo> {
self.txpool.read().await.txs().get(hash).cloned()
}

/// find all dependent tx and return them with requsted dependencies in one list sorted by Price.
Expand Down
3 changes: 2 additions & 1 deletion fuel-txpool/src/subscribers.rs
Original file line number Diff line number Diff line change
@@ -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::model::ArcTx;
use fuel_core_interfaces::txpool::Subscriber;
use parking_lot::RwLock;

Expand Down
2 changes: 1 addition & 1 deletion fuel-txpool/src/txpool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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::model::{ArcTx, TxInfo};
use fuel_core_interfaces::txpool::TxPoolDb;
use std::collections::HashMap;
use std::sync::Arc;
Expand Down
2 changes: 0 additions & 2 deletions fuel-txpool/src/types.rs
Original file line number Diff line number Diff line change
@@ -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<Transaction>;
pub type GasPrice = Word;