Search in sources :

Example 6 with REProcessedTxn

use of com.radixdlt.constraintmachine.REProcessedTxn 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

REProcessedTxn (com.radixdlt.constraintmachine.REProcessedTxn)6 CloseableCursor (com.radixdlt.atom.CloseableCursor)3 SubstateId (com.radixdlt.atom.SubstateId)3 REAddr (com.radixdlt.identifiers.REAddr)3 DeserializeException (com.radixdlt.serialization.DeserializeException)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 FeeReserveCompleteException (com.radixdlt.application.system.construction.FeeReserveCompleteException)2 TxBuilderException (com.radixdlt.atom.TxBuilderException)2 ExecutionContext (com.radixdlt.constraintmachine.ExecutionContext)2 RawSubstateBytes (com.radixdlt.constraintmachine.RawSubstateBytes)2 SubstateIndex (com.radixdlt.constraintmachine.SubstateIndex)2 SystemMapKey (com.radixdlt.constraintmachine.SystemMapKey)2 AuthorizationException (com.radixdlt.constraintmachine.exceptions.AuthorizationException)2 ConstraintMachineException (com.radixdlt.constraintmachine.exceptions.ConstraintMachineException)2 RadixEngineException (com.radixdlt.engine.RadixEngineException)2 TxnParseException (com.radixdlt.engine.parser.exceptions.TxnParseException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2