One-round serial queuer strategy
Overview
The one-round serial queuing strategy is a simple strategy for queuing batches for submission to a distributed ledger (DLT). It ensures that batches are submitted and committed to the DLT in the order in which they are submitted to Grid.
See the high-level document on (submission queuer strategies)[/community/planning/batch_queuer_strategies.html] for a detailed discussion of the decisions behind this strategy’s design.
Algorithm
Some of these steps may be pre-implemented in the store for efficiency, but the queuer should implement all of these so it can be separated from the store.
-
Start with a list of all batches that do not have these batch statuses:
Some(Committed)
Some(Valid)
Some(Invalid)
This should leave a list of batches (called
batch_list
) in the following states:{submitted = false, batch_status = None}
{submitted = true, batch_status = Some(Pending)}
{submitted = false, batch_status = Some(Unknown)}
{submitted = false, batch_status = Some(Delayed)}
-
Create a mutable vector called
batch_queue
. -
Get all batches from
batch_list
wherebatch_status = Some(Unknown)
and add these tobatch_queue
. -
Get all batches from
batch_list
wherebatch_status = Some(Delayed)
and the last submission attempt is outside the delay window, then add these tobatch_queue
. -
Get a list of all
service_id
s, excluding anyservice_id
of batches with abatch_status
ofSome(Pending)
,Some(Unknown)
, orSome(Delayed)
. Call this listservice_id_list
. -
For each
service_id
inservice_id_list
, find the batch or batches with the oldestcreated_at
date (there may be more than one if the oldest batches were created at the same time).If there is one oldest batch, add this batch to
batch_queue
.If there is more than one oldest batch, select the batch with the first alphabetically-sorted
batch_header
(this ensures deterministic queuing behavior). Add this batch tobatch_queue
.
Which batches to queue?
From the queuer’s perspective, batches fall into three categories:
Queue now
These batches look like (there are additional criteria for prioritization):
-
{submitted = false, batch_status = None}
- These have not been submitted and there are no pending batches with this service_id; there are also no batches with statusunknown
ordelayed
-
{submitted = false, batch_status = Some(Unknown)}
- These have been submitted, but the DLT doesn’t recognize them -
{submitted = false, batch_status = Some(Delayed), last_submitted_at <= now - 15 seconds?}
- The submitter attempted to submit these, but something went wrong and these need to be retried; the delay window has expired, so these should be retried now
Queue later
These batches look like:
-
{submitted = false, batch_status = Some(Delayed), last_submitted_at > now - 15 seconds?}
- The submitter attempted to submit these, but something went wrong and these need to be retried; the delay window has not expired yet -
{submitted = false, batch_status = None, service_id = (service_id of a pending, unknown, or delayed batch)}
- These are new batches, but there is a batch with the same service_id that must be committed or declared invalid before another batch with this service_id can be submitted
Don’t queue
These batches look like:
{submitted = true, batch_status = Some(Pending)}
{submitted = true, batch_status = Some(Invalid)}
{submitted = true, batch_status = Some(Valid)}
{submitted = true, batch_status = Some(Committed)}
-
{submitted = true, batch_status = None}
- These bathes are in process of being submitted and should not be queued
Additional notes
-
submitted = True
is an indicator that the submitter has the batch and is doing something with it when the batch status isNone
orDelayed
orUnknown
- it guards against the queuer re-queuing the batch while the submitter has it. - The monitor needs to update
submitted
to false when it sets the batch status toUnknown
.