MCPcopy Create free account
hub / github.com/ethstorage/es-node / queryBlobSidecars

Method queryBlobSidecars

ethstorage/archiver/api.go:107–165  ·  view source on GitHub ↗

Deprecated since Fusaka

(id string, indices []uint64)

Source from the content-addressed store, hash-verified

105
106// Deprecated since Fusaka
107func (a *API) queryBlobSidecars(id string, indices []uint64) (*BlobSidecars, *httpError) {
108 // query EL block
109 queryUrl, err := a.beaconClient.QueryUrlForV2BeaconBlock(id)
110 if err != nil {
111 a.lg.Error("Invalid beaconID", "beaconID", id, "err", err)
112 return nil, errUnknownBlock
113 }
114 elBlock, kzgCommitsAll, hErr := a.queryElBlockNumberAndKzg(queryUrl)
115 if hErr != nil {
116 a.lg.Error("Failed to get execution block number", "beaconID", id, "err", err)
117 return nil, hErr
118 }
119 a.lg.Info("BeaconID to execution block number", "beaconID", id, "elBlock", elBlock)
120
121 blobsInBeacon := uint64(len(kzgCommitsAll))
122 for _, index := range indices {
123 if index >= blobsInBeacon {
124 // beacon API will ignore invalid indices and return all blobs
125 indices = nil
126 }
127 }
128
129 // hashToIndex is used to determine correct blob index
130 hashToIndex := make(map[common.Hash]Index)
131 for i, c := range kzgCommitsAll {
132 if indexIncluded(uint64(i), indices) {
133 bh := gkzg.KZGToVersionedHash(gkzg.KZGCommitment(common.FromHex(c)))
134 hashToIndex[common.Hash(bh)] = Index(i)
135 }
136 }
137
138 // get event logs on the block
139 blockBN := new(big.Int).SetUint64(elBlock)
140 events, err := a.l1Source.FilterLogsByBlockRange(blockBN, blockBN, eth.PutBlobEvent)
141 if err != nil {
142 a.lg.Error("Failed to get events", "err", err)
143 return nil, errServerError
144 }
145 var res BlobSidecars
146 for i, event := range events {
147 blobHash := event.Topics[3]
148 a.lg.Info("Parsing event", "blobHash", blobHash, "event", fmt.Sprintf("%d of %d", i, len(events)))
149 // parse event to get kv_index with queried index
150 if index, ok := hashToIndex[blobHash]; ok {
151 kvIndex := big.NewInt(0).SetBytes(event.Topics[1][:]).Uint64()
152 a.lg.Info("Blobhash matched", "blobhash", blobHash, "index", index, "kvIndex", kvIndex)
153 sidecar, hErr := a.buildSidecar(kvIndex, common.FromHex(kzgCommitsAll[index]), blobHash)
154 if hErr != nil {
155 a.lg.Error("Failed to build sidecar", "err", hErr)
156 return nil, hErr
157 }
158 sidecar.Index = index
159 a.lg.Info("Sidecar built", "index", index, "sidecar", sidecar)
160 res.Data = append(res.Data, sidecar)
161 }
162 }
163 a.lg.Info("Query blob sidecars done", "blobs", len(res.Data))
164 return &res, nil

Callers 1

blobSidecarHandlerMethod · 0.80

Calls 8

buildSidecarMethod · 0.95
indexIncludedFunction · 0.85
IndexTypeAlias · 0.85
HashMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected