derive

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 26 Imported by: 47

Documentation

Overview

Package derive provides the data transformation functions that take L1 data and turn it into L2 blocks and results. Certain L2 data is also able to turned back into L1 data.

The flow is data is as follows receipts, batches -> eth.PayloadAttributes, by parsing the L1 data and deriving L2 inputs l2.PayloadAttributes -> l2.ExecutionPayload, by running the EVM (using an Execution Engine) L2 block -> Corresponding L1 block info, by parsing the first deposited transaction

The Payload Attributes derivation stage is a pure function. The Execution Payload derivation stage relies on the L2 execution engine to perform the state update. The inversion step is a pure function.

The steps should be kept separate to enable easier testing.

Index

Constants

View Source
const (
	// BatchDrop indicates that the batch is invalid, and will always be in the future, unless we reorg
	BatchDrop = iota
	// BatchAccept indicates that the batch is valid and should be processed
	BatchAccept
	// BatchUndecided indicates we are lacking L1 information until we can proceed batch filtering
	BatchUndecided
	// BatchFuture indicates that the batch may be valid, but cannot be processed yet and should be checked again later
	BatchFuture
)
View Source
const (
	UserDepositSourceDomain   = 0
	L1InfoDepositSourceDomain = 1
)
View Source
const (
	BatchV1Type = iota
)
View Source
const ChannelIDDataSize = 32

ChannelIDDataSize defines the length of the channel ID data part

View Source
const DerivationVersion0 = 0
View Source
const MaxChannelBankSize = 100_000_000

MaxChannelBankSize is the amount of memory space, in number of bytes, till the bank is pruned by removing channels, starting with the oldest channel.

View Source
const MaxFrameLen = 1_000_000

Frames cannot be larger than 1 MB. Data transactions that carry frames are generally not larger than 128 KB due to L1 network conditions, but we leave space to grow larger anyway (gas limit allows for more data).

Variables

View Source
var (
	DepositEventABI      = "TransactionDeposited(address,address,uint256,bytes)"
	DepositEventABIHash  = crypto.Keccak256Hash([]byte(DepositEventABI))
	DepositEventVersion0 = common.Hash{}
)
View Source
var (
	L1InfoFuncSignature    = "setL1BlockValues(uint64,uint64,uint256,bytes32,uint64)"
	L1InfoFuncBytes4       = crypto.Keccak256([]byte(L1InfoFuncSignature))[:4]
	L1InfoDepositerAddress = common.HexToAddress("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001")
	L1BlockAddress         = predeploys.L1BlockAddr
)
View Source
var DuplicateErr = errors.New("duplicate frame")

DuplicateErr is returned when a newly read frame is already known

View Source
var ErrCritical = NewCriticalError(nil)
View Source
var ErrReset = NewResetError(nil)
View Source
var ErrTemporary = NewTemporaryError(nil)

Sentinel errors, use these to get the severity of errors by calling errors.Is(err, ErrTemporary) for example.

Functions

func AttributesMatchBlock

func AttributesMatchBlock(attrs *eth.PayloadAttributes, parentHash common.Hash, block *eth.ExecutionPayload) error

AttributesMatchBlock checks if the L2 attributes pre-inputs match the output nil if it is a match. If err is not nil, the error contains the reason for the mismatch

func BatchReader

func BatchReader(r io.Reader, l1InclusionBlock eth.L1BlockRef) (func() (BatchWithL1InclusionBlock, error), error)

BatchReader provides a function that iteratively consumes batches from the reader. The L1Inclusion block is also provided at creation time.

func DataFromEVMTransactions

func DataFromEVMTransactions(config *rollup.Config, txs types.Transactions, log log.Logger) []eth.Data

func DeriveDeposits

func DeriveDeposits(receipts []*types.Receipt, depositContractAddr common.Address) ([]hexutil.Bytes, error)

func L1InfoDeposit

func L1InfoDeposit(seqNumber uint64, block eth.BlockInfo) (*types.DepositTx, error)

L1InfoDeposit creates a L1 Info deposit transaction based on the L1 block, and the L2 block-height difference with the start of the epoch.

func L1InfoDepositBytes

func L1InfoDepositBytes(seqNumber uint64, l1Info eth.BlockInfo) ([]byte, error)

L1InfoDepositBytes returns a serialized L1-info attributes transaction.

func MarshalDepositLogEvent

func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.DepositTx) *types.Log

MarshalDepositLogEvent returns an EVM log entry that encodes a TransactionDeposited event from the deposit contract. This is the reverse of the deposit transaction derivation.

func NewCriticalError

func NewCriticalError(err error) error

NewCriticalError returns a critical error.

func NewError

func NewError(err error, level Level) error

NewError returns a custom Error.

func NewResetError

func NewResetError(err error) error

NewResetError returns a pipeline reset error.

func NewTemporaryError

func NewTemporaryError(err error) error

NewTemporaryError returns a temporary error.

func PayloadToBlockRef

func PayloadToBlockRef(payload *eth.ExecutionPayload, genesis *rollup.Genesis) (eth.L2BlockRef, error)

PayloadToBlockRef extracts the essential L2BlockRef information from an execution payload, falling back to genesis information if necessary.

func PreparePayloadAttributes

func PreparePayloadAttributes(ctx context.Context, cfg *rollup.Config, dl L1ReceiptsFetcher, l2Parent eth.L2BlockRef, timestamp uint64, epoch eth.BlockID) (attrs *eth.PayloadAttributes, err error)

PreparePayloadAttributes prepares a PayloadAttributes template that is ready to build a L2 block with deposits only, on top of the given l2Parent, with the given epoch as L1 origin. The template defaults to NoTxPool=true, and no sequencer transactions: the caller has to modify the template to add transactions, by setting NoTxPool=false as sequencer, or by appending batch transactions as verifier. The severity of the error is returned; a crit=false error means there was a temporary issue, like a failed RPC or time-out. A crit=true error means the input arguments are inconsistent or invalid.

func UnmarshalDepositLogEvent

func UnmarshalDepositLogEvent(ev *types.Log) (*types.DepositTx, error)

UnmarshalDepositLogEvent decodes an EVM log entry emitted by the deposit contract into typed deposit data.

parse log data for:

event TransactionDeposited(
    address indexed from,
    address indexed to,
    uint256 indexed version,
    bytes opaqueData
);

Additionally, the event log-index and

func UserDeposits

func UserDeposits(receipts []*types.Receipt, depositContractAddr common.Address) ([]*types.DepositTx, error)

UserDeposits transforms the L2 block-height and L1 receipts into the transaction inputs for a full L2 block

Types

type AttributesQueue

type AttributesQueue struct {
	// contains filtered or unexported fields
}

func NewAttributesQueue

func NewAttributesQueue(log log.Logger, cfg *rollup.Config, l1Fetcher L1ReceiptsFetcher, next AttributesQueueOutput) *AttributesQueue

func (*AttributesQueue) AddBatch added in v0.3.0

func (aq *AttributesQueue) AddBatch(batch *BatchData)

func (*AttributesQueue) Progress added in v0.3.0

func (aq *AttributesQueue) Progress() Progress

func (*AttributesQueue) ResetStep added in v0.3.0

func (aq *AttributesQueue) ResetStep(ctx context.Context, l1Fetcher L1Fetcher) error

func (*AttributesQueue) SafeL2Head added in v0.3.0

func (aq *AttributesQueue) SafeL2Head() eth.L2BlockRef

func (*AttributesQueue) Step added in v0.3.0

func (aq *AttributesQueue) Step(ctx context.Context, outer Progress) error

type AttributesQueueOutput added in v0.3.0

type AttributesQueueOutput interface {
	AddSafeAttributes(attributes *eth.PayloadAttributes)
	SafeL2Head() eth.L2BlockRef
	StageProgress
}

type BatchData

type BatchData struct {
	BatchV1
}

func (*BatchData) DecodeRLP

func (b *BatchData) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (*BatchData) EncodeRLP

func (b *BatchData) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*BatchData) MarshalBinary

func (b *BatchData) MarshalBinary() ([]byte, error)

MarshalBinary returns the canonical encoding of the batch.

func (*BatchData) UnmarshalBinary

func (b *BatchData) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the canonical encoding of batch.

type BatchQueue

type BatchQueue struct {
	// contains filtered or unexported fields
}

BatchQueue contains a set of batches for every L1 block. L1 blocks are contiguous and this does not support reorgs.

func NewBatchQueue

func NewBatchQueue(log log.Logger, cfg *rollup.Config, next BatchQueueOutput) *BatchQueue

NewBatchQueue creates a BatchQueue, which should be Reset(origin) before use.

func (*BatchQueue) AddBatch

func (bq *BatchQueue) AddBatch(batch *BatchData)

func (*BatchQueue) Progress added in v0.3.0

func (bq *BatchQueue) Progress() Progress

func (*BatchQueue) ResetStep added in v0.3.0

func (bq *BatchQueue) ResetStep(ctx context.Context, l1Fetcher L1Fetcher) error

func (*BatchQueue) Step added in v0.3.0

func (bq *BatchQueue) Step(ctx context.Context, outer Progress) error

type BatchQueueOutput added in v0.3.0

type BatchQueueOutput interface {
	StageProgress
	AddBatch(batch *BatchData)
	SafeL2Head() eth.L2BlockRef
}

type BatchQueueStage added in v0.3.0

type BatchQueueStage interface {
	StageProgress
	AddBatch(batch *BatchData)
}

type BatchV1

type BatchV1 struct {
	ParentHash common.Hash  // parent L2 block hash
	EpochNum   rollup.Epoch // aka l1 num
	EpochHash  common.Hash  // block hash
	Timestamp  uint64
	// no feeRecipient address input, all fees go to a L2 contract
	Transactions []hexutil.Bytes
}

func (*BatchV1) Epoch

func (b *BatchV1) Epoch() eth.BlockID

type BatchValidity

type BatchValidity uint8

func CheckBatch

func CheckBatch(cfg *rollup.Config, log log.Logger, l1Blocks []eth.L1BlockRef, l2SafeHead eth.L2BlockRef, batch *BatchWithL1InclusionBlock) BatchValidity

CheckBatch checks if the given batch can be applied on top of the given l2SafeHead, given the contextual L1 blocks the batch was included in. The first entry of the l1Blocks should match the origin of the l2SafeHead. One or more consecutive l1Blocks should be provided. In case of only a single L1 block, the decision whether a batch is valid may have to stay undecided.

type BatchWithL1InclusionBlock

type BatchWithL1InclusionBlock struct {
	L1InclusionBlock eth.L1BlockRef
	Batch            *BatchData
}

type BlockInsertionErrType

type BlockInsertionErrType uint
const (
	BlockInsertOK BlockInsertionErrType = iota
	BlockInsertTemporaryErr
	BlockInsertPrestateErr
	BlockInsertPayloadErr
)

func InsertHeadBlock

func InsertHeadBlock(ctx context.Context, log log.Logger, eng Engine, fc eth.ForkchoiceState, attrs *eth.PayloadAttributes, updateSafe bool) (out *eth.ExecutionPayload, errTyp BlockInsertionErrType, err error)

InsertHeadBlock creates, executes, and inserts the specified block as the head block. It first uses the given FC to start the block creation process and then after the payload is executed, sets the FC to the same safe and finalized hashes, but updates the head hash to the new block. If updateSafe is true, the head block is considered to be the safe head as well as the head. It returns the payload, an RPC error (if the payload might still be valid), and a payload error (if the payload was not valid)

type ByteReader

type ByteReader interface {
	io.Reader
	io.ByteReader
}

type CalldataSource added in v0.3.0

type CalldataSource struct {
	// contains filtered or unexported fields
}

func NewCalldataSource added in v0.3.0

func NewCalldataSource(log log.Logger, cfg *rollup.Config, fetcher L1TransactionFetcher) *CalldataSource

func (*CalldataSource) OpenData added in v0.3.0

func (cs *CalldataSource) OpenData(ctx context.Context, id eth.BlockID) (DataIter, error)

type Channel

type Channel struct {
	// contains filtered or unexported fields
}

A Channel is a set of batches that are split into at least one, but possibly multiple frames. Frames are allowed to be ingested out of order. Each frame is ingested one by one. Once a frame with `closed` is added to the channel, the channel may mark itself as ready for reading once all intervening frames have been added

func NewChannel

func NewChannel(id ChannelID) *Channel

func (*Channel) AddFrame

func (ch *Channel) AddFrame(frame Frame, l1InclusionBlock eth.L1BlockRef) error

AddFrame adds a frame to the channel. If the frame is not valid for the channel it returns an error. Otherwise the frame is buffered.

func (*Channel) IsReady

func (ch *Channel) IsReady() bool

IsReady returns true iff the channel is ready to be read.

func (*Channel) Reader

func (ch *Channel) Reader() io.Reader

Reader returns an io.Reader over the channel data. This panics if it is called while `IsReady` is not true. This function is able to be called multiple times.

func (*Channel) Size

func (ch *Channel) Size() uint64

Size returns the current size of the channel including frame overhead. Reading from the channel does not reduce the size as reading is done on uncompressed data while this size is over compressed data.

type ChannelBank

type ChannelBank struct {
	// contains filtered or unexported fields
}

ChannelBank buffers channel frames, and emits full channel data

func NewChannelBank

func NewChannelBank(log log.Logger, cfg *rollup.Config, next ChannelBankOutput) *ChannelBank

NewChannelBank creates a ChannelBank, which should be Reset(origin) before use.

func (*ChannelBank) IngestData added in v0.3.0

func (ib *ChannelBank) IngestData(data []byte)

IngestData adds new L1 data to the channel bank. Read() should be called repeatedly first, until everything has been read, before adding new data.\

func (*ChannelBank) Progress added in v0.3.0

func (ib *ChannelBank) Progress() Progress

func (*ChannelBank) Read

func (ib *ChannelBank) Read() (data []byte, err error)

Read the raw data of the first channel, if it's timed-out or closed. Read returns io.EOF if there is nothing new to read.

func (*ChannelBank) ResetStep added in v0.3.0

func (ib *ChannelBank) ResetStep(ctx context.Context, l1Fetcher L1Fetcher) error

ResetStep walks back the L1 chain, starting at the origin of the next stage, to find the origin that the channel bank should be reset to, to get consistent reads starting at origin. Any channel data before this origin will be timed out by the time the channel bank is synced up to the origin, so it is not relevant to replay it into the bank.

func (*ChannelBank) Step added in v0.3.0

func (ib *ChannelBank) Step(ctx context.Context, outer Progress) error

type ChannelBankOutput added in v0.3.0

type ChannelBankOutput interface {
	StageProgress
	WriteChannel(data []byte)
}

type ChannelID

type ChannelID struct {
	Data [ChannelIDDataSize]byte
	Time uint64
}

ChannelID identifies a "channel" a stream encoding a sequence of L2 information. A channelID is part random data (this may become a hash commitment to restrict who opens which channel), and part timestamp. The timestamp invalidates the ID, to ensure channels cannot be re-opened after timeout, or opened too soon.

The ChannelID type is flat and can be used as map key.

func (ChannelID) MarshalText added in v0.3.0

func (id ChannelID) MarshalText() ([]byte, error)

func (ChannelID) String

func (id ChannelID) String() string

func (ChannelID) TerminalString

func (id ChannelID) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*ChannelID) UnmarshalText added in v0.3.0

func (id *ChannelID) UnmarshalText(text []byte) error

type ChannelInReader

type ChannelInReader struct {
	// contains filtered or unexported fields
}

func NewChannelInReader

func NewChannelInReader(log log.Logger, next BatchQueueStage) *ChannelInReader

NewChannelInReader creates a ChannelInReader, which should be Reset(origin) before use.

func (*ChannelInReader) NextChannel

func (cr *ChannelInReader) NextChannel()

NextChannel forces the next read to continue with the next channel, resetting any decoding/decompression state to a fresh start.

func (*ChannelInReader) Progress added in v0.3.0

func (cr *ChannelInReader) Progress() Progress

func (*ChannelInReader) ResetStep added in v0.3.0

func (cr *ChannelInReader) ResetStep(ctx context.Context, l1Fetcher L1Fetcher) error

func (*ChannelInReader) Step added in v0.3.0

func (cr *ChannelInReader) Step(ctx context.Context, outer Progress) error

func (*ChannelInReader) WriteChannel

func (cr *ChannelInReader) WriteChannel(data []byte)

TODO: Take full channel for better logging

type ChannelOut

type ChannelOut struct {
	// contains filtered or unexported fields
}

func NewChannelOut

func NewChannelOut(channelTime uint64) (*ChannelOut, error)

func (*ChannelOut) AddBlock

func (co *ChannelOut) AddBlock(block *types.Block) error

func (*ChannelOut) Close

func (co *ChannelOut) Close() error

func (*ChannelOut) Flush

func (co *ChannelOut) Flush() error

Flush flushes the internal compression stage to the ready buffer. It enables pulling a larger & more complete frame. It reduces the compression efficiency.

func (*ChannelOut) ID

func (co *ChannelOut) ID() ChannelID

func (*ChannelOut) OutputFrame

func (co *ChannelOut) OutputFrame(w *bytes.Buffer, maxSize uint64) error

OutputFrame writes a frame to w with a given max size Use `ReadyBytes`, `Flush`, and `Close` to modify the ready buffer. Returns io.EOF when the channel is closed & there are no more frames Returns nil if there is still more buffered data. Returns and error if it ran into an error during processing.

func (*ChannelOut) ReadyBytes

func (co *ChannelOut) ReadyBytes() int

ReadyBytes returns the number of bytes that the channel out can immediately output into a frame. Use `Flush` or `Close` to move data from the compression buffer into the ready buffer if more bytes are needed. Add blocks may add to the ready buffer, but it is not guaranteed due to the compression stage.

func (*ChannelOut) Reset

func (co *ChannelOut) Reset(channelTime uint64) error

TODO: reuse ChannelOut for performance

type DataAvailabilitySource

type DataAvailabilitySource interface {
	// OpenData does any initial data-fetching work and returns an iterator to fetch data with.
	OpenData(ctx context.Context, id eth.BlockID) (DataIter, error)
}

DataAvailabilitySource provides rollup input data

type DataIter

type DataIter interface {
	// Next can be repeatedly called for more data, until it returns an io.EOF error.
	// It never returns io.EOF and data at the same time.
	Next(ctx context.Context) (eth.Data, error)
}

DataIter is a minimal iteration interface to fetch rollup input data from an arbitrary data-availability source

type DataSlice added in v0.3.0

type DataSlice []eth.Data

func (*DataSlice) Next added in v0.3.0

func (ds *DataSlice) Next(ctx context.Context) (eth.Data, error)

type DerivationPipeline

type DerivationPipeline struct {
	// contains filtered or unexported fields
}

DerivationPipeline is updated with new L1 data, and the Step() function can be iterated on to keep the L2 Engine in sync.

func NewDerivationPipeline

func NewDerivationPipeline(log log.Logger, cfg *rollup.Config, l1Fetcher L1Fetcher, engine Engine, metrics Metrics) *DerivationPipeline

NewDerivationPipeline creates a derivation pipeline, which should be reset before use.

func (*DerivationPipeline) AddUnsafePayload

func (dp *DerivationPipeline) AddUnsafePayload(payload *eth.ExecutionPayload)

AddUnsafePayload schedules an execution payload to be processed, ahead of deriving it from L1

func (*DerivationPipeline) Finalize

func (dp *DerivationPipeline) Finalize(l1Origin eth.BlockID)

func (*DerivationPipeline) Finalized

func (dp *DerivationPipeline) Finalized() eth.L2BlockRef

func (*DerivationPipeline) Progress added in v0.3.0

func (dp *DerivationPipeline) Progress() Progress

func (*DerivationPipeline) Reset

func (dp *DerivationPipeline) Reset()

func (*DerivationPipeline) SafeL2Head

func (dp *DerivationPipeline) SafeL2Head() eth.L2BlockRef

func (*DerivationPipeline) SetUnsafeHead

func (dp *DerivationPipeline) SetUnsafeHead(head eth.L2BlockRef)

func (*DerivationPipeline) Step

func (dp *DerivationPipeline) Step(ctx context.Context) error

Step tries to progress the buffer. An EOF is returned if there pipeline is blocked by waiting for new L1 data. If ctx errors no error is returned, but the step may exit early in a state that can still be continued. Any other error is critical and the derivation pipeline should be reset. An error is expected when the underlying source closes. When Step returns nil, it should be called again, to continue the derivation process.

func (*DerivationPipeline) UnsafeL2Head

func (dp *DerivationPipeline) UnsafeL2Head() eth.L2BlockRef

UnsafeL2Head returns the head of the L2 chain that we are deriving for, this may be past what we derived from L1

type Engine

type Engine interface {
	GetPayload(ctx context.Context, payloadId eth.PayloadID) (*eth.ExecutionPayload, error)
	ForkchoiceUpdate(ctx context.Context, state *eth.ForkchoiceState, attr *eth.PayloadAttributes) (*eth.ForkchoiceUpdatedResult, error)
	NewPayload(ctx context.Context, payload *eth.ExecutionPayload) (*eth.PayloadStatusV1, error)
	PayloadByHash(context.Context, common.Hash) (*eth.ExecutionPayload, error)
	PayloadByNumber(context.Context, uint64) (*eth.ExecutionPayload, error)
	L2BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L2BlockRef, error)
	L2BlockRefByHash(ctx context.Context, l2Hash common.Hash) (eth.L2BlockRef, error)
}

type EngineQueue

type EngineQueue struct {
	// contains filtered or unexported fields
}

EngineQueue queues up payload attributes to consolidate or process with the provided Engine

func NewEngineQueue

func NewEngineQueue(log log.Logger, cfg *rollup.Config, engine Engine, metrics Metrics) *EngineQueue

NewEngineQueue creates a new EngineQueue, which should be Reset(origin) before use.

func (*EngineQueue) AddSafeAttributes

func (eq *EngineQueue) AddSafeAttributes(attributes *eth.PayloadAttributes)

func (*EngineQueue) AddUnsafePayload

func (eq *EngineQueue) AddUnsafePayload(payload *eth.ExecutionPayload)

func (*EngineQueue) Finalize

func (eq *EngineQueue) Finalize(l1Origin eth.BlockID)

func (*EngineQueue) Finalized

func (eq *EngineQueue) Finalized() eth.L2BlockRef

func (*EngineQueue) LastL2Time

func (eq *EngineQueue) LastL2Time() uint64

func (*EngineQueue) Progress added in v0.3.0

func (eq *EngineQueue) Progress() Progress

func (*EngineQueue) ResetStep added in v0.3.0

func (eq *EngineQueue) ResetStep(ctx context.Context, l1Fetcher L1Fetcher) error

ResetStep Walks the L2 chain backwards until it finds an L2 block whose L1 origin is canonical. The unsafe head is set to the head of the L2 chain, unless the existing safe head is not canonical.

func (*EngineQueue) SafeL2Head

func (eq *EngineQueue) SafeL2Head() eth.L2BlockRef

func (*EngineQueue) SetUnsafeHead

func (eq *EngineQueue) SetUnsafeHead(head eth.L2BlockRef)

func (*EngineQueue) Step

func (eq *EngineQueue) Step(ctx context.Context, outer Progress) error

func (*EngineQueue) UnsafeL2Head

func (eq *EngineQueue) UnsafeL2Head() eth.L2BlockRef

type EngineQueueStage

type EngineQueueStage interface {
	Finalized() eth.L2BlockRef
	UnsafeL2Head() eth.L2BlockRef
	SafeL2Head() eth.L2BlockRef
	Progress() Progress
	SetUnsafeHead(head eth.L2BlockRef)

	Finalize(l1Origin eth.BlockID)
	AddSafeAttributes(attributes *eth.PayloadAttributes)
	AddUnsafePayload(payload *eth.ExecutionPayload)
}

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is a wrapper for error, description and a severity level.

func (Error) Error

func (e Error) Error() string

Error satisfies the error interface.

func (Error) Is

func (e Error) Is(target error) bool

Is satisfies the error Unwrap interface.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap satisfies the Is/As interface.

type FinalityData

type FinalityData struct {
	// The last L2 block that was fully derived and inserted into the L2 engine while processing this L1 block.
	L2Block eth.L2BlockRef
	// The L1 block this stage was at when inserting the L2 block.
	// When this L1 block is finalized, the L2 chain up to this block can be fully reproduced from finalized L1 data.
	L1Block eth.BlockID
}

type Frame

type Frame struct {
	ID          ChannelID
	FrameNumber uint16
	Data        []byte
	IsLast      bool
}

func ParseFrames

func ParseFrames(data []byte) ([]Frame, error)

ParseFrames parse the on chain serialization of frame(s) in an L1 transaction. Currently only version 0 of the serialization format is supported. All frames must be parsed without error and there must not be any left over data and there must be at least one frame.

func (*Frame) MarshalBinary

func (f *Frame) MarshalBinary(w io.Writer) error

MarshalBinary writes the frame to `w`. It returns any errors encountered while writing, but generally expects the writer very rarely fail.

func (*Frame) UnmarshalBinary

func (f *Frame) UnmarshalBinary(r ByteReader) error

UnmarshalBinary consumes a full frame from the reader. If `r` fails a read, it returns the error from the reader The reader will be left in a partially read state.

type L1BlockInfo

type L1BlockInfo struct {
	Number    uint64
	Time      uint64
	BaseFee   *big.Int
	BlockHash common.Hash
	// Not strictly a piece of L1 information. Represents the number of L2 blocks since the start of the epoch,
	// i.e. when the actual L1 info was first introduced.
	SequenceNumber uint64
}

L1BlockInfo presents the information stored in a L1Block.setL1BlockValues call

func L1InfoDepositTxData

func L1InfoDepositTxData(data []byte) (L1BlockInfo, error)

L1InfoDepositTxData is the inverse of L1InfoDeposit, to see where the L2 chain is derived from

func (*L1BlockInfo) MarshalBinary

func (info *L1BlockInfo) MarshalBinary() ([]byte, error)

func (*L1BlockInfo) UnmarshalBinary

func (info *L1BlockInfo) UnmarshalBinary(data []byte) error

type L1BlockRefByHashFetcher

type L1BlockRefByHashFetcher interface {
	L1BlockRefByHash(context.Context, common.Hash) (eth.L1BlockRef, error)
}

type L1BlockRefByNumberFetcher

type L1BlockRefByNumberFetcher interface {
	L1BlockRefByNumber(context.Context, uint64) (eth.L1BlockRef, error)
}

type L1InfoDepositSource

type L1InfoDepositSource struct {
	L1BlockHash common.Hash
	SeqNumber   uint64
}

func (*L1InfoDepositSource) SourceHash

func (dep *L1InfoDepositSource) SourceHash() common.Hash

type L1ReceiptsFetcher

type L1ReceiptsFetcher interface {
	InfoByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, error)
	Fetch(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, types.Transactions, eth.ReceiptsFetcher, error)
}

L1ReceiptsFetcher fetches L1 header info and receipts for the payload attributes derivation (the info tx and deposits)

type L1Retrieval

type L1Retrieval struct {
	// contains filtered or unexported fields
}

func NewL1Retrieval

func NewL1Retrieval(log log.Logger, dataSrc DataAvailabilitySource, next L1SourceOutput) *L1Retrieval

func (*L1Retrieval) Progress added in v0.3.0

func (l1r *L1Retrieval) Progress() Progress

func (*L1Retrieval) ResetStep added in v0.3.0

func (l1r *L1Retrieval) ResetStep(ctx context.Context, l1Fetcher L1Fetcher) error

func (*L1Retrieval) Step added in v0.3.0

func (l1r *L1Retrieval) Step(ctx context.Context, outer Progress) error

type L1SourceOutput added in v0.3.0

type L1SourceOutput interface {
	StageProgress
	IngestData(data []byte)
}

type L1TransactionFetcher

type L1TransactionFetcher interface {
	InfoAndTxsByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, types.Transactions, error)
}

type L1Traversal

type L1Traversal struct {
	// contains filtered or unexported fields
}

func NewL1Traversal

func NewL1Traversal(log log.Logger, l1Blocks L1BlockRefByNumberFetcher, next StageProgress) *L1Traversal

func (*L1Traversal) Progress added in v0.3.0

func (l1t *L1Traversal) Progress() Progress

func (*L1Traversal) ResetStep added in v0.3.0

func (l1t *L1Traversal) ResetStep(ctx context.Context, l1Fetcher L1Fetcher) error

func (*L1Traversal) Step added in v0.3.0

func (l1t *L1Traversal) Step(ctx context.Context, outer Progress) error

type Level

type Level uint

Level is the severity level of the error.

const (
	// LevelTemporary is a temporary error for example due to an RPC or
	// connection issue, and can be safely ignored and retried by the caller
	LevelTemporary Level = iota
	// LevelReset is a pipeline reset error. It must be treated like a reorg.
	LevelReset
	// LevelCritical is a critical error.
	LevelCritical
)

There are three levels currently, out of which only 2 are being used to classify error by severity. LevelTemporary

func (Level) String

func (lvl Level) String() string

type Metrics

type Metrics interface {
	RecordL1Ref(name string, ref eth.L1BlockRef)
	RecordL2Ref(name string, ref eth.L2BlockRef)
}

type Progress added in v0.3.0

type Progress struct {
	Origin eth.L1BlockRef
	// Closed means that the Current has no more data that the stage may need.
	Closed bool
}

Progress represents the progress of a derivation stage: the input L1 block that is being processed, and whether it's fully processed yet.

func (*Progress) Update added in v0.3.0

func (pr *Progress) Update(outer Progress) (changed bool, err error)

type Stage added in v0.3.0

type Stage interface {
	StageProgress

	// Step tries to progress the state.
	// The outer stage progress informs the step what to do.
	//
	// If the stage:
	// - returns EOF: the stage will be skipped
	// - returns another error: the stage will make the pipeline error.
	// - returns nil: the stage will be repeated next Step
	Step(ctx context.Context, outer Progress) error

	// ResetStep prepares the state for usage in regular steps.
	// Similar to Step(ctx) it returns:
	// - EOF if the next stage should be reset
	// - error if the reset should start all over again
	// - nil if the reset should continue resetting this stage.
	ResetStep(ctx context.Context, l1Fetcher L1Fetcher) error
}

type StageProgress added in v0.3.0

type StageProgress interface {
	Progress() Progress
}

type UserDepositSource

type UserDepositSource struct {
	L1BlockHash common.Hash
	LogIndex    uint64
}

func (*UserDepositSource) SourceHash

func (dep *UserDepositSource) SourceHash() common.Hash

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL