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

Delegate all the block checks and validation to the block import phase #4098

Merged
merged 2 commits into from
Jul 14, 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 @@ -5,6 +5,7 @@
### Additions and Improvements
- Add a block to the bad blocks if it did not descend from the terminal block [#4080](https://github.com/hyperledger/besu/pull/4080)
- Backward sync exception improvements [#4092](https://github.com/hyperledger/besu/pull/4092)
- Remove block header checks during backward sync, since they will be always performed during block import phase [#4098](https://github.com/hyperledger/besu/pull/4098)

### Bug Fixes
- Return the correct latest valid hash in case of bad block when calling engine methods [#4056](https://github.com/hyperledger/besu/pull/4056)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ public synchronized void prependAncestorsHeader(final BlockHeader blockHeader) {
BlockHeader firstHeader = firstStoredAncestor.get();
if (firstHeader.getNumber() != blockHeader.getNumber() + 1) {
throw new BackwardSyncException(
"Block "
+ firstHeader.toLogString()
+ " has a wrong height, we were expecting "
+ (blockHeader.getNumber() + 1));
"Wrong height of header "
+ blockHeader.getHash().toHexString()
+ " is "
+ blockHeader.getNumber()
+ " when we were expecting "
+ (firstHeader.getNumber() - 1));
}
if (!firstHeader.getParentHash().equals(blockHeader.getHash())) {
throw new BackwardSyncException(
"For block "
+ firstHeader.toLogString()
+ " we were expecting the parent with hash "
+ firstHeader.getParentHash().toHexString()
+ " while as parent we found "
+ blockHeader.toLogString());
"Hash of header does not match our expectations, was "
+ blockHeader.toLogString()
+ " when we expected "
+ firstHeader.getParentHash().toHexString());
}
headers.put(blockHeader.getHash(), blockHeader);
chainStorage.put(blockHeader.getHash(), firstStoredAncestor.get().getHash());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
package org.hyperledger.besu.ethereum.eth.sync.backwardsync;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.hyperledger.besu.ethereum.eth.sync.backwardsync.ChainForTestCreator.prepareChain;
import static org.hyperledger.besu.ethereum.eth.sync.backwardsync.ChainForTestCreator.prepareWrongParentHash;

import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.core.Block;
Expand Down Expand Up @@ -95,32 +93,6 @@ public void shouldSaveHeadersWhenHeightAndHashMatches() {
assertThat(firstHeader).isEqualTo(blocks.get(blocks.size() - 4).getHeader());
}

@Test
public void shouldNotSaveHeadersWhenWrongHeight() {
BackwardChain backwardChain = createChainFromBlock(blocks.get(blocks.size() - 1));
backwardChain.prependAncestorsHeader(blocks.get(blocks.size() - 2).getHeader());
backwardChain.prependAncestorsHeader(blocks.get(blocks.size() - 3).getHeader());
assertThatThrownBy(
() -> backwardChain.prependAncestorsHeader(blocks.get(blocks.size() - 5).getHeader()))
.isInstanceOf(BackwardSyncException.class)
.hasMessageContaining("has a wrong height");
BlockHeader firstHeader = backwardChain.getFirstAncestorHeader().orElseThrow();
assertThat(firstHeader).isEqualTo(blocks.get(blocks.size() - 3).getHeader());
}

@Test
public void shouldNotSaveHeadersWhenWrongHash() {
BackwardChain backwardChain = createChainFromBlock(blocks.get(blocks.size() - 1));
backwardChain.prependAncestorsHeader(blocks.get(blocks.size() - 2).getHeader());
backwardChain.prependAncestorsHeader(blocks.get(blocks.size() - 3).getHeader());
BlockHeader wrongHashHeader = prepareWrongParentHash(blocks.get(blocks.size() - 4).getHeader());
assertThatThrownBy(() -> backwardChain.prependAncestorsHeader(wrongHashHeader))
.isInstanceOf(BackwardSyncException.class)
.hasMessageContaining("we were expecting the parent with hash");
BlockHeader firstHeader = backwardChain.getFirstAncestorHeader().orElseThrow();
assertThat(firstHeader).isEqualTo(blocks.get(blocks.size() - 3).getHeader());
}

@Test
public void shouldDropFromTheEnd() {

Expand Down