diff --git a/catchup/catchpointService.go b/catchup/catchpointService.go index 28823f393c..01316949f5 100644 --- a/catchup/catchpointService.go +++ b/catchup/catchpointService.go @@ -823,12 +823,14 @@ func (cs *CatchpointCatchupService) checkLedgerDownload() error { for i := 0; i < cs.config.CatchupLedgerDownloadRetryAttempts; i++ { psp, peerError := cs.blocksDownloadPeerSelector.getNextPeer() if peerError != nil { - return err + cs.log.Debugf("checkLedgerDownload: error on getNextPeer: %s", peerError.Error()) + return peerError } err = ledgerFetcher.headLedger(context.Background(), psp.Peer, round) if err == nil { return nil } + cs.log.Debugf("checkLedgerDownload: failed to headLedger from peer %s: %v", peerAddress(psp.Peer), err) // a non-nil error means that the catchpoint is not available, so we should rank it accordingly cs.blocksDownloadPeerSelector.rankPeer(psp, peerRankNoCatchpointForRound) } diff --git a/cmd/catchpointdump/net.go b/cmd/catchpointdump/net.go index 24a6ccfe65..2f47370f68 100644 --- a/cmd/catchpointdump/net.go +++ b/cmd/catchpointdump/net.go @@ -35,6 +35,8 @@ import ( "github.com/algorand/go-algorand/ledger/ledgercore" "github.com/algorand/go-algorand/logging" "github.com/algorand/go-algorand/network" + "github.com/algorand/go-algorand/network/p2p" + "github.com/algorand/go-algorand/network/p2p/peerstore" "github.com/algorand/go-algorand/protocol" tools "github.com/algorand/go-algorand/tools/network" "github.com/algorand/go-algorand/util" @@ -164,8 +166,8 @@ func printDownloadProgressLine(progress int, barLength int, url string, dld int6 fmt.Printf(escapeCursorUp+escapeDeleteLine+outString+" %s\n", formatSize(dld)) } -func getRemoteDataStream(url string, hint string) (result io.ReadCloser, ctxCancel context.CancelFunc, err error) { - fmt.Printf("downloading %s from %s\n", hint, url) +func getRemoteDataStream(addr string, url string, client *http.Client, hint string) (result io.ReadCloser, ctxCancel context.CancelFunc, err error) { + fmt.Printf("downloading %s from %s %s\n", hint, addr, url) request, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return @@ -174,7 +176,7 @@ func getRemoteDataStream(url string, hint string) (result io.ReadCloser, ctxCanc timeoutContext, ctxCancel := context.WithTimeout(context.Background(), config.GetDefaultLocal().MaxCatchpointDownloadDuration) request = request.WithContext(timeoutContext) network.SetUserAgentHeader(request.Header) - response, err := http.DefaultClient.Do(request) + response, err := client.Do(request) if err != nil { return } @@ -229,13 +231,28 @@ func doDownloadCatchpoint(url string, wdReader util.WatchdogStreamReader, out io } } +func buildURL(genesisID string, round int, resource string) string { + return fmt.Sprintf("/v1/%s/%s/%s", genesisID, resource, strconv.FormatUint(uint64(round), 36)) +} + // Downloads a catchpoint tar file and returns the path to the tar file. func downloadCatchpoint(addr string, round int) (string, error) { genesisID := strings.Split(networkName, ".")[0] + "-v1.0" - urlTemplate := "http://" + addr + "/v1/" + genesisID + "/%s/" + strconv.FormatUint(uint64(round), 36) - catchpointURL := fmt.Sprintf(urlTemplate, "ledger") - catchpointStream, catchpointCtxCancel, err := getRemoteDataStream(catchpointURL, "catchpoint") + // attempt to parse as p2p address first + var httpClient *http.Client + catchpointURL := buildURL(genesisID, round, "ledger") + if addrInfo, err := peerstore.PeerInfoFromAddr(addr); err == nil { + httpClient, err = p2p.MakeTestHTTPClient(addrInfo) + if err != nil { + return "", err + } + } else { + httpClient = http.DefaultClient + catchpointURL = "http://" + addr + catchpointURL + } + + catchpointStream, catchpointCtxCancel, err := getRemoteDataStream(addr, catchpointURL, httpClient, "catchpoint") defer catchpointCtxCancel() if err != nil { return "", err