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

Commit eef8d1e

Browse files
Merge pull request #3562 from input-output-hk/adinapoli/cbr-377/replace-new-wallet-flag
[CBR-377] Replace `--new-wallet` flag
2 parents 6327379 + e6717a9 commit eef8d1e

File tree

8 files changed

+58
-17
lines changed

8 files changed

+58
-17
lines changed

wallet-new/server/Main.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ actionWithWallet coreConfig txpConfig sscParams nodeParams ntpConfig params =
183183
-- Periodically compact & snapshot the acid-state database.
184184
, Plugins.acidStateSnapshots (view Kernel.Internal.wallets (snd w)) params dbMode
185185

186-
-- | A @Plugin@ to notify frontend via websockets.
187-
, Plugins.updateNotifier
186+
-- | A @Plugin@ to watch and store incoming update proposals
187+
, Plugins.updateWatcher
188188
]
189189

190190
-- Extract the logger name from node parameters

wallet-new/src/Cardano/Wallet/Server/CLI.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ chooseWalletBackendParser :: Parser ChooseWalletBackend
123123
chooseWalletBackendParser = choose
124124
<$> walletBackendParamsParser
125125
<*> (switch $ mconcat [
126-
long "new-wallet"
127-
, help "Use the new wallet implementation (NOT FOR PRODUCTION USE)"
126+
long "legacy-wallet"
127+
, help "Use the legacy wallet implementation (NOT RECOMMENDED)"
128128
])
129129
where
130-
choose opts False = WalletLegacy $ opts
131-
choose opts True = WalletNew $ NewWalletBackendParams opts
130+
choose opts True = WalletLegacy $ opts
131+
choose opts False = WalletNew $ NewWalletBackendParams opts
132132

133133
-- | The @Parser@ for the @WalletBackendParams@.
134134
walletBackendParamsParser :: Parser WalletBackendParams

wallet-new/src/Cardano/Wallet/Server/LegacyPlugins.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ import qualified Servant
4848
import Pos.Context (HasNodeContext)
4949
import Pos.Core as Core (Config)
5050
import Pos.Util (lensOf)
51-
import Pos.Util.Wlog (logInfo, modifyLoggerName, usingLoggerName)
51+
import Pos.Util.Wlog (logInfo, logWarning, modifyLoggerName,
52+
usingLoggerName)
5253

5354
import Cardano.NodeIPC (startNodeJsIPC)
5455
import Pos.Configuration (walletProductionApi,
@@ -115,6 +116,7 @@ legacyWalletBackend :: (HasConfigurations, HasCompileInfo)
115116
-> Plugin WalletWebMode
116117
legacyWalletBackend coreConfig txpConfig WalletBackendParams {..} ntpStatus = pure $ \diffusion -> do
117118
modifyLoggerName (const "legacyServantBackend") $ do
119+
logWarning $ sformat "RUNNING THE OLD LEGACY DATA LAYER IS NOT RECOMMENDED!"
118120
logInfo $ sformat ("Production mode for API: "%build)
119121
walletProductionApi
120122
logInfo $ sformat ("Transaction submission disabled: "%build)

wallet-new/src/Cardano/Wallet/Server/Plugins.hs

+13-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Cardano.Wallet.Server.Plugins
99
, docServer
1010
, monitoringServer
1111
, acidStateSnapshots
12-
, updateNotifier
12+
, updateWatcher
1313
) where
1414

1515
import Universum
@@ -30,14 +30,14 @@ import Cardano.Wallet.Server.CLI (NewWalletBackendParams (..),
3030
isDebugMode, walletAcidInterval)
3131
import Cardano.Wallet.WalletLayer (ActiveWalletLayer,
3232
PassiveWalletLayer)
33+
import Pos.Chain.Update (cpsSoftwareVersion)
3334
import Pos.Crypto (ProtocolMagic)
3435
import Pos.Infra.Diffusion.Types (Diffusion (..))
3536
import Pos.Infra.Shutdown (HasShutdownContext (shutdownContext),
3637
ShutdownContext)
3738
import Pos.Launcher.Configuration (HasConfigurations)
3839
import Pos.Util.CompileInfo (HasCompileInfo)
39-
import Pos.Util.Wlog (logError, logInfo, modifyLoggerName,
40-
usingLoggerName)
40+
import Pos.Util.Wlog (logInfo, modifyLoggerName, usingLoggerName)
4141
import Pos.Web (serveDocImpl, serveImpl)
4242
import qualified Pos.Web.Server
4343

@@ -46,6 +46,7 @@ import qualified Cardano.Wallet.Kernel.Mode as Kernel
4646
import qualified Cardano.Wallet.Server as Server
4747
import Cardano.Wallet.Server.Plugins.AcidState
4848
(createAndArchiveCheckpoints)
49+
import qualified Cardano.Wallet.WalletLayer as WalletLayer
4950
import qualified Cardano.Wallet.WalletLayer.Kernel as WalletLayer.Kernel
5051
import qualified Data.ByteString.Char8 as BS8
5152
import qualified Servant
@@ -158,8 +159,12 @@ acidStateSnapshots dbRef params dbMode = pure $ \_diffusion -> do
158159
(walletAcidInterval opts)
159160
dbMode
160161

161-
-- | A @Plugin@ to notify frontend via websockets.
162-
updateNotifier :: Plugin Kernel.WalletMode
163-
updateNotifier = [
164-
\_diffusion -> logError "Not Implemented: updateNotifier [CBR-374]"
165-
]
162+
-- | A @Plugin@ to store updates proposal received from the blockchain
163+
updateWatcher :: Plugin Kernel.WalletMode
164+
updateWatcher = pure $ \_diffusion -> do
165+
modifyLoggerName (const "update-watcher-plugin") $ do
166+
w <- Kernel.getWallet
167+
forever $ liftIO $ do
168+
newUpdate <- WalletLayer.waitForUpdate w
169+
logInfo "A new update was found!"
170+
WalletLayer.addUpdate w . cpsSoftwareVersion $ newUpdate

wallet-new/src/Cardano/Wallet/WalletLayer.hs

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Test.QuickCheck (Arbitrary (..), oneof)
3434

3535
import Pos.Chain.Block (Blund)
3636
import Pos.Chain.Txp (Tx, TxId, Utxo)
37+
import Pos.Chain.Update (ConfirmedProposalState)
3738
import Pos.Core (Coin, Timestamp)
3839
import Pos.Core.Chrono (NE, NewestFirst (..), OldestFirst (..))
3940
import Pos.Core.Update (SoftwareVersion)
@@ -463,6 +464,10 @@ data PassiveWalletLayer m = PassiveWalletLayer
463464
, postponeUpdate :: m ()
464465
, resetWalletState :: m ()
465466
, importWallet :: WalletImport -> m (Either ImportWalletError Wallet)
467+
468+
-- updates
469+
, waitForUpdate :: m ConfirmedProposalState
470+
, addUpdate :: SoftwareVersion -> m ()
466471
}
467472

468473
------------------------------------------------------------

wallet-new/src/Cardano/Wallet/WalletLayer/Kernel.hs

+2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ bracketPassiveWallet mode logFunction keystore node f = do
7171
, updateAccount = Accounts.updateAccount w
7272
, deleteAccount = Accounts.deleteAccount w
7373
, createAddress = Addresses.createAddress w
74+
, addUpdate = Internal.addUpdate w
7475
, nextUpdate = Internal.nextUpdate w
7576
, applyUpdate = Internal.applyUpdate w
7677
, postponeUpdate = Internal.postponeUpdate w
78+
, waitForUpdate = Internal.waitForUpdate w
7779
, resetWalletState = Internal.resetWalletState w
7880
, importWallet = Internal.importWallet w
7981
, applyBlocks = invokeIO . Actions.ApplyBlocks

wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Internal.hs

+18-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ module Cardano.Wallet.WalletLayer.Kernel.Internal (
44
, postponeUpdate
55
, resetWalletState
66
, importWallet
7+
8+
, waitForUpdate
9+
, addUpdate
710
) where
811

912
import Universum
@@ -12,12 +15,13 @@ import Control.Concurrent.MVar (modifyMVar_)
1215
import Data.Acid.Advanced (update')
1316
import System.IO.Error (isDoesNotExistError)
1417

18+
import Pos.Chain.Update (ConfirmedProposalState)
1519
import Pos.Core.Update (SoftwareVersion)
1620

1721
import Cardano.Wallet.API.V1.Types (V1 (..), Wallet,
1822
WalletImport (..))
19-
import Cardano.Wallet.Kernel.DB.AcidState (ClearDB (..),
20-
GetNextUpdate (..), RemoveNextUpdate (..))
23+
import Cardano.Wallet.Kernel.DB.AcidState (AddUpdate (..),
24+
ClearDB (..), GetNextUpdate (..), RemoveNextUpdate (..))
2125
import Cardano.Wallet.Kernel.DB.InDb
2226
import Cardano.Wallet.Kernel.DB.TxMeta
2327
import qualified Cardano.Wallet.Kernel.Internal as Kernel
@@ -67,6 +71,18 @@ applyUpdate w = liftIO $ do
6771
postponeUpdate :: MonadIO m => Kernel.PassiveWallet -> m ()
6872
postponeUpdate w = update' (w ^. Kernel.wallets) $ RemoveNextUpdate
6973

74+
-- | Wait for an update notification
75+
waitForUpdate :: MonadIO m => Kernel.PassiveWallet -> m ConfirmedProposalState
76+
waitForUpdate w = liftIO $
77+
Node.withNodeState (w ^. Kernel.walletNode) $ \_lock ->
78+
Node.waitForUpdate
79+
80+
-- | Add an update in the DB, this is triggered by the notifier once getting
81+
-- a new proposal from the blockchain
82+
addUpdate :: MonadIO m => Kernel.PassiveWallet -> SoftwareVersion -> m ()
83+
addUpdate w v = liftIO $
84+
update' (w ^. Kernel.wallets) $ AddUpdate (InDb v)
85+
7086
-- | Reset wallet state
7187
resetWalletState :: MonadIO m => Kernel.PassiveWallet -> m ()
7288
resetWalletState w = liftIO $ do

wallet-new/test/Cardano/Wallet/WalletLayer/QuickCheck.hs

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Cardano.Wallet.WalletLayer (ActiveWalletLayer (..),
2121

2222
import Cardano.Wallet.API.V1.Types (V1 (..))
2323

24+
import Pos.Chain.Update (ConfirmedProposalState)
2425
import Pos.Core ()
2526
import Test.Pos.Chain.Txp.Arbitrary ()
2627
import Test.QuickCheck (Arbitrary (..), arbitrary, generate, oneof)
@@ -71,6 +72,9 @@ bracketPassiveWallet =
7172
, postponeUpdate = liftedGen
7273
, resetWalletState = liftedGen
7374
, importWallet = \_ -> liftedGen
75+
76+
, waitForUpdate = liftedGen
77+
, addUpdate = \_ -> liftedGen
7478
}
7579

7680
-- | A utility function.
@@ -163,3 +167,10 @@ instance Arbitrary ImportWalletError where
163167
, ImportWalletNoWalletFoundInBackup <$> arbitrary
164168
, ImportWalletCreationFailed <$> arbitrary
165169
]
170+
171+
-- This is obviously not a valid 'Arbitrary' instance, but one will be provided
172+
-- when we will be start using this 'WalletLayer' implementation. Note how the
173+
-- core layer already provides one, it's just a matter of exposing it to other
174+
-- components and use it.
175+
instance Arbitrary ConfirmedProposalState where
176+
arbitrary = oneof []

0 commit comments

Comments
 (0)