Skip to content

Commit

Permalink
Merge pull request #9495 from ziggie1984/fix-graphbuilder-flake
Browse files Browse the repository at this point in the history
fix graphbuilder flake
  • Loading branch information
guggero authored Feb 10, 2025
2 parents 6eb8f1f + 6373d84 commit 2a0dca7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion graph/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func TestDisconnectedBlocks(t *testing.T) {
// TestChansClosedOfflinePruneGraph tests that if channels we know of are
// closed while we're offline, then once we resume operation of the
// ChannelRouter, then the channels are properly pruned.
func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
func TestChansClosedOfflinePruneGraph(t *testing.T) {
t.Parallel()

const startingBlockHeight = 101
Expand Down
16 changes: 14 additions & 2 deletions graph/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,21 @@ type mockChain struct {
var _ lnwallet.BlockChainIO = (*mockChain)(nil)

func newMockChain(currentHeight uint32) *mockChain {
return &mockChain{
chain := &mockChain{
bestHeight: int32(currentHeight),
blocks: make(map[chainhash.Hash]*wire.MsgBlock),
utxos: make(map[wire.OutPoint]wire.TxOut),
blockIndex: make(map[uint32]chainhash.Hash),
blockHeightIndex: make(map[chainhash.Hash]uint32),
}

// Initialize the block index with the empty hash for the
// starting height.
startingHash := chainhash.Hash{}
chain.blockIndex[currentHeight] = startingHash
chain.blockHeightIndex[startingHash] = currentHeight

return chain
}

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

blockHash := m.blockIndex[uint32(m.bestHeight)]
blockHash, exists := m.blockIndex[uint32(m.bestHeight)]
if !exists {
return nil, 0, fmt.Errorf("block at height %d not found",
m.bestHeight)
}

return &blockHash, m.bestHeight, nil
}
Expand Down

0 comments on commit 2a0dca7

Please sign in to comment.