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

Dump devchain state on demand #11229

Open
wants to merge 1 commit into
base: release/core-contracts/12
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion packages/protocol/scripts/foundry/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export L2_DEVCHAIN_FILE_NAME="l2-devchain.json" # Name of the file that will be
export TMP_FOLDER="$PWD/.tmp"
export TEMP_DIR="$PWD/.tmp/libraries"
export ANVIL_FOLDER="$TMP_FOLDER/devchain"
export SLEEP_DURATION=20

# Contract addresses
export REGISTRY_ADDRESS="0x000000000000000000000000000000000000ce10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,4 @@ $CELO_EPOCH_REWARDS_ADDRESS 2 "0x00000000000000000000000000000000000000000000000
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "Migration script total elapsed time: $ELAPSED_TIME seconds"

# this helps to make sure that devchain state is actually being saved
sleep $SLEEP_DURATION

if [[ "${KEEP_DEVCHAIN_FOLDER:-}" == "true" ]]; then
cp $ANVIL_FOLDER/state.json $TMP_FOLDER/$L1_DEVCHAIN_FILE_NAME
echo "Keeping devchain folder as per flag."
else
# Rename devchain artifact and remove unused directory
mv $ANVIL_FOLDER/state.json $TMP_FOLDER/$L1_DEVCHAIN_FILE_NAME
rm -rf $ANVIL_FOLDER
fi
source $PWD/scripts/foundry/dump_and_save.sh $L1_DEVCHAIN_FILE_NAME
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ set -euo pipefail
# Read environment variables and constants
source $PWD/scripts/foundry/constants.sh

export KEEP_DEVCHAIN_FOLDER=true

# Generate and run L1 devchain
echo "Generating and running L1 devchain before activating L2..."
source $PWD/scripts/foundry/create_and_migrate_anvil_devchain.sh
Expand Down Expand Up @@ -50,11 +48,5 @@ forge script \
$NON_INTERACTIVE \
--rpc-url $ANVIL_RPC_URL || { echo "Migration script failed"; exit 1; }

# Give anvil enough time to save the state
sleep $SLEEP_DURATION

# # Save L2 state so it can published to NPM
mv $ANVIL_FOLDER/state.json $TMP_FOLDER/$L2_DEVCHAIN_FILE_NAME
echo "Saved anvil L2 state to $TMP_FOLDER/$L2_DEVCHAIN_FILE_NAME"

rm -rf $ANVIL_FOLDER
source $PWD/scripts/foundry/dump_and_save.sh $L2_DEVCHAIN_FILE_NAME
15 changes: 15 additions & 0 deletions packages/protocol/scripts/foundry/dump_and_save.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <output_file_name>"
exit 1
fi

echo "Dumping state..."
cast rpc anvil_dumpState --rpc-url $ANVIL_RPC_URL > $TMP_FOLDER/tmp_state
hex_data=$(cat $TMP_FOLDER/tmp_state)
echo "Saving state to $TMP_FOLDER/$1.gz"
echo $hex_data | xxd -r -p > $TMP_FOLDER/$1.gz
Copy link
Contributor

Choose a reason for hiding this comment

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

seems that this command is causing test script to fail on CI

echo "uzipping..."
gunzip $TMP_FOLDER/$1.gz


rm $TMP_FOLDER/tmp_state
7 changes: 1 addition & 6 deletions packages/protocol/scripts/foundry/start_anvil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ source $PWD/scripts/foundry/constants.sh

timestamp=`date -Iseconds`

mkdir -p $ANVIL_FOLDER
echo "Anvil state will be saved to $ANVIL_FOLDER"

# create package.json
echo "{\"name\": \"@celo/devchain-anvil\",\"version\": \"1.0.0\",\"repository\": { \"url\": \"https://github.com/celo-org/celo-monorepo\", \"directory\": \"packages/protocol/migrations_sol\" },\"homepage\": \"https://github.com/celo-org/celo-monorepo/blob/master/packages/protocol/migrations_sol/README.md\",\"description\": \"Anvil based devchain that contains core smart contracts of celo\",\"author\":\"Celo\",\"license\": \"LGPL-3.0\"}" > $TMP_FOLDER/package.json
Expand All @@ -24,12 +22,9 @@ fi
# Start anvil
anvil \
--port $ANVIL_PORT \
--dump-state $ANVIL_FOLDER \
--state-interval $STATE_INTERVAL \
--gas-limit $GAS_LIMIT \
--code-size-limit $CODE_SIZE_LIMIT \
--balance $BALANCE \
--steps-tracing &
--balance $BALANCE &
# For context "&" tells the shell to start a command as a background process.
# This allows you to continue executing other commands without waiting for the background command to finish.

Expand Down
Loading