Commit 7e9ca1eb authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

l2geth: rollup client batch api (#516)

* l2geth: add batch querying to rollup client

* l2geth: add patch changeset

* l2geth: complete mock client interface

* l2geth: add comments to rollup client

* l2geth: more idiomatic error handling
parent 76c4ceb0
---
"@eth-optimism/l2geth": patch
---
Add batch API to rollup client
This diff is collapsed.
......@@ -249,13 +249,15 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error {
queueIndex := s.GetLatestEnqueueIndex()
if queueIndex == nil {
enqueue, err := s.client.GetLastConfirmedEnqueue()
if err != nil {
return fmt.Errorf("Cannot fetch last confirmed queue tx: %w", err)
}
// There are no enqueues yet
if enqueue == nil {
if errors.Is(err, errElementNotFound) {
return nil
}
// Other unexpected error
if err != nil {
return fmt.Errorf("Cannot fetch last confirmed queue tx: %w", err)
}
// No error, the queue element was found
queueIndex = enqueue.GetMeta().QueueIndex
}
s.SetLatestEnqueueIndex(queueIndex)
......@@ -310,14 +312,13 @@ func (s *SyncService) verify() error {
// The verifier polls for ctc transactions.
// the ctc transactions are extending the chain.
latest, err := s.client.GetLatestTransaction()
if err != nil {
return err
}
if latest == nil {
if errors.Is(err, errElementNotFound) {
log.Debug("latest transaction not found")
return nil
}
if err != nil {
return err
}
var start uint64
if s.GetLatestIndex() == nil {
......@@ -372,16 +373,13 @@ func (s *SyncService) sequence() error {
// Place as many L1ToL2 transactions in the same context as possible
// by executing them one after another.
latest, err := s.client.GetLatestEnqueue()
if err != nil {
return err
}
// This should never happen unless the backend is empty
if latest == nil {
if errors.Is(err, errElementNotFound) {
log.Debug("No enqueue transactions found")
return nil
}
if err != nil {
return fmt.Errorf("cannot fetch latest enqueue: %w", err)
}
// Compare the remote latest queue index to the local latest
// queue index. If the remote latest queue index is greater
// than the local latest queue index, be sure to ingest more
......@@ -486,15 +484,15 @@ func (s *SyncService) syncTransactionsToTip() error {
// This function must be sure to sync all the way to the tip.
// First query the latest transaction
latest, err := s.client.GetLatestTransaction()
if errors.Is(err, errElementNotFound) {
log.Info("No transactions to sync")
return nil
}
if err != nil {
log.Error("Cannot get latest transaction", "msg", err)
time.Sleep(time.Second * 2)
continue
}
if latest == nil {
log.Info("No transactions to sync")
return nil
}
tipHeight := latest.GetMeta().Index
index := rawdb.ReadHeadIndex(s.db)
start := uint64(0)
......
......@@ -428,6 +428,14 @@ func (m *mockClient) GetLastConfirmedEnqueue() (*types.Transaction, error) {
return nil, nil
}
func (m *mockClient) GetLatestTransactionBatch() (*Batch, []*types.Transaction, error) {
return nil, nil, nil
}
func (m *mockClient) GetTransactionBatch(index uint64) (*Batch, []*types.Transaction, error) {
return nil, nil, nil
}
func (m *mockClient) SyncStatus() (*SyncStatus, error) {
return &SyncStatus{
Syncing: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment