use of tech.pegasys.teku.storage.api.UpdateResult in project teku by ConsenSys.
the class KvStoreDatabase method doUpdate.
private UpdateResult doUpdate(final StorageUpdate update) {
LOG.trace("Applying finalized updates");
// Update finalized blocks and states
final Optional<SlotAndExecutionPayload> finalizedOptimisticExecutionPayload = updateFinalizedData(update.getFinalizedChildToParentMap(), update.getFinalizedBlocks(), update.getFinalizedStates(), update.getDeletedHotBlocks(), update.isFinalizedOptimisticTransitionBlockRootSet(), update.getOptimisticTransitionBlockRoot());
LOG.trace("Applying hot updates");
try (final HotUpdater updater = hotDao.hotUpdater()) {
// Store new hot data
update.getGenesisTime().ifPresent(updater::setGenesisTime);
update.getFinalizedCheckpoint().ifPresent(checkpoint -> {
updater.setFinalizedCheckpoint(checkpoint);
final int slotsPerEpoch = spec.slotsPerEpoch(checkpoint.getEpoch());
final UInt64 finalizedSlot = checkpoint.getEpochStartSlot(spec).plus(slotsPerEpoch);
updater.pruneHotStateRoots(hotDao.getStateRootsBeforeSlot(finalizedSlot));
updater.deleteHotState(checkpoint.getRoot());
});
update.getJustifiedCheckpoint().ifPresent(updater::setJustifiedCheckpoint);
update.getBestJustifiedCheckpoint().ifPresent(updater::setBestJustifiedCheckpoint);
update.getLatestFinalizedState().ifPresent(updater::setLatestFinalizedState);
updater.addHotBlocks(update.getHotBlocks());
updater.addHotStates(update.getHotStates());
if (update.getStateRoots().size() > 0) {
updater.addHotStateRoots(update.getStateRoots());
}
// Delete finalized data from hot db
update.getDeletedHotBlocks().forEach(updater::deleteHotBlock);
LOG.trace("Committing hot db changes");
updater.commit();
}
LOG.trace("Update complete");
return new UpdateResult(finalizedOptimisticExecutionPayload);
}
use of tech.pegasys.teku.storage.api.UpdateResult in project teku by ConsenSys.
the class ChainStorage method onStorageUpdate.
@Override
public SafeFuture<UpdateResult> onStorageUpdate(final StorageUpdate event) {
return SafeFuture.of(() -> {
final UpdateResult updateResult = database.update(event);
handleStoreUpdate();
return updateResult;
});
}
Aggregations