From 987939a18ac2fd8b95a59df4d37a7a829d7120d1 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 9 May 2026 15:18:06 -0300 Subject: [PATCH 1/2] db/snapcfg, cmd/downloader: internalize SnapshotSource enum Define SnapshotSource locally in db/snapcfg/cdn.go alongside the other helpers already mirrored from erigon-snapshot/embed.go, and switch FetchChainToml + its callers to the local type. cmd/downloader no longer imports erigon-snapshot at all; db/snapcfg still does for the embedded chain TOMLs and the webseed sub-package. --- cmd/downloader/main.go | 3 +-- db/snapcfg/cdn.go | 8 ++++++++ db/snapcfg/util.go | 10 +++++----- 3 files changed, 14 insertions(+), 7 deletions(-) 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..d74d0f9c4d3 100644 --- a/db/snapcfg/cdn.go +++ b/db/snapcfg/cdn.go @@ -6,6 +6,14 @@ 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. diff --git a/db/snapcfg/util.go b/db/snapcfg/util.go index 9f5621cce33..ed2023b3a8b 100644 --- a/db/snapcfg/util.go +++ b/db/snapcfg/util.go @@ -531,9 +531,9 @@ 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 +542,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 +578,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 } From 5e4e4972012c8c49211e21f437ebf31746836ca0 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 9 May 2026 15:23:35 -0300 Subject: [PATCH 2/2] db/snapcfg: drop TODOs tracking upstream erigon-snapshot cleanup The duplicated helpers (cloudflareHeaders, getURLByChain, fetchSnapshotHashes) have been removed upstream in erigontech/erigon-snapshot#1266 (merged to release/3.4); cherry-picks to main and performance are open as #1267 and #1268. The TODO markers have served their purpose. --- db/snapcfg/cdn.go | 2 -- db/snapcfg/util.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/db/snapcfg/cdn.go b/db/snapcfg/cdn.go index d74d0f9c4d3..c42eca85513 100644 --- a/db/snapcfg/cdn.go +++ b/db/snapcfg/cdn.go @@ -15,8 +15,6 @@ const ( ) // 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 ed2023b3a8b..df3a12f6cf2 100644 --- a/db/snapcfg/util.go +++ b/db/snapcfg/util.go @@ -529,8 +529,6 @@ 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 SnapshotSource, branch, chain string) ([]byte, error) { var url string if source == R2 {