Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 1686120

Browse files
Merge #37
37: use withRegistry in Logic callbacks r=avieth a=avieth Without this, cannot serve Byron peers, as the registry will blow up because it's used from an "unknown thread" Co-authored-by: Alexander Vieth <[email protected]>
2 parents 8a0584e + 6c05dd1 commit 1686120

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/exec/Main.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,11 @@ runByron
370370
-> CSL.Genesis.Config
371371
-> Cardano.ProtocolMagicId
372372
-> Cardano.EpochSlots
373-
-> ResourceRegistry IO
374373
-> Index IO (Header (Block ByronConfig))
375374
-> ChainDB IO (Block ByronConfig)
376375
-> Mempool IO (Block ByronConfig) TicketNo
377376
-> IO ()
378-
runByron tracer byronOptions genesisConfig _ epochSlots rr idx db mempool = do
377+
runByron tracer byronOptions genesisConfig _ epochSlots idx db mempool = do
379378
let cslTrace = mkCSLTrace tracer
380379
-- Get the `NetworkConfig` from the options
381380
networkConfig <- CSL.intNetworkConfigOpts
@@ -415,7 +414,7 @@ runByron tracer byronOptions genesisConfig _ epochSlots rr idx db mempool = do
415414
-- It would be much better if intNetworkConfigOpts set up the static
416415
-- peers to begin with, but that's just not how it is.
417416
withAsync (CSL.launchStaticConfigMonitoring (ncTopology networkConfig)) $ \monitorThread ->
418-
withByronProxy (contramap (\(a, b) -> ("", a, b)) tracer) bpc rr idx db mempool $ \bp -> do
417+
withByronProxy (contramap (\(a, b) -> ("", a, b)) tracer) bpc idx db mempool $ \bp -> do
419418
link monitorThread
420419
byronClient genesisBlock bp
421420

@@ -561,7 +560,6 @@ main = do
561560
oldGenesisConfig
562561
protocolMagic
563562
epochSlots
564-
rr
565563
idx
566564
cdb
567565
(getMempool kernel)

src/lib/Ouroboros/Byron/Proxy/Main.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ import Ouroboros.Consensus.Mempool.TxSeq (TicketNo)
113113
import Ouroboros.Consensus.NodeKernel (getMempoolReader,
114114
getMempoolWriter)
115115
import Ouroboros.Consensus.Util.ResourceRegistry (ResourceRegistry)
116+
import qualified Ouroboros.Consensus.Util.ResourceRegistry as ResourceRegistry
116117
import Ouroboros.Network.Block (ChainUpdate (..),
117118
Point (..))
118119
import qualified Ouroboros.Network.Point as Point (block)
@@ -700,13 +701,12 @@ withByronProxy
700701
:: ( ApplyTx (Block cfg) )
701702
=> Tracer IO (Severity, Text.Builder)
702703
-> ByronProxyConfig
703-
-> ResourceRegistry IO
704704
-> Index IO (Header (Block cfg))
705705
-> ChainDB IO (Block cfg)
706706
-> Mempool IO (Block cfg) TicketNo
707707
-> (ByronProxy -> IO t)
708708
-> IO t
709-
withByronProxy trace bpc rr idx db mempool k = do
709+
withByronProxy trace bpc idx db mempool k = do
710710

711711
-- The best announced block header, and the identifiers of every peer which
712712
-- announced it. `Nothing` whenever there is no known announcement. It will
@@ -807,7 +807,8 @@ withByronProxy trace bpc rr idx db mempool k = do
807807
, Logic.getBlockHeader = bbsGetBlockHeader epochSlots idx db blockDecodeError
808808
-- MsgGetHeaders conversation
809809
, getBlockHeaders = \mLimit checkpoints mTip -> do
810-
result <- bbsGetBlockHeaders epochSlots rr idx db blockDecodeError mLimit checkpoints mTip
810+
result <- ResourceRegistry.withRegistry $ \rr ->
811+
bbsGetBlockHeaders epochSlots rr idx db blockDecodeError mLimit checkpoints mTip
811812
case result of
812813
Nothing -> pure $ Left $ GHFBadInput ""
813814
Just it -> pure $ Right it
@@ -825,7 +826,8 @@ withByronProxy trace bpc rr idx db mempool k = do
825826
Right (legacyBlk :: Byron.Legacy.Block) -> pure legacyBlk
826827
-- GetBlocks conversation
827828
, getHashesRange = \mLimit from to -> do
828-
result <- bbsGetHashesRange rr idx db blockDecodeError mLimit from to
829+
result <- ResourceRegistry.withRegistry $ \rr ->
830+
bbsGetHashesRange rr idx db blockDecodeError mLimit from to
829831
case result of
830832
Nothing -> pure $ Left $ GHRBadInput ""
831833
Just it -> pure $ Right it
@@ -837,8 +839,9 @@ withByronProxy trace bpc rr idx db mempool k = do
837839
-- at the given start hash! This is not documented in cardano-sl.
838840
-- That's done by giving `False` to `bbsStreamBlocks`, which uses
839841
-- the `ChainDB` `Reader` API to do streaming. It stops at a fork.
840-
, Logic.streamBlocks = \hh l ->
841-
bbsStreamBlocks rr idx db blockDecodeError hh (pure . toSerializedBlock) False l
842+
, Logic.streamBlocks = \hh l -> do
843+
ResourceRegistry.withRegistry $ \rr ->
844+
bbsStreamBlocks rr idx db blockDecodeError hh (pure . toSerializedBlock) False l
842845
}
843846

844847
networkConfig = bpcNetworkConfig bpc

0 commit comments

Comments
 (0)