Skip to content
Permalink
Browse files

WIP: Demo PBFT with real ledger

This also upgrades to the latest -ledger, which involved quite a few changes
  • Loading branch information...
edsko committed May 15, 2019
1 parent 0f55b87 commit e152b4e1931f6fe99efd1c5ce2f7d21016df58ff
@@ -24,47 +24,90 @@ source-repository-package
type: git
location: https://github.com/input-output-hk/iohk-monitoring-framework
subdir: iohk-monitoring
tag: 8614c66d9f13ad7bd68975700651a720a78d620e
tag: 00413dcad916a41cf392437199cfba7a2e2c76d7

source-repository-package
type: git
location: https://github.com/input-output-hk/iohk-monitoring-framework
subdir: contra-tracer
tag: 8614c66d9f13ad7bd68975700651a720a78d620e
tag: 00413dcad916a41cf392437199cfba7a2e2c76d7

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 0d255c9b69e2fb76699e51d8474039f7ad9e25a9
tag: b676160954cea07d4378ccca870a61242bc188a2
subdir: binary

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: b676160954cea07d4378ccca870a61242bc188a2
subdir: binary/test

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: 7d958e16f3ba319234817106d8303d22cb93ec42
tag: 387b54646ababbd91e26b9d7b0d33e874dbd96cb
subdir: .

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: 7d958e16f3ba319234817106d8303d22cb93ec42
tag: 387b54646ababbd91e26b9d7b0d33e874dbd96cb
subdir: crypto

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: 387b54646ababbd91e26b9d7b0d33e874dbd96cb
subdir: test

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: 387b54646ababbd91e26b9d7b0d33e874dbd96cb
subdir: crypto/test

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-prelude
tag: e1fb84b1a955b6e3e3e53d9022e8bc0f927417a2
tag: b25eed0ab3b6da51bc10970759d491331e56c822
subdir: .

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-prelude
tag: d8091767addc1a51e11cb2f04392e4eb40e39b18
subdir: test

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-crypto
tag: 3c707936ba0a665375acf5bd240dc4b6eaa6c0bc

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-shell
tag: 4be5660c721cae4b001187ec614ef5cf4fad8fc7

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-sl-x509
tag: e8bfc1294e088f90e5ae0b4aedbc82ee46ac5ee4

source-repository-package
type: git
location: https://github.com/well-typed/cborg
tag: 80fbe0ee5e67a5622e2cb9eaa9d8594a2214322d
subdir: cborg

source-repository-package
type: git
location: https://github.com/joelwilliamson/bimap
tag: 997fbb38b08dec14d225d064dac05b0a85f4ceae

package contra-tracer
tests: False

constraints:
ip < 1.5
@@ -2,6 +2,8 @@ module CLI (
CLI(..)
, TopologyInfo(..)
, Command(..)
, Protocol(..)
, fromProtocol
, parseCLI
-- * Handy re-exports
, execParser
@@ -25,16 +27,43 @@ import Ouroboros.Consensus.Util
import Mock.TxSubmission (command', parseMockTx)
import Topology (TopologyInfo (..))

-- Needed to read genesis config
import qualified Cardano.Chain.Genesis as Genesis
import Cardano.Crypto.ProtocolMagic (RequiresNetworkMagic (..))
import Cardano.Prelude (identity, panic, runExceptT)
import Formatting (build, sformat)


data CLI = CLI {
systemStart :: SystemStart
, slotDuration :: SlotLength
, command :: Command
}

data Command =
SimpleNode TopologyInfo (Some DemoProtocol)
SimpleNode TopologyInfo Protocol
| TxSubmitter TopologyInfo Mock.Tx

data Protocol =
BFT
| Praos
| MockPBFT
| RealPBFT FilePath

fromProtocol :: Protocol -> IO (Some DemoProtocol)
fromProtocol BFT =
return $ Some $ DemoBFT defaultSecurityParam
fromProtocol Praos =
return $ Some $ DemoPraos defaultDemoPraosParams
fromProtocol MockPBFT =
return $ Some $ DemoMockPBFT (defaultDemoPBftParams genesisConfig)
where
-- TODO: This is nasty
genesisConfig = error "genesis config not needed when using mock ledger"
fromProtocol (RealPBFT fp) = do
genesisConfig <- readMainetCfg
return $ Some $ DemoMockPBFT (defaultDemoPBftParams genesisConfig)

parseCLI :: Parser CLI
parseCLI = CLI
<$> parseSystemStart
@@ -57,20 +86,27 @@ parseSlotDuration = option (mkSlotLength <$> auto) $ mconcat [
mkSlotLength :: Integer -> SlotLength
mkSlotLength = slotLengthFromMillisec . (* 1000)

parseProtocol :: Parser (Some DemoProtocol)
parseProtocol :: Parser Protocol
parseProtocol = asum [
flag' (Some (DemoBFT defaultSecurityParam)) $ mconcat [
flag' BFT $ mconcat [
long "bft"
, help "Use the BFT consensus algorithm"
]
, flag' (Some (DemoPraos defaultDemoPraosParams)) $ mconcat [
, flag' Praos $ mconcat [
long "praos"
, help "Use the Praos consensus algorithm"
]
, flag' (Some (DemoPBFT defaultDemoPBftParams)) $ mconcat [
long "pbft"
, help "Use the Permissive BFT consensus algorithm"
, flag' MockPBFT $ mconcat [
long "mock-pbft"
, help "Use the Permissive BFT consensus algorithm using a mock ledger"
]
, (flag' RealPBFT $ mconcat [
long "real-pbft"
, help "Use the Permissive BFT consensus algorithm using the real ledger"
]) <*> (argument str $ mconcat [
help "Path to JSON file with the genesis configuration"
, metavar "FILE"
])
]

parseCommand :: Parser Command
@@ -101,3 +137,18 @@ parseTopologyFile =

parseTopologyInfo :: Parser TopologyInfo
parseTopologyInfo = TopologyInfo <$> parseNodeId <*> parseTopologyFile

{-------------------------------------------------------------------------------
Read genesis
Copied from Test.Cardano.Chain.Config (not exported)
TODO: Export it (or use it from someplace else)
-------------------------------------------------------------------------------}

readMainetCfg :: IO Genesis.Config
readMainetCfg =
either
(panic . sformat build)
identity
<$> runExceptT
(Genesis.mkConfigFromFile RequiresNoMagic "mainnet-genesis.json" Nothing)
@@ -57,10 +57,10 @@ runNode cli@CLI{..} = do
case command of
TxSubmitter topology tx ->
handleTxSubmission topology tx
SimpleNode topology protocol ->
case protocol of
Some p -> case demoProtocolConstraints p of
Dict -> handleSimpleNode p cli topology
SimpleNode topology protocol -> do
Some p <- fromProtocol protocol
case demoProtocolConstraints p of
Dict -> handleSimpleNode p cli topology

-- | Sets up a simple node, which will run the chain sync protocol and block
-- fetch protocol, and, if core, will also look at the mempool when trying to
@@ -117,6 +117,7 @@ handleSimpleNode p CLI{..} (TopologyInfo myNodeId topologyFile) = do
prevHash
txs
proof

, produceDRG = drgNew
}

@@ -160,6 +160,7 @@ library
contra-tracer,

base16-bytestring >=0.1 && <0.2,
bimap >=0.3 && <0.4,
bytestring >=0.10 && <0.11,
cardano-binary,
cardano-crypto-wrapper,
@@ -207,6 +208,10 @@ executable demo-playground
ouroboros-network,
ouroboros-consensus,
io-sim-classes,
cardano-crypto-wrapper,
cardano-ledger,
cardano-ledger-test,
cardano-prelude,

aeson,
async,
@@ -215,6 +220,7 @@ executable demo-playground
containers,
cryptonite,
directory,
formatting,
mtl,
optparse-applicative,
serialise,
@@ -1,12 +1,15 @@
-- | Digital signatures.
module Ouroboros.Consensus.Crypto.DSIGN
( module Class
, module Cardano
, module Ed448
, module Mock
, module RSAPSS
) where

import Ouroboros.Consensus.Crypto.DSIGN.Class as Class

import Ouroboros.Consensus.Crypto.DSIGN.Cardano as Cardano
import Ouroboros.Consensus.Crypto.DSIGN.Ed448 as Ed448
import Ouroboros.Consensus.Crypto.DSIGN.Mock as Mock
import Ouroboros.Consensus.Crypto.DSIGN.RSAPSS as RSAPSS
@@ -15,19 +15,10 @@ module Ouroboros.Consensus.Crypto.DSIGN.Cardano

import Cardano.Binary
import qualified Cardano.Chain.Block as CC.Block
import qualified Cardano.Chain.Txp as CC.Txp
import Cardano.Crypto
( ProtocolMagicId
, ProxyVerificationKey
, SignTag(..)
, PublicKey
, Signature
, SecretKey
, keyGen
, toPublic
, signEncoded
, verifySignature
)
import qualified Cardano.Chain.UTxO as CC.UTxO
import Cardano.Crypto (ProtocolMagicId, ProxyVerificationKey,
SignTag (..), Signature, SigningKey, VerificationKey,
keyGen, signEncoded, toVerification, verifySignature)
import Data.Coerce (coerce)
import Data.Function (on)
import GHC.Generics (Generic)
@@ -41,7 +32,7 @@ pm = undefined
class HasSignTag a where
signTag :: a -> SignTag

instance HasSignTag CC.Txp.TxSigData where
instance HasSignTag CC.UTxO.TxSigData where
signTag = const SignTx

instance HasSignTag CC.Block.ToSign where
@@ -54,10 +45,10 @@ data CardanoDSIGN

instance DSIGNAlgorithm CardanoDSIGN where

newtype VerKeyDSIGN CardanoDSIGN = VerKeyCardanoDSIGN PublicKey
newtype VerKeyDSIGN CardanoDSIGN = VerKeyCardanoDSIGN VerificationKey
deriving (Show, Eq, Generic)

newtype SignKeyDSIGN CardanoDSIGN = SignKeyCardanoDSIGN SecretKey
newtype SignKeyDSIGN CardanoDSIGN = SignKeyCardanoDSIGN SigningKey
deriving (Show, Eq, Generic)

newtype SigDSIGN CardanoDSIGN = SigCardanoDSIGN (Signature Encoding)
@@ -76,7 +67,7 @@ instance DSIGNAlgorithm CardanoDSIGN where

genKeyDSIGN = SignKeyCardanoDSIGN . snd <$> keyGen

deriveVerKeyDSIGN (SignKeyCardanoDSIGN sk) = VerKeyCardanoDSIGN $ toPublic sk
deriveVerKeyDSIGN (SignKeyCardanoDSIGN sk) = VerKeyCardanoDSIGN $ toVerification sk

signDSIGN toEnc a (SignKeyCardanoDSIGN sk) = do
return $ SigCardanoDSIGN $ signEncoded pm (signTag a) sk (toEnc a)
Oops, something went wrong.

0 comments on commit e152b4e

Please sign in to comment.
You can’t perform that action at this time.