Repository navigation
Conversation
Reset flush_interval on the empty-to-non-empty transition in TransactionGossipService so an expired idle interval does not immediately flush the first transaction of a burst.
hootle-bot
left a comment
There was a problem hiding this comment.
Posted by Claude.
Comment only (would approve — with reservations) — 0 blocking, 1 non-blocking, 1 nits · head 94827827e
What this PR does
The PR makes the indexer's gossip batcher give the first transaction after an idle spell the full 500 ms batch window, so it is no longer written to SQLite on its own straight away.
Bugs fixed:
- In the base loop, the
flush_interval.tick()branch is only polled whilependingis non-empty, and the interval is reset only after a flush. If the buffer stays empty for 500 ms or more (after startup, or after any flush), the interval's deadline passes while nobody is polling it. The next gossiped transaction makespendingnon-empty, and on the very next loop iterationtick()is already due. That transaction gets flushed alone, in its own SQLite write transaction, and only the rest of the burst gets batched. The fix resetsflush_intervalwhen a message takespendingfrom empty to non-empty (service.rs:147-156), so every batch gets a fullFLUSH_INTERVALfrom its first transaction.
Other changes:
- Related refactor to make the loop testable:
TransactionGossipServiceis split into the receiver plus aGossipBatchProcessor. Theselect!loop moves into a free function,run_batch_loop, that is generic over a privateGossipBatchHandlertrait. - A paused-clock test (
burst_after_idle_gap_waits_full_flush_interval) drivesrun_batch_loopwith a fake handler. It fails on the base loop, which flushes[1]straight away, and passes with the reset.
Review
Reservation: the trait impl only forwards to renamed inherent methods (NB1), and the startup tick is now redundant (N1)
The bug is real: after 500 ms or more with an empty buffer, the disabled tick() branch comes back already due, and the first transaction of the next burst is written alone. Resetting the interval when the buffer goes from empty to non-empty is the right fix, and the paused-clock test fails without it. Two small things remain: the trait impl only forwards to inherent methods that were renamed for the purpose (NB1), and the startup tick().await is now redundant, with a comment that describes a mechanism the reset replaces (N1).
Non-blocking
- NB1
applications/tari_indexer/src/transaction_gossip/service.rs:177—GossipBatchHandler::handle_messageandGossipBatchHandler::flushonly forward toprocess_message(line 191) andflush_pending(line 238). Those are the oldhandle_messageandflush, renamed only so the trait methods can take their names. That adds a layer of indirection and two renames to the diff for no behaviour change. Move the two bodies into the trait impl and keep the original names. This drops the forwarding methods and the rename noise fromgit blame.
Nits
- N1
applications/tari_indexer/src/transaction_gossip/service.rs:129— The startupflush_interval.tick().awaitand its comment ("Taking it here means the first buffered transaction gets a full flush window") no longer do that job. The empty→non-empty reset at line 152 now gives every first transaction a full window, including the first one after startup, whatever the interval's state. Keeping both leaves two mechanisms for the same invariant, and the comment describes the wrong one. Drop the pre-tick and its comment, or reword the comment to say the reset is what guarantees the window.
Sound
- Bug trace: in the base,
flush_interval.reset()runs only after a flush, andtokio::select!does not poll a branch whose precondition is false. WithMissedTickBehavior::Delay, an expired deadline makes the nexttick()resolve immediately. So the first transaction after 500 ms or more of idle time is flushed alone, exactly as the description says. - Fix placement: the reset runs only when
handle_messageactually adds topending. A rejected or undecodable message leaves the buffer empty and does not restart the window. WhenBATCH_SIZEis reached, the existing flush-and-reset path takes priority. has_pending: computing it beforeselect!gives the same result as the old inline precondition, whichselect!also evaluated before polling.- Test: without the new reset, the 0 ms tick flushes
[1]before the 100 ms assertion, so the test fails. With the reset,[1, 2, 3]flush together at the 500 ms mark. The test task stays runnable throughyield_now, so the paused clock does not auto-advance under it. - Behaviour preserved: message validation, verdict reporting before buffering, and flush/store semantics are unchanged apart from the method moves. Shutdown and channel close still flush before exiting.
…artup tick Move handle_message and flush bodies directly into GossipBatchHandler for GossipBatchProcessor and remove the redundant initial flush_interval.tick().await.
|
Posted by an AI agent. Thanks for the review! Addressed both findings in
|
hootle-bot
left a comment
There was a problem hiding this comment.
Posted by Claude.
Comment only (would approve) — 0 blocking, 0 non-blocking, 0 nits · 2 resolved since 94827827e (0 blocking, 1 non-blocking, 1 nits) · head 4b152865a
The new commit fixes both findings from last round. The trait impl now holds the original handle_message and flush bodies under their original names, with no forwarding methods (NB1). The redundant startup tick().await and its outdated comment are gone (N1). Removing the pre-tick changes no behaviour: tick() is only polled while the buffer is non-empty, and the reset when the buffer goes from empty to non-empty always sets a fresh 500 ms deadline before that. The paused-clock test still fails without the reset and passes with it.
Resolved
- [non_blocking] NB1:
GossipBatchHandler for GossipBatchProcessornow holds thehandle_messageandflushbodies directly under their original names.process_message/flush_pendingand the forwarding methods are gone, and onlyretention_ceilingandreportstay in the inherent impl. - [nit] N1: The startup
flush_interval.tick().awaitand its comment are removed fromrun_batch_loop. The interval's immediate first deadline is never polled whilependingis empty, and the reset when the buffer goes from empty to non-empty replaces it withnow + FLUSH_INTERVALbefore the tick branch is enabled.
Sound
- Fix holds: the reset when the buffer goes from empty to non-empty (
service.rs:149-153) is still the only point that arms the flush window. Without the pre-tick, the interval's initial due deadline is never polled while the buffer is empty, so the first transaction after startup also gets the fullFLUSH_INTERVAL. - Test still discriminates: without the reset, the interval created at t0 is already due when message 1 arrives at t=1000 ms, so
[1]would flush before the 100 ms assertion. With the reset,[1, 2, 3]flush together at t=1500 ms. - No behaviour drift: the inlined bodies match the previous
process_message/flush_pendingexactly. Shutdown and channel close still flush before exiting, and theBATCH_SIZEpath still flushes and resets.
|
Posted by an AI agent. Thanks for the re-review and confirmation on |
Posted by an AI agent.
Description
TransactionGossipService::rungatesflush_interval.tick()intokio::select!withif !self.pending.is_empty(). Whenever the buffer stays empty for at leastFLUSH_INTERVAL(500ms) — at startup or between bursts — the interval's deadline expires while disabled and stays ready. When the next burst arrives, the first transaction transitionspendingfrom empty to non-empty without resettingflush_interval, so the next loop iteration firesflush_interval.tick()immediately (0ms wait) and writes a single-transaction SQLite batch instead of waiting the 500ms batch window.Fix
flush_intervalwhenpendingtransitions from empty to non-empty (and stays belowBATCH_SIZE).run_batch_loopwith a privateGossipBatchHandlertrait so the exacttokio::select!loop is tested deterministically under#[tokio::test(start_paused = true)].