use of com.radixdlt.ledger.LedgerUpdate in project radixdlt by radixdlt.
the class EpochManagerTest method should_not_send_consensus_messages_if_not_part_of_new_epoch.
@Test
public void should_not_send_consensus_messages_if_not_part_of_new_epoch() {
// Arrange
epochManager.start();
BFTValidatorSet nextValidatorSet = BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE)));
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
LedgerHeader header = LedgerHeader.genesis(accumulatorState, nextValidatorSet, 0);
UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header);
VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
var genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
var proposerElection = new WeightedRotatingLeaders(nextValidatorSet);
var bftConfiguration = new BFTConfiguration(proposerElection, nextValidatorSet, VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher));
LedgerProof proof = mock(LedgerProof.class);
when(proof.getEpoch()).thenReturn(header.getEpoch() + 1);
var epochChange = new EpochChange(proof, bftConfiguration);
var ledgerUpdate = new LedgerUpdate(mock(VerifiedTxnsAndProof.class), ImmutableClassToInstanceMap.of(EpochChange.class, epochChange));
// Act
epochManager.epochsLedgerUpdateEventProcessor().process(ledgerUpdate);
// Assert
verify(proposalDispatcher, never()).dispatch(any(Iterable.class), argThat(p -> p.getEpoch() == epochChange.getEpoch()));
verify(voteDispatcher, never()).dispatch(any(BFTNode.class), any());
}
use of com.radixdlt.ledger.LedgerUpdate in project radixdlt by radixdlt.
the class InMemorySystemInfoTest method createLedgerUpdate.
private LedgerUpdate createLedgerUpdate(BFTNode self) {
var events = List.<REEvent>of(new ValidatorBFTDataEvent(self.getKey(), 10, 1));
var txn = new REProcessedTxn(null, null, null, events);
var output = ImmutableClassToInstanceMap.<Object, REOutput>of(REOutput.class, REOutput.create(List.of(txn)));
return new LedgerUpdate(mock(VerifiedTxnsAndProof.class), output);
}
use of com.radixdlt.ledger.LedgerUpdate 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);
}
use of com.radixdlt.ledger.LedgerUpdate in project radixdlt by radixdlt.
the class RxEnvironmentModule method configure.
@Override
public void configure() {
ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(ThreadFactories.daemonThreads("TimeoutSender"));
bind(Environment.class).to(RxEnvironment.class);
bind(ScheduledExecutorService.class).toInstance(ses);
// TODO: Remove, still required by SimulationNodes.java
bind(new TypeLiteral<Observable<LedgerUpdate>>() {
}).toProvider(new ObservableProvider<>(LedgerUpdate.class));
bind(new TypeLiteral<Observable<BFTHighQCUpdate>>() {
}).toProvider(new ObservableProvider<>(BFTHighQCUpdate.class));
Multibinder.newSetBinder(binder(), new TypeLiteral<RxRemoteDispatcher<?>>() {
});
Multibinder.newSetBinder(binder(), new TypeLiteral<EventProcessorOnRunner<?>>() {
});
Multibinder.newSetBinder(binder(), new TypeLiteral<RemoteEventProcessorOnRunner<?>>() {
});
Multibinder.newSetBinder(binder(), new TypeLiteral<ScheduledEventProducerOnRunner<?>>() {
});
}
use of com.radixdlt.ledger.LedgerUpdate in project radixdlt by radixdlt.
the class LedgerInOrderInvariant method check.
@Override
public Observable<TestInvariantError> check(RunningNetwork network) {
Map<BFTNode, List<Txn>> commandsPerNode = new HashMap<>();
network.getNodes().forEach(n -> commandsPerNode.put(n, new ArrayList<>()));
return network.ledgerUpdates().flatMap(nodeAndCommand -> {
BFTNode node = nodeAndCommand.getFirst();
LedgerUpdate ledgerUpdate = nodeAndCommand.getSecond();
List<Txn> nodeTxns = commandsPerNode.get(node);
nodeTxns.addAll(ledgerUpdate.getNewTxns());
return commandsPerNode.values().stream().filter(list -> nodeTxns != list).filter(list -> list.size() >= nodeTxns.size()).findFirst().flatMap(list -> {
if (Collections.indexOfSubList(list, nodeTxns) != 0) {
TestInvariantError err = new TestInvariantError("Two nodes don't agree on commands: " + list + " " + nodeTxns);
return Optional.of(Observable.just(err));
}
return Optional.empty();
}).orElse(Observable.empty());
});
}
Aggregations