From 90c07dfb164fbb93c0b423fa43db2c1dd4fdedfb Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Sun, 4 Oct 2020 00:38:21 +0100 Subject: [PATCH 1/3] perf(wallet): fetch peer node info early --- renderer/reducers/peers.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/renderer/reducers/peers.js b/renderer/reducers/peers.js index 7519ffab700..c2b3d2dde65 100644 --- a/renderer/reducers/peers.js +++ b/renderer/reducers/peers.js @@ -1,5 +1,7 @@ import { grpc } from 'workers' +import { mainLog } from '@zap/utils/log' import createReducer from '@zap/utils/createReducer' +import { updateNodeData } from 'reducers/network' // ------------------------------------ // Initial State @@ -32,6 +34,14 @@ export const fetchPeers = () => async dispatch => { dispatch({ type: FETCH_PEERS }) try { const { peers } = await grpc.services.Lightning.listPeers() + peers.forEach(async ({ pubKey }) => { + try { + const { node } = await grpc.services.Lightning.getNodeInfo({ pubKey }) + dispatch(updateNodeData([node])) + } catch (error) { + mainLog.warn('Unable to get node info for peer %s: %s', pubKey, error) + } + }) dispatch({ type: FETCH_PEERS_SUCCESS, peers }) } catch (error) { dispatch({ type: FETCH_PEERS_FAILURE, error }) From 7de0e9b133240be34edc10f2913ea0bc83db31fe Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Sun, 4 Oct 2020 01:04:55 +0100 Subject: [PATCH 2/3] perf(wallet): remove redundent data fetch on wallet init --- renderer/components/App/App.js | 23 ++++++++++------------- renderer/containers/App/App.js | 2 ++ renderer/reducers/info/selectors.js | 13 +++++++++++-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/renderer/components/App/App.js b/renderer/components/App/App.js index 398cf0de884..fee97aa61e5 100644 --- a/renderer/components/App/App.js +++ b/renderer/components/App/App.js @@ -39,6 +39,7 @@ const App = ({ fetchTransactions, setModals, initBackupService, + isSyncedToGraph, fetchSuggestedNodes, initTickers, lnurlAuthParams, @@ -60,41 +61,31 @@ const App = ({ * node data quite frequently but as time goes on the frequency is reduced to a max of PEERS_MAX_REFETCH_INTERVAL */ appScheduler.addTask({ - task: () => fetchDescribeNetwork() && fetchPeers(), + task: () => !isSyncedToGraph && fetchDescribeNetwork(), taskId: 'fetchNetworkData', baseDelay: PEERS_INITIAL_REFETCH_INTERVAL, maxDelay: PEERS_MAX_REFETCH_INTERVAL, backoff: PEERS_REFETCH_BACKOFF_SCHEDULE, }) - appScheduler.addTask({ task: () => fetchTransactions(true), taskId: 'fetchTransactions', baseDelay: TX_REFETCH_INTERVAL, }) - appScheduler.addTask({ task: updateAutopilotNodeScores, taskId: 'updateAutopilotNodeScores', baseDelay: AUTOPILOT_SCORES_REFRESH_INTERVAL, }) - return () => { - appScheduler.removeAllTasks() - } - }, [fetchDescribeNetwork, fetchPeers, fetchTransactions, updateAutopilotNodeScores]) - - useEffect(() => { // Set wallet open state. setIsWalletOpen(true) // fetch data from lnd. + updateAutopilotNodeScores() initActivityHistory() - // fetch node info. fetchPeers() - // fetch network info fetchDescribeNetwork() - // Update autopilot node scores. - updateAutopilotNodeScores() + // fetch other application data. fetchSuggestedNodes() initTickers() // initialize backup service in forceUseTokens mode to avoid @@ -109,8 +100,13 @@ const App = ({ if (lnurlWithdrawParams && !willShowLnurlWithdrawPrompt) { finishLnurlWithdraw() } + + return () => { + appScheduler.removeAllTasks() + } }, [ initActivityHistory, + isSyncedToGraph, fetchDescribeNetwork, fetchPeers, fetchSuggestedNodes, @@ -165,6 +161,7 @@ App.propTypes = { initBackupService: PropTypes.func.isRequired, initTickers: PropTypes.func.isRequired, isAppReady: PropTypes.bool.isRequired, + isSyncedToGraph: PropTypes.bool.isRequired, lnurlAuthParams: PropTypes.object, lnurlChannelParams: PropTypes.object, lnurlWithdrawParams: PropTypes.object, diff --git a/renderer/containers/App/App.js b/renderer/containers/App/App.js index 6eceeb024d8..2ab1928cbb2 100644 --- a/renderer/containers/App/App.js +++ b/renderer/containers/App/App.js @@ -14,6 +14,7 @@ import { lnurlSelectors, } from 'reducers/lnurl' import { initBackupService } from 'reducers/backup' +import { infoSelectors } from 'reducers/info' import { setModals, modalSelectors } from 'reducers/modal' import { fetchSuggestedNodes } from 'reducers/channels' import { initTickers } from 'reducers/ticker' @@ -23,6 +24,7 @@ import AppErrorBoundary from './ErrorBoundary' const mapStateToProps = state => ({ isAppReady: appSelectors.isAppReady(state), + isSyncedToGraph: infoSelectors.isSyncedToGraph(), redirectPayReq: state.pay.redirectPayReq, modals: modalSelectors.getModalState(state), lnurlWithdrawParams: lnurlSelectors.lnurlWithdrawParams(state), diff --git a/renderer/reducers/info/selectors.js b/renderer/reducers/info/selectors.js index 2ac1823accd..524aa521bf7 100644 --- a/renderer/reducers/info/selectors.js +++ b/renderer/reducers/info/selectors.js @@ -64,13 +64,21 @@ const infoLoaded = state => state.info.infoLoaded const hasSynced = state => state.info.hasSynced /** - * hasSynced - Node sync state. + * isSyncedToChain - Chain sync state. * * @param {State} state Redux state - * @returns {boolean} Boolean indicating if node is synced + * @returns {boolean} Boolean indicating if chain is synced */ const isSyncedToChain = state => get(state, 'info.data.syncedToChain', false) +/** + * isSyncedToGraph - Graph sync state. + * + * @param {State} state Redux state + * @returns {boolean} Boolean indicating if node graph is synced + */ +const isSyncedToGraph = state => get(state, 'info.data.syncedToGraph', false) + /** * version - Node version. * @@ -230,6 +238,7 @@ export default { infoLoaded, hasSynced, isSyncedToChain, + isSyncedToGraph, version, identityPubkey, nodeUris, From d1866707f125cf17fa7ad1a1d3b75c483788ceec Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Sun, 4 Oct 2020 01:05:20 +0100 Subject: [PATCH 3/3] perf(wallet): fetch balane and channels before activity --- renderer/reducers/activity/reducer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/renderer/reducers/activity/reducer.js b/renderer/reducers/activity/reducer.js index 9b43df6d53b..6b8fbdfb935 100644 --- a/renderer/reducers/activity/reducer.js +++ b/renderer/reducers/activity/reducer.js @@ -284,9 +284,9 @@ export const reloadPages = () => async dispatch => { export const initActivityHistory = () => async dispatch => { dispatch({ type: FETCH_ACTIVITY_HISTORY }) try { - await dispatch(loadPage()) dispatch(fetchChannels()) dispatch(fetchBalance()) + await dispatch(loadPage()) dispatch({ type: FETCH_ACTIVITY_HISTORY_SUCCESS }) } catch (error) { dispatch({ type: FETCH_ACTIVITY_HISTORY_FAILURE, error })