Skip to content

Commit

Permalink
Remove MonadRandom from consensus
Browse files Browse the repository at this point in the history
Fixes #2036.

Update the dependencies on `cardano-base` and `cardano-ledger-specs`, bringing
in IntersectMBO/cardano-base#139 and
IntersectMBO/cardano-ledger#1621, which
remove `MonadRandom` from the VRF Crypto class.

This means we can remove `MonadRandom` from `checkIsLeader`.

The implementation code no longer mentions `MonadRandom`, but the `TxGen` used
in the ThreadNet tests still does.
  • Loading branch information
mrBliss committed Jul 8, 2020
1 parent 374e544 commit c0d6911
Show file tree
Hide file tree
Showing 56 changed files with 147 additions and 185 deletions.
67 changes: 37 additions & 30 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -135,106 +135,113 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 5e0b8bc8c7862be12da6989440f8644ba7c1e1cf
--sha256: 06i2wpla5hp4vz873zqy1f2p0pmbhnkmabw3ibhcf476qh3vfa3p
tag: 0b84523e48f678bb267c3f1db5af91a8fc49c593
--sha256: 01yzpwy9msnr6dr0wyi78r4g0h777mkz0zs2wq0wnkav1lm5ph3r
subdir: binary

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 5e0b8bc8c7862be12da6989440f8644ba7c1e1cf
--sha256: 06i2wpla5hp4vz873zqy1f2p0pmbhnkmabw3ibhcf476qh3vfa3p
tag: 0b84523e48f678bb267c3f1db5af91a8fc49c593
--sha256: 01yzpwy9msnr6dr0wyi78r4g0h777mkz0zs2wq0wnkav1lm5ph3r
subdir: binary/test

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 5e0b8bc8c7862be12da6989440f8644ba7c1e1cf
--sha256: 06i2wpla5hp4vz873zqy1f2p0pmbhnkmabw3ibhcf476qh3vfa3p
tag: 0b84523e48f678bb267c3f1db5af91a8fc49c593
--sha256: 01yzpwy9msnr6dr0wyi78r4g0h777mkz0zs2wq0wnkav1lm5ph3r
subdir: cardano-crypto-class

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 5e0b8bc8c7862be12da6989440f8644ba7c1e1cf
--sha256: 06i2wpla5hp4vz873zqy1f2p0pmbhnkmabw3ibhcf476qh3vfa3p
tag: 0b84523e48f678bb267c3f1db5af91a8fc49c593
--sha256: 01yzpwy9msnr6dr0wyi78r4g0h777mkz0zs2wq0wnkav1lm5ph3r
subdir: cardano-crypto-praos

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 5e0b8bc8c7862be12da6989440f8644ba7c1e1cf
--sha256: 06i2wpla5hp4vz873zqy1f2p0pmbhnkmabw3ibhcf476qh3vfa3p
tag: 0b84523e48f678bb267c3f1db5af91a8fc49c593
--sha256: 01yzpwy9msnr6dr0wyi78r4g0h777mkz0zs2wq0wnkav1lm5ph3r
subdir: slotting

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: semantics/executable-spec

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: semantics/small-steps-test

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: byron/ledger/executable-spec

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: byron/ledger/impl

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: byron/ledger/impl/test

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: byron/crypto

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: byron/crypto/test

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: byron/chain/executable-spec

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: shelley/chain-and-ledger/dependencies/non-integer

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: shelley/chain-and-ledger/executable-spec

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 12b13f390d64df6af6054b0d33bb3767756da041
--sha256: 0v9zj73sz984xpg0azckfpibkllribbzksg18isx2m7w58bya77m
tag: 515b73783ada98a7ede4b6b67ef39f0959a89571
--sha256: 128m3ir32013id671pmymdady30sl4phfp09bjvcdb25sm2hzqdb
subdir: shelley/chain-and-ledger/executable-spec/test

source-repository-package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ test-suite test
, byron-spec-chain
, byron-spec-ledger
, small-steps
, small-steps-test

, ouroboros-network
, ouroboros-consensus
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
��D��
��D&؏o
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions ouroboros-consensus-cardano/test/golden/disk/AnnTip_Shelley
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
��D��
�
��D&؏o�
Binary file modified ouroboros-consensus-cardano/test/golden/disk/Block_Shelley
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
D��
D&؏o
Binary file modified ouroboros-consensus-cardano/test/golden/disk/LedgerState_Shelley
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
�D��
�D&؏o
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions ouroboros-consensus-shelley-test/test/golden/disk/AnnTip
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
�D��
�
�D&؏o�
Binary file modified ouroboros-consensus-shelley-test/test/golden/disk/Block
Binary file not shown.
Binary file modified ouroboros-consensus-shelley-test/test/golden/disk/ChainDepState
Binary file not shown.
Binary file modified ouroboros-consensus-shelley-test/test/golden/disk/ExtLedgerState
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
D��
D&؏o
Binary file modified ouroboros-consensus-shelley-test/test/golden/disk/LedgerState
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ library
, cardano-slotting
, cborg >=0.2.2 && <0.3
, containers >=0.5 && <0.7
, cryptonite >=0.25 && <0.26
, mtl >=2.2 && <2.3
, serialise >=0.2 && <0.3
, transformers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,9 @@ instance TPraosCrypto c => ConsensusProtocol (TPraos c) where

protocolSecurityParam = tpraosSecurityParam . tpraosParams

checkIsLeader cfg@TPraosConfig{..} icn hk (Ticked slot lv) (Ticked _ cs) = do
rho <- VRF.evalCertified () rho' tpraosIsCoreNodeSignKeyVRF
y <- VRF.evalCertified () y' tpraosIsCoreNodeSignKeyVRF
checkIsLeader cfg@TPraosConfig{..} icn hk (Ticked slot lv) (Ticked _ cs) =
-- First, check whether we're in the overlay schedule
return $ case Map.lookup slot (SL.lvOverlaySched lv) of
case Map.lookup slot (SL.lvOverlaySched lv) of
Nothing
| meetsLeaderThreshold cfg lv (SL.coerceKeyRole vkhCold) y
-> case checkKesPeriod wallclockPeriod hk of
Expand Down Expand Up @@ -436,6 +434,9 @@ instance TPraosCrypto c => ConsensusProtocol (TPraos c) where
rho' = SL.mkSeed SL.seedEta slot eta0
y' = SL.mkSeed SL.seedL slot eta0

rho = VRF.evalCertified () rho' tpraosIsCoreNodeSignKeyVRF
y = VRF.evalCertified () y' tpraosIsCoreNodeSignKeyVRF

tickEta0 (STS.TicknState _ x) = x

-- The current wallclock KES period
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,21 @@ instance PraosCrypto c => ConsensusProtocol (Praos c) where
type CanBeLeader (Praos c) = CoreNodeId
type CannotLead (Praos c) = Void

checkIsLeader cfg@PraosConfig{..} nid _cis (Ticked slot _u) (Ticked _ cds) = do
rho <- evalCertified () rho' praosSignKeyVRF
y <- evalCertified () y' praosSignKeyVRF
return $ if fromIntegral (getOutputVRFNatural (certifiedOutput y)) < t
then IsLeader PraosProof {
praosProofRho = rho
, praosProofY = y
, praosLeader = nid
, praosProofSlot = slot
}
else NotLeader
checkIsLeader cfg@PraosConfig{..} nid _cis (Ticked slot _u) (Ticked _ cds) =
if fromIntegral (getOutputVRFNatural (certifiedOutput y)) < t
then IsLeader PraosProof {
praosProofRho = rho
, praosProofY = y
, praosLeader = nid
, praosProofSlot = slot
}
else NotLeader
where
(rho', y', t) = rhoYT cfg cds slot nid

rho = evalCertified () rho' praosSignKeyVRF
y = evalCertified () y' praosSignKeyVRF

-- Unlike the real Praos (which must switch nonce at the right time), there
-- is nothing to do for the mock Praos implementation in 'tickChainDepState'
-- since we have the /full/ history, and pick the right nonce from that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ library
Test.ThreadNet.Rekeying
Test.ThreadNet.TxGen
Test.ThreadNet.Util
Test.ThreadNet.Util.BlockProduction
Test.ThreadNet.Util.Expectations
Test.ThreadNet.Util.HasCreator
Test.ThreadNet.Util.NodeJoinPlan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import Ouroboros.Consensus.Mempool
import qualified Ouroboros.Consensus.MiniProtocol.BlockFetch.Server as BFServer
import qualified Ouroboros.Consensus.MiniProtocol.ChainSync.Client as CSClient
import qualified Ouroboros.Consensus.Network.NodeToNode as NTN
import Ouroboros.Consensus.Node.BlockProduction
import Ouroboros.Consensus.Node.NetworkProtocolVersion
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Node.Run
Expand All @@ -109,7 +110,6 @@ import qualified Ouroboros.Consensus.Storage.LedgerDB.InMemory as LgrDB
import qualified Ouroboros.Consensus.Storage.VolatileDB as VolDB

import Test.ThreadNet.TxGen
import Test.ThreadNet.Util.BlockProduction
import Test.ThreadNet.Util.NodeJoinPlan
import Test.ThreadNet.Util.NodeRestarts
import Test.ThreadNet.Util.NodeTopology
Expand Down Expand Up @@ -764,7 +764,7 @@ runThreadNetwork systemTime ThreadNetworkArgs
Nothing -> error "runThreadNetwork: cannot produce blocks"
Just creds -> creds

blockProduction <- blockProductionIOLike pInfoConfig canBeLeader maintainForgeState varRNG $
blockProduction <- customForgeBlockProduction pInfoConfig canBeLeader maintainForgeState $
\forgeState currentBno tickedLdgSt txs prf -> do
let currentSlot = tickedSlotNo tickedLdgSt
let currentEpoch = HFF.futureSlotToEpoch future currentSlot
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions ouroboros-consensus/ouroboros-consensus.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ library
, cborg >=0.2.2 && <0.3
, containers >=0.5 && <0.7
, contra-tracer
, cryptonite >=0.25 && <0.26
, deepseq
, digest
, directory >=1.3 && <1.4
Expand Down Expand Up @@ -397,7 +396,6 @@ test-suite test-consensus
Test.ThreadNet.Rekeying
Test.ThreadNet.TxGen
Test.ThreadNet.Util
Test.ThreadNet.Util.BlockProduction
Test.ThreadNet.Util.Expectations
Test.ThreadNet.Util.HasCreator
Test.ThreadNet.Util.NodeJoinPlan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ instance SingleEraBlock b => ConsensusProtocol (DegenForkProtocol b) where
chainIndepState
tickedLedgerView
tickedChainDepState =
castLeaderCheck <$>
castLeaderCheck $
checkIsLeader
cfg
canBeLeader
Expand Down
Loading

0 comments on commit c0d6911

Please sign in to comment.