Search in sources :

Example 1 with Proposal

use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.

the class BFTEventVerifierTest method when_process_bad_author_proposal_then_should_not_be_forwarded.

@Test
public void when_process_bad_author_proposal_then_should_not_be_forwarded() {
    Proposal proposal = mock(Proposal.class);
    BFTNode author = mock(BFTNode.class);
    when(proposal.getAuthor()).thenReturn(author);
    when(proposal.getSignature()).thenReturn(mock(ECDSASignature.class));
    when(validatorSet.containsNode(eq(author))).thenReturn(false);
    when(verifier.verify(any(), any(), any())).thenReturn(true);
    eventVerifier.processProposal(proposal);
    verify(forwardTo, never()).processProposal(any());
}
Also used : ECDSASignature(com.radixdlt.crypto.ECDSASignature) Proposal(com.radixdlt.hotstuff.Proposal) Test(org.junit.Test)

Example 2 with Proposal

use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.

the class BFTEventVerifierTest method when_process_correct_proposal_then_should_be_forwarded.

@Test
public void when_process_correct_proposal_then_should_be_forwarded() {
    Proposal proposal = mock(Proposal.class);
    BFTNode author = mock(BFTNode.class);
    when(proposal.getAuthor()).thenReturn(author);
    when(proposal.getSignature()).thenReturn(mock(ECDSASignature.class));
    when(validatorSet.containsNode(eq(author))).thenReturn(true);
    when(verifier.verify(any(), any(), any())).thenReturn(true);
    when(safetyRules.verifyHighQcAgainstTheValidatorSet(any())).thenReturn(true);
    eventVerifier.processProposal(proposal);
    verify(forwardTo, times(1)).processProposal(eq(proposal));
}
Also used : ECDSASignature(com.radixdlt.crypto.ECDSASignature) Proposal(com.radixdlt.hotstuff.Proposal) Test(org.junit.Test)

Example 3 with Proposal

use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.

the class FProposalsPerViewDropper method test.

@Override
public boolean test(SimulationNetwork.MessageInTransit msg) {
    if (msg.getContent() instanceof Proposal) {
        final Proposal proposal = (Proposal) msg.getContent();
        final View view = proposal.getVertex().getView();
        final Set<BFTNode> nodesToDrop = proposalToDrop.computeIfAbsent(view, v -> {
            final List<BFTNode> nodes = Lists.newArrayList(validatorSet);
            if (random != null) {
                Collections.shuffle(nodes, random);
            }
            return ImmutableSet.copyOf(nodes.subList(0, faultySize));
        });
        if (proposalCount.merge(view, 1, Integer::sum).equals(validatorSet.size())) {
            proposalToDrop.remove(view);
            proposalCount.remove(view);
        }
        return nodesToDrop.contains(msg.getReceiver());
    }
    return false;
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) View(com.radixdlt.hotstuff.bft.View) Proposal(com.radixdlt.hotstuff.Proposal)

Example 4 with Proposal

use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.

the class ProposalSerializeTest method get.

private static Proposal get() {
    View view = View.of(1234567891L);
    HashCode id = HashUtils.random256();
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    BFTHeader header = new BFTHeader(view, id, ledgerHeader);
    BFTHeader parent = new BFTHeader(View.of(1234567890L), HashUtils.random256(), ledgerHeader);
    VoteData voteData = new VoteData(header, parent, null);
    QuorumCertificate qc = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
    var txn = Txn.create(new byte[] { 0, 1, 2, 3 });
    // add a particle to ensure atom is valid and has at least one shard
    BFTNode author = BFTNode.create(ECKeyPair.generateNew().getPublicKey());
    UnverifiedVertex vertex = UnverifiedVertex.create(qc, view, List.of(txn), author);
    return new Proposal(vertex, qc, ECDSASignature.zeroSignature(), Optional.empty());
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTHeader(com.radixdlt.hotstuff.BFTHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) HashCode(com.google.common.hash.HashCode) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) View(com.radixdlt.hotstuff.bft.View) VoteData(com.radixdlt.hotstuff.VoteData) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) Proposal(com.radixdlt.hotstuff.Proposal)

Example 5 with Proposal

use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.

the class ConsensusModuleTest method getExternalModule.

private Module getExternalModule() {
    return new AbstractModule() {

        @Override
        protected void configure() {
            bind(Ledger.class).toInstance(mock(Ledger.class));
            bind(new TypeLiteral<EventDispatcher<LocalTimeoutOccurrence>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<ViewUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTInsertUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTRebuildUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTHighQCUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTCommittedUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LocalSyncRequest>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<ScheduledLocalTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<ViewQuorumReached>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<Vote>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<Proposal>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(requestSender);
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesResponse>>() {
            }).toInstance(responseSender);
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesErrorResponse>>() {
            }).toInstance(errorResponseSender);
            bind(new TypeLiteral<EventDispatcher<NoVote>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<View>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<VertexRequestTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
            bind(PersistentSafetyStateStore.class).toInstance(mock(PersistentSafetyStateStore.class));
            bind(NextTxnsGenerator.class).toInstance(mock(NextTxnsGenerator.class));
            bind(SystemCounters.class).toInstance(mock(SystemCounters.class));
            bind(TimeSupplier.class).toInstance(mock(TimeSupplier.class));
            bind(BFTConfiguration.class).toInstance(bftConfiguration);
            bind(BFTValidatorSet.class).toInstance(bftConfiguration.getValidatorSet());
            LedgerProof proof = mock(LedgerProof.class);
            when(proof.getView()).thenReturn(View.genesis());
            bind(LedgerProof.class).annotatedWith(LastProof.class).toInstance(proof);
            bind(RateLimiter.class).annotatedWith(GetVerticesRequestRateLimit.class).toInstance(RateLimiter.create(Double.MAX_VALUE));
            bindConstant().annotatedWith(BFTSyncPatienceMillis.class).to(200);
            bindConstant().annotatedWith(PacemakerTimeout.class).to(1000L);
            bindConstant().annotatedWith(PacemakerRate.class).to(2.0);
            bindConstant().annotatedWith(PacemakerMaxExponent.class).to(6);
            ECKeyPair ecKeyPair = ECKeyPair.generateNew();
            bind(HashSigner.class).toInstance(ecKeyPair::sign);
        }

        @Provides
        ViewUpdate viewUpdate(@Self BFTNode node) {
            return ViewUpdate.create(View.of(1), mock(HighQC.class), node, node);
        }

        @Provides
        @Self
        private BFTNode bftNode() {
            return BFTNode.create(ecKeyPair.getPublicKey());
        }
    };
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) TimeSupplier(com.radixdlt.utils.TimeSupplier) Self(com.radixdlt.hotstuff.bft.Self) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) EventDispatcher(com.radixdlt.environment.EventDispatcher) TypeLiteral(com.google.inject.TypeLiteral) LedgerProof(com.radixdlt.hotstuff.LedgerProof) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) NoVote(com.radixdlt.hotstuff.bft.NoVote) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) Ledger(com.radixdlt.hotstuff.Ledger) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) ECKeyPair(com.radixdlt.crypto.ECKeyPair) HashSigner(com.radixdlt.hotstuff.HashSigner) SystemCounters(com.radixdlt.counters.SystemCounters) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) View(com.radixdlt.hotstuff.bft.View) AbstractModule(com.google.inject.AbstractModule) LastProof(com.radixdlt.store.LastProof) NoVote(com.radixdlt.hotstuff.bft.NoVote) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) Proposal(com.radixdlt.hotstuff.Proposal)

Aggregations

Proposal (com.radixdlt.hotstuff.Proposal)11 ECDSASignature (com.radixdlt.crypto.ECDSASignature)5 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)5 View (com.radixdlt.hotstuff.bft.View)4 Test (org.junit.Test)4 AbstractModule (com.google.inject.AbstractModule)2 TypeLiteral (com.google.inject.TypeLiteral)2 SystemCounters (com.radixdlt.counters.SystemCounters)2 EventDispatcher (com.radixdlt.environment.EventDispatcher)2 RemoteEventDispatcher (com.radixdlt.environment.RemoteEventDispatcher)2 ScheduledEventDispatcher (com.radixdlt.environment.ScheduledEventDispatcher)2 BFTConfiguration (com.radixdlt.hotstuff.BFTConfiguration)2 HashSigner (com.radixdlt.hotstuff.HashSigner)2 HighQC (com.radixdlt.hotstuff.HighQC)2 Vote (com.radixdlt.hotstuff.Vote)2 BFTCommittedUpdate (com.radixdlt.hotstuff.bft.BFTCommittedUpdate)2 BFTHighQCUpdate (com.radixdlt.hotstuff.bft.BFTHighQCUpdate)2 BFTInsertUpdate (com.radixdlt.hotstuff.bft.BFTInsertUpdate)2 BFTRebuildUpdate (com.radixdlt.hotstuff.bft.BFTRebuildUpdate)2 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)2