MCPcopy Create free account
hub / github.com/base/base / fill_queue

Method fill_queue

crates/execution/tx-forwarding/src/reader/task.rs:205–233  ·  view source on GitHub ↗

Moves transactions from `lanes` into the destination queue until it is full or `lanes` is empty, alternating lanes per [`LaneMix`]. Returns how many were queued, or `None` if the forwarder is gone.

(&mut self, lanes: &mut Snapshot<P::Transaction>)

Source from the content-addressed store, hash-verified

203 /// empty, alternating lanes per [`LaneMix`]. Returns how many were queued, or `None` if the
204 /// forwarder is gone.
205 fn fill_queue(&mut self, lanes: &mut Snapshot<P::Transaction>) -> Option<u64> {
206 let mut txs_sent: u64 = 0;
207 let (mut standard_resent, mut validity_resent) = (0u64, 0u64);
208 while self.sender.capacity() > 0 {
209 let Some(tx) = lanes.pop(self.lane_mix.next_lane()) else { break };
210 let hash = *tx.hash();
211 match self.try_enqueue(&tx) {
212 Ok(()) => {
213 let is_validity = Self::is_validity(&tx);
214 if self.recently_sent.was_sent(&hash) {
215 if is_validity { validity_resent += 1 } else { standard_resent += 1 }
216 }
217 self.recently_sent.mark_sent(hash, is_validity);
218 txs_sent += 1;
219 }
220 // Only this reader produces into the queue, so capacity cannot shrink between the
221 // check above and the send.
222 Err(mpsc::error::TrySendError::Full(())) => break,
223 Err(mpsc::error::TrySendError::Closed(())) => return None,
224 }
225 }
226 Metrics::txs_sent(Arc::clone(&self.url_label)).increment(txs_sent);
227 for (kind, resent) in [("standard", standard_resent), ("validity", validity_resent)] {
228 if resent > 0 {
229 Metrics::txs_resent(Arc::clone(&self.url_label), kind).increment(resent);
230 }
231 }
232 Some(txs_sent)
233 }
234
235 /// Blocks until at least half of the destination queue is free.
236 ///

Callers 1

runMethod · 0.80

Calls 7

next_laneMethod · 0.80
try_enqueueMethod · 0.80
was_sentMethod · 0.80
mark_sentMethod · 0.80
incrementMethod · 0.80
popMethod · 0.45
hashMethod · 0.45

Tested by

no test coverage detected