Skip to content

Commit 70b3121

Browse files
Merge remote-tracking branch 'origin/bolt12/tx-submission' into mwojtowicz/genesis-ledger-peer-snapshot
2 parents 20a2b18 + f8fa637 commit 70b3121

File tree

21 files changed

+402
-78
lines changed

21 files changed

+402
-78
lines changed

bench/tx-generator/src/Cardano/Benchmarking/Command.hs

+2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ import GHC.Weak as Weak (deRefWeak)
5757
import System.Posix.Signals as Sig (Handler (CatchInfo),
5858
SignalInfo (..), SignalSpecificInfo (..), installHandler,
5959
sigINT, sigTERM)
60+
import Foreign.C (Errno(..))
6061
#if MIN_VERSION_base(4,18,0)
6162
import Data.Maybe as Maybe (fromMaybe)
6263
import GHC.Conc.Sync as Conc (threadLabel)
6364
#endif
6465
#endif
6566

6667
#ifdef UNIX
68+
deriving instance Show Errno
6769
deriving instance Show SignalInfo
6870
deriving instance Show SignalSpecificInfo
6971
#endif

bench/tx-generator/src/Cardano/Benchmarking/GeneratorTx/SubmissionClient.hs

+16-12
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
{-# LANGUAGE OverloadedStrings #-}
1212
{-# LANGUAGE RankNTypes #-}
1313
{-# LANGUAGE ScopedTypeVariables #-}
14-
{-# LANGUAGE TypeApplications #-}
15-
{-# LANGUAGE TypeOperators #-}
1614
{-# LANGUAGE UndecidableInstances #-}
1715

1816
{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}
@@ -26,10 +24,11 @@ module Cardano.Benchmarking.GeneratorTx.SubmissionClient
2624
) where
2725

2826
import Cardano.Api hiding (Active)
29-
import Cardano.Api.Shelley (fromShelleyTxId, toConsensusGenTx)
27+
import Cardano.Api.Shelley (Tx (..), fromShelleyTxId, toConsensusGenTx)
3028

3129
import Cardano.Benchmarking.LogTypes
3230
import Cardano.Benchmarking.Types
31+
import Cardano.Ledger.Core (sizeTxF)
3332
import Cardano.Logging
3433
import Cardano.Prelude hiding (ByteString, atomically, retry, state, threadDelay)
3534
import Cardano.Tracing.OrphanInstances.Byron ()
@@ -40,7 +39,7 @@ import Cardano.Tracing.OrphanInstances.Shelley ()
4039
import qualified Ouroboros.Consensus.Cardano as Consensus (CardanoBlock)
4140
import qualified Ouroboros.Consensus.Cardano.Block as Block
4241
(TxId (GenTxIdAllegra, GenTxIdAlonzo, GenTxIdBabbage, GenTxIdConway, GenTxIdMary, GenTxIdShelley))
43-
import Ouroboros.Consensus.Ledger.SupportsMempool (GenTx, GenTxId, txInBlockSize)
42+
import Ouroboros.Consensus.Ledger.SupportsMempool (GenTx, GenTxId)
4443
import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Mempool
4544
import Ouroboros.Consensus.Shelley.Eras (StandardCrypto)
4645
import qualified Ouroboros.Consensus.Shelley.Ledger.Mempool as Mempool (TxId (ShelleyTxId))
@@ -57,6 +56,8 @@ import qualified Data.List as L
5756
import qualified Data.List.Extra as L
5857
import qualified Data.List.NonEmpty as NE
5958
import qualified Data.Text as T
59+
import Lens.Micro.Extras (view)
60+
6061
type CardanoBlock = Consensus.CardanoBlock StandardCrypto
6162

6263
data SubmissionThreadStats
@@ -85,10 +86,9 @@ type LocalState era = (TxSource era, UnAcked (Tx era), SubmissionThreadStats)
8586
type EndOfProtocolCallback m = SubmissionThreadStats -> m ()
8687

8788
txSubmissionClient
88-
:: forall m era tx.
89+
:: forall m era .
8990
( MonadIO m, MonadFail m
9091
, IsShelleyBasedEra era
91-
, tx ~ Tx era
9292
)
9393
=> Trace m NodeToNodeSubmissionTrace
9494
-> Trace m (TraceBenchTxSubmit TxId)
@@ -110,11 +110,11 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
110110
traceWith bmtr $ SubmissionClientDiscardAcknowledged (getTxId . getTxBody <$> acked)
111111
return (txSource, UnAcked stillUnacked, newStats)
112112

113-
queueNewTxs :: [tx] -> LocalState era -> LocalState era
113+
queueNewTxs :: [Tx era] -> LocalState era -> LocalState era
114114
queueNewTxs newTxs (txSource, UnAcked unAcked, stats)
115115
= (txSource, UnAcked (newTxs <> unAcked), stats)
116116

117-
client ::LocalState era -> ClientStIdle (GenTxId CardanoBlock) (GenTx CardanoBlock) m ()
117+
client :: LocalState era -> ClientStIdle (GenTxId CardanoBlock) (GenTx CardanoBlock) m ()
118118

119119
client localState = ClientStIdle
120120
{ recvMsgRequestTxIds = requestTxIds localState
@@ -177,11 +177,15 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
177177
, stsUnavailable =
178178
stsUnavailable stats + Unav (length missIds)}))
179179

180-
txToIdSize :: tx -> (GenTxId CardanoBlock, SizeInBytes)
181-
txToIdSize = (Mempool.txId &&& (SizeInBytes . txInBlockSize)) . toGenTx
180+
txToIdSize :: Tx era -> (GenTxId CardanoBlock, SizeInBytes)
181+
txToIdSize = (Mempool.txId . toGenTx) &&& (SizeInBytes . fromInteger . getTxSize)
182+
where
183+
getTxSize :: Tx era -> Integer
184+
getTxSize (ShelleyTx sbe tx) =
185+
shelleyBasedEraConstraints sbe $ view sizeTxF tx
182186

183-
toGenTx :: tx -> GenTx CardanoBlock
184-
toGenTx tx = toConsensusGenTx $ TxInMode (shelleyBasedEra @era) tx
187+
toGenTx :: Tx era -> GenTx CardanoBlock
188+
toGenTx tx = toConsensusGenTx $ TxInMode shelleyBasedEra tx
185189

186190

187191
fromGenTxId :: GenTxId CardanoBlock -> TxId

bench/tx-generator/tx-generator.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ library
157157
, transformers-except
158158
, unordered-containers
159159
, yaml
160+
, microlens
160161

161162
default-language: Haskell2010
162163
default-extensions: OverloadedStrings

cabal.project

+29
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,32 @@ allow-newer:
6767
-- IMPORTANT
6868
-- Do NOT add more source-repository-package stanzas here unless they are strictly
6969
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.
70+
source-repository-package
71+
type: git
72+
location: https://github.com/IntersectMBO/ouroboros-network
73+
tag: 1070ab4afc337bf2718e270768e24f263061554a
74+
--sha256: sha256-ITwg+Hpw4MsoeYhXpe7rE6wDniOElOFxkKgnktKWMdo=
75+
subdir:
76+
cardano-client
77+
cardano-ping
78+
monoidal-synchronisation
79+
network-mux
80+
ntp-client
81+
ouroboros-network-api
82+
ouroboros-network-framework
83+
ouroboros-network-mock
84+
ouroboros-network-protocols
85+
ouroboros-network-testing
86+
ouroboros-network
87+
quickcheck-monoids
88+
89+
source-repository-package
90+
type: git
91+
location: https://github.com/IntersectMBO/ouroboros-consensus
92+
tag: 35adef5a76b285029762a4013059c1b430604e9c
93+
--sha256: sha256-FKCY2nFZyXnBR3Wkn80HXipiKlbyDOohU++aRBAq3fA=
94+
subdir:
95+
ouroboros-consensus
96+
ouroboros-consensus-cardano
97+
ouroboros-consensus-diffusion
98+
ouroboros-consensus-protocol

cardano-node/src/Cardano/Node/Configuration/POM.hs

+44-18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import qualified Ouroboros.Consensus.Node as Consensus (NetworkP2PMode (..))
3838
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (NumOfDiskSnapshots (..),
3939
SnapshotInterval (..))
4040
import Ouroboros.Network.Diffusion.Configuration as Configuration
41+
import Ouroboros.Network.TxSubmission.Inbound.Server (EnableNewTxSubmissionProtocol (..))
4142

4243
import Control.Monad (when)
4344
import Data.Aeson
@@ -148,6 +149,13 @@ data NodeConfiguration
148149
-- | Node AcceptedConnectionsLimit
149150
, ncAcceptedConnectionsLimit :: !AcceptedConnectionsLimit
150151

152+
-- Used to determine which set of peer targets to use
153+
-- by the diffusion layer when syncing
154+
, ncConsensusMode :: !ConsensusMode
155+
-- Minimum number of active big ledger peers we must be connected to
156+
-- in Genesis mode
157+
, ncMinBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState
158+
151159
-- P2P governor targets
152160
, ncDeadlineTargetOfRootPeers :: !Int
153161
, ncDeadlineTargetOfKnownPeers :: !Int
@@ -160,17 +168,15 @@ data NodeConfiguration
160168
, ncSyncTargetOfKnownBigLedgerPeers :: !Int
161169
, ncSyncTargetOfEstablishedBigLedgerPeers :: !Int
162170
, ncSyncTargetOfActiveBigLedgerPeers :: !Int
163-
, ncSyncMinTrusted :: !MinBigLedgerPeersForTrustedState
164-
165-
-- Used to determine which set of peer targets to use
166-
-- by the diffusion layer when syncing
167-
, ncConsensusMode :: !ConsensusMode
168171

169172
-- Enable experimental P2P mode
170173
, ncEnableP2P :: SomeNetworkP2PMode
171174

172175
-- Enable Peer Sharing
173176
, ncPeerSharing :: PeerSharing
177+
178+
-- Enable new TX Submission Protocol
179+
, ncEnableNewTxSubmissionProtocol :: EnableNewTxSubmissionProtocol
174180
} deriving (Eq, Show)
175181

176182

@@ -220,6 +226,12 @@ data PartialNodeConfiguration
220226
-- AcceptedConnectionsLimit
221227
, pncAcceptedConnectionsLimit :: !(Last AcceptedConnectionsLimit)
222228

229+
-- Consensus mode for diffusion layer
230+
, pncConsensusMode :: !(Last ConsensusMode)
231+
-- Minimum number of active big ledger peers we must be connected to
232+
-- in Genesis mode, otherwise syncing is halted temporarily
233+
, pncMinBigLedgerPeersForTrustedState :: !(Last MinBigLedgerPeersForTrustedState)
234+
223235
-- P2P governor targets
224236
, pncDeadlineTargetOfRootPeers :: !(Last Int)
225237
, pncDeadlineTargetOfKnownPeers :: !(Last Int)
@@ -232,16 +244,15 @@ data PartialNodeConfiguration
232244
, pncSyncTargetOfKnownBigLedgerPeers :: !(Last Int)
233245
, pncSyncTargetOfEstablishedBigLedgerPeers :: !(Last Int)
234246
, pncSyncTargetOfActiveBigLedgerPeers :: !(Last Int)
235-
, pncSyncMinTrusted :: !(Last MinBigLedgerPeersForTrustedState)
236-
237-
-- Consensus mode for diffusion layer
238-
, pncConsensusMode :: !(Last ConsensusMode)
239247

240248
-- Enable experimental P2P mode
241249
, pncEnableP2P :: !(Last NetworkP2PMode)
242250

243251
-- Peer Sharing
244252
, pncPeerSharing :: !(Last PeerSharing)
253+
254+
-- Enable new TX Submission Protocol
255+
, pncEnableNewTxSubmissionProtocol :: !(Last EnableNewTxSubmissionProtocol)
245256
} deriving (Eq, Generic, Show)
246257

247258
instance AdjustFilePaths PartialNodeConfiguration where
@@ -316,6 +327,8 @@ instance FromJSON PartialNodeConfiguration where
316327
pncAcceptedConnectionsLimit
317328
<- Last <$> v .:? "AcceptedConnectionsLimit"
318329

330+
pncConsensusMode <- Last <$> v .:? "ConsensusMode"
331+
319332
-- P2P Governor parameters, with conservative defaults.
320333
pncDeadlineTargetOfRootPeers <- Last <$> v .:? "TargetNumberOfRootPeers"
321334
pncDeadlineTargetOfKnownPeers <- Last <$> v .:? "TargetNumberOfKnownPeers"
@@ -328,9 +341,7 @@ instance FromJSON PartialNodeConfiguration where
328341
pncSyncTargetOfKnownBigLedgerPeers <- Last <$> v .:? "SyncTargetNumberOfKnownBigLedgerPeers"
329342
pncSyncTargetOfEstablishedBigLedgerPeers <- Last <$> v .:? "SyncTargetNumberOfEstablishedBigLedgerPeers"
330343
pncSyncTargetOfActiveBigLedgerPeers <- Last <$> v .:? "SyncTargetNumberOfActiveBigLedgerPeers"
331-
pncSyncMinTrusted <- Last <$> v .:? "SyncMinNumberOfBigLedgerPeersForTrustedState"
332-
333-
pncConsensusMode <- Last <$> v .:? "ConsensusMode"
344+
pncMinBigLedgerPeersForTrustedState <- Last <$> v .:? "MinBigLedgerPeersForTrustedState"
334345

335346
pncChainSyncIdleTimeout <- Last <$> v .:? "ChainSyncIdleTimeout"
336347

@@ -346,6 +357,14 @@ instance FromJSON PartialNodeConfiguration where
346357
-- DISABLED BY DEFAULT
347358
pncPeerSharing <- Last <$> v .:? "PeerSharing" .!= Just Configuration.PeerSharingDisabled
348359

360+
-- Enable new TX Submission Protocol
361+
newTxSubmissionProtocol <- v .:? "EnableNewTxSubmissionProtocol"
362+
let pncEnableNewTxSubmissionProtocol =
363+
case newTxSubmissionProtocol of
364+
Nothing -> Last $ Just EnableNewTxSubmissionProtocol -- defaultEnableNewTxSubmissionProtocol
365+
Just False -> Last $ Just DisableNewTxSubmissionProtocol
366+
Just True -> Last $ Just EnableNewTxSubmissionProtocol
367+
349368
pure PartialNodeConfiguration {
350369
pncProtocolConfig
351370
, pncSocketConfig = Last . Just $ SocketConfig mempty mempty mempty pncSocketPath
@@ -382,10 +401,11 @@ instance FromJSON PartialNodeConfiguration where
382401
, pncSyncTargetOfKnownBigLedgerPeers
383402
, pncSyncTargetOfEstablishedBigLedgerPeers
384403
, pncSyncTargetOfActiveBigLedgerPeers
385-
, pncSyncMinTrusted
404+
, pncMinBigLedgerPeersForTrustedState
386405
, pncConsensusMode
387406
, pncEnableP2P
388407
, pncPeerSharing
408+
, pncEnableNewTxSubmissionProtocol
389409
}
390410
where
391411
parseMempoolCapacityBytesOverride v = parseNoOverride <|> parseOverride
@@ -564,10 +584,11 @@ defaultPartialNodeConfiguration =
564584
, pncSyncTargetOfKnownBigLedgerPeers = Last (Just syncBigKnown)
565585
, pncSyncTargetOfEstablishedBigLedgerPeers = Last (Just syncBigEst)
566586
, pncSyncTargetOfActiveBigLedgerPeers = Last (Just syncBigAct)
567-
, pncSyncMinTrusted = Last (Just defaultMinBigLedgerPeersForTrustedState)
587+
, pncMinBigLedgerPeersForTrustedState = Last (Just defaultMinBigLedgerPeersForTrustedState)
568588
, pncConsensusMode = mempty
569589
, pncEnableP2P = Last (Just EnabledP2PMode)
570590
, pncPeerSharing = Last (Just Configuration.PeerSharingDisabled)
591+
, pncEnableNewTxSubmissionProtocol = Last (Just EnableNewTxSubmissionProtocol) -- defaultEnableNewTxSubmissionProtocol)
571592
}
572593
where
573594
Configuration.PeerSelectionTargets {
@@ -637,9 +658,9 @@ makeNodeConfiguration pnc = do
637658
ncSyncTargetOfActiveBigLedgerPeers <-
638659
lastToEither "Missing SyncTargetNumberOfActiveBigLedgerPeers"
639660
$ pncSyncTargetOfActiveBigLedgerPeers pnc
640-
ncSyncMinTrusted <-
641-
lastToEither "Missing SyncMinNumberOfBigLedgerPeersForTrustedState"
642-
$ pncSyncMinTrusted pnc
661+
ncMinBigLedgerPeersForTrustedState <-
662+
lastToEither "Missing MinBigLedgerPeersForTrustedState"
663+
$ pncMinBigLedgerPeersForTrustedState pnc
643664
ncConsensusMode <-
644665
lastToEither "Missing ConsensusMode"
645666
$ pncConsensusMode pnc
@@ -665,6 +686,10 @@ makeNodeConfiguration pnc = do
665686
lastToEither "Missing PeerSharing"
666687
$ pncPeerSharing pnc
667688

689+
ncEnableNewTxSubmissionProtocol <-
690+
lastToEither "Missing EnableNewTxSubmissionProtocol"
691+
$ pncEnableNewTxSubmissionProtocol pnc
692+
668693
-- TODO: This is not mandatory
669694
experimentalProtocols <-
670695
lastToEither "Missing ExperimentalProtocolsEnabled" $
@@ -712,12 +737,13 @@ makeNodeConfiguration pnc = do
712737
, ncSyncTargetOfKnownBigLedgerPeers
713738
, ncSyncTargetOfEstablishedBigLedgerPeers
714739
, ncSyncTargetOfActiveBigLedgerPeers
715-
, ncSyncMinTrusted
740+
, ncMinBigLedgerPeersForTrustedState
716741
, ncEnableP2P = case enableP2P of
717742
EnabledP2PMode -> SomeNetworkP2PMode Consensus.EnabledP2PMode
718743
DisabledP2PMode -> SomeNetworkP2PMode Consensus.DisabledP2PMode
719744
, ncPeerSharing
720745
, ncConsensusMode
746+
, ncEnableNewTxSubmissionProtocol
721747
}
722748

723749
ncProtocol :: NodeConfiguration -> Protocol

cardano-node/src/Cardano/Node/Parsers.hs

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Cardano.Node.Configuration.Socket
2020
import Cardano.Node.Handlers.Shutdown
2121
import Cardano.Node.Types
2222
import Cardano.Prelude (ConvertText (..))
23-
import Ouroboros.Consensus.Mempool (MempoolCapacityBytes (..))
23+
import Ouroboros.Consensus.Ledger.SupportsMempool (ByteSize32 (..))
2424
import Ouroboros.Consensus.Node
2525
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (NumOfDiskSnapshots (..),
2626
SnapshotInterval (..))
@@ -132,6 +132,9 @@ nodeRunParser = do
132132
, pncConsensusMode = mempty
133133
, pncEnableP2P = mempty
134134
, pncPeerSharing = mempty
135+
, pncConsensusMode = mempty
136+
, pncMinBigLedgerPeersForTrustedState = mempty
137+
, pncEnableNewTxSubmissionProtocol = mempty
135138
}
136139

137140
parseSocketPath :: Text -> Parser SocketPath
@@ -217,7 +220,7 @@ parseMempoolCapacityOverride = parseOverride <|> parseNoOverride
217220
where
218221
parseOverride :: Parser MempoolCapacityBytesOverride
219222
parseOverride =
220-
MempoolCapacityBytesOverride . MempoolCapacityBytes <$>
223+
MempoolCapacityBytesOverride . ByteSize32 <$>
221224
Opt.option (auto @Word32)
222225
( long "mempool-capacity-override"
223226
<> metavar "BYTES"

cardano-node/src/Cardano/Node/Protocol/Types.hs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import qualified Cardano.Api as Api
1616
import Cardano.Node.Orphans ()
1717
import Cardano.Node.Queries (HasKESInfo, HasKESMetricsData)
1818
import Cardano.Node.TraceConstraints (TraceConstraints)
19+
import Ouroboros.Consensus.Ledger.SupportsMempool (GenTxId)
1920

2021
import Control.DeepSeq (NFData)
2122
import Data.Aeson
@@ -45,6 +46,7 @@ data SomeConsensusProtocol where
4546
, HasKESMetricsData blk
4647
, HasKESInfo blk
4748
, TraceConstraints blk
49+
, ToJSONKey (GenTxId blk)
4850
)
4951
=> Api.BlockType blk
5052
-> Api.ProtocolInfoArgs blk

0 commit comments

Comments
 (0)