use of tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao.HotUpdater in project teku by ConsenSys.
the class KvStoreDatabase method updateWeakSubjectivityState.
@Override
public void updateWeakSubjectivityState(WeakSubjectivityUpdate weakSubjectivityUpdate) {
try (final HotUpdater updater = hotDao.hotUpdater()) {
Optional<Checkpoint> checkpoint = weakSubjectivityUpdate.getWeakSubjectivityCheckpoint();
checkpoint.ifPresentOrElse(updater::setWeakSubjectivityCheckpoint, updater::clearWeakSubjectivityCheckpoint);
updater.commit();
}
}
use of tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao.HotUpdater in project teku by ConsenSys.
the class KvStoreDatabase method storeInitialAnchor.
@Override
public void storeInitialAnchor(final AnchorPoint anchor) {
try (final HotUpdater hotUpdater = hotDao.hotUpdater();
final FinalizedUpdater finalizedUpdater = finalizedDao.finalizedUpdater()) {
// We should only have a single block / state / checkpoint at anchorpoint initialization
final Checkpoint anchorCheckpoint = anchor.getCheckpoint();
final Bytes32 anchorRoot = anchorCheckpoint.getRoot();
final BeaconState anchorState = anchor.getState();
final Optional<SignedBeaconBlock> anchorBlock = anchor.getSignedBeaconBlock();
hotUpdater.setAnchor(anchor.getCheckpoint());
hotUpdater.setGenesisTime(anchorState.getGenesis_time());
hotUpdater.setJustifiedCheckpoint(anchorCheckpoint);
hotUpdater.setBestJustifiedCheckpoint(anchorCheckpoint);
hotUpdater.setFinalizedCheckpoint(anchorCheckpoint);
hotUpdater.setLatestFinalizedState(anchorState);
// We need to store the anchor block in both hot and cold storage so that on restart
// we're guaranteed to have at least one block / state to load into RecentChainData.
anchorBlock.ifPresent(block -> {
// Save to hot storage
hotUpdater.addHotBlock(new BlockAndCheckpointEpochs(block, new CheckpointEpochs(anchorState.getCurrent_justified_checkpoint().getEpoch(), anchorState.getFinalized_checkpoint().getEpoch())));
// Save to cold storage
finalizedUpdater.addFinalizedBlock(block);
});
putFinalizedState(finalizedUpdater, anchorRoot, anchorState);
finalizedUpdater.commit();
hotUpdater.commit();
}
}
use of tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao.HotUpdater 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.server.kvstore.dataaccess.KvStoreHotDao.HotUpdater in project teku by ConsenSys.
the class KvStoreDatabase method pruneHotStateRoots.
@Override
public void pruneHotStateRoots(final List<Bytes32> stateRoots) {
try (final HotUpdater updater = hotDao.hotUpdater()) {
updater.pruneHotStateRoots(stateRoots);
updater.commit();
}
}
use of tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao.HotUpdater in project teku by ConsenSys.
the class KvStoreDatabase method addHotStateRoots.
@Override
public void addHotStateRoots(final Map<Bytes32, SlotAndBlockRoot> stateRootToSlotAndBlockRootMap) {
try (final HotUpdater updater = hotDao.hotUpdater()) {
updater.addHotStateRoots(stateRootToSlotAndBlockRootMap);
updater.commit();
}
}
Aggregations