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

Conversation

mask-pp
Copy link

@mask-pp mask-pp commented Feb 1, 2024

Issue Addressed

Which issue # does this PR address?
appear error when run ./setup_time.sh genesis.json:

  • grep: invalid option -- P
  • sed: 1: "genesis.json": extra characters at the end of g command
  • typo: taif in scripts/local_testnet/README.md
  • The lost of --debug-level flag in bootnode.sh
  • Avoid using GNU sed/grep in macOS system.

Proposed Changes

Please list or describe the changes introduced by this PR.

Additional Info

Please provide any additional information. For example, future considerations
or information useful for reviewers.

@CLAassistant
Copy link

CLAassistant commented Feb 1, 2024

CLA assistant check
All committers have signed the CLA.

@michaelsproul
Copy link
Member

which OS are you using where it didn't work? AFAIK our scripts are working on Linux and macOS. Are you using a BSD?

@mask-pp
Copy link
Author

mask-pp commented Feb 2, 2024

which OS are you using where it didn't work? AFAIK our scripts are working on Linux and macOS. Are you using a BSD?

My OS is macOS m3.

@michaelsproul michaelsproul added the ready-for-review The code is ready for review label Feb 4, 2024
@realbigsean realbigsean changed the base branch from stable to unstable April 4, 2024 15:26
@realbigsean
Copy link
Member

which OS are you using where it didn't work? AFAIK our scripts are working on Linux and macOS. Are you using a BSD?

On mac you need to install gnu sed and gnu grep to run these scripts. If these changes work for linux an mac out of the box, it'd be nice.

@realbigsean
Copy link
Member

@mask-pp would you mind signing the CLA?

Copy link
Member

@chong-he chong-he left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, left some comments

@@ -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.

scripts/local_testnet/bootnode.sh Show resolved Hide resolved
bootnode_enr=`cat $DATADIR/bootnode/enr.dat`
echo "- $bootnode_enr" > $TESTNET_DIR/boot_enr.yaml

echo "Generated bootnode enr and written to $TESTNET_DIR/boot_enr.yaml"
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what is the motivation of moving the initialization of boot_node to setup.sh? There is no harm here, just that the original script will have:
Now Generating bootnode enr and
Generated bootnode enr and written to $TESTNET_DIR
written to bootnode.log. Now it is written to setup.log

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.

@mask-pp
Copy link
Author

mask-pp commented Apr 23, 2024

@mask-pp would you mind signing the CLA?

Done!

@mask-pp
Copy link
Author

mask-pp commented Apr 23, 2024

Thanks for the PR, left some comments

Thanks very much for your review man.

@mask-pp mask-pp requested a review from chong-he April 23, 2024 14:47
@chong-he
Copy link
Member

chong-he commented Apr 24, 2024

Thanks for the PR, left some comments

Thanks very much for your review man.

I am good with the proposed change since it does the same thing, and it will be good for other users using MacOS trying to run a local testnet using the scripts. So I am happy to recommend merging this PR.

Thanks again!

Edit: how about the change in bootnode logs from to setup.sh: #5169 (comment)

It is not a major thing, but may I know the motivation behind? I think that should work on MacOS? If so, we can remain that part the same

@mask-pp
Copy link
Author

mask-pp commented Apr 24, 2024

Thanks for the PR, left some comments

Thanks very much for your review man.

I am good with the proposed change since it does the same thing, and it will be good for other users using MacOS trying to run a local testnet using the scripts. So I am happy to recommend merging this PR.

Thanks again!

Edit: how about the change in bootnode logs from to setup.sh: #5169 (comment)

It is not a major thing, but may I know the motivation behind? I think that should work on MacOS? If so, we can remain that part the same

Yeah, the bootnode change is optional. It is correct to write the bootnode log into bootnode.log. In order to reduce unnecessary changes I have reverted it.

@chong-he
Copy link
Member

Thanks @mask-pp

This seems to be a cleaner solution to enable MacOS to work with the script with sed -i: https://www.reddit.com/r/linux4noobs/comments/ne0ti8/why_does_sed_i_not_work_on_my_mac/

Could you give this a try and see if it works? If so, I can test linux on my end and we can use this cleaner solution

@mask-pp
Copy link
Author

mask-pp commented Apr 25, 2024

Thanks @mask-pp

This seems to be a cleaner solution to enable MacOS to work with the script with sed -i: https://www.reddit.com/r/linux4noobs/comments/ne0ti8/why_does_sed_i_not_work_on_my_mac/

Could you give this a try and see if it works? If so, I can test linux on my end and we can use this cleaner solution

It works with sed -i '' in macOS, but it doesn't work in linux.
The best way I can imagine to be compatible with mac and linux is don't use the parameter "-i".

Copy link
Member

@ackintosh ackintosh left a comment

Choose a reason for hiding this comment

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

Thanks for this PR!

I also noticed that we need to remove these lines from local-testnet.yml to avoid using GNU sed/grep in CI for macOS:

- 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

and the README in the local_testnet directory:

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

@mask-pp
Copy link
Author

mask-pp commented Apr 26, 2024

Thanks for this PR!

I also noticed that we need to remove these lines from local-testnet.yml to avoid using GNU sed/grep in CI for macOS:

- 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

and the README in the local_testnet directory:

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

Deleted.

@mask-pp mask-pp requested a review from ackintosh April 26, 2024 01:29
@chong-he
Copy link
Member

I am not sure why we need to delete the line on the README.md file? @ackintosh

As for the local-testnet.yml, does #5643 fix it?

@ackintosh
Copy link
Member

I am not sure why we need to delete the line on the README.md file? @ackintosh

If my understanding of this PR is correct, it eliminates the need for macOS users to install GNU sed/grep. They can now run start_local_testnet.sh using the built-in sed/grep commands. So the line in the README.md that encourages macOS users to install GNU sed/grep can be removed.

Copy link
Member

@ackintosh ackintosh left a comment

Choose a reason for hiding this comment

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

Thanks @mask-pp, LGTM.

Could you please update the Proposed Changes section of this comment?

@mask-pp
Copy link
Author

mask-pp commented May 4, 2024

Thanks @mask-pp, LGTM.

Could you please update the Proposed Changes section of this comment?

changed.

@dapplion
Copy link
Collaborator

Thank you so much for your contribution @mask-pp, but we recently replaced our local testnet scripts with kurtosis

@dapplion dapplion closed this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-review The code is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants