Repository navigation
Description
Split out from review discussion on #2139 (thanks @noahjoeris for spotting it).
The question
When a canonical transaction's reason is CanonicalReason::ObservedIn { observed_in: ObservedIn::Block(_), .. }, CanonicalViewTask reports:
ChainPosition::Unconfirmed {
first_seen: tx_node.first_seen,
last_seen: None,
}Is None the right answer?
The argument for None: last_seen means "last seen in the mempool". ObservedIn::Block is assigned in the LeftOverTxs stage to a transaction whose anchors are all not in the best chain — it was seen in a block that got reorged out, never in the mempool. A transaction that re-entered the mempool would carry a last_seen and be canonicalized in the SeenTxs stage as ObservedIn::Mempool instead, so it would never reach this arm.
The argument against: the transaction node may have a last_seen in the graph, and we are discarding it. A caller asking "when did we last hear about this transaction?" gets None even though we do know something.
Why it needs deciding rather than just documenting
The two are not always the same value. TxGraph::txids_by_descending_last_seen filters out evicted transactions:
.filter(|(last_seen, txid)| match self.last_evicted.get(txid) {
Some(last_evicted) => last_evicted < last_seen,
None => true,
})So an evicted transaction with a last_seen is never visited by the SeenTxs stage. It can still be marked canonical transitively, as an ancestor swept by mark_canonical when a descendant is marked ObservedIn::Block in the LeftOverTxs stage. That ancestor then lands in this arm while genuinely having tx_node.last_seen == Some(_).
In other words, "a transaction reaching ObservedIn::Block has no last_seen" is nearly an invariant of the stage ordering, but the eviction filter punches a hole in it. Whatever we decide should be stated in ChainPosition's docs rather than left resting on that ordering.
Context
#2139 briefly changed this arm from None to tx_node.last_seen as part of the ChainTask refactor. That has been reverted there so the refactor stays behaviour-preserving, and the semantic question moved here.
Suggested outcome
Either:
- Keep
None, and document onChainPosition::Unconfirmedthatlast_seenis specifically a mempool sighting and is absent for a transaction only ever seen in a stale block; or - Report
tx_node.last_seen, and document that it is the last time the transaction was heard of by any means.
Option 1 matches the current behaviour on master and the field's apparent intent. Either way a test covering the evicted-ancestor path would be worth adding, since nothing exercises it today.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
evanlinjin commentedon Sep 11, 2026
Closing — this is not an open design question, it is a bug with a clear answer, and it is fixed directly in #2139.
I filed this recommending
Noneas matching "the field's apparent intent". That was wrong. The field's doc settles it the other way:Two conditions, joined by "and". The evicted-ancestor case fails the first: that transaction was seen in the mempool — which is exactly why it has a
last_seento argue about.The asymmetry is the giveaway.
first_seenis documented on the same terms and is passed through unconditionally, so forcinglast_seen: Noneproducedfirst_seen: Some(t), last_seen: None— "first seen at t, never seen".Fixed in #2139 by reporting
tx_node.last_seen, with a regression test covering the evicted-ancestor path, which nothing exercised before.One correction to this issue's text for anyone reading it later: I claimed the match collapses to
last_seen: tx_node.last_seenin both arms. It does not. For a transitively-marked ancestor theMempoolarm carries the descendant's timestamp, which is a valid lower bound — a child cannot sit in the mempool without its parent.