-
Notifications
You must be signed in to change notification settings - Fork 872
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use correct list of validators when transitioning to different a vali…
…datorselectionmode (#2935) When producing the next block, the previousBlockHeader.number + 1 needs to be used to query the transition forkSchedule. This is because the list of validators associated with each forkSchedule may be a different set to the current block. This commit changes the implementation for getValidatorsAfterBlock to support this and points getValidatorsAtHead at this implementation. Note getValidatorsForBlock's forkSchedule query is unchanged since we have already mined the block at the point this is called (e.g. for RPCs qbft_getValidatorsBy...). For TransactionValidatorProvider, we need to use the next block's contract address but still use the previous block's validators in the contract call itself. Querying validators using afterBlock vs forBlock may yield different (blockNumber -> validatorAddresses) combinations when transitioning into CONTRACT mode. There we also split TransactionValidatorProvider validatorCache into two caches. Add special case to ForkingValidatorProvider (BlockValidatorProvider.hasValidatorOverridesForBlockNumber) to support transitioning to blockheader mode with some validator overrides. This might be needed if the current validator set loses quorum and we are no longer able to vote new ones in. New integration test cases for validatorselectionmode transitions: - contract -> contract - contract1 -> blockheader -> contract2 - contract1 -> blockheader with overridden validators -> contract2 Fixes #2901 Signed-off-by: Simon Dudley <[email protected]>
- Loading branch information
Showing
15 changed files
with
513 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...rg/hyperledger/besu/consensus/common/validator/blockbased/BlockValidatorProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright Hyperledger Besu contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.consensus.common.validator.blockbased; | ||
|
||
import static java.util.Collections.emptyMap; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.consensus.common.BftValidatorOverrides; | ||
import org.hyperledger.besu.consensus.common.BlockInterface; | ||
import org.hyperledger.besu.consensus.common.EpochManager; | ||
import org.hyperledger.besu.datatypes.Address; | ||
import org.hyperledger.besu.ethereum.chain.Blockchain; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.assertj.core.api.SoftAssertions; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class BlockValidatorProviderTest { | ||
|
||
@Mock private BlockInterface blockInterface; | ||
@Mock private Blockchain blockchain; | ||
@Mock private EpochManager epochManager; | ||
|
||
@Test | ||
public void nonForkingValidatorProviderHasNoOverrides() { | ||
final BlockValidatorProvider blockValidatorProvider = | ||
BlockValidatorProvider.nonForkingValidatorProvider( | ||
blockchain, epochManager, blockInterface); | ||
|
||
assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(0)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void forkingValidatorProviderHasNoOverrides() { | ||
final BlockValidatorProvider blockValidatorProvider = | ||
BlockValidatorProvider.forkingValidatorProvider( | ||
blockchain, epochManager, blockInterface, new BftValidatorOverrides(emptyMap())); | ||
|
||
assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(0)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void forkingValidatorProviderHasOverridesForBlock1() { | ||
final Map<Long, List<Address>> overriddenValidators = | ||
Map.of(1L, List.of(Address.fromHexString("0"))); | ||
final BftValidatorOverrides bftValidatorOverrides = | ||
new BftValidatorOverrides(overriddenValidators); | ||
final BlockValidatorProvider blockValidatorProvider = | ||
BlockValidatorProvider.forkingValidatorProvider( | ||
blockchain, epochManager, blockInterface, bftValidatorOverrides); | ||
|
||
SoftAssertions.assertSoftly( | ||
(softly) -> { | ||
softly | ||
.assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(0)) | ||
.as("Block 0 should have no overridden validators") | ||
.isFalse(); | ||
softly | ||
.assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(1)) | ||
.as("Block 1 should have some overridden validators") | ||
.isTrue(); | ||
softly | ||
.assertThat(blockValidatorProvider.hasValidatorOverridesForBlockNumber(2)) | ||
.as("Block 2 should have no overridden validators") | ||
.isFalse(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.