CommitEmptyBlobs use to commit batch empty blobs, return inserted blobs count, next index to fill and error GetKvMetas got. Any error (like encode or commit) happen to a blob, cancel to rest.
(start, limit uint64)
| 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. |
| 258 | func (s *StorageManager) CommitEmptyBlobs(start, limit uint64) (uint64, uint64, error) { |
| 259 | var ( |
| 260 | encodedBlobs = make([][]byte, 0) |
| 261 | kvIndices = make([]uint64, 0) |
| 262 | inserted = uint64(0) |
| 263 | emptyBs = make([]byte, 0) |
| 264 | hash = common.Hash{} |
| 265 | next = start |
| 266 | ) |
| 267 | for i := start; i <= limit; i++ { |
| 268 | encodedBlob, success, err := s.shardManager.TryEncodeKV(i, emptyBs, hash) |
| 269 | if !success || err != nil { |
| 270 | s.lg.Warn("Blob encode failed", "index", i, "err", err) |
| 271 | break |
| 272 | } |
| 273 | encodedBlobs = append(encodedBlobs, encodedBlob) |
| 274 | kvIndices = append(kvIndices, i) |
| 275 | } |
| 276 | |
| 277 | s.mu.Lock() |
| 278 | defer s.mu.Unlock() |
| 279 | |
| 280 | metas, err := s.getKvMetas(kvIndices) |
| 281 | if err != nil { |
| 282 | return inserted, next, err |
| 283 | } |
| 284 | |
| 285 | for i, index := range kvIndices { |
| 286 | err := s.commitEncodedBlob(index, encodedBlobs[i], hash, metas[i]) |
| 287 | if err == nil { |
| 288 | inserted++ |
| 289 | } else { |
| 290 | var commitErr *CommitMismatchError |
| 291 | if !errors.As(err, &commitErr) { |
| 292 | s.lg.Info("Commit blobs fail", "kvIndex", kvIndices[i], "err", err.Error()) |
| 293 | break |
| 294 | } |
| 295 | } |
| 296 | // if meta is not equal to empty hash, that mean the blob is not empty, |
| 297 | // so cancel the fill empty for that index and continue the rest. |
| 298 | next++ |
| 299 | } |
| 300 | return inserted, next, nil |
| 301 | } |
| 302 | |
| 303 | // CommitBlob This function will be called when p2p sync received a blob. |
| 304 | // Return err if the passed commit and the one queried from contract are not matched. |
nothing calls this directly
no test coverage detected