Search in sources :

Example 1 with UpdateResult

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);
}
Also used : SlotAndExecutionPayload(tech.pegasys.teku.spec.datastructures.execution.SlotAndExecutionPayload) HotUpdater(tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao.HotUpdater) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) UpdateResult(tech.pegasys.teku.storage.api.UpdateResult)

Example 2 with UpdateResult

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;
    });
}
Also used : UpdateResult(tech.pegasys.teku.storage.api.UpdateResult)

Aggregations

UpdateResult (tech.pegasys.teku.storage.api.UpdateResult)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 SlotAndExecutionPayload (tech.pegasys.teku.spec.datastructures.execution.SlotAndExecutionPayload)1 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)1 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)1 HotUpdater (tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao.HotUpdater)1