Search in sources :

Example 16 with TimestampedECDSASignatures

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);
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) BFTHeader(com.radixdlt.hotstuff.BFTHeader) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) VoteData(com.radixdlt.hotstuff.VoteData) Test(org.junit.Test)

Example 17 with TimestampedECDSASignatures

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));
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) VoteData(com.radixdlt.hotstuff.VoteData)

Example 18 with TimestampedECDSASignatures

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());
    }
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) AccumulatorState(com.radixdlt.ledger.AccumulatorState) REEvent(com.radixdlt.constraintmachine.REEvent) ArrayList(java.util.ArrayList) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Test(org.junit.Test)

Aggregations

TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)18 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)9 VoteData (com.radixdlt.hotstuff.VoteData)9 Test (org.junit.Test)9 BFTHeader (com.radixdlt.hotstuff.BFTHeader)8 LedgerProof (com.radixdlt.hotstuff.LedgerProof)8 AccumulatorState (com.radixdlt.ledger.AccumulatorState)8 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)7 HashCode (com.google.common.hash.HashCode)3 View (com.radixdlt.hotstuff.bft.View)3 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)2 Before (org.junit.Before)2 REEvent (com.radixdlt.constraintmachine.REEvent)1 EventDispatcher (com.radixdlt.environment.EventDispatcher)1 HighQC (com.radixdlt.hotstuff.HighQC)1 Ledger (com.radixdlt.hotstuff.Ledger)1 Proposal (com.radixdlt.hotstuff.Proposal)1 UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)1 Vote (com.radixdlt.hotstuff.Vote)1 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)1