Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scripts): fix bug about sed -i #5169

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/local-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ jobs:
run: |
brew tap ethereum/ethereum
brew install ethereum
- name: Install GNU sed & GNU grep
if: matrix.os == 'macos-12'
run: |
brew install gnu-sed grep
echo "$(brew --prefix)/opt/gnu-sed/libexec/gnubin" >> $GITHUB_PATH
echo "$(brew --prefix)/opt/grep/libexec/gnubin" >> $GITHUB_PATH
# https://github.com/actions/cache/blob/main/examples.md#rust---cargo
- uses: actions/cache@v4
id: cache-cargo
Expand Down
2 changes: 0 additions & 2 deletions scripts/local_testnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ This setup can be useful for testing and development.
The scripts require `lcli`, `lighthouse`, `geth`, `bootnode` to be installed on `PATH` (run `echo $PATH` to view all `PATH` directories).


MacOS users need to install GNU `sed` and GNU `grep`, and add them both to `PATH` as well.

The first step is to install Rust and dependencies. Refer to the [Lighthouse Book](https://lighthouse-book.sigmaprime.io/installation-source.html#dependencies) for installation. We will also need [jq](https://jqlang.github.io/jq/), which can be installed with `sudo apt install jq`.

Then, we clone the Lighthouse repository:
Expand Down
4 changes: 3 additions & 1 deletion scripts/local_testnet/bootnode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ DEBUG_LEVEL=${1:-info}

echo "Starting bootnode"

exec lighthouse boot_node \
exec lighthouse \
--debug-level $DEBUG_LEVEL \
boot_node \
mask-pp marked this conversation as resolved.
Show resolved Hide resolved
--testnet-dir $TESTNET_DIR \
--port $BOOTNODE_PORT \
--listen-address 127.0.0.1 \
Expand Down
25 changes: 15 additions & 10 deletions scripts/local_testnet/setup_time.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@ echo "slot_per_epoch=$SLOT_PER_EPOCH"
genesis_file=$1

# Update future hardforks time in the EL genesis file based on the CL genesis time
GENESIS_TIME=$(lcli pretty-ssz --spec $SPEC_PRESET --testnet-dir $TESTNET_DIR BeaconState $TESTNET_DIR/genesis.ssz | jq | grep -Po 'genesis_time": "\K.*\d')
echo $GENESIS_TIME
GENESIS_TIME=$(lcli pretty-ssz --spec $SPEC_PRESET --testnet-dir $TESTNET_DIR BeaconState $TESTNET_DIR/genesis.ssz | jq | sed -n 's/.*genesis_time": "\([0-9]*\).*/\1/p')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original script outputs the genesis_time, so does your script - they do the same thing. Not sure what do you mean by invalid option --P? Does the script not work in your OS (MacOS)?

Copy link
Author

@mask-pp mask-pp Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original script outputs the genesis_time, so does your script - they do the same thing. Not sure what do you mean by invalid option --P? Does the script not work in your OS (MacOS)?

Yeah, it doesn't work in my MacOS.

echo "GENESIS_TIME: $GENESIS_TIME"

CAPELLA_TIME=$((GENESIS_TIME + (CAPELLA_FORK_EPOCH * $SLOT_PER_EPOCH * SECONDS_PER_SLOT)))
echo $CAPELLA_TIME
sed -i 's/"shanghaiTime".*$/"shanghaiTime": '"$CAPELLA_TIME"',/g' $genesis_file
echo "SHANGHAI_TIME: $CAPELLA_TIME"
sed 's/"shanghaiTime".*$/"shanghaiTime": '"$CAPELLA_TIME"',/g' $genesis_file > "/tmp/genesis.json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the command not work in MacOS (I am not familiar with it)?

The original script with option -i in sed is to allow in-file editing straightaway, so it works. The proposed change creates a temporary file to replace the genesis.json, which does the same thing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the command not work in MacOS (I am not familiar with it)?

The original script with option -i in sed is to allow in-file editing straightaway, so it works. The proposed change creates a temporary file to replace the genesis.json, which does the same thing

It also doesn't work in MacOS, so I have to change it.

mv "/tmp/genesis.json" $genesis_file

CANCUN_TIME=$((GENESIS_TIME + (DENEB_FORK_EPOCH * $SLOT_PER_EPOCH * SECONDS_PER_SLOT)))
echo $CANCUN_TIME
sed -i 's/"cancunTime".*$/"cancunTime": '"$CANCUN_TIME"',/g' $genesis_file
PRAGUE_TIME=$((GENESIS_TIME + (ELECTRA_FORK_EPOCH * $SLOT_PER_EPOCH * SECONDS_PER_SLOT)))
echo $PRAGUE_TIME
sed -i 's/"pragueTime".*$/"pragueTime": '"$PRAGUE_TIME"',/g' $genesis_file
cat $genesis_file
echo "CANCUN_TIME: $CANCUN_TIME"
sed 's/"cancunTime".*$/"cancunTime": '"$CANCUN_TIME"',/g' $genesis_file > "/tmp/genesis.json"
mv "/tmp/genesis.json" $genesis_file


PRAGUE_TIME=$((GENESIS_TIME + (ELECTRA_FORK_EPOCH * $SLOT_PER_EPOCH * SECONDS_PER_SLOT)))
echo "PRAGUE_TIME: $PRAGUE_TIME"
sed 's/"pragueTime".*$/"pragueTime": '"$PRAGUE_TIME"',/g' $genesis_file > "/tmp/genesis.json"
mv "/tmp/genesis.json" $genesis_file
11 changes: 8 additions & 3 deletions scripts/local_testnet/start_local_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ done
sleeping 20

# Reset the `genesis.json` config file fork times.
sed -i 's/"shanghaiTime".*$/"shanghaiTime": 0,/g' $genesis_file
sed -i 's/"cancunTime".*$/"cancunTime": 0,/g' $genesis_file
sed -i 's/"pragueTime".*$/"pragueTime": 0,/g' $genesis_file
sed 's/"shanghaiTime".*$/"shanghaiTime": 0,/g' $genesis_file > "/tmp/genesis.json"
mv "/tmp/genesis.json" $genesis_file

sed 's/"cancunTime".*$/"cancunTime": 0,/g' $genesis_file > "/tmp/genesis.json"
mv "/tmp/genesis.json" $genesis_file

sed 's/"pragueTime".*$/"pragueTime": 0,/g' $genesis_file > "/tmp/genesis.json"
mv "/tmp/genesis.json" $genesis_file

for (( bn=1; bn<=$BN_COUNT; bn++ )); do
secret=$DATADIR/geth_datadir$bn/geth/jwtsecret
Expand Down