Skip to content

Commit 2a0dca7

Browse files
authored
Merge pull request #9495 from ziggie1984/fix-graphbuilder-flake
fix graphbuilder flake
2 parents 6eb8f1f + 6373d84 commit 2a0dca7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

graph/builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ func TestDisconnectedBlocks(t *testing.T) {
582582
// TestChansClosedOfflinePruneGraph tests that if channels we know of are
583583
// closed while we're offline, then once we resume operation of the
584584
// ChannelRouter, then the channels are properly pruned.
585-
func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
585+
func TestChansClosedOfflinePruneGraph(t *testing.T) {
586586
t.Parallel()
587587

588588
const startingBlockHeight = 101

graph/notifications_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,21 @@ type mockChain struct {
176176
var _ lnwallet.BlockChainIO = (*mockChain)(nil)
177177

178178
func newMockChain(currentHeight uint32) *mockChain {
179-
return &mockChain{
179+
chain := &mockChain{
180180
bestHeight: int32(currentHeight),
181181
blocks: make(map[chainhash.Hash]*wire.MsgBlock),
182182
utxos: make(map[wire.OutPoint]wire.TxOut),
183183
blockIndex: make(map[uint32]chainhash.Hash),
184184
blockHeightIndex: make(map[chainhash.Hash]uint32),
185185
}
186+
187+
// Initialize the block index with the empty hash for the
188+
// starting height.
189+
startingHash := chainhash.Hash{}
190+
chain.blockIndex[currentHeight] = startingHash
191+
chain.blockHeightIndex[startingHash] = currentHeight
192+
193+
return chain
186194
}
187195

188196
func (m *mockChain) setBestBlock(height int32) {
@@ -196,7 +204,11 @@ func (m *mockChain) GetBestBlock() (*chainhash.Hash, int32, error) {
196204
m.RLock()
197205
defer m.RUnlock()
198206

199-
blockHash := m.blockIndex[uint32(m.bestHeight)]
207+
blockHash, exists := m.blockIndex[uint32(m.bestHeight)]
208+
if !exists {
209+
return nil, 0, fmt.Errorf("block at height %d not found",
210+
m.bestHeight)
211+
}
200212

201213
return &blockHash, m.bestHeight, nil
202214
}

0 commit comments

Comments
 (0)