Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update references to cardano-ledger #666

Merged
merged 2 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .stack-to-nix.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions byron-proxy/src/exec/Validator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
{-# LANGUAGE FlexibleInstances #-}

import Codec.SerialiseTerm (CodecCBORTerm (..))
import Control.Monad.Trans.Except (runExceptT)
import Control.Tracer (Tracer (..), contramap, traceWith)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Except (runExceptT)
import Control.Monad.Trans.Reader (runReaderT)
import Control.Monad.Trans.Resource (ResourceT)
import Control.Tracer (Tracer (..), contramap, traceWith)
import Data.Text (Text, pack)
import qualified Options.Applicative as Opt

Expand All @@ -17,7 +18,8 @@ import qualified Cardano.Binary as Binary (unAnnotated)
import Cardano.Chain.Block (ChainValidationState (..))
import qualified Cardano.Chain.Block as Block
import qualified Cardano.Chain.Genesis as Genesis
import Cardano.Chain.Slotting (FlatSlotId(..))
import Cardano.Chain.Slotting (SlotNumber(..))
import Cardano.Chain.ValidationMode (fromBlockValidationMode)
import Cardano.Crypto (RequiresNetworkMagic(..), decodeAbstractHash)

import Cardano.Shell.Constants.Types (CardanoConfiguration (..), Core (..), Genesis (..))
Expand Down Expand Up @@ -51,14 +53,16 @@ clientFold
-> Client.Fold (ResourceT IO) () -- Either ChainValidationError (t, ChainValidationState))
clientFold tracer genesisConfig stopCondition cvs = Client.Fold $ pure $ Client.Continue
(\block _ -> Client.Fold $ do
outcome <- lift $ runExceptT (Block.updateChainBlockOrBoundary genesisConfig cvs (Binary.unAnnotated block))
let validationMode = fromBlockValidationMode Block.BlockValidation
outcome <- lift $ (`runReaderT` validationMode) $ runExceptT
(Block.updateChainBlockOrBoundary genesisConfig cvs (Binary.unAnnotated block))
case outcome of
Left err -> do
let msg = pack $ mconcat ["Validation failed: ", show err]
lift $ traceWith tracer msg
pure $ Client.Stop ()
Right cvs' -> do
let msg = pack $ mconcat ["Validated block at slot ", show (unFlatSlotId $ cvsLastSlot cvs')]
let msg = pack $ mconcat ["Validated block at slot ", show (unSlotNumber $ cvsLastSlot cvs')]
lift $ traceWith tracer msg
maybeStop <- lift $ stopCondition block
case maybeStop of
Expand Down
9 changes: 4 additions & 5 deletions byron-proxy/src/lib/Ouroboros/Byron/Proxy/DB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ epochFileParser epochSlots hasFS =
where
takeSlot :: Cardano.ABlockOrBoundary a -> SlotNo
takeSlot blk = case blk of
Cardano.ABOBBlock blk -> SlotNo $ Cardano.unFlatSlotId (Cardano.blockSlot blk)
Cardano.ABOBBlock blk -> SlotNo $ Cardano.unSlotNumber (Cardano.blockSlot blk)
Cardano.ABOBBoundary ebb -> SlotNo $ Cardano.boundaryEpoch ebb * Cardano.unEpochSlots epochSlots
decoder :: forall s . CBOR.Decoder s (Cardano.ABlockOrBoundary ByteSpan)
decoder = Cardano.fromCBORABlockOrBoundary epochSlots
Expand Down Expand Up @@ -282,10 +282,9 @@ dbAppendImpl err tracer epochSlots iwrite idb = DBAppend $ \blockToWrite -> do
pure slot
CardanoBlockToWrite (Annotated (Cardano.ABOBBlock blk) _) -> do
let hash = Cardano.blockHashAnnotated blk
flatSlotId = Cardano.blockSlot blk
slot = Cardano.unFlatSlotId flatSlotId
slotId = Cardano.unflattenSlotId epochSlots flatSlotId
Cardano.EpochIndex epoch = Cardano.siEpoch slotId
slotNumber = Cardano.blockSlot blk
slot = Cardano.unSlotNumber slotNumber
Cardano.EpochNumber epoch = Cardano.slotNumberEpoch epochSlots slotNumber
Index.updateTip iwrite (coerceHashToLegacy hash) (EpochNo epoch) (Index.RealSlot slot)
Immutable.appendBinaryBlob idb (SlotNo slot) builder
pure (SlotNo slot)
Expand Down
8 changes: 4 additions & 4 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: 7f5263eac329d73a0626fc0d9603dec2cd51d352
tag: e2d4663f2251ef76bae94e48fef910b8f5f867bd
subdir: cardano-ledger

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

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

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

source-repository-package
Expand Down
4 changes: 2 additions & 2 deletions nix/.stack.nix/cardano-crypto-test.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions nix/.stack.nix/cardano-crypto-wrapper.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions nix/.stack.nix/cardano-ledger-test.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions nix/.stack.nix/cardano-ledger.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ module Ouroboros.Consensus.Crypto.DSIGN.Cardano

import Cardano.Binary
import qualified Cardano.Chain.Block as CC.Block
import qualified Cardano.Chain.Delegation as CC.Delegation
import qualified Cardano.Chain.UTxO as CC.UTxO
import Cardano.Crypto (ProtocolMagicId, ProxyVerificationKey,
SignTag (..), Signature, SigningKey, VerificationKey,
keyGen, signEncoded, toVerification, verifySignature)
import Data.Constraint
import Cardano.Crypto (ProtocolMagicId, SignTag (..), Signature,
SigningKey, VerificationKey, keyGen, signEncoded,
toVerification, verifySignature)
import Data.Coerce (coerce)
import Data.Constraint
import Data.Function (on)
import Data.Proxy (Proxy (..))
import Data.Reflection (Given (..))
Expand Down Expand Up @@ -65,8 +66,8 @@ instance Given (VerKeyDSIGN CardanoDSIGN) => HasSignTag CC.Block.ToSign where
instance Given (VerKeyDSIGN CardanoDSIGN) :=> HasSignTag CC.Block.ToSign where
ins = Sub Dict

instance HasSignTag (ProxyVerificationKey w) where
signTag = const SignProxyVK
instance HasSignTag CC.Delegation.Certificate where
signTag = const SignCertificate

data CardanoDSIGN

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import qualified Data.Bimap as Bimap
import Data.Maybe (fromMaybe)

import qualified Cardano.Chain.Block as CC.Block
import qualified Cardano.Chain.Delegation as CC.Delegation
import qualified Cardano.Crypto as Cardano

import Ouroboros.Consensus.NodeId (CoreNodeId (..))
Expand Down Expand Up @@ -63,7 +64,7 @@ instance HasCreator (ByronBlock ByronDemoConfig) where
Bimap.lookup key pbftCoreNodes
where
key :: Cardano.VerificationKey
key = Cardano.pskIssuerVK
key = CC.Delegation.issuerVK
. CC.Block.delegationCertificate
. CC.Block.headerSignature
. CC.Block.blockHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ forgeBlock cfg curSlot curNo prevHash txs () = do
GenesisHash -> CC.Block.genesisHeaderHash pbftGenesisHash
BlockHash h -> h

slotId :: CC.Slot.SlotId
slotId = CC.Slot.unflattenSlotId pbftEpochSlots $ coerce curSlot
epochAndSlotCount :: CC.Slot.EpochAndSlotCount
epochAndSlotCount = CC.Slot.fromSlotNumber pbftEpochSlots $ coerce curSlot

toSign :: CC.Block.ToSign
toSign = CC.Block.ToSign {
CC.Block.tsHeaderHash = prevHeaderHash
, CC.Block.tsSlot = slotId
, CC.Block.tsSlot = epochAndSlotCount
, CC.Block.tsDifficulty = coerce curNo
, CC.Block.tsBodyProof = proof
, CC.Block.tsProtocolVersion = pbftProtocolVersion
Expand All @@ -107,8 +107,8 @@ forgeBlock cfg curSlot curNo prevHash txs () = do
where
dlgMap = CC.Genesis.unGenesisDelegation pbftGenesisDlg
VerKeyCardanoDSIGN issuer = pbftVerKey $ encNodeConfigP cfg
findDelegate = fmap (\crt -> (Crypto.pskIssuerVK crt, crt))
. find (\crt -> Crypto.pskDelegateVK crt == issuer)
findDelegate = fmap (\crt -> (CC.Delegation.issuerVK crt, crt))
. find (\crt -> CC.Delegation.delegateVK crt == issuer)
$ Map.elems dlgMap

forge :: PBftFields PBftCardanoCrypto CC.Block.ToSign
Expand Down
34 changes: 20 additions & 14 deletions ouroboros-consensus/src/Ouroboros/Consensus/Ledger/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Codec.CBOR.Encoding (Encoding)
import qualified Codec.CBOR.Read as CBOR
import qualified Codec.CBOR.Write as CBOR
import Control.Monad.Except
import Control.Monad.Reader
import qualified Data.Bimap as Bimap
import qualified Data.ByteString.Lazy as Lazy
import Data.Coerce (coerce)
Expand All @@ -61,6 +62,7 @@ import qualified Cardano.Chain.Genesis as CC.Genesis
import qualified Cardano.Chain.Slotting as CC.Slot
import qualified Cardano.Chain.Update.Validation.Interface as CC.UPI
import qualified Cardano.Chain.UTxO as CC.UTxO
import Cardano.Chain.ValidationMode (fromBlockValidationMode)
import qualified Cardano.Crypto as Crypto

import Ouroboros.Network.Block
Expand Down Expand Up @@ -187,7 +189,9 @@ instance (ByronGiven, Typeable cfg, ConfigContainsGenesis cfg)
(ByronLedgerState state snapshots) = do
CC.Block.BodyState { CC.Block.utxo, CC.Block.updateState
, CC.Block.delegationState }
<- CC.Block.updateBody bodyEnv bodyState block
<- runReaderT
(CC.Block.updateBody bodyEnv bodyState block)
(fromBlockValidationMode CC.Block.BlockValidation)
let state' = state
{ CC.Block.cvsLastSlot = CC.Block.blockSlot block
, CC.Block.cvsPreviousHash = Right $ CC.Block.blockHashAnnotated block
Expand Down Expand Up @@ -236,10 +240,9 @@ instance (ByronGiven, Typeable cfg, ConfigContainsGenesis cfg)
applyLedgerHeader (ByronLedgerConfig cfg) (ByronHeader hdr)
(ByronLedgerState state snapshots) =
mapExcept (fmap (\i -> ByronLedgerState i snapshots)) $ do
updateState <- CC.Block.updateHeader
headerEnv
(CC.Block.cvsUpdateState state)
hdr
updateState <- runReaderT
(CC.Block.updateHeader headerEnv (CC.Block.cvsUpdateState state) hdr)
(fromBlockValidationMode CC.Block.BlockValidation)
return $ state
{ CC.Block.cvsLastSlot = CC.Block.headerSlot hdr
, CC.Block.cvsPreviousHash = Right $ headerHashAnnotated hdr
Expand Down Expand Up @@ -292,7 +295,7 @@ instance (ByronGiven, Typeable cfg)
=> HeaderSupportsPBft PBftCardanoCrypto (Header (ByronBlock cfg)) where
headerPBftFields _ (ByronHeader hdr) = PBftFields {
pbftIssuer = VerKeyCardanoDSIGN
. Crypto.pskDelegateVK
. CC.Delegation.delegateVK
. CC.Block.delegationCertificate
. CC.Block.headerSignature
$ hdr
Expand Down Expand Up @@ -418,10 +421,13 @@ applyByronGenTx :: Bool -- ^ Have we verified this transaction previously?
applyByronGenTx _reapply (ByronLedgerConfig cfg) genTx st@ByronLedgerState{..} =
(\x -> st { blsCurrent = x }) <$> go genTx blsCurrent
where
validationMode = fromBlockValidationMode CC.Block.BlockValidation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I'm just hardcoding the BlockValidationMode as BlockValidation but I will utilize the reapply flag in the PR for #440.

Something like fromBlockValidationMode (if reapply then CC.Block.BlockValidation else CC.Block.NoBlockValidation).


go :: GenTx (ByronBlock cfg)
-> CC.Block.ChainValidationState
-> Except CC.UTxO.UTxOValidationError CC.Block.ChainValidationState
go (ByronTx tx) cvs = wrapCVS <$> CC.UTxO.updateUTxO env utxo [tx]
go (ByronTx tx) cvs = wrapCVS <$>
runReaderT (CC.UTxO.updateUTxO env utxo [tx]) validationMode
where
wrapCVS newUTxO = cvs { CC.Block.cvsUtxo = newUTxO }
protocolMagic = fixPM $ CC.Genesis.configProtocolMagic cfg
Expand All @@ -437,7 +443,7 @@ applyByronGenTx _reapply (ByronLedgerConfig cfg) genTx st@ByronLedgerState{..} =
Auxiliary
-------------------------------------------------------------------------------}

convertSlot :: CC.Slot.FlatSlotId -> SlotNo
convertSlot :: CC.Slot.SlotNumber -> SlotNo
convertSlot = coerce

{-------------------------------------------------------------------------------
Expand Down Expand Up @@ -470,12 +476,12 @@ instance Condense (Header (ByronBlock cfg)) where
", delegate: " <> condenseKey delegate <>
")"
where
psigPsk = CC.Block.delegationCertificate
. CC.Block.headerSignature
. unByronHeader
$ hdr
issuer = Crypto.pskIssuerVK psigPsk
delegate = Crypto.pskDelegateVK psigPsk
psigCert = CC.Block.delegationCertificate
. CC.Block.headerSignature
. unByronHeader
$ hdr
issuer = CC.Delegation.issuerVK psigCert
delegate = CC.Delegation.delegateVK psigCert

condenseKey :: Crypto.VerificationKey -> String
condenseKey = T.unpack . sformat build
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extra-deps:
- binary/test

- git: https://github.com/input-output-hk/cardano-ledger
commit: 7f5263eac329d73a0626fc0d9603dec2cd51d352
commit: e2d4663f2251ef76bae94e48fef910b8f5f867bd
subdirs:
- cardano-ledger
- cardano-ledger/test
Expand Down