rollup

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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
)

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) GetL1GasPrice

func (c *Client) GetL1GasPrice() (*big.Int, error)

GetL1GasPrice will return the current gas price on L1

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) 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) 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
	// Ensure that the correct layer 1 chain is being connected to
	Eth1ChainId uint64
	// Gas Limit
	GasLimit uint64
	// HTTP endpoint of the data transport layer
	RollupClientHttp              string
	L1CrossDomainMessengerAddress common.Address
	AddressManagerOwnerAddress    common.Address
	L1ETHGatewayAddress           common.Address
	GasPriceOracleAddress         common.Address
	// Turns on checking of state for L2 gas price
	EnableL2GasPolling bool
	// Deployment Height of the canonical transaction chain
	CanonicalTransactionChainDeployHeight *big.Int
	// Path to the state dump
	StateDumpPath string
	// Polling interval for rollup client
	PollInterval time.Duration
	// Interval for updating the timestamp
	TimestampRefreshThreshold time.Duration
	// The gas price to use when estimating L1 calldata publishing costs
	DataPrice *big.Int
	// The gas price to use for L2 congestion costs
	ExecutionPrice *big.Int
	// Represents the source of the transactions that is being synced
	Backend Backend
	// Only accept transactions with fees
	EnforceFees bool
}

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 OVM 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 OVMContext

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

OVMContext represents the blocknumber and timestamp that exist during L2 execution

type RollupClient

type RollupClient interface {
	GetEnqueue(index uint64) (*types.Transaction, error)
	GetLatestEnqueue() (*types.Transaction, error)
	GetLatestEnqueueIndex() (*uint64, error)
	GetTransaction(uint64, Backend) (*types.Transaction, error)
	GetLatestTransaction(Backend) (*types.Transaction, error)
	GetLatestTransactionIndex(Backend) (*uint64, 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)
	GetL1GasPrice() (*big.Int, error)
}

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

type SyncService

type SyncService struct {
	RollupGpo *gasprice.RollupOracle

	OVMContext OVMContext
	// 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) (*SyncService, error)

NewSyncService returns an initialized sync service

func (*SyncService) GetLatestBatchIndex

func (s *SyncService) GetLatestBatchIndex() *uint64

GetLatestBatchIndex reads the last processed transaction batch

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 OVMContext blocknumber

func (*SyncService) GetLatestL1Timestamp

func (s *SyncService) GetLatestL1Timestamp() uint64

GetLatestL1Timestamp returns the OVMContext 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) 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) 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) SetLatestBatchIndex

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

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

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 OVMContext blocknumber

func (*SyncService) SetLatestL1Timestamp

func (s *SyncService) SetLatestL1Timestamp(ts uint64)

SetLatestL1Timestamp will set the OVMContext 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 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