Browse Source

fix(clightning): fix c-lightning node initiator detection

master
jamaljsr 5 years ago
parent
commit
ad32e86826
  1. 4
      TODO.md
  2. 2
      docker/clightning/Dockerfile
  3. 5
      src/lib/bitcoin/bitcoindService.ts
  4. 36
      src/lib/lightning/clightning/clightningService.ts
  5. 1
      src/lib/lightning/clightning/types.ts
  6. 1
      src/store/models/lightning.ts

4
TODO.md

@ -1,13 +1,11 @@
# TODO List
- compile c-lightning with DEVELOPER=1 and execute with --dev-bitcoind-poll=1 (https://github.com/ElementsProject/lightning/blob/master/lightningd/options.c#L457)
- add persisted storage for lang, openChan c-ln notice
Small Stuff
- fix pasting text in terminal
- display bitcoin rpc user/pass in sidebar
- start/stop individual nodes
- add persisted storage for lang
- implement real-time channel updates from LND via GRPC streams
- implement option to auto-mine every X minutes
- switch renovatebot to dependabot and use automatic security fixes

2
docker/clightning/Dockerfile

@ -134,7 +134,7 @@ RUN apt-get update -y \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# install c-lightning-REST API plugin
RUN git clone https://github.com/saubyk/c-lightning-rest /opt/c-lightning-rest/ \
RUN git clone https://github.com/jamaljsr/c-lightning-rest /opt/c-lightning-rest/ \
&& cd /opt/c-lightning-rest \
&& npm install \
&& chmod -R a+rw /opt/c-lightning-rest

5
src/lib/bitcoin/bitcoindService.ts

@ -2,7 +2,7 @@ import * as logger from 'electron-log';
import BitcoinCore from 'bitcoin-core';
import { BitcoinNode } from 'shared/types';
import { BitcoindLibrary } from 'types';
import { waitFor } from 'utils/async';
import { delay, waitFor } from 'utils/async';
import { bitcoinCredentials, COINBASE_MATURITY_HEIGHT } from 'utils/constants';
class BitcoindService implements BitcoindLibrary {
@ -75,6 +75,9 @@ class BitcoindService implements BitcoindLibrary {
if (blocks < COINBASE_MATURITY_HEIGHT) {
const blocksLeft = COINBASE_MATURITY_HEIGHT - blocks;
await this.mine(blocksLeft, port);
// this usually mines up to 100 blocks at once, so add a couple second
// delay to allow the LN nodes to process all of the new blocks
await delay(2 * 1000);
}
}

36
src/lib/lightning/clightning/clightningService.ts

@ -51,26 +51,30 @@ class CLightningService implements LightningService {
}
async getChannels(node: LightningNode): Promise<PLN.LightningNodeChannel[]> {
const { pubkey } = await this.getInfo(node);
const channels = await httpGet<CLN.GetChannelsResponse[]>(
this.cast(node),
'channel/listChannels',
);
return channels
.filter(c => c.initiator === 1)
.filter(c => ChannelStateToStatus[c.state] !== 'Closed')
.map(c => {
const status = ChannelStateToStatus[c.state];
return {
pending: status !== 'Open',
uniqueId: c.fundingTxid.slice(-12),
channelPoint: c.channelId,
pubkey: c.id,
capacity: this.toSats(c.msatoshiTotal),
localBalance: this.toSats(c.msatoshiToUs),
remoteBalance: this.toSats(c.msatoshiTotal - c.msatoshiToUs),
status,
};
});
return (
channels
// only include the channels that were initiated by this node
.filter(chan => chan.fundingAllocationMsat[pubkey] > 0)
.filter(c => ChannelStateToStatus[c.state] !== 'Closed')
.map(c => {
const status = ChannelStateToStatus[c.state];
return {
pending: status !== 'Open',
uniqueId: c.fundingTxid.slice(-12),
channelPoint: c.channelId,
pubkey: c.id,
capacity: this.toSats(c.msatoshiTotal),
localBalance: this.toSats(c.msatoshiToUs),
remoteBalance: this.toSats(c.msatoshiTotal - c.msatoshiToUs),
status,
};
})
);
}
async getPeers(node: LightningNode): Promise<PLN.LightningNodePeer[]> {

1
src/lib/lightning/clightning/types.ts

@ -64,6 +64,7 @@ export interface GetChannelsResponse {
spendableMsatoshi: number;
state: ChannelState;
theirChannelReserveSatoshis: number;
fundingAllocationMsat: Record<string, number>;
initiator?: number;
}

1
src/store/models/lightning.ts

@ -192,6 +192,7 @@ const lightningModel: LightningModel = {
async (actions, { payload }, { getStoreState }) => {
// update all lightning nodes info when a block in mined
const network = getStoreState().network.networkById(payload.node.networkId);
await actions.waitForNodes(network.nodes.lightning);
await Promise.all(
network.nodes.lightning
.filter(n => n.status === Status.Started)

Loading…
Cancel
Save