Sequencer State

struct SequencerState {
		lib: HeaderId
		tip: HeaderId
		finalized_msg: MsgId 
		
		// The queue of channel messages that extend from the finalized message
		// but have not yet finalized (they may be in mempool, or in non-finalized blocks)
		pending: Vec<SignedMantleTx>
		
		// The block tree extending from LIB
		unfinalized_tree: BTreeMap<HeaderId, ZoneSdkBlock>
}

// Specialized block representing the relevant information from L1 blocks
// the Zone SDK
struct ZoneSdkBlock {
    parent: HeaderId, // parent L1 Block
    channel_txs: Vec<SignedMantletx>, // txs interacting with this channel
}

Cryptarchia Events

  1. On new block b
    1. let zone_block = ZoneSdkBlock::from(b)
    2. if zone_block.parent not in seq.unfinalized_tree && zone_block.parent ≠ seq.lib
      1. backfill missing blocks up to b (not including)
    3. seq.unfinalized_tree.insert(b.id(), zone_block)
  2. On new LIB new_lib
    1. if new_lib not in seq.unfinalized_tree:
      1. backfill missing blocks up to and including new_lib
    2. walk backwards through all zone blocks from new_lib to seq.lib in seq.unfinalized tree
      1. remove each channel tx that appears in those zone blocks from the seq.pending queue
    3. update seq.lib = new_lib
    4. update seq.finalized_msg = <last msg id seen at the point of new_lib>
    5. prune unfinalized_tree to keep only new_lib and its descendants
  3. On new tip new_tip
    1. if new_tip not in seq.unfinalized_tree && new_tip ≠ seq.lib
      1. backfill missing blocks up to and including new_tip
    2. if channel tip in new_tip extends from the channel tip in seq.tip
      1. collect all transactions that extend from seq.tip up to new_tip: call it new_msgs
      2. update seq.tip = new_tip
      3. Emit event to user ChannelExtended { new_msgs }
    3. otherwise we have a channel re-org
      1. find the most recent common message in the channel between the channel state in seq.tip and channel state in new_tip , call it lcm_msg
      2. remove all transactions who continue from lcm_msg from pending, call these orphaned_msgs
      3. collect all transactions who continue from lcm_msg up to channel tip in new_tip , adopted_msgs
      4. append adopted_msgs to seq.pending
      5. updated seq.tip = new.tip
      6. Emit event to user ChannelReog { orphaned_msgs, adopted_msgs }

Publishing Messages to Channels

  1. On publish(msg)
    1. parent = most recent channel msg:
      1. if seq.pending is not empty, use the last msg in the pending queue
      2. otherwise use seq.finalized_msg
    2. build and sign mantle tx: msg_tx
    3. seq.pending.push(msg_tx)
    4. mempool.add(msg_tx)

Liveness

Mempool is best effort, and therefore we need stronger guarantees from sequencers that a transaction will be included.

  1. Periodically (every 5 seconds)
    1. collect all seq.pending txs that are not yet included in the chain at seq.unfinalized_tree[seq.tip] : call them resubmit_txs
    2. Re-add all resubmit_txs to the mempool to guarantee inclusion