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 { ...@@ -249,13 +249,15 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error {
queueIndex := s.GetLatestEnqueueIndex() queueIndex := s.GetLatestEnqueueIndex()
if queueIndex == nil { if queueIndex == nil {
enqueue, err := s.client.GetLastConfirmedEnqueue() enqueue, err := s.client.GetLastConfirmedEnqueue()
if err != nil {
return fmt.Errorf("Cannot fetch last confirmed queue tx: %w", err)
}
// There are no enqueues yet // There are no enqueues yet
if enqueue == nil { if errors.Is(err, errElementNotFound) {
return nil 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 queueIndex = enqueue.GetMeta().QueueIndex
} }
s.SetLatestEnqueueIndex(queueIndex) s.SetLatestEnqueueIndex(queueIndex)
...@@ -310,14 +312,13 @@ func (s *SyncService) verify() error { ...@@ -310,14 +312,13 @@ func (s *SyncService) verify() error {
// The verifier polls for ctc transactions. // The verifier polls for ctc transactions.
// the ctc transactions are extending the chain. // the ctc transactions are extending the chain.
latest, err := s.client.GetLatestTransaction() latest, err := s.client.GetLatestTransaction()
if err != nil { if errors.Is(err, errElementNotFound) {
return err
}
if latest == nil {
log.Debug("latest transaction not found") log.Debug("latest transaction not found")
return nil return nil
} }
if err != nil {
return err
}
var start uint64 var start uint64
if s.GetLatestIndex() == nil { if s.GetLatestIndex() == nil {
...@@ -372,16 +373,13 @@ func (s *SyncService) sequence() error { ...@@ -372,16 +373,13 @@ func (s *SyncService) sequence() error {
// Place as many L1ToL2 transactions in the same context as possible // Place as many L1ToL2 transactions in the same context as possible
// by executing them one after another. // by executing them one after another.
latest, err := s.client.GetLatestEnqueue() latest, err := s.client.GetLatestEnqueue()
if err != nil { if errors.Is(err, errElementNotFound) {
return err
}
// This should never happen unless the backend is empty
if latest == nil {
log.Debug("No enqueue transactions found") log.Debug("No enqueue transactions found")
return nil return nil
} }
if err != nil {
return fmt.Errorf("cannot fetch latest enqueue: %w", err)
}
// Compare the remote latest queue index to the local latest // Compare the remote latest queue index to the local latest
// queue index. If the remote latest queue index is greater // queue index. If the remote latest queue index is greater
// than the local latest queue index, be sure to ingest more // than the local latest queue index, be sure to ingest more
...@@ -486,15 +484,15 @@ func (s *SyncService) syncTransactionsToTip() error { ...@@ -486,15 +484,15 @@ func (s *SyncService) syncTransactionsToTip() error {
// This function must be sure to sync all the way to the tip. // This function must be sure to sync all the way to the tip.
// First query the latest transaction // First query the latest transaction
latest, err := s.client.GetLatestTransaction() latest, err := s.client.GetLatestTransaction()
if errors.Is(err, errElementNotFound) {
log.Info("No transactions to sync")
return nil
}
if err != nil { if err != nil {
log.Error("Cannot get latest transaction", "msg", err) log.Error("Cannot get latest transaction", "msg", err)
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
continue continue
} }
if latest == nil {
log.Info("No transactions to sync")
return nil
}
tipHeight := latest.GetMeta().Index tipHeight := latest.GetMeta().Index
index := rawdb.ReadHeadIndex(s.db) index := rawdb.ReadHeadIndex(s.db)
start := uint64(0) start := uint64(0)
......
...@@ -428,6 +428,14 @@ func (m *mockClient) GetLastConfirmedEnqueue() (*types.Transaction, error) { ...@@ -428,6 +428,14 @@ func (m *mockClient) GetLastConfirmedEnqueue() (*types.Transaction, error) {
return nil, nil 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) { func (m *mockClient) SyncStatus() (*SyncStatus, error) {
return &SyncStatus{ return &SyncStatus{
Syncing: false, 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