| 593 | } |
| 594 | |
| 595 | func (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 | |
| 641 | func (s *SyncClient) RequestL2List(indexes []uint64) (uint64, error) { |
| 642 | if len(indexes) == 0 { |