Skip to content

Commit 2437b3d

Browse files
authored
renamed Store Interface Load methods to Get (#1349)
closes: #1284 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **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 c93ddf2 commit 2437b3d

8 files changed

Lines changed: 67 additions & 67 deletions

File tree

block/manager.go

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

9898
// getInitialState tries to load lastState from Store, and if it's not available it reads GenesisDoc.
9999
func getInitialState(store store.Store, genesis *cmtypes.GenesisDoc) (types.State, error) {
100-
s, err := store.LoadState()
100+
s, err := store.GetState()
101101
if err != nil {
102102
s, err = types.NewFromGenesisDoc(genesis)
103103
}
@@ -598,11 +598,11 @@ func (m *Manager) publishBlock(ctx context.Context) error {
598598
if newHeight == uint64(m.genesis.InitialHeight) {
599599
lastCommit = &types.Commit{}
600600
} else {
601-
lastCommit, err = m.store.LoadCommit(height)
601+
lastCommit, err = m.store.GetCommit(height)
602602
if err != nil {
603603
return fmt.Errorf("error while loading last commit: %w", err)
604604
}
605-
lastBlock, err := m.store.LoadBlock(height)
605+
lastBlock, err := m.store.GetBlock(height)
606606
if err != nil {
607607
return fmt.Errorf("error while loading last block: %w", err)
608608
}
@@ -614,7 +614,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
614614

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

node/full_client.go

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

319319
blocks := make([]*cmtypes.BlockMeta, 0, maxHeight-minHeight+1)
320320
for height := maxHeight; height >= minHeight; height-- {
321-
block, err := c.node.Store.LoadBlock(uint64(height))
321+
block, err := c.node.Store.GetBlock(uint64(height))
322322
if err != nil {
323323
return nil, err
324324
}
@@ -408,7 +408,7 @@ func (c *FullClient) Health(ctx context.Context) (*ctypes.ResultHealth, error) {
408408
// If height is nil, it returns information about last known block.
409409
func (c *FullClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) {
410410
heightValue := c.normalizeHeight(height)
411-
block, err := c.node.Store.LoadBlock(heightValue)
411+
block, err := c.node.Store.GetBlock(heightValue)
412412
if err != nil {
413413
return nil, err
414414
}
@@ -431,7 +431,7 @@ func (c *FullClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBl
431431

432432
// BlockByHash returns BlockID and block itself for given hash.
433433
func (c *FullClient) BlockByHash(ctx context.Context, hash []byte) (*ctypes.ResultBlock, error) {
434-
block, err := c.node.Store.LoadBlockByHash(hash)
434+
block, err := c.node.Store.GetBlockByHash(hash)
435435
if err != nil {
436436
return nil, err
437437
}
@@ -460,7 +460,7 @@ func (c *FullClient) BlockResults(ctx context.Context, height *int64) (*ctypes.R
460460
} else {
461461
h = uint64(*height)
462462
}
463-
resp, err := c.node.Store.LoadBlockResponses(h)
463+
resp, err := c.node.Store.GetBlockResponses(h)
464464
if err != nil {
465465
return nil, err
466466
}
@@ -478,11 +478,11 @@ func (c *FullClient) BlockResults(ctx context.Context, height *int64) (*ctypes.R
478478
// Commit returns signed header (aka commit) at given height.
479479
func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) {
480480
heightValue := c.normalizeHeight(height)
481-
com, err := c.node.Store.LoadCommit(heightValue)
481+
com, err := c.node.Store.GetCommit(heightValue)
482482
if err != nil {
483483
return nil, err
484484
}
485-
b, err := c.node.Store.LoadBlock(heightValue)
485+
b, err := c.node.Store.GetBlock(heightValue)
486486
if err != nil {
487487
return nil, err
488488
}
@@ -498,7 +498,7 @@ func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultC
498498
// Validators returns paginated list of validators at given height.
499499
func (c *FullClient) Validators(ctx context.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error) {
500500
height := c.normalizeHeight(heightPtr)
501-
validators, err := c.node.Store.LoadValidators(height)
501+
validators, err := c.node.Store.GetValidators(height)
502502
if err != nil {
503503
return nil, fmt.Errorf("failed to load validators for height %d: %w", height, err)
504504
}
@@ -536,7 +536,7 @@ func (c *FullClient) Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.R
536536

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

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

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

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

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

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

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

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

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

node/full_client_test.go

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

6161
func getBlockMeta(rpc *FullClient, n int64) *cmtypes.BlockMeta {
62-
b, err := rpc.node.Store.LoadBlock(uint64(n))
62+
b, err := rpc.node.Store.GetBlock(uint64(n))
6363
if err != nil {
6464
return nil
6565
}
@@ -1087,7 +1087,7 @@ func TestStatus(t *testing.T) {
10871087

10881088
// specific validation
10891089
assert.Equal(tconfig.DefaultBaseConfig().Moniker, resp.NodeInfo.Moniker)
1090-
state, err := rpc.node.Store.LoadState()
1090+
state, err := rpc.node.Store.GetState()
10911091
assert.NoError(err)
10921092
defaultProtocolVersion := p2p.NewProtocolVersion(
10931093
version.P2PProtocol,

node/full_node_integration_test.go

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

120120
// assert that all blocks known to node are same as produced by aggregator
121121
for h := uint64(1); h <= nodes[i].Store.Height(); h++ {
122-
aggBlock, err := nodes[0].Store.LoadBlock(h)
122+
aggBlock, err := nodes[0].Store.GetBlock(h)
123123
require.NoError(err)
124-
nodeBlock, err := nodes[i].Store.LoadBlock(h)
124+
nodeBlock, err := nodes[i].Store.GetBlock(h)
125125
require.NoError(err)
126126
assert.Equal(aggBlock, nodeBlock, fmt.Sprintf("height: %d", h))
127127
}
@@ -275,7 +275,7 @@ func TestFastDASync(t *testing.T) {
275275
// Verify that the block we synced to is DA included. This is to
276276
// ensure that the test is passing due to the DA syncing, since the P2P
277277
// block sync will sync quickly but the block won't be DA included.
278-
block, err := node2.Store.LoadBlock(numberOfBlocksToSyncTill)
278+
block, err := node2.Store.GetBlock(numberOfBlocksToSyncTill)
279279
require.NoError(err)
280280
require.True(node2.blockManager.IsDAIncluded(block.Hash()))
281281
}

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 *cmstate.ABCI
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) (*cmstate.ABCIResponses, 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) (*cmstate.ABCIResponses, 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) (*cmstate.ABCIResponses
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
@@ -112,12 +112,12 @@ func TestStoreLoad(t *testing.T) {
112112
}
113113

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

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

149149
s2 := New(ctx, kv)
150-
_, err = s2.LoadState()
150+
_, err = s2.GetState()
151151
assert.NoError(err)
152152

153153
assert.Equal(expectedHeight, s2.Height())
@@ -188,11 +188,11 @@ func TestBlockResponses(t *testing.T) {
188188
err := s.SaveBlockResponses(1, expected)
189189
assert.NoError(err)
190190

191-
resp, err := s.LoadBlockResponses(123)
191+
resp, err := s.GetBlockResponses(123)
192192
assert.Error(err)
193193
assert.Nil(resp)
194194

195-
resp, err = s.LoadBlockResponses(1)
195+
resp, err = s.GetBlockResponses(1)
196196
assert.NoError(err)
197197
assert.NotNil(resp)
198198
assert.Equal(expected, resp)

store/types.go

Lines changed: 13 additions & 13 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 *cmstate.ABCIResponses) error
2828

29-
// LoadBlockResponses returns block results at given height, or error if it's not found in Store.
30-
LoadBlockResponses(height uint64) (*cmstate.ABCIResponses, error)
29+
// GetBlockResponses returns block results at given height, or error if it's not found in Store.
30+
GetBlockResponses(height uint64) (*cmstate.ABCIResponses, 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)