mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-27 22:28:21 +00:00
4ebade3583
* save state * torrent experiments * torrent experiment passed * fixes after merge * snapshot headers processing passed * save state * save state * download headers works after snapshot processing * save state * save state * save state * save state * add lazy load tx to snapshots, increase number of trackers * save state * speedup getting info * change logging * move to turbo package * save state * save state * save state * cleanup * save state * add test test * save state * lmdb debugging * fix readonly mode * save state * fix build * sync works * save state * save state * save state * allow cmd stages stageSenders use snapshots * debugging failed hashing * remove experimental tests * remove torrent experimental tests * fix lint * extract snapshot wrapper * metainfo checker * add remote seeder * add logs * update gomod * remove useless code * fix lint&remove useless code * extract verify snapshot to separated command * skip debug test * fix test * change type of seedSnapshot flag * add eth logger to torrent lib * skip debug test * add Close method * review fixes * fix lint Co-authored-by: alex.sharov <AskAlexSharov@gmail.com> Co-authored-by: Alexey Akhunov <akhounov@gmail.com>
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package generate
|
|
|
|
import (
|
|
"context"
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
|
"github.com/ledgerwatch/turbo-geth/turbo/torrent"
|
|
"os"
|
|
"os/signal"
|
|
"time"
|
|
)
|
|
|
|
func SeedSnapshots(dir string) error {
|
|
client := torrent.New(dir, torrent.SnapshotMode{
|
|
Headers: true,
|
|
Bodies: true,
|
|
State: false,
|
|
Receipts: false,
|
|
}, true)
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, os.Interrupt)
|
|
go func() {
|
|
<-c
|
|
cancel()
|
|
}()
|
|
|
|
db := ethdb.NewLMDB().Path(dir + "/tmpdb").MustOpen()
|
|
err := client.Run(ethdb.NewObjectDatabase(db))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
go func() {
|
|
ticker := time.NewTicker(10 * time.Second)
|
|
for range ticker.C {
|
|
for _, t := range client.Cli.Torrents() {
|
|
log.Info("Snapshot stats", "snapshot", t.Name(), "active peers", t.Stats().ActivePeers, "seeding", t.Seeding())
|
|
}
|
|
if common.IsCanceled(ctx) {
|
|
ticker.Stop()
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
|
|
<-ctx.Done()
|
|
return nil
|
|
}
|