Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dot/sync/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type BlockState interface {
GetBlockBody(common.Hash) (*types.Body, error)
GetHeader(common.Hash) (*types.Header, error)
HasHeader(hash common.Hash) (bool, error)
Range(startHash, endHash common.Hash) (hashes []common.Hash, err error)
RangeInMemory(start, end common.Hash) ([]common.Hash, error)
GetReceipt(common.Hash) ([]byte, error)
GetMessageQueue(common.Hash) ([]byte, error)
Expand Down
4 changes: 2 additions & 2 deletions dot/sync/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ 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.RangeInMemory(ancestor, descendant)
subchain, err := s.blockState.Range(ancestor, descendant)
if err != nil {
return nil, fmt.Errorf("retrieving subchain: %w", err)
return nil, fmt.Errorf("retrieving range: %w", err)
}

// If the direction is descending, prune from the start.
Expand Down
20 changes: 10 additions & 10 deletions dot/sync/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
want *network.BlockResponseMessage
err error
}{
"invalid block request": {
"invalid_block_request": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().BestBlockNumber().Return(uint(1), nil)
Expand All @@ -36,7 +36,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
args: args{req: &network.BlockRequestMessage{}},
err: ErrInvalidBlockRequest,
},
"ascending request nil startHash": {
"ascending_request_nil_startHash": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().BestBlockNumber().Return(uint(1), nil)
Expand All @@ -51,7 +51,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
Hash: common.Hash{1, 2},
}}},
},
"ascending request start number higher": {
"ascending_request_start_number_higher": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().BestBlockNumber().Return(uint(1), nil)
Expand All @@ -65,7 +65,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
err: errRequestStartTooHigh,
want: nil,
},
"descending request nil startHash": {
"descending_request_nil_startHash": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().BestBlockNumber().Return(uint(1), nil)
Expand All @@ -77,7 +77,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
}},
want: &network.BlockResponseMessage{BlockData: []*types.BlockData{}},
},
"descending request start number higher": {
"descending_request_start_number_higher": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().BestBlockNumber().Return(uint(1), nil)
Expand All @@ -93,7 +93,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
Hash: common.Hash{1, 2},
}}},
},
"ascending request startHash": {
"ascending_request_startHash": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().GetHeader(common.Hash{}).Return(&types.Header{
Expand All @@ -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().RangeInMemory(common.Hash{}, common.Hash{1, 2, 3}).Return([]common.Hash{{1,
mockBlockState.EXPECT().Range(common.Hash{}, common.Hash{1, 2, 3}).Return([]common.Hash{{1,
2}},
nil)
return mockBlockState
Expand All @@ -116,7 +116,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
Hash: common.Hash{1, 2},
}}},
},
"descending request startHash": {
"descending_request_startHash": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().GetHeader(common.Hash{}).Return(&types.Header{
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().RangeInMemory(common.MustHexToHash(
mockBlockState.EXPECT().Range(common.MustHexToHash(
"0x6443a0b46e0412e626363028115a9f2cf963eeed526b8b33e5316f08b50d0dc3"),
common.Hash{}).Return([]common.Hash{{1, 2}}, nil)
return mockBlockState
Expand All @@ -138,7 +138,7 @@ func TestService_CreateBlockResponse(t *testing.T) {
Hash: common.Hash{1, 2},
}}},
},
"invalid direction": {
"invalid_direction": {
blockStateBuilder: func(ctrl *gomock.Controller) BlockState {
return nil
},
Expand Down
15 changes: 15 additions & 0 deletions dot/sync/mocks_test.go

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