Skip to content

Commit

Permalink
Bws internal error fix (hyperledger#6806)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Frame <jason.frame@consensys.net>
  • Loading branch information
jframe authored Apr 4, 2024
1 parent 9ae52a9 commit a7b10db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,6 @@ public Optional<BlockHeader> getOrSyncHeadByHash(final Hash headHash, final Hash
.addArgument(maybeHeadHeader.get()::toLogString)
.log();
} else {
LOG.atDebug()
.setMessage("Appending new head block hash {} to backward sync")
.addArgument(headHash::toHexString)
.log();
backwardSyncContext.maybeUpdateTargetHeight(headHash);
backwardSyncContext
.syncBackwardsUntil(headHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,15 @@ public synchronized void maybeUpdateTargetHeight(final Hash headHash) {
}

public synchronized CompletableFuture<Void> syncBackwardsUntil(final Hash newBlockHash) {
if (!isTrusted(newBlockHash)) {
backwardChain.addNewHash(newBlockHash);
}

if (isReady()) {
if (!isTrusted(newBlockHash)) {
LOG.atDebug()
.setMessage("Appending new head block hash {} to backward sync")
.addArgument(newBlockHash::toHexString)
.log();
backwardChain.addNewHash(newBlockHash);
}

final Status status = getOrStartSyncSession();
backwardChain
.getBlock(newBlockHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ public void shouldSyncUntilHash() throws Exception {
assertThat(localBlockchain.getChainHeadBlock()).isEqualTo(remoteBlockchain.getChainHeadBlock());
}

@Test
public void shouldNotSyncUntilHashWhenNotInSync() {
doReturn(false).when(context).isReady();
final Hash hash = getBlockByNumber(REMOTE_HEIGHT).getHash();
final CompletableFuture<Void> future = context.syncBackwardsUntil(hash);

respondUntilFutureIsDone(future);

assertThatThrownBy(future::get)
.isInstanceOf(ExecutionException.class)
.hasMessageContaining("Backward sync is not ready");
assertThat(backwardChain.getFirstHashToAppend()).isEmpty();
}

@Test
public void shouldSyncUntilRemoteBranch() throws Exception {

Expand Down

0 comments on commit a7b10db

Please sign in to comment.