Documentation ¶
Index ¶
- Constants
- Variables
- func CLIFlags(envPrefix string, category string) []cli.Flag
- func DecodeChallengeStatusEvent(log *types.Log) (*bindings.DataAvailabilityChallengeChallengeStatusChanged, error)
- func DecodeResolvedInput(data []byte) ([]byte, error)
- type AltDADisabled
- func (d *AltDADisabled) AdvanceL1Origin(ctx context.Context, l1 L1Fetcher, blockId eth.BlockID) error
- func (d *AltDADisabled) Finalize(ref eth.L1BlockRef)
- func (d *AltDADisabled) GetInput(ctx context.Context, l1 L1Fetcher, commitment CommitmentData, ...) (eth.Data, error)
- func (d *AltDADisabled) OnFinalizedHeadSignal(f HeadSignalFn)
- func (d *AltDADisabled) Reset(ctx context.Context, base eth.L1BlockRef, baseCfg eth.SystemConfig) error
- type CLIConfig
- type Challenge
- type ChallengeStatus
- type Commitment
- type CommitmentData
- type CommitmentType
- type Config
- type DA
- func (d *DA) AdvanceChallengeOrigin(ctx context.Context, l1 L1Fetcher, block eth.BlockID) error
- func (d *DA) AdvanceCommitmentOrigin(ctx context.Context, l1 L1Fetcher, block eth.BlockID) error
- func (d *DA) AdvanceL1Origin(ctx context.Context, l1 L1Fetcher, block eth.BlockID) error
- func (d *DA) Finalize(l1Finalized eth.L1BlockRef)
- func (d *DA) GetInput(ctx context.Context, l1 L1Fetcher, comm CommitmentData, blockId eth.L1BlockRef) (eth.Data, error)
- func (d *DA) LookAhead(ctx context.Context, l1 L1Fetcher) error
- func (d *DA) OnFinalizedHeadSignal(f HeadSignalFn)
- func (d *DA) Reset(ctx context.Context, base eth.L1BlockRef, baseCfg eth.SystemConfig) error
- type DAClient
- type DAErrFaker
- type DAServer
- type DAStorage
- type FakeDAServer
- func (s *FakeDAServer) HandleGet(w http.ResponseWriter, r *http.Request)
- func (s *FakeDAServer) HandlePut(w http.ResponseWriter, r *http.Request)
- func (s *FakeDAServer) SetGetRequestLatency(latency time.Duration)
- func (s *FakeDAServer) SetPutRequestLatency(latency time.Duration)
- func (s *FakeDAServer) Start() error
- type GenericCommitment
- type HeadSignalFn
- type KVStore
- type Keccak256Commitment
- type L1Fetcher
- type MemStore
- type Metricer
- type Metrics
- func (m *Metrics) RecordActiveChallenge(commBlock uint64, startBlock uint64, hash []byte)
- func (m *Metrics) RecordChallenge(status string)
- func (m *Metrics) RecordChallengesHead(name string, num uint64)
- func (m *Metrics) RecordExpiredChallenge(hash []byte)
- func (m *Metrics) RecordResolvedChallenge(hash []byte)
- func (m *Metrics) RecordStorageError()
- type MockDAClient
- type NoopMetrics
- func (m *NoopMetrics) RecordActiveChallenge(commBlock uint64, startBlock uint64, hash []byte)
- func (m *NoopMetrics) RecordChallengesHead(name string, num uint64)
- func (m *NoopMetrics) RecordExpiredChallenge(hash []byte)
- func (m *NoopMetrics) RecordResolvedChallenge(hash []byte)
- func (m *NoopMetrics) RecordStorageError()
- type State
- func (s *State) ClearCommitments()
- func (s *State) CreateChallenge(comm CommitmentData, inclusionBlock eth.BlockID, commBlockNumber uint64)
- func (s *State) ExpireChallenges(origin eth.BlockID)
- func (s *State) ExpireCommitments(origin eth.BlockID) error
- func (s *State) GetChallenge(comm CommitmentData, commBlockNumber uint64) (*Challenge, bool)
- func (s *State) GetChallengeStatus(comm CommitmentData, commBlockNumber uint64) ChallengeStatus
- func (s *State) NoCommitments() bool
- func (s *State) Prune(origin eth.BlockID)
- func (s *State) Reset()
- func (s *State) ResolveChallenge(comm CommitmentData, inclusionBlock eth.BlockID, commBlockNumber uint64, ...) error
- func (s *State) TrackCommitment(comm CommitmentData, inclusionBlock eth.L1BlockRef)
Constants ¶
const ( Keccak256CommitmentType CommitmentType = 0 GenericCommitmentType CommitmentType = 1 KeccakCommitmentString string = "KeccakCommitment" GenericCommitmentString string = "GenericCommitment" )
CommitmentType describes the binary format of the commitment. KeccakCommitmentType is the default commitment type for the centralized DA storage. GenericCommitmentType indicates an opaque bytestring that the op-node never opens.
const MaxInputSize = 130672
MaxInputSize ensures the canonical chain cannot include input batches too large to challenge in the Data Availability Challenge contract. Value in number of bytes. This value can only be changed in a hard fork.
const TxDataVersion1 = 1
TxDataVersion1 is the version number for batcher transactions containing altDA commitments. It should not collide with DerivationVersion which is still used downstream when parsing the frames.
Variables ¶
var ( EnabledFlagName = altDAFlags("enabled") DaServerAddressFlagName = altDAFlags("da-server") VerifyOnReadFlagName = altDAFlags("verify-on-read") DaServiceFlagName = altDAFlags("da-service") PutTimeoutFlagName = altDAFlags("put-timeout") GetTimeoutFlagName = altDAFlags("get-timeout") MaxConcurrentRequestsFlagName = altDAFlags("max-concurrent-da-requests") )
var ( ChallengeStatusEventName = "ChallengeStatusChanged" ChallengeStatusEventABI = "ChallengeStatusChanged(uint256,bytes,uint8)" ChallengeStatusEventABIHash = crypto.Keccak256Hash([]byte(ChallengeStatusEventABI)) )
var Disabled = &AltDADisabled{}
var ErrCommitmentMismatch = errors.New("commitment mismatch")
ErrCommitmentMismatch is returned when the commitment does not match the given input.
var ErrExpiredChallenge = errors.New("challenge expired")
ErrExpiredChallenge is returned when a challenge was not resolved and derivation should skip this input.
var ErrInvalidChallenge = errors.New("invalid challenge")
ErrInvalidChallenge is returned when a challenge event does is decoded but does not relate to the actual chain commitments.
var ErrInvalidCommitment = errors.New("invalid commitment")
ErrInvalidCommitment is returned when the commitment cannot be parsed into a known commitment type.
var ErrInvalidInput = errors.New("invalid input")
ErrInvalidInput is returned when the input is not valid for posting to the DA storage.
var ErrMissingPastWindow = errors.New("data missing past window")
ErrMissingPastWindow is returned when the input data is MIA and cannot be challenged. This is a protocol fatal error.
var ErrNotEnabled = errors.New("altDA not enabled")
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when the server could not find the input.
var ErrPendingChallenge = errors.New("not found, pending challenge")
ErrPendingChallenge is returned when data is not available but can still be challenged/resolved so derivation should halt temporarily.
var ErrReorgRequired = errors.New("reorg required")
ErrReorgRequired is returned when a commitment was derived but for which the challenge expired. This requires a reorg to rederive without the input even if the input was previously available.
Functions ¶
func DecodeChallengeStatusEvent ¶
func DecodeChallengeStatusEvent(log *types.Log) (*bindings.DataAvailabilityChallengeChallengeStatusChanged, error)
DecodeChallengeStatusEvent decodes the challenge status event from the log data and the indexed challenged hash and block number from the topics.
func DecodeResolvedInput ¶
DecodeResolvedInput decodes the preimage bytes from the tx input data.
Types ¶
type AltDADisabled ¶
type AltDADisabled struct{}
AltDADisabled is a noop AltDA implementation for stubbing.
func (*AltDADisabled) AdvanceL1Origin ¶
func (*AltDADisabled) Finalize ¶
func (d *AltDADisabled) Finalize(ref eth.L1BlockRef)
func (*AltDADisabled) GetInput ¶
func (d *AltDADisabled) GetInput(ctx context.Context, l1 L1Fetcher, commitment CommitmentData, blockId eth.L1BlockRef) (eth.Data, error)
func (*AltDADisabled) OnFinalizedHeadSignal ¶
func (d *AltDADisabled) OnFinalizedHeadSignal(f HeadSignalFn)
func (*AltDADisabled) Reset ¶
func (d *AltDADisabled) Reset(ctx context.Context, base eth.L1BlockRef, baseCfg eth.SystemConfig) error
type CLIConfig ¶
type CLIConfig struct { Enabled bool DAServerURL string VerifyOnRead bool GenericDA bool PutTimeout time.Duration GetTimeout time.Duration MaxConcurrentRequests uint64 }
func ReadCLIConfig ¶
func ReadCLIConfig(c *cli.Context) CLIConfig
func (CLIConfig) NewDAClient ¶
type Challenge ¶
type Challenge struct {
// contains filtered or unexported fields
}
Challenges are used to track the status of a challenge against a commitment.
type ChallengeStatus ¶
type ChallengeStatus uint8
const ( ChallengeUninitialized ChallengeStatus = iota ChallengeActive ChallengeResolved ChallengeExpired )
type Commitment ¶
type Commitment struct {
// contains filtered or unexported fields
}
Commitment keeps track of the onchain state of an input commitment.
type CommitmentData ¶
type CommitmentData interface { CommitmentType() CommitmentType Encode() []byte TxData() []byte Verify(input []byte) error String() string }
CommitmentData is the binary representation of a commitment.
func DecodeCommitmentData ¶
func DecodeCommitmentData(input []byte) (CommitmentData, error)
DecodeCommitmentData parses the commitment into a known commitment type. The input type is determined by the first byte of the raw data. The input type is discarded and the commitment is passed to the appropriate constructor.
func NewCommitmentData ¶
func NewCommitmentData(t CommitmentType, input []byte) CommitmentData
NewCommitmentData creates a new commitment from the given input and desired type.
type CommitmentType ¶
type CommitmentType byte
CommitmentType is the commitment type prefix.
func CommitmentTypeFromString ¶
func CommitmentTypeFromString(s string) (CommitmentType, error)
type Config ¶
type Config struct { // Required for filtering contract events DAChallengeContractAddress common.Address // Allowed CommitmentType CommitmentType CommitmentType // The number of l1 blocks after the input is committed during which one can challenge. ChallengeWindow uint64 // The number of l1 blocks after a commitment is challenged during which one can resolve. ResolveWindow uint64 }
Config is the relevant subset of rollup config for AltDA.
type DA ¶
type DA struct {
// contains filtered or unexported fields
}
func NewAltDAWithState ¶
func NewAltDAWithState(log log.Logger, cfg Config, storage DAStorage, metrics Metricer, state *State) *DA
NewAltDAWithState creates an AltDA storage from initial state used for testing in isolation. We pass the L1Fetcher to each method so it is kept in sync with the conf depth of the pipeline.
func NewAltDAWithStorage ¶
NewAltDAWithStorage creates a new AltDA instance with the given log and DAStorage interface.
func (*DA) AdvanceChallengeOrigin ¶
AdvanceChallengeOrigin reads & stores challenge events for the given L1 block
func (*DA) AdvanceCommitmentOrigin ¶
AdvanceCommitmentOrigin updates the commitment origin and the finalized head.
func (*DA) AdvanceL1Origin ¶
AdvanceL1Origin syncs any challenge events included in the l1 block, expires any active challenges after the new resolveWindow, computes and signals the new finalized head and sets the l1 block as the new head for tracking challenges and commitments. If forwards an error if any new challenge have expired to trigger a derivation reset.
func (*DA) Finalize ¶
func (d *DA) Finalize(l1Finalized eth.L1BlockRef)
Finalize sets the L1 finalized head signal and calls the handler function if set.
func (*DA) GetInput ¶
func (d *DA) GetInput(ctx context.Context, l1 L1Fetcher, comm CommitmentData, blockId eth.L1BlockRef) (eth.Data, error)
GetInput returns the input data for the given commitment bytes. blockNumber is required to lookup the challenge status in the DataAvailabilityChallenge L1 contract.
func (*DA) LookAhead ¶
LookAhead increments the challenges origin and process the new block if it exists. It is used when the derivation pipeline stalls due to missing data and we need to continue syncing challenge events until the challenge is resolved or expires.
func (*DA) OnFinalizedHeadSignal ¶
func (d *DA) OnFinalizedHeadSignal(f HeadSignalFn)
OnFinalizedHeadSignal sets the callback function to be called when the finalized head is updated. This will signal to the engine queue that will set the proper L2 block as finalized.
func (*DA) Reset ¶
func (d *DA) Reset(ctx context.Context, base eth.L1BlockRef, baseCfg eth.SystemConfig) error
Reset the challenge event derivation origin in case of L1 reorg
type DAClient ¶
type DAClient struct {
// contains filtered or unexported fields
}
DAClient is an HTTP client to communicate with a DA storage service. It creates commitments and retrieves input data + verifies if needed.
type DAErrFaker ¶
type DAErrFaker struct { Client *MockDAClient // contains filtered or unexported fields }
func (*DAErrFaker) ActGetPreImageFail ¶
func (f *DAErrFaker) ActGetPreImageFail()
func (*DAErrFaker) ActSetPreImageFail ¶
func (f *DAErrFaker) ActSetPreImageFail()
func (*DAErrFaker) GetInput ¶
func (f *DAErrFaker) GetInput(ctx context.Context, key CommitmentData) ([]byte, error)
func (*DAErrFaker) SetInput ¶
func (f *DAErrFaker) SetInput(ctx context.Context, data []byte) (CommitmentData, error)
type DAServer ¶
type DAServer struct {
// contains filtered or unexported fields
}
func NewDAServer ¶
func (*DAServer) HttpEndpoint ¶ added in v1.9.3
type DAStorage ¶
type DAStorage interface { GetInput(ctx context.Context, key CommitmentData) ([]byte, error) SetInput(ctx context.Context, img []byte) (CommitmentData, error) }
DAStorage interface for calling the DA storage server.
type FakeDAServer ¶ added in v1.9.3
type FakeDAServer struct { *DAServer // contains filtered or unexported fields }
FakeDAServer is a fake DA server for e2e tests. It is a small wrapper around DAServer that allows for setting request latencies, to mimic a DA service with slow responses (eg. eigenDA with 10 min batching interval).
func NewFakeDAServer ¶ added in v1.9.3
func NewFakeDAServer(host string, port int, log log.Logger) *FakeDAServer
func (*FakeDAServer) HandleGet ¶ added in v1.9.3
func (s *FakeDAServer) HandleGet(w http.ResponseWriter, r *http.Request)
func (*FakeDAServer) HandlePut ¶ added in v1.9.3
func (s *FakeDAServer) HandlePut(w http.ResponseWriter, r *http.Request)
func (*FakeDAServer) SetGetRequestLatency ¶ added in v1.9.3
func (s *FakeDAServer) SetGetRequestLatency(latency time.Duration)
func (*FakeDAServer) SetPutRequestLatency ¶ added in v1.9.3
func (s *FakeDAServer) SetPutRequestLatency(latency time.Duration)
func (*FakeDAServer) Start ¶ added in v1.9.3
func (s *FakeDAServer) Start() error
type GenericCommitment ¶
type GenericCommitment []byte
GenericCommitment is an implementation of CommitmentData that treats the commitment as an opaque bytestring.
func DecodeGenericCommitment ¶
func DecodeGenericCommitment(commitment []byte) (GenericCommitment, error)
DecodeGenericCommitment validates and casts the commitment into a GenericCommitment.
func NewGenericCommitment ¶
func NewGenericCommitment(input []byte) GenericCommitment
NewGenericCommitment creates a new commitment from the given input.
func (GenericCommitment) CommitmentType ¶
func (c GenericCommitment) CommitmentType() CommitmentType
CommitmentType returns the commitment type of Generic Commitment.
func (GenericCommitment) Encode ¶
func (c GenericCommitment) Encode() []byte
Encode adds a commitment type prefix self describing the commitment.
func (GenericCommitment) String ¶
func (c GenericCommitment) String() string
func (GenericCommitment) TxData ¶
func (c GenericCommitment) TxData() []byte
TxData adds an extra version byte to signal it's a commitment.
func (GenericCommitment) Verify ¶
func (c GenericCommitment) Verify(input []byte) error
Verify always returns true for GenericCommitment because the DA Server must validate the data before returning it to the op-node.
type HeadSignalFn ¶
type HeadSignalFn func(eth.L1BlockRef)
HeadSignalFn is the callback function to accept head-signals without a context.
type Keccak256Commitment ¶
type Keccak256Commitment []byte
Keccak256Commitment is an implementation of CommitmentData that uses Keccak256 as the commitment function.
func DecodeKeccak256 ¶
func DecodeKeccak256(commitment []byte) (Keccak256Commitment, error)
DecodeKeccak256 validates and casts the commitment into a Keccak256Commitment.
func NewKeccak256Commitment ¶
func NewKeccak256Commitment(input []byte) Keccak256Commitment
NewKeccak256Commitment creates a new commitment from the given input.
func (Keccak256Commitment) CommitmentType ¶
func (c Keccak256Commitment) CommitmentType() CommitmentType
CommitmentType returns the commitment type of Keccak256.
func (Keccak256Commitment) Encode ¶
func (c Keccak256Commitment) Encode() []byte
Encode adds a commitment type prefix that describes the commitment.
func (Keccak256Commitment) String ¶
func (c Keccak256Commitment) String() string
func (Keccak256Commitment) TxData ¶
func (c Keccak256Commitment) TxData() []byte
TxData adds an extra version byte to signal it's a commitment.
func (Keccak256Commitment) Verify ¶
func (c Keccak256Commitment) Verify(input []byte) error
Verify checks if the commitment matches the given input.
type L1Fetcher ¶
type L1Fetcher interface { InfoAndTxsByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, types.Transactions, error) FetchReceipts(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, types.Receipts, error) L1BlockRefByNumber(context.Context, uint64) (eth.L1BlockRef, error) }
L1Fetcher is the required interface for syncing the DA challenge contract state.
type MemStore ¶ added in v1.9.3
type MemStore struct {
// contains filtered or unexported fields
}
func NewMemStore ¶ added in v1.9.3
func NewMemStore() *MemStore
type Metrics ¶
type Metrics struct { ChallengesStatus *prometheus.GaugeVec ChallengesHead *prometheus.GaugeVec StorageErrors *metrics.Event }
func (*Metrics) RecordActiveChallenge ¶
RecordActiveChallenge records when a commitment is challenged including the block where the commitment is included, the block where the commitment was challenged and the commitment hash.
func (*Metrics) RecordChallenge ¶
func (*Metrics) RecordChallengesHead ¶
func (*Metrics) RecordExpiredChallenge ¶
func (*Metrics) RecordResolvedChallenge ¶
func (*Metrics) RecordStorageError ¶
func (m *Metrics) RecordStorageError()
type MockDAClient ¶
type MockDAClient struct { CommitmentType CommitmentType // contains filtered or unexported fields }
MockDAClient mocks a DA storage provider to avoid running an HTTP DA server in unit tests.
func NewMockDAClient ¶
func NewMockDAClient(log log.Logger) *MockDAClient
func (*MockDAClient) DeleteData ¶
func (c *MockDAClient) DeleteData(key []byte) error
func (*MockDAClient) GetInput ¶
func (c *MockDAClient) GetInput(ctx context.Context, key CommitmentData) ([]byte, error)
func (*MockDAClient) SetInput ¶
func (c *MockDAClient) SetInput(ctx context.Context, data []byte) (CommitmentData, error)
type NoopMetrics ¶
type NoopMetrics struct{}
func (*NoopMetrics) RecordActiveChallenge ¶
func (m *NoopMetrics) RecordActiveChallenge(commBlock uint64, startBlock uint64, hash []byte)
func (*NoopMetrics) RecordChallengesHead ¶
func (m *NoopMetrics) RecordChallengesHead(name string, num uint64)
func (*NoopMetrics) RecordExpiredChallenge ¶
func (m *NoopMetrics) RecordExpiredChallenge(hash []byte)
func (*NoopMetrics) RecordResolvedChallenge ¶
func (m *NoopMetrics) RecordResolvedChallenge(hash []byte)
func (*NoopMetrics) RecordStorageError ¶
func (m *NoopMetrics) RecordStorageError()
type State ¶
type State struct {
// contains filtered or unexported fields
}
State tracks the commitment and their challenges in order of l1 inclusion. Commitments and Challenges are tracked in L1 inclusion order. They are tracked in two separate queues for Active and Expired commitments. When commitments are moved to Expired, if there is an active challenge, the DA Manager is informed that a commitment became invalid. Challenges and Commitments can be pruned when they are beyond a certain block number (e.g. when they are finalized). In the special case of a L2 reorg, challenges are still tracked but commitments are removed. This will allow the altDA fetcher to find the expired challenge.
func (*State) ClearCommitments ¶
func (s *State) ClearCommitments()
ClearCommitments removes all tracked commitments but not challenges. This should be used to retain the challenge state when performing a L2 reorg
func (*State) CreateChallenge ¶
func (s *State) CreateChallenge(comm CommitmentData, inclusionBlock eth.BlockID, commBlockNumber uint64)
CreateChallenge creates & tracks a challenge. It will overwrite earlier challenges if the same commitment is challenged again.
func (*State) ExpireChallenges ¶
ExpireChallenges moves challenges from the active state map to the expired state map. challenges are considered expired when the origin is beyond the challenge's resolve window. This function processes challenges in order of inclusion until it finds a commitment which has not expired. This function must be called for every block because there is no contract event to expire challenges.
func (*State) ExpireCommitments ¶
ExpireCommitments moves commitments from the active state map to the expired state map. commitments are considered expired when the challenge window ends without a challenge, or when the resolve window ends without a resolution to the challenge. This function processes commitments in order of inclusion until it finds a commitment which has not expired. If a commitment expires which did not resolve its challenge, it returns ErrReorgRequired to indicate that a L2 reorg should be performed.
func (*State) GetChallenge ¶
func (s *State) GetChallenge(comm CommitmentData, commBlockNumber uint64) (*Challenge, bool)
GetChallenge looks up a challenge against commitment + inclusion block.
func (*State) GetChallengeStatus ¶
func (s *State) GetChallengeStatus(comm CommitmentData, commBlockNumber uint64) ChallengeStatus
GetChallengeStatus looks up a challenge's status, or returns ChallengeUninitialized if there is no challenge.
func (*State) NoCommitments ¶
NoCommitments returns true iff it is not tracking any commitments or challenges.
func (*State) Prune ¶
Prune removes challenges & commitments which have an expiry block number beyond the given block number.
func (*State) Reset ¶
func (s *State) Reset()
Reset clears the state. It should be used when a L1 reorg occurs.
func (*State) ResolveChallenge ¶
func (s *State) ResolveChallenge(comm CommitmentData, inclusionBlock eth.BlockID, commBlockNumber uint64, input []byte) error
ResolveChallenge marks a challenge as resolved. It will return an error if there was not a corresponding challenge.
func (*State) TrackCommitment ¶
func (s *State) TrackCommitment(comm CommitmentData, inclusionBlock eth.L1BlockRef)
TrackCommitment stores a commitment in the State