Skip to content

Commit

Permalink
fix(code standards): use kv naming in store where appropriate (dymens…
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt authored May 22, 2024
1 parent 6d2ecff commit a10ad36
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion da/avail/avail.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func WithBatchRetryAttempts(attempts uint) da.Option {
}

// Init initializes DataAvailabilityLayerClient instance.
func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KVStore, logger types.Logger, options ...da.Option) error {
func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KV, logger types.Logger, options ...da.Option) error {
c.logger = logger
c.synced = make(chan struct{}, 1)

Expand Down
2 changes: 1 addition & 1 deletion da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func WithSubmitBackoff(c uretry.BackoffConfig) da.Option {
}

// Init initializes DataAvailabilityLayerClient instance.
func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KVStore, logger types.Logger, options ...da.Option) error {
func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KV, logger types.Logger, options ...da.Option) error {
c.logger = logger
c.synced = make(chan struct{}, 1)
var err error
Expand Down
2 changes: 1 addition & 1 deletion da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ type ResultRetrieveBatch struct {
// It also contains life-cycle methods.
type DataAvailabilityLayerClient interface {
// Init is called once to allow DA client to read configuration and initialize resources.
Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KVStore, logger types.Logger, options ...Option) error
Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KV, logger types.Logger, options ...Option) error

// Start is called once, after Init. It's implementation should start operation of DataAvailabilityLayerClient.
Start() error
Expand Down
2 changes: 1 addition & 1 deletion da/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
)

// Init sets the configuration options.
func (d *DataAvailabilityLayerClient) Init(config []byte, _ *pubsub.Server, _ store.KVStore, logger types.Logger, options ...da.Option) error {
func (d *DataAvailabilityLayerClient) Init(config []byte, _ *pubsub.Server, _ store.KV, logger types.Logger, options ...da.Option) error {
d.logger = logger
if len(config) == 0 {
d.config = DefaultConfig
Expand Down
2 changes: 1 addition & 1 deletion da/grpc/mockserv/mockserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// GetServer creates and returns gRPC server instance.
func GetServer(kv store.KVStore, conf grpcda.Config, mockConfig []byte) *grpc.Server {
func GetServer(kv store.KV, conf grpcda.Config, mockConfig []byte) *grpc.Server {
logger := tmlog.NewTMLogger(os.Stdout)

srv := grpc.NewServer()
Expand Down
4 changes: 2 additions & 2 deletions da/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// It does actually ensures DA - it stores data in-memory.
type DataAvailabilityLayerClient struct {
logger types.Logger
dalcKV store.KVStore
dalcKV store.KV
daHeight atomic.Uint64
config config
synced chan struct{}
Expand All @@ -35,7 +35,7 @@ var (
)

// Init is called once to allow DA client to read configuration and initialize resources.
func (m *DataAvailabilityLayerClient) Init(config []byte, _ *pubsub.Server, dalcKV store.KVStore, logger types.Logger, options ...da.Option) error {
func (m *DataAvailabilityLayerClient) Init(config []byte, _ *pubsub.Server, dalcKV store.KV, logger types.Logger, options ...da.Option) error {
m.logger = logger
m.dalcKV = dalcKV
m.daHeight.Store(1)
Expand Down
6 changes: 3 additions & 3 deletions indexers/blockindexer/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ var _ indexer.BlockIndexer = (*BlockerIndexer)(nil)
// events with an underlying KV store. Block events are indexed by their height,
// such that matching search criteria returns the respective block height(s).
type BlockerIndexer struct {
store store.KVStore
store store.KV
}

func New(store store.KVStore) *BlockerIndexer {
func New(store store.KV) *BlockerIndexer {
return &BlockerIndexer{
store: store,
}
Expand Down Expand Up @@ -480,7 +480,7 @@ func (idx *BlockerIndexer) match(
return filteredHeights, nil
}

func (idx *BlockerIndexer) indexEvents(batch store.Batch, events []abci.Event, typ string, height int64) error {
func (idx *BlockerIndexer) indexEvents(batch store.KVBatch, events []abci.Event, typ string, height int64) error {
heightBz := int64ToBytes(height)

for _, event := range events {
Expand Down
6 changes: 3 additions & 3 deletions indexers/txindex/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ var _ txindex.TxIndexer = (*TxIndex)(nil)

// TxIndex is the simplest possible indexer, backed by key-value storage (levelDB).
type TxIndex struct {
store store.KVStore
store store.KV
}

// NewTxIndex creates new KV indexer.
func NewTxIndex(store store.KVStore) *TxIndex {
func NewTxIndex(store store.KV) *TxIndex {
return &TxIndex{
store: store,
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func (txi *TxIndex) Index(result *abci.TxResult) error {
return b.Commit()
}

func (txi *TxIndex) indexEvents(result *abci.TxResult, hash []byte, store store.Batch) error {
func (txi *TxIndex) indexEvents(result *abci.TxResult, hash []byte, store store.KVBatch) error {
for _, event := range result.Result.Events {
// only index events with a non-empty type
if len(event.Type) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NewNode(

pubsubServer := pubsub.NewServer()

var baseKV store.KVStore
var baseKV store.KV
if conf.RootDir == "" && conf.DBPath == "" { // this is used for testing
logger.Info("WARNING: working in in-memory mode")
baseKV = store.NewDefaultInMemoryKVStore()
Expand Down Expand Up @@ -341,7 +341,7 @@ func (n *Node) ProxyApp() proxy.AppConns {

func createAndStartIndexerService(
conf config.NodeConfig,
kvStore store.KVStore,
kvStore store.KV,
eventBus *tmtypes.EventBus,
logger log.Logger,
) (*txindex.IndexerService, txindex.TxIndexer, indexer.BlockIndexer, error) {
Expand Down
2 changes: 1 addition & 1 deletion settlement/grpc/mockserv/mockserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (

type server struct {
slmock.UnimplementedMockSLServer
kv store.KVStore
kv store.KV
}

func getKey(key uint64) []byte {
Expand Down
4 changes: 2 additions & 2 deletions settlement/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type HubClient struct {
mu sync.Mutex // keep the following in sync with *each other*
slStateIndex uint64
latestHeight uint64
settlementKV store.KVStore
settlementKV store.KV
}

var _ settlement.HubClient = &HubClient{}
Expand Down Expand Up @@ -112,7 +112,7 @@ func newHubClient(config settlement.Config, pubsub *pubsub.Server, logger types.
}, nil
}

func initConfig(conf settlement.Config) (slstore store.KVStore, proposer string, err error) {
func initConfig(conf settlement.Config) (slstore store.KV, proposer string, err error) {
if conf.KeyringHomeDir == "" {
// init store
slstore = store.NewDefaultInMemoryKVStore()
Expand Down
10 changes: 5 additions & 5 deletions store/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

var (
_ KVStore = &BadgerKV{}
_ Batch = &BadgerBatch{}
_ KV = &BadgerKV{}
_ KVBatch = &BadgerBatch{}
)

// ErrKeyNotFound is returned if key is not found in KVStore.
Expand Down Expand Up @@ -57,7 +57,7 @@ func (b *BadgerKV) Delete(key []byte) error {

// NewBatch creates new batch.
// Note: badger batches should be short lived as they use extra resources.
func (b *BadgerKV) NewBatch() Batch {
func (b *BadgerKV) NewBatch() KVBatch {
return &BadgerBatch{
txn: b.db.NewTransaction(true),
}
Expand Down Expand Up @@ -92,10 +92,10 @@ func (bb *BadgerBatch) Discard() {
bb.txn.Discard()
}

var _ Iterator = &BadgerIterator{}
var _ KVIterator = &BadgerIterator{}

// PrefixIterator returns instance of prefix Iterator for BadgerKV.
func (b *BadgerKV) PrefixIterator(prefix []byte) Iterator {
func (b *BadgerKV) PrefixIterator(prefix []byte) KVIterator {
txn := b.db.NewTransaction(false)
iter := txn.NewIterator(badger.DefaultIteratorOptions)
iter.Seek(prefix)
Expand Down
4 changes: 2 additions & 2 deletions store/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// NewDefaultInMemoryKVStore builds KVStore that works in-memory (without accessing disk).
func NewDefaultInMemoryKVStore() KVStore {
func NewDefaultInMemoryKVStore() KV {
db, err := badger.Open(badger.DefaultOptions("").WithInMemory(true))
if err != nil {
panic(err)
Expand All @@ -18,7 +18,7 @@ func NewDefaultInMemoryKVStore() KVStore {
}

// NewDefaultKVStore creates instance of default key-value store.
func NewDefaultKVStore(rootDir, dbPath, dbName string) KVStore {
func NewDefaultKVStore(rootDir, dbPath, dbName string) KV {
path := filepath.Join(rootify(rootDir, dbPath), dbName)
db, err := badger.Open(badger.DefaultOptions(path))
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions store/prefix.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package store

var (
_ KVStore = &PrefixKV{}
_ Batch = &PrefixKVBatch{}
_ KV = &PrefixKV{}
_ KVBatch = &PrefixKVBatch{}
)

// PrefixKV is a key-value store that prepends all keys with given prefix.
type PrefixKV struct {
kv KVStore
kv KV
prefix []byte
}

// NewPrefixKV creates new PrefixKV on top of other KVStore.
func NewPrefixKV(kv KVStore, prefix []byte) *PrefixKV {
func NewPrefixKV(kv KV, prefix []byte) *PrefixKV {
return &PrefixKV{
kv: kv,
prefix: prefix,
Expand All @@ -35,21 +35,21 @@ func (p *PrefixKV) Delete(key []byte) error {
}

// NewBatch creates a new batch.
func (p *PrefixKV) NewBatch() Batch {
func (p *PrefixKV) NewBatch() KVBatch {
return &PrefixKVBatch{
b: p.kv.NewBatch(),
prefix: p.prefix,
}
}

// PrefixIterator creates iterator to traverse given prefix.
func (p *PrefixKV) PrefixIterator(prefix []byte) Iterator {
func (p *PrefixKV) PrefixIterator(prefix []byte) KVIterator {
return p.kv.PrefixIterator(append(p.prefix, prefix...))
}

// PrefixKVBatch enables batching of operations on PrefixKV.
type PrefixKVBatch struct {
b Batch
b KVBatch
prefix []byte
}

Expand Down
2 changes: 1 addition & 1 deletion store/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (s *DefaultStore) PruneBlocks(from, to uint64) (uint64, error) {
batch := s.db.NewBatch()
defer batch.Discard()

flush := func(batch Batch, height uint64) error {
flush := func(batch KVBatch, height uint64) error {
err := batch.Commit()
if err != nil {
return fmt.Errorf("flush batch to disk: height %d: %w", height, err)
Expand Down
14 changes: 7 additions & 7 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ var (

// DefaultStore is a default store implementation.
type DefaultStore struct {
db KVStore
db KV
}

var _ Store = &DefaultStore{}

// New returns new, default store.
func New(kv KVStore) Store {
func New(kv KV) Store {
return &DefaultStore{
db: kv,
}
}

// NewBatch creates a new db batch.
func (s *DefaultStore) NewBatch() Batch {
func (s *DefaultStore) NewBatch() KVBatch {
return s.db.NewBatch()
}

// SaveBlock adds block to the store along with corresponding commit.
// Stored height is updated if block height is greater than stored value.
// In case a batch is provided, the block and commit are added to the batch and not saved.
func (s *DefaultStore) SaveBlock(block *types.Block, commit *types.Commit, batch Batch) (Batch, error) {
func (s *DefaultStore) SaveBlock(block *types.Block, commit *types.Commit, batch KVBatch) (KVBatch, error) {
hash := block.Header.Hash()
blockBlob, err := block.MarshalBinary()
if err != nil {
Expand Down Expand Up @@ -110,7 +110,7 @@ func (s *DefaultStore) LoadBlockByHash(hash [32]byte) (*types.Block, error) {
}

// SaveBlockResponses saves block responses (events, tx responses, validator set updates, etc) in Store.
func (s *DefaultStore) SaveBlockResponses(height uint64, responses *tmstate.ABCIResponses, batch Batch) (Batch, error) {
func (s *DefaultStore) SaveBlockResponses(height uint64, responses *tmstate.ABCIResponses, batch KVBatch) (KVBatch, error) {
data, err := responses.Marshal()
if err != nil {
return batch, fmt.Errorf("marshal response: %w", err)
Expand Down Expand Up @@ -161,7 +161,7 @@ func (s *DefaultStore) LoadCommitByHash(hash [32]byte) (*types.Commit, error) {

// UpdateState updates state saved in Store. Only one State is stored.
// If there is no State in Store, state will be saved.
func (s *DefaultStore) SaveState(state *types.State, batch Batch) (Batch, error) {
func (s *DefaultStore) SaveState(state *types.State, batch KVBatch) (KVBatch, error) {
pbState, err := state.ToProto()
if err != nil {
return batch, fmt.Errorf("marshal state to JSON: %w", err)
Expand Down Expand Up @@ -200,7 +200,7 @@ func (s *DefaultStore) LoadState() (*types.State, error) {
}

// SaveValidators stores validator set for given block height in store.
func (s *DefaultStore) SaveValidators(height uint64, validatorSet *tmtypes.ValidatorSet, batch Batch) (Batch, error) {
func (s *DefaultStore) SaveValidators(height uint64, validatorSet *tmtypes.ValidatorSet, batch KVBatch) (KVBatch, error) {
pbValSet, err := validatorSet.ToProto()
if err != nil {
return batch, fmt.Errorf("marshal ValidatorSet to protobuf: %w", err)
Expand Down
Loading

0 comments on commit a10ad36

Please sign in to comment.