use of com.radixdlt.hotstuff.TimestampedECDSASignatures in project radixdlt by radixdlt.
the class VerifiedVertexStoreStateCreationTest method creating_vertex_store_with_qc_not_matching_vertex_should_fail.
@Test
public void creating_vertex_store_with_qc_not_matching_vertex_should_fail() {
BFTHeader genesisHeader = new BFTHeader(View.of(0), HashUtils.random256(), mock(LedgerHeader.class));
VoteData voteData = new VoteData(genesisHeader, genesisHeader, genesisHeader);
QuorumCertificate badRootQC = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
assertThatThrownBy(() -> VerifiedVertexStoreState.create(HighQC.from(badRootQC), genesisVertex, Optional.empty(), hasher)).isInstanceOf(IllegalStateException.class);
}
use of com.radixdlt.hotstuff.TimestampedECDSASignatures in project radixdlt by radixdlt.
the class DifferentTimestampsCauseTimeoutTest method mutateQC.
private QuorumCertificate mutateQC(QuorumCertificate qc, int destination) {
TimestampedECDSASignatures signatures = qc.getTimestampedSignatures();
VoteData voteData = qc.getVoteData();
return new QuorumCertificate(voteData, mutateTimestampedSignatures(signatures, destination));
}
use of com.radixdlt.hotstuff.TimestampedECDSASignatures in project radixdlt by radixdlt.
the class LargeEpochChangeTest method large_epoch.
@Test
public void large_epoch() throws Exception {
var rt = Runtime.getRuntime();
logger.info("max mem: {}MB", rt.maxMemory() / 1024 / 1024);
int privKeyStart = 2;
int numTxnsPerRound = 10;
createInjector().injectMembers(this);
// Arrange
var request = TxnConstructionRequest.create();
IntStream.range(privKeyStart, NUM_ROUNDS * numTxnsPerRound + privKeyStart).forEach(i -> {
var k = PrivateKeys.ofNumeric(i);
var addr = REAddr.ofPubKeyAccount(k.getPublicKey());
request.action(new MintToken(REAddr.ofNativeToken(), addr, Amount.ofTokens(NUM_ROUNDS * 1000).toSubunits()));
request.action(new RegisterValidator(k.getPublicKey()));
});
var mint = sut.construct(request).buildWithoutSignature();
logger.info("mint_txn_size={}", mint.getPayload().length);
var accumulator = new AccumulatorState(2, HashUtils.zero256());
var proof = new LedgerProof(HashUtils.zero256(), LedgerHeader.create(1, View.of(1), accumulator, 0), new TimestampedECDSASignatures());
sut.execute(List.of(mint), LedgerAndBFTProof.create(proof), PermissionLevel.SYSTEM);
var systemConstruction = Stopwatch.createUnstarted();
var construction = Stopwatch.createUnstarted();
var signatures = Stopwatch.createUnstarted();
var execution = Stopwatch.createUnstarted();
var feesPaid = UInt256.ZERO;
for (int round = 1; round <= NUM_ROUNDS; round++) {
if (round % NUM_ROUNDS == 0) {
logger.info("Staking txn {}/{} sys_construct_time: {}s user_construct_time: {}s sig_time: {}s" + " execute_time: {}s", round * (numTxnsPerRound + 1), NUM_ROUNDS * (numTxnsPerRound + 1), systemConstruction.elapsed(TimeUnit.SECONDS), construction.elapsed(TimeUnit.SECONDS), signatures.elapsed(TimeUnit.SECONDS), execution.elapsed(TimeUnit.SECONDS));
}
var txns = new ArrayList<Txn>();
systemConstruction.start();
var sysTxn = sut.construct(new NextRound(round, false, 1, v -> TEST_KEY.getPublicKey())).buildWithoutSignature();
systemConstruction.stop();
txns.add(sysTxn);
for (int i = 0; i < numTxnsPerRound; i++) {
var privateKey = PrivateKeys.ofNumeric((round - 1) * numTxnsPerRound + i + privKeyStart);
var pubKey = privateKey.getPublicKey();
var addr = REAddr.ofPubKeyAccount(privateKey.getPublicKey());
construction.start();
var builder = sut.construct(TxnConstructionRequest.create().feePayer(addr).action(new StakeTokens(addr, pubKey, Amount.ofTokens(100 + i).toSubunits())));
construction.stop();
signatures.start();
var txn = builder.signAndBuild(privateKey::sign);
signatures.stop();
txns.add(txn);
}
var acc = new AccumulatorState(2 + round * (numTxnsPerRound + 1), HashUtils.zero256());
var proof2 = new LedgerProof(HashUtils.zero256(), LedgerHeader.create(1, View.of(1), acc, 0), new TimestampedECDSASignatures());
execution.start();
var result = sut.execute(txns, LedgerAndBFTProof.create(proof2), PermissionLevel.SUPER_USER);
execution.stop();
for (var p : result.getProcessedTxns()) {
feesPaid = feesPaid.add(p.getFeePaid());
}
}
logger.info("total_fees_paid: {}", Amount.ofSubunits(feesPaid));
// Act
construction.reset();
construction.start();
logger.info("constructing epoch...");
var txn = sut.construct(new NextEpoch(1)).buildWithoutSignature();
construction.stop();
logger.info("epoch_construction: size={}MB time={}s", txn.getPayload().length / 1024 / 1024, construction.elapsed(TimeUnit.SECONDS));
construction.reset();
construction.start();
logger.info("preparing epoch...");
var result = sut.transientBranch().execute(List.of(txn), PermissionLevel.SUPER_USER);
sut.deleteBranches();
var nextValidatorSet = result.getProcessedTxn().getEvents().stream().filter(REEvent.NextValidatorSetEvent.class::isInstance).map(REEvent.NextValidatorSetEvent.class::cast).findFirst().map(e -> BFTValidatorSet.from(e.nextValidators().stream().map(v -> BFTValidator.from(BFTNode.create(v.validatorKey()), v.amount()))));
var stateUpdates = result.getProcessedTxn().stateUpdates().count();
construction.stop();
logger.info("epoch_preparation: state_updates={} verification_time={}s store_time={}s total_time={}s", stateUpdates, result.getVerificationTime() / 1000, result.getStoreTime() / 1000, construction.elapsed(TimeUnit.SECONDS));
construction.reset();
construction.start();
logger.info("executing epoch...");
var acc = new AccumulatorState(2 + 1 + NUM_ROUNDS * (1 + numTxnsPerRound), HashUtils.zero256());
var header = LedgerHeader.create(1, View.of(10), acc, 0, nextValidatorSet.orElseThrow());
var proof2 = new LedgerProof(HashUtils.zero256(), header, new TimestampedECDSASignatures());
var executionResult = this.sut.execute(List.of(txn), LedgerAndBFTProof.create(proof2), PermissionLevel.SUPER_USER);
construction.stop();
logger.info("epoch_execution: verification_time={}s store_time={}s total_time={}s", executionResult.getVerificationTime() / 1000, executionResult.getStoreTime() / 1000, construction.elapsed(TimeUnit.SECONDS));
for (var v : nextValidatorSet.orElseThrow().getValidators()) {
logger.info("validator {} {}", v.getNode(), v.getPower());
}
}
Aggregations