Skip to content

Commit f126599

Browse files
deepakgudlaGanesha Upadhyaya
authored andcommitted
renamed Store Interface Load methods to Get (#1349)
closes: #1284 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> - **Refactor** - Updated method names for data retrieval across the application for improved clarity and consistency. - **Tests** - Adjusted test cases to align with the updated method names in the data retrieval process. - **Documentation** - Revised documentation to reflect the changes in method naming conventions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 18bfb14 commit f126599

8 files changed

Lines changed: 66 additions & 66 deletions

File tree

block/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type Manager struct {
9696

9797
// getInitialState tries to load lastState from Store, and if it's not available it reads GenesisDoc.
9898
func getInitialState(store store.Store, genesis *cmtypes.GenesisDoc) (types.State, error) {
99-
s, err := store.LoadState()
99+
s, err := store.GetState()
100100
if err != nil {
101101
s, err = types.NewFromGenesisDoc(genesis)
102102
}
@@ -597,11 +597,11 @@ func (m *Manager) publishBlock(ctx context.Context) error {
597597
if newHeight == uint64(m.genesis.InitialHeight) {
598598
lastCommit = &types.Commit{}
599599
} else {
600-
lastCommit, err = m.store.LoadCommit(height)
600+
lastCommit, err = m.store.GetCommit(height)
601601
if err != nil {
602602
return fmt.Errorf("error while loading last commit: %w", err)
603603
}
604-
lastBlock, err := m.store.LoadBlock(height)
604+
lastBlock, err := m.store.GetBlock(height)
605605
if err != nil {
606606
return fmt.Errorf("error while loading last block: %w", err)
607607
}
@@ -613,7 +613,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
613613

614614
// Check if there's an already stored block at a newer height
615615
// If there is use that instead of creating a new block
616-
pendingBlock, err := m.store.LoadBlock(newHeight)
616+
pendingBlock, err := m.store.GetBlock(newHeight)
617617
if err == nil {
618618
m.logger.Info("Using pending block", "height", newHeight)
619619
block = pendingBlock

node/full_client.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (c *FullClient) BlockchainInfo(ctx context.Context, minHeight, maxHeight in
315315

316316
blocks := make([]*cmtypes.BlockMeta, 0, maxHeight-minHeight+1)
317317
for height := maxHeight; height >= minHeight; height-- {
318-
block, err := c.node.Store.LoadBlock(uint64(height))
318+
block, err := c.node.Store.GetBlock(uint64(height))
319319
if err != nil {
320320
return nil, err
321321
}
@@ -405,7 +405,7 @@ func (c *FullClient) Health(ctx context.Context) (*ctypes.ResultHealth, error) {
405405
// If height is nil, it returns information about last known block.
406406
func (c *FullClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) {
407407
heightValue := c.normalizeHeight(height)
408-
block, err := c.node.Store.LoadBlock(heightValue)
408+
block, err := c.node.Store.GetBlock(heightValue)
409409
if err != nil {
410410
return nil, err
411411
}
@@ -428,7 +428,7 @@ func (c *FullClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBl
428428

429429
// BlockByHash returns BlockID and block itself for given hash.
430430
func (c *FullClient) BlockByHash(ctx context.Context, hash []byte) (*ctypes.ResultBlock, error) {
431-
block, err := c.node.Store.LoadBlockByHash(hash)
431+
block, err := c.node.Store.GetBlockByHash(hash)
432432
if err != nil {
433433
return nil, err
434434
}
@@ -461,7 +461,7 @@ func (c *FullClient) BlockResults(ctx context.Context, height *int64) (*ctypes.R
461461
if err != nil {
462462
return nil, err
463463
}
464-
resp, err := c.node.Store.LoadBlockResponses(h)
464+
resp, err := c.node.Store.GetBlockResponses(h)
465465
if err != nil {
466466
return nil, err
467467
}
@@ -479,11 +479,11 @@ func (c *FullClient) BlockResults(ctx context.Context, height *int64) (*ctypes.R
479479
// Commit returns signed header (aka commit) at given height.
480480
func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) {
481481
heightValue := c.normalizeHeight(height)
482-
com, err := c.node.Store.LoadCommit(heightValue)
482+
com, err := c.node.Store.GetCommit(heightValue)
483483
if err != nil {
484484
return nil, err
485485
}
486-
b, err := c.node.Store.LoadBlock(heightValue)
486+
b, err := c.node.Store.GetBlock(heightValue)
487487
if err != nil {
488488
return nil, err
489489
}
@@ -499,7 +499,7 @@ func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultC
499499
// Validators returns paginated list of validators at given height.
500500
func (c *FullClient) Validators(ctx context.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error) {
501501
height := c.normalizeHeight(heightPtr)
502-
validators, err := c.node.Store.LoadValidators(height)
502+
validators, err := c.node.Store.GetValidators(height)
503503
if err != nil {
504504
return nil, fmt.Errorf("failed to load validators for height %d: %w", height, err)
505505
}
@@ -537,7 +537,7 @@ func (c *FullClient) Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.R
537537

538538
var proof cmtypes.TxProof
539539
if prove {
540-
block, _ := c.node.Store.LoadBlock(uint64(height))
540+
block, _ := c.node.Store.GetBlock(uint64(height))
541541
blockProof := block.Data.Txs.Proof(int(index)) // XXX: overflow on 32-bit machines
542542
proof = cmtypes.TxProof{
543543
RootHash: blockProof.RootHash,
@@ -606,7 +606,7 @@ func (c *FullClient) TxSearch(ctx context.Context, query string, prove bool, pag
606606

607607
var proof cmtypes.TxProof
608608
/*if prove {
609-
block := nil //env.BlockStore.LoadBlock(r.Height)
609+
block := nil //env.BlockStore.GetBlock(r.Height)
610610
proof = block.Data.Txs.Proof(int(r.Index)) // XXX: overflow on 32-bit machines
611611
}*/
612612

@@ -666,7 +666,7 @@ func (c *FullClient) BlockSearch(ctx context.Context, query string, page, perPag
666666
// Fetch the blocks
667667
blocks := make([]*ctypes.ResultBlock, 0, pageSize)
668668
for i := skipCount; i < skipCount+pageSize; i++ {
669-
b, err := c.node.Store.LoadBlock(uint64(results[i]))
669+
b, err := c.node.Store.GetBlock(uint64(results[i]))
670670
if err != nil {
671671
return nil, err
672672
}
@@ -687,23 +687,23 @@ func (c *FullClient) BlockSearch(ctx context.Context, query string, page, perPag
687687

688688
// Status returns detailed information about current status of the node.
689689
func (c *FullClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
690-
latest, err := c.node.Store.LoadBlock(c.node.Store.Height())
690+
latest, err := c.node.Store.GetBlock(c.node.Store.Height())
691691
if err != nil {
692692
return nil, fmt.Errorf("failed to find latest block: %w", err)
693693
}
694694

695-
initial, err := c.node.Store.LoadBlock(uint64(c.node.GetGenesis().InitialHeight))
695+
initial, err := c.node.Store.GetBlock(uint64(c.node.GetGenesis().InitialHeight))
696696
if err != nil {
697697
return nil, fmt.Errorf("failed to find earliest block: %w", err)
698698
}
699699

700-
validators, err := c.node.Store.LoadValidators(latest.Height())
700+
validators, err := c.node.Store.GetValidators(latest.Height())
701701
if err != nil {
702702
return nil, fmt.Errorf("failed to fetch the validator info at latest block: %w", err)
703703
}
704704
_, validator := validators.GetByAddress(latest.SignedHeader.ProposerAddress)
705705

706-
state, err := c.node.Store.LoadState()
706+
state, err := c.node.Store.GetState()
707707
if err != nil {
708708
return nil, fmt.Errorf("failed to load the last saved state: %w", err)
709709
}
@@ -807,7 +807,7 @@ func (c *FullClient) HeaderByHash(ctx context.Context, hash cmbytes.HexBytes) (*
807807
// decoding logic in the HTTP service will correctly translate from JSON.
808808
// See https://github.com/cometbft/cometbft/issues/6802 for context.
809809

810-
block, err := c.node.Store.LoadBlockByHash(types.Hash(hash))
810+
block, err := c.node.Store.GetBlockByHash(types.Hash(hash))
811811
if err != nil {
812812
return nil, err
813813
}
@@ -891,7 +891,7 @@ func (c *FullClient) normalizeHeight(height *int64) uint64 {
891891
}
892892

893893
func (rpc *FullClient) getBlockMeta(n int64) *cmtypes.BlockMeta {
894-
b, err := rpc.node.Store.LoadBlock(uint64(n))
894+
b, err := rpc.node.Store.GetBlock(uint64(n))
895895
if err != nil {
896896
return nil
897897
}

node/full_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *t
4848
}
4949

5050
func getBlockMeta(rpc *FullClient, n int64) *cmtypes.BlockMeta {
51-
b, err := rpc.node.Store.LoadBlock(uint64(n))
51+
b, err := rpc.node.Store.GetBlock(uint64(n))
5252
if err != nil {
5353
return nil
5454
}
@@ -1109,7 +1109,7 @@ func TestStatus(t *testing.T) {
11091109

11101110
// specific validation
11111111
assert.Equal(tconfig.DefaultBaseConfig().Moniker, resp.NodeInfo.Moniker)
1112-
state, err := rpc.node.Store.LoadState()
1112+
state, err := rpc.node.Store.GetState()
11131113
assert.NoError(err)
11141114
defaultProtocolVersion := p2p.NewProtocolVersion(
11151115
version.P2PProtocol,

node/full_node_integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ func TestTxGossipingAndAggregation(t *testing.T) {
133133

134134
// assert that all blocks known to node are same as produced by aggregator
135135
for h := uint64(1); h <= nodes[i].Store.Height(); h++ {
136-
aggBlock, err := nodes[0].Store.LoadBlock(h)
136+
aggBlock, err := nodes[0].Store.GetBlock(h)
137137
require.NoError(err)
138-
nodeBlock, err := nodes[i].Store.LoadBlock(h)
138+
nodeBlock, err := nodes[i].Store.GetBlock(h)
139139
require.NoError(err)
140140
assert.Equal(aggBlock, nodeBlock, fmt.Sprintf("height: %d", h))
141141
}
@@ -289,7 +289,7 @@ func TestFastDASync(t *testing.T) {
289289
// Verify that the block we synced to is DA included. This is to
290290
// ensure that the test is passing due to the DA syncing, since the P2P
291291
// block sync will sync quickly but the block won't be DA included.
292-
block, err := node2.Store.LoadBlock(numberOfBlocksToSyncTill)
292+
block, err := node2.Store.GetBlock(numberOfBlocksToSyncTill)
293293
require.NoError(err)
294294
require.True(node2.blockManager.IsDAIncluded(block.Hash()))
295295
}

store/store.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ func (s *DefaultStore) SaveBlock(block *types.Block, commit *types.Commit) error
9494
return nil
9595
}
9696

97-
// LoadBlock returns block at given height, or error if it's not found in Store.
97+
// GetBlock returns block at given height, or error if it's not found in Store.
9898
// TODO(tzdybal): what is more common access pattern? by height or by hash?
9999
// currently, we're indexing height->hash, and store blocks by hash, but we might as well store by height
100100
// and index hash->height
101-
func (s *DefaultStore) LoadBlock(height uint64) (*types.Block, error) {
101+
func (s *DefaultStore) GetBlock(height uint64) (*types.Block, error) {
102102
h, err := s.loadHashFromIndex(height)
103103
if err != nil {
104104
return nil, fmt.Errorf("failed to load hash from index: %w", err)
105105
}
106-
return s.LoadBlockByHash(h)
106+
return s.GetBlockByHash(h)
107107
}
108108

109-
// LoadBlockByHash returns block with given block header hash, or error if it's not found in Store.
110-
func (s *DefaultStore) LoadBlockByHash(hash types.Hash) (*types.Block, error) {
109+
// GetBlockByHash returns block with given block header hash, or error if it's not found in Store.
110+
func (s *DefaultStore) GetBlockByHash(hash types.Hash) (*types.Block, error) {
111111
blockData, err := s.db.Get(s.ctx, ds.NewKey(getBlockKey(hash)))
112112
if err != nil {
113113
return nil, fmt.Errorf("failed to load block data: %w", err)
@@ -130,8 +130,8 @@ func (s *DefaultStore) SaveBlockResponses(height uint64, responses *abci.Respons
130130
return s.db.Put(s.ctx, ds.NewKey(getResponsesKey(height)), data)
131131
}
132132

133-
// LoadBlockResponses returns block results at given height, or error if it's not found in Store.
134-
func (s *DefaultStore) LoadBlockResponses(height uint64) (*abci.ResponseFinalizeBlock, error) {
133+
// GetBlockResponses returns block results at given height, or error if it's not found in Store.
134+
func (s *DefaultStore) GetBlockResponses(height uint64) (*abci.ResponseFinalizeBlock, error) {
135135
data, err := s.db.Get(s.ctx, ds.NewKey(getResponsesKey(height)))
136136
if err != nil {
137137
return nil, fmt.Errorf("failed to retrieve block results from height %v: %w", height, err)
@@ -144,17 +144,17 @@ func (s *DefaultStore) LoadBlockResponses(height uint64) (*abci.ResponseFinalize
144144
return &responses, nil
145145
}
146146

147-
// LoadCommit returns commit for a block at given height, or error if it's not found in Store.
148-
func (s *DefaultStore) LoadCommit(height uint64) (*types.Commit, error) {
147+
// GetCommit returns commit for a block at given height, or error if it's not found in Store.
148+
func (s *DefaultStore) GetCommit(height uint64) (*types.Commit, error) {
149149
hash, err := s.loadHashFromIndex(height)
150150
if err != nil {
151151
return nil, fmt.Errorf("failed to load hash from index: %w", err)
152152
}
153-
return s.LoadCommitByHash(hash)
153+
return s.GetCommitByHash(hash)
154154
}
155155

156-
// LoadCommitByHash returns commit for a block with given block header hash, or error if it's not found in Store.
157-
func (s *DefaultStore) LoadCommitByHash(hash types.Hash) (*types.Commit, error) {
156+
// GetCommitByHash returns commit for a block with given block header hash, or error if it's not found in Store.
157+
func (s *DefaultStore) GetCommitByHash(hash types.Hash) (*types.Commit, error) {
158158
commitData, err := s.db.Get(s.ctx, ds.NewKey(getCommitKey(hash)))
159159
if err != nil {
160160
return nil, fmt.Errorf("failed to retrieve commit from hash %v: %w", hash, err)
@@ -181,8 +181,8 @@ func (s *DefaultStore) UpdateState(state types.State) error {
181181
return s.db.Put(s.ctx, ds.NewKey(getStateKey()), data)
182182
}
183183

184-
// LoadState returns last state saved with UpdateState.
185-
func (s *DefaultStore) LoadState() (types.State, error) {
184+
// GetState returns last state saved with UpdateState.
185+
func (s *DefaultStore) GetState() (types.State, error) {
186186
blob, err := s.db.Get(s.ctx, ds.NewKey(getStateKey()))
187187
if err != nil {
188188
return types.State{}, fmt.Errorf("failed to retrieve state: %w", err)
@@ -213,8 +213,8 @@ func (s *DefaultStore) SaveValidators(height uint64, validatorSet *cmtypes.Valid
213213
return s.db.Put(s.ctx, ds.NewKey(getValidatorsKey(height)), blob)
214214
}
215215

216-
// LoadValidators loads validator set at given block height from store.
217-
func (s *DefaultStore) LoadValidators(height uint64) (*cmtypes.ValidatorSet, error) {
216+
// GetValidators loads validator set at given block height from store.
217+
func (s *DefaultStore) GetValidators(height uint64) (*cmtypes.ValidatorSet, error) {
218218
blob, err := s.db.Get(s.ctx, ds.NewKey(getValidatorsKey(height)))
219219
if err != nil {
220220
return nil, fmt.Errorf("failed to load Validators for height %v: %w", height, err)

store/store.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ The Store interface defines the following methods:
1111
- `Height`: Returns the height of the highest block in the store.
1212
- `SetHeight`: Sets given height in the store if it's higher than the existing height in the store.
1313
- `SaveBlock`: Saves a block along with its seen commit.
14-
- `LoadBlock`: Returns a block at a given height.
15-
- `LoadBlockByHash`: Returns a block with a given block header hash.
14+
- `GetBlock`: Returns a block at a given height.
15+
- `GetBlockByHash`: Returns a block with a given block header hash.
1616
- `SaveBlockResponses`: Saves block responses in the Store.
17-
- `LoadBlockResponses`: Returns block results at a given height.
18-
- `LoadCommit`: Returns a commit for a block at a given height.
19-
- `LoadCommitByHash`: Returns a commit for a block with a given block header hash.
17+
- `GetBlockResponses`: Returns block results at a given height.
18+
- `GetCommit`: Returns a commit for a block at a given height.
19+
- `GetCommitByHash`: Returns a commit for a block with a given block header hash.
2020
- `UpdateState`: Updates the state saved in the Store. Only one State is stored.
21-
- `LoadState`: Returns the last state saved with UpdateState.
21+
- `GetState`: Returns the last state saved with UpdateState.
2222
- `SaveValidators`: Saves the validator set at a given height.
23-
- `LoadValidators`: Returns the validator set at a given height.
23+
- `GetValidators`: Returns the validator set at a given height.
2424

2525
The `TxnDatastore` interface inside [go-datastore] is used for constructing different key-value stores for the underlying storage of a full node. The are two different implementations of `TxnDatastore` in [kv.go]:
2626

@@ -39,7 +39,7 @@ For the main node data, `DefaultStore` struct, an implementation of the Store in
3939
- `responsesPrefix` with value "r": Used to store responses related to the blocks.
4040
- `validatorsPrefix` with value "v": Used to store validator sets at a given height.
4141

42-
For example, in a call to `LoadBlockByHash` for some block hash `<block_hash>`, the key used in the full node's base key-value store will be `/0/b/<block_hash>` where `0` is the main store prefix and `b` is the block prefix. Similarly, in a call to `LoadValidators` for some height `<height>`, the key used in the full node's base key-value store will be `/0/v/<height>` where `0` is the main store prefix and `v` is the validator set prefix.
42+
For example, in a call to `GetBlockByHash` for some block hash `<block_hash>`, the key used in the full node's base key-value store will be `/0/b/<block_hash>` where `0` is the main store prefix and `b` is the block prefix. Similarly, in a call to `GetValidators` for some height `<height>`, the key used in the full node's base key-value store will be `/0/v/<height>` where `0` is the main store prefix and `v` is the validator set prefix.
4343

4444
Inside the key-value store, the value of these various types of data like `Block`, `Commit`, etc is stored as a byte array which is encoded and decoded using the corresponding Protobuf [marshal and unmarshal methods][serialization].
4545

store/store_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ func TestStoreLoad(t *testing.T) {
111111
}
112112

113113
for _, expected := range c.blocks {
114-
block, err := bstore.LoadBlock(uint64(expected.Height()))
114+
block, err := bstore.GetBlock(uint64(expected.Height()))
115115
assert.NoError(err)
116116
assert.NotNil(block)
117117
assert.Equal(expected, block)
118118

119-
commit, err := bstore.LoadCommit(uint64(expected.Height()))
119+
commit, err := bstore.GetCommit(uint64(expected.Height()))
120120
assert.NoError(err)
121121
assert.NotNil(commit)
122122
}
@@ -146,7 +146,7 @@ func TestRestart(t *testing.T) {
146146
assert.NoError(err)
147147

148148
s2 := New(ctx, kv)
149-
_, err = s2.LoadState()
149+
_, err = s2.GetState()
150150
assert.NoError(err)
151151

152152
assert.Equal(expectedHeight, s2.Height())
@@ -183,11 +183,11 @@ func TestBlockResponses(t *testing.T) {
183183
err := s.SaveBlockResponses(1, expected)
184184
assert.NoError(err)
185185

186-
resp, err := s.LoadBlockResponses(123)
186+
resp, err := s.GetBlockResponses(123)
187187
assert.Error(err)
188188
assert.Nil(resp)
189189

190-
resp, err = s.LoadBlockResponses(1)
190+
resp, err = s.GetBlockResponses(1)
191191
assert.NoError(err)
192192
assert.NotNil(resp)
193193
assert.Equal(expected, resp)

store/types.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@ type Store interface {
1818
// SaveBlock saves block along with its seen commit (which will be included in the next block).
1919
SaveBlock(block *types.Block, commit *types.Commit) error
2020

21-
// LoadBlock returns block at given height, or error if it's not found in Store.
22-
LoadBlock(height uint64) (*types.Block, error)
23-
// LoadBlockByHash returns block with given block header hash, or error if it's not found in Store.
24-
LoadBlockByHash(hash types.Hash) (*types.Block, error)
21+
// GetBlock returns block at given height, or error if it's not found in Store.
22+
GetBlock(height uint64) (*types.Block, error)
23+
// GetBlockByHash returns block with given block header hash, or error if it's not found in Store.
24+
GetBlockByHash(hash types.Hash) (*types.Block, error)
2525

2626
// SaveBlockResponses saves block responses (events, tx responses, validator set updates, etc) in Store.
2727
SaveBlockResponses(height uint64, responses *abci.ResponseFinalizeBlock) error
2828

2929
// LoadBlockResponses returns block results at given height, or error if it's not found in Store.
30-
LoadBlockResponses(height uint64) (*abci.ResponseFinalizeBlock, error)
30+
GetBlockResponses(height uint64) (*abci.ResponseFinalizeBlock, error)
3131

32-
// LoadCommit returns commit for a block at given height, or error if it's not found in Store.
33-
LoadCommit(height uint64) (*types.Commit, error)
34-
// LoadCommitByHash returns commit for a block with given block header hash, or error if it's not found in Store.
35-
LoadCommitByHash(hash types.Hash) (*types.Commit, error)
32+
// GetCommit returns commit for a block at given height, or error if it's not found in Store.
33+
GetCommit(height uint64) (*types.Commit, error)
34+
// GetCommitByHash returns commit for a block with given block header hash, or error if it's not found in Store.
35+
GetCommitByHash(hash types.Hash) (*types.Commit, error)
3636

3737
// UpdateState updates state saved in Store. Only one State is stored.
3838
// If there is no State in Store, state will be saved.
3939
UpdateState(state types.State) error
40-
// LoadState returns last state saved with UpdateState.
41-
LoadState() (types.State, error)
40+
// GetState returns last state saved with UpdateState.
41+
GetState() (types.State, error)
4242

4343
SaveValidators(height uint64, validatorSet *cmtypes.ValidatorSet) error
4444

45-
LoadValidators(height uint64) (*cmtypes.ValidatorSet, error)
45+
GetValidators(height uint64) (*cmtypes.ValidatorSet, error)
4646
}

0 commit comments

Comments
 (0)