Skip to content

Commit

Permalink
Remove hash to append from the queue only if the step succeeds (hyper…
Browse files Browse the repository at this point in the history
…ledger#4105)

* Remove hash to append from the queue only if the step succeeds

Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 authored and eum602 committed Nov 3, 2023
1 parent ea39842 commit 2ea6752
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
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

0 comments on commit 2ea6752

Please sign in to comment.