Search in sources :

Example 1 with LedgerProof

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

the class ForksVotingResultsHandlerTest method storeMetadataWithForks.

private void storeMetadataWithForks(long epoch, ImmutableSet<com.radixdlt.statecomputer.forks.ForkVotingResult> forkVotingResults) throws RadixEngineException {
    final var fakeTx = mock(REProcessedTxn.class);
    final var txn = mock(Txn.class);
    when(txn.getId()).thenReturn(AID.from(HashUtils.random256().asBytes()));
    when(fakeTx.getTxn()).thenReturn(txn);
    when(fakeTx.getTxnId()).thenReturn(AID.ZERO);
    when(fakeTx.getGroupedStateUpdates()).thenReturn(List.of());
    when(txn.getPayload()).thenReturn(HashUtils.random256().asBytes());
    final var proof1 = LedgerAndBFTProof.create(new LedgerProof(HashUtils.random256(), LedgerHeader.create(epoch, View.of(0L), new AccumulatorState(epoch, /* using same state version as epoch */
    HashCode.fromInt(1)), 0L), new TimestampedECDSASignatures(Map.of()))).withForksVotingResults(forkVotingResults);
    berkeleyLedgerEntryStore.transaction(tx -> {
        tx.storeTxn(fakeTx);
        tx.storeMetadata(proof1);
        return null;
    });
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) AccumulatorState(com.radixdlt.ledger.AccumulatorState) LedgerProof(com.radixdlt.hotstuff.LedgerProof)

Example 2 with LedgerProof

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

the class BerkeleyLedgerEntryStore method getNextCommittedTxns.

@Override
public VerifiedTxnsAndProof getNextCommittedTxns(DtoLedgerProof start) {
    long stateVersion = start.getLedgerHeader().getAccumulatorState().getStateVersion();
    final var startTime = System.nanoTime();
    com.sleepycat.je.Transaction txn = beginTransaction();
    final LedgerProof nextHeader;
    try (var proofCursor = proofDatabase.openCursor(txn, null)) {
        final var headerSearchKey = toPKey(stateVersion + 1);
        final var headerValue = entry();
        var headerCursorStatus = proofCursor.getSearchKeyRange(headerSearchKey, headerValue, DEFAULT);
        if (headerCursorStatus != SUCCESS) {
            return null;
        }
        nextHeader = deserializeOrElseFail(headerValue.getData(), LedgerProof.class);
    } finally {
        txn.commit();
    }
    final var txns = ImmutableList.<Txn>builder();
    final var atomSearchKey = toPKey(stateVersion + 1);
    final var atomPosData = entry();
    try (var txnCursor = txnDatabase.openCursor(null, null)) {
        int atomCount = (int) (nextHeader.getStateVersion() - stateVersion);
        int count = 0;
        var atomCursorStatus = txnCursor.getSearchKeyRange(atomSearchKey, atomPosData, DEFAULT);
        do {
            if (atomCursorStatus != SUCCESS) {
                throw new BerkeleyStoreException("Atom database search failure");
            }
            var offset = fromByteArray(atomPosData.getData());
            var txnBytes = txnLog.read(offset);
            txns.add(Txn.create(txnBytes));
            atomCursorStatus = txnCursor.getNext(atomSearchKey, atomPosData, DEFAULT);
            count++;
        } while (count < atomCount);
        return VerifiedTxnsAndProof.create(txns.build(), nextHeader);
    } catch (IOException e) {
        throw new BerkeleyStoreException("Unable to read from atom store.", e);
    } finally {
        addTime(startTime, CounterType.ELAPSED_BDB_LEDGER_ENTRIES, CounterType.COUNT_BDB_LEDGER_ENTRIES);
    }
}
Also used : LedgerProof(com.radixdlt.hotstuff.LedgerProof) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn) Txn(com.radixdlt.atom.Txn) IOException(java.io.IOException) Transaction(com.sleepycat.je.Transaction)

Example 3 with LedgerProof

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

the class LedgerFileSync method restoreFromFile.

/**
 * Reads and processes ledger sync data from a file.
 */
public static void restoreFromFile(String fileName, Serialization serialization, EventDispatcher<VerifiedTxnsAndProof> verifiedTxnsAndProofDispatcher) throws IOException {
    try (var in = new FileInputStream(fileName)) {
        while (in.available() > 0) {
            final var len = ByteBuffer.wrap(in.readNBytes(4)).getInt();
            final var data = in.readNBytes(len);
            final var wrapper = serialization.fromDson(Compress.uncompress(data), CommandsAndProof.class);
            final var proof = wrapper.getProof();
            // TODO: verify the proof
            final var verifiedTxnsAndProof = VerifiedTxnsAndProof.create(wrapper.getTxns(), new LedgerProof(proof.getOpaque(), proof.getLedgerHeader(), proof.getSignatures()));
            verifiedTxnsAndProofDispatcher.dispatch(verifiedTxnsAndProof);
        }
    }
}
Also used : LedgerProof(com.radixdlt.hotstuff.LedgerProof) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) FileInputStream(java.io.FileInputStream)

Example 4 with LedgerProof

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

the class RadixEngineStateComputerTest method committing_epoch_change_with_additional_cmds_should_fail.

// TODO: should catch this and log it somewhere as proof of byzantine quorum
@Test
public void committing_epoch_change_with_additional_cmds_should_fail() throws Exception {
    // Arrange
    var keyPair = ECKeyPair.generateNew();
    var cmd0 = systemUpdateCommand(0, 2);
    var cmd1 = registerCommand(keyPair);
    var ledgerProof = new LedgerProof(HashUtils.random256(), LedgerHeader.create(0, View.of(9), new AccumulatorState(3, HashUtils.zero256()), 0), new TimestampedECDSASignatures());
    var commandsAndProof = VerifiedTxnsAndProof.create(ImmutableList.of(cmd0, cmd1), ledgerProof);
    // Act
    // Assert
    assertThatThrownBy(() -> sut.commit(commandsAndProof, null)).isInstanceOf(ByzantineQuorumException.class);
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) AccumulatorState(com.radixdlt.ledger.AccumulatorState) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Test(org.junit.Test)

Example 5 with LedgerProof

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

the class RadixEngineStateComputerTest method committing_epoch_change_when_there_shouldnt_be_one__should_fail.

// TODO: should catch this and log it somewhere as proof of byzantine quorum
@Test
public void committing_epoch_change_when_there_shouldnt_be_one__should_fail() throws TxBuilderException {
    // Arrange
    var cmd0 = systemUpdateCommand(1, 1);
    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(cmd0), ledgerProof);
    // Act
    // Assert
    assertThatThrownBy(() -> sut.commit(commandsAndProof, null)).isInstanceOf(ByzantineQuorumException.class);
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) AccumulatorState(com.radixdlt.ledger.AccumulatorState) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Test(org.junit.Test)

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