Skip to content
Permalink
Browse files

Give forging the right signature

  • Loading branch information...
edsko committed May 15, 2019
1 parent a5be308 commit 7222f3c6112006dc6dd3c37b0d5e908aab38cd07
@@ -72,18 +72,6 @@ import Ouroboros.Consensus.Protocol.Praos
import Ouroboros.Consensus.Util
import Ouroboros.Consensus.Util.Condense

{-------------------------------------------------------------------------------
Support for PBFT against the real ledger
-------------------------------------------------------------------------------}

-- Extended configuration we need to run PBFT with the real ledger
data ExtRealPBFT = ExtRealPBFT {
-- | Mapping from generic keys to core node IDs
--
-- TODO: Think about delegation
pbftNodes :: Map Cardano.VerificationKey CoreNodeId
}

{-------------------------------------------------------------------------------
Abstract over the various protocols
-------------------------------------------------------------------------------}
@@ -92,7 +80,7 @@ type DemoBFT = Bft BftMockCrypto
type DemoPraos = ExtNodeConfig AddrDist (Praos PraosMockCrypto)
type DemoLeaderSchedule = WithLeaderSchedule (Praos PraosMockCrypto)
type DemoMockPBFT = ExtNodeConfig (PBftLedgerView PBftMockCrypto) (PBft PBftMockCrypto)
type DemoRealPBFT = ExtNodeConfig ExtRealPBFT (PBft PBftCardanoCrypto)
type DemoRealPBFT = ExtNodeConfig ByronDemoConfig (PBft PBftCardanoCrypto)

-- | Consensus protocol to use
data DemoProtocol p where
@@ -266,7 +254,7 @@ protocolInfo (DemoRealPBFT params)
, pbftSignKey = SignKeyCardanoDSIGN (snd (mkKey nid))
, pbftVerKey = VerKeyCardanoDSIGN (fst (mkKey nid))
}
, encNodeConfigExt = ExtRealPBFT {
, encNodeConfigExt = ByronDemoConfig {
pbftNodes = Map.fromList [
(fst (mkKey n), CoreNodeId n)
| n <- [0 .. numCoreNodes]
@@ -389,7 +377,7 @@ instance HasCreator DemoMockPBFT where
. simpleHeader

instance HasCreator DemoRealPBFT where
getCreator (EncNodeConfig _ ExtRealPBFT{..}) (ByronBlock b) =
getCreator (EncNodeConfig _ ByronDemoConfig{..}) (ByronBlock b) =
Map.findWithDefault (error "getCreator: unknown key") key pbftNodes
where
key :: Cardano.VerificationKey
@@ -424,4 +412,4 @@ instance DemoForgeBlock DemoMockPBFT where
demoForgeBlock = forgeSimpleBlock

instance DemoForgeBlock DemoRealPBFT where
demoForgeBlock = error "TODO (Nick)"
demoForgeBlock = forgeByronDemoBlock
@@ -1,8 +1,10 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

@@ -17,14 +19,15 @@ import qualified Cardano.Chain.Delegation as Delegation
import qualified Cardano.Chain.Delegation.Validation.Interface as V.Interface
import qualified Cardano.Chain.Delegation.Validation.Scheduling as V.Scheduling
import qualified Cardano.Chain.Genesis as Genesis
import qualified Cardano.Chain.Ssc as CC.Ssc
import qualified Cardano.Chain.Slotting as CC.Slot
import qualified Cardano.Chain.Ssc as CC.Ssc
import qualified Cardano.Chain.Update as CC.Update
import qualified Cardano.Chain.Update.Validation.Interface as CC.UPI
import qualified Cardano.Chain.UTxO as CC.UTxO
import qualified Cardano.Crypto as Crypto
import Cardano.Prelude (panic)
import Control.Monad.Except
import Crypto.Random (MonadRandom)
import Data.Bifunctor (bimap)
import qualified Data.Bimap as Bimap
import Data.ByteString (ByteString)
@@ -35,10 +38,13 @@ import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Sequence as Seq
import Data.Word
import Ouroboros.Consensus.Crypto.DSIGN.Cardano
import Ouroboros.Consensus.Crypto.DSIGN.Class (SignedDSIGN (..))
import Ouroboros.Consensus.Crypto.DSIGN
import Ouroboros.Consensus.Crypto.Hash
import Ouroboros.Consensus.Ledger.Abstract
import qualified Ouroboros.Consensus.Ledger.Mock as Mock
import Ouroboros.Consensus.Node (CoreNodeId)
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Protocol.ExtNodeConfig
import Ouroboros.Consensus.Protocol.PBFT
import Ouroboros.Network.Block

@@ -240,9 +246,30 @@ instance ProtocolLedgerView ByronBlock where
$ foldl (\acc x -> Bimap.insert (V.Scheduling.sdDelegator x) (V.Scheduling.sdDelegate x) acc) dsNow toApply

{-------------------------------------------------------------------------------
Forging blocks
Running Byron in the demo
-------------------------------------------------------------------------------}

-- Extended configuration we need for the demo
data ByronDemoConfig = ByronDemoConfig {
-- | Mapping from generic keys to core node IDs
--
-- TODO: Think about delegation
pbftNodes :: Map Crypto.VerificationKey CoreNodeId
}

forgeByronDemoBlock
:: ( HasNodeState_ () m -- @()@ is the @NodeState@ of PBFT
, MonadRandom m
)
=> NodeConfig (ExtNodeConfig ByronDemoConfig (PBft PBftCardanoCrypto))
-> SlotNo -- ^ Current slot
-> BlockNo -- ^ Current block number
-> ChainHash ByronHeader -- ^ Previous hash
-> Map (Hash ShortHash Mock.Tx) Mock.Tx -- ^ Txs to add in the block
-> () -- Leader proof (IsLeader)
-> m ByronBlock
forgeByronDemoBlock = undefined
{-
forgeBlockFromMock
:: forall m. NodeConfig (PBft PBftCardanoCrypto)
-> SlotNo -- ^ Current slot
@@ -294,3 +321,4 @@ forgeBlockFromMock cfg curSlot curNo prevHash txs = do
, CC.Block._msChainDiff = coerce curNo
, CC.Block._msBodyProof = proof
}
-}

0 comments on commit 7222f3c

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