Search in sources :

Example 26 with Blockchain

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);
}
Also used : AssertionsForClassTypes.assertThatExceptionOfType(org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BftQueryService(org.hyperledger.besu.plugin.services.query.BftQueryService) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Util(org.hyperledger.besu.ethereum.core.Util) BftBlockHeaderFunctions(org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions) Lists(com.google.common.collect.Lists) BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) BftExtraDataCodec(org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec) NoSuchElementException(java.util.NoSuchElementException) Before(org.junit.Before) NonBesuBlockHeader(org.hyperledger.besu.ethereum.core.NonBesuBlockHeader) NodeKeyUtils(org.hyperledger.besu.crypto.NodeKeyUtils) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Collectors(java.util.stream.Collectors) List(java.util.List) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) NodeKey(org.hyperledger.besu.crypto.NodeKey) Hash(org.hyperledger.besu.datatypes.Hash) Address(org.hyperledger.besu.datatypes.Address) BftQueryService(org.hyperledger.besu.plugin.services.query.BftQueryService) Test(org.junit.Test)

Example 27 with Blockchain

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));
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) Address(org.hyperledger.besu.datatypes.Address) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) Test(org.junit.Test)

Example 28 with Blockchain

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);
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) Address(org.hyperledger.besu.datatypes.Address) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) Test(org.junit.Test)

Example 29 with Blockchain

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));
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) Address(org.hyperledger.besu.datatypes.Address) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) Test(org.junit.Test)

Example 30 with Blockchain

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));
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) Address(org.hyperledger.besu.datatypes.Address) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) Test(org.junit.Test)

Aggregations

Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)72 Test (org.junit.Test)45 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)42 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)36 Optional (java.util.Optional)31 Hash (org.hyperledger.besu.datatypes.Hash)31 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)31 List (java.util.List)30 Block (org.hyperledger.besu.ethereum.core.Block)30 Bytes (org.apache.tuweni.bytes.Bytes)27 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)26 Transaction (org.hyperledger.besu.ethereum.core.Transaction)25 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)24 InMemoryKeyValueStorageProvider.createInMemoryBlockchain (org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain)24 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)23 ArrayList (java.util.ArrayList)22 Difficulty (org.hyperledger.besu.ethereum.core.Difficulty)22 CompletableFuture (java.util.concurrent.CompletableFuture)21 Wei (org.hyperledger.besu.datatypes.Wei)21 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)21