Skip to content

Commit

Permalink
removed save and load validators from store
Browse files Browse the repository at this point in the history
  • Loading branch information
chandiniv1 committed Nov 27, 2023
1 parent 4892ede commit 3fd7146
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 54 deletions.
52 changes: 5 additions & 47 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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.
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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})
}
9 changes: 2 additions & 7 deletions store/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}

0 comments on commit 3fd7146

Please sign in to comment.