rollup

package
v0.0.0-...-5cda5f8 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: GPL-3.0, MIT Imports: 30 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BVMContext

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

BVMContext represents the blocknumber and timestamp that exist during L2 execution

type Backend

type Backend uint

Backend represents the type of transactions that are being synced. The different types have different security models.

const (
	// BackendL1 Backend involves syncing transactions that have been batched to
	// Layer One. Once the transactions have been batched to L1, they cannot be
	// removed assuming that they are not reorganized out of the chain.
	BackendL1 Backend = iota
	// BackendL2 Backend involves syncing transactions from the sequencer,
	// meaning that the transactions may have not been batched to Layer One yet.
	// This gives higher latency access to the sequencer data but no guarantees
	// around the transactions as they have not been submitted via a batch to
	// L1.
	BackendL2
	//Eigen
	BackendEigen
)

func NewBackend

func NewBackend(typ string) (Backend, error)

NewBackend creates a Backend from a human readable string

func (Backend) String

func (s Backend) String() string

String implements the Stringer interface

type Batch

type Batch struct {
	Index             uint64         `json:"index"`
	Root              common.Hash    `json:"root,omitempty"`
	Size              uint32         `json:"size,omitempty"`
	PrevTotalElements uint32         `json:"prevTotalElements,omitempty"`
	ExtraData         hexutil.Bytes  `json:"extraData,omitempty"`
	BlockNumber       uint64         `json:"blockNumber"`
	Timestamp         uint64         `json:"timestamp"`
	Submitter         common.Address `json:"submitter"`
}

Batch represents the data structure that is submitted with a series of transactions to layer one

type Client

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

Client is an HTTP based RollupClient

func NewClient

func NewClient(url string, chainID *big.Int) *Client

NewClient create a new Client given a remote HTTP url and a chain id

func (*Client) GetEnqueue

func (c *Client) GetEnqueue(index uint64) (*types.Transaction, error)

GetEnqueue fetches an `enqueue` transaction by queue index

func (*Client) GetEthContext

func (c *Client) GetEthContext(blockNumber uint64) (*EthContext, error)

GetEthContext will return the EthContext by block number

func (*Client) GetLastConfirmedEnqueue

func (c *Client) GetLastConfirmedEnqueue() (*types.Transaction, error)

GetLastConfirmedEnqueue will get the last `enqueue` transaction that has been batched up

func (*Client) GetLatestEnqueue

func (c *Client) GetLatestEnqueue() (*types.Transaction, error)

GetLatestEnqueue fetches the latest `enqueue`, meaning the `enqueue` transaction with the greatest queue index.

func (*Client) GetLatestEnqueueIndex

func (c *Client) GetLatestEnqueueIndex() (*uint64, error)

GetLatestEnqueueIndex returns the latest `enqueue()` index

func (*Client) GetLatestEthContext

func (c *Client) GetLatestEthContext() (*EthContext, error)

GetLatestEthContext will return the latest EthContext

func (*Client) GetLatestTransaction

func (c *Client) GetLatestTransaction(backend Backend) (*types.Transaction, error)

GetLatestTransaction will get the latest transaction, meaning the transaction with the greatest Canonical Transaction Chain index

func (*Client) GetLatestTransactionBatch

func (c *Client) GetLatestTransactionBatch() (*Batch, []*types.Transaction, error)

GetLatestTransactionBatch will return the latest transaction batch

func (*Client) GetLatestTransactionBatchIndex

func (c *Client) GetLatestTransactionBatchIndex() (*uint64, error)

GetLatestTransactionBatchIndex returns the latest transaction batch index

func (*Client) GetLatestTransactionIndex

func (c *Client) GetLatestTransactionIndex(backend Backend) (*uint64, error)

GetLatestTransactionIndex returns the latest CTC index that has been batch submitted or not, depending on the backend

func (*Client) GetRawTransaction

func (c *Client) GetRawTransaction(index uint64, backend Backend) (*TransactionResponse, error)

GetTransaction will get a transaction by Canonical Transaction Chain index

func (*Client) GetStateRoot

func (c *Client) GetStateRoot(index uint64, backend Backend) (*StateRoot, error)

func (*Client) GetTransaction

func (c *Client) GetTransaction(index uint64, backend Backend) (*types.Transaction, error)

GetTransaction will get a transaction by Canonical Transaction Chain index

func (*Client) GetTransactionBatch

func (c *Client) GetTransactionBatch(index uint64) (*Batch, []*types.Transaction, error)

GetTransactionBatch will return the transaction batch by batch index

func (*Client) GetTxStatusResponse

func (c *Client) GetTxStatusResponse(index uint64, backend Backend) (*types.TxStatusResponse, error)

func (*Client) SyncStatus

func (c *Client) SyncStatus(backend Backend) (*SyncStatus, error)

SyncStatus will query the remote server to determine if it is still syncing

type Config

type Config struct {
	// Maximum calldata size for a Queue Origin Sequencer Tx
	MaxCallDataSize int
	// Verifier mode
	IsVerifier bool
	// Enable the sync service
	Eth1SyncServiceEnable bool
	// Gas Limit
	GasLimit uint64
	// HTTP endpoint of the data transport layer
	RollupClientHttp string

	// // HTTP endpoint of the eigen client
	EigenClientHttp string

	L1MsgSender string

	DtlEigenEnable bool

	// Owner of the GasPriceOracle contract
	GasPriceOracleOwnerAddress common.Address
	// Turns on checking of state for L2 gas price
	EnableL2GasPolling bool
	// Deployment Height of the canonical transaction chain
	CanonicalTransactionChainDeployHeight *big.Int
	// Polling interval for rollup client
	PollInterval time.Duration
	// Interval for updating the timestamp
	TimestampRefreshThreshold time.Duration
	// Represents the source of the transactions that is being synced
	Backend Backend
	// Only accept transactions with fees
	EnforceFees bool
	// Allow fees within a buffer upwards or downwards
	// to take fee volatility into account between being
	// quoted and the transaction being executed
	FeeThresholdDown *big.Float
	FeeThresholdUp   *big.Float
	// HTTP endpoint of the sequencer
	SequencerClientHttp string
	// stake amount
	StakeAmount *big.Int
	// node character
	RollupRole Role

	MpcVerifier bool
}

type DataStore

type DataStore struct {
	Index              uint64 `json:"index"`
	UpgradeDataStoreId uint32 `json:"upgrade_data_store_id"`
	DataStoreId        uint32 `json:"data_store_id"`
	Status             uint8  `json:"status"`
	ConfirmAt          uint32 `json:"confirm_at"`
}

type DataStoreId

type DataStoreId struct {
	BatchIndex          uint64    `json:"batchIndex"`
	BatchIndexDataStore DataStore `json:"dataStore"`
}

type DtlClient

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

func NewDtlEigenClient

func NewDtlEigenClient(url string, chainID *big.Int) *DtlClient

func (*DtlClient) GetDtlBatchTransactionByDataStoreId

func (dc *DtlClient) GetDtlBatchTransactionByDataStoreId(storeNumber uint32) ([]*types.Transaction, error)

func (*DtlClient) GetDtlLatestBatchIndex

func (dc *DtlClient) GetDtlLatestBatchIndex() (batchIndex *uint64, err error)

func (*DtlClient) GetDtlRollupStoreByBatchIndex

func (dc *DtlClient) GetDtlRollupStoreByBatchIndex(batchIndex int64) (*StoreResponse, error)

type DtlEigenClient

type DtlEigenClient interface {
	GetDtlLatestBatchIndex() (*uint64, error)
	GetDtlRollupStoreByBatchIndex(batchIndex int64) (*StoreResponse, error)
	GetDtlBatchTransactionByDataStoreId(storeNumber uint32) ([]*types.Transaction, error)
}

type Enqueue

type Enqueue struct {
	Index       *uint64         `json:"ctcIndex"`
	Target      *common.Address `json:"target"`
	Data        *hexutil.Bytes  `json:"data"`
	GasLimit    *uint64         `json:"gasLimit,string"`
	Origin      *common.Address `json:"origin"`
	BlockNumber *uint64         `json:"blockNumber"`
	Timestamp   *uint64         `json:"timestamp"`
	QueueIndex  *uint64         `json:"index"`
}

Enqueue represents an `enqueue` transaction or a L1 to L2 transaction.

type EthContext

type EthContext struct {
	BlockNumber uint64      `json:"blockNumber"`
	BlockHash   common.Hash `json:"blockHash"`
	Timestamp   uint64      `json:"timestamp"`
}

EthContext represents the L1 EVM context that is injected into the BVM at runtime. It is updated with each `enqueue` transaction and needs to be fetched from a remote server to be updated when too much time has passed between `enqueue` transactions.

type L1GasPrice

type L1GasPrice struct {
	GasPrice string `json:"gasPrice"`
}

L1GasPrice represents the gas price of L1. It is used as part of the gas estimatation logic.

type Role

type Role uint8
const (
	SCHEDULER_NODE Role = 0
	SEQUENCER_NODE Role = 1
	VERIFIER_NODE  Role = 2
)

type RollupBatchIndex

type RollupBatchIndex struct {
	BatchIndex uint64 `json:"batchIndex"`
}

type RollupClient

type RollupClient interface {
	GetEnqueue(index uint64) (*types.Transaction, error)
	GetLatestEnqueue() (*types.Transaction, error)
	GetLatestEnqueueIndex() (*uint64, error)
	GetRawTransaction(uint64, Backend) (*TransactionResponse, error)
	GetTransaction(uint64, Backend) (*types.Transaction, error)
	GetLatestTransaction(Backend) (*types.Transaction, error)
	GetLatestTransactionIndex(Backend) (*uint64, error)
	GetStateRoot(uint64, Backend) (*StateRoot, error)
	GetTxStatusResponse(uint64, Backend) (*types.TxStatusResponse, error)
	GetEthContext(uint64) (*EthContext, error)
	GetLatestEthContext() (*EthContext, error)
	GetLastConfirmedEnqueue() (*types.Transaction, error)
	GetLatestTransactionBatch() (*Batch, []*types.Transaction, error)
	GetLatestTransactionBatchIndex() (*uint64, error)
	GetTransactionBatch(uint64) (*Batch, []*types.Transaction, error)
	SyncStatus(Backend) (*SyncStatus, error)
}

RollupClient is able to query for information that is required by the SyncService

type StateRoot

type StateRoot struct {
	Index      uint64 `json:"index"`
	BatchIndex uint64 `json:"batchIndex"`
	Value      string `json:"value"`
}

stateroot represents the return result of the remote server. it came from a batch or was replicated from the sequencer.

type StateRootResponse

type StateRootResponse struct {
	StateRoot *StateRoot `json:"stateRoot"`
	Batch     *Batch     `json:"batch"`
}

StateRootResponse represents the response from the remote server when querying stateroot

type StoreResponse

type StoreResponse struct {
	UpgradeDataStoreId uint32 `json:"upgrade_data_store_id"`
	OriginDataStoreId  uint32 `json:"origin_data_store_id"`
	DataStoreId        uint32 `json:"data_store_id"`
	ConfirmAt          uint32 `json:"confirm_at"`
	Status             uint8  `json:"status"`
}

type SyncService

type SyncService struct {
	RollupGpo *gasprice.RollupOracle

	BVMContext BVMContext
	// contains filtered or unexported fields
}

SyncService implements the main functionality around pulling in transactions and executing them. It can be configured to run in both sequencer mode and in verifier mode.

func NewSyncService

func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *core.BlockChain, db ethdb.Database, gasFloor uint64, chainConfig *params.ChainConfig, engine consensus.Engine) (*SyncService, error)

NewSyncService returns an initialized sync service

func (*SyncService) GasPriceOracleOwnerAddress

func (s *SyncService) GasPriceOracleOwnerAddress() *common.Address

A thread safe getter for the gas price oracle owner address

func (*SyncService) GetEigenNextBatchIndex

func (s *SyncService) GetEigenNextBatchIndex() uint64

func (*SyncService) GetLatestBatchIndex

func (s *SyncService) GetLatestBatchIndex() *uint64

GetLatestBatchIndex reads the last processed transaction batch

func (*SyncService) GetLatestEigenBatchIndex

func (s *SyncService) GetLatestEigenBatchIndex() *uint64

func (*SyncService) GetLatestEnqueueIndex

func (s *SyncService) GetLatestEnqueueIndex() *uint64

GetLatestEnqueueIndex reads the last queue index processed

func (*SyncService) GetLatestIndex

func (s *SyncService) GetLatestIndex() *uint64

GetLatestIndex reads the last CTC index that was processed

func (*SyncService) GetLatestL1BlockNumber

func (s *SyncService) GetLatestL1BlockNumber() uint64

GetLatestL1BlockNumber returns the BVMContext blocknumber

func (*SyncService) GetLatestL1Timestamp

func (s *SyncService) GetLatestL1Timestamp() uint64

GetLatestL1Timestamp returns the BVMContext timestamp

func (*SyncService) GetLatestVerifiedIndex

func (s *SyncService) GetLatestVerifiedIndex() *uint64

GetLatestVerifiedIndex reads the last verified CTC index that was processed These are set by processing batches of transactions that were submitted to the Canonical Transaction Chain.

func (*SyncService) GetNextBatchIndex

func (s *SyncService) GetNextBatchIndex() uint64

GetNextBatchIndex reads the index of the next transaction batch to process

func (*SyncService) GetNextEnqueueIndex

func (s *SyncService) GetNextEnqueueIndex() uint64

GetNextEnqueueIndex returns the next queue index to process

func (*SyncService) GetNextIndex

func (s *SyncService) GetNextIndex() uint64

GetNextIndex reads the next CTC index to process

func (*SyncService) GetNextVerifiedIndex

func (s *SyncService) GetNextVerifiedIndex() uint64

GetNextVerifiedIndex reads the next verified index

func (*SyncService) GetTxStatusByNumber

func (s *SyncService) GetTxStatusByNumber(number uint64) (*types.TxStatusResponse, error)

func (*SyncService) IngestTransaction

func (s *SyncService) IngestTransaction(tx *types.Transaction) error

IngestTransaction should only be called by trusted parties as it skips all validation and applies the transaction

func (*SyncService) IsSyncing

func (s *SyncService) IsSyncing() bool

IsSyncing returns the syncing status of the syncservice. Returns false if not yet set.

func (*SyncService) SchedulerRollback

func (s *SyncService) SchedulerRollback(start uint64) error

func (*SyncService) SequencerLoop

func (s *SyncService) SequencerLoop()

SequencerLoop is the polling loop that runs in sequencer mode. It sequences transactions and then updates the EthContext.

func (*SyncService) SequencerRollback

func (s *SyncService) SequencerRollback() error

func (*SyncService) SetExtra

func (s *SyncService) SetExtra(extra []byte) error

func (*SyncService) SetHead

func (s *SyncService) SetHead(number uint64) error

func (*SyncService) SetLatestBatchIndex

func (s *SyncService) SetLatestBatchIndex(index *uint64)

SetLatestBatchIndex writes the last index of the transaction batch that was processed

func (*SyncService) SetLatestEigenBatchIndex

func (s *SyncService) SetLatestEigenBatchIndex(index *uint64)

func (*SyncService) SetLatestEnqueueIndex

func (s *SyncService) SetLatestEnqueueIndex(index *uint64)

SetLatestEnqueueIndex writes the last queue index that was processed

func (*SyncService) SetLatestIndex

func (s *SyncService) SetLatestIndex(index *uint64)

SetLatestIndex writes the last CTC index that was processed

func (*SyncService) SetLatestL1BlockNumber

func (s *SyncService) SetLatestL1BlockNumber(bn uint64)

SetLatestL1BlockNumber will set the BVMContext blocknumber

func (*SyncService) SetLatestL1Timestamp

func (s *SyncService) SetLatestL1Timestamp(ts uint64)

SetLatestL1Timestamp will set the BVMContext timestamp

func (*SyncService) SetLatestVerifiedIndex

func (s *SyncService) SetLatestVerifiedIndex(index *uint64)

SetLatestVerifiedIndex writes the last verified index that was processed

func (*SyncService) Start

func (s *SyncService) Start() error

Start initializes the service

func (*SyncService) Stop

func (s *SyncService) Stop() error

Stop will close the open channels and cancel the goroutines started by this service.

func (*SyncService) SubscribeNewTxsEvent

func (s *SyncService) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription

SubscribeNewTxsEvent registers a subscription of NewTxsEvent and starts sending event to the given channel.

func (*SyncService) ValidateAndApplySequencerTransaction

func (s *SyncService) ValidateAndApplySequencerTransaction(tx *types.Transaction) error

Higher level API for applying transactions. Should only be called for queue origin sequencer transactions, as the contracts on L1 manage the same validity checks that are done here.

func (*SyncService) VerifierLoop

func (s *SyncService) VerifierLoop()

VerifierLoop is the main loop for Verifier mode

type SyncStatus

type SyncStatus struct {
	Syncing                      bool   `json:"syncing"`
	HighestKnownTransactionIndex uint64 `json:"highestKnownTransactionIndex"`
	CurrentTransactionIndex      uint64 `json:"currentTransactionIndex"`
}

SyncStatus represents the state of the remote server. The SyncService does not want to begin syncing until the remote server has fully synced.

type TransactionBatchResponse

type TransactionBatchResponse struct {
	Batch        *Batch         `json:"batch"`
	Transactions []*transaction `json:"transactions"`
}

TransactionBatchResponse represents the response from the remote server when querying batches.

type TransactionBatchResponseV2

type TransactionBatchResponseV2 struct {
	DsId         uint64        `json:"dsId"`
	Transactions []transaction `json:"batchTx"`
}

type TransactionResponse

type TransactionResponse struct {
	Transaction *transaction `json:"transaction"`
	Batch       *Batch       `json:"batch"`
}

TransactionResponse represents the response from the remote server when querying transactions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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