diff --git a/rollup/da_syncer/batch_queue.go b/rollup/da_syncer/batch_queue.go index a0172a86c077..093ce12d830e 100644 --- a/rollup/da_syncer/batch_queue.go +++ b/rollup/da_syncer/batch_queue.go @@ -98,5 +98,6 @@ func (bq *BatchQueue) deleteBatch(batch da.Entry) { func (bq *BatchQueue) Reset(height uint64) { bq.batches.Clear() bq.batchesMap.Clear() + bq.lastFinalizedBatchIndex = 0 bq.DAQueue.Reset(height) } diff --git a/rollup/da_syncer/blob_client/block_native_client.go b/rollup/da_syncer/blob_client/block_native_client.go index ddd574d02d10..7b1cce86f083 100644 --- a/rollup/da_syncer/blob_client/block_native_client.go +++ b/rollup/da_syncer/blob_client/block_native_client.go @@ -30,7 +30,11 @@ func (c *BlockNativeClient) GetBlobByVersionedHashAndBlockNumber(ctx context.Con if err != nil { return nil, fmt.Errorf("failed to join path, err: %w", err) } - resp, err := http.Get(path) + req, err := http.NewRequestWithContext(ctx, "GET", path, nil) + if err != nil { + return nil, fmt.Errorf("cannot create request, err: %w", err) + } + resp, err := http.DefaultClient.Do(req) if err != nil { return nil, fmt.Errorf("cannot do request, err: %w", err) } diff --git a/rollup/da_syncer/da/commitV1.go b/rollup/da_syncer/da/commitV1.go index 4670eec8bbcb..532b0f81abd6 100644 --- a/rollup/da_syncer/da/commitV1.go +++ b/rollup/da_syncer/da/commitV1.go @@ -52,7 +52,7 @@ func NewCommitBatchDAWithBlob(ctx context.Context, db ethdb.Database, // compute blob versioned hash and compare with one from tx c, err := kzg4844.BlobToCommitment(blob) if err != nil { - return nil, fmt.Errorf("failed to create blob commitment") + return nil, fmt.Errorf("failed to create blob commitment: %w", err) } blobVersionedHash := common.Hash(kzg4844.CalcBlobHashV1(sha256.New(), &c)) if blobVersionedHash != versionedHash { diff --git a/rollup/da_syncer/da_queue.go b/rollup/da_syncer/da_queue.go index 64673a4a646b..3602947f51e2 100644 --- a/rollup/da_syncer/da_queue.go +++ b/rollup/da_syncer/da_queue.go @@ -27,6 +27,12 @@ func NewDAQueue(l1height uint64, dataSourceFactory *DataSourceFactory) *DAQueue func (dq *DAQueue) NextDA(ctx context.Context) (da.Entry, error) { for len(dq.da) == 0 { + select { + case <-ctx.Done(): + return nil, ctx.Err() + default: + } + err := dq.getNextData(ctx) if err != nil { return nil, err diff --git a/rollup/da_syncer/da_syncer.go b/rollup/da_syncer/da_syncer.go index b787abff3d8a..e0970d37bc9a 100644 --- a/rollup/da_syncer/da_syncer.go +++ b/rollup/da_syncer/da_syncer.go @@ -37,6 +37,10 @@ func (s *DASyncer) SyncOneBlock(block *da.PartialBlock) error { } parentBlock := s.blockchain.GetBlockByNumber(currentBlock.Number().Uint64()) + if parentBlock == nil { + return fmt.Errorf("parent block not found at height %d", currentBlock.Number().Uint64()) + } + if _, err := s.blockchain.BuildAndWriteBlock(parentBlock, block.PartialHeader.ToHeader(), block.Transactions); err != nil { return fmt.Errorf("failed building and writing block, number: %d, error: %v", block.PartialHeader.Number, err) } diff --git a/rollup/da_syncer/modes.go b/rollup/da_syncer/modes.go deleted file mode 100644 index bfcc1d1dfba0..000000000000 --- a/rollup/da_syncer/modes.go +++ /dev/null @@ -1,52 +0,0 @@ -package da_syncer - -import "fmt" - -// FetcherMode represents the mode of fetcher -type FetcherMode int - -const ( - // L1RPC mode fetches DA from L1RPC - L1RPC FetcherMode = iota - // Snapshot mode loads DA from snapshot file - Snapshot -) - -func (mode FetcherMode) IsValid() bool { - return mode >= L1RPC && mode <= Snapshot -} - -// String implements the stringer interface. -func (mode FetcherMode) String() string { - switch mode { - case L1RPC: - return "l1rpc" - case Snapshot: - return "snapshot" - default: - return "unknown" - } -} - -func (mode FetcherMode) MarshalText() ([]byte, error) { - switch mode { - case L1RPC: - return []byte("l1rpc"), nil - case Snapshot: - return []byte("snapshot"), nil - default: - return nil, fmt.Errorf("unknown sync mode %d", mode) - } -} - -func (mode *FetcherMode) UnmarshalText(text []byte) error { - switch string(text) { - case "l1rpc": - *mode = L1RPC - case "snapshot": - *mode = Snapshot - default: - return fmt.Errorf(`unknown sync mode %q, want "l1rpc" or "snapshot"`, text) - } - return nil -}