erigon-pulse/cmd/snapshots/generator/commands/metainfo_hash.go
b00ris 565a4250d6
Snapshot sync headers stage (#1836)
* save state

* snapshot update works

* save state

* snapshot migrator

* tx test

* save state

* migrations stages refactor

* refactor snapshot migrator

* compilation fixed

* integrate snapshot migrator

* goerli sync headers

* debug async snapshotter on goerly

* move verify headers, remove experiments, fix remove old snapshot

* save state

* refactor snapshotsync injection

* fix deadlock

* replace snapshot generation stage logic to migrate method

* change done for body snapshot

* clean

* clean&&change deleted value

* clean

* fix hash len

* fix hash len

* remove one of wrap methods, add remove snapshots on start

* add err check

* fix shadowing

* stages unwind order debug

* matryoshka experiments

* steam test

* fix build

* fix test

* fix lint

* fix test

* fix test datarace

* add get test

* return timeout

* fix mdbx overlap

* fix after merge

* change epoch size

* clean todo

* fix

* return testdata

* added return from sndownloader gorutine

* fix review comments

* Fix

* More info

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-08 09:45:40 +01:00

47 lines
1.0 KiB
Go

package commands
import (
"errors"
"fmt"
"time"
"github.com/anacrolix/torrent/bencode"
"github.com/anacrolix/torrent/metainfo"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/turbo/snapshotsync"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(snapshotMetainfoCmd)
}
func PrintMetaInfoHash(path string) error {
t := time.Now()
mi := metainfo.MetaInfo{}
info, err := snapshotsync.BuildInfoBytesForSnapshot(path, snapshotsync.MdbxFilename)
if err != nil {
return err
}
mi.InfoBytes, err = bencode.Marshal(info)
if err != nil {
return err
}
fmt.Println("infohash:", mi.HashInfoBytes().String())
fmt.Println("infobytes:", common.Bytes2Hex(mi.InfoBytes))
fmt.Println("It took", time.Since(t))
return nil
}
var snapshotMetainfoCmd = &cobra.Command{
Use: "snapshotMetainfo",
Short: "Calculate snapshot metainfo",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("empty path")
}
return PrintMetaInfoHash(args[0])
},
}