This repository has been archived by the owner on May 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b64bf1a
commit 1e3fb08
Showing
12 changed files
with
196 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ func (s *ChainSyncerTestSuite) SetupTest() { | |
false, | ||
1*time.Hour, | ||
0, | ||
nil, | ||
) | ||
s.Nil(err) | ||
s.s = syncer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package txlistdecoder | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/go-resty/resty/v2" | ||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/blob" | ||
"github.com/taikoxyz/taiko-client/bindings" | ||
"github.com/taikoxyz/taiko-client/pkg/rpc" | ||
) | ||
|
||
type BlobDataSource struct { | ||
ctx context.Context | ||
rpc *rpc.Client | ||
blobServerEndpoint *url.URL | ||
} | ||
|
||
type BlobData struct { | ||
// TODO: wait /getBlob add column | ||
BlobHash string `json:"blob_hash"` | ||
KzgCommitment string `json:"kzg_commitment"` | ||
} | ||
|
||
type BlobDataSeq struct { | ||
Data []*BlobData `json:"data"` | ||
} | ||
|
||
func NewBlobDataSource( | ||
ctx context.Context, | ||
rpc *rpc.Client, | ||
blobServerEndpoint *url.URL, | ||
) *BlobDataSource { | ||
return &BlobDataSource{ | ||
ctx: ctx, | ||
rpc: rpc, | ||
blobServerEndpoint: blobServerEndpoint, | ||
} | ||
} | ||
|
||
// GetBlobs get blob sidecar by meta | ||
func (ds *BlobDataSource) GetBlobs( | ||
ctx context.Context, | ||
meta *bindings.TaikoDataBlockMetadata, | ||
) ([]*blob.Sidecar, error) { | ||
if !meta.BlobUsed { | ||
return nil, errBlobUnused | ||
} | ||
|
||
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[:])) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for index, value := range blobs.Data { | ||
sidecars[index] = &blob.Sidecar{ | ||
// TODO: wait /getBlob add column | ||
KzgCommitment: value.KzgCommitment, | ||
} | ||
} | ||
} | ||
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{} | ||
) | ||
err := ds.get(ctx, route, param, result) | ||
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). | ||
SetQueryParams(param). | ||
SetContext(ctx). | ||
SetHeader("Content-Type", "application/json"). | ||
SetHeader("Accept", "application/json"). | ||
Get(fmt.Sprintf("%v/%v", ds.blobServerEndpoint.String(), route)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !resp.IsSuccess() { | ||
return fmt.Errorf( | ||
"unable to contect blob server endpoint, status code: %v", | ||
resp.StatusCode(), | ||
) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package txlistdecoder | ||
|
||
import ( | ||
"context" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/taikoxyz/taiko-client/bindings" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
"github.com/taikoxyz/taiko-client/internal/testutils" | ||
) | ||
|
||
type BlobDataSourceTestSuite struct { | ||
testutils.ClientTestSuite | ||
ds *BlobDataSource | ||
} | ||
|
||
func (s *BlobDataSourceTestSuite) SetupTest() { | ||
s.ClientTestSuite.SetupTest() | ||
// Init BlobDataSource | ||
blobServerEndpoint, err := url.Parse("https://blob.hekla.taiko.xyz") | ||
s.Nil(err) | ||
s.ds = NewBlobDataSource(context.Background(), s.RPCClient, blobServerEndpoint) | ||
} | ||
|
||
func (s *BlobDataSourceTestSuite) TestGetBlobs() { | ||
meta := &bindings.TaikoDataBlockMetadata{ | ||
BlobUsed: true, | ||
BlobHash: common.HexToHash(""), | ||
Timestamp: 1, | ||
} | ||
sidecars, err := s.ds.GetBlobs(context.Background(), meta) | ||
s.Nil(err) | ||
s.Greater(len(sidecars), 0) | ||
} | ||
|
||
func TestBlobDataSourceTestSuite(t *testing.T) { | ||
suite.Run(t, new(BlobDataSourceTestSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ func (s *EventHandlerTestSuite) SetupTest() { | |
testState, | ||
tracker, | ||
0, | ||
nil, | ||
) | ||
s.Nil(err) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ func (s *ProofSubmitterTestSuite) SetupTest() { | |
testState, | ||
tracker, | ||
0, | ||
nil, | ||
) | ||
s.Nil(err) | ||
|
||
|