EPF4: UPDATE 7

This is a direct follow-up to UPDATE 6, 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 in lodestar's ephemery package:

  • checkTestnet.ts
  • resetTestnet.ts
  • index.ts

NOTE: checkTestnet.ts is a dependency on holly's genesis implementation. 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

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:
  • rename stopClients() ==> pauseClients().
  • add a state variable (flag) to indicate that the client has been paused
  • pseudocode for pauseClient():
// 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 i commented that that an implementation code for starting the beacon chain will be useful and i have found it here, thanks to pk :)
  • rename startClients() ==> restartClients().
  • pseduocode for restartClients():
// 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()

TODO: