Skip to content

Commit

Permalink
(dot/state) chore: rename SubChain to RangeInMemory (#3011)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior authored Jan 4, 2023
1 parent 58ce668 commit eded603
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 89 deletions.
2 changes: 1 addition & 1 deletion dot/core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type BlockState interface {
BestBlockHeader() (*types.Header, error)
AddBlock(*types.Block) error
GetBlockStateRoot(bhash common.Hash) (common.Hash, error)
SubChain(start, end common.Hash) ([]common.Hash, error)
RangeInMemory(start, end common.Hash) ([]common.Hash, error)
GetBlockBody(hash common.Hash) (*types.Body, error)
HandleRuntimeChanges(newState *rtstorage.TrieState, in state.Runtime, bHash common.Hash) error
GetRuntime(blockHash common.Hash) (instance state.Runtime, err error)
Expand Down
30 changes: 15 additions & 15 deletions dot/core/mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (s *Service) handleChainReorg(best, curr common.Hash) error {
return nil
}

subchain, err := s.blockState.SubChain(ancestor, best)
subchain, err := s.blockState.RangeInMemory(ancestor, best)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions dot/core/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ func TestService_handleChainReorg(t *testing.T) {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().LowestCommonAncestor(testPrevHash, testCurrentHash).
Return(testAncestorHash, nil)
mockBlockState.EXPECT().SubChain(testAncestorHash, testPrevHash).Return([]common.Hash{}, errDummyErr)
mockBlockState.EXPECT().RangeInMemory(testAncestorHash, testPrevHash).Return([]common.Hash{}, errDummyErr)

service := &Service{
blockState: mockBlockState,
Expand All @@ -822,7 +822,7 @@ func TestService_handleChainReorg(t *testing.T) {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().LowestCommonAncestor(testPrevHash, testCurrentHash).
Return(testAncestorHash, nil)
mockBlockState.EXPECT().SubChain(testAncestorHash, testPrevHash).Return([]common.Hash{}, nil)
mockBlockState.EXPECT().RangeInMemory(testAncestorHash, testPrevHash).Return([]common.Hash{}, nil)

service := &Service{
blockState: mockBlockState,
Expand All @@ -836,7 +836,7 @@ func TestService_handleChainReorg(t *testing.T) {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().LowestCommonAncestor(testPrevHash, testCurrentHash).
Return(testAncestorHash, nil)
mockBlockState.EXPECT().SubChain(testAncestorHash, testPrevHash).Return(testSubChain, nil)
mockBlockState.EXPECT().RangeInMemory(testAncestorHash, testPrevHash).Return(testSubChain, nil)
mockBlockState.EXPECT().BestBlockHash().Return(common.Hash{1})
mockBlockState.EXPECT().GetRuntime(common.Hash{1}).Return(nil, errDummyErr)

Expand Down Expand Up @@ -869,7 +869,7 @@ func TestService_handleChainReorg(t *testing.T) {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().LowestCommonAncestor(testPrevHash, testCurrentHash).
Return(testAncestorHash, nil)
mockBlockState.EXPECT().SubChain(testAncestorHash, testPrevHash).Return(testSubChain, nil)
mockBlockState.EXPECT().RangeInMemory(testAncestorHash, testPrevHash).Return(testSubChain, nil)
mockBlockState.EXPECT().BestBlockHash().Return(common.Hash{1})
mockBlockState.EXPECT().GetRuntime(common.Hash{1}).Return(runtimeMockErr, nil)
mockBlockState.EXPECT().GetBlockBody(testCurrentHash).Return(nil, errDummyErr)
Expand Down Expand Up @@ -908,7 +908,7 @@ func TestService_handleChainReorg(t *testing.T) {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().LowestCommonAncestor(testPrevHash, testCurrentHash).
Return(testAncestorHash, nil)
mockBlockState.EXPECT().SubChain(testAncestorHash, testPrevHash).Return(testSubChain, nil)
mockBlockState.EXPECT().RangeInMemory(testAncestorHash, testPrevHash).Return(testSubChain, nil)
mockBlockState.EXPECT().BestBlockHash().Return(common.Hash{1})
mockBlockState.EXPECT().GetRuntime(common.Hash{1}).Return(runtimeMockOk, nil)
mockBlockState.EXPECT().GetBlockBody(testCurrentHash).Return(nil, errDummyErr)
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type BlockAPI interface {
FreeImportedBlockNotifierChannel(ch chan *types.Block)
GetFinalisedNotifierChannel() chan *types.FinalisationInfo
FreeFinalisedNotifierChannel(ch chan *types.FinalisationInfo)
SubChain(start, end common.Hash) ([]common.Hash, error)
RangeInMemory(start, end common.Hash) ([]common.Hash, error)
RegisterRuntimeUpdatedChannel(ch chan<- runtime.Version) (uint32, error)
UnregisterRuntimeUpdatedChannel(id uint32) bool
GetRuntime(blockHash common.Hash) (runtime state.Runtime, err error)
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type BlockAPI interface {
FreeImportedBlockNotifierChannel(ch chan *types.Block)
GetFinalisedNotifierChannel() chan *types.FinalisationInfo
FreeFinalisedNotifierChannel(ch chan *types.FinalisationInfo)
SubChain(start, end common.Hash) ([]common.Hash, error)
RangeInMemory(start, end common.Hash) ([]common.Hash, error)
RegisterRuntimeUpdatedChannel(ch chan<- runtime.Version) (uint32, error)
UnregisterRuntimeUpdatedChannel(id uint32) bool
GetRuntime(blockHash common.Hash) (instance state.Runtime, err error)
Expand Down
40 changes: 20 additions & 20 deletions dot/rpc/modules/mocks/block_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions dot/rpc/modules/mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dot/state/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,13 @@ func (bs *BlockState) retrieveRangeFromDatabase(startHash common.Hash,
return hashes, nil
}

// SubChain returns the sub-blockchain between the starting hash and the ending hash using the block tree
func (bs *BlockState) SubChain(start, end common.Hash) ([]common.Hash, error) {
// RangeInMemory returns the sub-blockchain between the starting hash and the ending hash using the block tree
func (bs *BlockState) RangeInMemory(start, end common.Hash) ([]common.Hash, error) {
if bs.bt == nil {
return nil, fmt.Errorf("%w", errNilBlockTree)
}

return bs.bt.SubBlockchain(start, end)
return bs.bt.RangeInMemory(start, end)
}

// IsDescendantOf returns true if child is a descendant of parent, false otherwise.
Expand Down
2 changes: 1 addition & 1 deletion dot/state/block_finalisation.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (bs *BlockState) handleFinalisedBlock(curr common.Hash) error {
return nil
}

subchain, err := bs.SubChain(prev, curr)
subchain, err := bs.RangeInMemory(prev, curr)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion dot/sync/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type BlockState interface {
GetBlockBody(common.Hash) (*types.Body, error)
GetHeader(common.Hash) (*types.Header, error)
HasHeader(hash common.Hash) (bool, error)
SubChain(start, end common.Hash) ([]common.Hash, error)
RangeInMemory(start, end common.Hash) ([]common.Hash, error)
GetReceipt(common.Hash) ([]byte, error)
GetMessageQueue(common.Hash) ([]byte, error)
GetJustification(common.Hash) ([]byte, error)
Expand Down
2 changes: 1 addition & 1 deletion dot/sync/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (s *Service) handleDescendingByNumber(start, end uint,
func (s *Service) handleChainByHash(ancestor, descendant common.Hash,
max uint, requestedData byte, direction network.SyncDirection) (
*network.BlockResponseMessage, error) {
subchain, err := s.blockState.SubChain(ancestor, descendant)
subchain, err := s.blockState.RangeInMemory(ancestor, descendant)
if err != nil {
return nil, fmt.Errorf("retrieving subchain: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions dot/sync/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
mockBlockState.EXPECT().GetHashByNumber(uint(2)).Return(common.Hash{1, 2, 3}, nil)
mockBlockState.EXPECT().IsDescendantOf(common.Hash{}, common.Hash{1, 2, 3}).Return(true,
nil)
mockBlockState.EXPECT().SubChain(common.Hash{}, common.Hash{1, 2, 3}).Return([]common.Hash{{1,
mockBlockState.EXPECT().RangeInMemory(common.Hash{}, common.Hash{1, 2, 3}).Return([]common.Hash{{1,
2}},
nil)
return mockBlockState
Expand All @@ -125,7 +125,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
mockBlockState.EXPECT().GetHeaderByNumber(uint(1)).Return(&types.Header{
Number: 1,
}, nil)
mockBlockState.EXPECT().SubChain(common.MustHexToHash(
mockBlockState.EXPECT().RangeInMemory(common.MustHexToHash(
"0x6443a0b46e0412e626363028115a9f2cf963eeed526b8b33e5316f08b50d0dc3"),
common.Hash{}).Return([]common.Hash{{1, 2}}, nil)
return mockBlockState
Expand Down
30 changes: 15 additions & 15 deletions dot/sync/mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/blocktree/blocktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ func (bt *BlockTree) Range(startHash common.Hash, endHash common.Hash) (hashes [
return hashes, nil
}

// SubBlockchain returns the path from the node with Hash start to the node with Hash end
func (bt *BlockTree) SubBlockchain(startHash common.Hash, endHash common.Hash) (hashes []common.Hash, err error) {
// RangeInMemory returns the path from the node with Hash start to the node with Hash end
func (bt *BlockTree) RangeInMemory(startHash common.Hash, endHash common.Hash) (hashes []common.Hash, err error) {
bt.Lock()
defer bt.Unlock()

Expand Down
Loading

0 comments on commit eded603

Please sign in to comment.