Skip to content

Sequencer

Actions ordering

Every Micro-Rollup has a built in sequencing module that picks up the transactions from the actions pool and creates an ordered list of actions to be included in the next block. The sequencer also ensures that the actions are ordered in a way that they are executed in a deterministic manner across all the nodes in the network.

Private Sequencing

Currently each micro-rollup handles its own sequencer, it means its a centralized sequencer. We deliberately kept it this way to allow for different and interesting design patterns. We have a censorship resistance mechanism in place to prevent the sequencer from censoring actions in form of C0. More on this in the Confirmation Status section.

Parameters

The sequencer module has the following parameters that are set in the stackr.config.ts file

stackr.config.ts
 sequencer: {
    blockSize: 16,
    blockTime: 10,
    allowEmptyBlocks: true,
    disableBuilder: false,
  },
  • blockSize: The number of actions that the sequencer picks up from the pool to build a block.
  • blockTime: The time interval after which the sequencer picks up actions from the pool to build a block.
  • allowEmptyBlocks: A flag to allow creation of empty blocks (the one with no actions). Defaults to false.
  • disableBuilder: A flag to indicate if the rollup should not use the builder to generate new blocks. This is useful for functionally generating blocks when needed. Defaults to false.

Lazy blocks

In the above example, it means that the sequencer picks upto 16 actions every second and orders them in a block. If there are no actions in the pool then the sequencer does not create a block.

If there are less than 16 actions in the pool when the timer expires then the sequencer picks up any remaining number of actions and creates a block.

Ordering

The default sequencer strategy is FIFO (First In First Out) ordering of the actions. This means that the actions are ordered in the same order as they are received in the pool.

Custom Ordering Strategy

Stackr provides primitives for defining custom ordering strategies.

This is done by defining a new class that extends BaseStrategy class with the custom ordering logic implemented inside getOrderedActions method. For example:

strategy.ts
import { BaseStrategy, Action } from "@stackr/sdk";
 
/**
 * RandomStrategy is responsible for ordering actions in a random order.
 */
export class RandomStrategy extends BaseStrategy {
  /**
   * Create a new instance of RandomStrategy
   */
  constructor() {
    super('RandomOrder');
  }
 
  /**
   * Custom ordering logic for actions
   * returns the actions in a random order
   * @param actions - Unordered List of actions
   * @returns - Ordered list of actions
   */
  async getOrderedActions(actions: Action[]): Promise<Action[]> {
    return Promise.resolve(
      actions.sort(() => {
        return 0.5 - Math.random();
      }),
    );
  }
}

Shared Sequencing (soon)

In the future, Stackr also aims to integrate third-party sequencers that can be used to sequence the actions. This will allow for more flexibility in the ordering of the actions and also allow micro-rollups to compose with other chains in the system