From the getBlobs spec: https://ethereum.github.io/beacon-APIs/beacon-node-oapi.yaml The returned blobs are ordered based on their kzg commitments in the block. So EthStorage needs to follow the order of kzg commitments in the block as well.
(id string, hashes []common.Hash)
| 40 | // The returned blobs are ordered based on their kzg commitments in the block. |
| 41 | // So EthStorage needs to follow the order of kzg commitments in the block as well. |
| 42 | func (a *API) queryBlobs(id string, hashes []common.Hash) (*blobs.BeaconBlobs, *httpError) { |
| 43 | // /eth/v2/beacon/blocks |
| 44 | queryUrl, err := a.beaconClient.QueryUrlForV2BeaconBlock(id) |
| 45 | if err != nil { |
| 46 | a.lg.Error("Invalid beaconID", "beaconID", id, "err", err) |
| 47 | return nil, errUnknownBlock |
| 48 | } |
| 49 | elBlock, kzgCommitsAll, hErr := a.queryElBlockNumberAndKzg(queryUrl) |
| 50 | if hErr != nil { |
| 51 | a.lg.Error("Failed to get execution block number", "beaconID", id, "err", err) |
| 52 | return nil, hErr |
| 53 | } |
| 54 | a.lg.Info("BeaconID to execution block number", "beaconID", id, "elBlock", elBlock) |
| 55 | |
| 56 | // hashToIndex is used to determine correct blob index |
| 57 | hashToIndex := make(map[common.Hash]int) |
| 58 | for _, c := range kzgCommitsAll { |
| 59 | var commit kzg4844.Commitment |
| 60 | copy(commit[:], common.FromHex(c)) |
| 61 | vh := common.Hash(kzg4844.CalcBlobHashV1(sha256.New(), &commit)) |
| 62 | if hashIncluded(vh, hashes) { |
| 63 | hashToIndex[vh] = len(hashToIndex) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // get event logs on the block |
| 68 | blockBN := new(big.Int).SetUint64(elBlock) |
| 69 | events, err := a.l1Source.FilterLogsByBlockRange(blockBN, blockBN, eth.PutBlobEvent) |
| 70 | if err != nil { |
| 71 | a.lg.Error("Failed to get events", "err", err) |
| 72 | return nil, errServerError |
| 73 | } |
| 74 | |
| 75 | blobsData := make([]string, len(hashToIndex)) |
| 76 | for i, event := range events { |
| 77 | blobHash := event.Topics[3] |
| 78 | a.lg.Info("Parsing event", "blobHash", blobHash, "event", fmt.Sprintf("%d of %d", i, len(events))) |
| 79 | // parse event to get kv_index with queried index |
| 80 | if index, ok := hashToIndex[blobHash]; ok { |
| 81 | kvIndex := big.NewInt(0).SetBytes(event.Topics[1][:]).Uint64() |
| 82 | a.lg.Info("Blobhash matched", "blobhash", blobHash, "index", index, "kvIndex", kvIndex) |
| 83 | blobData, found, err := a.storageMgr.TryRead(kvIndex, int(a.storageMgr.MaxKvSize()), blobHash) |
| 84 | if err != nil { |
| 85 | a.lg.Error("Failed to read blob", "err", err) |
| 86 | return nil, errServerError |
| 87 | } |
| 88 | if !found { |
| 89 | a.lg.Info("Blob not found by storage manager", "kvIndex", kvIndex, "blobHash", blobHash) |
| 90 | return nil, errBlobNotInES |
| 91 | } |
| 92 | blobsData[index] = "0x" + common.Bytes2Hex(blobData) |
| 93 | } |
| 94 | } |
| 95 | // remove empty entries (not found) |
| 96 | filteredBlobs := make([]string, 0, len(blobsData)) |
| 97 | for _, data := range blobsData { |
| 98 | if data != "" { |
| 99 | filteredBlobs = append(filteredBlobs, data) |
no test coverage detected