-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
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 936dbfb
Removed dependent_txs
ControlCplusControlV 3ef1c1c
Cleaned up code
ControlCplusControlV dca62b0
Removed dependent_txs
ControlCplusControlV 601425a
Fmt + Clippy
ControlCplusControlV 5f84599
Fixed minor bug, test almost done
ControlCplusControlV c07af7f
cleanup and remove test
ControlCplusControlV b8ccda6
last fix
ControlCplusControlV 5173669
Merge branch 'master' into controlc/152_pt2
ControlCplusControlV b3a430c
Test todo!()
ControlCplusControlV 6989750
Test annotation
ControlCplusControlV a1ba2dd
Merge branch 'master' into controlc/152_pt2
ControlCplusControlV 8e68f9f
Merge remote-tracking branch 'origin/master' into controlc/152_pt2
ControlCplusControlV 750812b
minor fix
ControlCplusControlV de9b918
fmt
ControlCplusControlV 20d05cd
Use find_one, use correct time, TxInfo refactor, ArcTx Move, also sta…
ControlCplusControlV 32e0059
Weird fmt fix
ControlCplusControlV f2d29bb
forgot git add
ControlCplusControlV 33c54bc
mod fmt is hard
ControlCplusControlV 844f40e
rename+mv file
ControlCplusControlV a3b972e
rename+mv file
ControlCplusControlV 6c063e4
Fixed import
ControlCplusControlV 7ab9b57
Remove redundant check
ControlCplusControlV c984ae7
Merge branch 'master' into controlc/152_pt2
ControlCplusControlV 74104af
Fixed Remove bug
ControlCplusControlV 19201cf
Merge branch 'master' into controlc/152_pt2
ControlCplusControlV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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())); | ||
|
||
let transaction_in_pool = txpool.find(&[self.0.id()]).await; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just extend TxPool to support |
||
|
||
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>>> { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 withCustom { 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?There was a problem hiding this comment.
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.