mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 04:00:05 +00:00
Fix state gen migration (#5858)
* Remove useless `currentSplitSlot == 0` * Increase slots per archived point to 2048 * Don't delete last archived state * Revert back to 256 * Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-migration-delete-latest-state * Don't delete last archived state * Regression test * Revert
This commit is contained in:
parent
7a8e85af9e
commit
2f27966b44
@ -20,7 +20,7 @@ func (s *State) MigrateToCold(ctx context.Context, finalizedSlot uint64, finaliz
|
||||
// Verify migration is sensible. The new finalized point must increase the current split slot, and
|
||||
// on an epoch boundary for hot state summary scheme to work.
|
||||
currentSplitSlot := s.splitInfo.slot
|
||||
if currentSplitSlot == 0 || currentSplitSlot > finalizedSlot {
|
||||
if currentSplitSlot > finalizedSlot {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -74,7 +74,8 @@ func (s *State) MigrateToCold(ctx context.Context, finalizedSlot uint64, finaliz
|
||||
// Do not delete the current finalized state in case user wants to
|
||||
// switch back to old state service, deleting the recent finalized state
|
||||
// could cause issue switching back.
|
||||
if s.beaconDB.HasState(ctx, r) && r != finalizedRoot {
|
||||
lastArchivedIndexRoot := s.beaconDB.LastArchivedIndexRoot(ctx)
|
||||
if s.beaconDB.HasState(ctx, r) && r != lastArchivedIndexRoot && r != finalizedRoot {
|
||||
if err := s.beaconDB.DeleteState(ctx, r); err != nil {
|
||||
// For whatever reason if node is unable to delete a state due to
|
||||
// state is finalized, it is more reasonable to continue than to exit.
|
||||
|
@ -105,3 +105,71 @@ func TestMigrateToCold_MigrationCompletes(t *testing.T) {
|
||||
testutil.AssertLogsContain(t, hook, "Deleted state during migration")
|
||||
testutil.AssertLogsContain(t, hook, "Set hot and cold state split point")
|
||||
}
|
||||
|
||||
func TestMigrateToCold_CantDeleteCurrentArchivedIndex(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service.splitInfo.slot = 1
|
||||
service.slotsPerArchivedPoint = 2
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{Slot: 2},
|
||||
}
|
||||
if err := service.beaconDB.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bRoot, err := stateutil.BlockRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Root: bRoot[:], Slot: 2}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, beaconState, bRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
newBeaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
if err := newBeaconState.SetSlot(3); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b = ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{Slot: 3},
|
||||
}
|
||||
if err := service.beaconDB.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bRoot, err = stateutil.BlockRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Root: bRoot[:], Slot: 3}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, newBeaconState, bRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveArchivedPointRoot(ctx, bRoot, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveLastArchivedIndex(ctx, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := service.MigrateToCold(ctx, beaconState.Slot(), [32]byte{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !service.beaconDB.HasArchivedPoint(ctx, 1) {
|
||||
t.Error("Did not preserve archived point")
|
||||
}
|
||||
if !service.beaconDB.HasState(ctx, bRoot) {
|
||||
t.Error("State should not be deleted")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user