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
Changes from 5 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
26 changes: 24 additions & 2 deletions fuel-core/src/schema/tx/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +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_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,
Expand Down Expand Up @@ -214,8 +219,25 @@ 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 tx_pooldb = Box::new(db.clone()) as Box<dyn TxPoolDb>;

let txpool = TxPoolService::new(tx_pooldb, Arc::new(Config::default()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this creating an brand new instance of a txpool on each status request? We should be fetching the shared txpool out of the ctx like we do with the db. The db backs the txpool, but a lot of the data in the txpool is managed in memory, so creating an ephemeral txpool like this will not share any data with the txpool used in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if this was the best way to access the txpool, I went with this approach as I wanted to avoid side effects (hence the clone), but I see why this could be extremely expensive and how the shared data could end up being helpful, so I will move this to fetch from the context

Copy link
Member

@Voxelot Voxelot Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clone is of the db, which is just cloning a pointer and virtually has no cost. The issue is that creating a new txpool instance wouldn't know about the transaction submitted by the user, as it's a different instance with it's own hashmaps in memory. So the transaction the user is looking for would never exist in the temp pool you're making here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will keep that in mind when deciding between whether to clone or pull in an object from the context.

What is the best way to fetch the TxPool from a context - let txpool = ctx.data::<Arc<dyn TxPool>>().unwrap(); however this results in many tests breaking with Custom { kind: Other, error: Curl("Send failed since rewinding of the data stream failed"): Send failed since rewinding of the data stream failed }, what would be the correct way to fetch the TxPool or TxPoolService from the current context?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's injected into the context here: https://github.com/FuelLabs/fuel-core/blob/master/fuel-core/src/service/graph_api.rs#L37

So based on the type use there it would be the concrete Arc<TxPool> instead of dyn TxPool.


let transaction_in_pool = txpool.find(&[self.0.id()]).await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just extend TxPool to support find_one function it should be easy to add as you just need to see how find is made, this should simplify a bit logic here.
Other than that this seems okay.


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))))
} 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