Skip to content

Commit

Permalink
ignore bws sync requests until initial sync is complete (hyperledger#…
Browse files Browse the repository at this point in the history
…6455)

* ignore bws sync requests until initial sync is complete
* return failed Future when BWS is invoked but not ready

Signed-off-by: garyschulte <[email protected]>
  • Loading branch information
garyschulte authored Jan 24, 2024
1 parent 4ac32c6 commit ed1480b
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,30 @@ public synchronized CompletableFuture<Void> syncBackwardsUntil(final Hash newBlo
backwardChain.addNewHash(newBlockHash);
}

final Status status = getOrStartSyncSession();
backwardChain
.getBlock(newBlockHash)
.ifPresent(
newTargetBlock -> status.updateTargetHeight(newTargetBlock.getHeader().getNumber()));
return status.currentFuture;
if (isReady()) {
final Status status = getOrStartSyncSession();
backwardChain
.getBlock(newBlockHash)
.ifPresent(
newTargetBlock -> status.updateTargetHeight(newTargetBlock.getHeader().getNumber()));
return status.currentFuture;
} else {
return CompletableFuture.failedFuture(new Throwable("Backward sync is not ready"));
}
}

public synchronized CompletableFuture<Void> syncBackwardsUntil(final Block newPivot) {
if (!isTrusted(newPivot.getHash())) {
backwardChain.appendTrustedBlock(newPivot);
}

final Status status = getOrStartSyncSession();
status.updateTargetHeight(newPivot.getHeader().getNumber());
return status.currentFuture;
if (isReady()) {
final Status status = getOrStartSyncSession();
status.updateTargetHeight(newPivot.getHeader().getNumber());
return status.currentFuture;
} else {
return CompletableFuture.failedFuture(new Throwable("Backward sync is not ready"));
}
}

private Status getOrStartSyncSession() {
Expand Down

0 comments on commit ed1480b

Please sign in to comment.