Skip to content

TxSubmission Logic: integration #1522

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,22 @@ if impl (ghc >= 9.12)

-- https://github.com/kapralVV/Unique/issues/11
, Unique:hashable

source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-network
tag: 5f12333fcaa5931c2bbbcd28582bb8262d02d220
--sha256: sha256-NMJXzPuTOfdQzHwpRD5j/Q5JUpDPt6yjEPGnIZvTfcc=
subdir:
cardano-client
cardano-ping
monoidal-synchronisation
network-mux
ntp-client
ouroboros-network
ouroboros-network-api
ouroboros-network-framework
ouroboros-network-mock
ouroboros-network-protocols
ouroboros-network-testing
quickcheck-monoids
12 changes: 6 additions & 6 deletions flake.lock

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
@@ -0,0 +1,21 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Patch

- A bullet item for the Patch category.

-->
<!--
### Non-Breaking

- A bullet item for the Non-Breaking category.

-->
### Breaking

- Implement txWireSize of TxLimits instantiations for Byron and Shelley
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ instance LedgerSupportsMempool ByronBlock where
instance TxLimits ByronBlock where
type TxMeasure ByronBlock = IgnoringOverflow ByteSize32

txWireSize = (+ 2)
-- 2 bytes overhead added by `EncCBOR (AMempoolPayload
-- ByteString)` instance
. fromIntegral
. Strict.length
. CC.mempoolPayloadRecoverBytes
. toMempoolPayload

blockCapacityTxMeasure _cfg st =
IgnoringOverflow
$ ByteSize32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module Ouroboros.Consensus.Shelley.Ledger.Mempool (
import qualified Cardano.Crypto.Hash as Hash
import qualified Cardano.Ledger.Allegra.Rules as AllegraEra
import Cardano.Ledger.Alonzo.Core (Tx, TxSeq, bodyTxL, eraDecoder,
fromTxSeq, ppMaxBBSizeL, ppMaxBlockExUnitsL, sizeTxF)
fromTxSeq, ppMaxBBSizeL, ppMaxBlockExUnitsL, sizeTxF,
wireSizeTxF)
import qualified Cardano.Ledger.Alonzo.Rules as AlonzoEra
import Cardano.Ledger.Alonzo.Scripts (ExUnits, ExUnits' (..),
pointWiseExUnits, unWrapExUnits)
Expand Down Expand Up @@ -67,6 +68,7 @@ import Data.Foldable (toList)
import Data.Measure (Measure)
import Data.Typeable (Typeable)
import qualified Data.Validation as V
import Data.Word (Word32)
import GHC.Generics (Generic)
import GHC.Natural (Natural)
import Lens.Micro ((^.))
Expand All @@ -85,6 +87,7 @@ import Ouroboros.Consensus.Shelley.Protocol.Abstract (ProtoCrypto)
import Ouroboros.Consensus.Util (ShowProxy (..))
import Ouroboros.Consensus.Util.Condense
import Ouroboros.Network.Block (unwrapCBORinCBOR, wrapCBORinCBOR)
import Ouroboros.Network.SizeInBytes

data instance GenTx (ShelleyBlock proto era) = ShelleyTx !SL.TxId !(Tx era)
deriving stock (Generic)
Expand Down Expand Up @@ -425,18 +428,37 @@ instance MaxTxSizeUTxO ConwayEra where

-----

wrapCBORinCBOROverhead :: Word32
-- ^ payload size
-> SizeInBytes
wrapCBORinCBOROverhead size =
2 -- wrapCBORinCBOR's encodeTag 24

+ -- upper bound for wrapCBORinCBOR's encodeBytes overhead;
-- it is bounded by maximum tx size
case size of
_ | size <= 0x17 -> 1
| size <= 0xff -> 2
| size <= 0xffff -> 3
| otherwise -> 5
+ fromIntegral size


instance ShelleyCompatible p ShelleyEra => TxLimits (ShelleyBlock p ShelleyEra) where
type TxMeasure (ShelleyBlock p ShelleyEra) = IgnoringOverflow ByteSize32
txWireSize (ShelleyTx _ tx) = wrapCBORinCBOROverhead (tx ^. wireSizeTxF)
txMeasure _cfg st tx = runValidation $ txInBlockSize st tx
blockCapacityTxMeasure _cfg = txsMaxBytes

instance ShelleyCompatible p AllegraEra => TxLimits (ShelleyBlock p AllegraEra) where
type TxMeasure (ShelleyBlock p AllegraEra) = IgnoringOverflow ByteSize32
txWireSize (ShelleyTx _ tx) = wrapCBORinCBOROverhead (tx ^. wireSizeTxF)
txMeasure _cfg st tx = runValidation $ txInBlockSize st tx
blockCapacityTxMeasure _cfg = txsMaxBytes

instance ShelleyCompatible p MaryEra => TxLimits (ShelleyBlock p MaryEra) where
type TxMeasure (ShelleyBlock p MaryEra) = IgnoringOverflow ByteSize32
txWireSize (ShelleyTx _ tx) = wrapCBORinCBOROverhead (tx ^. wireSizeTxF)
txMeasure _cfg st tx = runValidation $ txInBlockSize st tx
blockCapacityTxMeasure _cfg = txsMaxBytes

Expand Down Expand Up @@ -547,6 +569,7 @@ instance ( ShelleyCompatible p AlonzoEra
) => TxLimits (ShelleyBlock p AlonzoEra) where

type TxMeasure (ShelleyBlock p AlonzoEra) = AlonzoMeasure
txWireSize (ShelleyTx _ tx) = wrapCBORinCBOROverhead (tx ^. wireSizeTxF)
txMeasure _cfg st tx = runValidation $ txMeasureAlonzo st tx
blockCapacityTxMeasure _cfg = blockCapacityAlonzoMeasure

Expand Down Expand Up @@ -661,12 +684,14 @@ instance ( ShelleyCompatible p BabbageEra
) => TxLimits (ShelleyBlock p BabbageEra) where

type TxMeasure (ShelleyBlock p BabbageEra) = ConwayMeasure
txWireSize (ShelleyTx _ tx) = wrapCBORinCBOROverhead (tx ^. wireSizeTxF)
txMeasure _cfg st tx = runValidation $ txMeasureBabbage st tx
blockCapacityTxMeasure _cfg = blockCapacityConwayMeasure

instance ( ShelleyCompatible p ConwayEra
) => TxLimits (ShelleyBlock p ConwayEra) where

type TxMeasure (ShelleyBlock p ConwayEra) = ConwayMeasure
txWireSize (ShelleyTx _ tx) = wrapCBORinCBOROverhead (tx ^. wireSizeTxF)
txMeasure _cfg st tx = runValidation $ txMeasureConway st tx
blockCapacityTxMeasure _cfg = blockCapacityConwayMeasure
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ instance TxLimits ByronSpecBlock where
type TxMeasure ByronSpecBlock = IgnoringOverflow ByteSize32

-- Dummy values, as these are not used in practice.
txWireSize = const . fromIntegral $ (0 :: Int)
blockCapacityTxMeasure _cfg _st = IgnoringOverflow $ ByteSize32 1

txMeasure _cfg _st _tx = pure $ IgnoringOverflow $ ByteSize32 0
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@ genTestConfig k (EpochSize epochSize1, EpochSize epochSize2) = do
Topo.unionNodeTopology oddTopo $
topo0

txLogicVersion <- elements [minBound..maxBound]

pure TestConfig
{ initSeed
, nodeTopology
, numCoreNodes = NumCoreNodes ncn
, numSlots
, txLogicVersion
}

-- | Generate 'setupPartition'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ import Test.Tasty.QuickCheck
import Test.Util.Corruption
import Test.Util.Orphans.Arbitrary ()
import Test.Util.Serialisation.Roundtrip
import Test.Util.Serialisation.TxWireSize

tests :: TestTree
tests = testGroup "Byron"
[ roundtrip_all testCodecCfg dictNestedHdr
, testProperty "GenTx.txWireSize.txSubmission" (prop_txWireSize_txSubmission testCodecCfg)
, testProperty "GenTx.txWireSize.tight" (prop_txWireSize (const Nothing) testCodecCfg)

, testProperty "BinaryBlockInfo sanity check" prop_byronBinaryBlockInfo

Expand Down
Loading