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

Method TryWriteWithMetaCheck

ethstorage/storage_manager.go:579–592  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
579func (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
594func (s *StorageManager) tryWrite(kvIdx uint64, blob []byte, commit common.Hash) error {
595 ok, err := s.shardManager.TryWrite(kvIdx, blob, PrepareCommit(commit))

Callers

nothing calls this directly

Calls 2

checkMetaMethod · 0.95
tryWriteMethod · 0.95

Tested by

no test coverage detected