diff --git a/cmd/downloader/main.go b/cmd/downloader/main.go index 1e7198fc37f..17864b1ea4e 100644 --- a/cmd/downloader/main.go +++ b/cmd/downloader/main.go @@ -34,7 +34,6 @@ import ( g "github.com/anacrolix/generics" "github.com/anacrolix/missinggo/v2/panicif" "github.com/anacrolix/torrent/metainfo" - snapshothashes "github.com/erigontech/erigon-snapshot" "github.com/go-viper/mapstructure/v2" "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery" "github.com/pelletier/go-toml/v2" @@ -712,7 +711,7 @@ type hashChange struct{ name, released, local string } func doDiffTorrentHashes(ctx context.Context, local map[string]string) error { branch := version.DefaultSnapshotGitBranch url := snapcfg.ChainTomlGitHubURL(branch, chain) - body, err := snapcfg.FetchChainToml(ctx, snapshothashes.Github, branch, chain) + body, err := snapcfg.FetchChainToml(ctx, snapcfg.Github, branch, chain) if err != nil { return fmt.Errorf("diff: %w", err) } diff --git a/db/snapcfg/cdn.go b/db/snapcfg/cdn.go index f5e069ddba0..c42eca85513 100644 --- a/db/snapcfg/cdn.go +++ b/db/snapcfg/cdn.go @@ -6,9 +6,15 @@ import ( "net/http" ) +// SnapshotSource selects which CDN to fetch preverified snapshot TOMLs from. +type SnapshotSource int + +const ( + Github SnapshotSource = 0 + R2 SnapshotSource = 1 +) + // cloudflareHeaders are required for R2 CDN access. -// TODO: Copied from github.com/erigontech/erigon-snapshot/embed.go (cloudflareHeaders). -// Remove the copy in erigon-snapshot once this is the canonical location. var cloudflareHeaders = http.Header{ "lsjdjwcush6jbnjj3jnjscoscisoc5s": []string{"I%OSJDNFKE783DDHHJD873EFSIVNI7384R78SSJBJBCCJBC32JABBJCBJK45"}, } diff --git a/db/snapcfg/util.go b/db/snapcfg/util.go index 9f5621cce33..df3a12f6cf2 100644 --- a/db/snapcfg/util.go +++ b/db/snapcfg/util.go @@ -529,11 +529,9 @@ func GetEmbeddedWebseeds(chain string) ([]string, bool) { const RemotePreverifiedEnvKey = "ERIGON_REMOTE_PREVERIFIED" // FetchChainToml fetches a single chain's TOML file from the snapshot CDN. -// TODO: Copied from github.com/erigontech/erigon-snapshot/embed.go (getURLByChain + fetchSnapshotHashes). -// Remove the copies in erigon-snapshot once this is the canonical location. -func FetchChainToml(ctx context.Context, source snapshothashes.SnapshotSource, branch, chain string) ([]byte, error) { +func FetchChainToml(ctx context.Context, source SnapshotSource, branch, chain string) ([]byte, error) { var url string - if source == snapshothashes.R2 { + if source == R2 { url = ChainTomlR2URL(branch, chain) } else { url = ChainTomlGitHubURL(branch, chain) @@ -542,7 +540,7 @@ func FetchChainToml(ctx context.Context, source snapshothashes.SnapshotSource, b if err != nil { return nil, err } - if source == snapshothashes.R2 { + if source == R2 { InsertCloudflareHeaders(req) } resp, err := http.DefaultClient.Do(req) @@ -578,11 +576,11 @@ func LoadRemotePreverified(ctx context.Context, chainName string) error { } else { log.Info("Loading remote snapshot hashes", "chain", chainName) - hashes, err := FetchChainToml(ctx, snapshothashes.R2, snapshotGitBranch, chainName) + hashes, err := FetchChainToml(ctx, R2, snapshotGitBranch, chainName) if err != nil { log.Root().Warn("Failed to load snapshot hashes from R2; falling back to GitHub", "chain", chainName, "err", err) - hashes, err = FetchChainToml(ctx, snapshothashes.Github, snapshotGitBranch, chainName) + hashes, err = FetchChainToml(ctx, Github, snapshotGitBranch, chainName) if err != nil { return err }