-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature request: add button to balance all existing channels in current network #831
Comments
That's a pretty cool idea. No objections from me if you want to implement this. |
I'll implement it. |
Hi @jamaljsr and @Anyitechs. I think I need help here, but more with the development stuff. In the past, I was able to build Polar locally and to run the development server with hot-reload. But, I'm currently not being able to do so neither locally neither using Dev Containers. I get the following errors:
after troubleshooting, I updated Node version to the latest stable using NVM. It solved the error but I got a new one:
After more troubleshooting, I exported
This one got me stuck. I do want to implement this feature for Polar, but I'm not being able to compile or launch a development server. I'll try setting up a Ubuntu VM and see if I can get it to work. If any of you can help me here, I'll appreciate it! |
Make sure you're using the latest I just tested with a fresh clone of the repo using node v20.9.0 and it worked for me. |
Thanks @jamaljsr it worked. Now I can work on this issue. I'll try to do some work this week, and finish it in the next week, because Im kinda busy this weekend. |
Hi @jamaljsr. I'm almost finishing it, but I need a tip on how to get specific information. For context, here is the function to balance a single channel: const balanceChannel = async (
channel: LightningNodeChannel,
localNode: LightningNode,
remoteNode: LightningNode,
satsTolerance = 100,
) => {
if (channel.status !== 'Open') {
// TODO: warn about channel not opened.
return;
}
if (remoteNode === undefined || remoteNode === null) {
// TODO: warn about remote node being null.
return;
}
const localBalance = Number(channel.localBalance);
const remoteBalance = Number(channel.remoteBalance);
const balanceDifference = localBalance - remoteBalance;
// If the balance difference in satoshis is too small, we ignore it.
if (Math.abs(balanceDifference) < satsTolerance) {
return;
}
// The source node pays an invoice to the target node, in order to balance the channel.
const src = balanceDifference > 0 ? localNode : remoteNode;
const target = balanceDifference > 0 ? remoteNode : localNode;
const invoice = await getNodeLightningService(target).createInvoice(
target,
balanceDifference,
);
await getNodeLightningService(src).payInvoice(src, invoice);
}; Notice we need the Here is how the const AutoBalanceButton: React.FC<Props> = ({ network }) => {
const handleClick = async () => {
const lnNodes = network.nodes.lightning;
const channels = {} as { [key: string]: ChannelInfo };
for (const node of lnNodes) {
const lightningService = getNodeLightningService(node);
const nodeChannels = await lightningService.getChannels(node);
for (const channel of nodeChannels) {
const { uniqueId } = channel;
// Add the channel, using current node as local node.
if (!Object(channels).hasOwnProperty(uniqueId)) {
channels[uniqueId] = {
channel: channel,
localNode: node,
} as ChannelInfo;
} else {
// Channel already exists, so current node is treated as remote node.
channels[uniqueId].remoteNode = node;
}
}
}
await autoBalanceChannels(Object.values(channels));
};
return <Button onClick={handleClick}>Auto Balance channels</Button>;
}; It is not working because the method Can you tell me which function, class or methdo I can use to get the |
Yes, the I hope this helps, but let me know if you have more questions. |
Solves jamaljsr#831. NOTE: work in progress, implementation not ready yet.
Is your feature request related to a problem? Please describe.
Yes, the problem is: sometimes we need balanced channels to do some stuff while testing and developing locally, but balancing them manually takes precious time.
Describe the solution you'd like
A button that we can click and have the channels balanced automatically (in the background by polar).
Suggestion
Here is a pseudo-code to balance the channels:
I can try do this, but some guidance is welcomed
The text was updated successfully, but these errors were encountered: