-
Notifications
You must be signed in to change notification settings - Fork 311
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
refactor(chain)!: Change tx_last_seen to Option<u64>
#1416
refactor(chain)!: Change tx_last_seen to Option<u64>
#1416
Conversation
23ffb41
to
fc090cb
Compare
fc090cb
to
59315f7
Compare
Option<u64>
Option<u64>
59315f7
to
15d9579
Compare
15d9579
to
007beaf
Compare
Isn't |
03d0515
to
6fbd167
Compare
if let Some(seen_at) = tx_tmp.last_seen { | ||
let _ = graph.insert_seen_at(tx.txid(), seen_at); | ||
} | ||
let _ = graph.insert_seen_at(tx.txid(), tx_tmp.last_seen.unwrap_or(0)); |
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.
Why are we force-inserting a last_seen
when the template last_seen
is None
?
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.
This was a fix for test_tx_graph_conflicts
. Because we're interested in testing tx conflicts, we have to control for the fact that txs without a last_seen would now be filtered out, so we just assume all txs are canonical.
edit: An alternative is to patch up some of the scenarios in test_tx_graph_conflicts
to ensure every tx template is given some value of last_seen. That might make things clearer.
summarizes the main usecase of these changes. With this context in mind, this PR description needs to highlight how we should handle non-broadcasted transactions in How can the caller list these non-broadcasted transactions? What if the caller would like to include UTXOs of non-broadcasted transactions when listing their UTXO set? What if the caller would NOT like to do so? What if the caller would like to replace non-broadcasted transactions? Currently, we do transaction-precedence based on last_seen. Wouldn't we need something like this for non-broadcasted transactions too? It seems that many things have not be thought through clearly. Let's have some more concrete discussion about how everything should look after these changes. |
6fbd167
to
7b00dca
Compare
c37abfa
to
c547aa4
Compare
2aaf5cc
to
d94ec7c
Compare
d94ec7c
to
750daaa
Compare
While it's possible to store a transaction in As an aside, if you're trying to build a chain of dependent transactions without broadcasting them, it should be possible to bypass coin selection by adding any owned txouts as a foreign utxo to a new |
75cf153
to
5bf9504
Compare
For example in |
since we'd be lacking context that should normally occur during sync with a chain source. The logic for inserting a graph anchor from a `ConfirmationTime` is moved to the wallet common test module in order to simulate receiving new txs and confirming them.
5bf9504
to
53a1e86
Compare
I feel like we should include a method for returning "unseen and unanchored" transactions. Not sure what to name it, maybe |
92e9720
to
42fab2b
Compare
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.
ACK 42fab2b
This looks good and all comments addressed.
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.
Thanks. I've made a few suggestions about how to clean up the internals and tests. API looks good.
crates/chain/src/tx_graph.rs
Outdated
@@ -110,7 +110,7 @@ use core::{ | |||
#[derive(Clone, Debug, PartialEq)] | |||
pub struct TxGraph<A = ()> { | |||
// all transactions that the graph is aware of in format: `(tx_node, tx_anchors, tx_last_seen)` | |||
txs: HashMap<Txid, (TxNodeInternal, BTreeSet<A>, u64)>, | |||
txs: HashMap<Txid, (TxNodeInternal, BTreeSet<A>, Option<u64>)>, |
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.
This should not be in this tuple I think. last_seen
should just been its own HashMap<Txid, u64>
if the value would be None
here it would just not have an entry in the map. This is more idomatic and easier to reason about imo.
42fab2b
to
56b3573
Compare
I'm interested in implementing the suggestion to make last-seen a new field in |
Also fixup `test_list_owned_txouts` to check that the right outputs, utxos, and balance are returned at different local chain heights. This fixes an issue where unbroadcast and otherwise non-canonical transactions were returned from methods `list_chain_txs` and `Wallet::transactions` because every tx inserted had a last_seen of 0 making it appear unconfirmed. Note this commit changes the way `Balance` is represented due to new logic in `try_get_chain_position` that no longer considers txs with non-canonical anchors. Before this change, a tx anchored to a block that is reorged out had a permanent effect on the pending balance, and now only txs with a last_seen time or an anchor confirmed in the best chain will return a `ChainPosition`.
56b3573
to
af75817
Compare
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.
Option<u64>
Option<u64>
The PR changes the type of last_seen to
Option<u64>
fortxs
member ofTxGraph
.This fixes an issue where unbroadcast and otherwise non-canonical transactions were returned from methods
list_chain_txs
andWallet::transactions
because every new tx inserted had a last_seen of 0 making it appear unconfirmed.fixes #1446
fixes #1396
Notes to the reviewers
Changelog notice
Changed
last_seen_unconfirmed
ofTxNode
is changed toOption<u64>
TxGraph
methodlist_chain_txs
tolist_canonical_txs
Wallet::insert_tx
to take a singletx: Transaction
as parameterAdded
txs_with_no_anchor_or_last_seen
forTxGraph
unbroadcast_transactions
forWallet
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingBugfixes: