AdedamolaXL
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
EPF4: UPDATE 6 Got very busy with my other project this week, but i was able to dig into [ephemery native retention scripts](https://github.com/ephemery-testnet/ephemery-scripts/blob/master/retention.sh) and understand how ephemery reset works manually and rewrote it in typescript. Typescript is the language of choice for Lodestar. I have written the purpose of this experimental code [here](https://github.com/atkinsonholly/lodestar/pull/1), so i will just jump into my own impression of how to modify it within Lodestar here: ``` import * as fs from 'fs'; import * as path from 'path'; import * as util from 'util'; import { exec } from 'child_process'; import axios from 'axios'; import * as tar from 'tar'; const execPromise = util.promisify(exec); const genesisRepository = 'ephemery-testnet/ephemery-genesis'; const testnetDir = '/home/ethereum/testnet'; const clDataDir = '/home/ethereum/data-lodestar'; const clPort = 5052; const genesisResetInterval = 86400; // 1 day in seconds ``` **notes** * most of the constants and modules here are already present in lodestar, which is a good thing. i still want to know how directories are created though! ### START CLIENTS ``` async function startClients() { console.log('Start clients'); await execPromise('sudo systemctl start beacon-chain'); await execPromise('sudo systemctl start validator'); } ``` **notes** * this is not really neccessary, in the sense that lodestar with ephemery currently starts with `./lodestar beacon --network ephemery`. however this is done manually from the terminal by the user. * is there any implementation code in lodestar in which the client is restarted after a process? If yes, it can be repurposed here. ### STOP CLIENTS ``` async function stopClients() { console.log('Stop clients'); await execPromise('sudo systemctl stop beacon-chain'); await execPromise('sudo systemctl stop validator'); } ``` **notes:** * same as above. * stopping the client is probably not semantically correct because the client will still be implementing the following processes below after it has 'stopped' * what's being stopped actually are the transactions :). ### CLEAR DIRECTORIES ``` async function clearDataDirs() { fs.rmdirSync(path.join(clDataDir, 'beacon'), { recursive: true }); fs.unlinkSync(path.join(clDataDir, 'validators/slashing_protection.sqlite')); } ``` **notes** * this refers to the management of the directories automatically created in `.ethereum`. the directory being cleared here is lodestar's which will contain beacon configurations(?) and validator list(?). * something worth noting here is that the consensus client directories are not recreated as they are done in the original retention scripts for the execution client. i think this is so because once the client is restarted again after the reset, lodestar will reinitialize this directory automatically? * this process is indicated in the `setupGenesis` function below: ### SETUP GENESIS ``` async function setupGenesis() { console.log('Setup Genesis'); await execPromise(`~/lodestar/bin/lodestar init --datadir ${clDataDir} ${path.join(testnetDir, 'genesis.json')}`); } ``` **notes** * this function initializes lodestar while creating the neccessary directories. * however, in the original retention scripts there is no genesis setup function for the consensus clients, i wonder why it's not available ? * is it because it's already created by the execution client? * this function also indicates that the ephemery directory(`testnetDir`) will be within lodestar's directory(`clDataDir`) ### GET GITHUB RELEASE ``` async function getGithubRelease(repository: string) { try { const response = await axios.get(`https://api.github.com/repos/${repository}/releases/latest`); return response.data.tag_name; } catch (error) { console.error('Error fetching GitHub release:', error); throw error; } } ``` **notes** * this is basically grabbing the latest release of ephemery (i need to confirm it this is already being done automatically on lodestar) ### DOWNLOAD GENESIS RELEASE ``` async function downloadGenesisRelease(genesisRelease: string) { console.log('Download Genesis Release'); const testnetDirExists = fs.existsSync(testnetDir); if (testnetDirExists) { fs.rmdirSync(testnetDir); } fs.mkdirSync(testnetDir, { recursive: true }); const response = await axios.get(`https://github.com/${genesisRepository}/releases/download/${genesisRelease}/testnet-all.tar.gz`, { responseType: 'stream' }); response.data.pipe(tar.x({ C: testnetDir })); await new Promise((resolve, reject) => { response.data.on('end', resolve); response.data.on('error', reject); }); } ``` **notes:** * if there is a new github release, this function downloads it. more file management here; this release will be downloaded into the `.ethereum` folder as well. * lodestar like every other client after initialization has files within the `.ethereum`. so i suspect something similar to this will be available already. ### RESET TESTNET ``` async function resetTestnet(genesisRelease: string) { await stopClients(); clearDataDirs(); await downloadGenesisRelease(genesisRelease); await setupGenesis(); await startClients(); } ``` **notes** * this function encompasses all the previous functions and implements them sequentially one after the other. * (i think) most of these functions already exist in some form on lodestar and i will just need to modify them as neccessary. * thus, this function will likely end up importing them into the [ephemery package within lodestar](https://github.com/atkinsonholly/lodestar/tree/unstable/packages/ephemery) where the reset can happen. ### CHECK TESTNET ``` async function checkTestnet() { const currentTime = Math.floor(Date.now() / 1000); const genesisTimeResponse = await axios.get(`http://localhost:${clPort}/eth/v1/beacon/genesis`); const genesisTime = genesisTimeResponse.data.genesis_time; if (!genesisTime || genesisTime <= 0) { console.error('Could not get genesis time from beacon node'); return; } const retentionVarsPath = path.join(testnetDir, 'retention.vars'); if (!fs.existsSync(retentionVarsPath)) { console.error('Could not find retention.vars'); return; } const { GENESIS_RESET_INTERVAL, ITERATION_RELEASE, CHAIN_ID } = require(retentionVarsPath); const testnetTimeout = genesisTime + GENESIS_RESET_INTERVAL - 300; console.log(`Genesis timeout: ${testnetTimeout - currentTime} sec`); if (testnetTimeout <= currentTime) { const latestGenesisRelease = await getGithubRelease(genesisRepository); if (!ITERATION_RELEASE) { process.env.ITERATION_RELEASE = CHAIN_ID; } if (latestGenesisRelease === ITERATION_RELEASE) { console.error(`Could not find new genesis release (release: ${latestGenesisRelease})`); return; } await resetTestnet(latestGenesisRelease); } } ``` **notes** * this function does the same thing as the previous in that it will be importing the previous functions (including the reset function). * this function is checking if it's time to reset the testnet so as to proceed towards downloading a new genesis. ### MAIN ``` async function main() { const genesisJsonPath = path.join(testnetDir, 'genesis.json'); if (!fs.existsSync(genesisJsonPath)) { const latestGenesisRelease = await getGithubRelease(genesisRepository); await resetTestnet(latestGenesisRelease); } else { await checkTestnet(); } } ``` **notes** * this function will end up being an index file in keeping with lodestar best practice of setting up files in directories using typescript. * this suggests that the code files within ephemery/reset directory will look somewhat like this: * `checktestnet.ts` * `reset.ts` * `index.ts` Where the `index.ts` imports all the aforementioned functions to implement ephemery reset automatically.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully