Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Auto stash before merge of "feat-blob-datasource" and "main"
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 committed Apr 5, 2024
1 parent b33afc9 commit 2db0613
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 29 deletions.
3 changes: 1 addition & 2 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 3 additions & 5 deletions driver/txlist_fetcher/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 22 additions & 20 deletions driver/txlist_fetcher/blob_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion driver/txlist_fetcher/blob_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions driver/txlist_fetcher/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 2db0613

Please sign in to comment.