Search in sources :

Example 1 with EventDispatcher

use of com.radixdlt.environment.EventDispatcher 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 2 with EventDispatcher

use of com.radixdlt.environment.EventDispatcher 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 MainnetForkConfigsModule());
            install(new ForksModule());
            install(new RadixEngineForksLatestOnlyModule());
            // HACK
            bind(CommittedReader.class).toInstance(CommittedReader.mocked());
            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) RERules(com.radixdlt.statecomputer.forks.RERules) SimpleLedgerAccumulatorAndVerifier(com.radixdlt.ledger.SimpleLedgerAccumulatorAndVerifier) TxAction(com.radixdlt.atom.TxAction) 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) TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) RoundData(com.radixdlt.application.system.state.RoundData) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) ByzantineQuorumException(com.radixdlt.ledger.ByzantineQuorumException) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.consensus.LedgerProof) View(com.radixdlt.consensus.bft.View) HashUtils(com.radixdlt.crypto.HashUtils) Genesis(com.radixdlt.statecomputer.checkpoint.Genesis) SystemCounters(com.radixdlt.counters.SystemCounters) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.consensus.Sha256Hasher) REEvent(com.radixdlt.constraintmachine.REEvent) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) EngineStore(com.radixdlt.store.EngineStore) Collectors(java.util.stream.Collectors) LedgerHeader(com.radixdlt.consensus.LedgerHeader) ProposerElection(com.radixdlt.consensus.liveness.ProposerElection) 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) Amount(com.radixdlt.application.tokens.Amount) MainnetForkConfigsModule(com.radixdlt.statecomputer.forks.MainnetForkConfigsModule) TypeLiteral(com.google.inject.TypeLiteral) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) Mockito.mock(org.mockito.Mockito.mock) Serialization(com.radixdlt.serialization.Serialization) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) BFTValidatorSet(com.radixdlt.consensus.bft.BFTValidatorSet) com.radixdlt.atom(com.radixdlt.atom) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) BFTValidator(com.radixdlt.consensus.bft.BFTValidator) 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) 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) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) BFTHeader(com.radixdlt.consensus.BFTHeader) InMemoryEngineStore(com.radixdlt.store.InMemoryEngineStore) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Rule(org.junit.Rule) Ignore(org.junit.Ignore) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) BFTNode(com.radixdlt.consensus.bft.BFTNode) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) BFTNode(com.radixdlt.consensus.bft.BFTNode) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) SystemCounters(com.radixdlt.counters.SystemCounters) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) AbstractModule(com.google.inject.AbstractModule) DefaultSerialization(com.radixdlt.DefaultSerialization) Serialization(com.radixdlt.serialization.Serialization) Hasher(com.radixdlt.crypto.Hasher) Sha256Hasher(com.radixdlt.consensus.Sha256Hasher) EventDispatcher(com.radixdlt.environment.EventDispatcher) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) TypeLiteral(com.google.inject.TypeLiteral) CommittedReader(com.radixdlt.sync.CommittedReader) MainnetForkConfigsModule(com.radixdlt.statecomputer.forks.MainnetForkConfigsModule) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) ProposerElection(com.radixdlt.consensus.liveness.ProposerElection) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders)

Example 3 with EventDispatcher

use of com.radixdlt.environment.EventDispatcher in project radixdlt by radixdlt.

the class EpochsConsensusModule method pacemakerStateFactory.

@Provides
private PacemakerStateFactory pacemakerStateFactory(EventDispatcher<EpochViewUpdate> epochViewUpdateEventDispatcher) {
    return (initialView, epoch, proposerElection) -> new PacemakerState(initialView, proposerElection, viewUpdate -> {
        EpochViewUpdate epochViewUpdate = new EpochViewUpdate(epoch, viewUpdate);
        epochViewUpdateEventDispatcher.dispatch(epochViewUpdate);
    });
}
Also used : VertexStoreBFTSyncRequestProcessor(com.radixdlt.consensus.sync.VertexStoreBFTSyncRequestProcessor) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) GetVerticesRequest(com.radixdlt.consensus.sync.GetVerticesRequest) Hasher(com.radixdlt.crypto.Hasher) Random(java.util.Random) BFTCommittedUpdate(com.radixdlt.consensus.bft.BFTCommittedUpdate) EventProcessor(com.radixdlt.environment.EventProcessor) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) VertexRequestTimeout(com.radixdlt.consensus.sync.VertexRequestTimeout) LedgerProof(com.radixdlt.consensus.LedgerProof) SystemCounters(com.radixdlt.counters.SystemCounters) ProvidesIntoSet(com.google.inject.multibindings.ProvidesIntoSet) BFTSyncFactory(com.radixdlt.consensus.epoch.BFTSyncFactory) RemoteEventProcessorOnRunner(com.radixdlt.environment.RemoteEventProcessorOnRunner) PacemakerState(com.radixdlt.consensus.liveness.PacemakerState) BFTSyncRequestProcessorFactory(com.radixdlt.consensus.epoch.BFTSyncRequestProcessorFactory) Multibinder(com.google.inject.multibindings.Multibinder) Runners(com.radixdlt.environment.Runners) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) BFTRebuildUpdate(com.radixdlt.consensus.bft.BFTRebuildUpdate) VertexStoreFactory(com.radixdlt.consensus.epoch.VertexStoreFactory) LedgerHeader(com.radixdlt.consensus.LedgerHeader) BFTHighQCUpdate(com.radixdlt.consensus.bft.BFTHighQCUpdate) ProcessOnDispatch(com.radixdlt.environment.ProcessOnDispatch) TypeLiteral(com.google.inject.TypeLiteral) BFTSyncPatienceMillis(com.radixdlt.consensus.sync.BFTSyncPatienceMillis) StartProcessorOnRunner(com.radixdlt.environment.StartProcessorOnRunner) EpochManager(com.radixdlt.consensus.epoch.EpochManager) Epoched(com.radixdlt.consensus.epoch.Epoched) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) EventProcessorOnRunner(com.radixdlt.environment.EventProcessorOnRunner) Proposal(com.radixdlt.consensus.Proposal) LocalTimeoutOccurrence(com.radixdlt.consensus.liveness.LocalTimeoutOccurrence) NextTxnsGenerator(com.radixdlt.consensus.liveness.NextTxnsGenerator) BFTSync(com.radixdlt.consensus.sync.BFTSync) RateLimiter(com.google.common.util.concurrent.RateLimiter) EpochViewUpdate(com.radixdlt.consensus.epoch.EpochViewUpdate) LocalEvents(com.radixdlt.environment.LocalEvents) VertexStore(com.radixdlt.consensus.bft.VertexStore) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) Vote(com.radixdlt.consensus.Vote) Pacemaker(com.radixdlt.consensus.liveness.Pacemaker) LastEpochProof(com.radixdlt.store.LastEpochProof) BFTConfiguration(com.radixdlt.consensus.BFTConfiguration) Ledger(com.radixdlt.consensus.Ledger) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) PacemakerStateFactory(com.radixdlt.consensus.liveness.PacemakerStateFactory) TimeSupplier(com.radixdlt.utils.TimeSupplier) EventDispatcher(com.radixdlt.environment.EventDispatcher) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) PacemakerFactory(com.radixdlt.consensus.liveness.PacemakerFactory) Scopes(com.google.inject.Scopes) EpochChange(com.radixdlt.consensus.epoch.EpochChange) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) Provides(com.google.inject.Provides) Self(com.radixdlt.consensus.bft.Self) BFTNode(com.radixdlt.consensus.bft.BFTNode) EpochLocalTimeoutOccurrence(com.radixdlt.consensus.liveness.EpochLocalTimeoutOccurrence) Comparator(java.util.Comparator) GetVerticesErrorResponse(com.radixdlt.consensus.sync.GetVerticesErrorResponse) GetVerticesResponse(com.radixdlt.consensus.sync.GetVerticesResponse) AbstractModule(com.google.inject.AbstractModule) EpochViewUpdate(com.radixdlt.consensus.epoch.EpochViewUpdate) PacemakerState(com.radixdlt.consensus.liveness.PacemakerState) Provides(com.google.inject.Provides)

Example 4 with EventDispatcher

use of com.radixdlt.environment.EventDispatcher 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

AbstractModule (com.google.inject.AbstractModule)4 TypeLiteral (com.google.inject.TypeLiteral)4 BFTNode (com.radixdlt.consensus.bft.BFTNode)4 SystemCounters (com.radixdlt.counters.SystemCounters)4 EventDispatcher (com.radixdlt.environment.EventDispatcher)4 BFTConfiguration (com.radixdlt.consensus.BFTConfiguration)3 LedgerProof (com.radixdlt.consensus.LedgerProof)3 Proposal (com.radixdlt.consensus.Proposal)3 Vote (com.radixdlt.consensus.Vote)3 BFTCommittedUpdate (com.radixdlt.consensus.bft.BFTCommittedUpdate)3 BFTHighQCUpdate (com.radixdlt.consensus.bft.BFTHighQCUpdate)3 BFTInsertUpdate (com.radixdlt.consensus.bft.BFTInsertUpdate)3 BFTRebuildUpdate (com.radixdlt.consensus.bft.BFTRebuildUpdate)3 PersistentVertexStore (com.radixdlt.consensus.bft.PersistentVertexStore)3 Self (com.radixdlt.consensus.bft.Self)3 View (com.radixdlt.consensus.bft.View)3 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)3 LocalTimeoutOccurrence (com.radixdlt.consensus.liveness.LocalTimeoutOccurrence)3 NextTxnsGenerator (com.radixdlt.consensus.liveness.NextTxnsGenerator)3 ScheduledLocalTimeout (com.radixdlt.consensus.liveness.ScheduledLocalTimeout)3