Search in sources :

Example 1 with Epoched

use of com.radixdlt.hotstuff.epoch.Epoched 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) 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) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) DatabaseLocation(com.radixdlt.store.DatabaseLocation) MempoolConfig(com.radixdlt.mempool.MempoolConfig) SingleNodeAndPeersDeterministicNetworkModule(com.radixdlt.modules.SingleNodeAndPeersDeterministicNetworkModule) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) PrivateKeys(com.radixdlt.utils.PrivateKeys) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) Set(java.util.Set) Test(org.junit.Test) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Injector(com.google.inject.Injector) EpochViewUpdate(com.radixdlt.hotstuff.epoch.EpochViewUpdate) Epoched(com.radixdlt.hotstuff.epoch.Epoched) Rule(org.junit.Rule) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) Amount(com.radixdlt.application.tokens.Amount) TypeLiteral(com.google.inject.TypeLiteral) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) EpochViewUpdate(com.radixdlt.hotstuff.epoch.EpochViewUpdate) ControlledMessage(com.radixdlt.environment.deterministic.network.ControlledMessage) Epoched(com.radixdlt.hotstuff.epoch.Epoched) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) Test(org.junit.Test)

Example 2 with Epoched

use of com.radixdlt.hotstuff.epoch.Epoched 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) 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) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) DatabaseLocation(com.radixdlt.store.DatabaseLocation) MempoolConfig(com.radixdlt.mempool.MempoolConfig) SingleNodeAndPeersDeterministicNetworkModule(com.radixdlt.modules.SingleNodeAndPeersDeterministicNetworkModule) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) PrivateKeys(com.radixdlt.utils.PrivateKeys) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) Set(java.util.Set) Test(org.junit.Test) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Injector(com.google.inject.Injector) EpochViewUpdate(com.radixdlt.hotstuff.epoch.EpochViewUpdate) Epoched(com.radixdlt.hotstuff.epoch.Epoched) Rule(org.junit.Rule) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) Amount(com.radixdlt.application.tokens.Amount) 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.hotstuff.epoch.Epoched) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) Test(org.junit.Test)

Aggregations

AbstractModule (com.google.inject.AbstractModule)2 Guice (com.google.inject.Guice)2 Inject (com.google.inject.Inject)2 Injector (com.google.inject.Injector)2 TypeLiteral (com.google.inject.TypeLiteral)2 Amount (com.radixdlt.application.tokens.Amount)2 DeterministicProcessor (com.radixdlt.environment.deterministic.DeterministicProcessor)2 ControlledMessage (com.radixdlt.environment.deterministic.network.ControlledMessage)2 DeterministicNetwork (com.radixdlt.environment.deterministic.network.DeterministicNetwork)2 BFTInsertUpdate (com.radixdlt.hotstuff.bft.BFTInsertUpdate)2 ViewUpdate (com.radixdlt.hotstuff.bft.ViewUpdate)2 EpochViewUpdate (com.radixdlt.hotstuff.epoch.EpochViewUpdate)2 Epoched (com.radixdlt.hotstuff.epoch.Epoched)2 ScheduledLocalTimeout (com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout)2 MempoolConfig (com.radixdlt.mempool.MempoolConfig)2 SingleNodeAndPeersDeterministicNetworkModule (com.radixdlt.modules.SingleNodeAndPeersDeterministicNetworkModule)2 MockedGenesisModule (com.radixdlt.statecomputer.checkpoint.MockedGenesisModule)2 ForksModule (com.radixdlt.statecomputer.forks.ForksModule)2 RadixEngineForksLatestOnlyModule (com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule)2 MainnetForksModule (com.radixdlt.statecomputer.forks.modules.MainnetForksModule)2