Search in sources :

Example 26 with LedgerProof

use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.

the class RemoteSyncServiceTest method when_remote_sync_request__then_process_it.

@Test
public void when_remote_sync_request__then_process_it() {
    SyncRequest request = mock(SyncRequest.class);
    DtoLedgerProof header = mock(DtoLedgerProof.class);
    when(header.getOpaque()).thenReturn(HashUtils.zero256());
    when(header.getLedgerHeader()).thenReturn(mock(LedgerHeader.class));
    when(header.getSignatures()).thenReturn(mock(TimestampedECDSASignatures.class));
    when(request.getHeader()).thenReturn(header);
    BFTNode node = mock(BFTNode.class);
    VerifiedTxnsAndProof verifiedTxnsAndProof = mock(VerifiedTxnsAndProof.class);
    LedgerProof verifiedHeader = mock(LedgerProof.class);
    when(verifiedHeader.toDto()).thenReturn(header);
    when(verifiedTxnsAndProof.getProof()).thenReturn(verifiedHeader);
    when(reader.getNextCommittedTxns(any())).thenReturn(verifiedTxnsAndProof);
    processor.syncRequestEventProcessor().process(node, SyncRequest.create(header));
    verify(syncResponseDispatcher, times(1)).dispatch(eq(node), any());
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) SyncRequest(com.radixdlt.sync.messages.remote.SyncRequest) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.hotstuff.LedgerProof) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) Test(org.junit.Test)

Example 27 with LedgerProof

use of com.radixdlt.hotstuff.LedgerProof 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)

Example 28 with LedgerProof

use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.

the class RemoteSyncService method processLedgerUpdate.

private void processLedgerUpdate(LedgerUpdate ledgerUpdate) {
    final LedgerProof updatedHeader = ledgerUpdate.getTail();
    if (accComparator.compare(updatedHeader.getAccumulatorState(), this.currentHeader.getAccumulatorState()) > 0) {
        this.currentHeader = updatedHeader;
        this.sendStatusUpdateToSomePeers(updatedHeader);
    }
}
Also used : LedgerProof(com.radixdlt.hotstuff.LedgerProof) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof)

Aggregations

LedgerProof (com.radixdlt.hotstuff.LedgerProof)28 Test (org.junit.Test)17 DtoLedgerProof (com.radixdlt.ledger.DtoLedgerProof)13 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)9 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)9 AccumulatorState (com.radixdlt.ledger.AccumulatorState)9 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)4 AbstractModule (com.google.inject.AbstractModule)3 TypeLiteral (com.google.inject.TypeLiteral)3 Txn (com.radixdlt.atom.Txn)3 SystemCounters (com.radixdlt.counters.SystemCounters)3 EventDispatcher (com.radixdlt.environment.EventDispatcher)3 BFTConfiguration (com.radixdlt.hotstuff.BFTConfiguration)3 HighQC (com.radixdlt.hotstuff.HighQC)3 Self (com.radixdlt.hotstuff.bft.Self)3 View (com.radixdlt.hotstuff.bft.View)3 StateComputer (com.radixdlt.ledger.StateComputerLedger.StateComputer)3 VerifiedTxnsAndProof (com.radixdlt.ledger.VerifiedTxnsAndProof)3 ImmutableClassToInstanceMap (com.google.common.collect.ImmutableClassToInstanceMap)2 Inject (com.google.inject.Inject)2