Salvaged from #258 (closed): two session-correctness fixes that had nothing to do with the anti-abuse bond and are worth having on their own.
1. A retake keeps the stale session
take_order creates the session with:
let _ = crate::mostro::session::session_manager()
.create_session(order_id.clone(), trade.role.clone(), trade_index, trade.order.clone())
.await;
and create_session returns Err("SessionAlreadyExists") when one is already present (session.rs:98). The error is discarded, so a confirmed take over an order that already has a session keeps the old session with the old trade_key_index — and the chat key lookups that read session.trade_key_index then use the wrong index.
Reachable whenever the same order is taken twice in one process: a first take that the daemon rejected or that timed out, followed by a retake. Each take_order derives a fresh trade key, so the two takes hold different indexes.
#258 proposed install_session: an accepted take replaces whatever it finds instead of discarding the error.
2. A message from a superseded take acts on the current session
Daemon messages carry the trade index they were addressed to. Nothing checks it against the session's, so a late reply belonging to an earlier take can drive the Canceled / peer-pubkey handling of the take that replaced it. #258 proposed a generation gate: the deferral (and the exit-side effects) carry the trade key index they were armed for, and act only if it is still current.
Note: reachability here is more plausible than in the subscription-side case discussed in #325, because a retake reuses the same order_id with a different index — but it has not been verified against a live daemon, and that should be part of the work.
Related
Salvaged from #258 (closed): two session-correctness fixes that had nothing to do with the anti-abuse bond and are worth having on their own.
1. A retake keeps the stale session
take_ordercreates the session with:and
create_sessionreturnsErr("SessionAlreadyExists")when one is already present (session.rs:98). The error is discarded, so a confirmed take over an order that already has a session keeps the old session with the oldtrade_key_index— and the chat key lookups that readsession.trade_key_indexthen use the wrong index.Reachable whenever the same order is taken twice in one process: a first take that the daemon rejected or that timed out, followed by a retake. Each
take_orderderives a fresh trade key, so the two takes hold different indexes.#258 proposed
install_session: an accepted take replaces whatever it finds instead of discarding the error.2. A message from a superseded take acts on the current session
Daemon messages carry the trade index they were addressed to. Nothing checks it against the session's, so a late reply belonging to an earlier take can drive the
Canceled/ peer-pubkey handling of the take that replaced it. #258 proposed a generation gate: the deferral (and the exit-side effects) carry the trade key index they were armed for, and act only if it is still current.Note: reachability here is more plausible than in the subscription-side case discussed in #325, because a retake reuses the same
order_idwith a different index — but it has not been verified against a live daemon, and that should be part of the work.Related