Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 50a496c

Browse files
authored
Merge pull request #1061 from lightninglabs/fix-autopilot-race-condition
Prevent autopilot race condition when initiating
2 parents fa9dbfb + aa400dc commit 50a496c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/action/autopilot.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ class AtplAction {
3636
* @return {Promise<undefined>}
3737
*/
3838
async toggle() {
39-
const success = await this._setStatus(!this._store.settings.autopilot);
39+
const newState = !this._store.settings.autopilot;
40+
const success = await this._setStatus(newState);
4041
if (success) {
41-
this._store.settings.autopilot = !this._store.settings.autopilot;
42+
this._store.settings.autopilot = newState;
4243
this._db.save();
4344
}
4445
}

src/action/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ when(
8989
* lnd node all balances, channels and transactions are fetched.
9090
*/
9191
when(
92-
() => store.lndReady && store.autopilotReady,
92+
() => store.lndReady,
9393
() => {
94-
autopilot.init();
9594
wallet.pollBalances();
9695
wallet.pollExchangeRate();
9796
channel.pollChannels();
@@ -101,3 +100,15 @@ when(
101100
info.pollInfo();
102101
}
103102
);
103+
104+
/**
105+
* Initialize autopilot after syncing is finished and the grpc client
106+
* is ready
107+
*/
108+
when(
109+
() => store.syncedToChain && store.autopilotReady,
110+
async () => {
111+
await nap();
112+
autopilot.init();
113+
}
114+
);

0 commit comments

Comments
 (0)