Search in sources :

Example 1 with LedgerAndBFTProof

use of com.radixdlt.statecomputer.LedgerAndBFTProof in project radixdlt by radixdlt.

the class EngineStatusServiceTest method setup.

private void setup(long currentEpoch) {
    final RadixEngine<LedgerAndBFTProof> radixEngine = rmock(RadixEngine.class);
    final var committedReader = mock(CommittedReader.class);
    final var lastProof = mock(LedgerProof.class);
    when(lastProof.getEpoch()).thenReturn(currentEpoch);
    forksEpochStore = new InMemoryForksEpochStore(new InMemoryForksEpochStore.Store());
    forkVoteStatusService = mock(ForkVoteStatusService.class);
    sut = new EngineStatusService(radixEngine, committedReader, lastProof, lastProof, forks, forksEpochStore, forkVoteStatusService);
}
Also used : ForkVoteStatusService(com.radixdlt.api.system.health.ForkVoteStatusService) LedgerAndBFTProof(com.radixdlt.statecomputer.LedgerAndBFTProof) InMemoryForksEpochStore(com.radixdlt.statecomputer.forks.InMemoryForksEpochStore) InMemoryForksEpochStore(com.radixdlt.statecomputer.forks.InMemoryForksEpochStore)

Example 2 with LedgerAndBFTProof

use of com.radixdlt.statecomputer.LedgerAndBFTProof in project radixdlt by radixdlt.

the class BerkeleyLedgerEntryStore method transaction.

@Override
public <R> R transaction(TransactionEngineStoreConsumer<LedgerAndBFTProof, R> consumer) throws RadixEngineException {
    var dbTxn = createTransaction();
    try {
        var result = consumer.start(new EngineStoreInTransaction<>() {

            @Override
            public void storeTxn(REProcessedTxn txn) {
                BerkeleyLedgerEntryStore.this.storeTxn(dbTxn, txn);
            }

            @Override
            public void storeMetadata(LedgerAndBFTProof metadata) {
                BerkeleyLedgerEntryStore.this.storeMetadata(dbTxn, metadata);
            }

            @Override
            public ByteBuffer verifyVirtualSubstate(SubstateId substateId) throws VirtualSubstateAlreadyDownException, VirtualParentStateDoesNotExist {
                var parent = substateId.getVirtualParent().orElseThrow();
                var parentState = BerkeleyLedgerEntryStore.this.loadSubstate(dbTxn, parent);
                if (parentState.isEmpty()) {
                    throw new VirtualParentStateDoesNotExist(parent);
                }
                var buf = parentState.get();
                if (buf.get() != SubstateTypeId.VIRTUAL_PARENT.id()) {
                    throw new VirtualParentStateDoesNotExist(parent);
                }
                buf.position(buf.position() - 1);
                if (BerkeleyLedgerEntryStore.this.isVirtualDown(dbTxn, substateId)) {
                    throw new VirtualSubstateAlreadyDownException(substateId);
                }
                return buf;
            }

            @Override
            public Optional<ByteBuffer> loadSubstate(SubstateId substateId) {
                return BerkeleyLedgerEntryStore.this.loadSubstate(dbTxn, substateId);
            }

            @Override
            public CloseableCursor<RawSubstateBytes> openIndexedCursor(SubstateIndex<?> index) {
                return BerkeleyLedgerEntryStore.this.openIndexedCursor(dbTxn, index);
            }

            @Override
            public Optional<ByteBuffer> loadResource(REAddr addr) {
                return BerkeleyLedgerEntryStore.this.loadAddr(dbTxn, addr);
            }
        });
        dbTxn.commit();
        return result;
    } catch (Exception e) {
        dbTxn.abort();
        throw e;
    }
}
Also used : CloseableCursor(com.radixdlt.atom.CloseableCursor) Optional(java.util.Optional) LedgerAndBFTProof(com.radixdlt.statecomputer.LedgerAndBFTProof) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn) ByteBuffer(java.nio.ByteBuffer) RadixEngineException(com.radixdlt.engine.RadixEngineException) VirtualSubstateAlreadyDownException(com.radixdlt.constraintmachine.exceptions.VirtualSubstateAlreadyDownException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) DeserializeException(com.radixdlt.serialization.DeserializeException) VirtualParentStateDoesNotExist(com.radixdlt.constraintmachine.exceptions.VirtualParentStateDoesNotExist) SubstateId(com.radixdlt.atom.SubstateId) VirtualSubstateAlreadyDownException(com.radixdlt.constraintmachine.exceptions.VirtualSubstateAlreadyDownException) REAddr(com.radixdlt.identifiers.REAddr)

Aggregations

LedgerAndBFTProof (com.radixdlt.statecomputer.LedgerAndBFTProof)2 ForkVoteStatusService (com.radixdlt.api.system.health.ForkVoteStatusService)1 CloseableCursor (com.radixdlt.atom.CloseableCursor)1 SubstateId (com.radixdlt.atom.SubstateId)1 REProcessedTxn (com.radixdlt.constraintmachine.REProcessedTxn)1 VirtualParentStateDoesNotExist (com.radixdlt.constraintmachine.exceptions.VirtualParentStateDoesNotExist)1 VirtualSubstateAlreadyDownException (com.radixdlt.constraintmachine.exceptions.VirtualSubstateAlreadyDownException)1 RadixEngineException (com.radixdlt.engine.RadixEngineException)1 REAddr (com.radixdlt.identifiers.REAddr)1 DeserializeException (com.radixdlt.serialization.DeserializeException)1 InMemoryForksEpochStore (com.radixdlt.statecomputer.forks.InMemoryForksEpochStore)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1