use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class ConsensusModuleTest method setup.
@Before
public void setup() {
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
var genesis = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, null, 0));
var hashedGenesis = new VerifiedVertex(genesis, HashUtils.zero256());
var qc = QuorumCertificate.ofGenesis(hashedGenesis, LedgerHeader.genesis(accumulatorState, null, 0));
this.validatorKeyPair = ECKeyPair.generateNew();
this.validatorBftNode = BFTNode.create(this.validatorKeyPair.getPublicKey());
var validatorSet = BFTValidatorSet.from(Stream.of(BFTValidator.from(this.validatorBftNode, UInt256.ONE)));
var vertexStoreState = VerifiedVertexStoreState.create(HighQC.from(qc), hashedGenesis, Optional.empty(), hasher);
var proposerElection = new WeightedRotatingLeaders(validatorSet);
this.bftConfiguration = new BFTConfiguration(proposerElection, validatorSet, vertexStoreState);
this.ecKeyPair = ECKeyPair.generateNew();
this.requestSender = rmock(RemoteEventDispatcher.class);
this.responseSender = rmock(RemoteEventDispatcher.class);
this.errorResponseSender = rmock(RemoteEventDispatcher.class);
Guice.createInjector(new ConsensusModule(), new CryptoModule(), getExternalModule()).injectMembers(this);
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex 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())));
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class MockedLedgerModule method syncedLedger.
@Provides
@Singleton
Ledger syncedLedger(TimeSupplier timeSupplier) {
return new Ledger() {
@Override
public Optional<PreparedVertex> prepare(LinkedList<PreparedVertex> previous, VerifiedVertex vertex) {
final long timestamp = vertex.getQC().getTimestampedSignatures().weightedTimestamp();
final LedgerHeader ledgerHeader = vertex.getParentHeader().getLedgerHeader().updateViewAndTimestamp(vertex.getView(), timestamp);
return Optional.of(vertex.withHeader(ledgerHeader, timeSupplier.currentTime()).andTxns(vertex.getTxns().stream().<PreparedTxn>map(MockPrepared::new).toList(), Map.of()));
}
};
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class StateComputerLedgerTest method should_not_change_accumulator_when_there_is_no_command.
@Test
public void should_not_change_accumulator_when_there_is_no_command() {
// Arrange
genesisIsEndOfEpoch(false);
when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(), ImmutableMap.of()));
var unverifiedVertex = UnverifiedVertex.create(genesisQC, View.of(1), List.of(), BFTNode.random());
var proposedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
// Act
Optional<PreparedVertex> nextPrepared = sut.prepare(new LinkedList<>(), proposedVertex);
// Assert
assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().isEndOfEpoch()).isFalse());
assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().getAccumulatorState()).isEqualTo(ledgerHeader.getAccumulatorState()));
}
use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.
the class StateComputerLedgerTest method should_accumulate_when_next_command_valid.
@Test
public void should_accumulate_when_next_command_valid() {
// Arrange
genesisIsEndOfEpoch(false);
when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(successfulNextCommand), ImmutableMap.of()));
// Act
var unverifiedVertex = UnverifiedVertex.create(genesisQC, View.of(1), List.of(nextTxn), BFTNode.random());
var proposedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
Optional<PreparedVertex> nextPrepared = sut.prepare(new LinkedList<>(), proposedVertex);
// Assert
assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().isEndOfEpoch()).isFalse());
assertThat(nextPrepared.flatMap(x -> accumulatorVerifier.verifyAndGetExtension(ledgerHeader.getAccumulatorState(), List.of(nextTxn), txn -> txn.getId().asHashCode(), x.getLedgerHeader().getAccumulatorState()))).contains(List.of(nextTxn));
}
Aggregations