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

TX Submission Logic #4887

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e40ab72
tx-submission: PeerTxState & SharedTxState
coot Nov 21, 2023
c94c63a
tx-submission: decision logic
coot Dec 8, 2023
7908d7c
tx-submission: generalised CollectPipelined
coot Feb 23, 2024
4a5f810
tx-submission: registry
coot Mar 13, 2024
70ca39e
tx-submission: inbound peer using tx-submission decision logic
coot Jul 15, 2024
704a13a
ouroboros-network: tx-submission module structure
coot Jul 22, 2024
8563cfe
tx-submission: debug tracer for SharedTxState
coot Jul 30, 2024
47a7522
Refactor TxSubmission files and added V2 sim
bolt12 Jul 22, 2024
d9d23e9
Fixed ArbTxDecisionPolicy generator
bolt12 Sep 10, 2024
4a8b900
New txSubmissionV2 simulation
bolt12 Sep 11, 2024
8d3c6e1
Drop V2 in internal APIs
coot Sep 17, 2024
81db781
Fix race condition when producing the right policy
bolt12 Sep 11, 2024
b59dbd6
tx-submission: defaultTxDecisionPolicy
coot Sep 17, 2024
44c83bc
Added test that checks tx multiplicities
bolt12 Sep 11, 2024
3352ffc
Integrates txSubmissionV2 in testnet diffusion sim
bolt12 Sep 11, 2024
f4c2dc4
tx-submission: added DebugTxLogic tracer
coot Sep 16, 2024
42931e0
tx-submission: label TVars in tests
coot Sep 16, 2024
14a6afa
tx-submission: use strict STM in tests
coot Sep 16, 2024
c243d7a
tx-submission: refactored test
coot Sep 17, 2024
e3d144f
tx-submission: put common types in one place
coot Sep 17, 2024
6b18472
tx-submission: reorganised test modules
coot Sep 18, 2024
51a2aa9
tx-submission: compile with ghc < 9.10
coot Sep 18, 2024
06b6bda
Update CHaP and hackage
bolt12 Sep 18, 2024
de63b64
Move TxDecisionPolicy to MiniProtocolParamenters
bolt12 Sep 19, 2024
440d1af
Added EnableNewTxSubmissionProtocol flag
bolt12 Sep 19, 2024
3d5a735
tx-submission: verify tx sizes
coot Sep 23, 2024
22c71d5
Send TraceTxSubmissionProcessed for the new TX submission
karknu Oct 2, 2024
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 cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository cardano-haskell-packages
-- repeat the index-state for hackage to work around haskell.nix parsing limitation
index-state:
-- Bump this if you need newer packages from Hackage
, hackage.haskell.org 2024-07-10T11:10:47Z
, hackage.haskell.org 2024-09-18T10:39:04Z

-- Bump this if you need newer packages from CHaP
, cardano-haskell-packages 2024-09-26T15:16:07Z
Expand Down
6 changes: 3 additions & 3 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
Expand Up @@ -17,6 +17,7 @@ import Quiet (Quiet (..))
newtype SizeInBytes = SizeInBytes { getSizeInBytes :: Word32 }
deriving (Eq, Ord)
deriving Show via Quiet SizeInBytes
deriving Bounded via Word32
deriving Enum via Word32
deriving Num via Word32
deriving Real via Word32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ data ServerStIdle (n :: N) txid tx m a where
-- | Collect a pipelined result.
--
CollectPipelined
:: Maybe (ServerStIdle (S n) txid tx m a)
-> (Collect txid tx -> m (ServerStIdle n txid tx m a))
-> ServerStIdle (S n) txid tx m a
:: Maybe (m (ServerStIdle (S n) txid tx m a))
-> (Collect txid tx -> m ( ServerStIdle n txid tx m a))
-> ServerStIdle (S n) txid tx m a


-- | Transform a 'TxSubmissionServerPipelined' into a 'PeerPipelined'.
Expand Down Expand Up @@ -136,6 +136,6 @@ txSubmissionServerPeerPipelined (TxSubmissionServerPipelined server) =
(Effect (go <$> k))

go (CollectPipelined mNone collect) =
Collect (fmap go mNone)
(Effect . fmap go . collect)
Collect (Effect . fmap go <$> mNone)
(Effect . fmap go . collect)

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ directPipelined (TxSubmissionServerPipelined mserver)
SendMsgReplyTxs txs client' <- recvMsgRequestTxs txids
directSender (enqueue (CollectTxs txids txs) q) server' client'

directSender q (CollectPipelined (Just server') _) client =
directSender q (CollectPipelined (Just server) _) client = do
server' <- server
directSender q server' client

directSender (ConsQ c q) (CollectPipelined _ collect) client = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ txSubmissionServer tracer txId maxUnacked maxTxIdsToRequest maxTxToRequest =
--
| canRequestMoreTxs st
= CollectPipelined
(Just (serverReqTxs accum (Succ n) st))
(Just (pure $ serverReqTxs accum (Succ n) st))
(handleReply accum n st)

-- In this case there is nothing else to do so we block until we
Expand Down
13 changes: 13 additions & 0 deletions ouroboros-network/ouroboros-network.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ library
Ouroboros.Network.PeerSharing
Ouroboros.Network.Tracers
Ouroboros.Network.TxSubmission.Inbound
Ouroboros.Network.TxSubmission.Inbound.Decision
Ouroboros.Network.TxSubmission.Inbound.Policy
Ouroboros.Network.TxSubmission.Inbound.Registry
Ouroboros.Network.TxSubmission.Inbound.Server
Ouroboros.Network.TxSubmission.Inbound.State
Ouroboros.Network.TxSubmission.Inbound.Types
Ouroboros.Network.TxSubmission.Mempool.Reader
Ouroboros.Network.TxSubmission.Outbound

Expand Down Expand Up @@ -168,6 +174,7 @@ library
random,
si-timers,
strict-checked-vars ^>=0.2,
strict-mvar,
strict-stm,
typed-protocols ^>=0.3,
typed-protocols-stateful,
Expand Down Expand Up @@ -199,6 +206,7 @@ library sim-tests-lib
cardano-binary,
cardano-prelude,
cardano-slotting,
cardano-strict-containers,
cborg,
containers,
contra-tracer,
Expand Down Expand Up @@ -228,6 +236,7 @@ library sim-tests-lib
random,
serialise,
si-timers,
strict-mvar,
strict-stm,
tasty,
tasty-hunit,
Expand Down Expand Up @@ -267,6 +276,10 @@ library sim-tests-lib
Test.Ouroboros.Network.Testnet
Test.Ouroboros.Network.Testnet.Simulation.Node
Test.Ouroboros.Network.TxSubmission
Test.Ouroboros.Network.TxSubmission.AppV1
Test.Ouroboros.Network.TxSubmission.AppV2
Test.Ouroboros.Network.TxSubmission.TxLogic
Test.Ouroboros.Network.TxSubmission.Types
Test.Ouroboros.Network.Version

-- Simulation tests, and IO tests which don't require native system calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import Ouroboros.Network.Testing.Data.Script (Script (..), stepScriptSTM')

import Simulation.Network.Snocket (AddressType (..), FD)

import Ouroboros.Network.BlockFetch.ClientRegistry (readPeerGSVs)
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers)
import Ouroboros.Network.PeerSelection.LedgerPeers.Type
(LedgerPeersConsensusInterface,
Expand All @@ -105,6 +106,10 @@ import Ouroboros.Network.PeerSelection.RelayAccessPoint (DomainAccessPoint,
import Ouroboros.Network.PeerSelection.RootPeersDNS.DNSActions (DNSLookupType)
import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency,
WarmValency)
import Ouroboros.Network.TxSubmission.Inbound.Policy (TxDecisionPolicy)
import Ouroboros.Network.TxSubmission.Inbound.Registry (decisionLogicThread)
import Ouroboros.Network.TxSubmission.Inbound.Types (TraceTxLogic,
TraceTxSubmissionInbound)
import Test.Ouroboros.Network.Diffusion.Node.ChainDB (addBlock,
getBlockPointSet)
import Test.Ouroboros.Network.Diffusion.Node.MiniProtocols qualified as Node
Expand All @@ -114,6 +119,7 @@ import Test.Ouroboros.Network.Diffusion.Node.NodeKernel (NodeKernel (..),
import Test.Ouroboros.Network.Diffusion.Node.NodeKernel qualified as Node
import Test.Ouroboros.Network.PeerSelection.RootPeersDNS (DNSLookupDelay,
DNSTimeout, mockDNSActions)
import Test.Ouroboros.Network.TxSubmission.Types (Tx)


data Interfaces m = Interfaces
Expand Down Expand Up @@ -158,6 +164,8 @@ data Arguments m = Arguments
, aDNSTimeoutScript :: Script DNSTimeout
, aDNSLookupDelayScript :: Script DNSLookupDelay
, aDebugTracer :: Tracer m String
, aTxDecisionPolicy :: TxDecisionPolicy
, aTxs :: [Tx Int]
}

-- The 'mockDNSActions' is not using \/ specifying 'resolverException', thus we
Expand Down Expand Up @@ -193,9 +201,11 @@ run :: forall resolver m.
NtCAddr NtCVersion NtCVersionData
ResolverException m
-> Tracer m (TraceLabelPeer NtNAddr (TraceFetchClientState BlockHeader))
-> Tracer m (TraceTxSubmissionInbound Int (Tx Int))
-> Tracer m (TraceTxLogic NtNAddr Int (Tx Int))
-> m Void
run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch =
Node.withNodeKernelThread blockGeneratorArgs
run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch tracerTxSubmissionInbound tracerTxLogic =
Node.withNodeKernelThread blockGeneratorArgs (aTxs na)
$ \ nodeKernel nodeKernelThread -> do
dnsTimeoutScriptVar <- newTVarIO (aDNSTimeoutScript na)
dnsLookupDelayScriptVar <- newTVarIO (aDNSLookupDelayScript na)
Expand Down Expand Up @@ -268,7 +278,7 @@ run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch =
, Diff.P2P.daPeerSharingRegistry = nkPeerSharingRegistry nodeKernel
}

let apps = Node.applications (aDebugTracer na) nodeKernel Node.cborCodecs limits appArgs blockHeader
let apps = Node.applications (aDebugTracer na) tracerTxSubmissionInbound tracerTxLogic nodeKernel Node.cborCodecs limits appArgs blockHeader

withAsync
(Diff.P2P.runM interfaces
Expand All @@ -278,11 +288,19 @@ run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch =
(mkArgsExtra useBootstrapPeersScriptVar) apps appsExtra)
$ \ diffusionThread ->
withAsync (blockFetch nodeKernel) $ \blockFetchLogicThread ->
wait diffusionThread
<> wait blockFetchLogicThread
<> wait nodeKernelThread

withAsync (decisionLogicThread
tracerTxLogic
(aTxDecisionPolicy na)
(readPeerGSVs (nkFetchClientRegistry nodeKernel))
(nkTxChannelsVar nodeKernel)
(nkSharedTxStateVar nodeKernel)) $ \decLogicThread ->
wait diffusionThread
<> wait blockFetchLogicThread
<> wait nodeKernelThread
<> wait decLogicThread
where
blockFetch :: NodeKernel BlockHeader Block s m
blockFetch :: NodeKernel BlockHeader Block s txid m
-> m Void
blockFetch nodeKernel = do
blockFetchLogic
Expand All @@ -298,7 +316,7 @@ run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch =
bfcSalt = 0
})

blockFetchPolicy :: NodeKernel BlockHeader Block s m
blockFetchPolicy :: NodeKernel BlockHeader Block s txid m
-> BlockFetchConsensusInterface NtNAddr BlockHeader Block m
blockFetchPolicy nodeKernel =
BlockFetchConsensusInterface {
Expand Down Expand Up @@ -420,6 +438,7 @@ run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch =
, Node.aaOwnPeerSharing = aOwnPeerSharing na
, Node.aaUpdateOutboundConnectionsState =
iUpdateOutboundConnectionsState ni
, Node.aaTxDecisionPolicy = aTxDecisionPolicy na
}

--- Utils
Expand Down
Loading