From 2db0613d817198e466e9599256bd31c236c37080 Mon Sep 17 00:00:00 2001 From: gavin Date: Fri, 5 Apr 2024 16:56:59 +0800 Subject: [PATCH] Auto stash before merge of "feat-blob-datasource" and "main" --- driver/chain_syncer/calldata/syncer.go | 3 +- driver/txlist_fetcher/blob.go | 8 ++-- driver/txlist_fetcher/blob_datasource.go | 42 ++++++++++--------- driver/txlist_fetcher/blob_datasource_test.go | 2 +- driver/txlist_fetcher/interface.go | 1 + proposer/proposer_test.go | 7 +++- 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/driver/chain_syncer/calldata/syncer.go b/driver/chain_syncer/calldata/syncer.go index c962c1586..89d6593b8 100644 --- a/driver/chain_syncer/calldata/syncer.go +++ b/driver/chain_syncer/calldata/syncer.go @@ -247,8 +247,7 @@ func (s *Syncer) onBlockProposed( // Decode transactions list. var txListDecoder txlistfetcher.TxListFetcher if event.Meta.BlobUsed { - txListDecoder = txlistfetcher.NewBlobTxListFetcher(s.rpc.L1Beacon) - txListDecoder = txlistfetcher.NewBlobTxListFetcher(s.rpc, s.blobDatasource) + txListDecoder = txlistfetcher.NewBlobTxListFetcher(s.rpc.L1Beacon, s.blobDatasource) } else { txListDecoder = new(txlistfetcher.CalldataFetcher) } diff --git a/driver/txlist_fetcher/blob.go b/driver/txlist_fetcher/blob.go index 91daea9aa..4dae676e3 100644 --- a/driver/txlist_fetcher/blob.go +++ b/driver/txlist_fetcher/blob.go @@ -17,14 +17,12 @@ import ( // BlobFetcher is responsible for fetching the txList blob from the L1 block sidecar. type BlobFetcher struct { l1Beacon *rpc.BeaconClient - ds *BlobDataSource + ds *BlobDataSource } // NewBlobTxListFetcher creates a new BlobFetcher instance based on the given rpc client. -func NewBlobTxListFetcher(l1Beacon *rpc.BeaconClient) *BlobFetcher { - return &BlobFetcher{l1Beacon} -func NewBlobTxListFetcher(rpc *rpc.Client, ds *BlobDataSource) *BlobFetcher { - return &BlobFetcher{rpc, ds} +func NewBlobTxListFetcher(l1Beacon *rpc.BeaconClient, ds *BlobDataSource) *BlobFetcher { + return &BlobFetcher{l1Beacon, ds} } // Fetch implements the TxListFetcher interface. diff --git a/driver/txlist_fetcher/blob_datasource.go b/driver/txlist_fetcher/blob_datasource.go index a9884a49b..09b5863e1 100644 --- a/driver/txlist_fetcher/blob_datasource.go +++ b/driver/txlist_fetcher/blob_datasource.go @@ -20,9 +20,9 @@ type BlobDataSource struct { } type BlobData struct { - // TODO: wait /getBlob add column BlobHash string `json:"blob_hash"` KzgCommitment string `json:"kzg_commitment"` + Blob string `json:"blob"` } type BlobDataSeq struct { @@ -50,60 +50,62 @@ func (ds *BlobDataSource) GetBlobs( return nil, errBlobUnused } - sidecars, err := ds.rpc.L1Beacon.GetBlobs(ctx, meta.Timestamp) + var ( + sidecars []*blob.Sidecar + err error + ) + if ds.rpc.L1Beacon == nil { + sidecars, err = nil, errBeaconNotFound + } else { + sidecars, err = ds.rpc.L1Beacon.GetBlobs(ctx, meta.Timestamp) + } if err != nil { log.Info("Failed to get blobs from beacon, try to use blob server.", "err", err.Error()) if ds.blobServerEndpoint == nil { log.Info("No blob server endpoint set") return nil, err } - blobs, err := ds.getBlobFromServer(ctx, common.Bytes2Hex(meta.BlobHash[:])) + blobs, err := ds.getBlobFromServer(ctx, "0x"+common.Bytes2Hex(meta.BlobHash[:])) if err != nil { return nil, err } + sidecars = make([]*blob.Sidecar, len(blobs.Data)) for index, value := range blobs.Data { sidecars[index] = &blob.Sidecar{ - // TODO: wait /getBlob add column KzgCommitment: value.KzgCommitment, + Blob: value.Blob, } } } + err = nil return sidecars, err } // getBlobFromServer get blob data from server path `/getBlob`. func (ds *BlobDataSource) getBlobFromServer(ctx context.Context, blobHash string) (*BlobDataSeq, error) { var ( - route = "/getBlob" - param = map[string]string{"blobHash": blobHash} - result = &BlobDataSeq{} + route = "/getBlob" + param = map[string]string{"blobHash": blobHash} ) - err := ds.get(ctx, route, param, result) + requestURL, err := url.JoinPath(ds.blobServerEndpoint.String(), route) if err != nil { return nil, err } - return result, nil -} - -// get send the given GET request to the blob server. -func (ds *BlobDataSource) get(ctx context.Context, route string, param map[string]string, result interface{}) error { resp, err := resty.New().R(). - SetResult(result). + SetResult(BlobDataSeq{}). SetQueryParams(param). SetContext(ctx). SetHeader("Content-Type", "application/json"). SetHeader("Accept", "application/json"). - Get(fmt.Sprintf("%v/%v", ds.blobServerEndpoint.String(), route)) + Get(requestURL) if err != nil { - return err + return nil, err } - if !resp.IsSuccess() { - return fmt.Errorf( + return nil, fmt.Errorf( "unable to contect blob server endpoint, status code: %v", resp.StatusCode(), ) } - - return nil + return resp.Result().(*BlobDataSeq), nil } diff --git a/driver/txlist_fetcher/blob_datasource_test.go b/driver/txlist_fetcher/blob_datasource_test.go index e4bf55c8b..dbd9ae43d 100644 --- a/driver/txlist_fetcher/blob_datasource_test.go +++ b/driver/txlist_fetcher/blob_datasource_test.go @@ -27,7 +27,7 @@ func (s *BlobDataSourceTestSuite) SetupTest() { func (s *BlobDataSourceTestSuite) TestGetBlobs() { meta := &bindings.TaikoDataBlockMetadata{ BlobUsed: true, - BlobHash: common.HexToHash(""), + BlobHash: common.HexToHash("0x019101fb28118ceccaabca22a47e35b9c3f12eb2dcb25e5c543d5b75e6cd841f"), Timestamp: 1, } sidecars, err := s.ds.GetBlobs(context.Background(), meta) diff --git a/driver/txlist_fetcher/interface.go b/driver/txlist_fetcher/interface.go index 6f43e69d8..6d2f8864a 100644 --- a/driver/txlist_fetcher/interface.go +++ b/driver/txlist_fetcher/interface.go @@ -12,6 +12,7 @@ var ( errBlobUsed = errors.New("blob is used") errBlobUnused = errors.New("blob is not used") errSidecarNotFound = errors.New("sidecar not found") + errBeaconNotFound = errors.New("beacon client not found") ) // TxListFetcher is responsible for fetching the L2 txList bytes from L1 diff --git a/proposer/proposer_test.go b/proposer/proposer_test.go index 62d72c31e..ae84bbaed 100644 --- a/proposer/proposer_test.go +++ b/proposer/proposer_test.go @@ -46,6 +46,7 @@ func (s *ProposerTestSuite) SetupTest() { state2, beaconsync.NewSyncProgressTracker(s.RPCClient.L2, 1*time.Hour), 0, + nil, ) s.Nil(err) s.s = syncer @@ -113,7 +114,11 @@ func parseTxs(client *rpc.Client, event *bindings.TaikoL1ClientBlockProposed) (t // Decode transactions list. var txListDecoder txlistfetcher.TxListFetcher if event.Meta.BlobUsed { - txListDecoder = txlistfetcher.NewBlobTxListFetcher(client.L1Beacon) + txListDecoder = txlistfetcher.NewBlobTxListFetcher(client.L1Beacon, txlistfetcher.NewBlobDataSource( + context.Background(), + client, + nil, + )) } else { txListDecoder = new(txlistfetcher.CalldataFetcher) }