Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit de0b762

Browse files
authored
Merge pull request #3263 from input-output-hk/jordan/CDEC-403
[CDEC-403] Remove partial field accessors from `HandlerSpec`, `InductiveValidationError`, `InvariantViolation` and `ValidationResult` data types.
2 parents efb498f + 0d5b014 commit de0b762

File tree

4 files changed

+108
-116
lines changed

4 files changed

+108
-116
lines changed

infra/src/Pos/Infra/Communication/Types/Protocol.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ buildBS :: ByteString -> B.Builder
186186
buildBS = bprint base16F
187187

188188
data HandlerSpec
189-
= ConvHandler { hsReplyType :: MessageCode }
190-
| UnknownHandler Word8 ByteString
189+
-- | ConvHandler hsReplyType
190+
= ConvHandler !MessageCode
191+
| UnknownHandler !Word8 !ByteString
191192
deriving (Show, Generic, Eq)
192193

193194
instance Bi HandlerSpec where

wallet-new/test/unit/Test/Spec/Translation.hs

+21-15
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,17 @@ data ValidationResult h a =
292292
ExpectedValid
293293

294294
-- | We expected the chain to be invalid; DSL and Cardano both agree
295-
| ExpectedInvalid {
296-
validationErrorDsl :: Text
297-
, validationErrorCardano :: Cardano.VerifyBlocksException
298-
}
295+
-- ExpectedInvalid
296+
-- validationErrorDsl
297+
-- validationErrorCardano
298+
| ExpectedInvalid !Text !Cardano.VerifyBlocksException
299299

300300
-- | Variation on 'ExpectedInvalid', where we cannot even /construct/
301301
-- the Cardano chain, much less validate it.
302-
| ExpectedInvalid' {
303-
validationErrorDsl :: Text
304-
, validationErrorInt :: IntException
305-
}
302+
-- ExpectedInvalid
303+
-- validationErrorDsl
304+
-- validationErrorInt
305+
| ExpectedInvalid' !Text !IntException
306306

307307
-- | Disagreement between the DSL and Cardano
308308
--
@@ -315,10 +315,10 @@ data ValidationResult h a =
315315
--
316316
-- We record the error message from Cardano, if Cardano thought the chain
317317
-- was invalid, as well as the ledger that causes the problem.
318-
| Disagreement {
319-
validationLedger :: Ledger h a
320-
, validationDisagreement :: Disagreement h a
321-
}
318+
-- Disagreement
319+
-- validationLedger
320+
-- validationDisagreement
321+
| Disagreement !(Ledger h a) !(Disagreement h a)
322322

323323
-- | Disagreement between Cardano and the DSL
324324
--
@@ -357,23 +357,29 @@ expectInvalid _otherwise = False
357357

358358
instance (Hash h a, Buildable a) => Buildable (ValidationResult h a) where
359359
build ExpectedValid = "ExpectedValid"
360-
build ExpectedInvalid{..} = bprint
360+
build (ExpectedInvalid
361+
validationErrorDsl
362+
validationErrorCardano) = bprint
361363
( "ExpectedInvalid"
362364
% ", errorDsl: " % build
363365
% ", errorCardano: " % build
364366
% "}"
365367
)
366368
validationErrorDsl
367369
validationErrorCardano
368-
build ExpectedInvalid'{..} = bprint
370+
build (ExpectedInvalid'
371+
validationErrorDsl
372+
validationErrorInt) = bprint
369373
( "ExpectedInvalid'"
370374
% ", errorDsl: " % build
371375
% ", errorInt: " % build
372376
% "}"
373377
)
374378
validationErrorDsl
375379
validationErrorInt
376-
build Disagreement{..} = bprint
380+
build (Disagreement
381+
validationLedger
382+
validationDisagreement) = bprint
377383
( "Disagreement "
378384
% "{ ledger: " % build
379385
% ", disagreement: " % build

wallet-new/test/unit/Wallet/Inductive/Invariants.hs

+22-42
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,12 @@ invariant name e p = void . interpret notChecked ((:[]) . e) p'
5656
notChecked :: History h a
5757
-> InvalidInput h a
5858
-> InvariantViolation h a
59-
notChecked history reason = InvariantNotChecked {
60-
invariantNotCheckedName = name
61-
, invariantNotCheckedReason = reason
62-
, invariantNotCheckedEvents = history
63-
}
59+
notChecked history reason = InvariantNotChecked name reason history
6460

6561
violation :: History h a
6662
-> InvariantViolationEvidence
6763
-> InvariantViolation h a
68-
violation history ev = InvariantViolation {
69-
invariantViolationName = name
70-
, invariantViolationEvidence = ev
71-
, invariantViolationEvents = history
72-
}
64+
violation history ev = InvariantViolation name ev history
7365

7466
p' :: History h a
7567
-> [Wallet h a]
@@ -82,28 +74,18 @@ invariant name e p = void . interpret notChecked ((:[]) . e) p'
8274
-- | Invariant violation
8375
data InvariantViolation h a =
8476
-- | Invariance violation
85-
InvariantViolation {
86-
-- | Name of the invariant
87-
invariantViolationName :: Text
88-
89-
-- | Evidence that the invariant was violated
90-
, invariantViolationEvidence :: InvariantViolationEvidence
91-
92-
-- | The evens that led to the error
93-
, invariantViolationEvents :: History h a
94-
}
77+
-- invariantViolationName = Name of the invariant
78+
-- invariantViolationEvidence = Evidence that the invariant
79+
-- was violated
80+
-- invariantViolationEvents = The evennts that led to the error
81+
InvariantViolation !Text !InvariantViolationEvidence !(History h a)
9582

9683
-- | The invariant was not checked because the input was invalid
97-
| InvariantNotChecked {
98-
-- | Name of the invariant
99-
invariantNotCheckedName :: Text
100-
101-
-- | Why did we not check the invariant
102-
, invariantNotCheckedReason :: InvalidInput h a
103-
104-
-- | The events that led to the error
105-
, invariantNotCheckedEvents :: History h a
106-
}
84+
-- InvariantNotChecked
85+
-- invariantNotCheckedName = Name of the invariant
86+
-- invariantNotCheckedReason = Why did we not check the invariant
87+
-- invariantNotCheckedEvents = The events that led to the error
88+
| InvariantNotChecked !Text !(InvalidInput h a) !(History h a)
10789

10890
{-------------------------------------------------------------------------------
10991
Evidence that an invariant was violated
@@ -288,20 +270,12 @@ walletEquivalent lbl e e' = void .
288270
notChecked :: History h a
289271
-> InvalidInput h a
290272
-> InvariantViolation h a
291-
notChecked history reason = InvariantNotChecked {
292-
invariantNotCheckedName = lbl
293-
, invariantNotCheckedReason = reason
294-
, invariantNotCheckedEvents = history
295-
}
273+
notChecked history reason = InvariantNotChecked lbl reason history
296274

297275
violation :: History h a
298276
-> InvariantViolationEvidence
299277
-> InvariantViolation h a
300-
violation history ev = InvariantViolation {
301-
invariantViolationName = lbl
302-
, invariantViolationEvidence = ev
303-
, invariantViolationEvents = history
304-
}
278+
violation history ev = InvariantViolation lbl ev history
305279

306280
p :: History h a
307281
-> [Wallet h a]
@@ -332,7 +306,10 @@ walletEquivalent lbl e e' = void .
332306
-------------------------------------------------------------------------------}
333307

334308
instance (Hash h a, Buildable a) => Buildable (InvariantViolation h a) where
335-
build InvariantViolation{..} = bprint
309+
build (InvariantViolation
310+
invariantViolationName
311+
invariantViolationEvidence
312+
invariantViolationEvents) = bprint
336313
( "InvariantViolation "
337314
% "{ name: " % build
338315
% ", evidence: " % build
@@ -342,7 +319,10 @@ instance (Hash h a, Buildable a) => Buildable (InvariantViolation h a) where
342319
invariantViolationName
343320
invariantViolationEvidence
344321
invariantViolationEvents
345-
build (InvariantNotChecked{..}) = bprint
322+
build (InvariantNotChecked
323+
invariantNotCheckedName
324+
invariantNotCheckedReason
325+
invariantNotCheckedEvents) = bprint
346326
( "InvariantNotChecked "
347327
% "{ name: " % build
348328
% ", reason: " % build

wallet-new/test/unit/Wallet/Inductive/Validation.hs

+62-57
Original file line numberDiff line numberDiff line change
@@ -45,55 +45,46 @@ data ValidatedInductive h a = ValidatedInductive {
4545

4646
data InductiveValidationError h a =
4747
-- | Bootstrap transaction is invalid
48-
InductiveInvalidBoot {
49-
-- | The bootstrap transaction
50-
inductiveInvalidBoot :: Transaction h a
51-
52-
-- | The error message
53-
, inductiveInvalidError :: Text
54-
}
48+
-- InductiveInvalidBoot
49+
-- inductiveInvalidBoot = The bootstrap transaction
50+
-- inductiveInvalidError = The error message
51+
InductiveInvalidBoot !(Transaction h a) !Text
5552

5653
-- | Invalid transaction in the given block
57-
| InductiveInvalidApplyBlock {
58-
-- | The events leading up to the error
59-
inductiveInvalidEvents :: OldestFirst [] (WalletEvent h a)
60-
61-
-- | The transactions in the block we successfully validated
62-
, inductiveInvalidBlockPrefix :: OldestFirst [] (Transaction h a)
63-
64-
-- | The transaction that was invalid
65-
, inductiveInvalidTransaction :: Transaction h a
66-
67-
-- | The error message
68-
, inductiveInvalidError :: Text
69-
}
54+
-- InductiveInvalidApplyBlock
55+
-- inductiveInvalidEvents = The events leading up to the error
56+
-- inductiveInvalidBlockPrefix = The transactions in the block we
57+
-- successfully validated
58+
-- inductiveInvalidTransaction = The transaction that was invalid
59+
-- inductiveInvalidError = The error message
60+
| InductiveInvalidApplyBlock
61+
!(OldestFirst [] (WalletEvent h a))
62+
!(OldestFirst [] (Transaction h a))
63+
!(Transaction h a)
64+
!Text
7065

7166
-- | A 'NewPending' call was invalid because the input was already spent
72-
| InductiveInvalidNewPendingAlreadySpent {
73-
-- | The events leading up to the error
74-
inductiveInvalidEvents :: OldestFirst [] (WalletEvent h a)
75-
76-
-- | The transaction that was invalid
77-
, inductiveInvalidTransaction :: Transaction h a
78-
79-
-- | The specific input that was not valid
80-
, inductiveInvalidInput :: Input h a
81-
}
67+
-- InductiveInvalidNewPendingAlreadySpent
68+
-- inductiveInvalidEvents = The events leading up to the error
69+
-- inductiveInvalidTransaction = The transaction that was invalid
70+
-- inductiveInvalidInput = The specific input that was not valid
71+
| InductiveInvalidNewPendingAlreadySpent
72+
!(OldestFirst [] (WalletEvent h a))
73+
!(Transaction h a)
74+
!(Input h a)
8275

8376
-- | A 'NewPending' call was invalid because the input was not @ours@
84-
| InductiveInvalidNewPendingNotOurs {
85-
-- | The events leading up to the error
86-
inductiveInvalidEvents :: OldestFirst [] (WalletEvent h a)
87-
88-
-- | The transaction that was invalid
89-
, inductiveInvalidTransaction :: Transaction h a
77+
-- InductiveInvalidNewPendingNotOurs
78+
-- inductiveInvalidEvents = The events leading up to the error
79+
-- inductiveInvalidTransaction = The transaction that was invalid
80+
-- inductiveInvalidInput = The specific input that was not valid
81+
-- inductiveInvalidAddress = The address this input belonged to
82+
| InductiveInvalidNewPendingNotOurs
83+
!(OldestFirst [] (WalletEvent h a))
84+
!(Transaction h a)
85+
!(Input h a)
86+
!a
9087

91-
-- | The specific input that was not valid
92-
, inductiveInvalidInput :: Input h a
93-
94-
-- | The address this input belonged to
95-
, inductiveInvalidAddress :: a
96-
}
9788

9889
{-------------------------------------------------------------------------------
9990
Validation proper
@@ -150,19 +141,20 @@ inductiveIsValid Inductive{..} = do
150141
forM_ (zip inputs resolved) $ \(input, mAddr) ->
151142
case mAddr of
152143
Nothing ->
153-
throwError InductiveInvalidNewPendingAlreadySpent {
154-
inductiveInvalidEvents = toOldestFirst viEvents
155-
, inductiveInvalidTransaction = t
156-
, inductiveInvalidInput = input
157-
}
144+
throwError
145+
$ InductiveInvalidNewPendingAlreadySpent
146+
(toOldestFirst viEvents)
147+
t
148+
input
158149
Just addr ->
159150
unless (addr `Set.member` inductiveOurs) $
160-
throwError InductiveInvalidNewPendingNotOurs {
161-
inductiveInvalidEvents = toOldestFirst viEvents
162-
, inductiveInvalidTransaction = t
163-
, inductiveInvalidInput = input
164-
, inductiveInvalidAddress = addr
165-
}
151+
throwError
152+
$ InductiveInvalidNewPendingNotOurs
153+
(toOldestFirst viEvents)
154+
t
155+
input
156+
addr
157+
166158
goEvents es vi
167159

168160
goBlock :: OldestFirst [] (WalletEvent h a) -- Events leading to this point (for err msgs)
@@ -201,15 +193,21 @@ inductiveIsValid Inductive{..} = do
201193
-------------------------------------------------------------------------------}
202194

203195
instance (Hash h a, Buildable a) => Buildable (InductiveValidationError h a) where
204-
build InductiveInvalidBoot{..} = bprint
196+
build (InductiveInvalidBoot
197+
inductiveInvalidBoot
198+
inductiveInvalidError) = bprint
205199
( "InductiveInvalidBoot"
206200
% "{ boot: " % build
207201
% ", error: " % build
208202
% "}"
209203
)
210204
inductiveInvalidBoot
211205
inductiveInvalidError
212-
build InductiveInvalidApplyBlock{..} = bprint
206+
build (InductiveInvalidApplyBlock
207+
inductiveInvalidEvents
208+
inductiveInvalidBlockPrefix
209+
inductiveInvalidTransaction
210+
inductiveInvalidError) = bprint
213211
( "InductiveInvalidApplyBlock"
214212
% "{ events: " % build
215213
% ", blockPrefix: " % build
@@ -220,7 +218,10 @@ instance (Hash h a, Buildable a) => Buildable (InductiveValidationError h a) whe
220218
inductiveInvalidBlockPrefix
221219
inductiveInvalidTransaction
222220
inductiveInvalidError
223-
build InductiveInvalidNewPendingAlreadySpent{..} = bprint
221+
build (InductiveInvalidNewPendingAlreadySpent
222+
inductiveInvalidEvents
223+
inductiveInvalidTransaction
224+
inductiveInvalidInput) = bprint
224225
( "InductiveInvalidNewPendingAlreadySpent"
225226
% "{ events: " % build
226227
% ", transaction: " % build
@@ -230,7 +231,11 @@ instance (Hash h a, Buildable a) => Buildable (InductiveValidationError h a) whe
230231
inductiveInvalidEvents
231232
inductiveInvalidTransaction
232233
inductiveInvalidInput
233-
build InductiveInvalidNewPendingNotOurs{..} = bprint
234+
build (InductiveInvalidNewPendingNotOurs
235+
inductiveInvalidEvents
236+
inductiveInvalidTransaction
237+
inductiveInvalidInput
238+
inductiveInvalidAddress) = bprint
234239
( "InductiveInvalidNewPendingNotOurs"
235240
% "{ events: " % build
236241
% ", transaction: " % build

0 commit comments

Comments
 (0)