use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.
the class LocalSyncServiceTest method when_status_timeout_with_no_responses__then_should_reschedule_another_check.
@Test
public void when_status_timeout_with_no_responses__then_should_reschedule_another_check() {
final LedgerProof currentHeader = createHeaderAtStateVersion(10L);
final BFTNode waiting1 = createPeer();
setupPeersView(waiting1);
final var syncState = SyncState.SyncCheckState.init(currentHeader, ImmutableSet.of(waiting1));
this.setupSyncServiceWithState(syncState);
this.localSyncService.syncCheckReceiveStatusTimeoutEventProcessor().process(SyncCheckReceiveStatusTimeout.create());
verifyNoMoreInteractions(syncRequestDispatcher);
}
use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.
the class LocalSyncServiceTest method when_sync_check_is_triggered_at_idle__then_should_ask_peers_for_their_statuses.
@Test
public void when_sync_check_is_triggered_at_idle__then_should_ask_peers_for_their_statuses() {
final var peer1 = createPeer();
final var peer2 = createPeer();
final var peer3 = createPeer();
setupPeersView(peer1, peer2, peer3);
final LedgerProof currentHeader = mock(LedgerProof.class);
this.setupSyncServiceWithState(SyncState.IdleState.init(currentHeader));
this.localSyncService.syncCheckTriggerEventProcessor().process(SyncCheckTrigger.create());
verify(statusRequestDispatcher, times(1)).dispatch(eq(peer1), any());
verify(statusRequestDispatcher, times(1)).dispatch(eq(peer2), any());
verify(statusRequestDispatcher, times(1)).dispatch(eq(peer2), any());
}
use of com.radixdlt.hotstuff.LedgerProof 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());
}
};
}
use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.
the class StateComputerLedgerTest method should_do_nothing_if_committing_lower_state_version.
@Test
public void should_do_nothing_if_committing_lower_state_version() {
// Arrange
genesisIsEndOfEpoch(false);
when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(successfulNextCommand), ImmutableMap.of()));
final AccumulatorState accumulatorState = new AccumulatorState(genesisStateVersion - 1, HashUtils.zero256());
final LedgerHeader ledgerHeader = LedgerHeader.create(genesisEpoch, View.of(2), accumulatorState, 1234);
final LedgerProof header = new LedgerProof(HashUtils.random256(), ledgerHeader, new TimestampedECDSASignatures());
var verified = VerifiedTxnsAndProof.create(List.of(nextTxn), header);
// Act
sut.syncEventProcessor().process(verified);
// Assert
verify(stateComputer, never()).commit(any(), any());
verify(mempool, never()).committed(any());
}
use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.
the class MockedStateComputer method commit.
@Override
public void commit(VerifiedTxnsAndProof txnsAndProof, VerifiedVertexStoreState vertexStoreState) {
var output = txnsAndProof.getProof().getNextValidatorSet().map(validatorSet -> {
LedgerProof header = txnsAndProof.getProof();
UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header.getRaw());
VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
QuorumCertificate genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
final var initialState = VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher);
var proposerElection = new WeightedRotatingLeaders(validatorSet);
var bftConfiguration = new BFTConfiguration(proposerElection, validatorSet, initialState);
return new EpochChange(header, bftConfiguration);
}).map(e -> ImmutableClassToInstanceMap.<Object, EpochChange>of(EpochChange.class, e)).orElse(ImmutableClassToInstanceMap.of());
var ledgerUpdate = new LedgerUpdate(txnsAndProof, output);
ledgerUpdateDispatcher.dispatch(ledgerUpdate);
}
Aggregations