Skip to content

Commit 3425d67

Browse files
committed
Super basic scaffolding
1 parent de3deab commit 3425d67

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block/SupportsPeras.hs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,68 @@ instance Condense PerasWeight where
4545
boostPerCert :: PerasWeight
4646
boostPerCert = PerasWeight 15
4747

48+
-- TODO using 'Validated' for extra safety? Or some @.Unsafe@ module?
49+
data ValidatedPerasCert blk = ValidatedPerasCert
50+
{ validatedPerasCert :: !(PerasCert blk)
51+
, validatedPerasCertBoost :: !PerasWeight
52+
}
53+
deriving stock (Show, Eq)
54+
4855
class
49-
NoThunks (PerasCert blk) =>
56+
( Show (PerasCfg blk)
57+
, NoThunks (PerasCert blk)
58+
) =>
5059
BlockSupportsPeras blk
5160
where
61+
data PerasCfg blk
62+
5263
data PerasCert blk
5364

65+
data PerasValidationErr blk
66+
5467
perasCertRound :: PerasCert blk -> PerasRoundNo
5568

5669
perasCertBoostedBlock :: PerasCert blk -> Point blk
5770

71+
validatePerasCert ::
72+
PerasCfg blk ->
73+
-- | Current round number
74+
PerasRoundNo ->
75+
PerasCert blk ->
76+
Either (PerasValidationErr blk) (ValidatedPerasCert blk)
77+
5878
-- TODO degenerate instance for all blks to get things to compile
5979
instance StandardHash blk => BlockSupportsPeras blk where
80+
newtype PerasCfg blk = PerasCfg
81+
{ -- TODO eventually, this will come from the protocol parameters from the
82+
-- ledger state
83+
perasCfgWeightBoost :: PerasWeight
84+
}
85+
deriving stock (Show, Eq)
86+
6087
data PerasCert blk = PerasCert
6188
{ pcCertRound :: PerasRoundNo
6289
, pcCertBoostedBlock :: Point blk
6390
}
6491
deriving stock (Generic, Eq, Ord, Show)
6592
deriving anyclass NoThunks
6693

94+
data PerasValidationErr blk
95+
= PerasInFuture
96+
-- current round
97+
PerasRoundNo
98+
-- round of cert
99+
PerasRoundNo
100+
67101
perasCertRound = pcCertRound
68102
perasCertBoostedBlock = pcCertBoostedBlock
103+
104+
validatePerasCert cfg curRound cert
105+
| perasCertRound cert > curRound =
106+
Left $ PerasInFuture curRound (perasCertRound cert)
107+
| otherwise =
108+
Right
109+
ValidatedPerasCert
110+
{ validatedPerasCert = cert
111+
, validatedPerasCertBoost = perasCfgWeightBoost cfg
112+
}

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/MiniProtocol/ObjectDiffusion/ObjectPool/PerasCert.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ makePerasCertPoolWriterFromChainDB ::
6868
makePerasCertPoolWriterFromChainDB chainDB =
6969
ObjectPoolWriter
7070
{ opwObjectId = perasCertRound
71-
, opwAddObjects =
72-
mapM_ $ ChainDB.addPerasCertAsync chainDB
71+
, opwAddObjects = \certs -> do
72+
-- TODO validate certificates, throwing an exception if it fails,
73+
-- disconnecting from the peer
74+
mapM_ (ChainDB.addPerasCertAsync chainDB) certs
7375
, opwHasObject = do
7476
certSnapshot <- atomically $ ChainDB.getPerasCertSnapshot chainDB
7577
pure $ PerasCertDB.containsCert certSnapshot

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/API.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ data ChainDB m blk = ChainDB
393393
-- ^ Get statistics from the LedgerDB, in particular the number of entries
394394
-- in the tables.
395395
, addPerasCertAsync :: PerasCert blk -> m (AddPerasCertPromise m)
396-
-- ^ TODO
396+
-- ^ TODO docs
397+
-- TODO take a 'ValidatedPerasCert'
397398
, getPerasWeightSnapshot :: STM m (WithFingerprint (PerasWeightSnapshot blk))
398399
-- ^ TODO
399400
, getPerasCertSnapshot :: STM m (PerasCertSnapshot blk)

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/PerasCertDB/API.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import Ouroboros.Consensus.Util.STM (WithFingerprint (..))
2222

2323
data PerasCertDB m blk = PerasCertDB
2424
{ addCert :: PerasCert blk -> m AddPerasCertResult
25+
-- ^ TODO docs
26+
-- TODO use 'ValidatedPerasCert'.
2527
, getWeightSnapshot :: STM m (WithFingerprint (PerasWeightSnapshot blk))
2628
-- ^ Return the Peras weights in order compare the current selection against
2729
-- potential candidate chains, namely the weights for blocks not older than

0 commit comments

Comments
 (0)