Skip to content

Commit fe0ea5b

Browse files
committed
fix bug where reorg occurs precisely at known chaintip height
1 parent 4233460 commit fe0ea5b

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

xcode/DirectBindingsApp/DirectBindingsApp/app-batteries/BlockchainObserver.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,14 @@ class BlockchainObserver {
193193
}
194194

195195
// create an array of the new blocks
196-
// the variable is called anchored because there should be an overlap of one
197196
var addedBlocks = [RPCBlockDetails]()
198197
for addedBlockHeight in (knownChaintip.height + 1)...currentChaintipHeight {
199198
let addedBlockHash = try await self.getBlockHash(height: addedBlockHeight)
200199
let addedBlock = try await self.getBlock(hash: addedBlockHash)
201200
addedBlocks.append(addedBlock)
202201
}
203202

204-
while addedBlocks.first!.previousblockhash != self.connectedBlocks.last!.hash {
203+
while addedBlocks.isEmpty || addedBlocks.first!.previousblockhash != self.connectedBlocks.last!.hash {
205204
// we must keep popping until it matches
206205
let trimmedLocalTip = try await self.disconnectBlock()
207206
let reorgedBlockHash = try await self.getBlockHash(height: trimmedLocalTip.height)

0 commit comments

Comments
 (0)