use of com.radixdlt.constraintmachine.REProcessedTxn 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));
}
use of com.radixdlt.constraintmachine.REProcessedTxn in project radixdlt by radixdlt.
the class InMemorySystemInfoTest method createLedgerUpdate.
private LedgerUpdate createLedgerUpdate(BFTNode self) {
var events = List.<REEvent>of(new ValidatorBFTDataEvent(self.getKey(), 10, 1));
var txn = new REProcessedTxn(null, null, null, events);
var output = ImmutableClassToInstanceMap.<Object, REOutput>of(REOutput.class, REOutput.create(List.of(txn)));
return new LedgerUpdate(mock(VerifiedTxnsAndProof.class), output);
}
use of com.radixdlt.constraintmachine.REProcessedTxn in project radixdlt by radixdlt.
the class InMemoryEngineStore method transaction.
@Override
public <R> R transaction(TransactionEngineStoreConsumer<M, R> consumer) throws RadixEngineException {
return consumer.start(new EngineStoreInTransaction<>() {
@Override
public void storeTxn(REProcessedTxn txn) {
synchronized (lock) {
txn.stateUpdates().forEach(update -> {
store.storedState.put(update.getId(), update);
// FIXME: Superhack
if (update.isBootUp()) {
if (update.getParsed() instanceof TokenResource) {
var tokenDef = (TokenResource) update.getParsed();
store.resources.put(tokenDef.addr(), update::getStateBuf);
} else if (update.getParsed() instanceof VirtualParent) {
var p = (VirtualParent) update.getParsed();
var typeByte = p.data()[0];
var mapKey = SystemMapKey.ofSystem(typeByte);
store.maps.put(mapKey, update.getRawSubstateBytes());
} else if (update.getParsed() instanceof ValidatorData) {
var data = (ValidatorData) update.getParsed();
var mapKey = SystemMapKey.ofSystem(update.typeByte(), data.validatorKey().getCompressedBytes());
store.maps.put(mapKey, update.getRawSubstateBytes());
} else if (update.getParsed() instanceof SystemData) {
var mapKey = SystemMapKey.ofSystem(update.typeByte());
store.maps.put(mapKey, update.getRawSubstateBytes());
}
} else if (update.isShutDown()) {
if (update.getParsed() instanceof ValidatorData) {
var data = (ValidatorData) update.getParsed();
var mapKey = SystemMapKey.ofSystem(update.typeByte(), data.validatorKey().getCompressedBytes());
store.maps.remove(mapKey);
} else if (update.getParsed() instanceof SystemData) {
var mapKey = SystemMapKey.ofSystem(update.typeByte());
store.maps.remove(mapKey);
}
}
});
}
}
@Override
public void storeMetadata(M metadata) {
store.metadata = metadata;
}
@Override
public ByteBuffer verifyVirtualSubstate(SubstateId substateId) throws VirtualSubstateAlreadyDownException, VirtualParentStateDoesNotExist {
synchronized (lock) {
var parent = substateId.getVirtualParent().orElseThrow();
var update = store.storedState.get(parent);
if (update == null || !(update.getParsed() instanceof VirtualParent)) {
throw new VirtualParentStateDoesNotExist(parent);
}
var inst = store.storedState.get(substateId);
if (inst != null && inst.isShutDown()) {
throw new VirtualSubstateAlreadyDownException(substateId);
}
return update.getStateBuf();
}
}
@Override
public Optional<ByteBuffer> loadSubstate(SubstateId substateId) {
synchronized (lock) {
var inst = store.storedState.get(substateId);
if (inst == null || !inst.isBootUp()) {
return Optional.empty();
}
return Optional.of(inst.getStateBuf());
}
}
@Override
public CloseableCursor<RawSubstateBytes> openIndexedCursor(SubstateIndex<?> index) {
return InMemoryEngineStore.this.openIndexedCursor(index);
}
@Override
public Optional<ByteBuffer> loadResource(REAddr addr) {
synchronized (lock) {
var supplier = store.resources.get(addr);
return supplier == null ? Optional.empty() : Optional.of(supplier.get());
}
}
});
}
use of com.radixdlt.constraintmachine.REProcessedTxn 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;
}
}
use of com.radixdlt.constraintmachine.REProcessedTxn in project radixdlt by radixdlt.
the class ConstructionParseHandler method handleRequest.
@Override
public ConstructionParseResponse handleRequest(ConstructionParseRequest request) throws CoreApiException {
modelMapper.verifyNetwork(request.getNetworkIdentifier());
var txn = modelMapper.bytes(request.getTransaction());
REProcessedTxn processed;
try {
processed = radixEngineStateComputer.test(txn, request.getSigned());
} catch (RadixEngineException e) {
throw modelMapper.radixEngineException(e);
}
var response = new ConstructionParseResponse();
var transaction = modelMapper.transaction(processed, this::symbol);
transaction.getOperationGroups().forEach(response::addOperationGroupsItem);
response.metadata(new ParsedTransactionMetadata().fee(transaction.getMetadata().getFee()).message(transaction.getMetadata().getMessage()));
return response;
}
Aggregations