Skip to content

Commit 0ac5ab3

Browse files
committed
sync: Always use the CodecConfig from TopLevelConfig
By extracting it from the TopLevelConfig it should always be correct and by supplying a custom TopLevelConfig we should be able to swap out the regular codec for an identity codec for testing purposes.
1 parent bd42bc6 commit 0ac5ab3

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

cardano-sync/src/Cardano/Sync.hs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import Cardano.BM.Data.Tracer (ToLogObject (..))
3636
import Cardano.BM.Trace (Trace, appendName, logError, logInfo)
3737
import qualified Cardano.BM.Trace as Logging
3838

39-
import qualified Cardano.Chain.Genesis as Byron
4039
import Cardano.Client.Subscription (subscribe)
4140
import qualified Cardano.Crypto as Crypto
4241

@@ -70,16 +69,16 @@ import Network.TypedProtocol.Pipelined (N (..), Nat (Succ, Zero))
7069
import Ouroboros.Network.Driver.Simple (runPipelinedPeer)
7170

7271
import Ouroboros.Consensus.Block.Abstract (CodecConfig)
73-
import Ouroboros.Consensus.Byron.Ledger.Config (mkByronCodecConfig)
7472
import Ouroboros.Consensus.Byron.Node ()
75-
import Ouroboros.Consensus.Cardano.Block (CardanoEras, CodecConfig (..))
73+
import Ouroboros.Consensus.Cardano.Block (CardanoEras)
7674
import Ouroboros.Consensus.Cardano.Node ()
75+
import Ouroboros.Consensus.Config (configCodec)
7776
import Ouroboros.Consensus.HardFork.History.Qry (Interpreter)
7877
import qualified Ouroboros.Consensus.HardFork.Simple as HardFork
7978
import Ouroboros.Consensus.Network.NodeToClient (ClientCodecs, cChainSyncCodec,
8079
cStateQueryCodec, cTxSubmissionCodec)
8180
import Ouroboros.Consensus.Node.ErrorPolicy (consensusErrorPolicy)
82-
import Ouroboros.Consensus.Shelley.Ledger.Config (CodecConfig (ShelleyCodecConfig))
81+
import qualified Ouroboros.Consensus.Node.ProtocolInfo as Consensus
8382
import Ouroboros.Consensus.Shelley.Protocol (StandardCrypto)
8483

8584
import Ouroboros.Network.Block (BlockNo (..), Point (..), Tip (..), blockNo, genesisPoint,
@@ -154,24 +153,16 @@ runSyncNode dataLayer metricsSetters trce plugin enp insertValidateGenesisDist r
154153
-- Must run plugin startup after the genesis distribution has been inserted/validate.
155154
liftIO $ runDbStartup trce plugin
156155
case genCfg of
157-
GenesisCardano _ bCfg _sCfg _aCfg -> do
156+
GenesisCardano {} -> do
158157
syncEnv <- ExceptT $ mkSyncEnvFromConfig dataLayer trce (enpLedgerStateDir enp) genCfg
159158
liftIO $ runSyncNodeNodeClient metricsSetters syncEnv iomgr trce plugin
160-
runDBThreadFunction (cardanoCodecConfig bCfg) (enpSocketPath enp)
159+
runDBThreadFunction (enpSocketPath enp)
161160
where
162-
cardanoCodecConfig :: Byron.Config -> CodecConfig CardanoBlock
163-
cardanoCodecConfig cfg =
164-
CardanoCodecConfig
165-
(mkByronCodecConfig cfg)
166-
ShelleyCodecConfig
167-
ShelleyCodecConfig -- Allegra
168-
ShelleyCodecConfig -- Mary
169-
ShelleyCodecConfig -- Alonzo
170-
171161
useShelleyInit :: HardFork.TriggerHardFork -> Bool
172162
useShelleyInit trigger = case trigger of
173163
HardFork.TriggerHardForkAtEpoch (EpochNo 0) -> True
174164
_ -> False
165+
175166
-- -------------------------------------------------------------------------------------------------
176167

177168
runSyncNodeNodeClient
@@ -181,10 +172,9 @@ runSyncNodeNodeClient
181172
-> Trace IO Text
182173
-> SyncNodePlugin
183174
-> RunDBThreadFunction
184-
-> CodecConfig CardanoBlock
185175
-> SocketPath
186176
-> IO ()
187-
runSyncNodeNodeClient metricsSetters env iomgr trce plugin runDBThreadFunction codecConfig (SocketPath socketPath) = do
177+
runSyncNodeNodeClient metricsSetters env iomgr trce plugin runDBThreadFunction (SocketPath socketPath) = do
188178
queryVar <- newStateQueryTMVar
189179
logInfo trce $ "localInitiatorNetworkApplication: connecting to node via " <> textShow socketPath
190180
void $ subscribe
@@ -195,6 +185,9 @@ runSyncNodeNodeClient metricsSetters env iomgr trce plugin runDBThreadFunction c
195185
clientSubscriptionParams
196186
(dbSyncProtocols trce env metricsSetters plugin queryVar runDBThreadFunction)
197187
where
188+
codecConfig :: CodecConfig CardanoBlock
189+
codecConfig = configCodec $ Consensus.pInfoConfig (leProtocolInfo $ envLedger env)
190+
198191
clientSubscriptionParams =
199192
ClientSubscriptionParams
200193
{ cspAddress = Snocket.localAddressFromPath socketPath

0 commit comments

Comments
 (0)