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

Method CommitBlobs

ethstorage/storage_manager.go:214–254  ·  view source on GitHub ↗

CommitBlobs This function will be called when p2p sync received blobs. It will commit the blobs that match local L1 view and return the unmatched ones. Note that the caller must make sure the blobs data and the corresponding commit are matched.

(kvIndices []uint64, blobs [][]byte, commits []common.Hash)

Source from the content-addressed store, hash-verified

212// that match local L1 view and return the unmatched ones.
213// Note that the caller must make sure the blobs data and the corresponding commit are matched.
214func (s *StorageManager) CommitBlobs(kvIndices []uint64, blobs [][]byte, commits []common.Hash) ([]uint64, error) {
215 if len(kvIndices) != len(blobs) || len(blobs) != len(commits) {
216 return nil, errors.New("invalid params lens")
217 }
218 var (
219 l = len(kvIndices)
220 encodedBlobs = make([][]byte, l)
221 encoded = make([]bool, l)
222 )
223 for i := 0; i < len(kvIndices); i++ {
224 encodedBlob, success, err := s.shardManager.TryEncodeKV(kvIndices[i], blobs[i], commits[i])
225 if !success || err != nil {
226 s.lg.Warn("Blob encode failed", "index", kvIndices[i], "err", err)
227 continue
228 }
229 encodedBlobs[i] = encodedBlob
230 encoded[i] = true
231 }
232
233 s.mu.Lock()
234 defer s.mu.Unlock()
235
236 metas, err := s.getKvMetas(kvIndices)
237 if err != nil {
238 return nil, err
239 }
240
241 inserted := []uint64{}
242 for i, contractMeta := range metas {
243 if !encoded[i] {
244 continue
245 }
246 err := s.commitEncodedBlob(kvIndices[i], encodedBlobs[i], commits[i], contractMeta)
247 if err != nil {
248 s.lg.Warn("Commit blobs fail", "kvIndex", kvIndices[i], "err", err.Error())
249 continue
250 }
251 inserted = append(inserted, kvIndices[i])
252 }
253 return inserted, nil
254}
255
256// CommitEmptyBlobs use to commit batch empty blobs, return inserted blobs count, next index to fill
257// and error GetKvMetas got. Any error (like encode or commit) happen to a blob, cancel to rest.

Callers

nothing calls this directly

Calls 4

getKvMetasMethod · 0.95
commitEncodedBlobMethod · 0.95
TryEncodeKVMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected