From eed972febe452008f80a9102f8d62be38c057f86 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Thu, 15 Dec 2022 13:42:17 -0400 Subject: [PATCH 1/2] chore: replace the `sync/message.go` usage of method `SubChain` for `Range` --- dot/sync/interface.go | 1 + dot/sync/message.go | 4 ++-- dot/sync/mocks_test.go | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dot/sync/interface.go b/dot/sync/interface.go index 422c812b67..69328e4bb7 100644 --- a/dot/sync/interface.go +++ b/dot/sync/interface.go @@ -59,6 +59,7 @@ type BlockState interface { SetHeader(*types.Header) error GetHeader(common.Hash) (*types.Header, error) HasHeader(hash common.Hash) (bool, error) + Range(startHash, endHash common.Hash) (hashes []common.Hash, err error) SubChain(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 2c44629ed1..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.SubChain(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/mocks_test.go b/dot/sync/mocks_test.go index be977a2217..c4f5f8700e 100644 --- a/dot/sync/mocks_test.go +++ b/dot/sync/mocks_test.go @@ -367,6 +367,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) +} + // SetFinalisedHash mocks base method. func (m *MockBlockState) SetFinalisedHash(arg0 common.Hash, arg1, arg2 uint64) error { m.ctrl.T.Helper() From f235665fe10f5dbf4c295eb7b0d3aaa2811160f4 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Fri, 16 Dec 2022 16:18:24 -0400 Subject: [PATCH 2/2] chore: make CI green again --- dot/sync/message_test.go | 20 ++++++++++---------- dot/sync/mocks_test.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/dot/sync/message_test.go b/dot/sync/message_test.go index 71fc20f81b..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().SubChain(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().SubChain(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 c901a70f9b..f0e1a32ac2 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) +} + // SetJustification mocks base method. func (m *MockBlockState) SetJustification(arg0 common.Hash, arg1 []byte) error { m.ctrl.T.Helper()