Skip to content

Commit

Permalink
Merge #1009
Browse files Browse the repository at this point in the history
1009: Start IPC channel as soon as the wallet BE socket is available r=KtorZ a=KtorZ



# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->


# Overview

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

- [x] I have revised the starting order and "dependencies" to make sure that the DaedalusIPC server is started as soon as we know the wallet server port, and before we try to setup the networking layer. 

- [x] reviewed the starting logic with Daedalus team who confirmed that they have error-handling mechanism in place to actually repeatedly poll the API server after a "Started" message is received via IPC. This is necessary since we'll now be starting the IPC channel much before the API is actually ready. 

- [x] Since we have disabled the IPC tests in CI, I've made sure they still pass locally.

# Comments

<!-- 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
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: KtorZ <[email protected]>
  • Loading branch information
iohk-bors[bot] and KtorZ authored Nov 12, 2019
2 parents 7054d56 + f8cf1ff commit 2ecc806
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions lib/jormungandr/src/Cardano/Wallet/Jormungandr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import Cardano.Wallet.Transaction
import Control.Concurrent
( forkFinally )
import Control.Concurrent.Async
( race_ )
( Async, async, waitEither_ )
import Control.DeepSeq
( NFData )
import Control.Monad
Expand All @@ -109,7 +109,7 @@ import Data.Text
import Data.Text.Class
( ToText (..), showT )
import Network.Socket
( SockAddr, getSocketName )
( SockAddr, Socket, getSocketName )
import Network.Wai.Handler.Warp
( setBeforeMainLoop )
import System.Exit
Expand Down Expand Up @@ -156,43 +156,43 @@ serveWallet (cfg, tr) sTolerance databaseDir hostPref listen lj beforeMainLoop =
installSignalHandlers tr
logInfo tr "Wallet backend server starting..."
logInfo tr $ "Node is Jörmungandr on " <> toText (networkDiscriminantVal @n)
withNetworkLayer tr lj $ \case
Right (cp, nl) -> do
let nPort = Port $ baseUrlPort $ _restApi cp
let (_, bp) = staticBlockchainParameters nl
let rndTl = newTransactionLayer @'Mainnet (getGenesisBlockHash bp)
let seqTl = newTransactionLayer @n (getGenesisBlockHash bp)
let poolDBPath = Pool.defaultFilePath <$> databaseDir
Pool.withDBLayer cfg tr poolDBPath $ \db -> do
spl <- stakePoolLayer tr nl db
rndApi <- apiLayer tr rndTl nl
seqApi <- apiLayer tr seqTl nl
startServer tr nPort bp rndApi seqApi spl
Left e -> handleNetworkStartupError e
Server.withListeningSocket hostPref listen $ \case
Left e -> handleApiServerStartupError e
Right (wPort, socket) -> do
let tracerIPC = appendName "daedalus-ipc" tr
ipcServer <- async $ daedalusIPC tracerIPC wPort
withNetworkLayer tr lj $ \case
Left e -> handleNetworkStartupError e
Right (cp, nl) -> do
let nPort = Port $ baseUrlPort $ _restApi cp
let (_, bp) = staticBlockchainParameters nl
let rndTl = newTransactionLayer @'Mainnet (getGenesisBlockHash bp)
let seqTl = newTransactionLayer @n (getGenesisBlockHash bp)
let poolDBPath = Pool.defaultFilePath <$> databaseDir
Pool.withDBLayer cfg tr poolDBPath $ \db -> do
poolApi <- stakePoolLayer tr nl db
rndApi <- apiLayer tr rndTl nl
seqApi <- apiLayer tr seqTl nl
apiServer <- startServer
tr socket nPort bp rndApi seqApi poolApi
waitEither_ ipcServer apiServer
pure ExitSuccess
where
startServer
:: Trace IO Text
-> Socket
-> Port "node"
-> BlockchainParameters
-> ApiLayer (RndState 'Mainnet) t ByronKey
-> ApiLayer (SeqState n ShelleyKey) t ShelleyKey
-> StakePoolLayer IO
-> IO ExitCode
startServer tracer nPort bp rndWallet seqWallet spl = do
Server.withListeningSocket hostPref listen $ \case
Right (wPort, socket) -> do
sockAddr <- getSocketName socket
let tracerIPC = appendName "daedalus-ipc" tracer
let tracerApi = appendName "api" tracer
let settings = Warp.defaultSettings
& setBeforeMainLoop (beforeMainLoop sockAddr nPort bp)
let ipcServer = daedalusIPC tracerIPC wPort
let apiServer =
Server.start
settings tracerApi socket rndWallet seqWallet spl
race_ ipcServer apiServer
pure ExitSuccess
Left e -> handleApiServerStartupError e
-> IO (Async ())
startServer tracer socket nPort bp rndApi seqApi poolApi = do
sockAddr <- getSocketName socket
let tracerApi = appendName "api" tracer
let settings = Warp.defaultSettings
& setBeforeMainLoop (beforeMainLoop sockAddr nPort bp)
async $ Server.start settings tracerApi socket rndApi seqApi poolApi

apiLayer
:: forall s k.
Expand Down

0 comments on commit 2ecc806

Please sign in to comment.