Skip to content

Commit

Permalink
fix: 🐛 channels with unfound nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed May 23, 2020
1 parent 5df58ec commit 077e20d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 78 deletions.
15 changes: 3 additions & 12 deletions api/schemas/query/channels/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import {
getWalletInfo,
} from 'ln-service';
import { ContextType } from 'api/types/apiTypes';
import { toWithError } from 'api/helpers/async';
import { toWithError, to } from 'api/helpers/async';
import { logger } from '../../../helpers/logger';
import { requestLimiter } from '../../../helpers/rateLimiter';
import {
getAuthLnd,
getErrorMsg,
getCorrectAuth,
} from '../../../helpers/helpers';
import { getAuthLnd, getCorrectAuth } from '../../../helpers/helpers';
import { defaultParams } from '../../../helpers/defaultProps';
import { ChannelType } from '../../types/QueryType';

Expand All @@ -35,18 +31,13 @@ export const getChannels = {
walletError &&
logger.debug('Error getting wallet info in getChannels: %o', walletError);

const [channelList, channelListError] = await toWithError(
const channelList = await to(
getLnChannels({
lnd,
is_active: params.active,
})
);

if (channelListError) {
logger.error('Error getting channels: %o', channelListError);
throw new Error(getErrorMsg(channelListError));
}

const getChannelList = () =>
Promise.all(
channelList.channels.map(async channel => {
Expand Down
50 changes: 25 additions & 25 deletions api/schemas/query/channels/closedChannels.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { GraphQLList, GraphQLString } from 'graphql';
import { getClosedChannels as getLnClosedChannels, getNode } from 'ln-service';
import { ContextType } from 'api/types/apiTypes';
import { to, toWithError } from 'api/helpers/async';
import { logger } from '../../../helpers/logger';
import { requestLimiter } from '../../../helpers/rateLimiter';
import {
getAuthLnd,
getErrorMsg,
getCorrectAuth,
} from '../../../helpers/helpers';

import { getAuthLnd, getCorrectAuth } from '../../../helpers/helpers';
import { defaultParams } from '../../../helpers/defaultProps';
import { ClosedChannelType } from '../../types/QueryType';

Expand Down Expand Up @@ -45,28 +41,32 @@ export const getClosedChannels = {
const auth = getCorrectAuth(params.auth, context);
const lnd = getAuthLnd(auth);

try {
const closedChannels: ChannelListProps = await getLnClosedChannels({
lnd,
});
const channels = closedChannels.channels.map(async channel => {
const nodeInfo = await getNode({
const closedChannels: ChannelListProps = await to(
getLnClosedChannels({ lnd })
);

const channels = closedChannels.channels.map(async channel => {
const [nodeInfo, nodeError] = await toWithError(
getNode({
lnd,
is_omitting_channels: true,
public_key: channel.partner_public_key,
});
})
);

nodeError &&
logger.debug(
`Error getting node with public key ${channel.partner_public_key}: %o`,
nodeError
);

return {
...channel,
partner_node_info: {
...nodeInfo,
},
};
});
return channels;
} catch (error) {
logger.error('Error getting closed channels: %o', error);
throw new Error(getErrorMsg(error));
}
return {
...channel,
partner_node_info: {
...(!nodeError && nodeInfo),
},
};
});
return channels;
},
};
50 changes: 24 additions & 26 deletions api/schemas/query/channels/pendingChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import {
} from 'ln-service';
import { GraphQLList } from 'graphql';
import { ContextType } from 'api/types/apiTypes';
import { to, toWithError } from 'api/helpers/async';
import { logger } from '../../../helpers/logger';
import { requestLimiter } from '../../../helpers/rateLimiter';
import {
getAuthLnd,
getErrorMsg,
getCorrectAuth,
} from '../../../helpers/helpers';
import { getAuthLnd, getCorrectAuth } from '../../../helpers/helpers';
import { defaultParams } from '../../../helpers/defaultProps';
import { PendingChannelType } from '../../types/QueryType';

Expand Down Expand Up @@ -44,31 +41,32 @@ export const getPendingChannels = {
const auth = getCorrectAuth(params.auth, context);
const lnd = getAuthLnd(auth);

try {
const pendingChannels: PendingChannelListProps = await getLnPendingChannels(
{
lnd,
}
);
const pendingChannels: PendingChannelListProps = await to(
getLnPendingChannels({ lnd })
);

const channels = pendingChannels.pending_channels.map(async channel => {
const nodeInfo = await getNode({
const channels = pendingChannels.pending_channels.map(async channel => {
const [nodeInfo, nodeError] = await toWithError(
getNode({
lnd,
is_omitting_channels: true,
public_key: channel.partner_public_key,
});
})
);

nodeError &&
logger.debug(
`Error getting node with public key ${channel.partner_public_key}: %o`,
nodeError
);

return {
...channel,
partner_node_info: {
...nodeInfo,
},
};
});
return channels;
} catch (error) {
logger.error('Error getting pending channels: %o', error);
throw new Error(getErrorMsg(error));
}
return {
...channel,
partner_node_info: {
...(!nodeError && nodeInfo),
},
};
});
return channels;
},
};
27 changes: 18 additions & 9 deletions src/views/channels/channels/ChannelCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ export const ChannelCard = ({
});
};

const renderPartner = () =>
alias ? (
<>
{renderLine('Node Capacity:', nodeCapacity)}
{renderLine('Channel Count:', channel_count)}
{renderLine(
'Last Update:',
`${getDateDif(updated_at)} ago (${getFormatDate(updated_at)})`
)}
{renderLine('Base Fee:', `${base_fee} mSats`)}
{renderLine('Fee Rate:', `${fee_rate} sats/MSats`)}
{renderLine('CTLV Delta:', cltv_delta)}
</>
) : (
<DarkSubTitle>Partner node not found</DarkSubTitle>
);

const renderDetails = () => {
return (
<>
Expand Down Expand Up @@ -215,15 +232,7 @@ export const ChannelCard = ({
{renderLine('Transaction Vout:', transaction_vout)}
{renderLine('Unsettled Balance:', unsettled_balance)}
<Sub4Title>Partner Node Info</Sub4Title>
{renderLine('Node Capacity:', nodeCapacity)}
{renderLine('Channel Count:', channel_count)}
{renderLine(
'Last Update:',
`${getDateDif(updated_at)} ago (${getFormatDate(updated_at)})`
)}
{renderLine('Base Fee:', `${base_fee} mSats`)}
{renderLine('Fee Rate:', `${fee_rate} sats/MSats`)}
{renderLine('CTLV Delta:', cltv_delta)}
{renderPartner()}
<AdminSwitch>
<Separation />
<RightAlign>
Expand Down
22 changes: 16 additions & 6 deletions src/views/channels/pendingChannels/PendingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ResponsiveLine,
ResponsiveSingle,
ResponsiveCol,
DarkSubTitle,
} from '../../../components/generic/Styled';
import { useConfigState } from '../../../context/ConfigContext';
import {
Expand Down Expand Up @@ -89,6 +90,20 @@ export const PendingCard = ({
}
};

const renderPartner = () =>
alias ? (
<>
{renderLine('Node Capacity:', capacity)}
{renderLine('Channels:', channel_count)}
{renderLine(
'Last Update:',
`${getDateDif(updated_at)} ago (${getFormatDate(updated_at)})`
)}
</>
) : (
<DarkSubTitle>Partner node not found</DarkSubTitle>
);

const renderDetails = () => {
return (
<>
Expand All @@ -108,12 +123,7 @@ export const PendingCard = ({
{renderLine('Local Reserve:', local_reserve)}
{renderLine('Remote Reserve:', remote_reserve)}
<Sub4Title>Partner Node Info</Sub4Title>
{renderLine('Node Capacity:', capacity)}
{renderLine('Channels:', channel_count)}
{renderLine(
'Last Update:',
`${getDateDif(updated_at)} ago (${getFormatDate(updated_at)})`
)}
{renderPartner()}
</>
);
};
Expand Down

0 comments on commit 077e20d

Please sign in to comment.