Skip to content

Commit

Permalink
NODE-2609 Call rollback trigger only after successful block validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mashonskii committed Sep 20, 2023
1 parent 98ef738 commit 26f343e
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ class BlockchainUpdaterImpl(
val height = rocksdb.unsafeHeightOf(ng.base.header.reference)
val miningConstraints = MiningConstraints(rocksdb, height, wavesSettings.enableLightMode)

blockchainUpdateTriggers.onRollback(this, ng.base.header.reference, rocksdb.height)

val referencedBlockchain = SnapshotBlockchain(rocksdb, ng.reward)
BlockDiffer
.fromBlock(
Expand All @@ -278,6 +276,7 @@ class BlockchainUpdaterImpl(
BlockStats.replaced(ng.base, block)
val (mbs, diffs) = ng.allSnapshots.unzip
log.trace(s"Discarded microblocks = $mbs, diffs = ${diffs.map(_.hashString)}")
blockchainUpdateTriggers.onRollback(this, ng.base.header.reference, rocksdb.height)
blockchainUpdateTriggers.onProcessBlock(block, r.keyBlockSnapshot, ng.reward, hitSource, referencedBlockchain)
Some((r, diffs, ng.reward, hitSource))
}
Expand All @@ -298,12 +297,6 @@ class BlockchainUpdaterImpl(
if (!verify || referencedForgedBlock.signatureValid()) {
val height = rocksdb.heightOf(referencedForgedBlock.header.reference).getOrElse(0)

if (discarded.nonEmpty) {
blockchainUpdateTriggers.onMicroBlockRollback(this, block.header.reference)
metrics.microBlockForkStats.increment()
metrics.microBlockForkHeightStats.record(discarded.size)
}

val constraint: MiningConstraint = {
val miningConstraints = MiningConstraints(rocksdb, height, wavesSettings.enableLightMode)
miningConstraints.total
Expand Down Expand Up @@ -350,6 +343,11 @@ class BlockchainUpdaterImpl(
)
miner.scheduleMining(Some(tempBlockchain))

if (discarded.nonEmpty) {
blockchainUpdateTriggers.onMicroBlockRollback(this, block.header.reference)
metrics.microBlockForkStats.increment()
metrics.microBlockForkHeightStats.record(discarded.size)
}
blockchainUpdateTriggers.onProcessBlock(block, differResult.keyBlockSnapshot, reward, hitSource, this)

rocksdb.append(
Expand Down

0 comments on commit 26f343e

Please sign in to comment.