Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/downloader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 8 additions & 2 deletions db/snapcfg/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
Expand Down
12 changes: 5 additions & 7 deletions db/snapcfg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
Loading