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

Method FetchBlob

ethstorage/p2p/protocol/syncclient.go:595–639  ·  view source on GitHub ↗
(kvIndex uint64, commit common.Hash)

Source from the content-addressed store, hash-verified

593}
594
595func (s *SyncClient) FetchBlob(kvIndex uint64, commit common.Hash) ([]byte, error) {
596 if len(s.peers) == 0 {
597 return nil, fmt.Errorf("no peer can be used to send requests")
598 }
599
600 for _, pr := range s.peers {
601 var packet BlobsByListPacket
602 var payload *BlobPayload = nil
603
604 _, err := pr.RequestBlobsByList(rand.Uint64(), s.storageManager.ContractAddress(), kvIndex/s.storageManager.KvEntries(), []uint64{kvIndex}, &packet)
605 if err != nil {
606 s.lg.Warn("FetchBlob failed", "error", err)
607 continue
608 }
609
610 for _, val := range packet.Blobs {
611 if val.BlobIndex != kvIndex {
612 continue
613 }
614 if commitError := ethstorage.CompareCommits(commit.Bytes(), val.BlobCommit.Bytes()); commitError != nil {
615 s.lg.Warn("FetchBlob failed", "peer", pr.ID(), "error", commitError)
616 continue
617 }
618 payload = val
619 }
620
621 if payload == nil {
622 continue
623 }
624
625 decodedBlob, success := s.decodeKV(payload)
626 if !success {
627 continue
628 }
629
630 success = s.checkBlobCommit(decodedBlob, payload)
631 if !success {
632 continue
633 }
634
635 return decodedBlob, nil
636 }
637
638 return nil, fmt.Errorf("fail to fetch blob from peers")
639}
640
641func (s *SyncClient) RequestL2List(indexes []uint64) (uint64, error) {
642 if len(indexes) == 0 {

Callers 1

TestSync_RequestL2ListFunction · 0.45

Calls 7

decodeKVMethod · 0.95
checkBlobCommitMethod · 0.95
CompareCommitsFunction · 0.92
RequestBlobsByListMethod · 0.80
ContractAddressMethod · 0.65
KvEntriesMethod · 0.65
IDMethod · 0.65

Tested by 1

TestSync_RequestL2ListFunction · 0.36