@@ -33,14 +33,13 @@ import Pos.Core (epochIndexL)
33
33
import Pos.Core.Chrono (NE , NewestFirst (.. ), OldestFirst (.. ),
34
34
toNewestFirst , toOldestFirst )
35
35
import Pos.Core.Reporting (HasMisbehaviorMetrics )
36
+ import Pos.Core.Slotting (MonadSlots (getCurrentSlot ), SlotId )
36
37
import Pos.Crypto (ProtocolMagic )
37
38
import Pos.DB.Block.Logic.Internal (BypassSecurityCheck (.. ),
38
39
MonadBlockApply , MonadBlockVerify ,
39
40
MonadMempoolNormalization , applyBlocksUnsafe ,
40
41
normalizeMempool , rollbackBlocksUnsafe , toSscBlock ,
41
42
toTxpBlock , toUpdateBlock )
42
- import Pos.DB.Block.Logic.Types (VerifyBlocksContext (.. ),
43
- getVerifyBlocksContext )
44
43
import Pos.DB.Block.Lrc (LrcModeFull , lrcSingleShot )
45
44
import Pos.DB.Block.Slog.Logic (ShouldCallBListener (.. ),
46
45
mustDataBeKnown , slogVerifyBlocks )
@@ -49,7 +48,7 @@ import qualified Pos.DB.GState.Common as GS (getTip)
49
48
import Pos.DB.Ssc (sscVerifyBlocks )
50
49
import Pos.DB.Txp.Settings
51
50
(TxpGlobalSettings (TxpGlobalSettings , tgsVerifyBlocks ))
52
- import Pos.DB.Update (getAdoptedBVFull , usVerifyBlocks )
51
+ import Pos.DB.Update (getAdoptedBV , usVerifyBlocks )
53
52
import Pos.Util (neZipWith4 , spanSafe , _neHead )
54
53
import Pos.Util.Util (HasLens (.. ))
55
54
import Pos.Util.Wlog (logDebug )
@@ -77,33 +76,34 @@ verifyBlocksPrefix
77
76
( MonadBlockVerify ctx m
78
77
)
79
78
=> ProtocolMagic
80
- -> VerifyBlocksContext
79
+ -> Maybe SlotId -- ^ current slot to verify that headers are not from future slots
81
80
-> OldestFirst NE Block
82
81
-> m (Either VerifyBlocksException (OldestFirst NE Undo , PollModifier ))
83
- verifyBlocksPrefix pm ctx blocks = runExceptT $ do
82
+ verifyBlocksPrefix pm currentSlot blocks = runExceptT $ do
84
83
-- This check (about tip) is here just in case, we actually check
85
84
-- it before calling this function.
86
85
tip <- lift GS. getTip
87
86
when (tip /= blocks ^. _Wrapped . _neHead . prevBlockL) $
88
87
throwError $ VerifyBlocksError " the first block isn't based on the tip"
89
88
-- Some verifications need to know whether all data must be known.
90
89
-- We determine it here and pass to all interested components.
91
- let dataMustBeKnown = mustDataBeKnown (vbcBlockVersion ctx)
90
+ adoptedBV <- lift getAdoptedBV
91
+ let dataMustBeKnown = mustDataBeKnown adoptedBV
92
92
93
93
-- Run verification of each component.
94
94
-- 'slogVerifyBlocks' uses 'Pos.Chain.Block.Pure.verifyBlocks' which does
95
95
-- the internal consistency checks formerly done in the 'Bi' instance
96
96
-- 'decode'.
97
97
slogUndos <- withExceptT VerifyBlocksError $
98
- ExceptT $ slogVerifyBlocks pm ctx blocks
98
+ ExceptT $ slogVerifyBlocks pm currentSlot blocks
99
99
_ <- withExceptT (VerifyBlocksError . pretty) $
100
- ExceptT $ sscVerifyBlocks pm (vbcBlockVersionData ctx) ( map toSscBlock blocks)
100
+ ExceptT $ sscVerifyBlocks pm (map toSscBlock blocks)
101
101
TxpGlobalSettings {.. } <- view (lensOf @ TxpGlobalSettings )
102
102
txUndo <- withExceptT (VerifyBlocksError . pretty) $
103
103
ExceptT $ tgsVerifyBlocks dataMustBeKnown $ map toTxpBlock blocks
104
104
pskUndo <- withExceptT VerifyBlocksError $ dlgVerifyBlocks pm blocks
105
105
(pModifier, usUndos) <- withExceptT (VerifyBlocksError . pretty) $
106
- ExceptT $ usVerifyBlocks pm dataMustBeKnown (vbcBlockVersion ctx) ( map toUpdateBlock blocks)
106
+ ExceptT $ usVerifyBlocks pm dataMustBeKnown (map toUpdateBlock blocks)
107
107
108
108
-- Eventually we do a sanity check just in case and return the result.
109
109
when (length txUndo /= length pskUndo) $
@@ -137,11 +137,11 @@ verifyAndApplyBlocks
137
137
)
138
138
=> ProtocolMagic
139
139
-> TxpConfiguration
140
- -> VerifyBlocksContext
140
+ -> Maybe SlotId
141
141
-> Bool
142
142
-> OldestFirst NE Block
143
143
-> m (Either ApplyBlocksException (HeaderHash , NewestFirst [] Blund ))
144
- verifyAndApplyBlocks pm txpConfig ctx rollback blocks = runExceptT $ do
144
+ verifyAndApplyBlocks pm txpConfig curSlot rollback blocks = runExceptT $ do
145
145
tip <- lift GS. getTip
146
146
let assumedTip = blocks ^. _Wrapped . _neHead . prevBlockL
147
147
when (tip /= assumedTip) $
@@ -176,16 +176,11 @@ verifyAndApplyBlocks pm txpConfig ctx rollback blocks = runExceptT $ do
176
176
applyAMAP e (OldestFirst [] ) _ True = throwError e
177
177
applyAMAP _ (OldestFirst [] ) blunds False = (,blunds) <$> lift GS. getTip
178
178
applyAMAP e (OldestFirst (block: xs)) blunds nothingApplied = do
179
- lift (verifyBlocksPrefix pm ctx (one block)) >>= \ case
179
+ lift (verifyBlocksPrefix pm curSlot (one block)) >>= \ case
180
180
Left (ApplyBlocksVerifyFailure -> e') ->
181
181
applyAMAP e' (OldestFirst [] ) blunds nothingApplied
182
182
Right (OldestFirst (undo :| [] ), pModifier) -> do
183
- lift $ applyBlocksUnsafe pm
184
- (vbcBlockVersion ctx)
185
- (vbcBlockVersionData ctx)
186
- (ShouldCallBListener True )
187
- (one (block, undo))
188
- (Just pModifier)
183
+ lift $ applyBlocksUnsafe pm (ShouldCallBListener True ) (one (block, undo)) (Just pModifier)
189
184
applyAMAP e (OldestFirst xs) (NewestFirst $ (block, undo) : getNewestFirst blunds) False
190
185
Right _ -> error " verifyAndApplyBlocksInternal: applyAMAP: \
191
186
\verification of one block produced more than one undo"
@@ -216,7 +211,7 @@ verifyAndApplyBlocks pm txpConfig ctx rollback blocks = runExceptT $ do
216
211
<> pretty epochIndex
217
212
lift $ lrcSingleShot pm epochIndex
218
213
logDebug " Rolling: verifying"
219
- lift (verifyBlocksPrefix pm ctx prefix) >>= \ case
214
+ lift (verifyBlocksPrefix pm curSlot prefix) >>= \ case
220
215
Left (ApplyBlocksVerifyFailure -> failure)
221
216
| rollback -> failWithRollback failure blunds
222
217
| otherwise -> do
@@ -231,12 +226,7 @@ verifyAndApplyBlocks pm txpConfig ctx rollback blocks = runExceptT $ do
231
226
getOldestFirst undos
232
227
let blunds' = toNewestFirst newBlunds : blunds
233
228
logDebug " Rolling: Verification done, applying unsafe block"
234
- lift $ applyBlocksUnsafe pm
235
- (vbcBlockVersion ctx)
236
- (vbcBlockVersionData ctx)
237
- (ShouldCallBListener True )
238
- newBlunds
239
- (Just pModifier)
229
+ lift $ applyBlocksUnsafe pm (ShouldCallBListener True ) newBlunds (Just pModifier)
240
230
case getOldestFirst suffix of
241
231
[] -> (,concatNE blunds') <$> lift GS. getTip
242
232
(genesis: xs) -> do
@@ -268,8 +258,7 @@ applyBlocks pm calculateLrc pModifier blunds = do
268
258
-- caller most definitely should have computed lrc to verify
269
259
-- the sequence beforehand.
270
260
lrcSingleShot pm (prefixHead ^. epochIndexL)
271
- (bv, bvd) <- getAdoptedBVFull
272
- applyBlocksUnsafe pm bv bvd (ShouldCallBListener True ) prefix pModifier
261
+ applyBlocksUnsafe pm (ShouldCallBListener True ) prefix pModifier
273
262
case getOldestFirst suffix of
274
263
[] -> pass
275
264
(genesis: xs) -> applyBlocks pm calculateLrc pModifier (OldestFirst (genesis:| xs))
@@ -334,7 +323,7 @@ applyWithRollback pm txpConfig toRollback toApply = runExceptT $ do
334
323
applyBack $> Left (ApplyBlocksTipMismatch " applyWithRollback/apply" tip newestToRollback)
335
324
336
325
onGoodRollback = do
337
- ctx <- getVerifyBlocksContext
338
- verifyAndApplyBlocks pm txpConfig ctx True toApply >>= \ case
326
+ curSlot <- getCurrentSlot
327
+ verifyAndApplyBlocks pm txpConfig curSlot True toApply >>= \ case
339
328
Left err -> applyBack $> Left err
340
329
Right (tipHash, _) -> pure (Right tipHash)
0 commit comments