@@ -3,13 +3,15 @@ package watcher
33import (
44 "context"
55 "errors"
6+ "fmt"
67 "math/big"
78
9+ "github.com/ethereum/go-ethereum/common/hexutil"
810 "github.com/prometheus/client_golang/prometheus"
9- "github.com/scroll-tech/go-ethereum/consensus/misc"
1011 gethTypes "github.com/scroll-tech/go-ethereum/core/types"
1112 "github.com/scroll-tech/go-ethereum/ethclient"
1213 "github.com/scroll-tech/go-ethereum/log"
14+ "github.com/scroll-tech/go-ethereum/rpc"
1315 "gorm.io/gorm"
1416
1517 "scroll-tech/common/types"
@@ -20,7 +22,8 @@ import (
2022// L1WatcherClient will listen for smart contract events from Eth L1.
2123type L1WatcherClient struct {
2224 ctx context.Context
23- client * ethclient.Client
25+ rpcClient * rpc.Client // Raw RPC client
26+ client * ethclient.Client // Go SDK RPC client
2427 l1BlockOrm * orm.L1Block
2528
2629 // The height of the block that the watcher has retrieved header rlp
@@ -30,7 +33,7 @@ type L1WatcherClient struct {
3033}
3134
3235// NewL1WatcherClient returns a new instance of L1WatcherClient.
33- func NewL1WatcherClient (ctx context.Context , client * ethclient .Client , startHeight uint64 , db * gorm.DB , reg prometheus.Registerer ) * L1WatcherClient {
36+ func NewL1WatcherClient (ctx context.Context , rpcClient * rpc .Client , startHeight uint64 , db * gorm.DB , reg prometheus.Registerer ) * L1WatcherClient {
3437 l1BlockOrm := orm .NewL1Block (db )
3538 savedL1BlockHeight , err := l1BlockOrm .GetLatestL1BlockHeight (ctx )
3639 if err != nil {
@@ -43,7 +46,8 @@ func NewL1WatcherClient(ctx context.Context, client *ethclient.Client, startHeig
4346
4447 return & L1WatcherClient {
4548 ctx : ctx ,
46- client : client ,
49+ rpcClient : rpcClient ,
50+ client : ethclient .NewClient (rpcClient ),
4751 l1BlockOrm : l1BlockOrm ,
4852
4953 processedBlockHeight : savedL1BlockHeight ,
@@ -78,10 +82,16 @@ func (w *L1WatcherClient) FetchBlockHeader(blockHeight uint64) error {
7882 baseFee = block .BaseFee .Uint64 ()
7983 }
8084
81- var blobBaseFee uint64
82- if excess := block .ExcessBlobGas ; excess != nil {
83- blobBaseFee = misc .CalcBlobFee (* excess ).Uint64 ()
85+ // Leave it up to the L1 node to return the correct blob base fee.
86+ // Previously we would compute it locally using `CalcBlobFee`, but
87+ // that needs to be in sync with the L1 node's configuration.
88+ // Note: The fetched blob base fee might not correspond to the block
89+ // that we fetched in the previous step, but this is acceptable.
90+ var hex hexutil.Big
91+ if err := w .rpcClient .CallContext (w .ctx , & hex , "eth_blobBaseFee" ); err != nil {
92+ return fmt .Errorf ("failed to call eth_blobBaseFee, err: %w" , err )
8493 }
94+ blobBaseFee := hex .ToInt ().Uint64 ()
8595
8696 l1Block := orm.L1Block {
8797 Number : blockHeight ,
0 commit comments