-
Notifications
You must be signed in to change notification settings - Fork 312
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 last seen unconfirmed #1385
Fix last seen unconfirmed #1385
Conversation
This looks fine to me, but my understanding is that a time value always should be provided, even if it's made up as long the the values are increasing. If we make this optional we should at least explain what the downside is of using None, which I believe was unneeded DB updates. |
Ok, I think I agree it should be required. |
I agree on required. It should also make for a better UX as the end user "refreshes" their wallet. |
ffce704
to
3162957
Compare
Sorry about the conflicts! We have merged #1171 |
3162957
to
84dc09e
Compare
electrum: @evanlinjin Can we assume in electrum_ext if a relevant txid has no associated anchors, it must be unconfirmed and therefore be an appropriate time to |
@ValuedMammal that sounds right to me! Let's add a couple of tests and I'll be happy to ACK and merge. My proposed tests for both |
Update on test coverage: For electrum, repeated syncing doesn't update the last seen timestamp, because if a tx is already present in graph, TxGraph won't report it as missing. For esplora I did successfully check that timestamps increase for repeat syncs as long as a tx is unconfirmed. When the tx confirms, the timestamp is unchanged. Note: I don't love the fact that every test needs to mine 100 regtest blocks, as that slows down CI. We should perhaps think about consolidating various assertions into more monolithic tests. |
sync
, full_scan
to take a timestamp parameter5af0f99
to
5928143
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.
The changes here look exactly how I imagined they should. Thanks! But now that I see it, isn't it simpler just to have method like update_last_seen_unconfirmed
on TxGraph
which sets the last seen of all unanchored transactions? We can just call this on the update TxGraph
and set it to now
before applying it. This means we wouldn't need to pass it in, we can just mutate the TxGraph
afterwards.
At least presently it doesn't look like we lose anything by doing this since the backends are both just setting whatever you tell them when you pass the time in. I was thinking that maybe esplora or electrum would tell you the last time it was seen in the API but I guess that's not the case. Mempool.space does have this api: https://mempool.space/docs/api/rest#get-transaction-times but that's "first seen" rather than last seen.
I'll have another look at this. |
5928143
to
c94f27b
Compare
|
crates/electrum/src/electrum_ext.rs
Outdated
if let Some(seen_at) = seen_at { | ||
let _ = graph.insert_seen_at(txid, seen_at); | ||
if anchors.is_empty() { | ||
if let Some(seen_at) = seen_at { |
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 know it breaks the current API but shouldn't seen_at
be required and non-optional here too?
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 don't know whether it makes more sense to make this seen_at
parameter required, or to remove the param and use the new update_last_seen_unconfirmed
method on the update TxGraph
.
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 think it's fine as it is. Will likely be radically changed soon.
[EDIT] but when you did:
l let mut graph_update =
relevant_txids.into_confirmation_time_tx_graph(&client, None, missing)?;
let now = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs();
let _ = graph_update.update_last_seen_unconfirmed(now);
You are choosing to pass in None
but then manually update it. If this is what you want to do in the examples then just remove the option from these functions. It's confusing to use both in the examples.
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.
Fixed. I made seen_at
a required parameter for into_tx_graph
.
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.
LGTM just need to make the electrum examples consistent (decide whether to pass it into the into_confirmation_time_tx_graph
or just remove the Option and do it manually outside).
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 looks great! However, there may be a situation where the chain-source returns anchors that do not point to a block in the best chain. Those unconfirmed transactions will therefore have no "timestamp". Would it be better if TxGraph::update_last_seen_unconfirmed
takes in a checkpoint tip so unconfirmed transactions are transactions that do not have an anchor that points to a checkpoint?
c94f27b
to
b21ea0f
Compare
I had not thought of that |
|
@LLFourn the problem is we can't get blocks and transactions atomically. We either get blocks before getting transactions, or get transactions before getting blocks. There might be a situation when a reorg happens between fetching txs and blocks. The tx might be sent back to mempool because it's not included in replacement block. |
...or it might not be if the re-org confirms a double spend. It might be in the mempool it might not be so we don't set |
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 b21ea0f
From looking at it, the changes in electrum_ext.rs
seem to do exactly the same thing that would be achieved if you just called update_last_seen_unconfirmed
so it would make sense to just do that instead of passing in seen_at
. I'm pretty sure @evanlinjin will change this soon so I don't think it matters that much.
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 449dd9a
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.
LGTM! Thanks for the quality work. Let's drop the last_seen
parameter from .into_tx_graph
and I'll ACK/merge.
That accepts a `u64` as param representing the latest timestamp and internally calls `insert_seen_at` for all transactions in graph that aren't yet anchored in a confirmed block.
and `into_confirmation_time_tx_graph`, since now it makes sense to use `TxGraph::update_last_seen_unconfirmed`. Also, use `update_last_seen_unconfirmed` in examples for electrum/esplora. We show how to update the last seen time for transactions by calling `update_last_seen_unconfirmed` on the graph update returned from a blockchain source, passing in the current time, before applying it to another `TxGraph`.
449dd9a
to
a2a64ff
Compare
Done. Thank you to the reviewers @evanlinjin @LLFourn @notmandatory @rustaceanrob |
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 a2a64ff
A method
update_last_seen_unconfirmed
is added forTxGraph
that allows inserting aseen_at
time for all unanchored transactions.fixes #1336
Changelog notice
Changed:
into_tx_graph
andinto_confirmation_time_tx_graph
forRelevantTxids
are changed to no longer accept aseen_at
parameter.Added:
update_last_seen_unconfirmed
forTxGraph
.Checklists
All Submissions:
cargo fmt
andcargo clippy
before committing