neo-project / neo-node

MIT License
229 stars 223 forks source link

node: Mode system #853

Open Jim8y opened 2 years ago

Jim8y commented 2 years ago

updated to work under https://github.com/neo-project/neo-modules/pull/709

This pr implements neo-project/neo-node#863 Mode system is intended to help developers to save and load neo node configurations.

  1. cli provides some default settings, such as mainnet, testnet, private net. Maybe Oracle net and FS net in the future.
  2. user can load from these default settings.
  3. user can have their own node setttings and save them as a mode
  4. user can delete existing modes
  5. if no mode is assigned from the console, load mainnet
  6. Does not support runtime mode switch.
image image

mainnet mode:

dotnet neo-cli.dll /mode mainnet

testnet mode:

dotnet neo-cli.dll /mode testnet

privatenet mode:

dotnet neo-cli.dll /mode privatenet

when user load into the privatenet mode, a single node blockchain network will be setup with the default primary account NbVj8GhwToNv4WF2gVaoco6hbkMQ8hrHWP. Please note that the secret key of this account is publicly available to everyone,

do not send any asset to this account in main net

you will lose your token and we will not be responsible for that.

Create your own mode You can config your own network by modifying the config.json and config.fs.json in the root directory, as well as the config.json of Plugins. Then run mode save [mode name] to save your configuration as a mode. If the name you assigned is an existing mode, existing mode will be updated.

Your configurations will not be updated into mode automatically, you must manually run mode save [mode name] to save them.

nicolegys commented 2 years ago

mode delete Cannot delete a directory which is not empty. Image

save as an existing mode name There is no warning and the original mode configs will be overwritten. Image

nicolegys commented 2 years ago

The logic of mode save is a little strange for me. If I want to save a mode, firstly I need to start neo-cli with some specified mode in ./Mode/ folder or with default mode mainnet, and corresponding config files will be generated in ./ folder. Then I modify or replace the config files in ./ folder , use mode save <modeName> cmd to copy the config files to ./Mode/ folder. Why don't I directly create a new mode in ./Mode/ folder?:joy:

Jim8y commented 2 years ago

The logic of mode save is a little strange for me. If I want to save a mode, firstly I need to start neo-cli with some specified mode in ./Mode/ folder or with default mode mainnet, and corresponding config files will be generated in ./ folder. Then I modify or replace the config files in ./ folder , use mode save <modeName> cmd to copy the config files to ./Mode/ folder. Why don't I directly create a new mode in ./Mode/ folder?😂

Cause config.json are spread everywhere, with save mode we can collect config file from the node and Plugins. If user directly creates mode under Modes folder, how could they deal with Plugins.

Jim8y commented 2 years ago

@nicolegys May you please test this?

nicolegys commented 2 years ago

After I install a new plugin, neo-cli will remind me to restart it. But if I restart it immediately without saving this mode, in this pr, the new installed plugin will be removed. Need to add some words in this warning to remind users saving mode before restarting neo-cli.

https://github.com/neo-project/neo-node/blob/fd9203f1ce75f163b8c6a8d9870cd20c6abbc4c3/neo-cli/CLI/MainService.Plugins.cs#L43

Jim8y commented 2 years ago

After I install a new plugin, neo-cli will remind me to restart it. But if I restart it immediately without saving this mode, in this pr, the new installed plugin will be removed. Need to add some words in this warning to remind users saving mode before restarting neo-cli.

https://github.com/neo-project/neo-node/blob/fd9203f1ce75f163b8c6a8d9870cd20c6abbc4c3/neo-cli/CLI/MainService.Plugins.cs#L43

This issue should have been solved in my last commit. The reason of that issue is the plugin folder name is kinda different from the plugin name.

nicolegys commented 2 years ago

1658829598028

Need to remind users to restart/resync neo-cli if new plugins are auto-installed.

nicolegys commented 2 years ago

1658831583979 exception.

Jim8y commented 2 years ago

Need to remind users to restart/resync neo-cli if new plugins are auto-installed.

Well, actually, it is supposed to be loaded automatically....will check this logic.

nicolegys commented 2 years ago

async issue still exists.

superboyiii commented 2 years ago

@Liaojinghui Can we move on? I think it's useful.

nicolegys commented 2 years ago
  1. If plugins are auto-installed/auto-uninstalled when starting neo-cli, type exit and neo-cli will throw an exception. 1662634153298

  2. reinstall plugin will replace this plugin's config file in mode\xxx by the default config file.

  3. e.g. Both ApplicationLogs and RpcServer are not installed but in \mode\testnet, now I start neo-cli with testnet mode, I could find that RpcServer's config file in \mode\testnet be replaced by the default one. Because RpcServer is installed as a dependency of ApplicationLogs.

nicolegys commented 2 years ago
  1. If plugins are auto-installed/auto-uninstalled when starting neo-cli, type exit and neo-cli will throw an exception. 1662634153298
  2. reinstall plugin will replace this plugin's config file in mode\xxx by the default config file.
  3. e.g. Both ApplicationLogs and RpcServer are not installed but in \mode\testnet, now I start neo-cli with testnet mode, I could find that RpcServer's config file in \mode\testnet be replaced by the default one. Because RpcServer is installed as a dependency of ApplicationLogs.

2. ... hasn't been fixed.

nicolegys commented 2 years ago

If use lower case to install plugins, it can't find folders like Plugins/applicationlogs.

1663226371028

1663227689871

Jim8y commented 2 years ago

Doesn' the GetActualPath work?

nicolegys commented 1 year ago

This issue still exists. neo-project/neo#3000

nicolegys commented 1 year ago

Threw an exception when reinstalling StateService, but not always. Image

nicolegys commented 1 year ago
  1. If plugins are auto-installed/auto-uninstalled when starting neo-cli, type exit and neo-cli will throw an exception. 1662634153298
  2. reinstall plugin will replace this plugin's config file in mode\xxx by the default config file.
  3. e.g. Both ApplicationLogs and RpcServer are not installed but in \mode\testnet, now I start neo-cli with testnet mode, I could find that RpcServer's config file in \mode\testnet be replaced by the default one. Because RpcServer is installed as a dependency of ApplicationLogs.
  1. ... hasn't been fixed. To Reproduce 1.Make sure that ApplicationLogs is before RpcServer in .PLUGINS file, and both of them are not installed. 1663833620087 2.Start neo-cli.
Jim8y commented 1 year ago

Threw an exception when reinstalling StateService, but not always. Image

This is an issue in neo core, and has being addressed in https://github.com/neo-project/neo/pull/2569 . This pr can not and should not handle that.

nicolegys commented 1 year ago

No more issues,need review.

superboyiii commented 1 year ago

@Liaojinghui Please fix format.

nicolegys commented 1 year ago

1666863841910 It uses an error plugin path when starting neo-cli in the different directory with neo-cli.dll.

Jim8y commented 1 year ago

1666863841910 It uses an error plugin path when starting neo-cli in the different directory with neo-cli.dll.

The path issue is not a problem should be addressed in this pr. it is a nature feature of C# on windows platform.

Relative path will always be relative to the executing folder, unless you publish it in a self-contain mode.

nicolegys commented 1 year ago

1666863841910 It uses an error plugin path when starting neo-cli in the different directory with neo-cli.dll.

The path issue is not a problem should be addressed in this pr. it is a nature feature of C# on windows platform.

Relative path will always be relative to the executing folder, unless you publish it in a self-contain mode.

It was published in the self-contain mode. Actually, this issue is because method PluginExists uses the wrong path to find the specified plugin. 1667211617870

nicolegys commented 1 year ago

In addtion, as you said, relative path is an old issue that also exists in master branch, and it happens not only in the places I mentioned in this pr. I'll create annother issue if needed.

Jim8y commented 1 year ago

In addtion, as you said, relative path is an old issue that also exists in master branch, and it happens not only in the places I mentioned in this pr. I'll create annother issue if needed.

You dont have to, cause this issue does not exist in the official publish package as it is published in the self-contain mode.

nicolegys commented 1 year ago

In addtion, as you said, relative path is an old issue that also exists in master branch, and it happens not only in the places I mentioned in this pr. I'll create annother issue if needed.

You dont have to, cause this issue does not exist in the official publish package as it is published in the self-contain mode.

I have said that this issue also exists when it is published in the self-contain mode. I've tested it both on v3.4.0 and master branch, both on windows and linux. The cause of this issue is, in our code, files are read or generated based on the current execution directory, not the relative directory. And this issue was not raised before because of few usage scenarios, so it's not a high priority. Please be more careful.

superboyiii commented 1 year ago

@shargon Could you review again?

superboyiii commented 1 year ago

@Liaojinghui Please solve conflicts

Jim8y commented 1 year ago

@Liaojinghui Please solve conflicts

Resolved