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

Check new state mgmt service is compatible with DB #5231

Merged
merged 6 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions beacon-chain/db/kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
"attestations.go",
"backup.go",
"blocks.go",
"check_state.go",
"checkpoint.go",
"deposit_contract.go",
"encoding.go",
Expand Down
33 changes: 33 additions & 0 deletions beacon-chain/db/kv/check_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package kv

import (
"errors"

"github.com/prysmaticlabs/prysm/shared/featureconfig"
bolt "go.etcd.io/bbolt"
)

var historicalStateDeletedKey = []byte("historical-states-deleted")

func (kv *Store) ensureNewStateServiceCompatible() error {
if !featureconfig.Get().NewStateMgmt {
return kv.db.Update(func(tx *bolt.Tx) error {
bkt := tx.Bucket(newStateServiceCompatibleBucket)
return bkt.Put(historicalStateDeletedKey, []byte{0x01})
})
}

var historicalStateDeleted bool
kv.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(newStateServiceCompatibleBucket)
v := bkt.Get(historicalStateDeletedKey)
historicalStateDeleted = len(v) == 1 && v[0] == 0x01
return nil
})

if historicalStateDeleted {
return errors.New("historical states were pruned in db, do not run with flag --new-state-mgmt")
}

return nil
}
8 changes: 6 additions & 2 deletions beacon-chain/db/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@ func NewKVStore(dirPath string) (*Store, error) {
blockSlotIndicesBucket,
blockParentRootIndicesBucket,
finalizedBlockRootsIndexBucket,
// Migration bucket.
migrationBucket,
// New State Management service bucket.
newStateServiceCompatibleBucket,
)
}); err != nil {
return nil, err
}

if err := kv.ensureNewStateServiceCompatible(); err != nil {
return nil, err
}

err = prometheus.Register(createBoltCollector(kv.db))

return kv, err
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/db/kv/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ var (
savedBlockSlotsKey = []byte("saved-block-slots")
savedStateSlotsKey = []byte("saved-state-slots")

// Migration bucket.
migrationBucket = []byte("migrations")
// New state management service compatibility bucket.
newStateServiceCompatibleBucket = []byte("new-state-compatible")
)