From d6e26db54e95c9f64be02987639896e3ab4b851f Mon Sep 17 00:00:00 2001 From: welkin22 <136572398+welkin22@users.noreply.github.com> Date: Tue, 30 Apr 2024 10:57:11 +0800 Subject: [PATCH] fix: cannot unmarshal blob sidecar (#190) --- op-service/eth/blobs_api.go | 19 +++++++++---------- op-service/sources/l1_client.go | 10 +++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/op-service/eth/blobs_api.go b/op-service/eth/blobs_api.go index 1e3b07819285..14b739352211 100644 --- a/op-service/eth/blobs_api.go +++ b/op-service/eth/blobs_api.go @@ -1,9 +1,8 @@ package eth import ( - "math/big" - "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" ) type BlobSidecar struct { @@ -74,17 +73,17 @@ type VersionInformation struct { } type BSCBlobTxSidecar struct { - Blobs []Blob `json:"blobs"` - Commitments []Bytes48 `json:"commitments"` - Proofs []Bytes48 `json:"proofs"` + Blobs []Blob `json:"blobs"` + Commitments []Bytes48 `json:"commitments"` + Proofs []Bytes48 `json:"proofs"` } type BSCBlobSidecar struct { - BSCBlobTxSidecar - BlockNumber *big.Int `json:"blockNumber"` - BlockHash common.Hash `json:"blockHash"` - TxIndex uint64 `json:"transactionIndex"` - TxHash common.Hash `json:"transactionHash"` + BSCBlobTxSidecar `json:"blobSidecar"` + BlockNumber *hexutil.Big `json:"blockNumber"` + BlockHash common.Hash `json:"blockHash"` + TxIndex *hexutil.Uint64 `json:"txIndex"` + TxHash common.Hash `json:"txHash"` } type BSCBlobSidecars []*BSCBlobSidecar diff --git a/op-service/sources/l1_client.go b/op-service/sources/l1_client.go index c2672aaa3d9d..fc69d061c4fb 100644 --- a/op-service/sources/l1_client.go +++ b/op-service/sources/l1_client.go @@ -295,23 +295,23 @@ func (s *L1Client) getBlobSidecars(ctx context.Context, ref eth.L1BlockRef) (eth return blobSidecars, nil } -func validateBlobSidecars (blobSidecars eth.BSCBlobSidecars, ref eth.L1BlockRef) (map[common.Hash]*eth.Blob, error) { +func validateBlobSidecars(blobSidecars eth.BSCBlobSidecars, ref eth.L1BlockRef) (map[common.Hash]*eth.Blob, error) { if len(blobSidecars) == 0 { return nil, fmt.Errorf("invalidate api response, blob sidecars of block %s are empty", ref.Hash) } blobsMap := make(map[common.Hash]*eth.Blob) for _, blobSidecar := range blobSidecars { - if blobSidecar.BlockNumber.Cmp(big.NewInt(0).SetUint64(ref.Number)) != 0 { - return nil, fmt.Errorf("invalidate api response of tx %s, expect block number %d, got %d", blobSidecar.TxHash, ref.Number, blobSidecar.BlockNumber.Uint64()) + if blobSidecar.BlockNumber.ToInt().Cmp(big.NewInt(0).SetUint64(ref.Number)) != 0 { + return nil, fmt.Errorf("invalidate api response of tx %s, expect block number %d, got %d", blobSidecar.TxHash, ref.Number, blobSidecar.BlockNumber.ToInt().Uint64()) } if blobSidecar.BlockHash.Cmp(ref.Hash) != 0 { return nil, fmt.Errorf("invalidate api response of tx %s, expect block hash %s, got %s", blobSidecar.TxHash, ref.Hash, blobSidecar.BlockHash) } if len(blobSidecar.Blobs) == 0 || len(blobSidecar.Blobs) != len(blobSidecar.Commitments) || len(blobSidecar.Blobs) != len(blobSidecar.Proofs) { - return nil, fmt.Errorf("invalidate api response of tx %s, len of blobs/commitments/proofs is not equal or is 0", blobSidecar.TxHash) + return nil, fmt.Errorf("invalidate api response of tx %s,idx:%d, len of blobs(%d)/commitments(%d)/proofs(%d) is not equal or is 0", blobSidecar.TxHash, blobSidecar.TxIndex, len(blobSidecar.Blobs), len(blobSidecar.Commitments), len(blobSidecar.Proofs)) } - for i:=0; i