Skip to content

Commit

Permalink
Add check to the snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
  • Loading branch information
frolosofsky committed Apr 2, 2019
1 parent 7d21e75 commit c65c646
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/p2p/finalizer_commits_handler_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ bool FinalizerCommitsHandlerImpl::OnCommits(

const uint32_t index_epoch = index_state->GetLastFinalizedEpoch();
const uint32_t tip_epoch = tip_state->GetLastFinalizedEpoch();
const bool snapshot_enabled = snapshot::IsISDEnabled();
const bool snapshot_enabled = snapshot::IsISDEnabled() && snapshot::IsInitialSnapshotDownload();

if (!snapshot_enabled && index_epoch > tip_epoch) {
download_until = index_state->GetEpochCheckpointHeight(index_epoch + 1);
Expand Down
15 changes: 11 additions & 4 deletions src/snapshot/p2p_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <snapshot/p2p_processing.h>

#include <esperanza/finalizationstate.h>
#include <injector.h>
#include <snapshot/iterator.h>
#include <snapshot/snapshot_index.h>
#include <snapshot/state.h>
Expand All @@ -15,14 +16,20 @@

namespace snapshot {

inline CBlockIndex *LookupFinalizedBlockIndex(const uint256 &hash) {
CBlockIndex *bi = LookupBlockIndex(hash);
inline const CBlockIndex *LookupFinalizedBlockIndex(const uint256 &hash) {
const CBlockIndex *bi = LookupBlockIndex(hash);
if (!bi) {
LogPrint(BCLog::SNAPSHOT, "%s: block=%s not found\n", __func__, hash.GetHex());
return nullptr;
}

auto fin_repo = GetComponent<finalization::StateRepository>();
const finalization::FinalizationState *fin_state = fin_repo->GetTipState();
if (bi->nHeight <= fin_state->GetEpochCheckpointHeight(fin_state->GetLastFinalizedEpoch())) {
LogPrint(BCLog::SNAPSHOT, "%s: block=%s height=%d is not finalized\n", hash.GetHex(), bi->nHeight);
return nullptr;
}

// todo: check that header is finalized
// once ADR-21 is implemented
return bi;
}

Expand Down

0 comments on commit c65c646

Please sign in to comment.