Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bws internal error fix #6806

Merged
merged 7 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -228,6 +228,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