mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-08 12:01:20 +00:00
8db5790838
* move experiments to new branch&reorganise kv_snapshot * walk&modify tests * added delete from snapshot tests * fmt * state snapshot debug * snapshot validation passed. copy state snapshot * debug * snapshot cursor.Prev test * Prev works correct. Added Current check * add err check * added walk forward and backward test * before refactoring * refactoring * execution with snapshot debug * fix * remove useless test * before dupcursor implimentation * tests with prev and delete works * execution based on state snapshot passed * remove useless tests * blocks to 1140000 passed * clean verifier * cleanup state generation * clean verify && seeder * remove debug code * tests passed * fix lint * save state * test passed * fix lint * add state hash * fix lint
114 lines
2.4 KiB
Go
114 lines
2.4 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
lg "github.com/anacrolix/log"
|
|
"github.com/anacrolix/torrent"
|
|
"github.com/anacrolix/torrent/bencode"
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
|
trnt "github.com/ledgerwatch/turbo-geth/turbo/snapshotsync/bittorrent"
|
|
)
|
|
|
|
func Seed(ctx context.Context, datadir string) error {
|
|
datadir = filepath.Dir(datadir)
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
defer cancel()
|
|
|
|
cfg := trnt.DefaultTorrentConfig()
|
|
cfg.NoDHT = false
|
|
cfg.DisableTrackers = false
|
|
cfg.Seed = true
|
|
cfg.Debug = false
|
|
cfg.Logger = cfg.Logger.FilterLevel(lg.Info)
|
|
cfg.DataDir = datadir
|
|
|
|
pathes := []string{
|
|
cfg.DataDir + "/headers",
|
|
cfg.DataDir + "/bodies",
|
|
cfg.DataDir + "/state",
|
|
//cfg.DataDir+"/receipts",
|
|
}
|
|
|
|
cl, err := torrent.NewClient(cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer cl.Close()
|
|
|
|
torrents := make([]*torrent.Torrent, len(pathes))
|
|
for i, v := range pathes {
|
|
i := i
|
|
mi := &metainfo.MetaInfo{
|
|
CreationDate: time.Now().Unix(),
|
|
CreatedBy: "turbogeth",
|
|
AnnounceList: trnt.Trackers,
|
|
}
|
|
|
|
if _, err := os.Stat(v); os.IsNotExist(err) {
|
|
fmt.Println(err)
|
|
continue
|
|
} else if err != nil {
|
|
return err
|
|
}
|
|
tt := time.Now()
|
|
if common.IsCanceled(ctx) {
|
|
return common.ErrStopped
|
|
}
|
|
info, err := trnt.BuildInfoBytesForLMDBSnapshot(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
mi.InfoBytes, err = bencode.Marshal(info)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
torrents[i], _, err = cl.AddTorrentSpec(&torrent.TorrentSpec{
|
|
Trackers: trnt.Trackers,
|
|
InfoHash: mi.HashInfoBytes(),
|
|
InfoBytes: mi.InfoBytes,
|
|
ChunkSize: trnt.DefaultChunkSize,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Info("Torrent added", "name", torrents[i].Info().Name, "path", v, "t", time.Since(tt))
|
|
|
|
if !torrents[i].Seeding() {
|
|
log.Warn(torrents[i].Name() + " not seeding")
|
|
}
|
|
|
|
if common.IsCanceled(ctx) {
|
|
return common.ErrStopped
|
|
}
|
|
|
|
torrents[i].VerifyData()
|
|
}
|
|
|
|
go func() {
|
|
ticker := time.NewTicker(10 * time.Second)
|
|
for range ticker.C {
|
|
for _, t := range cl.Torrents() {
|
|
log.Info("Snapshot stats", "snapshot", t.Name(), "active peers", t.Stats().ActivePeers, "seeding", t.Seeding(), "hash", t.Metainfo().HashInfoBytes().String())
|
|
}
|
|
|
|
if common.IsCanceled(ctx) {
|
|
ticker.Stop()
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
|
|
<-ctx.Done()
|
|
return nil
|
|
}
|