Skip to content

Should ChainPosition::Unconfirmed::last_seen be None for a tx only seen in a stale block? #2300

Closed as not planned

Description

@evanlinjin

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:

  1. Keep None, and document on ChainPosition::Unconfirmed that last_seen is specifically a mempool sighting and is absent for a transaction only ever seen in a stale block; or
  2. 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.

Activity

  1. self-assigned this
    on Sep 11, 2026
  2. added
    discussion
    on Sep 11, 2026
  3. evanlinjin commented on Sep 11, 2026

    @evanlinjin
    ContributorAuthor

    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 None as matching "the field's apparent intent". That was wrong. The field's doc settles it the other way:

    When the chain data is last seen in the mempool. This value will be None if the chain data was never seen in the mempool and only seen in a conflicting chain.

    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_seen to argue about.

    The asymmetry is the giveaway. first_seen is documented on the same terms and is passed through unconditionally, so forcing last_seen: None produced first_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_seen in both arms. It does not. For a transitively-marked ancestor the Mempool arm carries the descendant's timestamp, which is a valid lower bound — a child cannot sit in the mempool without its parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

discussion

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions