use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method committing_epoch_change_with_different_validator_signed_should_fail.
// TODO: should catch this and log it somewhere as proof of byzantine quorum
@Test
public void committing_epoch_change_with_different_validator_signed_should_fail() throws Exception {
// Arrange
var cmd1 = systemUpdateCommand(0, 2);
var ledgerProof = new LedgerProof(HashUtils.random256(), LedgerHeader.create(0, View.of(9), new AccumulatorState(3, HashUtils.zero256()), 0, BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE)))), new TimestampedECDSASignatures());
var commandsAndProof = VerifiedTxnsAndProof.create(ImmutableList.of(cmd1), ledgerProof);
// Act
// Assert
assertThatThrownBy(() -> sut.commit(commandsAndProof, null)).isInstanceOf(ByzantineQuorumException.class);
}
use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.
the class RecoveryTest method on_reboot_should_load_same_last_epoch_header.
@Test
public void on_reboot_should_load_same_last_epoch_header() {
// Arrange
processForCount(processForCount);
var epochView = getLastEpochView();
// Act
restartNode();
// Assert
LedgerProof restartedEpochProof = currentInjector.getInstance(Key.get(LedgerProof.class, LastEpochProof.class));
assertThat(restartedEpochProof.isEndOfEpoch()).isTrue();
assertThat(restartedEpochProof.getEpoch() == epochView.getEpoch() - 1 || (restartedEpochProof.getEpoch() == epochView.getEpoch() && epochView.getView().number() > epochCeilingView + 3)).isTrue();
}
use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.
the class StateComputerLedger method commit.
private void commit(VerifiedTxnsAndProof verifiedTxnsAndProof, VerifiedVertexStoreState vertexStoreState) {
synchronized (lock) {
final LedgerProof nextHeader = verifiedTxnsAndProof.getProof();
if (headerComparator.compare(nextHeader, this.currentLedgerHeader) <= 0) {
return;
}
var verifiedExtension = verifier.verifyAndGetExtension(this.currentLedgerHeader.getAccumulatorState(), verifiedTxnsAndProof.getTxns(), txn -> txn.getId().asHashCode(), verifiedTxnsAndProof.getProof().getAccumulatorState());
if (verifiedExtension.isEmpty()) {
throw new ByzantineQuorumException("Accumulator failure " + currentLedgerHeader + " " + verifiedTxnsAndProof);
}
var txns = verifiedExtension.get();
if (vertexStoreState == null) {
this.counters.add(CounterType.LEDGER_SYNC_COMMANDS_PROCESSED, txns.size());
} else {
this.counters.add(CounterType.LEDGER_BFT_COMMANDS_PROCESSED, txns.size());
}
var txnsAndProof = VerifiedTxnsAndProof.create(txns, verifiedTxnsAndProof.getProof());
// persist
this.stateComputer.commit(txnsAndProof, vertexStoreState);
// TODO: move all of the following to post-persist event handling
this.currentLedgerHeader = nextHeader;
this.counters.set(CounterType.LEDGER_STATE_VERSION, this.currentLedgerHeader.getStateVersion());
}
}
use of com.radixdlt.hotstuff.LedgerProof 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.hotstuff.LedgerProof in project radixdlt by radixdlt.
the class MempoolRunnerTest method createModule.
@SuppressWarnings(// The mock method doesn't support type-safe generics due to type erasure
"unchecked")
public Module createModule() {
return new AbstractModule() {
@Override
public void configure() {
bind(BFTNode.class).annotatedWith(Self.class).toInstance(BFTNode.random());
bind(LedgerProof.class).annotatedWith(LastProof.class).toInstance(mock(LedgerProof.class));
bind(StateComputer.class).toInstance(stateComputer);
bind(SystemCounters.class).toInstance(new SystemCountersImpl());
bind(RxRemoteEnvironment.class).toInstance(new RxRemoteEnvironment() {
@Override
public <T> Flowable<RemoteEvent<T>> remoteEvents(Class<T> remoteEventClass) {
return Flowable.never();
}
});
bind(LedgerAccumulator.class).toInstance(mock(LedgerAccumulator.class));
bind(LedgerAccumulatorVerifier.class).toInstance(mock(LedgerAccumulatorVerifier.class));
bind(new TypeLiteral<Comparator<LedgerProof>>() {
}).toInstance(mock(Comparator.class));
bind(Addressing.class).toInstance(Addressing.ofNetwork(Network.LOCALNET));
bind(TimeSupplier.class).toInstance(System::currentTimeMillis);
Multibinder.newSetBinder(binder(), StartProcessorOnRunner.class);
install(MempoolConfig.asModule(100, 10));
install(new MockedKeyModule());
install(new MockedCryptoModule());
install(new RxEnvironmentModule());
install(new DispatcherModule());
install(new MempoolReceiverModule());
install(new EventLoggerModule());
}
};
}
Aggregations