From b34687d7bc8965e8f918d2ea302f12378cb64b09 Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Wed, 16 Jun 2021 13:49:18 +0200 Subject: [PATCH] Ensure cluster setup runs without rollbacks This commit re-adds the setup specific callback from removed in https://github.com/input-output-hk/cardano-wallet/commit/925b4d903c170eb1e510d4519aa8688c9a6beaff such that the fuacet setup is run on the BFT node, before pools are registered and can roll back. This should hopefully fix a #2720, #2428, and perhaps something more. --- lib/shelley/bench/Latency.hs | 9 ++++----- lib/shelley/exe/local-cluster.hs | 8 ++++---- lib/shelley/src/Cardano/Wallet/Shelley/Launch/Cluster.hs | 9 ++++++--- lib/shelley/test/integration/Main.hs | 5 ++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/shelley/bench/Latency.hs b/lib/shelley/bench/Latency.hs index cb2b64f079f..a77fdfdec00 100644 --- a/lib/shelley/bench/Latency.hs +++ b/lib/shelley/bench/Latency.hs @@ -451,19 +451,18 @@ withShelleyServer tracers action = do createDirectory db let logCfg = LogFileConfig Error Nothing Error let clusterCfg = LocalClusterConfig [] maxBound logCfg - withCluster nullTracer dir clusterCfg $ - onClusterStart act dir db + withCluster nullTracer dir clusterCfg (setupFaucet dir) $ + onClusterStart act db - setupFaucet conn dir = do + setupFaucet dir (RunningNode conn _ _) = do let encodeAddr = T.unpack . encodeAddress @'Mainnet let addresses = map (first encodeAddr) shelleyIntegrationTestFunds let addressesMA = map (first encodeAddr) (maryIntegrationTestAssets (Coin 10_000_000)) sendFaucetFundsTo nullTracer conn dir addresses sendFaucetAssetsTo nullTracer conn dir 20 addressesMA - onClusterStart act dir db (RunningNode conn block0 (np, vData)) = do + onClusterStart act db (RunningNode conn block0 (np, vData)) = do listen <- walletListenFromEnv - setupFaucet conn dir serveWallet (SomeNetworkDiscriminant $ Proxy @'Mainnet) tracers diff --git a/lib/shelley/exe/local-cluster.hs b/lib/shelley/exe/local-cluster.hs index 92d653e4804..d4c24cf378f 100644 --- a/lib/shelley/exe/local-cluster.hs +++ b/lib/shelley/exe/local-cluster.hs @@ -213,10 +213,11 @@ main = withLocalClusterSetup $ \dir clusterLogs walletLogs -> withLoggingNamed "cluster" clusterLogs $ \(_, (_, trCluster)) -> do let tr' = contramap MsgCluster $ trMessageText trCluster clusterCfg <- localClusterConfigFromEnv - withCluster tr' dir clusterCfg $ - whenReady dir (trMessageText trCluster) walletLogs + withCluster tr' dir clusterCfg + (setupFaucet dir (trMessageText trCluster)) + (whenReady dir (trMessageText trCluster) walletLogs) where - setupFaucet dir trCluster socketPath = do + setupFaucet dir trCluster (RunningNode socketPath _ _) = do traceWith trCluster MsgSettingUpFaucet let trCluster' = contramap MsgCluster trCluster let encodeAddresses = map (first (T.unpack . encodeAddress @'Mainnet)) @@ -231,7 +232,6 @@ main = withLocalClusterSetup $ \dir clusterLogs walletLogs -> whenReady dir trCluster logs (RunningNode socketPath block0 (gp, vData)) = withLoggingNamed "cardano-wallet" logs $ \(sb, (cfg, tr)) -> do - setupFaucet dir trCluster socketPath ekgEnabled >>= flip when (EKG.plugin cfg tr sb >>= loadPlugin sb) diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Launch/Cluster.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Launch/Cluster.hs index 33f63488cdc..4019904e84e 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Launch/Cluster.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Launch/Cluster.hs @@ -513,11 +513,12 @@ withCluster -- ^ Temporary directory to create config files in. -> LocalClusterConfig -- ^ The configurations of pools to spawn. + -> (RunningNode -> IO ()) + -- ^ Setup action to run using the BFT node. -> (RunningNode -> IO a) - -- ^ Action to run once we have transitioned to the Allegra era and cluster - -- nodes (stake pools and bft) are running. + -- ^ Action to run once when the stake pools are setup. -> IO a -withCluster tr dir LocalClusterConfig{..} onClusterStart = +withCluster tr dir LocalClusterConfig{..} onSetup onClusterStart = bracketTracer' tr "withCluster" $ do traceWith tr $ MsgStartingCluster dir resetGlobals @@ -530,6 +531,8 @@ withCluster tr dir LocalClusterConfig{..} onClusterStart = withBFTNode tr dir bftCfg $ \bftSocket block0 params -> do waitForSocket tr bftSocket + onSetup $ RunningNode bftSocket block0 params + (rawTx, faucetPrv) <- prepareKeyRegistration tr dir tx <- signTx tr dir rawTx [faucetPrv] submitTx tr bftSocket "pre-registered stake key" tx diff --git a/lib/shelley/test/integration/Main.hs b/lib/shelley/test/integration/Main.hs index efd3d636588..87ba2cf1052 100644 --- a/lib/shelley/test/integration/Main.hs +++ b/lib/shelley/test/integration/Main.hs @@ -312,12 +312,12 @@ specWithServer testDir (tr, tracers) = aroundAll withContext withServer dbDecorator onReady = bracketTracer' tr "withServer" $ withSMASH testDir $ \smashUrl -> do clusterCfg <- localClusterConfigFromEnv - withCluster tr' testDir clusterCfg $ + withCluster tr' testDir clusterCfg setupFaucet $ onClusterStart (onReady $ T.pack smashUrl) dbDecorator tr' = contramap MsgCluster tr encodeAddresses = map (first (T.unpack . encodeAddress @'Mainnet)) - setupFaucet conn = do + setupFaucet (RunningNode conn _ _) = do traceWith tr MsgSettingUpFaucet let rewards = (,Coin $ fromIntegral oneMillionAda) <$> concatMap genRewardAccounts mirMnemonics @@ -328,7 +328,6 @@ specWithServer testDir (tr, tracers) = aroundAll withContext encodeAddresses (maryIntegrationTestAssets (Coin 10_000_000)) onClusterStart action dbDecorator (RunningNode conn block0 (gp, vData)) = do - setupFaucet conn let db = testDir "wallets" createDirectory db listen <- walletListenFromEnv