Skip to content
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

feat(rename): Rename Nodes #841

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Conversation

Jem256
Copy link

@Jem256 Jem256 commented Mar 1, 2024

Closes #388

Description

Adds a rename node feature that allows users to rename a node.

Screenshots

Screenshot from 2024-03-07 11-06-34

@Jem256 Jem256 changed the title feat(rename): add rename button feat(rename): Rename Nodes Mar 1, 2024
@Jem256
Copy link
Author

Jem256 commented Mar 10, 2024

@jamaljsr here is the code

Edit: the last commit fixed the issue of the ports undefined error. Although the visual connector of the node to the backend has disappeared as shown below.
Screenshot from 2024-03-11 00-45-33

@jamaljsr
Copy link
Owner

The code currently on Github is missing the lightning.renameNode() function and is throwing an error, so I don't see the issue you're having.

image

@Jem256
Copy link
Author

Jem256 commented Mar 11, 2024

The code currently on Github is missing the lightning.renameNode() function and is throwing an error, so I don't see the issue you're having.

image

I've fixed all the issues. I kindly request for a review of my PR

@Jem256 Jem256 marked this pull request as ready for review March 11, 2024 14:21
Copy link
Owner

@jamaljsr jamaljsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for working on this. When testing it, I found a few functional issues.

polar-node-rename.mp4
  1. When the network is started and I enter a new name then click Save, the network is stopped, but the node isn't renamed. I have to click Save a second time to rename the node.
  2. After the rename, the node's open channels are no longer displayed.
  3. The file paths to the cert & macaroons are still showing the old name. We should rename this folder as well.
  4. I think it would be better to use a modal to have the user type the new name in so that we can access this from the right-click menu on each node.
  5. Rename is not available for the Bitcoin Core and TAP nodes. Shouldn't this be supported for all node types?

@Jem256
Copy link
Author

Jem256 commented Mar 11, 2024

Thanks so much for working on this. When testing it, I found a few functional issues.
polar-node-rename.mp4

1. When the network is started and I enter a new name then click Save, the network is stopped, but the node isn't renamed. I have to click Save a second time to rename the node.

2. After the rename, the node's open channels are no longer displayed.

3. The file paths to the cert & macaroons are still showing the old name. We should rename this folder as well.

4. I think it would be better to use a modal to have the user type the new name in so that we can access this from the right-click menu on each node.

5. Rename is not available for the Bitcoin Core and TAP nodes. Shouldn't this be supported for all node types?

Thank so much for the review. I am going to address all these. I have a question though, about Number 4, should we remove the button and simply have the modal accessible through the right click menu or should we have both?

@codecov-commenter
Copy link

codecov-commenter commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 18.48739% with 97 lines in your changes are missing coverage. Please review.

Project coverage is 97.72%. Comparing base (05d0bb8) to head (4b67452).
Report is 67 commits behind head on master.

Files Patch % Lines
src/utils/network.ts 2.94% 33 Missing ⚠️
src/components/common/RenameNodeModal.tsx 4.16% 23 Missing ⚠️
src/store/models/designer.ts 0.00% 14 Missing ⚠️
src/store/models/network.ts 50.00% 11 Missing ⚠️
src/store/models/modals.ts 0.00% 6 Missing ⚠️
src/lib/docker/dockerService.ts 0.00% 5 Missing ⚠️
src/utils/files.ts 20.00% 4 Missing ⚠️
src/components/common/RenameNodeButton.tsx 87.50% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##            master     #841      +/-   ##
===========================================
- Coverage   100.00%   97.72%   -2.28%     
===========================================
  Files          140      142       +2     
  Lines         4428     4700     +272     
  Branches       862      874      +12     
===========================================
+ Hits          4428     4593     +165     
- Misses           0      107     +107     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jamaljsr
Copy link
Owner

I have a question though, about Number 4, should we remove the button and simply have the modal accessible through the right click menu or should we have both?

To be consistent with the other modals, I think you should remove the sidebar dropdown menu and add a new "Rename Node" button between the "Restart" and "Advanced Options" buttons in the Actions tab.

@Jem256
Copy link
Author

Jem256 commented Mar 25, 2024

Screenshot from 2024-03-25 14-03-57
Hey @jamaljsr do you have an idea why this is happening? when the app is restarted, the paths update to the new node name but the node also shows this error.

@jamaljsr
Copy link
Owner

Hey @Jem256, for each node, there is a folder on the host machine that contains the node's data. It's located at ~/.polar/networks/<network-id>/volumes/<implementation>/<node-name>/. It looks like Polar isn't renaming this dir when the node is renamed.

@Jem256
Copy link
Author

Jem256 commented Mar 25, 2024

~/.polar/networks//volumes///

how can I access this dir through the code to update the name? I can't seem to figure that out

@jamaljsr
Copy link
Owner

The DockerService.ensureDirs is currently the method that initially creates this dir when it starts the containers. This seems like the most appropriate place to rename the dir when the node is renamed. You can call it from the stores using injections.dockerService.

@Jem256 Jem256 marked this pull request as draft April 2, 2024 09:00
@jamaljsr
Copy link
Owner

Hey @Jem256 please let me know when you feel this is ready for review and I'll take a look at it.

@Jem256
Copy link
Author

Jem256 commented Apr 24, 2024

Hey @Jem256 please let me know when you feel this is ready for review and I'll take a look at it.

Hey Jamal, It should be ready sometime this week. Finishing up a few things today. I'll ping you when it's ready

@Jem256 Jem256 requested a review from jamaljsr April 24, 2024 11:49
@Jem256 Jem256 marked this pull request as ready for review April 24, 2024 11:50
@Jem256
Copy link
Author

Jem256 commented Apr 24, 2024

@jamaljsr please take a look and let me know what you think. The channel links are not yet working but I've tried to make a lot of other things work and would like to know your thoughts on my approach. The other thing I would like to highlight is that in case someone tries to rename the bitcoin nodes, the path to the node can't be updated because it doesn't have that property. Also on the issue of links, syncChart doesn't work in updating them. But the functions updateBackendLink and updateTapBackendLink worked for those corresponding links. Do you think we have to write a separate function like updateChannelLink for the channels

Copy link
Owner

@jamaljsr jamaljsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for working on this feature. It has been requested many times in the past. You are off to a great start. I've left a bunch of feedback on where I see room for improvement.

One strange issue I noticed when testing was that I couldn't select the text in the input field of the modal. Instead, it was dragging the node on the canvas underneath the modal. I'm not sure how that's even possible but my hunch is it's related to where you have the Modal component being mounted. I mentioned some details about this in a comment below.

polar-rename.mp4

src/components/common/RenameNode.tsx Outdated Show resolved Hide resolved
src/components/common/RenameNode.tsx Outdated Show resolved Hide resolved
src/shared/types.ts Outdated Show resolved Hide resolved
src/store/models/network.ts Outdated Show resolved Hide resolved
src/store/models/network.ts Outdated Show resolved Hide resolved
src/store/models/designer.ts Outdated Show resolved Hide resolved
src/store/models/designer.ts Outdated Show resolved Hide resolved
src/store/models/lightning.ts Outdated Show resolved Hide resolved
src/store/models/network.ts Outdated Show resolved Hide resolved
src/i18n/locales/de-DE.json Outdated Show resolved Hide resolved
@Jem256 Jem256 requested a review from jamaljsr May 2, 2024 17:17
Copy link
Owner

@jamaljsr jamaljsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking amazing! Great work 👍

I just have a bit more feedback on the latest changes.

Also, I noticed this error when trying to rename a Core Lightning node. Does it work fine for you?

image

src/lib/docker/dockerService.ts Outdated Show resolved Hide resolved
src/lib/docker/dockerService.ts Outdated Show resolved Hide resolved
src/lib/docker/dockerService.ts Outdated Show resolved Hide resolved
src/store/models/designer.ts Outdated Show resolved Hide resolved
src/store/models/designer.ts Show resolved Hide resolved
src/i18n/locales/en-US.json Outdated Show resolved Hide resolved
src/i18n/locales/en-US.json Outdated Show resolved Hide resolved
src/store/models/network.ts Outdated Show resolved Hide resolved
src/components/common/RenameNodeModal.tsx Show resolved Hide resolved
src/lib/docker/dockerService.ts Outdated Show resolved Hide resolved
@Jem256 Jem256 requested a review from jamaljsr May 11, 2024 20:51
Copy link
Owner

@jamaljsr jamaljsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the additional updates. This is looking really good. I found a few remaining issues, but this should be complete once these are fixed.

The last things remaining would be to rebase this branch on master and add/update the unit tests to fix the failures and get the coverage back up. Testing all of the code paths can be pretty tricky sometimes so please let me know if you need any assistance with this.

Comment on lines +242 to +244
const volumeDir = (node as AnyNode).implementation
.toLocaleLowerCase()
.replace('-', '');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for being too specific in my last comment. You can use nodePath() for the newPath variable as well. We don't want to have this custom string manipulation here when the volume dir name is already spcified in the dockerConfig. This is what nodePath uses.

@@ -277,6 +290,7 @@
"cmps.designer.lightning.LightningDetails.actions": "Actions",
"cmps.designer.lightning.LightningDetails.waitingNotice": "Waiting for {{implementation}} to come online",
"cmps.designer.lightning.LightningDetails.connectError": "Unable to connect to {{implementation}} node",
"cmps.designer.lightning.LightningDetails.menuRename": "Rename",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I missed this in my prior review. This key isn't used and can be removed.

await rename(abs(oldPath), abs(newPath));
info(`File renamed successfully from ${oldPath} to ${newPath}`);
} catch (err) {
debug('Error occurred while renaming file:', err);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into this error when testing. I created a new network with 1 LND node. I started the network then immediately stopped it. I just wanted the data dirs to be created. Then I renamed alice to alice2. It seemed to work correctly because I saw the success notification. But when I started the network up, the node failed to come online. I went to check the data dir and saw that it was still named alice. Then I found this message in my logs:

[electron] 01:51:55.172 › Error occurred while renaming file: Error: ENOENT: no such file or directory, rename '/Users/jamal/.polar/networks/1/volumes/lnd/alice2' -> '/Users/jamal/.polar/networks/1/volumes/lnd/alice2'

It looks like the oldPath being passed to this function contains the new name. I'm not sure how this is exactly happening, but one additional suggestion I have is to remove the try/catch here and let the error bubble up to the UI, so that users will be aware if the directory rename fails. it may be better to try to rename the dir first before updating the network & store state, otherwise you'll end up with data thats out of sync.

case 'lightning':
switch (node.implementation) {
case 'LND':
updatedNode = network?.nodes.lightning.find(n => n.id === node.id) as LndNode;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: we don't need the ?. throughout this function because the network parameter will never be undefined.

Comment on lines +982 to +984
actions.setNetworks([...networks]);
await actions.save();
await injections.dockerService.saveComposeFile(network);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 lines don't need to be duplicated in both conditions. Just call them outside of the if and only have actions.start() called inside of the if block.

Comment on lines +968 to +974
await renameNode(network, node, newName);
await getStoreActions().designer.renameNode({
name: newName,
nodeId: oldNodeName,
});

await injections.dockerService.renameNodeDir(network, node, newName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, i see why the new name is being passed to dockerService.renameNodeDir(). It's because the await renameNode(network, node, newName); is updating the name on the node first. You should be able to resolve the error I mentioned above by just moving the dockerService rename above the await renameNode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Rename nodes
3 participants