EPF4: UPDATE 7 This is a direct follow-up to [UPDATE 6](https://hackmd.io/WBAtfKu3RGyUw__DFw16Fw), which is basically me reviewing the experimental code i have written prior for implementing ephemery reset using Lodestar. The most important takeaway is that i will be creating three major code files within the [reset directory](https://github.com/AdedamolaXL/lodestar/tree/unstable/packages/ephemery/src/reset) in lodestar's ephemery package: * `checkTestnet.ts` * `resetTestnet.ts` * `index.ts` **NOTE:** `checkTestnet.ts` is a dependency on holly's [genesis implementation](https://github.com/atkinsonholly/lodestar/tree/feat/genesis/packages/ephemery/src/genesis). This is because the `checkTestnet` function as a whole is checking if a new ephemery genesis has been released based on the terminal timestamp and using that information to reset the client using the new genesis. I will address the `checkTestnet` function in another update so as to focus solely on `resetTestnet.ts` in this one. The `index.ts` file is simply useful for importing the aforementioned functions and doesn't warrant a deep dive. ## resetTestnet.ts ```e! async function resetTestnet(genesisRelease: string) { await stopClients(); clearDataDirs(); await downloadGenesisRelease(genesisRelease); await setupGenesis(); await startClients(); } ``` ### Priority order of important functions to execute: #### 1. `stopClients()` This is probably the most important part of the reset implementation problem. * how to stop (pause) all transactions ( & any other processes ? ) on lodestar so that we can execute the functions in [(3)]() and then perform a restart with [(2)](). * two lodestar implementation will be paused: * the beacon-chain : lodestar's [implementation](https://github.com/ChainSafe/lodestar/tree/unstable/packages/cli/src/cmds/beacon). * the validators : lodestar's [implementation](https://github.com/ChainSafe/lodestar/tree/unstable/packages/cli/src/cmds/validator). * rename `stopClients()` ==> `pauseClients()`. * add a state variable (flag) to indicate that the client has been paused * ##### pseudocode for pauseClient(): ```e! // Define a flag to track the paused state let isPaused = false; // Function to pause the client async function pauseClient() { if (!isPaused) { // Stop validating new transactions and blocks validator/index // Handle ongoing network interactions gracefully beacon/index // Set the paused flag to true isPaused = true; } } ``` #### 2. `startClients()` * confirm if a new genesis has been downloaded and created * restart the client gracefully using updated config from the new genesis created. * resume all processes and network interactions that were paused * in [update6](https://hackmd.io/WBAtfKu3RGyUw__DFw16Fw) i commented that that an implementation code for starting the beacon chain will be useful and i have found it [here](https://github.com/atkinsonholly/lodestar/blob/unstable/packages/cli/src/cmds/beacon/handler.ts#L35), thanks to pk :) * rename `startClients() ==> restartClients()`. * ##### pseduocode for restartClients(): ```e! // Function to automatically restart the client async function restartClient(latestGenesisRelease) { // Detect the trigger condition for restart (e.g: new genesis) chectTestnet() // If the client is currently paused, resume it first if (isPaused) { isPaused = false; // Resume processing and network interactions validator/index beaocn/index } // Implement logic to restart the existing client gracefully beacon/handler // Update client configuration with new genesis state or other changes beacon/index <== latestGenesisRelease // Invoke beaconHandler with the updated config to start the client await beaconHandler(updatedConfig); } // Usage examples await pauseClient(); // Pause the client await restartClient(latestGenesisRelease); // Restart the client with new genesis state ``` #### 3. `clearDataDirs() && downloadGenesisRelease(genesisRelease) && setupGenesis()` * these functions are also dependencies that will come in from holly's [genesis implementation](https://github.com/atkinsonholly/lodestar/tree/feat/genesis/packages/ephemery/src/genesis). **TODO:** * In another update i will review: * lodestar's beacon's chain [implementation](https://github.com/ChainSafe/lodestar/tree/unstable/packages/cli/src/cmds/beacon) and possibly, * the validator [implementation](https://github.com/ChainSafe/lodestar/tree/unstable/packages/cli/src/cmds/validator) as well.