use of com.radixdlt.constraintmachine.RawSubstateBytes in project radixdlt by radixdlt.
the class BerkeleyLedgerEntryStore method scanner.
public Stream<RawSubstateBytes> scanner() {
var cursor = substatesDatabase.openCursor(null, null);
var iterator = new Iterator<RawSubstateBytes>() {
final DatabaseEntry key = new DatabaseEntry();
final DatabaseEntry data = new DatabaseEntry();
OperationStatus status = cursor.getFirst(key, data, null);
@Override
public boolean hasNext() {
return status == SUCCESS;
}
@Override
public RawSubstateBytes next() {
if (status != SUCCESS) {
throw new NoSuchElementException();
}
var next = new RawSubstateBytes(key.getData(), data.getData());
status = cursor.getNext(key, data, null);
return next;
}
};
return Streams.stream(iterator).onClose(cursor::close);
}
use of com.radixdlt.constraintmachine.RawSubstateBytes 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.RawSubstateBytes in project radixdlt by radixdlt.
the class RadixEngine method construct.
private TxBuilder construct(TxBuilderExecutable executable, Set<SubstateId> avoid) throws TxBuilderException {
synchronized (stateUpdateEngineLock) {
SubstateStore filteredStore = new SubstateStore() {
@Override
public CloseableCursor<RawSubstateBytes> openIndexedCursor(SubstateIndex<?> index) {
return engineStore.openIndexedCursor(index).filter(i -> !avoid.contains(SubstateId.fromBytes(i.getId())));
}
@Override
public Optional<RawSubstateBytes> get(SystemMapKey key) {
return engineStore.get(key);
}
};
var txBuilder = TxBuilder.newBuilder(filteredStore, constraintMachine.getDeserialization(), serialization, maxMessageLen);
executable.execute(txBuilder);
return txBuilder;
}
}
Aggregations