diff --git a/dot/sync/interfaces.go b/dot/sync/interfaces.go index f6154e8c62..8eac5c99fa 100644 --- a/dot/sync/interfaces.go +++ b/dot/sync/interfaces.go @@ -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) diff --git a/dot/sync/message.go b/dot/sync/message.go index 2698bdf0dd..4c1ad50470 100644 --- a/dot/sync/message.go +++ b/dot/sync/message.go @@ -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. diff --git a/dot/sync/message_test.go b/dot/sync/message_test.go index d72aa03f22..e3ce179be2 100644 --- a/dot/sync/message_test.go +++ b/dot/sync/message_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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{ @@ -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 @@ -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{ @@ -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 @@ -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 }, diff --git a/dot/sync/mocks_test.go b/dot/sync/mocks_test.go index ef16cd6ea2..45f1efd5d0 100644 --- a/dot/sync/mocks_test.go +++ b/dot/sync/mocks_test.go @@ -322,6 +322,21 @@ func (mr *MockBlockStateMockRecorder) IsDescendantOf(arg0, arg1 interface{}) *go return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsDescendantOf", reflect.TypeOf((*MockBlockState)(nil).IsDescendantOf), arg0, arg1) } +// Range mocks base method. +func (m *MockBlockState) Range(arg0, arg1 common.Hash) ([]common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Range", arg0, arg1) + ret0, _ := ret[0].([]common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Range indicates an expected call of Range. +func (mr *MockBlockStateMockRecorder) Range(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Range", reflect.TypeOf((*MockBlockState)(nil).Range), arg0, arg1) +} + // RangeInMemory mocks base method. func (m *MockBlockState) RangeInMemory(arg0, arg1 common.Hash) ([]common.Hash, error) { m.ctrl.T.Helper()