Skip to content

Commit

Permalink
Merge #1315 #1321
Browse files Browse the repository at this point in the history
1315: Add shutdown handler for new launcher r=KtorZ a=rvl

Relates to #1314.

# Overview

This adds a simpler way of ensuring clean shutdown of the wallet on windows (and linux), which doesn't require DaedalusIPC. The mechanism will be used by cardano-launcher.

- Adds the shutdown handler thread.
- Needed to rearrange startup functions around a little bit.
- Unit tests and an integration test.

# Comments

[Hydra jobset](https://hydra.iohk.io/jobset/Cardano/cardano-wallet-pr-1315)


1321: Add CLI command for extracting root xprvs r=Anviking a=Anviking

# Issue Number

#1316 


# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] I have added `cardano-wallet-jormungandr key root --type random <mnemonic words>`
- [x] I added unit tests for help-text and actual usage.
- [x] I added a *pending* test making sure keys are compatible with jcli (which would fail)

# Comments

```bash
$ cardano-wallet-jormungandr key --help
Usage: cardano-wallet-jormungandr key COMMAND
  Derive keys from mnemonics.

Available options:
  -h,--help                Show this help text

Available commands:
  root                     Extract root xprv as hex (64 bytes private key + 32
                           bytes chain code)
$ cardano-wallet-jormungandr key root --help
Usage: cardano-wallet-jormungandr key root --type KEYTYPE MNEMONIC_WORDS...
  Extract root xprv as hex (64 bytes private key + 32 bytes chain code)

Available options:
  -h,--help                Show this help text
  --type KEYTYPE           Any of the following:
                             random (Daedalus, 12 words)
                             icarus (15 words)
                             trezor (12, 15, 18, 21, or 24 words)
                             ledger (12, 15, 18, 21, or 24 words)
$ cardano-wallet-jormungandr key root --type random flock advance execute country leader exotic mix twenty six margin orient meat
68a0f29e6bd5d8af7ffd00a55006afa8af6fbdbded07984ddf7fb1c31c66f7460685e5d1016553fccc9724f5ee95dd8d66facd2ac1bb2f6fcd7fa5e53c97a57f50c592fcd18b67bf3393a16184d009fb25450b2de8079f870222874e804584a8
```

<!-- Additional comments or screenshots to attach if any -->

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Rodney Lorrimar <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: Johannes Lund <[email protected]>
  • Loading branch information
4 people authored Feb 26, 2020
3 parents 8857410 + 3003a3a + c9fa75e commit 4984781
Show file tree
Hide file tree
Showing 37 changed files with 1,359 additions and 212 deletions.
3 changes: 1 addition & 2 deletions .weeder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,4 @@
- name: library
- message:
- name: Module not compiled
- module: Cardano.Launcher.Windows

- module: Cardano.Startup.Windows
2 changes: 2 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ let
haskellBuildUtils = haskellBuildUtils.package;
};

inherit (haskellPackages.cardano-wallet-byron.components.exes) cardano-wallet-byron;

# `tests` are the test suites which have been built.
tests = collectComponents "tests" isCardanoWallet haskellPackages;
# `checks` are the result of executing the tests.
Expand Down
2 changes: 1 addition & 1 deletion lib/byron/cardano-wallet-byron.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ library
, cardano-crypto-wrapper
, cardano-ledger
, cardano-wallet-core
, cardano-wallet-launcher
, cborg
, contra-tracer
, cryptonite
Expand Down Expand Up @@ -88,6 +87,7 @@ executable cardano-wallet-byron
, cardano-wallet-cli
, cardano-wallet-core
, cardano-wallet-launcher
, contra-tracer
, iohk-monitoring
, network
, optparse-applicative
Expand Down
44 changes: 30 additions & 14 deletions lib/byron/exe/cardano-wallet-byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Prelude
import Cardano.BM.Data.Severity
( Severity (..) )
import Cardano.BM.Trace
( Trace, appendName, logDebug, logInfo )
( Trace, appendName, logDebug, logInfo, logNotice )
import Cardano.CLI
( LoggingOptions (..)
, cli
Expand All @@ -50,8 +50,12 @@ import Cardano.CLI
, syncToleranceOption
, withLogging
)
import Cardano.Launcher
( withUtf8Encoding )
import Cardano.Startup
( ShutdownHandlerLog
, installSignalHandlers
, withShutdownHandler
, withUtf8Encoding
)
import Cardano.Wallet.Api.Server
( HostPreference, Listen (..) )
import Cardano.Wallet.Byron
Expand All @@ -66,7 +70,7 @@ import Cardano.Wallet.Byron
import Cardano.Wallet.Byron.Network
( localSocketAddrInfo )
import Cardano.Wallet.Logging
( transformTextTrace )
( trMessage, transformTextTrace )
import Cardano.Wallet.Primitive.AddressDerivation
( NetworkDiscriminant (..) )
import Cardano.Wallet.Primitive.Types
Expand All @@ -75,6 +79,10 @@ import Cardano.Wallet.Version
( GitRevision, Version, gitRevision, showFullVersion, version )
import Control.Applicative
( Const (..), optional )
import Control.Monad
( void )
import Control.Tracer
( contramap )
import Data.Text
( Text )
import Data.Text.Class
Expand Down Expand Up @@ -160,16 +168,18 @@ cmdServe = command "serve" $ info (helper <*> helper' <*> cmd) $ mempty
exec args@(ServeArgs hostPreference listen nodeSocket databaseDir sTolerance logOpt) = do
let addrInfo = localSocketAddrInfo nodeSocket
withTracers logOpt $ \tr tracers -> do
logDebug tr $ MsgServeArgs args
whenJust databaseDir $ setupDirectory (logInfo tr . MsgSetupDatabases)
exitWith =<< serveWallet @'Mainnet
tracers
sTolerance
databaseDir
hostPreference
listen
addrInfo
(beforeMainLoop tr)
installSignalHandlers (logNotice tr MsgSigTerm)
void $ withShutdownHandler (trMessage (contramap (fmap MsgShutdownHandler) tr)) $ do
logDebug tr $ MsgServeArgs args
whenJust databaseDir $ setupDirectory (logInfo tr . MsgSetupDatabases)
exitWith =<< serveWallet @'Mainnet
tracers
sTolerance
databaseDir
hostPreference
listen
addrInfo
(beforeMainLoop tr)

whenJust m fn = case m of
Nothing -> pure ()
Expand Down Expand Up @@ -212,6 +222,8 @@ data MainLog
| MsgSetupDatabases Text
| MsgServeArgs ServeArgs
| MsgListenAddress SockAddr
| MsgSigTerm
| MsgShutdownHandler ShutdownHandlerLog
deriving (Show, Eq)

instance ToText MainLog where
Expand All @@ -228,6 +240,10 @@ instance ToText MainLog where
T.pack $ show args
MsgListenAddress addr ->
"Wallet backend server listening on " <> T.pack (show addr)
MsgSigTerm ->
"Terminated by signal."
MsgShutdownHandler msg' ->
toText msg'

withTracers
:: LoggingOptions TracerSeverities
Expand Down
7 changes: 0 additions & 7 deletions lib/byron/src/Cardano/Wallet/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ import Cardano.BM.Trace
( Trace, appendName )
import Cardano.DB.Sqlite
( DBLog )
import Cardano.Launcher
( installSignalHandlers )
import Cardano.Wallet
( WalletLog )
import Cardano.Wallet.Api
Expand Down Expand Up @@ -166,7 +164,6 @@ serveWallet
-- ^ Callback to run before the main loop
-> IO ExitCode
serveWallet Tracers{..} sTolerance databaseDir hostPref listen addrInfo beforeMainLoop = do
installSignalHandlers (traceWith applicationTracer MsgSigTerm)
traceWith applicationTracer $ MsgStarting addrInfo
traceWith applicationTracer $ MsgNetworkName $ networkDiscriminantVal @n
Server.withListeningSocket hostPref listen $ \case
Expand Down Expand Up @@ -245,7 +242,6 @@ exitCodeApiServer = \case
data ApplicationLog
= MsgStarting AddrInfo
| MsgNetworkName NetworkDiscriminant
| MsgSigTerm
| MsgServerStartupError ListenError
| MsgDatabaseStartup DatabasesStartupLog
deriving (Generic, Show, Eq)
Expand All @@ -256,8 +252,6 @@ instance ToText ApplicationLog where
"Wallet backend server starting. " <> T.pack (show info) <> "..."
MsgNetworkName n ->
"Node is Haskell Node on " <> toText n
MsgSigTerm ->
"Terminated by signal."
MsgDatabaseStartup dbMsg ->
toText dbMsg
MsgServerStartupError startupErr -> case startupErr of
Expand All @@ -281,7 +275,6 @@ instance DefinePrivacyAnnotation ApplicationLog
instance DefineSeverity ApplicationLog where
defineSeverity = \case
MsgStarting _ -> Info
MsgSigTerm -> Notice
MsgNetworkName _ -> Info
MsgDatabaseStartup ev -> defineSeverity ev
MsgServerStartupError _ -> Alert
Expand Down
3 changes: 3 additions & 0 deletions lib/cli/cardano-wallet-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ library
, fmt
, http-client
, iohk-monitoring
, memory
, servant-client
, servant-client-core
, text
Expand All @@ -69,12 +70,14 @@ test-suite unit
-Werror
build-depends:
base
, bytestring
, cardano-wallet-cli
, cardano-wallet-core
, filepath
, hspec
, optparse-applicative
, QuickCheck
, silently
, temporary
, text
, text-class
Expand Down
Loading

0 comments on commit 4984781

Please sign in to comment.