Search in sources :

Example 26 with BFTNode

use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.

the class WeightedRotatingLeadersTest method when_get_proposer_skipping_views__then_should_return_same_result_as_in_order.

@Test
public void when_get_proposer_skipping_views__then_should_return_same_result_as_in_order() {
    for (int validatorSetSize = 1; validatorSetSize <= 128; validatorSetSize *= 2) {
        for (int sizeOfCache = 1; sizeOfCache <= 128; sizeOfCache *= 2) {
            setUp(validatorSetSize, sizeOfCache);
            // 2 * sizeOfCache so cache eviction occurs
            final int viewsToTest = 2 * sizeOfCache;
            for (int view = 0; view < viewsToTest; view++) {
                weightedRotatingLeaders2.getProposer(View.of(view));
            }
            BFTNode node1 = weightedRotatingLeaders.getProposer(View.of(viewsToTest - 1));
            BFTNode node2 = weightedRotatingLeaders2.getProposer(View.of(viewsToTest - 1));
            assertThat(node1).isEqualTo(node2);
        }
    }
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Test(org.junit.Test)

Example 27 with BFTNode

use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.

the class WeightedRotatingLeadersTest method when_validators_distributed_by_fibonacci__then_leaders_also_distributed_in_fibonacci.

@Test
public void when_validators_distributed_by_fibonacci__then_leaders_also_distributed_in_fibonacci() {
    // fibonacci sequence can quickly explode so keep sizes small
    final int validatorSetSize = 8;
    final int sizeOfCache = 4;
    final Supplier<IntStream> fibonacci = () -> Stream.iterate(new int[] { 1, 1 }, t -> new int[] { t[1], t[0] + t[1] }).mapToInt(t -> t[0]).limit(validatorSetSize);
    final int sumOfPower = fibonacci.get().sum();
    this.validatorsInOrder = fibonacci.get().mapToObj(p -> BFTValidator.from(BFTNode.random(), UInt256.from(p))).collect(ImmutableList.toImmutableList());
    BFTValidatorSet validatorSet = BFTValidatorSet.from(validatorsInOrder);
    this.weightedRotatingLeaders = new WeightedRotatingLeaders(validatorSet, sizeOfCache);
    Map<BFTNode, UInt256> proposerCounts = Stream.iterate(View.of(0), View::next).limit(sumOfPower).map(this.weightedRotatingLeaders::getProposer).collect(groupingBy(p -> p, collectingAndThen(counting(), UInt256::from)));
    Map<BFTNode, UInt256> expected = validatorsInOrder.stream().collect(toMap(BFTValidator::getNode, BFTValidator::getPower));
    assertThat(proposerCounts).isEqualTo(expected);
}
Also used : IntStream(java.util.stream.IntStream) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors.counting(java.util.stream.Collectors.counting) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Test(org.junit.Test) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) Supplier(java.util.function.Supplier) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ECKeyPair(com.radixdlt.crypto.ECKeyPair) View(com.radixdlt.hotstuff.bft.View) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) ImmutableList(com.google.common.collect.ImmutableList) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Map(java.util.Map) KeyComparator(com.radixdlt.utils.KeyComparator) Comparator(java.util.Comparator) UInt256(com.radixdlt.utils.UInt256) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) IntStream(java.util.stream.IntStream) UInt256(com.radixdlt.utils.UInt256) Test(org.junit.Test)

Example 28 with BFTNode

use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.

the class MessageCentralBFTNetworkTest method when_send_vote__then_message_central_should_be_sent_vote_message.

@Test
public void when_send_vote__then_message_central_should_be_sent_vote_message() {
    Vote vote = mock(Vote.class);
    ECPublicKey leaderPk = ECKeyPair.generateNew().getPublicKey();
    BFTNode leader = mock(BFTNode.class);
    when(leader.getKey()).thenReturn(leaderPk);
    network.voteDispatcher().dispatch(leader, vote);
    verify(messageCentral, times(1)).send(eq(NodeId.fromPublicKey(leaderPk)), any(ConsensusEventMessage.class));
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) ECPublicKey(com.radixdlt.crypto.ECPublicKey) Test(org.junit.Test)

Example 29 with BFTNode

use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.

the class MessageCentralValidatorSyncTest method when_send_response__then_message_central_will_send_response.

@Test
public void when_send_response__then_message_central_will_send_response() {
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.toSerializable()).thenReturn(mock(UnverifiedVertex.class));
    ImmutableList<VerifiedVertex> vertices = ImmutableList.of(vertex);
    BFTNode node = mock(BFTNode.class);
    ECPublicKey ecPublicKey = mock(ECPublicKey.class);
    when(node.getKey()).thenReturn(ecPublicKey);
    sync.verticesResponseDispatcher().dispatch(node, new GetVerticesResponse(vertices));
    verify(messageCentral, times(1)).send(any(), any(GetVerticesResponseMessage.class));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) ECPublicKey(com.radixdlt.crypto.ECPublicKey) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) Test(org.junit.Test)

Example 30 with BFTNode

use of com.radixdlt.hotstuff.bft.BFTNode in project radixdlt by radixdlt.

the class SafetyChecker method process.

private Optional<TestInvariantError> process(BFTNode node, VerifiedVertex vertex) {
    final EpochView epochView = EpochView.of(vertex.getParentHeader().getLedgerHeader().getEpoch(), vertex.getView());
    final VerifiedVertex currentVertexAtView = committedVertices.get(epochView);
    if (currentVertexAtView != null) {
        if (!currentVertexAtView.getId().equals(vertex.getId())) {
            return conflictingVerticesError(vertex, currentVertexAtView);
        }
    } else {
        EpochView parentEpochView = EpochView.of(vertex.getParentHeader().getLedgerHeader().getEpoch(), vertex.getParentHeader().getView());
        VerifiedVertex parent = committedVertices.get(parentEpochView);
        if (parent == null) {
            Entry<EpochView, VerifiedVertex> higherCommitted = committedVertices.higherEntry(parentEpochView);
            if (higherCommitted != null) {
                BFTHeader higherParentHeader = higherCommitted.getValue().getParentHeader();
                EpochView higherCommittedParentEpochView = EpochView.of(higherParentHeader.getLedgerHeader().getEpoch(), higherParentHeader.getView());
                if (epochView.compareTo(higherCommittedParentEpochView) > 0) {
                    return brokenChainError(vertex, higherCommitted.getValue());
                }
            }
        }
        committedVertices.put(epochView, vertex);
    }
    // Clean up old vertices so that we avoid consuming too much memory
    lastCommittedByNode.put(node, epochView);
    final EpochView lowest = nodes.stream().map(n -> lastCommittedByNode.getOrDefault(n, EpochView.of(0, View.genesis()))).reduce((v0, v1) -> v0.compareTo(v1) < 0 ? v0 : v1).orElse(EpochView.of(0, View.genesis()));
    committedVertices.headMap(lowest).clear();
    return Optional.empty();
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) EpochView(com.radixdlt.hotstuff.epoch.EpochView) BFTHeader(com.radixdlt.hotstuff.BFTHeader) ImmutableSet(com.google.common.collect.ImmutableSet) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Objects(java.util.Objects) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) View(com.radixdlt.hotstuff.bft.View) ImmutableList(com.google.common.collect.ImmutableList) TestInvariantError(com.radixdlt.harness.simulation.TestInvariant.TestInvariantError) TreeMap(java.util.TreeMap) Map(java.util.Map) Entry(java.util.Map.Entry) Optional(java.util.Optional) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) BFTHeader(com.radixdlt.hotstuff.BFTHeader) EpochView(com.radixdlt.hotstuff.epoch.EpochView)

Aggregations

BFTNode (com.radixdlt.hotstuff.bft.BFTNode)40 Test (org.junit.Test)22 View (com.radixdlt.hotstuff.bft.View)14 LedgerProof (com.radixdlt.hotstuff.LedgerProof)9 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)9 HashCode (com.google.common.hash.HashCode)8 ECKeyPair (com.radixdlt.crypto.ECKeyPair)8 HighQC (com.radixdlt.hotstuff.HighQC)8 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)8 Vote (com.radixdlt.hotstuff.Vote)7 ImmutableList (com.google.common.collect.ImmutableList)6 AbstractModule (com.google.inject.AbstractModule)6 TypeLiteral (com.google.inject.TypeLiteral)6 BFTHeader (com.radixdlt.hotstuff.BFTHeader)6 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)6 Proposal (com.radixdlt.hotstuff.Proposal)5 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)5 BFTCommittedUpdate (com.radixdlt.hotstuff.bft.BFTCommittedUpdate)5 Self (com.radixdlt.hotstuff.bft.Self)5 Inject (com.google.inject.Inject)4