Search in sources :

Example 1 with BFTInsertUpdate

use of com.radixdlt.consensus.bft.BFTInsertUpdate in project radixdlt by radixdlt.

the class PacemakerTest method on_view_timeout_quorum_pacemaker_should_move_to_next_view.

@Test
public void on_view_timeout_quorum_pacemaker_should_move_to_next_view() {
    // Arrange
    createRunner().injectMembers(this);
    processor.start();
    ControlledMessage timeoutMsg = network.nextMessage(e -> Epoched.isInstance(e.message(), ScheduledLocalTimeout.class)).value();
    processor.handleMessage(timeoutMsg.origin(), timeoutMsg.message(), new TypeLiteral<Epoched<ScheduledLocalTimeout>>() {
    });
    ControlledMessage bftUpdateMsg = network.nextMessage(e -> e.message() instanceof BFTInsertUpdate).value();
    processor.handleMessage(bftUpdateMsg.origin(), bftUpdateMsg.message(), null);
    // Act
    ControlledMessage viewTimeout = network.nextMessage(e -> (e.message() instanceof Vote) && ((Vote) e.message()).isTimeout()).value();
    processor.handleMessage(viewTimeout.origin(), viewTimeout.message(), null);
    // Assert
    assertThat(network.allMessages()).haveExactly(1, new Condition<>(msg -> msg.message() instanceof EpochViewUpdate, "A remote view timeout has been emitted"));
    EpochViewUpdate nextEpochViewUpdate = network.allMessages().stream().filter(msg -> msg.message() instanceof EpochViewUpdate).map(ControlledMessage::message).map(EpochViewUpdate.class::cast).findAny().orElseThrow();
    assertThat(nextEpochViewUpdate.getViewUpdate().getCurrentView()).isEqualTo(initialViewUpdate.getCurrentView().next());
}
Also used : ControlledMessage(com.radixdlt.environment.deterministic.network.ControlledMessage) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) Epoched(com.radixdlt.consensus.epoch.Epoched) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) DeterministicNetwork(com.radixdlt.environment.deterministic.network.DeterministicNetwork) EpochViewUpdate(com.radixdlt.consensus.epoch.EpochViewUpdate) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) DatabaseLocation(com.radixdlt.store.DatabaseLocation) MempoolConfig(com.radixdlt.mempool.MempoolConfig) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) PrivateKeys(com.radixdlt.utils.PrivateKeys) Set(java.util.Set) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) Test(org.junit.Test) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Injector(com.google.inject.Injector) Rule(org.junit.Rule) SingleNodeAndPeersDeterministicNetworkModule(com.radixdlt.SingleNodeAndPeersDeterministicNetworkModule) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) Amount(com.radixdlt.application.tokens.Amount) MainnetForkConfigsModule(com.radixdlt.statecomputer.forks.MainnetForkConfigsModule) TypeLiteral(com.google.inject.TypeLiteral) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) EpochViewUpdate(com.radixdlt.consensus.epoch.EpochViewUpdate) ControlledMessage(com.radixdlt.environment.deterministic.network.ControlledMessage) Epoched(com.radixdlt.consensus.epoch.Epoched) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) Test(org.junit.Test)

Example 2 with BFTInsertUpdate

use of com.radixdlt.consensus.bft.BFTInsertUpdate in project radixdlt by radixdlt.

the class PacemakerTest method when_local_timeout__then_send_empty_vote_if_no_previous.

@Test
public void when_local_timeout__then_send_empty_vote_if_no_previous() {
    HighQC viewUpdateHighQc = mock(HighQC.class);
    QuorumCertificate committedQc = mock(QuorumCertificate.class);
    QuorumCertificate highestQc = mock(QuorumCertificate.class);
    when(viewUpdateHighQc.highestCommittedQC()).thenReturn(committedQc);
    when(viewUpdateHighQc.highestQC()).thenReturn(highestQc);
    BFTHeader highestQcProposed = mock(BFTHeader.class);
    HashCode highQcParentVertexId = mock(HashCode.class);
    when(highestQcProposed.getVertexId()).thenReturn(highQcParentVertexId);
    when(highestQc.getProposed()).thenReturn(highestQcProposed);
    when(committedQc.getView()).thenReturn(View.of(0));
    ViewUpdate viewUpdate = ViewUpdate.create(View.of(1), viewUpdateHighQc, mock(BFTNode.class), mock(BFTNode.class));
    this.pacemaker.processViewUpdate(viewUpdate);
    View view = View.of(1);
    Vote emptyVote = mock(Vote.class);
    Vote emptyVoteWithTimeout = mock(Vote.class);
    ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
    BFTHeader bftHeader = mock(BFTHeader.class);
    HighQC highQC = mock(HighQC.class);
    BFTInsertUpdate bftInsertUpdate = mock(BFTInsertUpdate.class);
    when(bftInsertUpdate.getHeader()).thenReturn(bftHeader);
    PreparedVertex preparedVertex = mock(PreparedVertex.class);
    when(preparedVertex.getView()).thenReturn(view);
    when(preparedVertex.getLedgerHeader()).thenReturn(mock(LedgerHeader.class));
    VerifiedVertexStoreState vertexStoreState = mock(VerifiedVertexStoreState.class);
    when(vertexStoreState.getHighQC()).thenReturn(highQC);
    when(bftInsertUpdate.getInserted()).thenReturn(preparedVertex);
    when(bftInsertUpdate.getVertexStoreState()).thenReturn(vertexStoreState);
    var node = BFTNode.random();
    when(preparedVertex.getId()).thenReturn(hasher.hash(UnverifiedVertex.createTimeout(highestQc, view, node)));
    when(this.safetyRules.getLastVote(view)).thenReturn(Optional.empty());
    when(this.safetyRules.createVote(any(), any(), anyLong(), any())).thenReturn(emptyVote);
    when(this.safetyRules.timeoutVote(emptyVote)).thenReturn(emptyVoteWithTimeout);
    when(this.validatorSet.nodes()).thenReturn(validators);
    when(this.vertexStore.getPreparedVertex(any())).thenReturn(Optional.empty());
    this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(ViewUpdate.create(View.of(1), mock(HighQC.class), node, BFTNode.random()), 0L));
    this.pacemaker.processBFTUpdate(bftInsertUpdate);
    verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(emptyVoteWithTimeout));
    verify(this.safetyRules, times(1)).getLastVote(view);
    verify(this.safetyRules, times(1)).createVote(any(), any(), anyLong(), any());
    verify(this.safetyRules, times(1)).timeoutVote(emptyVote);
    verifyNoMoreInteractions(this.safetyRules);
    verify(this.vertexStore, times(1)).getPreparedVertex(any());
    ArgumentCaptor<VerifiedVertex> insertVertexCaptor = ArgumentCaptor.forClass(VerifiedVertex.class);
    verify(this.vertexStore, times(1)).insertVertex(insertVertexCaptor.capture());
    assertEquals(insertVertexCaptor.getValue().getParentId(), highQcParentVertexId);
    verifyNoMoreInteractions(this.vertexStore);
}
Also used : HighQC(com.radixdlt.consensus.HighQC) BFTHeader(com.radixdlt.consensus.BFTHeader) BFTNode(com.radixdlt.consensus.bft.BFTNode) Vote(com.radixdlt.consensus.Vote) PreparedVertex(com.radixdlt.consensus.bft.PreparedVertex) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) View(com.radixdlt.consensus.bft.View) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) LedgerHeader(com.radixdlt.consensus.LedgerHeader) HashCode(com.google.common.hash.HashCode) VerifiedVertexStoreState(com.radixdlt.consensus.bft.VerifiedVertexStoreState) Test(org.junit.Test)

Example 3 with BFTInsertUpdate

use of com.radixdlt.consensus.bft.BFTInsertUpdate 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);
            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.consensus.HighQC) GetVerticesRequest(com.radixdlt.consensus.sync.GetVerticesRequest) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) LocalTimeoutOccurrence(com.radixdlt.consensus.liveness.LocalTimeoutOccurrence) BFTCommittedUpdate(com.radixdlt.consensus.bft.BFTCommittedUpdate) VertexRequestTimeout(com.radixdlt.consensus.sync.VertexRequestTimeout) TimeSupplier(com.radixdlt.utils.TimeSupplier) Self(com.radixdlt.consensus.bft.Self) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) NextTxnsGenerator(com.radixdlt.consensus.liveness.NextTxnsGenerator) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) PacemakerMaxExponent(com.radixdlt.consensus.bft.PacemakerMaxExponent) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) PacemakerRate(com.radixdlt.consensus.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.consensus.LedgerProof) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) BFTNode(com.radixdlt.consensus.bft.BFTNode) Vote(com.radixdlt.consensus.Vote) NoVote(com.radixdlt.consensus.bft.NoVote) BFTSyncPatienceMillis(com.radixdlt.consensus.sync.BFTSyncPatienceMillis) GetVerticesResponse(com.radixdlt.consensus.sync.GetVerticesResponse) BFTRebuildUpdate(com.radixdlt.consensus.bft.BFTRebuildUpdate) GetVerticesErrorResponse(com.radixdlt.consensus.sync.GetVerticesErrorResponse) Ledger(com.radixdlt.consensus.Ledger) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) ECKeyPair(com.radixdlt.crypto.ECKeyPair) HashSigner(com.radixdlt.consensus.HashSigner) SystemCounters(com.radixdlt.counters.SystemCounters) PacemakerTimeout(com.radixdlt.consensus.bft.PacemakerTimeout) View(com.radixdlt.consensus.bft.View) AbstractModule(com.google.inject.AbstractModule) LastProof(com.radixdlt.store.LastProof) NoVote(com.radixdlt.consensus.bft.NoVote) BFTConfiguration(com.radixdlt.consensus.BFTConfiguration) ViewQuorumReached(com.radixdlt.consensus.bft.ViewQuorumReached) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) BFTHighQCUpdate(com.radixdlt.consensus.bft.BFTHighQCUpdate) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PersistentSafetyStateStore(com.radixdlt.consensus.safety.PersistentSafetyStateStore) Proposal(com.radixdlt.consensus.Proposal)

Example 4 with BFTInsertUpdate

use of com.radixdlt.consensus.bft.BFTInsertUpdate in project radixdlt by radixdlt.

the class PacemakerTest method on_timeout_pacemaker_should_send_vote_with_timeout.

@Test
public void on_timeout_pacemaker_should_send_vote_with_timeout() {
    // Arrange
    createRunner().injectMembers(this);
    processor.start();
    // Act
    ControlledMessage timeoutMsg = network.nextMessage(e -> Epoched.isInstance(e.message(), ScheduledLocalTimeout.class)).value();
    processor.handleMessage(timeoutMsg.origin(), timeoutMsg.message(), new TypeLiteral<Epoched<ScheduledLocalTimeout>>() {
    });
    ControlledMessage bftUpdateMsg = network.nextMessage(e -> e.message() instanceof BFTInsertUpdate).value();
    processor.handleMessage(bftUpdateMsg.origin(), bftUpdateMsg.message(), null);
    // Assert
    assertThat(network.allMessages()).haveExactly(1, new Condition<>(msg -> (msg.message() instanceof Vote) && ((Vote) msg.message()).isTimeout(), "A remote timeout vote has been emitted"));
}
Also used : ControlledMessage(com.radixdlt.environment.deterministic.network.ControlledMessage) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) Epoched(com.radixdlt.consensus.epoch.Epoched) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) DeterministicNetwork(com.radixdlt.environment.deterministic.network.DeterministicNetwork) EpochViewUpdate(com.radixdlt.consensus.epoch.EpochViewUpdate) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) DatabaseLocation(com.radixdlt.store.DatabaseLocation) MempoolConfig(com.radixdlt.mempool.MempoolConfig) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) PrivateKeys(com.radixdlt.utils.PrivateKeys) Set(java.util.Set) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) Test(org.junit.Test) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Injector(com.google.inject.Injector) Rule(org.junit.Rule) SingleNodeAndPeersDeterministicNetworkModule(com.radixdlt.SingleNodeAndPeersDeterministicNetworkModule) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) Amount(com.radixdlt.application.tokens.Amount) MainnetForkConfigsModule(com.radixdlt.statecomputer.forks.MainnetForkConfigsModule) TypeLiteral(com.google.inject.TypeLiteral) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) ControlledMessage(com.radixdlt.environment.deterministic.network.ControlledMessage) Epoched(com.radixdlt.consensus.epoch.Epoched) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) Test(org.junit.Test)

Example 5 with BFTInsertUpdate

use of com.radixdlt.consensus.bft.BFTInsertUpdate in project radixdlt by radixdlt.

the class EpochManagerTest method getExternalModule.

private Module getExternalModule() {
    BFTNode self = BFTNode.create(ecKeyPair.getPublicKey());
    return new AbstractModule() {

        @Override
        protected void configure() {
            bind(HashSigner.class).toInstance(ecKeyPair::sign);
            bind(BFTNode.class).annotatedWith(Self.class).toInstance(self);
            bind(new TypeLiteral<EventDispatcher<LocalTimeoutOccurrence>>() {
            }).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<EpochLocalTimeoutOccurrence>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<EpochView>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LocalSyncRequest>>() {
            }).toInstance(syncLedgerRequestSender);
            bind(new TypeLiteral<EventDispatcher<ViewQuorumReached>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<EpochViewUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<ViewUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<NoVote>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LedgerUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(timeoutScheduler);
            bind(new TypeLiteral<ScheduledEventDispatcher<ScheduledLocalTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<Epoched<ScheduledLocalTimeout>>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<VertexRequestTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<Proposal>>() {
            }).toInstance(proposalDispatcher);
            bind(new TypeLiteral<RemoteEventDispatcher<Vote>>() {
            }).toInstance(voteDispatcher);
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesResponse>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesErrorResponse>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<LedgerStatusUpdate>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(PersistentSafetyStateStore.class).toInstance(mock(PersistentSafetyStateStore.class));
            bind(NextTxnsGenerator.class).toInstance(nextTxnsGenerator);
            bind(SystemCounters.class).toInstance(new SystemCountersImpl());
            bind(Mempool.class).toInstance(mempool);
            bind(StateComputer.class).toInstance(stateComputer);
            bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
            bind(RateLimiter.class).annotatedWith(GetVerticesRequestRateLimit.class).toInstance(RateLimiter.create(Double.MAX_VALUE));
            bindConstant().annotatedWith(BFTSyncPatienceMillis.class).to(50);
            bindConstant().annotatedWith(PacemakerTimeout.class).to(10L);
            bindConstant().annotatedWith(PacemakerRate.class).to(2.0);
            bindConstant().annotatedWith(PacemakerMaxExponent.class).to(0);
            bind(TimeSupplier.class).toInstance(System::currentTimeMillis);
            bind(new TypeLiteral<Consumer<EpochViewUpdate>>() {
            }).toInstance(rmock(Consumer.class));
        }

        @Provides
        private ViewUpdate view(BFTConfiguration bftConfiguration) {
            HighQC highQC = bftConfiguration.getVertexStoreState().getHighQC();
            View view = highQC.highestQC().getView().next();
            return ViewUpdate.create(view, highQC, self, self);
        }

        @Provides
        BFTValidatorSet validatorSet() {
            return BFTValidatorSet.from(Stream.of(BFTValidator.from(self, UInt256.ONE)));
        }

        @Provides
        @LastProof
        LedgerProof verifiedLedgerHeaderAndProof(BFTValidatorSet validatorSet) {
            var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
            return LedgerProof.genesis(accumulatorState, validatorSet, 0);
        }

        @Provides
        @LastEpochProof
        LedgerProof lastEpochProof(BFTValidatorSet validatorSet) {
            var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
            return LedgerProof.genesis(accumulatorState, validatorSet, 0);
        }

        @Provides
        BFTConfiguration bftConfiguration(@Self BFTNode self, Hasher hasher, BFTValidatorSet validatorSet) {
            var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
            var unverifiedVertex = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, validatorSet, 0));
            var verifiedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
            var qc = QuorumCertificate.ofGenesis(verifiedVertex, LedgerHeader.genesis(accumulatorState, validatorSet, 0));
            var proposerElection = new WeightedRotatingLeaders(validatorSet);
            return new BFTConfiguration(proposerElection, validatorSet, VerifiedVertexStoreState.create(HighQC.from(qc), verifiedVertex, Optional.empty(), hasher));
        }
    };
}
Also used : HighQC(com.radixdlt.consensus.HighQC) AccumulatorState(com.radixdlt.ledger.AccumulatorState) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) BFTCommittedUpdate(com.radixdlt.consensus.bft.BFTCommittedUpdate) VertexRequestTimeout(com.radixdlt.consensus.sync.VertexRequestTimeout) NextTxnsGenerator(com.radixdlt.consensus.liveness.NextTxnsGenerator) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) PacemakerMaxExponent(com.radixdlt.consensus.bft.PacemakerMaxExponent) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) Consumer(java.util.function.Consumer) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) Mempool(com.radixdlt.mempool.Mempool) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) BFTNode(com.radixdlt.consensus.bft.BFTNode) Vote(com.radixdlt.consensus.Vote) NoVote(com.radixdlt.consensus.bft.NoVote) GetVerticesResponse(com.radixdlt.consensus.sync.GetVerticesResponse) HashSigner(com.radixdlt.consensus.HashSigner) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) Hasher(com.radixdlt.crypto.Hasher) NoVote(com.radixdlt.consensus.bft.NoVote) Proposal(com.radixdlt.consensus.Proposal) LedgerStatusUpdate(com.radixdlt.sync.messages.remote.LedgerStatusUpdate) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) GetVerticesRequest(com.radixdlt.consensus.sync.GetVerticesRequest) LocalTimeoutOccurrence(com.radixdlt.consensus.liveness.LocalTimeoutOccurrence) EpochLocalTimeoutOccurrence(com.radixdlt.consensus.liveness.EpochLocalTimeoutOccurrence) Self(com.radixdlt.consensus.bft.Self) TimeSupplier(com.radixdlt.utils.TimeSupplier) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) EpochLocalTimeoutOccurrence(com.radixdlt.consensus.liveness.EpochLocalTimeoutOccurrence) PacemakerRate(com.radixdlt.consensus.bft.PacemakerRate) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) EventDispatcher(com.radixdlt.environment.EventDispatcher) TypeLiteral(com.google.inject.TypeLiteral) BFTSyncPatienceMillis(com.radixdlt.consensus.sync.BFTSyncPatienceMillis) BFTRebuildUpdate(com.radixdlt.consensus.bft.BFTRebuildUpdate) GetVerticesErrorResponse(com.radixdlt.consensus.sync.GetVerticesErrorResponse) SystemCounters(com.radixdlt.counters.SystemCounters) PacemakerTimeout(com.radixdlt.consensus.bft.PacemakerTimeout) BFTValidatorSet(com.radixdlt.consensus.bft.BFTValidatorSet) View(com.radixdlt.consensus.bft.View) AbstractModule(com.google.inject.AbstractModule) BFTConfiguration(com.radixdlt.consensus.BFTConfiguration) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) ViewQuorumReached(com.radixdlt.consensus.bft.ViewQuorumReached) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) BFTHighQCUpdate(com.radixdlt.consensus.bft.BFTHighQCUpdate) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PersistentSafetyStateStore(com.radixdlt.consensus.safety.PersistentSafetyStateStore)

Aggregations

BFTInsertUpdate (com.radixdlt.consensus.bft.BFTInsertUpdate)5 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)5 AbstractModule (com.google.inject.AbstractModule)4 TypeLiteral (com.google.inject.TypeLiteral)4 ScheduledLocalTimeout (com.radixdlt.consensus.liveness.ScheduledLocalTimeout)4 HighQC (com.radixdlt.consensus.HighQC)3 Vote (com.radixdlt.consensus.Vote)3 BFTNode (com.radixdlt.consensus.bft.BFTNode)3 View (com.radixdlt.consensus.bft.View)3 Guice (com.google.inject.Guice)2 Inject (com.google.inject.Inject)2 Injector (com.google.inject.Injector)2 BFTConfiguration (com.radixdlt.consensus.BFTConfiguration)2 HashSigner (com.radixdlt.consensus.HashSigner)2 Proposal (com.radixdlt.consensus.Proposal)2 BFTCommittedUpdate (com.radixdlt.consensus.bft.BFTCommittedUpdate)2 BFTHighQCUpdate (com.radixdlt.consensus.bft.BFTHighQCUpdate)2 BFTRebuildUpdate (com.radixdlt.consensus.bft.BFTRebuildUpdate)2 NoVote (com.radixdlt.consensus.bft.NoVote)2 PacemakerMaxExponent (com.radixdlt.consensus.bft.PacemakerMaxExponent)2