erigon-pulse/turbo/snapshotsync/snapshothashes/embed.go
ledgerwatch 538543ad17
Experiment files 1 by 1 (#3959)
* Experiment files 1 by 1

* Remove check

* sort preverified snapshots

* docs: docker permissions

* sort preverified snapshots

* sort preverified snapshots

* sort preverified snapshots

* sort preverified snapshots

* sort preverified snapshots

* sort preverified snapshots

* save

* Fix speed log, remove file name

* Move timer out of the loop

* Calculate total size of downloaded files

* Fixes

* Fix

* Fix

* Fix

* Move downloadData

* Fix

* Revert "Fix"

This reverts commit 038e02b8a4d23cd32ddb111e9f325fc4ce1bbe2b.

* Revert "Move downloadData"

This reverts commit 8130a4d9bdc0705082eb7fe94e2261c9313f8482.

* Revert "Fix"

This reverts commit 1dca25bd68772bc42ac710c24698c8670f9f6b86.

* Revert "Fix"

This reverts commit ee5a1e82abd47bef4f9d8f0f68b8497476d29c0b.

* Revert "Fix"

This reverts commit 8af7be71d4685e0d6115fef91ed2f304695e1df9.

* Revert "Fixes"

This reverts commit 50509af81f3721cca957cd15d0286e8f30e5097b.

* Revert "Calculate total size of downloaded files"

This reverts commit 64a26df54f6226d739c8a5b57b32ad5af07d3061.

* Remove progress

* Remove progress

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
Co-authored-by: alex.sharov <AskAlexSharov@gmail.com>
2022-04-25 19:32:27 +01:00

106 lines
2.2 KiB
Go

package snapshothashes
import (
_ "embed"
"path/filepath"
"sort"
"strconv"
"strings"
"github.com/ledgerwatch/erigon/params/networkname"
"github.com/pelletier/go-toml/v2"
)
//go:embed erigon-snapshots/mainnet.toml
var mainnet []byte
var Mainnet = fromToml(mainnet)
//go:embed erigon-snapshots/goerli.toml
var goerli []byte
var Goerli = fromToml(goerli)
//go:embed erigon-snapshots/bsc.toml
var bsc []byte
var Bsc = fromToml(bsc)
type PreverifiedItem struct {
Name string
Hash string
}
type Preverified []PreverifiedItem
type preverified map[string]string
func fromToml(in []byte) (out Preverified) {
var outMap preverified
if err := toml.Unmarshal(in, &outMap); err != nil {
panic(err)
}
return doSort(outMap)
}
func doSort(in preverified) Preverified {
out := make(Preverified, 0, len(in))
for k, v := range in {
out = append(out, PreverifiedItem{k, v})
}
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
return out
}
var (
MainnetChainSnapshotConfig = newConfig(Mainnet)
GoerliChainSnapshotConfig = newConfig(Goerli)
BscChainSnapshotConfig = newConfig(Bsc)
)
func newConfig(preverified Preverified) *Config {
return &Config{ExpectBlocks: maxBlockNum(preverified), Preverified: preverified}
}
func maxBlockNum(preverified Preverified) uint64 {
max := uint64(0)
for _, p := range preverified {
_, fileName := filepath.Split(p.Name)
ext := filepath.Ext(fileName)
if ext != ".seg" {
continue
}
onlyName := fileName[:len(fileName)-len(ext)]
parts := strings.Split(onlyName, "-")
if parts[0] != "v1" {
panic("not implemented")
}
if parts[3] != "headers" {
continue
}
to, err := strconv.ParseUint(parts[2], 10, 64)
if err != nil {
panic(err)
}
if max < to {
max = to
}
}
if max == 0 { // to prevent underflow
return 0
}
return max*1_000 - 1
}
type Config struct {
ExpectBlocks uint64
Preverified Preverified
}
func KnownConfig(networkName string) *Config {
switch networkName {
case networkname.MainnetChainName:
return MainnetChainSnapshotConfig
case networkname.GoerliChainName:
return GoerliChainSnapshotConfig
case networkname.BSCChainName:
return BscChainSnapshotConfig
default:
return newConfig(Preverified{})
}
}