Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sync and migration on compacted state #3472

Merged
merged 1 commit into from Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -59,11 +59,15 @@ class LastFinalizedKeyValueStorage[F[_]: Sync] private (
_ <- Log[F].info("Migration of LFB done.")

// record finalized blocks
finalizedBlockSet = DagOps
.bfTraverse(List(lfb)) { bh =>
blocksInfoMap.get(bh).map(_.parents.toList).getOrElse(List.empty)
}
.toList
finalizedBlockSet <- DagOps
.bfTraverseF(List(lfb)) { bh =>
blocksInfoMap
.get(bh)
// with trimmed state edge parents might not be in the blockmetadataDB, so filter them out
.map(_.parents.toList.filterA(blockMetadataDb.contains(_)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On compacted state finalized block set during migration were including edge blocks parents, which do not exist in metadata store. Fix is filtering them out.

.getOrElse(List.empty[BlockHash].pure)
}
.toList

processChunk = (chunk: List[BlockHash]) => {
implicit val s = new Show[BlockHash] {
Expand Down
Expand Up @@ -246,9 +246,9 @@ class Initializing[F[_]
.map(_.latestBlockHash)
.toSet

// Add sorted DAG in order from oldest to approved block
// Add sorted DAG in order from approved block to oldest
minHeight <- getMinBlockHeight
_ <- heightMap.flatMap(_._2).toList.traverse_ { hash =>
_ <- heightMap.flatMap(_._2).toList.reverse.traverse_ { hash =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to add LFB first, because each DagStore.insert returns DagRepresentation, which requires having finalized block in DagStore. Also each insert checks consistency of the DAG (heights should be continuous)

private def validateDagState(state: DagState): DagState = {
// Validate height map index (block numbers) are in sequence without holes
val m = state.heightMap
val (min, max) = if (m.nonEmpty) (m.firstKey, m.lastKey + 1) else (0L, 0L)
assert(max - min == m.size.toLong, "DAG store height map has numbers not in sequence.")
state
}

So fix is to add blocks in reverse order - down from LFB.

for {
block <- BlockStore[F].getUnsafe(hash)
// If sender has stake 0 in approved block, this means that sender has been slashed and block is invalid
Expand Down