mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Use only first block in pendingBlocks instead of iteration
This commit is contained in:
parent
806fcbe7c0
commit
92c852b601
1 changed files with 4 additions and 11 deletions
|
@ -215,16 +215,10 @@ public abstract class BsqNode implements DaoSetupService {
|
|||
// After parsing we check if we have pending blocks we might have received earlier but which have been
|
||||
// not connecting from the latest height we had. The list is sorted by height
|
||||
if (!pendingBlocks.isEmpty()) {
|
||||
// To avoid ConcurrentModificationException we copy the list. It might be altered in the method call
|
||||
ArrayList<RawBlock> tempPendingBlocks = new ArrayList<>(pendingBlocks);
|
||||
for (RawBlock tempPendingBlock : tempPendingBlocks) {
|
||||
try {
|
||||
doParseBlock(tempPendingBlock);
|
||||
} catch (RequiredReorgFromSnapshotException e1) {
|
||||
// In case we got a reorg we break the iteration
|
||||
break;
|
||||
}
|
||||
}
|
||||
// We take only first element after sorting (so it is the block with the next height) to avoid that
|
||||
// we would repeat calls in recursions in case we would iterate the list.
|
||||
pendingBlocks.sort(Comparator.comparing(RawBlock::getHeight));
|
||||
doParseBlock(pendingBlocks.get(0));
|
||||
}
|
||||
|
||||
return Optional.of(block);
|
||||
|
@ -236,7 +230,6 @@ public abstract class BsqNode implements DaoSetupService {
|
|||
int heightForNextBlock = daoStateService.getChainHeight() + 1;
|
||||
if (rawBlock.getHeight() > heightForNextBlock) {
|
||||
pendingBlocks.add(rawBlock);
|
||||
pendingBlocks.sort(Comparator.comparing(RawBlock::getHeight));
|
||||
log.info("We received an block with a future block height. We store it as pending and try to apply " +
|
||||
"it at the next block. rawBlock: height/hash={}/{}", rawBlock.getHeight(), rawBlock.getHash());
|
||||
} else if (rawBlock.getHeight() >= daoStateService.getGenesisBlockHeight()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue