Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
badgersrus committed Aug 23, 2024
1 parent 768cdb5 commit 9d4aa8c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 79 deletions.
2 changes: 0 additions & 2 deletions go/enclave/components/rollup_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ func (rc *rollupConsumerImpl) extractRollups(ctx context.Context, br *common.Blo

blobs, err := rc.blobResolver.FetchBlobs(ctx, br.Block.Header(), rollupHashes.BlobHashes)
if err != nil {
println("CONSUMER FAILED fetch blobs: ", err.Error())
rc.logger.Crit("could not fetch blobs consumer", log.ErrKey, err)
return nil
}
println("CONSUMER SUCCESS fetch blobs")
r, err := ethadapter.ReconstructRollup(blobs)
if err != nil {
rc.logger.Crit("could not recreate rollup from blobs.", log.ErrKey, err)
Expand Down
23 changes: 9 additions & 14 deletions go/ethadapter/beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,14 @@ func (bc *BeaconHTTPClient) BeaconGenesis(ctx context.Context) (APIGenesisRespon
return genesisResp, nil
}

func (bc *BeaconHTTPClient) BeaconBlobSideCars(ctx context.Context, slot uint64, hashes []IndexedBlobHash) (APIGetBlobSidecarsResponse, error) {
func (bc *BeaconHTTPClient) BeaconBlobSideCars(ctx context.Context, slot uint64, _ []IndexedBlobHash) (APIGetBlobSidecarsResponse, error) {
reqPath := path.Join(sidecarsMethodPrefix, strconv.FormatUint(slot, 10))
var reqQuery url.Values
//reqQuery = url.Values{}
//for i := range hashes {
// reqQuery.Add("indices", strconv.FormatUint(hashes[i].Index, 10))
//}
var resp APIGetBlobSidecarsResponse

err := bc.request(ctx, &resp, reqPath, reqQuery)

if err != nil {
println("ERROR GETTING SIDECAR with hash: ", hashes[0].Hash.Hex(), " with err: ", err.Error())
return APIGetBlobSidecarsResponse{}, err
}
return resp, nil
Expand Down Expand Up @@ -249,28 +244,28 @@ func (cl *L1BeaconClient) GetBlobSidecars(ctx context.Context, b *types.Header,
return nil, fmt.Errorf("failed to fetch blob sidecars for slot %v block %v: %w", slot, b, err)
}

sidescars := make([]*APIBlobSidecar, 0, len(hashes))
sidecars := make([]*APIBlobSidecar, 0, len(hashes))
// find the sidecars that match the provided versioned hashes
for _, h := range hashes {
for _, sidecar := range resp.Data {
versionedHash := KZGToVersionedHash(kzg4844.Commitment(sidecar.KZGCommitment))
if h.Hash == versionedHash {
sidescars = append(sidescars, sidecar)
sidecars = append(sidecars, sidecar)
break
}
}
}

if len(hashes) != len(sidescars) {
return nil, fmt.Errorf("expected %v sidecars but got %v", len(hashes), len(sidescars))
if len(hashes) != len(sidecars) {
return nil, fmt.Errorf("expected %v sidecars but got %v", len(hashes), len(sidecars))
}

bscs := make([]*BlobSidecar, 0, len(hashes))
for _, apisc := range sidescars {
bscs = append(bscs, apisc.BlobSidecar())
blobSidecars := make([]*BlobSidecar, 0, len(hashes))
for _, sidecar := range sidecars {
blobSidecars = append(blobSidecars, sidecar.BlobSidecar())
}

return bscs, nil
return blobSidecars, nil
}

// FetchBlobs fetches blobs that were confirmed in the specified L1 block with the given indexed
Expand Down
61 changes: 0 additions & 61 deletions go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/base64"
"fmt"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/params"
"math/big"
"strings"

Expand Down Expand Up @@ -191,13 +190,6 @@ func (c *contractLibImpl) CreateBlobRollup(t *ethadapter.L1RollupTx) (types.TxDa
return nil, fmt.Errorf("failed to make sidecar: %w", err)
}

println("creating rollup blob tx: ", decodedRollup.Hash().Hex())
println("creating rollup blob seq no: ", decodedRollup.Header.LastBatchSeqNo)

for _, blobH := range blobHashes {
println("blob hash: ", blobH.Hex())
}

return &types.BlobTx{
To: *c.addr,
Data: data,
Expand Down Expand Up @@ -504,59 +496,6 @@ func convertCrossChainMessages(messages []MessageBus.StructsCrossChainMessage) [
return msgs
}

func encodeBlobs(data []byte) []kzg4844.Blob {
blobs := []kzg4844.Blob{{}}
blobIndex := 0
fieldIndex := -1
for i := 0; i < len(data); i += 31 {
fieldIndex++
if fieldIndex == params.BlobTxFieldElementsPerBlob {
blobs = append(blobs, kzg4844.Blob{})
blobIndex++
fieldIndex = 0
}
max := i + 31
if max > len(data) {
max = len(data)
}
copy(blobs[blobIndex][fieldIndex*32+1:], data[i:max])
}
return blobs
}

//// chunkRollup splits the rollup into blobs based on the max blob size and index's the blobs
//func chunkRollup(blob ethadapter.Blob) ([]ethadapter.Blob, error) {
// maxBlobSize := 128 * 1024 // 128KB in bytes TODO move to config
// base64ChunkSize := int(math.Floor(float64(maxBlobSize) * 4 / 3))
// base64ChunkSize = base64ChunkSize - (base64ChunkSize % 4) - 4 //metadata size
// //indexByteSize := 4 // size in bytes for the chunk index metadata
// var blobs []ethadapter.Blob
//
// for i := 0; i < len(blob); i += maxBlobSize {
// end := i + maxBlobSize
// if end > len(blob) {
// end = len(blob)
// }
//
// chunkData := blob[i:end]
//
// // ethereum expects fixed blob length so we need to pad it out
// actualLength := len(chunkData)
// if actualLength < 131072 {
// // Add padding
// padding := make([]byte, 131072-actualLength)
// chunkData = append(chunkData, padding...)
// }
//
// if len(chunkData) != 131072 {
// return nil, fmt.Errorf("rollup blob must be 131072 in length")
// }
//
// blobs = append(blobs, blob)
// }
// return blobs, nil
//}

// MakeSidecar builds & returns the BlobTxSidecar and corresponding blob hashes from the raw blob
// data.
func makeSidecar(blobs []kzg4844.Blob) (*types.BlobTxSidecar, []gethcommon.Hash, error) {
Expand Down
2 changes: 0 additions & 2 deletions go/host/l1/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,9 @@ func (p *Publisher) ExtractObscuroRelevantTransactions(block *types.Block) ([]*e

blobs, err := p.blobResolver.FetchBlobs(p.sendingContext, block.Header(), rollupHashes.BlobHashes)
if err != nil {
println("PUBLISHER FAILED fetch blobs: ", err.Error())
p.logger.Crit("could not fetch blobs publisher", log.ErrKey, err)
return nil, nil, nil
}
println("PUBLISHER SUCCESS fetch blobs")
encodedRlp, err := ethadapter.DecodeBlobs(blobs)
if err != nil {
p.logger.Crit("could not decode blobs.", log.ErrKey, err)
Expand Down

0 comments on commit 9d4aa8c

Please sign in to comment.