Skip to content

Commit 19de805

Browse files
authored
Merge pull request #1320 from Concordium/fix-1319
Fix bug in calculation of absolute block height
2 parents 0917569 + 7a04a42 commit 19de805

File tree

7 files changed

+33
-23
lines changed

7 files changed

+33
-23
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Unreleased changes
44

5+
## 8.0.3
6+
7+
- Fix a bug where, after a protocol update in consensus version 1 (P6 onwards), a node may
8+
miscalculate the absolute height of blocks when it is restarted. (#1319)
9+
- Fix a bug where `GetBlockInfo` reports the parent block of a genesis block to be the last
10+
finalized block of the previous genesis index, instead of the terminal block.
11+
512
## 8.0.2
613

714
- Fix a bug where the P7->P8 protocol update affects payday timing.

concordium-consensus/src/Concordium/KonsensusV1/SkovMonad.hs

+3-6
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,9 @@ data ExistingSkov pv m = ExistingSkov
465465
esState :: !(SkovV1State pv),
466466
-- | The hash of the current genesis block.
467467
esGenesisHash :: !BlockHash,
468-
-- | The (relative) height of the last finalized block.
469-
esLastFinalizedHeight :: !BlockHeight,
470-
-- | The effective protocol update if one has occurred.
471-
esProtocolUpdate :: !(Maybe ProtocolUpdate)
468+
-- | The effective protocol update if one has occurred, together with the relative
469+
-- block height of the terminal block.
470+
esProtocolUpdate :: !(Maybe (ProtocolUpdate, BlockHeight))
472471
}
473472

474473
-- | Internal type used for deriving 'HasDatabaseHandlers' and 'LMDBAccountMap.HasDatabaseHandlers'
@@ -541,8 +540,6 @@ initialiseExistingSkovV1 genesisBlockHeightInfo bakerCtx handlerCtx unliftSkov g
541540
_notifiedProtocolUpdate = Nothing
542541
},
543542
esGenesisHash = initialSkovData ^. currentGenesisHash,
544-
esLastFinalizedHeight =
545-
blockHeight (initialSkovData ^. lastFinalized),
546543
esProtocolUpdate = effectiveProtocolUpdate
547544
}
548545
return $ Just es

concordium-consensus/src/Concordium/KonsensusV1/TreeState/StartUp.hs

+9-10
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ loadSkovData ::
181181
RuntimeParameters ->
182182
-- | Set to 'True' if a rollback occurred before loading the skov
183183
Bool ->
184-
-- | The 'SkovData' and, if the consensus is shutdown, the effective protocol update.
185-
m (SkovData pv, Maybe ProtocolUpdate)
184+
-- | The 'SkovData' and, if the consensus is shutdown, the effective protocol update and
185+
-- relative block height of the terminal block.
186+
m (SkovData pv, Maybe (ProtocolUpdate, BlockHeight))
186187
loadSkovData _genesisBlockHeight _runtimeParameters didRollback = do
187188
_persistentRoundStatus <- LowLevel.lookupCurrentRoundStatus
188189
mLatestFinEntry <- LowLevel.lookupLatestFinalizationEntry
@@ -238,10 +239,6 @@ loadSkovData _genesisBlockHeight _runtimeParameters didRollback = do
238239
-- seedstate, the consensus is shutdown, so we determine the shutdown trigger block, which
239240
-- will be the terminal block. The terminal block may differ from the last finalized block.
240241
let consensusIsShutdown = lastFinSeedState ^. shutdownTriggered
241-
_terminalBlock <-
242-
if consensusIsShutdown
243-
then Present <$> findShutdownTriggerBlock lastFinBlock
244-
else return Absent
245242
(currentEpoch, lastEpochFinEntry) <-
246243
if lastFinSeedState ^. epochTransitionTriggered
247244
&& not consensusIsShutdown
@@ -288,16 +285,18 @@ loadSkovData _genesisBlockHeight _runtimeParameters didRollback = do
288285
_focusBlock = lastFinBlock
289286
}
290287
let _statistics = Stats.initialConsensusStatistics
291-
protocolUpdate <-
288+
(_terminalBlock, protocolUpdate) <-
292289
if consensusIsShutdown
293290
then do
294291
getProtocolUpdateStatus (bpState lastFinBlock) >>= \case
295-
ProtocolUpdated pu -> return $ Just pu
292+
ProtocolUpdated pu -> do
293+
termBlock <- findShutdownTriggerBlock lastFinBlock
294+
return (Present termBlock, Just (pu, blockHeight termBlock))
296295
PendingProtocolUpdates{} ->
297296
throwM . TreeStateInvariantViolation $
298297
"Consensus is shut down, but no effective protocol update was present \
299298
\in the last finalized block."
300-
else return Nothing
299+
else return (Absent, Nothing)
301300
return (SkovData{..}, protocolUpdate)
302301

303302
-- | Load the certified blocks from the low-level database into the tree state.
@@ -454,7 +453,7 @@ loadCertifiedBlocks = do
454453
Nothing -> liftIO DiffMap.newEmptyReference
455454
Just diffMapReference -> return diffMapReference
456455
newDifferenceMap <- reconstructAccountDifferenceMap (bpState blockPointer) parentDiffMapReference accountsToInsert
457-
-- append to the accummulator with this new difference map reference
456+
-- append to the accumulator with this new difference map reference
458457
let loadedBlocks' = HM.insert (getHash storedBlock) newDifferenceMap loadedBlocks
459458

460459
cacheBlockState (bpState blockPointer)

concordium-consensus/src/Concordium/MultiVersion.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ startupSkov genesis = do
13661366
activateConfiguration (newVersionV1 newEConfig)
13671367
liftSkovV1Update newEConfig checkForProtocolUpdateV1
13681368
case esProtocolUpdate of
1369-
Just protocolUpdate
1369+
Just (protocolUpdate, terminalBlockHeight)
13701370
| Right upd <- ProtocolUpdateV1.checkUpdate @pv protocolUpdate -> do
13711371
let nextSPV = ProtocolUpdateV1.updateNextProtocolVersion upd
13721372
-- A protocol update has occurred for this configuration, so
@@ -1377,7 +1377,7 @@ startupSkov genesis = do
13771377
nextSPV
13781378
activateThis
13791379
(genIndex + 1)
1380-
(localToAbsoluteBlockHeight genHeight esLastFinalizedHeight + 1)
1380+
(localToAbsoluteBlockHeight genHeight terminalBlockHeight + 1)
13811381
_ -> do
13821382
-- This is still the current configuration (i.e. no protocol update
13831383
-- has occurred, or the protocol update is not supported), so

concordium-consensus/src/Concordium/Queries.hs

+10-3
Original file line numberDiff line numberDiff line change
@@ -754,13 +754,20 @@ getBlockInfo =
754754
-- The block is the genesis block of a non-initial chain, so we use the
755755
-- hash of the last finalized block of the previous chain as the parent block.
756756
-- Since the genesis index is non-zero, we know that there will be a previous
757-
-- chain, and that it will be shut down with the last finalized block being
758-
-- terminal.
757+
-- chain, and that it will be shut down. For consensus version 0, the last
758+
-- finalized block will be the terminal block. For consensus version 1, we
759+
-- explicitly get the terminal block (which may not be the last finalized
760+
-- block).
761+
let errorNoTerminal = error "Updated consensus is missing terminal block."
759762
lift $
760763
liftSkovQueryAtGenesisIndex
761764
(biGenesisIndex - 1)
762765
(getHash <$> lastFinalizedBlock)
763-
(use (SkovV1.lastFinalized . to getHash))
766+
( use
767+
( SkovV1.terminalBlock
768+
. to (getHash . fromOption errorNoTerminal)
769+
)
770+
)
764771
else getHash <$> bpParent bp
765772
biBlockLastFinalized <- getHash <$> bpLastFinalized bp
766773
let biBlockHeight = localToAbsoluteBlockHeight (vc1GenesisHeight vc) (SkovV1.blockHeight bp)

concordium-node/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

concordium-node/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "concordium_node"
3-
version = "8.0.2" # must be kept in sync with 'is_compatible_version' in 'src/configuration.rs'
3+
version = "8.0.3" # must be kept in sync with 'is_compatible_version' in 'src/configuration.rs'
44
description = "Concordium Node"
55
authors = ["Concordium <developers@concordium.com>"]
66
exclude = [".gitignore", ".gitlab-ci.yml", "test/**/*","**/**/.gitignore","**/**/.gitlab-ci.yml"]

0 commit comments

Comments
 (0)