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

Commit 99444a4

Browse files
committed
Display LoaderSyncing view while syncing filter headers
1 parent 3f5995a commit 99444a4

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

src/action/info.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class InfoAction {
2020
* Fetches the current details of the lnd node and sets the corresponding
2121
* store parameters. This api is polled at the beginning of app initialization
2222
* until lnd has finished syncing the chain to the connected bitcoin full node.
23+
* Since fetching filter headers can take a long time during initial sync, we
24+
* use the number of nodes from the network info api as a proxy if filter
25+
* headers are finished syncing and autopilot has enough nodes to start.
2326
* @return {Promise<undefined>}
2427
*/
2528
async getInfo() {
@@ -28,22 +31,28 @@ class InfoAction {
2831
this._store.pubKey = response.identity_pubkey;
2932
this._store.syncedToChain = response.synced_to_chain;
3033
this._store.blockHeight = response.block_height;
34+
const netRes = await this._grpc.sendCommand('getNetworkInfo');
35+
this._store.isSyncing = !response.synced_to_chain || netRes.num_nodes < 2;
3136
if (this.startingSyncTimestamp === undefined) {
3237
this.startingSyncTimestamp = response.best_header_timestamp || 0;
3338
}
34-
if (!response.synced_to_chain) {
39+
if (this._store.isSyncing) {
3540
this._notification.display({ msg: 'Syncing to chain', wait: true });
36-
log.info(`Syncing to chain ... block height: ${response.block_height}`);
41+
log.info(
42+
`Syncing to chain ...`,
43+
`block height: ${response.block_height}`,
44+
`num nodes: ${netRes.num_nodes}`
45+
);
3746
this._store.percentSynced = this.calcPercentSynced(response);
3847
}
39-
return response.synced_to_chain;
48+
return !this._store.isSyncing;
4049
} catch (err) {
4150
log.error('Getting node info failed', err);
4251
}
4352
}
4453

4554
/**
46-
* Poll the getInfo api until synced_to_chain is true.
55+
* Poll the getInfo api until isSyncing is false.
4756
* @return {Promise<undefined>}
4857
*/
4958
async pollInfo() {
@@ -62,7 +71,7 @@ class InfoAction {
6271
this._nav.goHome();
6372
} else {
6473
this._nav.goLoaderSyncing();
65-
observe(this._store, 'syncedToChain', () => this._nav.goHome());
74+
observe(this._store, 'isSyncing', () => this._nav.goHome());
6675
}
6776
}
6877

@@ -80,7 +89,8 @@ class InfoAction {
8089
: 0;
8190
const totalProgress = currTimestamp - this.startingSyncTimestamp || 0.001;
8291
const percentSynced = progressSoFar * 1.0 / totalProgress;
83-
return percentSynced;
92+
// TODO: display max 0.9 until we have progress for fetching filter headers
93+
return percentSynced * 0.9;
8494
}
8595
}
8696

src/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class Store {
2525
walletUnlocked: false, // Is the wallet unlocked
2626
lndReady: false, // Is lnd process running
2727
syncedToChain: false, // Is lnd synced to blockchain
28+
isSyncing: false, // Is lnd syncing to chain or filter headers
2829
percentSynced: 0, // Expects 0-1 range
2930
route: DEFAULT_ROUTE,
3031
blockHeight: null,

test/unit/action/info.spec.js

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,41 +33,65 @@ describe('Action Info Unit Tests', () => {
3333
it('should get public key, synced to chain, and block height', async () => {
3434
grpc.sendCommand.withArgs('getInfo').resolves({
3535
identity_pubkey: 'some-pubkey',
36-
synced_to_chain: 'true/false',
36+
synced_to_chain: true,
3737
block_height: 'some-height',
3838
});
39+
grpc.sendCommand.withArgs('getNetworkInfo').resolves({
40+
num_nodes: 2,
41+
});
3942
await info.getInfo();
4043
expect(store.pubKey, 'to equal', 'some-pubkey');
41-
expect(store.syncedToChain, 'to equal', 'true/false');
44+
expect(store.syncedToChain, 'to be', true);
45+
expect(store.isSyncing, 'to be', false);
4246
expect(store.blockHeight, 'to equal', 'some-height');
4347
});
4448

45-
it('should return true if chain is synced', async () => {
49+
it('should return true if chain and filter headers are synced', async () => {
4650
grpc.sendCommand.withArgs('getInfo').resolves({
4751
synced_to_chain: true,
4852
});
53+
grpc.sendCommand.withArgs('getNetworkInfo').resolves({
54+
num_nodes: 2,
55+
});
4956
const synced = await info.getInfo();
5057
expect(synced, 'to be', true);
5158
});
5259

53-
it('should set percentSynced', async () => {
54-
const testTimestamp = new Date().getTime();
60+
it('should return false if chain is synced but not filter headers', async () => {
5561
grpc.sendCommand.withArgs('getInfo').resolves({
56-
synced_to_chain: false,
57-
best_header_timestamp: testTimestamp / 1000,
62+
synced_to_chain: true,
5863
});
59-
await info.getInfo();
60-
expect(store.percentSynced, 'to be within', 0, 1);
64+
grpc.sendCommand.withArgs('getNetworkInfo').resolves({
65+
num_nodes: 1,
66+
});
67+
const synced = await info.getInfo();
68+
expect(synced, 'to be', false);
6169
});
6270

63-
it('should return false if chain is not synced', async () => {
71+
it('should return false if chain is not synced but filter headers are', async () => {
6472
grpc.sendCommand.withArgs('getInfo').resolves({
6573
synced_to_chain: false,
6674
});
75+
grpc.sendCommand.withArgs('getNetworkInfo').resolves({
76+
num_nodes: 2,
77+
});
6778
const synced = await info.getInfo();
6879
expect(synced, 'to be', false);
6980
});
7081

82+
it('should set percentSynced', async () => {
83+
const testTimestamp = new Date().getTime();
84+
grpc.sendCommand.withArgs('getInfo').resolves({
85+
synced_to_chain: false,
86+
best_header_timestamp: testTimestamp / 1000,
87+
});
88+
grpc.sendCommand.withArgs('getNetworkInfo').resolves({
89+
num_nodes: 2,
90+
});
91+
await info.getInfo();
92+
expect(store.percentSynced, 'to be within', 0, 1);
93+
});
94+
7195
it('should log error on failure', async () => {
7296
grpc.sendCommand.rejects();
7397
await info.getInfo();
@@ -89,6 +113,9 @@ describe('Action Info Unit Tests', () => {
89113
grpc.sendCommand.withArgs('getInfo').resolves({
90114
synced_to_chain: 'true',
91115
});
116+
grpc.sendCommand.withArgs('getNetworkInfo').resolves({
117+
num_nodes: 2,
118+
});
92119
await info.getInfo();
93120
info.initLoaderSyncing();
94121
expect(nav.goHome, 'was called once');
@@ -98,12 +125,18 @@ describe('Action Info Unit Tests', () => {
98125
grpc.sendCommand.withArgs('getInfo').resolves({
99126
synced_to_chain: false,
100127
});
128+
grpc.sendCommand.withArgs('getNetworkInfo').resolves({
129+
num_nodes: 1,
130+
});
101131
await info.getInfo();
102132
info.initLoaderSyncing();
103133
expect(nav.goLoaderSyncing, 'was called once');
104134
grpc.sendCommand.withArgs('getInfo').resolves({
105135
synced_to_chain: true,
106136
});
137+
grpc.sendCommand.withArgs('getNetworkInfo').resolves({
138+
num_nodes: 2,
139+
});
107140
await info.getInfo();
108141
expect(nav.goHome, 'was called once');
109142
});

0 commit comments

Comments
 (0)