Skip to content

Commit

Permalink
Added wireTxSize method to LedgerSupportsMempool class
Browse files Browse the repository at this point in the history
The new method leverages a corresponding method recently exposed by
ledger side to provide encoded transaction sizes to eg. diffusion layer.
  • Loading branch information
crocodile-dentist committed Sep 23, 2024
1 parent 35adef5 commit f141ebf
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ if impl(ghc >= 9.10)
source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-network
tag: d900a38c55e02f5eed8c8d6d6a4671cd8c5acc6a
--sha256: sha256-VVccbWFmd9GlL2N/xNsKtXg2U2asGc4fIX1lLEo+Ar8=
tag: 388cc6906b83f41ac2da192b1fd89ab986b4af74
--sha256: sha256-LUwryrP5jK+/c4lDitJf/oKg/DqLgbIc68bn83FsHI0=
subdir:
cardano-client
cardano-ping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.SupportsMempool
import Ouroboros.Consensus.Util (ShowProxy (..))
import Ouroboros.Consensus.Util.Condense
import Ouroboros.Network.SizeInBytes as Network

{-------------------------------------------------------------------------------
Transactions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ 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, eraProtVerLow,
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 @@ -146,6 +146,8 @@ instance (ShelleyCompatible proto era, TxLimits (ShelleyBlock proto era))

reapplyTx = reapplyShelleyTx

wireTxSize (ShelleyTx _ tx) = fromIntegral $ tx ^. wireSizeTxF

txForgetValidated (ShelleyValidatedTx txid vtx) = ShelleyTx txid (SL.extractTx vtx)

mkShelleyTx :: forall era proto. ShelleyBasedEra era => Tx era -> GenTx (ShelleyBlock proto era)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ mkApps kernel Tracers {..} mkCodecs ByteLimits {..} genChainSyncTimeout lopBucke
(getSharedTxStateVar kernel)
(mapTxSubmissionMempoolReader txForgetValidated
$ getMempoolReader (getMempool kernel))
wireTxSize
them $ \api ->
runServer (newTxSubmissionServer api)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ instance CanHardFork xs => LedgerSupportsMempool (HardForkBlock xs) where
(WrapValidatedGenTx vtx)
tls

wireTxSize =
hcollapse
. hcmap proxySingle (K . wireTxSize)
. getOneEraGenTx
. getHardForkGenTx

txForgetValidated =
HardForkGenTx
. OneEraGenTx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ instance Bridge m a => LedgerSupportsMempool (DualBlock m a) where
tickedDualLedgerStateBridge
}

wireTxSize = wireTxSize . dualGenTxMain

txForgetValidated vtx =
DualGenTx {
dualGenTxMain = txForgetValidated vDualGenTxMain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import NoThunks.Class
import Ouroboros.Consensus.Block.Abstract
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ticked
import Ouroboros.Network.SizeInBytes as Network

-- | Generalized transaction
--
Expand Down Expand Up @@ -111,6 +112,10 @@ class ( UpdateLedger blk
-> TickedLedgerState blk
-> Except (ApplyTxErr blk) (TickedLedgerState blk)

-- | Return the size of a serialised transaction as it is transmitted
-- across the network.
wireTxSize :: GenTx blk -> Network.SizeInBytes

-- | Discard the evidence that transaction has been previously validated
txForgetValidated :: Validated (GenTx blk) -> GenTx blk

Expand Down

0 comments on commit f141ebf

Please sign in to comment.