Skip to content

Commit

Permalink
fix e2e case fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Welkin committed Sep 21, 2023
1 parent db5d4ed commit ca93db6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions op-node/sources/l1_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type L1Client struct {
preFetchReceiptsOnce sync.Once
//start block for pre-fetch receipts
preFetchReceiptsStartBlockChan chan uint64
//done chan
done chan struct{}
}

// NewL1Client wraps a RPC with bindings to fetch L1 data, while logging errors, tracking metrics (optional), and caching.
Expand All @@ -77,6 +79,7 @@ func NewL1Client(client client.RPC, log log.Logger, metrics caching.Metrics, con
l1BlockRefsCache: caching.NewLRUCache(metrics, "blockrefs", config.L1BlockRefsCacheSize),
preFetchReceiptsOnce: sync.Once{},
preFetchReceiptsStartBlockChan: make(chan uint64, 1),
done: make(chan struct{}),
}, nil
}

Expand Down Expand Up @@ -131,6 +134,9 @@ func (s *L1Client) GoOrUpdatePreFetchReceipts(ctx context.Context, l1Start uint6
var currentL1Block uint64
for {
select {
case <-s.done:
s.log.Info("pre-fetching receipts done")
return
case currentL1Block = <-s.preFetchReceiptsStartBlockChan:
s.log.Debug("pre-fetching receipts currentL1Block changed", "block", currentL1Block)
default:
Expand All @@ -155,3 +161,8 @@ func (s *L1Client) GoOrUpdatePreFetchReceipts(ctx context.Context, l1Start uint6
s.preFetchReceiptsStartBlockChan <- l1Start
return nil
}

func (s *L1Client) Close() {
s.done <- struct{}{}
s.EthClient.Close()
}
6 changes: 6 additions & 0 deletions op-program/client/l1/cache.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package l1

import (
"context"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -61,3 +62,8 @@ func (o *CachingOracle) ReceiptsByBlockHash(blockHash common.Hash) (eth.BlockInf
o.rcpts.Add(blockHash, rcpts)
return block, rcpts
}

func (o *CachingOracle) GoOrUpdatePreFetchReceipts(ctx context.Context, block uint64) error {
// do nothing
return nil
}
4 changes: 4 additions & 0 deletions op-program/client/l1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ func (o *OracleL1Client) InfoAndTxsByHash(ctx context.Context, hash common.Hash)
info, txs := o.oracle.TransactionsByBlockHash(hash)
return info, txs, nil
}

func (o *OracleL1Client) GoOrUpdatePreFetchReceipts(ctx context.Context, l1StartBlock uint64) error {
return o.oracle.GoOrUpdatePreFetchReceipts(ctx, l1StartBlock)
}
7 changes: 7 additions & 0 deletions op-program/client/l1/oracle.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package l1

import (
"context"
"fmt"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -21,6 +22,7 @@ type Oracle interface {

// ReceiptsByBlockHash retrieves the receipts from the block with the given hash.
ReceiptsByBlockHash(blockHash common.Hash) (eth.BlockInfo, types.Receipts)
GoOrUpdatePreFetchReceipts(ctx context.Context, block uint64) error
}

// PreimageOracle implements Oracle using by interfacing with the pure preimage.Oracle
Expand Down Expand Up @@ -86,3 +88,8 @@ func (p *PreimageOracle) ReceiptsByBlockHash(blockHash common.Hash) (eth.BlockIn

return info, receipts
}

func (p *PreimageOracle) GoOrUpdatePreFetchReceipts(ctx context.Context, block uint64) error {
// do nothing
return nil
}

0 comments on commit ca93db6

Please sign in to comment.