From 3fd7146303d5be9c8d113e22e282c8173969f403 Mon Sep 17 00:00:00 2001 From: chandiniv1 Date: Mon, 20 Nov 2023 14:43:10 +0530 Subject: [PATCH] removed save and load validators from store --- store/store.go | 52 +++++--------------------------------------------- store/types.go | 9 ++------- 2 files changed, 7 insertions(+), 54 deletions(-) diff --git a/store/store.go b/store/store.go index 7d46b5e76..5cfa344c4 100644 --- a/store/store.go +++ b/store/store.go @@ -8,8 +8,6 @@ import ( "sync/atomic" cmstate "github.com/cometbft/cometbft/proto/tendermint/state" - cmproto "github.com/cometbft/cometbft/proto/tendermint/types" - cmtypes "github.com/cometbft/cometbft/types" ds "github.com/ipfs/go-datastore" "go.uber.org/multierr" @@ -20,12 +18,11 @@ import ( ) var ( - blockPrefix = "b" - indexPrefix = "i" - commitPrefix = "c" - statePrefix = "s" - responsesPrefix = "r" - validatorsPrefix = "v" + blockPrefix = "b" + indexPrefix = "i" + commitPrefix = "c" + statePrefix = "s" + responsesPrefix = "r" ) // DefaultStore is a default store implmementation. @@ -199,41 +196,6 @@ func (s *DefaultStore) GetState() (types.State, error) { return state, err } -// SaveValidators stores validator set for given block height in store. -func (s *DefaultStore) SaveValidators(height uint64, validatorSet *cmtypes.ValidatorSet) error { - pbValSet, err := validatorSet.ToProto() - if err != nil { - return fmt.Errorf("failed to marshal ValidatorSet to protobuf: %w", err) - } - blob, err := pbValSet.Marshal() - if err != nil { - return fmt.Errorf("failed to marshal ValidatorSet: %w", err) - } - - return s.db.Put(s.ctx, ds.NewKey(getValidatorsKey(height)), blob) -} - -// GetValidators loads validator set at given block height from store. -func (s *DefaultStore) GetValidators(height uint64) (*cmtypes.ValidatorSet, error) { - blob, err := s.db.Get(s.ctx, ds.NewKey(getValidatorsKey(height))) - if err != nil { - return nil, fmt.Errorf("failed to load Validators for height %v: %w", height, err) - } - var pbValSet cmproto.ValidatorSet - err = pbValSet.Unmarshal(blob) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal to protobuf: %w", err) - } - if len(pbValSet.Validators) == 0 { - return &cmtypes.ValidatorSet{ - Validators: make([]*cmtypes.Validator, 0), - Proposer: nil, - }, nil - } - - return cmtypes.ValidatorSetFromProto(&pbValSet) -} - // loadHashFromIndex returns the hash of a block given its height func (s *DefaultStore) loadHashFromIndex(height uint64) (header.Hash, error) { blob, err := s.db.Get(s.ctx, ds.NewKey(getIndexKey(height))) @@ -266,7 +228,3 @@ func getStateKey() string { func getResponsesKey(height uint64) string { return GenerateKey([]interface{}{responsesPrefix, height}) } - -func getValidatorsKey(height uint64) string { - return GenerateKey([]interface{}{validatorsPrefix, height}) -} diff --git a/store/types.go b/store/types.go index 93a3bb6bb..dd7a47438 100644 --- a/store/types.go +++ b/store/types.go @@ -2,7 +2,6 @@ package store import ( cmstate "github.com/cometbft/cometbft/proto/tendermint/state" - cmtypes "github.com/cometbft/cometbft/types" "github.com/rollkit/rollkit/types" ) @@ -37,10 +36,6 @@ type Store interface { // UpdateState updates state saved in Store. Only one State is stored. // If there is no State in Store, state will be saved. UpdateState(state types.State) error - // GetState returns last state saved with UpdateState. - GetState() (types.State, error) - - SaveValidators(height uint64, validatorSet *cmtypes.ValidatorSet) error - - GetValidators(height uint64) (*cmtypes.ValidatorSet, error) + // LoadState returns last state saved with UpdateState. + LoadState() (types.State, error) }