-
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
Conversation
fuel-core/src/schema/tx/types.rs
Outdated
|
||
let tx_pooldb = Box::new(db.clone()) as Box<dyn TxPoolDb>; | ||
|
||
let txpool = TxPoolService::new(tx_pooldb, Arc::new(Config::default())); |
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 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?
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.
tests? |
Oh I thought the transaction status api unit tests would cover this, however I will in one to specifically test this new behavior and make sure it is behaving properly |
I've been running into some conversion issues. I noticed the So my question boils down to how would this behavior be tested? As the only way to get a transaction from |
So the I have been able to test it though by removing the block execution and deletion of the tx from txpool by commenting out parts of |
fuel-core/src/schema/tx/types.rs
Outdated
|
||
let txpool = ctx.data::<Arc<TxPool>>().unwrap().pool(); | ||
|
||
let transaction_in_pool = txpool.find(&[self.0.id()]).await; |
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.
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.
You could include the test that passed when you modified the txpool and add the |
I've added an empty test with a |
So to explain this (hopefully) final commit
I have re-done manual testing as well to ensure |
fuel-core-interfaces/src/info.rs
Outdated
use fuel_tx::Transaction; | ||
use std::sync::Arc; | ||
|
||
pub type ArcTx = Arc<Transaction>; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct TxInfo { |
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.
nit: I would just move this file to fuel-core-interfaces/src/model/info.rs
and maybe even rename it to txpool.rs
it feels like modules specific to txpool, that is why a little bit a specific naming of file.
other than that lgtm :)
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, I wasn't sure what name so I chose info
but I agreetxpool
is better to make it more clear in what it does and easier to find. It is now moved it to fuel-core-interfaces/src/model/txpool.rs
Co-authored-by: Brandon Kite <brandonkite92@gmail.com>
if transaction_in_pool.is_some() { | ||
let time = transaction_in_pool.unwrap().submited_time(); |
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.
[nit] use if-let syntax to avoid .is_some followed by unwrap.
Closes #154
This updates the transaction status api to use the mempool as a shortcut to determine transaction status, as if a transaction is in the mempool it's status is submitted. There is a small TODO where the time used for the submitted status is the current time of when the status if fetched rather than the actual time it was submitted.
The
dependent_transactions
api was shelved as I understand it isn't that important, and I thought that if it is implemented it may make more sense to do with once utxo_validation is turned on.