Search in sources :

Example 1 with ExecutionContext

use of com.radixdlt.constraintmachine.ExecutionContext in project radixdlt by radixdlt.

the class RadixEngine method executeInternal.

private RadixEngineResult executeInternal(EngineStore.EngineStoreInTransaction<M> engineStoreInTransaction, List<Txn> txns, M meta, PermissionLevel permissionLevel, boolean skipAuthorization) throws RadixEngineException {
    var processedTxns = new ArrayList<REProcessedTxn>();
    // FIXME: This is quite the hack to increase sigsLeft for execution on noncommits (e.g. mempool)
    // FIXME: Should probably just change metering
    // Start with 0
    var sigsLeft = meta != null ? 0 : 1000;
    var storageStopwatch = Stopwatch.createUnstarted();
    var verificationStopwatch = Stopwatch.createUnstarted();
    for (int i = 0; i < txns.size(); i++) {
        var txn = txns.get(i);
        verificationStopwatch.start();
        var context = new ExecutionContext(txn, permissionLevel, skipAuthorization, sigsLeft);
        final REProcessedTxn processedTxn;
        try {
            processedTxn = this.verify(engineStoreInTransaction, txn, context);
        } catch (TxnParseException | AuthorizationException | ConstraintMachineException e) {
            throw new RadixEngineException(i, txns.size(), txn, e);
        }
        verificationStopwatch.stop();
        // Carry sigs left to the next transaction
        sigsLeft = context.sigsLeft();
        storageStopwatch.start();
        try {
            engineStoreInTransaction.storeTxn(processedTxn);
        } catch (Exception e) {
            logger.error("Store of atom failed: " + processedTxn, e);
            throw e;
        }
        storageStopwatch.stop();
        processedTxns.add(processedTxn);
    }
    try {
        batchVerifier.testMetadata(meta, processedTxns);
    } catch (MetadataException e) {
        logger.error("Invalid metadata: " + processedTxns);
        throw e;
    }
    if (meta != null) {
        engineStoreInTransaction.storeMetadata(meta);
    }
    return RadixEngineResult.create(processedTxns, verificationStopwatch.elapsed(TimeUnit.MILLISECONDS), storageStopwatch.elapsed(TimeUnit.MILLISECONDS));
}
Also used : ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) ExecutionContext(com.radixdlt.constraintmachine.ExecutionContext) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) ArrayList(java.util.ArrayList) TxnParseException(com.radixdlt.engine.parser.exceptions.TxnParseException) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) TxBuilderException(com.radixdlt.atom.TxBuilderException) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) TxnParseException(com.radixdlt.engine.parser.exceptions.TxnParseException) DeserializeException(com.radixdlt.serialization.DeserializeException) FeeReserveCompleteException(com.radixdlt.application.system.construction.FeeReserveCompleteException)

Example 2 with ExecutionContext

use of com.radixdlt.constraintmachine.ExecutionContext in project radixdlt by radixdlt.

the class RadixEngine method executeInternal.

private RadixEngineResult<M> executeInternal(EngineStore.EngineStoreInTransaction<M> engineStoreInTransaction, List<Txn> txns, Optional<M> metaOpt, PermissionLevel permissionLevel, boolean skipAuthorization) throws RadixEngineException {
    var processedTxns = new ArrayList<REProcessedTxn>();
    // FIXME: This is quite the hack to increase sigsLeft for execution on noncommits (e.g. mempool)
    // FIXME: Should probably just change metering
    // Start with 0
    var sigsLeft = metaOpt.isPresent() ? 0 : 1000;
    var storageStopwatch = Stopwatch.createUnstarted();
    var verificationStopwatch = Stopwatch.createUnstarted();
    for (int i = 0; i < txns.size(); i++) {
        var txn = txns.get(i);
        verificationStopwatch.start();
        var context = new ExecutionContext(txn, permissionLevel, skipAuthorization, sigsLeft);
        final REProcessedTxn processedTxn;
        try {
            processedTxn = this.verify(engineStoreInTransaction, txn, context);
        } catch (TxnParseException | AuthorizationException | ConstraintMachineException e) {
            throw new RadixEngineException(i, txns.size(), txn, e);
        }
        verificationStopwatch.stop();
        // Carry sigs left to the next transaction
        sigsLeft = context.sigsLeft();
        storageStopwatch.start();
        try {
            engineStoreInTransaction.storeTxn(processedTxn);
        } catch (Exception e) {
            logger.error("Store of atom failed: " + processedTxn, e);
            throw e;
        }
        storageStopwatch.stop();
        processedTxns.add(processedTxn);
    }
    try {
        final var resultMetadata = metaOpt.map(meta -> {
            final var postProcessedMetadata = postProcessor.process(meta, engineStoreInTransaction, processedTxns);
            engineStoreInTransaction.storeMetadata(postProcessedMetadata);
            return postProcessedMetadata;
        }).orElse(null);
        return RadixEngineResult.create(processedTxns, resultMetadata, verificationStopwatch.elapsed(TimeUnit.MILLISECONDS), storageStopwatch.elapsed(TimeUnit.MILLISECONDS));
    } catch (PostProcessorException e) {
        logger.error("Invalid metadata: " + processedTxns);
        throw e;
    }
}
Also used : SubstateSerialization(com.radixdlt.constraintmachine.SubstateSerialization) TxAction(com.radixdlt.atom.TxAction) BiFunction(java.util.function.BiFunction) TxBuilder(com.radixdlt.atom.TxBuilder) TxnConstructionRequest(com.radixdlt.atom.TxnConstructionRequest) ResourceInBucket(com.radixdlt.application.tokens.ResourceInBucket) VirtualSubstateDeserialization(com.radixdlt.constraintmachine.VirtualSubstateDeserialization) ParsedTxn(com.radixdlt.engine.parser.ParsedTxn) Map(java.util.Map) SystemMapKey(com.radixdlt.constraintmachine.SystemMapKey) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) Predicate(java.util.function.Predicate) Set(java.util.Set) ExecutionContext(com.radixdlt.constraintmachine.ExecutionContext) REAddr(com.radixdlt.identifiers.REAddr) TxBuilderException(com.radixdlt.atom.TxBuilderException) EngineStore(com.radixdlt.store.EngineStore) Particle(com.radixdlt.constraintmachine.Particle) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) Optional(java.util.Optional) TxnParseException(com.radixdlt.engine.parser.exceptions.TxnParseException) SubstateId(com.radixdlt.atom.SubstateId) UInt384(com.radixdlt.utils.UInt384) Stopwatch(com.google.common.base.Stopwatch) SubstateStore(com.radixdlt.atom.SubstateStore) HashMap(java.util.HashMap) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) ECPublicKey(com.radixdlt.crypto.ECPublicKey) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) RawSubstateBytes(com.radixdlt.constraintmachine.RawSubstateBytes) ArrayList(java.util.ArrayList) TransientEngineStore(com.radixdlt.store.TransientEngineStore) SubstateDeserialization(com.radixdlt.constraintmachine.SubstateDeserialization) REParser(com.radixdlt.engine.parser.REParser) UInt256(com.radixdlt.utils.UInt256) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn) SubstateIndex(com.radixdlt.constraintmachine.SubstateIndex) ConstraintMachineConfig(com.radixdlt.constraintmachine.ConstraintMachineConfig) Txn(com.radixdlt.atom.Txn) TimeUnit(java.util.concurrent.TimeUnit) CloseableCursor(com.radixdlt.atom.CloseableCursor) ConstraintMachine(com.radixdlt.constraintmachine.ConstraintMachine) DeserializeException(com.radixdlt.serialization.DeserializeException) FeeReserveCompleteException(com.radixdlt.application.system.construction.FeeReserveCompleteException) LogManager(org.apache.logging.log4j.LogManager) REConstructor(com.radixdlt.atom.REConstructor) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) ArrayList(java.util.ArrayList) TxnParseException(com.radixdlt.engine.parser.exceptions.TxnParseException) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) TxBuilderException(com.radixdlt.atom.TxBuilderException) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) TxnParseException(com.radixdlt.engine.parser.exceptions.TxnParseException) DeserializeException(com.radixdlt.serialization.DeserializeException) FeeReserveCompleteException(com.radixdlt.application.system.construction.FeeReserveCompleteException) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) ExecutionContext(com.radixdlt.constraintmachine.ExecutionContext)

Aggregations

FeeReserveCompleteException (com.radixdlt.application.system.construction.FeeReserveCompleteException)2 TxBuilderException (com.radixdlt.atom.TxBuilderException)2 ExecutionContext (com.radixdlt.constraintmachine.ExecutionContext)2 REProcessedTxn (com.radixdlt.constraintmachine.REProcessedTxn)2 AuthorizationException (com.radixdlt.constraintmachine.exceptions.AuthorizationException)2 ConstraintMachineException (com.radixdlt.constraintmachine.exceptions.ConstraintMachineException)2 TxnParseException (com.radixdlt.engine.parser.exceptions.TxnParseException)2 DeserializeException (com.radixdlt.serialization.DeserializeException)2 ArrayList (java.util.ArrayList)2 Stopwatch (com.google.common.base.Stopwatch)1 ResourceInBucket (com.radixdlt.application.tokens.ResourceInBucket)1 CloseableCursor (com.radixdlt.atom.CloseableCursor)1 REConstructor (com.radixdlt.atom.REConstructor)1 SubstateId (com.radixdlt.atom.SubstateId)1 SubstateStore (com.radixdlt.atom.SubstateStore)1 TxAction (com.radixdlt.atom.TxAction)1 TxBuilder (com.radixdlt.atom.TxBuilder)1 Txn (com.radixdlt.atom.Txn)1 TxnConstructionRequest (com.radixdlt.atom.TxnConstructionRequest)1 ConstraintMachine (com.radixdlt.constraintmachine.ConstraintMachine)1