Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move migrations to kv interfaces #2430

Merged
merged 4 commits into from
Jul 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
save
AskAlexSharov committed Jul 24, 2021
commit 237d07324245651baac893adfe0a673636e6afa2
19 changes: 11 additions & 8 deletions turbo/snapshotsync/postprocessing.go
Original file line number Diff line number Diff line change
@@ -40,23 +40,26 @@ var (
Snapshot11kkTD = []byte{138, 3, 199, 118, 5, 203, 95, 162, 81, 64, 161}
)

func PostProcessing(tx ethdb.RwTx, downloadedSnapshots map[SnapshotType]*SnapshotsInfo) error {
func PostProcessing(db ethdb.RwKV, downloadedSnapshots map[SnapshotType]*SnapshotsInfo) error {
if _, ok := downloadedSnapshots[SnapshotType_headers]; ok {
err := GenerateHeaderIndexes(context.Background(), tx)
if err != nil {
if err := db.Update(context.Background(), func(tx ethdb.RwTx) error {
return GenerateHeaderIndexes(context.Background(), tx)
}); err != nil {
return err
}
}
if _, ok := downloadedSnapshots[SnapshotType_state]; ok {
err := PostProcessState(tx, downloadedSnapshots[SnapshotType_state])
if err != nil {
if err := db.Update(context.Background(), func(tx ethdb.RwTx) error {
return PostProcessState(tx, downloadedSnapshots[SnapshotType_state])
}); err != nil {
return err
}
}

if _, ok := downloadedSnapshots[SnapshotType_bodies]; ok {
err := PostProcessBodies(tx)
if err != nil {
if err := db.Update(context.Background(), func(tx ethdb.RwTx) error {
return PostProcessBodies(tx)
}); err != nil {
return err
}
}
@@ -325,7 +328,7 @@ func GenerateHeaderIndexes(ctx context.Context, tx ethdb.RwTx) error {
return err1
}

return tx.Commit()
return nil
}
return nil
}
8 changes: 2 additions & 6 deletions turbo/snapshotsync/wrapdb.go
Original file line number Diff line number Diff line change
@@ -171,9 +171,7 @@ func DownloadSnapshots(torrentClient *Client, ExternalSnapshotDownloaderAddr str
}
chainDb.(ethdb.HasRwKV).SetRwKV(snapshotKV)

if err := chainDb.RwKV().Update(context.Background(), func(tx ethdb.RwTx) error {
return PostProcessing(tx, downloadedSnapshots)
}); err != nil {
if err := PostProcessing(chainDb.RwKV(), downloadedSnapshots); err != nil {
return err
}

@@ -206,9 +204,7 @@ func DownloadSnapshots(torrentClient *Client, ExternalSnapshotDownloaderAddr str
return innerErr
}
chainDb.(ethdb.HasRwKV).SetRwKV(snapshotKV)
if err := chainDb.RwKV().Update(context.Background(), func(tx ethdb.RwTx) error {
return PostProcessing(tx, downloadedSnapshots)
}); err != nil {
if err := PostProcessing(snapshotKV, downloadedSnapshots); err != nil {

return err
}