Search in sources :

Example 21 with BFTNode

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

the class RadixEngineStateComputerTest method getExternalModule.

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

        @Override
        public void configure() {
            var validatorSet = BFTValidatorSet.from(registeredNodes.stream().map(ECKeyPair::getPublicKey).map(BFTNode::create).map(n -> BFTValidator.from(n, UInt256.ONE)));
            bind(ProposerElection.class).toInstance(new WeightedRotatingLeaders(validatorSet));
            bind(Serialization.class).toInstance(serialization);
            bind(Hasher.class).toInstance(Sha256Hasher.withDefaultSerialization());
            bind(new TypeLiteral<EngineStore<LedgerAndBFTProof>>() {
            }).toInstance(engineStore);
            bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
            install(MempoolConfig.asModule(10, 10));
            install(new MainnetForksModule());
            install(new RadixEngineForksLatestOnlyModule());
            install(new ForksModule());
            // HACK
            bind(CommittedReader.class).toInstance(new NoOpCommittedReader());
            bind(ForksEpochStore.class).toInstance(new NoOpForksEpochStore());
            bind(LedgerAccumulator.class).to(SimpleLedgerAccumulatorAndVerifier.class);
            bind(new TypeLiteral<EventDispatcher<MempoolAddSuccess>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<InvalidProposedTxn>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<TxnsRemovedFromMempool>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<REOutput>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<MempoolRelayTrigger>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LedgerUpdate>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(SystemCounters.class).to(SystemCountersImpl.class);
        }
    };
}
Also used : Module(com.google.inject.Module) SimpleLedgerAccumulatorAndVerifier(com.radixdlt.ledger.SimpleLedgerAccumulatorAndVerifier) TxAction(com.radixdlt.atom.TxAction) NoOpCommittedReader(com.radixdlt.sync.NoOpCommittedReader) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) RadixEngineException(com.radixdlt.engine.RadixEngineException) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) TypedMocks(com.radixdlt.utils.TypedMocks) DefaultSerialization(com.radixdlt.DefaultSerialization) Hasher(com.radixdlt.crypto.Hasher) MempoolAdd(com.radixdlt.mempool.MempoolAdd) RoundData(com.radixdlt.application.system.state.RoundData) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) ByzantineQuorumException(com.radixdlt.ledger.ByzantineQuorumException) CurrentForkView(com.radixdlt.statecomputer.forks.CurrentForkView) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) HashUtils(com.radixdlt.crypto.HashUtils) Genesis(com.radixdlt.statecomputer.checkpoint.Genesis) SystemCounters(com.radixdlt.counters.SystemCounters) NoOpForksEpochStore(com.radixdlt.statecomputer.forks.NoOpForksEpochStore) REEvent(com.radixdlt.constraintmachine.REEvent) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) EngineStore(com.radixdlt.store.EngineStore) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) Collectors(java.util.stream.Collectors) ForksEpochStore(com.radixdlt.statecomputer.forks.ForksEpochStore) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) CommittedReader(com.radixdlt.sync.CommittedReader) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) Amount(com.radixdlt.application.tokens.Amount) TypeLiteral(com.google.inject.TypeLiteral) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) Mockito.mock(org.mockito.Mockito.mock) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Serialization(com.radixdlt.serialization.Serialization) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) com.radixdlt.atom(com.radixdlt.atom) ProposerElection(com.radixdlt.hotstuff.liveness.ProposerElection) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) View(com.radixdlt.hotstuff.bft.View) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) MempoolConfig(com.radixdlt.mempool.MempoolConfig) AccumulatorState(com.radixdlt.ledger.AccumulatorState) RadixEngineCheckpointModule(com.radixdlt.statecomputer.checkpoint.RadixEngineCheckpointModule) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) BFTHeader(com.radixdlt.hotstuff.BFTHeader) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) RadixEngine(com.radixdlt.engine.RadixEngine) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) InMemoryEngineStore(com.radixdlt.store.InMemoryEngineStore) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Rule(org.junit.Rule) Ignore(org.junit.Ignore) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) EventDispatcher(com.radixdlt.environment.EventDispatcher) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) TypeLiteral(com.google.inject.TypeLiteral) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) ProposerElection(com.radixdlt.hotstuff.liveness.ProposerElection) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) SystemCounters(com.radixdlt.counters.SystemCounters) NoOpForksEpochStore(com.radixdlt.statecomputer.forks.NoOpForksEpochStore) AbstractModule(com.google.inject.AbstractModule) NoOpCommittedReader(com.radixdlt.sync.NoOpCommittedReader) NoOpForksEpochStore(com.radixdlt.statecomputer.forks.NoOpForksEpochStore) ForksEpochStore(com.radixdlt.statecomputer.forks.ForksEpochStore) DefaultSerialization(com.radixdlt.DefaultSerialization) Serialization(com.radixdlt.serialization.Serialization) Hasher(com.radixdlt.crypto.Hasher) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) NoOpCommittedReader(com.radixdlt.sync.NoOpCommittedReader) CommittedReader(com.radixdlt.sync.CommittedReader) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders)

Example 22 with BFTNode

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

the class MockedRecoveryModule method view.

@Provides
private ViewUpdate view(BFTConfiguration configuration, ProposerElection proposerElection) {
    HighQC highQC = configuration.getVertexStoreState().getHighQC();
    View view = highQC.highestQC().getView().next();
    final BFTNode leader = proposerElection.getProposer(view);
    final BFTNode nextLeader = proposerElection.getProposer(view.next());
    return ViewUpdate.create(view, highQC, leader, nextLeader);
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) View(com.radixdlt.hotstuff.bft.View) Provides(com.google.inject.Provides)

Example 23 with BFTNode

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

the class PacemakerState method updateView.

@Override
public void updateView(View nextView) {
    if (nextView.lte(this.currentView)) {
        return;
    }
    final BFTNode leader = this.proposerElection.getProposer(nextView);
    final BFTNode nextLeader = this.proposerElection.getProposer(nextView.next());
    this.currentView = nextView;
    viewUpdateSender.dispatch(ViewUpdate.create(this.currentView, this.highQC, leader, nextLeader));
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode)

Example 24 with BFTNode

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

the class ConsensusModuleTest method on_synced_to_vertex_should_request_for_parent.

@Test
public void on_synced_to_vertex_should_request_for_parent() {
    // Arrange
    BFTNode bftNode = BFTNode.random();
    QuorumCertificate parent = vertexStore.highQC().highestQC();
    Pair<QuorumCertificate, VerifiedVertex> nextVertex = createNextVertex(parent, validatorKeyPair);
    Pair<QuorumCertificate, VerifiedVertex> nextNextVertex = createNextVertex(nextVertex.getFirst(), validatorKeyPair);
    HighQC unsyncedHighQC = HighQC.from(nextNextVertex.getFirst(), nextNextVertex.getFirst(), Optional.empty());
    bftSync.syncToQC(unsyncedHighQC, bftNode);
    // Act
    // FIXME: Remove when rate limit on send removed
    nothrowSleep(100);
    GetVerticesResponse response = new GetVerticesResponse(ImmutableList.of(nextNextVertex.getSecond()));
    bftSync.responseProcessor().process(bftNode, response);
    // Assert
    verify(requestSender, times(1)).dispatch(eq(bftNode), argThat(r -> r.getCount() == 1 && r.getVertexId().equals(nextVertex.getSecond().getId())));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) Module(com.google.inject.Module) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Inject(com.google.inject.Inject) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) Ledger(com.radixdlt.hotstuff.Ledger) Map(java.util.Map) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) HashUtils(com.radixdlt.crypto.HashUtils) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) SystemCounters(com.radixdlt.counters.SystemCounters) Vote(com.radixdlt.hotstuff.Vote) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) List(java.util.List) Stream(java.util.stream.Stream) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) Optional(java.util.Optional) TypeLiteral(com.google.inject.TypeLiteral) Proposal(com.radixdlt.hotstuff.Proposal) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) Mockito.mock(org.mockito.Mockito.mock) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) RateLimiter(com.google.common.util.concurrent.RateLimiter) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) HashSigner(com.radixdlt.hotstuff.HashSigner) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) VertexStore(com.radixdlt.hotstuff.bft.VertexStore) View(com.radixdlt.hotstuff.bft.View) ImmutableList(com.google.common.collect.ImmutableList) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) AccumulatorState(com.radixdlt.ledger.AccumulatorState) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) BFTSync(com.radixdlt.hotstuff.sync.BFTSync) BFTHeader(com.radixdlt.hotstuff.BFTHeader) TimeSupplier(com.radixdlt.utils.TimeSupplier) EventDispatcher(com.radixdlt.environment.EventDispatcher) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) NoVote(com.radixdlt.hotstuff.bft.NoVote) Txn(com.radixdlt.atom.Txn) VoteData(com.radixdlt.hotstuff.VoteData) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) TimestampedECDSASignature(com.radixdlt.hotstuff.TimestampedECDSASignature) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) Pair(com.radixdlt.utils.Pair) LastProof(com.radixdlt.store.LastProof) AbstractModule(com.google.inject.AbstractModule) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 25 with BFTNode

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

the class PacemakerTest method when_local_timeout__then_resend_previous_vote.

@Test
public void when_local_timeout__then_resend_previous_vote() {
    View view = View.of(0);
    Vote lastVote = mock(Vote.class);
    Vote lastVoteWithTimeout = mock(Vote.class);
    ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
    when(this.safetyRules.getLastVote(view)).thenReturn(Optional.of(lastVote));
    when(this.safetyRules.timeoutVote(lastVote)).thenReturn(lastVoteWithTimeout);
    when(this.validatorSet.nodes()).thenReturn(validators);
    ViewUpdate viewUpdate = ViewUpdate.create(View.of(0), mock(HighQC.class), mock(BFTNode.class), mock(BFTNode.class));
    this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(viewUpdate, 0L));
    verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(lastVoteWithTimeout));
    verifyNoMoreInteractions(this.vertexStore);
    verify(this.safetyRules, times(1)).getLastVote(view);
    verify(this.safetyRules, times(1)).timeoutVote(lastVote);
    verifyNoMoreInteractions(this.safetyRules);
}
Also used : ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) HighQC(com.radixdlt.hotstuff.HighQC) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) View(com.radixdlt.hotstuff.bft.View) Test(org.junit.Test)

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