references:

Week 1 - Research Notes

1.Background and Definitions

In the Mantle protocol, a Channel is a virtual chain maintained by one or more sequencers on behalf of a Zone. Each channel maintains a state that includes a list of accredited keys — the set of sequencers authorized to write messages to it.

The Round-Robin algorithm is the mechanism Mantle uses to determine, at any given block slot, which sequencer in the accredited list holds the current write authority. Only the sequencer holding write authority at a given slot is permitted to post a valid CHANNEL_INSCRIBE operation to that channel.

The full implementation from the Mantle specification is reproduced below:

# Round Robin algorithm determining the new sequencer index and the
# new sequencer starting slot
def round_robin(block_slot: Slot, channel: ChannelState) -> (u16, u64):
    elapsed_slots = block_slot - channel.tip_slot
    if (elapsed_slots >= channel.posting_timeout && channel.posting_timeout != 0):
        # Get the number of sequencers that get timed out
        sequencers_timed_out = elapsed_slots // channel.posting_timeout
        index = (channel.tip_sequencer + sequencers_timed_out) \
                % len(channel.accredited_keys)
        starting_slot = channel.tip_slot \
                      + sequencers_timed_out * channel.posting_timeout
    elif channel.posting_timeframe != 0:
        # Get the number of timeframes elapsed to get who is the sequencer
        tip_sequencer_duration = block_slot - channel.tip_sequencer_starting_slot
        rotations = tip_sequencer_duration // channel.posting_timeframe
        index = (channel.tip_sequencer + rotations) \
                % len(channel.accredited_keys)
        starting_slot = channel.tip_sequencer_starting_slot \
                      + rotations * channel.posting_timeframe
    else:
        # Infinite turn (posting_timeframe = 0), not timed out
        index = channel.tip_sequencer
        starting_slot = channel.tip_sequencer_starting_slot
    return (index, starting_slot)

2. Mode 1 — Timeout-Based Forced Rotation

2.1 Trigger Condition

This mode is activated when:

That is, the last message was posted far enough in the past that the current sequencer is considered to have exceeded its allowed idle period.

2.2 Mechanism

When a sequencer fails to post a message within posting_timeout slots since the last message was written, the algorithm treats this as an implicit forfeit. It then computes how many consecutive sequencers have been skipped due to inactivity:

sequencers_timed_out = elapsed_slots // channel.posting_timeout
index = (channel.tip_sequencer + sequencers_timed_out)
        % len(channel.accredited_keys)