TryWriteWithMetaCheck will try to fetch blob and write into the local storage file. Before fetching blob, it will compare the provided commit to the one in the contract and make sure the correct commit is used.
(kvIdx uint64, commit common.Hash, fetchBlob FetchBlobFunc)
| 577 | // TryWriteWithMetaCheck will try to fetch blob and write into the local storage file. |
| 578 | // Before fetching blob, it will compare the provided commit to the one in the contract and make sure the correct commit is used. |
| 579 | func (s *StorageManager) TryWriteWithMetaCheck(kvIdx uint64, commit common.Hash, fetchBlob FetchBlobFunc) error { |
| 580 | s.mu.Lock() |
| 581 | defer s.mu.Unlock() |
| 582 | |
| 583 | newCommit, _ := s.checkMeta(kvIdx) |
| 584 | if newCommit != (common.Hash{}) { |
| 585 | commit = newCommit |
| 586 | } |
| 587 | blob, err := fetchBlob(kvIdx, commit) |
| 588 | if err != nil { |
| 589 | return fmt.Errorf("fetch blob error: kvIdx=%d, commit=%x, %w", kvIdx, commit, err) |
| 590 | } |
| 591 | return s.tryWrite(kvIdx, blob, commit) |
| 592 | } |
| 593 | |
| 594 | func (s *StorageManager) tryWrite(kvIdx uint64, blob []byte, commit common.Hash) error { |
| 595 | ok, err := s.shardManager.TryWrite(kvIdx, blob, PrepareCommit(commit)) |