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

Cleanup pointer serialization #4831

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion eras/allegra/impl/cddl-files/allegra.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ transaction_body = {0 : set<transaction_input>

transaction_index = uint .size 2

transaction_input = [transaction_id : $hash32, index : uint]
transaction_input = [transaction_id : $hash32, index : uint .size 2]

transaction_metadatum = {* transaction_metadatum => transaction_metadatum}
/ [* transaction_metadatum]
Expand Down
2 changes: 1 addition & 1 deletion eras/alonzo/impl/cddl-files/alonzo.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ transaction_body = {0 : set<transaction_input>

transaction_index = uint .size 2

transaction_input = [transaction_id : $hash32, index : uint]
transaction_input = [transaction_id : $hash32, index : uint .size 2]

transaction_metadatum = {* transaction_metadatum => transaction_metadatum}
/ [* transaction_metadatum]
Expand Down
Binary file modified eras/alonzo/impl/golden/translations.cbor
Binary file not shown.
2 changes: 1 addition & 1 deletion eras/babbage/impl/cddl-files/babbage.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ transaction_body = {0 : set<transaction_input>

transaction_index = uint .size 2

transaction_input = [transaction_id : $hash32, index : uint]
transaction_input = [transaction_id : $hash32, index : uint .size 2]

transaction_metadatum = {* transaction_metadatum => transaction_metadatum}
/ [* transaction_metadatum]
Expand Down
Binary file modified eras/babbage/impl/golden/translations.cbor
Binary file not shown.
4 changes: 2 additions & 2 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/Collateral.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Cardano.Ledger.UTxO (UTxO (..), coinBalance)
import Cardano.Ledger.Val ((<->))
import qualified Data.Map.Strict as Map
import Data.Maybe.Strict (StrictMaybe (..))
import Data.Word (Word16, Word64)
import Data.Word (Word16)
import Lens.Micro

-- ============================================================
Expand Down Expand Up @@ -54,4 +54,4 @@ collOuts txBody =
-- In the impossible event that there are more transaction outputs
-- in the transaction than will fit into a Word16 (which backs the TxIx),
-- we give the collateral return output an index of maxBound.
Nothing -> TxIx ((fromIntegral :: Word16 -> Word64) (maxBound :: Word16))
Nothing -> TxIx (maxBound :: Word16)
7 changes: 2 additions & 5 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/TxOut.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import Cardano.Ledger.Address (
CompactAddr,
compactAddr,
decompactAddr,
fromCborBackwardsBothAddr,
fromCborBothAddr,
fromCborRigorousBothAddr,
)
import Cardano.Ledger.Alonzo.Core
import Cardano.Ledger.Alonzo.TxBody (
Expand Down Expand Up @@ -463,10 +463,7 @@ instance (EraScript era, Val (Value era)) => DecCBOR (BabbageTxOut era) where
instance (EraScript era, Val (Value era)) => DecShareCBOR (BabbageTxOut era) where
type Share (BabbageTxOut era) = Interns (Credential 'Staking)
decShareCBOR credsInterns =
-- Even in Babbage the ledger state still contains garbage pointers that we need to
-- deal with. This will be taken care of upon entry to Conway era. After which this
-- backwards compatibility shim can be removed.
internBabbageTxOut (interns credsInterns) <$!> decodeBabbageTxOut fromCborBackwardsBothAddr
internBabbageTxOut (interns credsInterns) <$!> decodeBabbageTxOut fromCborRigorousBothAddr
{-# INLINEABLE decShareCBOR #-}

internBabbageTxOut ::
Expand Down
2 changes: 1 addition & 1 deletion eras/babbage/impl/test/GenerateGoldenFileMain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import Test.Cardano.Ledger.Babbage.Translation.TranslatableGen ()

-- | Generates golden translation file for Babbage era
main :: IO ()
main = generateGoldenFile @BabbageEra "eras/babbage/test-suite/golden/translations.cbor"
main = generateGoldenFile @BabbageEra "eras/babbage/impl/golden/translations.cbor"
1 change: 0 additions & 1 deletion eras/conway/impl/cardano-ledger-conway.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ test-suite tests
cardano-ledger-alonzo,
cardano-ledger-alonzo:testlib,
cardano-ledger-babbage,
cardano-ledger-binary,
cardano-ledger-binary:testlib,
cardano-ledger-conway,
cardano-ledger-core,
Expand Down
3 changes: 1 addition & 2 deletions eras/conway/impl/src/Cardano/Ledger/Conway/TxOut.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

module Cardano.Ledger.Conway.TxOut () where

import Cardano.Ledger.Address (addrPtrNormalize)
import Cardano.Ledger.Babbage.Core
import Cardano.Ledger.Babbage.TxOut (
BabbageTxOut (..),
Expand All @@ -37,7 +36,7 @@ instance EraTxOut ConwayEra where
mkBasicTxOut addr vl = BabbageTxOut addr vl NoDatum SNothing

upgradeTxOut (BabbageTxOut addr value d s) =
BabbageTxOut (addrPtrNormalize addr) value (translateDatum d) (upgradeScript <$> s)
BabbageTxOut addr value (translateDatum d) (upgradeScript <$> s)

addrEitherTxOutL = addrEitherBabbageTxOutL
{-# INLINE addrEitherTxOutL #-}
Expand Down
21 changes: 0 additions & 21 deletions eras/conway/impl/test/Test/Cardano/Ledger/Conway/BinarySpec.hs
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Ledger.Conway.BinarySpec (spec) where

import Cardano.Ledger.Babbage
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.Binary
import Cardano.Ledger.Conway
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Genesis
import Cardano.Ledger.Conway.Governance
import Cardano.Ledger.Credential
import Cardano.Ledger.Shelley.LedgerState
import Data.Default (def)
import qualified Data.Map.Strict as Map
import Lens.Micro
import Test.Cardano.Ledger.Binary.RoundTrip
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Conway.Arbitrary ()
Expand All @@ -38,15 +29,3 @@ spec = do
roundTripConwayCommonSpec @ConwayEra
-- ConwayGenesis only makes sense in Conway era
roundTripEraSpec @ConwayEra @ConwayGenesis
describe "Regression" $ do
prop "Drop Ptrs from Incrementasl Stake" $ \(ls :: LedgerState BabbageEra) conwayGenesis slotNo testCoin -> do
let
badPtr = Ptr slotNo (TxIx maxBound) (CertIx maxBound)
lsBabbage :: LedgerState BabbageEra
lsBabbage = ls & lsUTxOStateL . utxosStakeDistrL . ptrMapL <>~ Map.singleton badPtr testCoin
lsConway :: LedgerState ConwayEra
lsConway = translateEra' conwayGenesis lsBabbage
v = eraProtVerLow @ConwayEra
expectNoBadPtr :: LedgerState ConwayEra -> LedgerState ConwayEra -> Expectation
expectNoBadPtr x y = x `shouldBe` (y & lsUTxOStateL . utxosStakeDistrL . ptrMapL .~ mempty)
embedTripExpectation v v (mkTrip encCBOR decNoShareCBOR) expectNoBadPtr lsConway
18 changes: 9 additions & 9 deletions eras/mary/impl/cddl-files/mary.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ move_instantaneous_reward = [0 / 1, {* stake_credential => delta_coin} / coin]
;
; invalid_before:
; specifies the left (included) endpoint a.
;
;
; invalid_hereafter:
; specifies the right (excluded) endpoint b.
;
Expand Down Expand Up @@ -221,7 +221,7 @@ reward_account = h'E090000000000000000000000000000000000000000000000000000000'
; "\x00" for multisig scripts
; "\x01" for Plutus V1 scripts
; "\x02" for Plutus V2 scripts
; "\x03" for Plutus V3 scripts
; "\x03" for Plutus V3 scripts
;
script_hash = $hash28

Expand All @@ -242,7 +242,7 @@ transaction_body = {0 : set<transaction_input>

transaction_index = uint .size 2

transaction_input = [transaction_id : $hash32, index : uint]
transaction_input = [transaction_id : $hash32, index : uint .size 2]

transaction_metadatum = {* transaction_metadatum => transaction_metadatum}
/ [* transaction_metadatum]
Expand Down Expand Up @@ -271,7 +271,7 @@ transaction_witness_set = {? 0 : [* vkeywitness]
; which poses a problem for testing. We need to be able to
; generate random valid data for testing implementation of
; our encoders/decoders. Which means we cannot use the actual
; definition here and we hard code the value to 1/2
; definition here and we hard code the value to 1/2
;
unit_interval = #6.30([1, 2])

Expand Down Expand Up @@ -306,11 +306,11 @@ multi_host_name = (2, dns_name)
;
operational_cert = ($kes_vkey, uint, uint, $signature)

; pool_keyhash: operator
; coin: pledge
; coin: cost
; unit_interval: margin
; set<addr_keyhash>: pool_owners
; pool_keyhash: operator
; coin: pledge
; coin: cost
; unit_interval: margin
; set<addr_keyhash>: pool_owners
;
pool_params = (pool_keyhash
, vrf_keyhash
Expand Down
2 changes: 1 addition & 1 deletion eras/shelley/impl/cddl-files/shelley.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ transaction_body = {0 : set<transaction_input>

transaction_index = uint .size 2

transaction_input = [transaction_id : $hash32, index : uint]
transaction_input = [transaction_id : $hash32, index : uint .size 2]

transaction_metadata = {* transaction_metadatum_label => transaction_metadatum}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import Cardano.Ledger.Val (zero, (<->))
import qualified Data.ByteString.Short as SBS
import Data.Default (def)
import qualified Data.Map.Strict as Map
import Data.Word
import GHC.Stack (HasCallStack)
import Lens.Micro ((&), (.~), (^.))
import Lens.Micro.Extras (view)
Expand Down Expand Up @@ -73,7 +72,7 @@ translateCompactTxInByronToShelley ::
translateCompactTxInByronToShelley (Byron.CompactTxInUtxo compactTxId idx) =
TxIn
(translateTxIdByronToShelley (Byron.fromCompactTxId compactTxId))
(TxIx ((fromIntegral :: Word16 -> Word64) idx))
(TxIx idx)

translateUTxOByronToShelley ::
Byron.UTxO ->
Expand Down
19 changes: 10 additions & 9 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Delegs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ module Cardano.Ledger.Shelley.Rules.Delegs (
where

import Cardano.Ledger.BaseTypes (
CertIx (..),
EpochNo,
Network,
ShelleyBase,
TxIx,
TxIx (..),
invalidKey,
mkCertIxPartial,
networkId,
)
import Cardano.Ledger.Binary (
Expand All @@ -45,7 +45,7 @@ import Cardano.Ledger.Binary (
)
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential, Ptr (..))
import Cardano.Ledger.Credential (Credential, Ptr (..), SlotNo32 (..))
import Cardano.Ledger.Rules.ValidationMode (Test)
import Cardano.Ledger.Shelley.Era (ShelleyDELEGS, ShelleyEra)
import Cardano.Ledger.Shelley.LedgerState (
Expand All @@ -71,7 +71,7 @@ import Cardano.Ledger.Shelley.TxBody (
Withdrawals (..),
)
import Cardano.Ledger.Shelley.TxCert (pattern DelegStakeTxCert)
import Cardano.Ledger.Slot (SlotNo)
import Cardano.Ledger.Slot (SlotNo (..))
import Cardano.Ledger.UMap (UMElem (..), UMap (..), UView (..), fromCompact)
import qualified Cardano.Ledger.UMap as UM
import Control.DeepSeq
Expand All @@ -92,7 +92,7 @@ import qualified Data.Map.Strict as Map
import Data.Maybe.Strict (StrictMaybe (..))
import Data.Sequence (Seq (..))
import Data.Typeable (Typeable)
import Data.Word (Word8)
import Data.Word (Word16, Word32, Word64, Word8)
import GHC.Generics (Generic)
import Lens.Micro ((^.))
import NoThunks.Class (NoThunks (..))
Expand Down Expand Up @@ -237,7 +237,8 @@ delegsTransition ::
) =>
TransitionRule (ShelleyDELEGS era)
delegsTransition = do
TRC (env@(DelegsEnv slot epochNo txIx pp tx acnt), certState, certificates) <- judgmentContext
TRC (env@(DelegsEnv slot@(SlotNo slot64) epochNo txIx pp tx acnt), certState, certificates) <-
judgmentContext
network <- liftSTS $ asks networkId

case certificates of
Expand All @@ -255,9 +256,9 @@ delegsTransition = do
DelegStakeTxCert _ targetPool ->
validateStakePoolDelegateeRegistered (certPState certState') targetPool
_ -> pure ()
-- It is impossible to have 65535 number of certificates in a
-- transaction, therefore partial function is justified.
let ptr = Ptr slot txIx (mkCertIxPartial $ toInteger $ length gamma)
-- It is impossible to have 65535 number of certificates in a transaction.
let certIx = CertIx (fromIntegral @Int @Word16 $ length gamma)
ptr = Ptr (SlotNo32 (fromIntegral @Word64 @Word32 slot64)) txIx certIx
trans @(EraRule "DELPL" era) $
TRC (DelplEnv slot epochNo ptr pp acnt, certState', txCert)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ transaction_body =
]

transaction_input :: Rule
transaction_input = "transaction_input" =:= arr ["transaction_id" ==> hash32, "index" ==> VUInt]
transaction_input =
"transaction_input"
=:= arr
[ "transaction_id" ==> hash32
, "index" ==> VUInt `sized` (2 :: Word64)
]

transaction_output :: Rule
transaction_output = "transaction_output" =:= arr [a address, "amount" ==> coin]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import Cardano.Ledger.PoolParams (
PoolMetadata (..),
PoolParams (..),
)
import Cardano.Ledger.Slot (SlotNo (..))
import Cardano.Protocol.Crypto (hashVerKeyVRF)
import Cardano.Protocol.TPraos.OCert (KESPeriod (..))
import qualified Data.ByteString.Char8 as BS (pack)
Expand Down Expand Up @@ -120,7 +119,7 @@ aliceSHK = (KeyHashObj . hashKey . vKey) aliceStake

-- | Alice's base address
alicePtrAddr :: Addr
alicePtrAddr = Addr Testnet alicePHK (StakeRefPtr $ Ptr (SlotNo 10) minBound minBound)
alicePtrAddr = Addr Testnet alicePHK (StakeRefPtr $ Ptr 10 minBound minBound)

-- | Alice's stake pool parameters
alicePoolParams :: PoolParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Test.Cardano.Ledger.Shelley.Generator.Trace.TxCert (
)
where

import Cardano.Ledger.BaseTypes (CertIx, Globals, ShelleyBase, TxIx)
import Cardano.Ledger.BaseTypes (CertIx, Globals, ShelleyBase, SlotNo (..), TxIx)
import Cardano.Ledger.CertState (
CertState (..),
lookupDepositDState,
Expand All @@ -28,6 +28,7 @@ import Cardano.Ledger.CertState (
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Core
import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Credential (SlotNo32 (..))
import Cardano.Ledger.Keys (HasKeyRole (coerceKeyRole), asWitness)
import Cardano.Ledger.Shelley.API (
AccountState,
Expand All @@ -36,7 +37,6 @@ import Cardano.Ledger.Shelley.API (
ShelleyDELPL,
)
import Cardano.Ledger.Shelley.Rules (ShelleyDelplEvent, ShelleyDelplPredFailure)
import Cardano.Ledger.Slot (SlotNo (..))
import Control.Monad.Trans.Reader (runReaderT)
import Control.State.Transition (
BaseM,
Expand Down Expand Up @@ -123,15 +123,15 @@ certsTransition ::
TransitionRule (CERTS era)
certsTransition = do
TRC
( (slot, txIx, pp, acnt)
( (slot@(SlotNo slot64), txIx, pp, acnt)
, (dpState, nextCertIx)
, c
) <-
judgmentContext

case c of
Just (cert, _wits) -> do
let ptr = Ptr slot txIx nextCertIx
let ptr = Ptr (SlotNo32 (fromIntegral slot64)) txIx nextCertIx
let epoch = epochFromSlotNo slot
dpState' <-
trans @(Core.EraRule "DELPL" era) $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ module Test.Cardano.Ledger.Shelley.Rules.TestChain (
shortChainTrace,
) where

import Cardano.Ledger.BaseTypes (Globals)
import Cardano.Ledger.BaseTypes (Globals, SlotNo (..))
import Cardano.Ledger.Block (
Block (..),
bheader,
neededTxInsForBlock,
)
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Ptr (..))
import Cardano.Ledger.Credential (Ptr (..), SlotNo32 (..))
import Cardano.Ledger.Shelley.API (ApplyBlock, CertState (..), ShelleyDELEG)
import Cardano.Ledger.Shelley.Core
import Cardano.Ledger.Shelley.LedgerState (
Expand Down Expand Up @@ -223,10 +223,10 @@ delegTraceFromBlock chainSt block =
certs = concatMap (reverse . toList . view certsTxBodyL . view bodyTxL)
blockCerts = filter delegCert (certs txs)
delegEnv =
let (LedgerEnv s _ txIx pp reserves _) = ledgerEnv
let (LedgerEnv slot@(SlotNo slot64) _ txIx pp reserves _) = ledgerEnv
dummyCertIx = minBound
ptr = Ptr s txIx dummyCertIx
in DelegEnv s (epochFromSlotNo s) ptr reserves pp
ptr = Ptr (SlotNo32 (fromIntegral slot64)) txIx dummyCertIx
in DelegEnv slot (epochFromSlotNo slot) ptr reserves pp
delegSt0 =
certDState (lsCertState ledgerSt0)
delegCert (RegTxCert _) = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Cardano.Ledger.Credential (
import Cardano.Ledger.Shelley.LedgerState (IncrementalStake (..))
import Cardano.Ledger.TxIn (TxId (..), TxIn (..))
import Cardano.Ledger.UTxO (UTxO (..))
import Cardano.Slotting.Slot (SlotNo (..))
import qualified Data.Map.Strict as Map

-- ====================================================
Expand Down Expand Up @@ -85,7 +84,7 @@ instance Terse (Credential r) where
terse (KeyHashObj (KeyHash hash)) = "Key " ++ show hash

instance Terse Ptr where
terse (Ptr (SlotNo n) i j) = "Ptr " ++ show n ++ " " ++ show i ++ " " ++ show j
terse (Ptr n i j) = "Ptr " ++ show n ++ " " ++ show i ++ " " ++ show j

instance Terse TxId where
terse (TxId safehash) = show (extractHash safehash)
Expand Down
Loading
Loading