@@ -40,14 +40,14 @@ import Pos.Chain.Block.Slog (ConsensusEraLeaders (..),
40
40
import Pos.Chain.Genesis as Genesis (Config (.. ))
41
41
import Pos.Chain.Txp (TxValidationRules )
42
42
import Pos.Chain.Update (BlockVersionData (.. ), ConsensusEra (.. ))
43
- import Pos.Core (BlockCount (.. ), ChainDifficulty , EpochOrSlot ( .. ) ,
44
- HasDifficulty (.. ), HasEpochOrSlot (.. ),
43
+ import Pos.Core (AddressHash , BlockCount (.. ), ChainDifficulty ,
44
+ EpochOrSlot ( .. ), HasDifficulty (.. ), HasEpochOrSlot (.. ),
45
45
LocalSlotIndex (.. ), SlotId (.. ), addressHash ,
46
46
getSlotIndex )
47
47
import Pos.Core.Attributes (areAttributesKnown )
48
48
import Pos.Core.Chrono (NewestFirst (.. ), OldestFirst (.. ))
49
49
import Pos.Crypto (ProtocolMagic (.. ), ProtocolMagicId (.. ),
50
- getProtocolMagic )
50
+ PublicKey , getProtocolMagic )
51
51
52
52
----------------------------------------------------------------------------
53
53
-- Header
@@ -135,6 +135,7 @@ verifyHeader pm VerifyHeaderParams {..} h =
135
135
(" slots are not monotonic (" % build% " >= " % build% " )" )
136
136
oldEOS newEOS
137
137
)
138
+ checkProtocolMagicId :: [(Bool , Text )]
138
139
checkProtocolMagicId =
139
140
[ ( getProtocolMagicId pm == blockHeaderProtocolMagicId h
140
141
, sformat
@@ -143,6 +144,7 @@ verifyHeader pm VerifyHeaderParams {..} h =
143
144
(getProtocolMagic pm)
144
145
)
145
146
]
147
+ checkSize :: [(Bool , Text )]
146
148
checkSize =
147
149
case vhpMaxSize of
148
150
Nothing -> mempty
@@ -186,6 +188,7 @@ verifyHeader pm VerifyHeaderParams {..} h =
186
188
]
187
189
188
190
-- CHECK: Checks that the block leader is the expected one.
191
+ relatedToLeaders :: ConsensusEraLeaders -> [(Bool , Text )]
189
192
relatedToLeaders leaders =
190
193
case h of
191
194
BlockHeaderGenesis _ -> []
@@ -201,50 +204,62 @@ verifyHeader pm VerifyHeaderParams {..} h =
201
204
-- a slot leader schedule as it would for the `OBFT ObftStrict`
202
205
-- and `Original` cases.
203
206
ObftLenientLeaders ldrs blkSecurityParam lastBlkSlots ->
204
- [ ( (blockSlotLeader `elem` ldrs)
205
- , sformat (" slot leader who published block, " % build% " , is not an acceptable leader." )
206
- blockSlotLeader)
207
- , ( (obftLeaderCanMint blockSlotLeader blkSecurityParam lastBlkSlots)
208
- , sformat (" slot leader who published block, " % build% " , has minted too many blocks in the past " % build% " slots." )
207
+ [ ( blockSlotLeader `elem` ldrs
208
+ , sformat (" ObftLenient: slot leader who published block, " % build% " , is not an acceptable leader." )
209
209
blockSlotLeader
210
- (getBlockCount blkSecurityParam))
211
- ]
210
+ )
211
+ , ( obftLeaderCanMint blockSlotLeader blkSecurityParam lastBlkSlots
212
+ , sformat (" ObftLenient: slot leader who published block, " % build% " , has minted too many blocks (" % build % " ) in the past " % build% " slots." )
213
+ blockSlotLeader
214
+ (blocksMintedByLeaderInLastKSlots blockSlotLeader $ getOldestFirst lastBlkSlots)
215
+ (getBlockCount blkSecurityParam)
216
+ )
217
+ ]
212
218
213
219
ObftStrictLeaders ldrs ->
214
- [ ( (Just blockSlotLeader == (scheduleSlotLeader ldrs))
215
- , sformat (" slot leader from schedule, " % build% " , is different from slot leader who published block, " % build% " ." )
216
- (scheduleSlotLeader ldrs)
217
- blockSlotLeader)
218
- ]
220
+ if isNothing (scheduleSlotLeader ldrs)
221
+ then [ (isJust (scheduleSlotLeader ldrs), " ObftStrict: scheduled slot leader is missing" ) ]
222
+ else
223
+ [ ( Just blockSlotLeader == scheduleSlotLeader ldrs
224
+ , sformat (" ObftStrict: slot leader from schedule, " % build% " , is different from slot leader who published block, " % build% " ." )
225
+ (scheduleSlotLeader ldrs)
226
+ blockSlotLeader
227
+ )
228
+ ]
219
229
220
230
OriginalLeaders ldrs ->
221
- [ ( (Just blockSlotLeader == (scheduleSlotLeader ldrs))
222
- , sformat (" slot leader from schedule, " % build% " , is different from slot leader who published block, " % build% " ." )
223
- (scheduleSlotLeader ldrs)
224
- blockSlotLeader)
225
- ]
231
+ if isNothing (scheduleSlotLeader ldrs)
232
+ then [ (isJust (scheduleSlotLeader ldrs), " ObftStrict: scheduled slot leader is missing" ) ]
233
+ else
234
+ [ ( Just blockSlotLeader == scheduleSlotLeader ldrs
235
+ , sformat (" Original: slot leader from schedule, " % build% " , is different from slot leader who published block, " % build% " ." )
236
+ (scheduleSlotLeader ldrs)
237
+ blockSlotLeader
238
+ )
239
+ ]
226
240
where
227
241
-- Determine whether the leader is allowed to mint a block based on
228
242
-- whether blocksMintedByLeaderInLastKSlots <= floor (k * t)
229
- obftLeaderCanMint leaderAddrHash
230
- blkSecurityParam
231
- ( OldestFirst lastBlkSlots) =
232
- (blocksMintedByLeaderInLastKSlots leaderAddrHash lastBlkSlots)
233
- <= (leaderMintThreshold blkSecurityParam)
234
- --
243
+ obftLeaderCanMint :: AddressHash PublicKey -> BlockCount -> OldestFirst [] LastSlotInfo -> Bool
244
+ obftLeaderCanMint leaderAddrHash blkSecurityParam ( OldestFirst lastBlkSlots) =
245
+ blocksMintedByLeaderInLastKSlots leaderAddrHash lastBlkSlots
246
+ <= leaderMintThreshold blkSecurityParam
247
+
248
+ blocksMintedByLeaderInLastKSlots :: AddressHash PublicKey -> [ LastSlotInfo ] -> Int
235
249
blocksMintedByLeaderInLastKSlots leaderAddrHash lastBlkSlots =
236
250
length $
237
251
filter (\ lsi -> leaderAddrHash == (addressHash $ lsiLeaderPubkeyHash lsi))
238
252
lastBlkSlots
239
- --
253
+
240
254
leaderMintThreshold :: BlockCount -> Int
241
255
leaderMintThreshold blkSecurityParam =
242
256
let k = getBlockCount blkSecurityParam
243
257
in floor $ (fromIntegral k :: Double ) * t
244
- --
258
+
245
259
t :: Double
246
260
t = 0.22
247
261
262
+ verifyNoUnknown :: BlockHeader -> [(Bool , Text )]
248
263
verifyNoUnknown (BlockHeaderGenesis genH) =
249
264
let attrs = genH ^. gbhExtra . gehAttributes
250
265
in [ ( areAttributesKnown attrs
0 commit comments