mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package kv
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
bolt "go.etcd.io/bbolt"
|
|
)
|
|
|
|
var migrationArchivedIndex0Key = []byte("archive_index_0")
|
|
|
|
func migrateArchivedIndex(ctx context.Context, db *bolt.DB) error {
|
|
if updateErr := db.Update(func(tx *bolt.Tx) error {
|
|
mb := tx.Bucket(migrationsBucket)
|
|
if b := mb.Get(migrationArchivedIndex0Key); bytes.Equal(b, migrationCompleted) {
|
|
return nil // Migration already completed.
|
|
}
|
|
|
|
bkt := tx.Bucket(archivedRootBucket)
|
|
if bkt == nil {
|
|
return nil
|
|
}
|
|
// Remove "last archived index" key before iterating over all keys.
|
|
if err := bkt.Delete(lastArchivedIndexKey); err != nil {
|
|
return err
|
|
}
|
|
|
|
var highest types.Slot
|
|
c := bkt.Cursor()
|
|
for k, v := c.First(); k != nil; k, v = c.Next() {
|
|
// Look up actual slot from block
|
|
b := tx.Bucket(blocksBucket).Get(v)
|
|
// Skip this key if there is no block for whatever reason.
|
|
if b == nil {
|
|
continue
|
|
}
|
|
blk := ðpb.SignedBeaconBlock{}
|
|
if err := decode(context.TODO(), b, blk); err != nil {
|
|
return err
|
|
}
|
|
if err := tx.Bucket(stateSlotIndicesBucket).Put(bytesutil.SlotToBytesBigEndian(blk.Block.Slot), v); err != nil {
|
|
return err
|
|
}
|
|
if blk.Block.Slot > highest {
|
|
highest = blk.Block.Slot
|
|
}
|
|
// check if context is cancelled in between
|
|
if ctx.Err() != nil {
|
|
return ctx.Err()
|
|
}
|
|
}
|
|
|
|
// Delete deprecated buckets.
|
|
for _, bkt := range [][]byte{slotsHasObjectBucket, archivedRootBucket} {
|
|
if tx.Bucket(bkt) != nil {
|
|
if err := tx.DeleteBucket(bkt); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
// Mark migration complete.
|
|
return mb.Put(migrationArchivedIndex0Key, migrationCompleted)
|
|
}); updateErr != nil {
|
|
log.WithError(updateErr).Errorf("could not migrate bucket: %s", archivedRootBucket)
|
|
return updateErr
|
|
}
|
|
return nil
|
|
}
|