use of org.hyperledger.besu.ethereum.chain.Blockchain in project besu by hyperledger.
the class BftQueryServiceImplTest method getValidatorsReturnsAddresses.
@Test
public void getValidatorsReturnsAddresses() {
final BftQueryService service = new BftQueryServiceImpl(bftBlockInterface, blockchain, validatorProvider, null, null);
final List<Address> validators = signingKeys.stream().map(nodeKey -> Util.publicKeyToAddress(nodeKey.getPublicKey())).collect(Collectors.toList());
when(validatorProvider.getValidatorsAtHead()).thenReturn(validators);
assertThat(service.getValidatorsForLatestBlock()).containsExactlyElementsOf(validators);
}
use of org.hyperledger.besu.ethereum.chain.Blockchain in project besu by hyperledger.
the class ProposerSelectorTest method whenProposerSelfRemovesSelectsNextProposerInLineEvenWhenSticky.
@Test
public void whenProposerSelfRemovesSelectsNextProposerInLineEvenWhenSticky() {
final long PREV_BLOCK_NUMBER = 2;
final ConsensusRoundIdentifier roundId = new ConsensusRoundIdentifier(PREV_BLOCK_NUMBER + 1, 0);
// arbitrarily selected
final Address localAddr = AddressHelpers.ofValue(10);
// LocalAddr will be in index 2 - the next proposer will also be in 2 (as prev proposer is
// removed)
final List<Address> validatorList = createValidatorList(localAddr, 2, 2);
validatorList.remove(localAddr);
// Note the signer of the Previous block was not included.
final Blockchain blockchain = createMockedBlockChainWithHeadOf(PREV_BLOCK_NUMBER, localAddr, validatorList);
final ProposerSelector uut = new ProposerSelector(blockchain, blockInterface, false, validatorProvider);
assertThat(uut.selectProposerForRound(roundId)).isEqualTo(validatorList.get(2));
}
use of org.hyperledger.besu.ethereum.chain.Blockchain in project besu by hyperledger.
the class ProposerSelectorTest method stickyProposerDoesNotChangeOnRoundZeroOfNextBlock.
@Test
public void stickyProposerDoesNotChangeOnRoundZeroOfNextBlock() {
final long PREV_BLOCK_NUMBER = 2;
final ConsensusRoundIdentifier roundId = new ConsensusRoundIdentifier(PREV_BLOCK_NUMBER + 1, 0);
// arbitrarily selected
final Address localAddr = AddressHelpers.ofValue(10);
final List<Address> validatorList = createValidatorList(localAddr, 4, 0);
final Blockchain blockchain = createMockedBlockChainWithHeadOf(PREV_BLOCK_NUMBER, localAddr, validatorList);
final ProposerSelector uut = new ProposerSelector(blockchain, blockInterface, false, validatorProvider);
final Address nextProposer = uut.selectProposerForRound(roundId);
assertThat(nextProposer).isEqualTo(localAddr);
}
use of org.hyperledger.besu.ethereum.chain.Blockchain in project besu by hyperledger.
the class ProposerSelectorTest method stickyProposerChangesOnSubsequentRoundsAtSameBlockHeight.
@Test
public void stickyProposerChangesOnSubsequentRoundsAtSameBlockHeight() {
final long PREV_BLOCK_NUMBER = 2;
ConsensusRoundIdentifier roundId = new ConsensusRoundIdentifier(PREV_BLOCK_NUMBER + 1, 0);
// arbitrarily selected
final Address localAddr = AddressHelpers.ofValue(10);
final List<Address> validatorList = createValidatorList(localAddr, 4, 0);
final Blockchain blockchain = createMockedBlockChainWithHeadOf(PREV_BLOCK_NUMBER, localAddr, validatorList);
final ProposerSelector uut = new ProposerSelector(blockchain, blockInterface, false, validatorProvider);
assertThat(uut.selectProposerForRound(roundId)).isEqualTo(localAddr);
roundId = new ConsensusRoundIdentifier(PREV_BLOCK_NUMBER + 1, 1);
assertThat(uut.selectProposerForRound(roundId)).isEqualTo(validatorList.get(0));
roundId = new ConsensusRoundIdentifier(PREV_BLOCK_NUMBER + 1, 2);
assertThat(uut.selectProposerForRound(roundId)).isEqualTo(validatorList.get(1));
}
use of org.hyperledger.besu.ethereum.chain.Blockchain in project besu by hyperledger.
the class ProposerSelectorTest method roundRobinChangesProposerOnRoundZeroOfNextBlock.
@Test
public void roundRobinChangesProposerOnRoundZeroOfNextBlock() {
final long PREV_BLOCK_NUMBER = 2;
// arbitrarily selected
final Address localAddr = AddressHelpers.ofValue(10);
final List<Address> validatorList = createValidatorList(localAddr, 0, 4);
final Blockchain blockchain = createMockedBlockChainWithHeadOf(PREV_BLOCK_NUMBER, localAddr, validatorList);
final ProposerSelector uut = new ProposerSelector(blockchain, blockInterface, true, validatorProvider);
final ConsensusRoundIdentifier roundId = new ConsensusRoundIdentifier(PREV_BLOCK_NUMBER + 1, 0);
final Address nextProposer = uut.selectProposerForRound(roundId);
assertThat(nextProposer).isEqualTo(validatorList.get(1));
}
Aggregations