diff --git a/dot/core/interfaces.go b/dot/core/interfaces.go index 23982f9f58..7b2ed1b066 100644 --- a/dot/core/interfaces.go +++ b/dot/core/interfaces.go @@ -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) diff --git a/dot/core/mocks_test.go b/dot/core/mocks_test.go index 580d045424..28a34fd1f9 100644 --- a/dot/core/mocks_test.go +++ b/dot/core/mocks_test.go @@ -161,31 +161,31 @@ func (mr *MockBlockStateMockRecorder) LowestCommonAncestor(arg0, arg1 interface{ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LowestCommonAncestor", reflect.TypeOf((*MockBlockState)(nil).LowestCommonAncestor), arg0, arg1) } -// StoreRuntime mocks base method. -func (m *MockBlockState) StoreRuntime(arg0 common.Hash, arg1 state.Runtime) { +// RangeInMemory mocks base method. +func (m *MockBlockState) RangeInMemory(arg0, arg1 common.Hash) ([]common.Hash, error) { m.ctrl.T.Helper() - m.ctrl.Call(m, "StoreRuntime", arg0, arg1) + ret := m.ctrl.Call(m, "RangeInMemory", arg0, arg1) + ret0, _ := ret[0].([]common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// StoreRuntime indicates an expected call of StoreRuntime. -func (mr *MockBlockStateMockRecorder) StoreRuntime(arg0, arg1 interface{}) *gomock.Call { +// RangeInMemory indicates an expected call of RangeInMemory. +func (mr *MockBlockStateMockRecorder) RangeInMemory(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StoreRuntime", reflect.TypeOf((*MockBlockState)(nil).StoreRuntime), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RangeInMemory", reflect.TypeOf((*MockBlockState)(nil).RangeInMemory), arg0, arg1) } -// SubChain mocks base method. -func (m *MockBlockState) SubChain(arg0, arg1 common.Hash) ([]common.Hash, error) { +// StoreRuntime mocks base method. +func (m *MockBlockState) StoreRuntime(arg0 common.Hash, arg1 state.Runtime) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubChain", arg0, arg1) - ret0, _ := ret[0].([]common.Hash) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.Call(m, "StoreRuntime", arg0, arg1) } -// SubChain indicates an expected call of SubChain. -func (mr *MockBlockStateMockRecorder) SubChain(arg0, arg1 interface{}) *gomock.Call { +// StoreRuntime indicates an expected call of StoreRuntime. +func (mr *MockBlockStateMockRecorder) StoreRuntime(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubChain", reflect.TypeOf((*MockBlockState)(nil).SubChain), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StoreRuntime", reflect.TypeOf((*MockBlockState)(nil).StoreRuntime), arg0, arg1) } // MockStorageState is a mock of StorageState interface. diff --git a/dot/core/service.go b/dot/core/service.go index ccd0807d78..4e198995ff 100644 --- a/dot/core/service.go +++ b/dot/core/service.go @@ -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 } diff --git a/dot/core/service_test.go b/dot/core/service_test.go index 0a4c46bc37..379ff4a53a 100644 --- a/dot/core/service_test.go +++ b/dot/core/service_test.go @@ -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, @@ -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, @@ -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) @@ -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) @@ -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) diff --git a/dot/rpc/interfaces.go b/dot/rpc/interfaces.go index 8a0667730f..2fd16e088b 100644 --- a/dot/rpc/interfaces.go +++ b/dot/rpc/interfaces.go @@ -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) diff --git a/dot/rpc/modules/api.go b/dot/rpc/modules/api.go index 34ac27b9b2..9c4dfbebf5 100644 --- a/dot/rpc/modules/api.go +++ b/dot/rpc/modules/api.go @@ -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) diff --git a/dot/rpc/modules/mocks/block_api.go b/dot/rpc/modules/mocks/block_api.go index d982818e18..c5730809a5 100644 --- a/dot/rpc/modules/mocks/block_api.go +++ b/dot/rpc/modules/mocks/block_api.go @@ -258,20 +258,22 @@ func (_m *BlockAPI) HasJustification(hash common.Hash) (bool, error) { return r0, r1 } -// RegisterRuntimeUpdatedChannel provides a mock function with given fields: ch -func (_m *BlockAPI) RegisterRuntimeUpdatedChannel(ch chan<- runtime.Version) (uint32, error) { - ret := _m.Called(ch) +// RangeInMemory provides a mock function with given fields: start, end +func (_m *BlockAPI) RangeInMemory(start common.Hash, end common.Hash) ([]common.Hash, error) { + ret := _m.Called(start, end) - var r0 uint32 - if rf, ok := ret.Get(0).(func(chan<- runtime.Version) uint32); ok { - r0 = rf(ch) + var r0 []common.Hash + if rf, ok := ret.Get(0).(func(common.Hash, common.Hash) []common.Hash); ok { + r0 = rf(start, end) } else { - r0 = ret.Get(0).(uint32) + if ret.Get(0) != nil { + r0 = ret.Get(0).([]common.Hash) + } } var r1 error - if rf, ok := ret.Get(1).(func(chan<- runtime.Version) error); ok { - r1 = rf(ch) + if rf, ok := ret.Get(1).(func(common.Hash, common.Hash) error); ok { + r1 = rf(start, end) } else { r1 = ret.Error(1) } @@ -279,22 +281,20 @@ func (_m *BlockAPI) RegisterRuntimeUpdatedChannel(ch chan<- runtime.Version) (ui return r0, r1 } -// SubChain provides a mock function with given fields: start, end -func (_m *BlockAPI) SubChain(start common.Hash, end common.Hash) ([]common.Hash, error) { - ret := _m.Called(start, end) +// RegisterRuntimeUpdatedChannel provides a mock function with given fields: ch +func (_m *BlockAPI) RegisterRuntimeUpdatedChannel(ch chan<- runtime.Version) (uint32, error) { + ret := _m.Called(ch) - var r0 []common.Hash - if rf, ok := ret.Get(0).(func(common.Hash, common.Hash) []common.Hash); ok { - r0 = rf(start, end) + var r0 uint32 + if rf, ok := ret.Get(0).(func(chan<- runtime.Version) uint32); ok { + r0 = rf(ch) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]common.Hash) - } + r0 = ret.Get(0).(uint32) } var r1 error - if rf, ok := ret.Get(1).(func(common.Hash, common.Hash) error); ok { - r1 = rf(start, end) + if rf, ok := ret.Get(1).(func(chan<- runtime.Version) error); ok { + r1 = rf(ch) } else { r1 = ret.Error(1) } diff --git a/dot/rpc/modules/mocks_test.go b/dot/rpc/modules/mocks_test.go index a1909464b6..55ea00c65a 100644 --- a/dot/rpc/modules/mocks_test.go +++ b/dot/rpc/modules/mocks_test.go @@ -377,34 +377,34 @@ func (mr *MockBlockAPIMockRecorder) HasJustification(arg0 interface{}) *gomock.C return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasJustification", reflect.TypeOf((*MockBlockAPI)(nil).HasJustification), arg0) } -// RegisterRuntimeUpdatedChannel mocks base method. -func (m *MockBlockAPI) RegisterRuntimeUpdatedChannel(arg0 chan<- runtime.Version) (uint32, error) { +// RangeInMemory mocks base method. +func (m *MockBlockAPI) RangeInMemory(arg0, arg1 common.Hash) ([]common.Hash, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RegisterRuntimeUpdatedChannel", arg0) - ret0, _ := ret[0].(uint32) + ret := m.ctrl.Call(m, "RangeInMemory", arg0, arg1) + ret0, _ := ret[0].([]common.Hash) ret1, _ := ret[1].(error) return ret0, ret1 } -// RegisterRuntimeUpdatedChannel indicates an expected call of RegisterRuntimeUpdatedChannel. -func (mr *MockBlockAPIMockRecorder) RegisterRuntimeUpdatedChannel(arg0 interface{}) *gomock.Call { +// RangeInMemory indicates an expected call of RangeInMemory. +func (mr *MockBlockAPIMockRecorder) RangeInMemory(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRuntimeUpdatedChannel", reflect.TypeOf((*MockBlockAPI)(nil).RegisterRuntimeUpdatedChannel), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RangeInMemory", reflect.TypeOf((*MockBlockAPI)(nil).RangeInMemory), arg0, arg1) } -// SubChain mocks base method. -func (m *MockBlockAPI) SubChain(arg0, arg1 common.Hash) ([]common.Hash, error) { +// RegisterRuntimeUpdatedChannel mocks base method. +func (m *MockBlockAPI) RegisterRuntimeUpdatedChannel(arg0 chan<- runtime.Version) (uint32, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubChain", arg0, arg1) - ret0, _ := ret[0].([]common.Hash) + ret := m.ctrl.Call(m, "RegisterRuntimeUpdatedChannel", arg0) + ret0, _ := ret[0].(uint32) ret1, _ := ret[1].(error) return ret0, ret1 } -// SubChain indicates an expected call of SubChain. -func (mr *MockBlockAPIMockRecorder) SubChain(arg0, arg1 interface{}) *gomock.Call { +// RegisterRuntimeUpdatedChannel indicates an expected call of RegisterRuntimeUpdatedChannel. +func (mr *MockBlockAPIMockRecorder) RegisterRuntimeUpdatedChannel(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubChain", reflect.TypeOf((*MockBlockAPI)(nil).SubChain), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRuntimeUpdatedChannel", reflect.TypeOf((*MockBlockAPI)(nil).RegisterRuntimeUpdatedChannel), arg0) } // UnregisterRuntimeUpdatedChannel mocks base method. diff --git a/dot/state/block.go b/dot/state/block.go index d2ba34e7d0..311b7c7e81 100644 --- a/dot/state/block.go +++ b/dot/state/block.go @@ -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. diff --git a/dot/state/block_finalisation.go b/dot/state/block_finalisation.go index 2ebf138632..9b8e1f5e0c 100644 --- a/dot/state/block_finalisation.go +++ b/dot/state/block_finalisation.go @@ -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 } diff --git a/dot/sync/interfaces.go b/dot/sync/interfaces.go index b1db9e81df..f6154e8c62 100644 --- a/dot/sync/interfaces.go +++ b/dot/sync/interfaces.go @@ -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) diff --git a/dot/sync/message.go b/dot/sync/message.go index 2c44629ed1..2698bdf0dd 100644 --- a/dot/sync/message.go +++ b/dot/sync/message.go @@ -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) } diff --git a/dot/sync/message_test.go b/dot/sync/message_test.go index 71fc20f81b..d72aa03f22 100644 --- a/dot/sync/message_test.go +++ b/dot/sync/message_test.go @@ -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 @@ -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 diff --git a/dot/sync/mocks_test.go b/dot/sync/mocks_test.go index 156ec4fd91..ef16cd6ea2 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) } +// RangeInMemory mocks base method. +func (m *MockBlockState) RangeInMemory(arg0, arg1 common.Hash) ([]common.Hash, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RangeInMemory", arg0, arg1) + ret0, _ := ret[0].([]common.Hash) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RangeInMemory indicates an expected call of RangeInMemory. +func (mr *MockBlockStateMockRecorder) RangeInMemory(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RangeInMemory", reflect.TypeOf((*MockBlockState)(nil).RangeInMemory), arg0, arg1) +} + // SetJustification mocks base method. func (m *MockBlockState) SetJustification(arg0 common.Hash, arg1 []byte) error { m.ctrl.T.Helper() @@ -348,21 +363,6 @@ func (mr *MockBlockStateMockRecorder) StoreRuntime(arg0, arg1 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StoreRuntime", reflect.TypeOf((*MockBlockState)(nil).StoreRuntime), arg0, arg1) } -// SubChain mocks base method. -func (m *MockBlockState) SubChain(arg0, arg1 common.Hash) ([]common.Hash, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubChain", arg0, arg1) - ret0, _ := ret[0].([]common.Hash) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// SubChain indicates an expected call of SubChain. -func (mr *MockBlockStateMockRecorder) SubChain(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubChain", reflect.TypeOf((*MockBlockState)(nil).SubChain), arg0, arg1) -} - // MockStorageState is a mock of StorageState interface. type MockStorageState struct { ctrl *gomock.Controller diff --git a/lib/blocktree/blocktree.go b/lib/blocktree/blocktree.go index 66739e9dec..b03e059c96 100644 --- a/lib/blocktree/blocktree.go +++ b/lib/blocktree/blocktree.go @@ -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() diff --git a/lib/blocktree/blocktree_test.go b/lib/blocktree/blocktree_test.go index 0acf2637cf..8478aaffaf 100644 --- a/lib/blocktree/blocktree_test.go +++ b/lib/blocktree/blocktree_test.go @@ -59,7 +59,7 @@ func createTestBlockTree(t *testing.T, header *types.Header, number uint) (*Bloc previousHash := header.Hash() // branch tree randomly - branches := []testBranch{} + var branches []testBranch r := rand.New(rand.NewSource(time.Now().UnixNano())) //skipcq: GSC-G404 at := int64(0) @@ -264,15 +264,14 @@ func Test_BlockTree_GetAllBlocksAtNumber(t *testing.T) { bt, _ := createTestBlockTree(t, testHeader, 8) hashes := bt.root.getNodesWithNumber(10, []common.Hash{}) - expected := []common.Hash{} - require.Equal(t, expected, hashes) + require.Empty(t, hashes) // create one-path tree const btNumber uint = 8 const desiredNumber uint = 6 bt, btHashes := createFlatTree(t, btNumber) - expected = []common.Hash{btHashes[desiredNumber]} + expected := []common.Hash{btHashes[desiredNumber]} // add branch previousHash := btHashes[4] @@ -562,7 +561,7 @@ func Test_BlockTree_BestBlockHash_AllChainsEqual(t *testing.T) { bt := NewBlockTreeFromRoot(testHeader) previousHash := testHeader.Hash() - branches := []testBranch{} + var branches []testBranch const fixedArrivalTime = 99 const depth uint = 4 @@ -814,7 +813,7 @@ func BenchmarkBlockTreeSubBlockchain(b *testing.B) { b.Run(fmt.Sprintf("input_len_%d", tt.input), func(b *testing.B) { for i := 0; i < b.N; i++ { - bt.SubBlockchain(firstHash, endHash) + bt.RangeInMemory(firstHash, endHash) } }) }