shardeum / validator-cli

MIT License
20 stars 9 forks source link

Clean Up Unused Code in the Validator CLI #30

Closed kenny-io closed 1 week ago

kenny-io commented 3 weeks ago

The Validator CLI codebase contains unused code, some of which is commented out. We need to clean up the entire codebase by removing unnecessary code while being careful not to delete important comments, documentation, or code that's been temporarily commented out for future use.

Proposed Solution

Go through all files in the project, including TypeScript, JavaScript, and any other relevant files. Identify and remove unused code, being careful to preserve:

  1. Code comments and documentation
  2. TODO items
  3. Code that has been temporarily commented out for future use or debugging purposes

Expected Outcome

After implementing your solution:

  1. The entire codebase should be cleaner and more maintainable
  2. All truly unused code should be removed across all files
  3. Important comments, documentation, and temporarily disabled code should remain intact
  4. The functionality of the Validator CLI should remain unchanged
  5. The codebase follows a consistent standard ESLint

Getting Started

  1. Fork the repository
  2. Clone your fork: git clone [your-fork-url]
  3. Create a new branch: git checkout -b cleanup/unused-code
  4. Make your changes
  5. Test that everything still works as before
  6. Commit your changes: git commit -m "Cleanup: Remove unused code from codebase"
  7. Push to your fork: git push origin cleanup/unused-code
  8. Create a pull request

Mentorship

If you need any help or have questions about which code is safe to remove, feel free to ask in the comments. You can also start a discussion here on Github and our team will be happy to provide the necessary assistance.

Gmhaxx commented 2 weeks ago

image how to configure it? i already update my apt-get install -y sudo && apt-get install -y logrotate but still error

thibault-ketterer commented 1 week ago

Hi there i read the code but saw no unused fucntions to be sure of it i wrote a checker script in python

can you tell me waht you mean about unused code if every function is used ?

besides the only commented code are the disabled commands which I think are reserved for future use

I think the js is builded from the ts so I don't think there is a sue looking into it (but it does not look like there is unused functions)

python check_unused.py
adding  . index.ts
adding  . node-commands.ts
adding  . gui-commands.ts
adding  . projectFlags.ts
adding  . pm2.ts
adding  ./config default-rpc-config.ts
adding  ./config default-network-config.ts
adding  ./config default-gui-config.ts
adding  ./config default-node-config.ts
adding  ./utils index.ts
adding  ./utils performance-stats.ts
adding  ./utils logger.ts
adding  ./utils tcache.ts
adding  ./utils userInput.ts
adding  ./utils fetch-network-data.ts
adding  ./utils project-data.ts
adding  ./utils fetch-node-data.ts
[registerNodeCommands] is used in ./index.ts import {registerNodeCommands} from './node-commands';
[registerNodeCommands] is used in ./index.ts registerNodeCommands(program);
[stopNode] is used in ./node-commands.ts                 return stopNode();
[stopNode] is used in ./node-commands.ts                 return stopNode();
[stopNode] is used in ./node-commands.ts           return stopNode();
[unstake] is used in ./node-commands.ts         console.error("Couldn't unstake (`eoaData` is null)");
[unstake] is used in ./node-commands.ts     .command('unstake')
[unstake] is used in ./node-commands.ts       'Force unstake in case the node is stuck, will forfeit rewards'
[unstake] is used in ./node-commands.ts               'Confirm if you would like to force unstake (y/N): '
[unstake] is used in ./node-commands.ts         await unstake(options);
[writeNodeConfig] is used in ./node-commands.ts             writeNodeConfig();
[writeNodeConfig] is used in ./node-commands.ts       writeNodeConfig();
[isNumber] is used in ./gui-commands.ts       if (!isNumber(port)) {
[validPassword] is used in ./gui-commands.ts         if (!validPassword(password)) {
[registerGuiCommands] is used in ./index.ts import {registerGuiCommands} from './gui-commands';
[registerGuiCommands] is used in ./index.ts registerGuiCommands(program);
[startGui] is used in ./gui-commands.ts     .action(async () => await startGui());
[startGui] is used in ./gui-commands.ts       await startGui();
[stopGui] is used in ./gui-commands.ts       await stopGui();
[stopGui] is used in ./gui-commands.ts       await stopGui();
[statusFromPM2] is used in ./node-commands.ts import {Pm2ProcessStatus, statusFromPM2} from './pm2';
[statusFromPM2] is used in ./node-commands.ts         const status: Pm2ProcessStatus = statusFromPM2(description);
[statusFromPM2] is used in ./node-commands.ts           const status: Pm2ProcessStatus = statusFromPM2(description);
[statusFromPM2] is used in ./gui-commands.ts import {Pm2ProcessStatus, statusFromPM2} from './pm2';
[statusFromPM2] is used in ./gui-commands.ts         const status: Pm2ProcessStatus = statusFromPM2(description);
[statusFromPM2] is used in ./utils/fetch-network-data.ts import {Pm2ProcessStatus, statusFromPM2} from '../pm2';
[statusFromPM2] is used in ./utils/fetch-network-data.ts     const status: Pm2ProcessStatus = statusFromPM2(description);
[getUsedDiskPercentage] is used in ./utils/performance-stats.ts   const diskPercentage = await getUsedDiskPercentage();
[getCpuUsage] is used in ./utils/performance-stats.ts   const cpuPercentage = await getCpuUsage();
[getPerformanceStatus] is used in ./node-commands.ts   getPerformanceStatus,
[getPerformanceStatus] is used in ./node-commands.ts           getPerformanceStatus(),
[readMaps] is used in ./utils/tcache.ts     this.readMaps();
[writeMaps] is used in ./node-commands.ts           cache.writeMaps();
[writeMaps] is used in ./node-commands.ts           cache.writeMaps();
[writeMaps] is used in ./node-commands.ts         cache.writeMaps();
[getUserInput] is used in ./node-commands.ts   getUserInput,
[getUserInput] is used in ./node-commands.ts               const answer = await getUserInput(
[getUserInput] is used in ./node-commands.ts               const answer = await getUserInput(
[getUserInput] is used in ./node-commands.ts       let privateKey = await getUserInput('Please enter your private key: ');
[getUserInput] is used in ./node-commands.ts         privateKey = await getUserInput('Please enter your private key: ');
[getUserInput] is used in ./node-commands.ts     let privateKey = await getUserInput('Please enter your private key: ');
[getUserInput] is used in ./node-commands.ts       privateKey = await getUserInput('Please enter your private key: ');
[getUserInput] is used in ./node-commands.ts           const answer = await getUserInput(
[readActiveNode] is used in ./utils/fetch-network-data.ts   if (!readActiveNode()) {
[getNewActiveNode] is used in ./utils/fetch-network-data.ts     await getNewActiveNode(config);
[getNewActiveNode] is used in ./utils/fetch-network-data.ts       await getNewActiveNode(config);
[fetchInitialParameters] is used in ./utils/fetch-network-data.ts   } = await fetchInitialParameters(config);
[fetchNodeParameters] is used in ./utils/fetch-network-data.ts     const nodeData = await fetchNodeParameters(config, nodePubKey);
[fetchNodeLoad] is used in ./utils/fetch-network-data.ts       const nodeLoad = await fetchNodeLoad(config);
[fetchNodeTxStats] is used in ./utils/fetch-network-data.ts       const nodeTxStats = await fetchNodeTxStats(config);
[fetchNodeInfo] is used in ./node-commands.ts   fetchNodeInfo,
[fetchNodeInfo] is used in ./node-commands.ts             nodeInfo = await fetchNodeInfo(config);
[fetchNodeInfo] is used in ./node-commands.ts               nodeInfo = await fetchNodeInfo(config);
[fetchNodeInfo] is used in ./node-commands.ts             nodeInfo = await fetchNodeInfo(config);
[fetchNetworkStats] is used in ./utils/fetch-network-data.ts     const networkStats = await fetchNetworkStats(config);
[getNetworkParams] is used in ./node-commands.ts   getNetworkParams,
[getNetworkParams] is used in ./node-commands.ts           const networkStats = await getNetworkParams(config, descriptions);
[fetchEOADetails] is used in ./node-commands.ts   fetchEOADetails,
[fetchEOADetails] is used in ./node-commands.ts         const eoaData = await fetchEOADetails(config, address)
[fetchEOADetails] is used in ./node-commands.ts         fetchEOADetails(config, walletWithProvider.address),
[fetchEOADetails] is used in ./node-commands.ts       const eoaData = await fetchEOADetails(config, walletWithProvider.address);
[fetchValidatorVersions] is used in ./node-commands.ts   fetchValidatorVersions,
[fetchValidatorVersions] is used in ./node-commands.ts       const validatorVersions = await fetchValidatorVersions(config);
[getAccountInfoParams] is used in ./node-commands.ts   getAccountInfoParams,
[getAccountInfoParams] is used in ./node-commands.ts           getAccountInfoParams(config, publicKey),
[fetchStakeParameters] is used in ./node-commands.ts   fetchStakeParameters,
[fetchStakeParameters] is used in ./node-commands.ts           fetchStakeParameters(config),
[fetchStakeParameters] is used in ./node-commands.ts         fetchStakeParameters(config),
[fetchCycleDuration] is used in ./utils/fetch-network-data.ts   const cycleDuration = await fetchCycleDuration(config);
[fetchCycleDuration] is used in ./utils/fetch-network-data.ts   const cycleDuration = await fetchCycleDuration(config);
[getLatestCliVersion] is used in ./node-commands.ts   getLatestCliVersion,
[getLatestCliVersion] is used in ./node-commands.ts         latestCliVersion: await getLatestCliVersion(),
[getLatestGuiVersion] is used in ./node-commands.ts   getLatestGuiVersion,
[getLatestGuiVersion] is used in ./node-commands.ts           latestGuiVersion: await getLatestGuiVersion(),
[getInstalledGuiVersion] is used in ./node-commands.ts   getInstalledGuiVersion,
[getInstalledGuiVersion] is used in ./node-commands.ts           runningGuiVersion: getInstalledGuiVersion(),
[getInstalledGuiVersion] is used in ./gui-commands.ts import {getInstalledGuiVersion} from './utils/project-data';
[getInstalledGuiVersion] is used in ./gui-commands.ts       console.log(getInstalledGuiVersion());
[getInstalledValidatorVersion] is used in ./node-commands.ts   getInstalledValidatorVersion,
[getInstalledValidatorVersion] is used in ./node-commands.ts           runnningValidatorVersion: getInstalledValidatorVersion(),
[isGuiInstalled] is used in ./node-commands.ts   isGuiInstalled,
[isGuiInstalled] is used in ./node-commands.ts       if (isGuiInstalled()) {
[isGuiInstalled] is used in ./utils/project-data.ts   if (!isGuiInstalled()) {
[isValidatorInstalled] is used in ./node-commands.ts   isValidatorInstalled,
[isValidatorInstalled] is used in ./node-commands.ts       if (isValidatorInstalled()) {
[isValidatorInstalled] is used in ./utils/project-data.ts   if (!isValidatorInstalled()) {
[getBranchNameForCLI] is used in ./node-commands.ts   getBranchNameForCLI,
[getBranchNameForCLI] is used in ./node-commands.ts         runningCliBranch: await getBranchNameForCLI(),
[getBranchNameForGUI] is used in ./node-commands.ts   getBranchNameForGUI,
[getBranchNameForGUI] is used in ./node-commands.ts           runningGuiBranch: await getBranchNameForGUI(),
[getBranchNameForValidator] is used in ./node-commands.ts   getBranchNameForValidator,
[getBranchNameForValidator] is used in ./node-commands.ts           runningValidatorBranch: await getBranchNameForValidator(),
[getCommitHashForCLI] is used in ./node-commands.ts   getCommitHashForCLI,
[getCommitHashForCLI] is used in ./node-commands.ts         runningCliCommitHash: await getCommitHashForCLI(),
[getCommitHashForGUI] is used in ./node-commands.ts   getCommitHashForGUI,
[getCommitHashForGUI] is used in ./node-commands.ts           runningGuiBranchCommitHash: await getCommitHashForGUI(),
[getCommitHashForValidator] is used in ./node-commands.ts   getCommitHashForValidator,
[getCommitHashForValidator] is used in ./node-commands.ts           runningValidatorBranchCommitHash: await getCommitHashForValidator(),
[getBranchNameFor] is used in ./utils/project-data.ts   return getBranchNameFor(CLI_LOCAL_PATH);
[getBranchNameFor] is used in ./utils/project-data.ts   return getBranchNameFor(GUI_LOCAL_PATH);
[getBranchNameFor] is used in ./utils/project-data.ts   return getBranchNameFor(VALIDATOR_LOCAL_PATH);
[getCommitHash] is used in ./utils/project-data.ts   return getCommitHash(CLI_LOCAL_PATH);
[getCommitHash] is used in ./utils/project-data.ts   return getCommitHash(GUI_LOCAL_PATH);
[getCommitHash] is used in ./utils/project-data.ts   return getCommitHash(VALIDATOR_LOCAL_PATH);
[fetchExitSummary] is used in ./utils/fetch-node-data.ts   const exitSummary = fetchExitSummary();
[fetchStartSummary] is used in ./utils/fetch-node-data.ts   const startSummary = fetchStartSummary();
[fetchNodeProgress] is used in ./node-commands.ts   fetchNodeProgress,
[fetchNodeProgress] is used in ./node-commands.ts           fetchNodeProgress().then(getProgressData),
[getExitInformation] is used in ./node-commands.ts   getExitInformation,
[getExitInformation] is used in ./node-commands.ts           getExitInformation(),
[interceptExitMessage] is used in ./utils/fetch-node-data.ts     ? interceptExitMessage(exitSummary?.message)
[getProgressData] is used in ./node-commands.ts   getProgressData,
[getProgressData] is used in ./node-commands.ts           fetchNodeProgress().then(getProgressData),
[getNodeSettings] is used in ./node-commands.ts   getNodeSettings,
[getNodeSettings] is used in ./node-commands.ts       const settings = getNodeSettings();
[validatorLogExists] is used in ./utils/fetch-node-data.ts   if (!validatorLogExists(logName)) {
[fetchFromLog] is used in ./utils/fetch-node-data.ts   return fetchFromLog(`${File.EXIT_SUMMARY}`);
[fetchFromLog] is used in ./utils/fetch-node-data.ts   return fetchFromLog(`${File.START_SUMMARY}`);
[fetchFromLog] is used in ./utils/fetch-node-data.ts   return fetchFromLog(`${File.NODE_PROGRESS}`);
[fetchFromLog] is used in ./utils/fetch-node-data.ts   const startData = fetchFromLog(`${File.START_SUMMARY}`);
[convertMsToDHM] is used in ./utils/fetch-node-data.ts     totalTimeValidating: convertMsToDHM(nodeProgress.totalActiveTime)
Gmhaxx commented 1 week ago

you made me headache sir HAHA

kenny-io commented 1 week ago

Hi there i read the code but saw no unused fucntions to be sure of it i wrote a checker script in python

can you tell me waht you mean about unused code if every function is used ?

besides the only commented code are the disabled commands which I think are reserved for future use

I think the js is builded from the ts so I don't think there is a sue looking into it (but it does not look like there is unused functions)

@thibault-ketterer we have some unused and commented out code in the node-commands.ts file . The entire test file is also not used but on a second thought I think we can keep them as we'll likely use those bits later. Thank you for digging around and trying to help with this. Look at some of our other open issues and help where you can!