erigon-pulse/turbo/snapshotsync/bittorrent/server.go
b00ris 8db5790838
State snapshot sync (#1417)
* 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
2021-01-02 19:28:37 +00:00

58 lines
1.5 KiB
Go

package bittorrent
import (
"context"
"errors"
"github.com/golang/protobuf/ptypes/empty"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/turbo/snapshotsync"
)
var (
ErrNotSupportedNetworkID = errors.New("not supported network id")
ErrNotSupportedSnapshot = errors.New("not supported snapshot for this network id")
)
var (
_ snapshotsync.DownloaderServer = &SNDownloaderServer{}
)
func NewServer(dir string, seeding bool) (*SNDownloaderServer, error) {
downloader, err := New(dir, seeding)
if err != nil {
return nil, err
}
return &SNDownloaderServer{
t: downloader,
db: ethdb.MustOpen(dir + "/db"),
}, nil
}
type SNDownloaderServer struct {
snapshotsync.DownloaderServer
t *Client
db ethdb.Database
}
func (S *SNDownloaderServer) Download(ctx context.Context, request *snapshotsync.DownloadSnapshotRequest) (*empty.Empty, error) {
err := S.t.AddSnapshotsTorrents(ctx, S.db, request.NetworkId, snapshotsync.FromSnapshotTypes(request.Type))
if err != nil {
return nil, err
}
return &empty.Empty{}, nil
}
func (S *SNDownloaderServer) Load() error {
return S.t.Load(S.db)
}
func (S *SNDownloaderServer) Snapshots(ctx context.Context, request *snapshotsync.SnapshotsRequest) (*snapshotsync.SnapshotsInfoReply, error) {
reply := snapshotsync.SnapshotsInfoReply{}
resp, err := S.t.GetSnapshots(S.db, request.NetworkId)
if err != nil {
return nil, err
}
for i := range resp {
reply.Info = append(reply.Info, resp[i])
}
return &reply, nil
}