2021-05-08 08:45:40 +00:00
|
|
|
package snapshotsync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/binary"
|
2021-07-06 22:33:26 +00:00
|
|
|
"path/filepath"
|
2021-05-08 08:45:40 +00:00
|
|
|
"strconv"
|
|
|
|
|
2021-07-29 11:53:13 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
2021-05-08 08:45:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func SnapshotName(baseDir, name string, blockNum uint64) string {
|
2021-07-06 22:33:26 +00:00
|
|
|
return filepath.Join(baseDir, name) + strconv.FormatUint(blockNum, 10)
|
2021-05-08 08:45:40 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 02:47:38 +00:00
|
|
|
func GetSnapshotInfo(db kv.RwDB) (uint64, []byte, error) {
|
2021-06-05 15:17:04 +00:00
|
|
|
tx, err := db.BeginRo(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
2021-07-28 02:47:38 +00:00
|
|
|
v, err := tx.GetOne(kv.BittorrentInfo, kv.CurrentHeadersSnapshotBlock)
|
2021-06-05 15:17:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
if v == nil {
|
2021-05-08 08:45:40 +00:00
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
var snapshotBlock uint64
|
|
|
|
if len(v) == 8 {
|
|
|
|
snapshotBlock = binary.BigEndian.Uint64(v)
|
|
|
|
}
|
|
|
|
|
2021-07-28 02:47:38 +00:00
|
|
|
infohash, err := tx.GetOne(kv.BittorrentInfo, kv.CurrentHeadersSnapshotHash)
|
2021-06-05 15:17:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
if infohash == nil {
|
2021-05-08 08:45:40 +00:00
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
return snapshotBlock, infohash, nil
|
|
|
|
}
|