From bfb8b6d86e9a9fbdae3b789976f74a225b5f55f2 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Tue, 4 Sep 2018 19:41:17 +0200 Subject: [PATCH] fix(fsm): ensure lnd connect before state change Ensure that a failed lnd connection attempt prevents the FSM from changing state by moving the connect handlers to the `onBefore` lifecycle events. See https://github.com/jakesgordon/javascript-state-machine/blob/master/docs/lifecycle-events.md#cancelling-a-transition Fix #739 --- app/lib/zap/controller.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/lib/zap/controller.js b/app/lib/zap/controller.js index 2387f280..6484e553 100644 --- a/app/lib/zap/controller.js +++ b/app/lib/zap/controller.js @@ -147,8 +147,8 @@ class ZapController { this.sendMessage('startOnboarding', this.lndConfig) } - onStartLnd() { - mainLog.debug('[FSM] onStartLnd...') + onBeforeStartLnd() { + mainLog.debug('[FSM] onBeforeStartLnd...') return isLndRunning().then(res => { if (res) { @@ -168,8 +168,8 @@ class ZapController { }) } - onConnectLnd() { - mainLog.debug('[FSM] onConnectLnd...') + onBeforeConnectLnd() { + mainLog.debug('[FSM] onBeforeConnectLnd...') mainLog.info('Connecting to custom lnd instance') mainLog.info(' > host:', this.lndConfig.host) mainLog.info(' > cert:', this.lndConfig.cert) @@ -197,7 +197,8 @@ class ZapController { } // Notify the app of errors. - return this.sendMessage('startLndError', errors) + this.sendMessage('startLndError', errors) + throw e }) }