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

Remove hash to append from the queue only if the step succeeds #4105

Merged
merged 4 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Add a PoS block header rule to check that the current block is more recent than its parent [#4066](https://github.com/hyperledger/besu/pull/4066)
- Fixed a trie log layer issue on bonsai during reorg [#4069](https://github.com/hyperledger/besu/pull/4069)
- Fix transition protocol schedule to return the pre Merge schedule when reorg pre TTD [#4078](https://github.com/hyperledger/besu/pull/4078)
- Remove hash to sync from the queue only if the sync step succeeds [#4105](https://github.com/hyperledger/besu/pull/4105)
- The build process runs successfully even though the system language is not English [#4102](https://github.com/hyperledger/besu/pull/4102)

## 22.7.0-RC1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ public synchronized void addNewHash(final Hash newBlockHash) {
}

public synchronized Optional<Hash> getFirstHashToAppend() {
return Optional.ofNullable(hashesToAppend.poll());
return Optional.ofNullable(hashesToAppend.peek());
}

public synchronized void removeFromHashToAppend(final Hash hashToRemove) {
if (hashesToAppend.contains(hashToRemove)) {
hashesToAppend.remove(hashToRemove);
}
}

public void addBadChainToManager(final BadBlockManager badBlocksManager, final Hash hash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public CompletableFuture<Void> executeBackwardsSync(final Void unused) {
public CompletableFuture<Void> pickNextStep() {
final Optional<Hash> firstHash = context.getBackwardChain().getFirstHashToAppend();
if (firstHash.isPresent()) {
return executeSyncStep(firstHash.get());
return executeSyncStep(firstHash.get())
.whenComplete(
(result, throwable) -> {
if (throwable == null) {
context.getBackwardChain().removeFromHashToAppend(firstHash.get());
}
});
}
if (!context.isReady()) {
return waitForReady();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,15 @@ public void shouldAddHeaderToQueue() {
firstHash = backwardChain.getFirstHashToAppend();
assertThat(firstHash).isPresent();
assertThat(firstHash.orElseThrow()).isEqualTo(blocks.get(7).getHash());
backwardChain.removeFromHashToAppend(firstHash.get());
firstHash = backwardChain.getFirstHashToAppend();
assertThat(firstHash).isPresent();
assertThat(firstHash.orElseThrow()).isEqualTo(blocks.get(9).getHash());
backwardChain.removeFromHashToAppend(firstHash.get());
firstHash = backwardChain.getFirstHashToAppend();
assertThat(firstHash).isPresent();
assertThat(firstHash.orElseThrow()).isEqualTo(blocks.get(11).getHash());
backwardChain.removeFromHashToAppend(firstHash.get());
}

@Test
Expand Down