Documentation
¶
Index ¶
- Variables
- func GenerateInstanceID(periodID compose.PeriodID, seq compose.SequenceNumber, ...) compose.InstanceID
- type BlockHeader
- type BlockNumber
- type L1
- type PendingBlock
- type Publisher
- type PublisherMessenger
- type PublisherProver
- type PublisherState
- type SealedBlockHeader
- type Sequencer
- type SequencerMessenger
- type SequencerProver
- type SequencerState
- type SettledState
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCannotStartInstance = errors.New("can not start any instance") ErrCannotStartPeriod = errors.New("can not start period") ErrChainNotActive = errors.New("chain not active") ErrOldSettledState = errors.New("can not advance to older settled state") ErrInvalidRequest = errors.New("invalid request") )
View Source
var ( ErrBlockSealMismatch = errors.New( "block number to be sealed does not match the current block number", ) ErrBlockAlreadyOpen = errors.New("there is already an open block") ErrBlockNotSequential = errors.New("block number is not sequential") ErrNoPendingBlock = errors.New("no pending block") ErrActiveInstanceExists = errors.New("there is already an active instance") ErrNoActiveInstance = errors.New("no active instance") ErrActiveInstanceMismatch = errors.New("mismatched active instance ID") ErrMismatchedFinalizedState = errors.New("mismatched finalized state") ErrPeriodIDMismatch = errors.New("instance period ID does not match current block period ID") ErrLowSequencerNumber = errors.New("instance sequence number is not greater than last sequence number") )
Functions ¶
func GenerateInstanceID ¶
func GenerateInstanceID( periodID compose.PeriodID, seq compose.SequenceNumber, xtRequest compose.XTRequest, ) compose.InstanceID
GenerateInstanceID returns SHA256(periodID || seq || tx1 || tx2 || ... || txn).
Types ¶
type BlockHeader ¶
type BlockHeader struct {
Number BlockNumber
BlockHash compose.BlockHash
StateRoot compose.StateRoot
}
type BlockNumber ¶
type BlockNumber uint64
type L1 ¶
type L1 interface {
PublishProof(superblockNumber compose.SuperblockNumber, proof []byte)
}
type PendingBlock ¶
type PendingBlock struct {
Number BlockNumber
PeriodID compose.PeriodID
SuperblockNumber compose.SuperblockNumber
}
type Publisher ¶
type Publisher interface {
// StartPeriod is called whenever a new period starts (i.e. CurrEthereumEpoch % 10 == 0).
StartPeriod() error
// StartInstance is called by the upper layer to try starting a new instance from the queued requests.
StartInstance(req compose.XTRequest) (compose.Instance, error)
// DecideInstance is called once an instance gets decided.
DecideInstance(instance compose.Instance) error
// AdvanceSettledState is called when L1 emits a new settled state event
AdvanceSettledState(
superblockNumber compose.SuperblockNumber,
superblockHash compose.SuperblockHash,
) error
// ProofTimeout: Once a period starts, if the network ZK proof is not generated within 9 epochs,
// the publisher must roll back to the last finalized superblock and discard any active settlement pipeline.
ProofTimeout()
// ReceiveProof is called whenever a proof is received from a sequencer.
ReceiveProof(
periodID compose.PeriodID,
superblockNumber compose.SuperblockNumber,
proof []byte,
chainID compose.ChainID,
)
}
func NewPublisher ¶
func NewPublisher( prover PublisherProver, messenger PublisherMessenger, l1 L1, previousPeriodID compose.PeriodID, previousTargetSuperblockNumber compose.SuperblockNumber, lastFinalizedSuperblockNumber compose.SuperblockNumber, lastFinalizedSuperblockHash compose.SuperblockHash, proofWindow uint64, logger zerolog.Logger, chains map[compose.ChainID]struct{}, ) (Publisher, error)
NewPublisher creates a new Publisher instance given a config, the immediate previous period ID, previous target superblock number, and the last settled state. The StartPeriod function needs to be called to start the first period, automatically incrementing PeriodID and TargetSuperblockNumber. Thus, if the current period is N and current superblock target is T, call NewPublisher with periodID = N-1 and target = T-1.
type PublisherMessenger ¶
type PublisherMessenger interface {
BroadcastStartPeriod(periodID compose.PeriodID, targetSuperblockNumber compose.SuperblockNumber)
BroadcastRollback(
periodID compose.PeriodID,
superblockNumber compose.SuperblockNumber,
superblockHash compose.SuperblockHash,
)
}
type PublisherProver ¶
type PublisherProver interface {
// RequestSuperblockProof requests a proof for the given superblock number. It's called after all proofs from sequencers have been received.
RequestSuperblockProof(
superblockNumber compose.SuperblockNumber,
lastSuperblockHash compose.SuperblockHash,
proofs [][]byte,
) ([]byte, error)
}
type PublisherState ¶
type PublisherState struct {
PeriodID compose.PeriodID
TargetSuperblockNumber compose.SuperblockNumber
// Settlement state
LastFinalizedSuperblockNumber compose.SuperblockNumber
LastFinalizedSuperblockHash compose.SuperblockHash
Proofs map[compose.SuperblockNumber]map[compose.ChainID][]byte
Chains map[compose.ChainID]struct{}
// Instances scheduling
SequenceNumber compose.SequenceNumber // Per-period sequence counter (monotone)
ActiveChains map[compose.ChainID]bool // Chains with active instances
// Proof window duration (in number of superblocks/periods) through which a pending superblock can be proven.
// StartPeriods are rejected if the next superblock is bigger than LastFinalizedSuperblockNumber + ProofWindow.
// 0 value means no window constrain.
ProofWindow uint64
// contains filtered or unexported fields
}
type SealedBlockHeader ¶
type SealedBlockHeader struct {
BlockHeader BlockHeader
PeriodID compose.PeriodID
SuperblockNumber compose.SuperblockNumber
}
SealedBlockHeader represents a block that has been sealed and included in the superblock chain.
type Sequencer ¶
type Sequencer interface {
// StartPeriod and Rollback are called when the publisher sends their respective messages.
StartPeriod(ctx context.Context, periodID compose.PeriodID, targetSuperblockNumber compose.SuperblockNumber) error
Rollback(
superblockNumber compose.SuperblockNumber,
superblockHash compose.SuperblockHash,
currentPeriodID compose.PeriodID,
) (BlockHeader, error)
// ReceiveXTRequest is called whenever a request from a user is received.
ReceiveXTRequest(ctx context.Context, request compose.XTRequest) error
// AdvanceSettledState is called when the L1 settlement event has occurred.
AdvanceSettledState(SettledState)
// Block builder policy
// BeginBlock is called at start of a new block
BeginBlock(blockNumber BlockNumber) error
// CanIncludeLocalTx return whether a local tx is admissible right now.
CanIncludeLocalTx() (include bool, err error)
// OnStartInstance is an SCP start-up hook. Locks local txs from being added (internal logic).
OnStartInstance(id compose.InstanceID, periodID compose.PeriodID, sequenceNumber compose.SequenceNumber) error
// OnDecidedInstance is an SCP decision hook. Unlocks local txs (internal logic).
OnDecidedInstance(id compose.InstanceID) error
// EndBlock: hook for when block ends
EndBlock(ctx context.Context, b BlockHeader) error
}
func NewSequencer ¶
func NewSequencer( prover SequencerProver, messenger SequencerMessenger, periodID compose.PeriodID, targetSuperblock compose.SuperblockNumber, settledState SettledState, logger zerolog.Logger, ) Sequencer
type SequencerMessenger ¶
type SequencerProver ¶
type SequencerProver interface {
// RequestProofs starts the settlement pipeline using the provided block header as head.
// If nil, it means there's no sealed block for the period.
RequestProofs(
ctx context.Context,
blockHeader *BlockHeader,
superblockNumber compose.SuperblockNumber,
) ([]byte, error)
}
type SequencerState ¶
type SequencerState struct {
PeriodID compose.PeriodID
TargetSuperblockNumber compose.SuperblockNumber // from StartPeriod.target_superblock_number
// PendingBlock represents the block being built.
PendingBlock *PendingBlock
ActiveInstanceID *compose.InstanceID // nil if no active instance
LastSequenceNumber *compose.SequenceNumber // nil if no started instance in this period
// Head represents the highest sealed block number.
Head BlockNumber
SealedBlockHead map[compose.PeriodID]SealedBlockHeader
SettledState SettledState
// contains filtered or unexported fields
}
type SettledState ¶
type SettledState struct {
BlockHeader BlockHeader
SuperblockNumber compose.SuperblockNumber
SuperblockHash compose.SuperblockHash
}
Click to show internal directories.
Click to hide internal directories.