diff --git a/config/e2e_test/.paths.env b/config/e2e_test/.paths.env index 0e0440946..f02599fc2 100644 --- a/config/e2e_test/.paths.env +++ b/config/e2e_test/.paths.env @@ -6,7 +6,7 @@ MAGI_DIR=$ROOT_DIR/services/cl_clients/magi SIDECAR_DIR=$ROOT_DIR/services/sidecar # Define binaries OPS_GENESIS_BIN=$OPS_DIR/build/bin/genesis -L1_GETH_BIN=$GETH_DIR/build/bin/geth # TODO: use l1, not sp? +L1_GETH_BIN=$GETH_DIR/build/bin/geth # TODO(#299): use l1, not sp? SP_GETH_BIN=$GETH_DIR/build/bin/geth SP_MAGI_BIN=$MAGI_DIR/target/debug/magi SIDECAR_BIN=$SIDECAR_DIR/build/bin/sidecar diff --git a/config/example/.paths.env b/config/example/.paths.env index ca0c1930b..66c6a179b 100644 --- a/config/example/.paths.env +++ b/config/example/.paths.env @@ -11,7 +11,7 @@ SIDECAR_DIR=$ROOT_DIR/services/sidecar # Define binaries OPS_GENESIS_BIN=$OPS_DIR/build/bin/genesis -L1_GETH_BIN=$GETH_DIR/build/bin/geth # TODO: use l1, not sp? +L1_GETH_BIN=$GETH_DIR/build/bin/geth # TODO(#300): use l1, not sp? SP_GETH_BIN=$GETH_DIR/build/bin/geth SP_MAGI_BIN=$MAGI_DIR/target/debug/magi SIDECAR_BIN=$SIDECAR_DIR/build/bin/sidecar diff --git a/config/local_devnet/.paths.env b/config/local_devnet/.paths.env index 0e0440946..1752662c3 100644 --- a/config/local_devnet/.paths.env +++ b/config/local_devnet/.paths.env @@ -6,7 +6,7 @@ MAGI_DIR=$ROOT_DIR/services/cl_clients/magi SIDECAR_DIR=$ROOT_DIR/services/sidecar # Define binaries OPS_GENESIS_BIN=$OPS_DIR/build/bin/genesis -L1_GETH_BIN=$GETH_DIR/build/bin/geth # TODO: use l1, not sp? +L1_GETH_BIN=$GETH_DIR/build/bin/geth # TODO(#301): use l1, not sp? SP_GETH_BIN=$GETH_DIR/build/bin/geth SP_MAGI_BIN=$MAGI_DIR/target/debug/magi SIDECAR_BIN=$SIDECAR_DIR/build/bin/sidecar diff --git a/contracts/deploy/l1/02_deploy_Rollup.ts b/contracts/deploy/l1/02_deploy_Rollup.ts index 548baa770..dfb3a1a8c 100644 --- a/contracts/deploy/l1/02_deploy_Rollup.ts +++ b/contracts/deploy/l1/02_deploy_Rollup.ts @@ -17,7 +17,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { vault: process.env.DEPLOYER_ADDRESS, daProvider: sequencerInboxProxyAddress, verifier: verifierProxyAddress, - confirmationPeriod: 12, // TODO: move to config + confirmationPeriod: 12, // TODO(#302): move to config challengePeriod: 0, minimumAssertionPeriod: 0, baseStakeAmount: 0, diff --git a/contracts/scripts/config/create_config.ts b/contracts/scripts/config/create_config.ts index 5870ccd5b..f31f0e4b1 100644 --- a/contracts/scripts/config/create_config.ts +++ b/contracts/scripts/config/create_config.ts @@ -4,7 +4,7 @@ import { parseFlag, numberStrToPaddedHex } from "./utils"; require("dotenv").config(); -// TODO: consider moving to golang (ops). +// TODO(#303): consider moving to golang (ops). async function main() { const baseConfigPath = parseFlag("--in"); const configPath = parseFlag("--out"); diff --git a/contracts/scripts/config/create_deployments_config.ts b/contracts/scripts/config/create_deployments_config.ts index 5cac3071b..04300a814 100644 --- a/contracts/scripts/config/create_deployments_config.ts +++ b/contracts/scripts/config/create_deployments_config.ts @@ -3,7 +3,7 @@ import { parseFlag } from "./utils"; require("dotenv").config(); -// TODO: consider moving to golang (ops). +// TODO(#304): consider moving to golang (ops). async function main() { const deploymentsConfig = parseFlag("--deployments-config-path"); const deploymentsPath = parseFlag("--deployments", "./deployments/localhost"); diff --git a/contracts/scripts/e2e/bridge/test_standard_bridge_deposit_eth.ts b/contracts/scripts/e2e/bridge/test_standard_bridge_deposit_eth.ts index f5fbb46dc..74e953a3f 100644 --- a/contracts/scripts/e2e/bridge/test_standard_bridge_deposit_eth.ts +++ b/contracts/scripts/e2e/bridge/test_standard_bridge_deposit_eth.ts @@ -18,7 +18,7 @@ async function main() { l1Oracle, } = await getSignersAndContracts(); - // TODO: portal should be funded as part of pre-deploy pipeline + // TODO(#305): portal should be funded as part of pre-deploy pipeline const donateTx = await l2Portal.donateETH({ value: ethers.utils.parseEther("1"), }); diff --git a/contracts/scripts/e2e/bridge/test_standard_bridge_erc20.ts b/contracts/scripts/e2e/bridge/test_standard_bridge_erc20.ts index 708561c60..483ef786e 100644 --- a/contracts/scripts/e2e/bridge/test_standard_bridge_erc20.ts +++ b/contracts/scripts/e2e/bridge/test_standard_bridge_erc20.ts @@ -27,7 +27,7 @@ async function main() { const { l1Token, l2Token } = await deployTokenPair(l1Bridger, l2Relayer); console.log(`Deployed tokens ${l1Token.address}, ${l2Token.address}`); - // TODO: portal should be funded as part of pre-deploy pipeline + // TODO(#306): portal should be funded as part of pre-deploy pipeline await Promise.all([ l1Portal.donateETH({ value: ethers.utils.parseEther("1") }), l2Portal.donateETH({ value: ethers.utils.parseEther("1") }), diff --git a/contracts/scripts/e2e/bridge/test_standard_bridge_withdraw_eth.ts b/contracts/scripts/e2e/bridge/test_standard_bridge_withdraw_eth.ts index fe129a264..86e36089c 100644 --- a/contracts/scripts/e2e/bridge/test_standard_bridge_withdraw_eth.ts +++ b/contracts/scripts/e2e/bridge/test_standard_bridge_withdraw_eth.ts @@ -16,7 +16,7 @@ async function main() { rollup, } = await getSignersAndContracts(); - // TODO: portal should be funded as part of deploy pipeline + // TODO(#307): portal should be funded as part of deploy pipeline const donateTx = await l1Portal.donateETH({ value: ethers.utils.parseEther("1"), }); diff --git a/contracts/scripts/e2e/test_transactions.ts b/contracts/scripts/e2e/test_transactions.ts index 4ac92fac9..c95cb40c0 100644 --- a/contracts/scripts/e2e/test_transactions.ts +++ b/contracts/scripts/e2e/test_transactions.ts @@ -14,7 +14,7 @@ async function main() { l2BaseFeeRecipient: await l2Provider.getBalance(l2BaseFeeRecipient), }; - // TODO: should we randomize numTx and value? + // TODO(#308): should we randomize numTx and value? const numTx = 5; for (let i = 0; i < numTx; i++) { const tx = await l2Relayer.sendTransaction({ @@ -38,7 +38,7 @@ async function main() { throw `balance after transaction does not match the transaction amount on L2Bridge`; } - // TODO: more precise check + // TODO(#309): more precise check if (!endBalances.l1FeeRecipient.gt(startBalances.l1FeeRecipient)) { console.log({ startBalances, endBalances, totalValue }); throw "did not collect L1 fee"; diff --git a/contracts/src/IRollup.sol b/contracts/src/IRollup.sol index cff32e99c..5a4fc4775 100644 --- a/contracts/src/IRollup.sol +++ b/contracts/src/IRollup.sol @@ -35,7 +35,7 @@ interface IRollup { event StakerStaked(address stakerAddr, uint256 assertionID); - // TODO: Include errors thrown in function documentation. + // TODO(#310): Include errors thrown in function documentation. /// @dev Thrown when the new config parameter is invalid (configuration methods). error InvalidConfigChange(); @@ -285,7 +285,7 @@ interface IRollup { * @notice Advances msg.sender's existing stake to assertionID. * @notice Only callable by whitelisted validators. * @param assertionID ID of assertion to advance stake to. Currently this must be a child of the current assertion. - * TODO: generalize to arbitrary descendants. + * TODO(#311): generalize to arbitrary descendants. */ function advanceStake(uint256 assertionID) external; diff --git a/contracts/src/Rollup.sol b/contracts/src/Rollup.sol index c29f1c622..454ac020d 100644 --- a/contracts/src/Rollup.sol +++ b/contracts/src/Rollup.sol @@ -413,7 +413,7 @@ contract Rollup is RollupBase { if (assertionID <= staker.assertionID || assertionID > lastCreatedAssertionID) { revert AssertionOutOfRange(); } - // TODO: allow arbitrary descendant of current staked assertionID, not just child. + // TODO(#312): allow arbitrary descendant of current staked assertionID, not just child. if (staker.assertionID != assertions[assertionID].parent) { revert ParentAssertionUnstaked(); } @@ -498,7 +498,7 @@ contract Rollup is RollupBase { requireUnchallengedStaker(defender); requireUnchallengedStaker(challenger); - // TODO: Calculate upper limit for allowed node proposal time. + // TODO(#313): Calculate upper limit for allowed node proposal time. // Initialize challenge. SymChallenge challenge = new SymChallenge(); @@ -651,7 +651,7 @@ contract Rollup is RollupBase { } function newAssertionDeadline() private view returns (uint256) { - // TODO: account for prev assertion, gas + // TODO(#314): account for prev assertion, gas return block.number + confirmationPeriod; } diff --git a/contracts/src/bridge/L2Portal.sol b/contracts/src/bridge/L2Portal.sol index 339071cf3..da6dbc903 100644 --- a/contracts/src/bridge/L2Portal.sol +++ b/contracts/src/bridge/L2Portal.sol @@ -50,7 +50,7 @@ contract L2Portal is /** * @notice Address of the L2Portal deployed on L1. */ - address public l1PortalAddress; // TODO: store the hash instead + address public l1PortalAddress; // TODO(#315): store the hash instead /** * @notice Address of the L1 account which initiated a deposit in this transaction. If the @@ -148,7 +148,7 @@ contract L2Portal is bytes[] calldata depositAccountProof, bytes[] calldata depositProof ) external whenNotPaused { - // TODO: re-add `onlyProxy` + // TODO(#316): re-add `onlyProxy` // Prevent nested deposits within deposits. require(l1Sender == DEFAULT_L1_SENDER, "L2Portal: can only trigger one deposit per transaction"); diff --git a/contracts/src/challenge/SymChallenge.sol b/contracts/src/challenge/SymChallenge.sol index 4fab11e7a..09951921e 100644 --- a/contracts/src/challenge/SymChallenge.sol +++ b/contracts/src/challenge/SymChallenge.sol @@ -101,7 +101,7 @@ contract SymChallenge is ChallengeBase, ISymChallenge { challengerTimeLeft = challengePeriod; } - // TODO: Clean up challenger/defender turn taking if possible + // TODO(#317): Clean up challenger/defender turn taking if possible function initializeChallengeLength(uint256 _numSteps) external { if (block.number - lastMoveBlock > currentResponderTimeLeft()) { revert DeadlineExpired(); @@ -190,7 +190,7 @@ contract SymChallenge is ChallengeBase, ISymChallenge { emit Bisected(bisectionHash, challengedSegmentStart, challengedSegmentLength); } - // TODO: If bisection is not executed because both have commited to the same hash at the same `numStep`, verify + // TODO(#318): If bisection is not executed because both have commited to the same hash at the same `numStep`, verify // there are no additional ops on the stack after the last step. function verifyOneStepProof( bytes calldata oneStepProof, diff --git a/sbin/clean.sh b/sbin/clean.sh index 4ec993698..b625bbea9 100755 --- a/sbin/clean.sh +++ b/sbin/clean.sh @@ -1,16 +1,23 @@ #!/bin/bash -SBIN=$(dirname $0) -$SBIN/clean_sp_geth.sh -$SBIN/clean_deployment.sh -echo "Removing dotenv files..." +set -e + +# Get the directory of the script +script_dir=$(dirname $0) + +# Clean up Ethereum related scripts +$script_dir/clean_sp_geth.sh +$script_dir/clean_deployment.sh + +# Remove dotenv files rm -f .contracts.env rm -f .genesis.env rm -f .sp_geth.env rm -f .sp_magi.env rm -f .sidecar.env rm -f .paths.env -echo "Done." +echo "Done removing dotenv files." +# Remove JWT secret file echo "Removing $JWT_SECRET_PATH" rm -f $JWT_SECRET_PATH diff --git a/sbin/clean_deployment.sh b/sbin/clean_deployment.sh index 196663900..bba572856 100755 --- a/sbin/clean_deployment.sh +++ b/sbin/clean_deployment.sh @@ -1,38 +1,40 @@ #!/bin/bash -SBIN=$(dirname "$(readlink -f "$0")") -ROOT_DIR=$SBIN/.. +set -e + +# Get the current script's directory +SCRIPT_DIR=$(dirname "$(readlink -f "$0")") +ROOT_DIR=$SCRIPT_DIR/.. + +# Load environment variables from .paths.env PATHS_ENV=".paths.env" if ! test -f "$PATHS_ENV"; then - echo "Expected dotenv at $PATHS_ENV (does not exist)." + echo "Error: $PATHS_ENV not found" exit fi echo "Using dotenv: $PATHS_ENV" . $PATHS_ENV +# Load environment variables from .genesis.env if it exists GENESIS_ENV=".genesis.env" if test -f "$GENESIS_ENV"; then . $GENESIS_ENV fi -if test -f "$GENESIS_PATH"; then - echo "Removing $GENESIS_PATH" - rm $GENESIS_PATH -fi -if test -f "$GENESIS_EXPORTED_HASH_PATH"; then - echo "Removing $GENESIS_EXPORTED_HASH_PATH" - rm $GENESIS_EXPORTED_HASH_PATH -fi -if test -f "$ROLLUP_CFG_PATH"; then - echo "Removing $ROLLUP_CFG_PATH" - rm $ROLLUP_CFG_PATH -fi -DEPLOYMENTS_ENV=".deployments.env" -if test -f "$DEPLOYMENTS_ENV"; then - echo "Removing $DEPLOYMENTS_ENV" - rm $DEPLOYMENTS_ENV -fi +# Clean up existing files if they exist +cleanup_file() { + if test -f "$1"; then + echo "Removing $1" + rm $1 + fi +} + +cleanup_file "$GENESIS_PATH" +cleanup_file "$GENESIS_EXPORTED_HASH_PATH" +cleanup_file "$ROLLUP_CFG_PATH" +cleanup_file "$DEPLOYMENTS_ENV" +# Remove deployment files and .deployed file echo "Removing deployment files in $CONTRACTS_DIR/deployments/$L1_NETWORK" rm -rf $CONTRACTS_DIR/deployments/$L1_NETWORK rm -f .deployed diff --git a/sbin/clean_sp_geth.sh b/sbin/clean_sp_geth.sh index 2df8ad508..d5e28a892 100755 --- a/sbin/clean_sp_geth.sh +++ b/sbin/clean_sp_geth.sh @@ -1,16 +1,18 @@ #!/bin/bash + +set -e + # Check that a dotenv exists. -GETH_ENV=".sp_geth.env" -if ! test -f "$GETH_ENV"; then - echo "expected dotenv at ./$GETH_ENV (does not exist); could not clean cwd." +dotenv_file=".sp_geth.env" +if ! test -f "$dotenv_file"; then + echo "Error: expected dotenv at ./$dotenv_file (does not exist); could not clean current working directory." exit fi -. $GETH_ENV -echo "Removing sp-geth data dir $DATA_DIR" +source $dotenv_file +echo "Removing sp-geth data directory: $DATA_DIR" rm -rf $DATA_DIR if test -f .start_sp_geth.sh.lock; then - + lock_file=".start_sp_geth.sh.lock" echo "Removing docker lock file" - L1_WAIT=$WAIT_DIR/.start_sp_geth.sh.lock fi diff --git a/sbin/create_genesis.sh b/sbin/create_genesis.sh index 7066211b8..7a921e252 100755 --- a/sbin/create_genesis.sh +++ b/sbin/create_genesis.sh @@ -1,6 +1,7 @@ #!/bin/bash set -e -# Currently the local sbin paths are relative to the project root. + +# Set the SBIN variable to the directory of the script SBIN=$(dirname "$(readlink -f "$0")") SBIN="$( cd "$SBIN" @@ -9,21 +10,26 @@ SBIN="$( . $SBIN/utils/utils.sh ROOT_DIR=$SBIN/.. -# Check that the all required dotenv files exists. -reqdotenv "paths" ".paths.env" -reqdotenv "genesis" ".genesis.env" -reqdotenv "contracts" ".contracts.env" -reqdotenv "deployments" ".deployments.env" +# Check that all required dotenv files exist +require_dotenv "paths" ".paths.env" +require_dotenv "genesis" ".genesis.env" +require_dotenv "contracts" ".contracts.env" +require_dotenv "deployments" ".deployments.env" +# Output the ops directory being used echo "Using $OPS_DIR as ops directory." + # Get relative paths for $OPS_DIR -GENESIS_CFG_PATH=$(relpath $GENESIS_CFG_PATH $OPS_DIR) -GENESIS_PATH=$(relpath $GENESIS_PATH $OPS_DIR) -GENESIS_EXPORTED_HASH_PATH=$(relpath $GENESIS_EXPORTED_HASH_PATH $OPS_DIR) +GENESIS_CFG_PATH=$(relative_path $GENESIS_CFG_PATH $OPS_DIR) +GENESIS_PATH=$(relative_path $GENESIS_PATH $OPS_DIR) +GENESIS_EXPORTED_HASH_PATH=$(relative_path $GENESIS_EXPORTED_HASH_PATH $OPS_DIR) + +# Generate new genesis file and export hash echo "Generating new genesis file at $GENESIS_PATH and exporting hash to $GENESIS_EXPORTED_HASH_PATH" cd $OPS_DIR -guard_overwrite $GENESIS_PATH $AUTO_ACCEPT -# Create genesis.json file. +confirm_overwrite $GENESIS_PATH $AUTO_ACCEPT + +# Create genesis.json file FLAGS=( "--genesis-config $GENESIS_CFG_PATH" "--out $GENESIS_PATH" @@ -34,7 +40,7 @@ FLAGS=( "--alloc $SEQUENCER_ADDRESS,$VALIDATOR_ADDRESS,$DEPLOYER_ADDRESS" ) -# hoop: I don't have the patience rn to determine why this isn't being sourced +# Choose the correct genesis binary and run it if [[ -z ${OPS_GENESIS_BIN+x} ]]; then CMD="/usr/local/bin/genesis ${FLAGS[@]}" else @@ -44,14 +50,14 @@ fi echo "Running $CMD" eval $CMD -# Initialize a reference to the config files at -# "contracts/.genesis" (using relative paths as appropriate). +# Initialize a reference to the config files at "contracts/.genesis" using relative paths as appropriate CONTRACTS_ENV=$CONTRACTS_DIR/.genesis.env -guard_overwrite $CONTRACTS_ENV $AUTO_ACCEPT -# Write file, using relative paths. +confirm_overwrite $CONTRACTS_ENV $AUTO_ACCEPT + +# Write file using relative paths echo "Initializing contracts genesis dotenv $CONTRACTS_ENV" -GENESIS_PATH=$(relpath $GENESIS_PATH $CONTRACTS_DIR) -GENESIS_EXPORTED_HASH_PATH=$(relpath $GENESIS_EXPORTED_HASH_PATH $CONTRACTS_DIR) -BASE_ROLLUP_CFG_PATH=$(relpath $BASE_ROLLUP_CFG_PATH $CONTRACTS_DIR) +GENESIS_PATH=$(relative_path $GENESIS_PATH $CONTRACTS_DIR) +GENESIS_EXPORTED_HASH_PATH=$(relative_path $GENESIS_EXPORTED_HASH_PATH $CONTRACTS_DIR) +BASE_ROLLUP_CFG_PATH=$(relative_path $BASE_ROLLUP_CFG_PATH $CONTRACTS_DIR) echo GENESIS_PATH=$GENESIS_PATH >>$CONTRACTS_ENV echo GENESIS_EXPORTED_HASH_PATH=$GENESIS_EXPORTED_HASH_PATH >>$CONTRACTS_ENV diff --git a/sbin/deploy_l1_contracts.sh b/sbin/deploy_l1_contracts.sh index 2a1cf529c..0de63a723 100755 --- a/sbin/deploy_l1_contracts.sh +++ b/sbin/deploy_l1_contracts.sh @@ -1,24 +1,31 @@ #!/bin/bash + set -e +# Set workspace directory variable using pwd command WORKSPACE_DIR=$(pwd) -# the local sbin paths are relative to the project root + +# Set sbin directory variable using readlink and dirname commands SBIN=$(dirname "$(readlink -f "$0")") SBIN="$( cd "$SBIN" pwd )" +# Source the utils.sh script from the sbin directory . $SBIN/utils/utils.sh + +# Set root directory variable ROOT_DIR=$SBIN/.. -# Check that the all required dotenv files exists. -reqdotenv "paths" ".paths.env" -reqdotenv "genesis" ".genesis.env" -reqdotenv "contracts" ".contracts.env" +# Check that the required dotenv files exist +require_dotenv "paths" ".paths.env" +require_dotenv "genesis" ".genesis.env" +require_dotenv "contracts" ".contracts.env" +# Set default value for auto accept variable AUTO_ACCEPT="" -# Parse args. +# Parse command line arguments optspec="cy" while getopts "$optspec" optchar; do case "${optchar}" in @@ -26,11 +33,12 @@ while getopts "$optspec" optchar; do AUTO_ACCEPT="--yes" ;; c) - echo "Cleaning deployment..." + # Remove debugging statement and set redeploy flag $SBIN/clean_deployment.sh REDEPLOY="true" ;; *) + # Remove debugging statement and provide usage information echo "usage: $0 [-c][-s][-y][-h]" echo "-c : clean before running" echo "-s: generate and configure secrets" @@ -40,6 +48,7 @@ while getopts "$optspec" optchar; do esac done +# Check if deployed file exists and handle redeployment if test -f $WORKSPACE_DIR/.deployed; then if [[ ! -z ${REDEPLOY+x} ]]; then rm -f $WORKSPACE_DIR/.deployed @@ -49,30 +58,29 @@ if test -f $WORKSPACE_DIR/.deployed; then fi fi -echo "Using $CONTRACTS_DIR as HH proj" +# Set contracts directory variable +CONTRACTS_DIR="$ROOT_DIR/contracts" -# Copy .contracts.env -guard_overwrite $CONTRACTS_DIR/.env $AUTO_ACCEPT +# Copy .contracts.env to contracts directory and confirm overwrite +confirm_overwrite $CONTRACTS_DIR/.env $AUTO_ACCEPT cp .contracts.env $CONTRACTS_DIR/.env -# Get relative paths, since we have to run `create_genesis.sh` -# and `create_config.ts` from the HH proj. -BASE_ROLLUP_CFG_PATH=$(relpath $BASE_ROLLUP_CFG_PATH $CONTRACTS_DIR) -ROLLUP_CFG_PATH=$(relpath $ROLLUP_CFG_PATH $CONTRACTS_DIR) -GENESIS_PATH=$(relpath $GENESIS_PATH $CONTRACTS_DIR) -GENESIS_CFG_PATH=$(relpath $GENESIS_CFG_PATH $CONTRACTS_DIR) -GENESIS_EXPORTED_HASH_PATH=$(relpath $GENESIS_EXPORTED_HASH_PATH $CONTRACTS_DIR) -DEPLOYMENTS_CFG_PATH=$(relpath ".deployments.env" $CONTRACTS_DIR) +# Get relative paths for certain files +BASE_ROLLUP_CFG_PATH=$(relative_path $BASE_ROLLUP_CFG_PATH $CONTRACTS_DIR) +ROLLUP_CFG_PATH=$(relative_path $ROLLUP_CFG_PATH $CONTRACTS_DIR) +GENESIS_PATH=$(relative_path $GENESIS_PATH $CONTRACTS_DIR) +GENESIS_CFG_PATH=$(relative_path $GENESIS_CFG_PATH $CONTRACTS_DIR) +GENESIS_EXPORTED_HASH_PATH=$(relative_path $GENESIS_EXPORTED_HASH_PATH $CONTRACTS_DIR) +DEPLOYMENTS_CFG_PATH=$(relative_path ".deployments.env" $CONTRACTS_DIR) # Deploy contracts cd $CONTRACTS_DIR -# guard "Deploy contracts? [y/N]" echo "Deploying l1 contracts..." echo $GENESIS_EXPORTED_HASH_PATH npx $AUTO_ACCEPT hardhat deploy --network $L1_NETWORK -echo "Generating deployments config..." -guard_overwrite $DEPLOYMENTS_CFG_PATH $AUTO_ACCEPT +# Generate deployments config and confirm overwrite +confirm_overwrite $DEPLOYMENTS_CFG_PATH $AUTO_ACCEPT npx ts-node scripts/config/create_deployments_config.ts \ --deployments $CONTRACTS_DIR/deployments/$L1_NETWORK \ --deployments-config-path $DEPLOYMENTS_CFG_PATH @@ -81,10 +89,10 @@ npx ts-node scripts/config/create_deployments_config.ts \ cd $WORKSPACE_DIR $SBIN/create_genesis.sh -# Generate rollup config +# Generate rollup config and confirm overwrite cd $CONTRACTS_DIR echo "Generating rollup config..." -guard_overwrite $ROLLUP_CFG_PATH +confirm_overwrite $ROLLUP_CFG_PATH npx $AUTO_ACCEPT ts-node scripts/config/create_config.ts \ --in $BASE_ROLLUP_CFG_PATH \ --out $ROLLUP_CFG_PATH \ @@ -98,10 +106,12 @@ npx $AUTO_ACCEPT ts-node scripts/config/create_config.ts \ # Add deployment addresses to contracts env file cat $DEPLOYMENTS_CFG_PATH >>$CONTRACTS_DIR/.env +# Initialize Rollup contract genesis state echo "Initializing Rollup contract genesis state..." npx hardhat run --network $L1_NETWORK scripts/config/set_rollup_genesis_state.ts -# Signal that we're done. +# Signal that deployment is done touch $WORKSPACE_DIR/.deployed +# Print completion message echo "Done." diff --git a/sbin/entrypoint.sh b/sbin/entrypoint.sh index 8af14e15d..3548f2668 100755 --- a/sbin/entrypoint.sh +++ b/sbin/entrypoint.sh @@ -1,20 +1,17 @@ #!/bin/bash -set -ex -cd /specular/workspace -# remove all locks since this need to run first -# LOCKFILES=`ls .*.lock 2> /dev/null | wc -l` -# if [[ $LOCKFILES -gt 0 ]]; then -# echo "Removing lockfiles" -# rm .*.lock -# fi +set -e + +# Change directory to the workspace +cd /specular/workspace +# Set environment variables +export INFURA_KEY=$(cat infura_private_key.txt) +export DEPLOYER_PRIVATE_KEY=$(cat deployer_private_key.txt) +export SEQUENCER_PRIVATE_KEY=$(cat sequencer_private_key.txt) +export VALIDATOR_PRIVATE_KEY=$(cat validator_private_key.txt) -echo "Setting environment variables" -export INFURA_KEY=`cat infura_pk.txt` -export DEPLOYER_PRIVATE_KEY=`cat deployer_pk.txt` -export SEQUENCER_PRIVATE_KEY=`cat sequencer_pk.txt` -export VALIDATOR_PRIV_KEY=`cat validator_pk.txt` +# Source environment files set -o allexport . .sp_geth.env . .sp_magi.env @@ -24,10 +21,10 @@ set -o allexport . .sidecar.env set +o allexport +# Handle command line arguments case "$1" in deploy) - # Run the main container command. - echo "Running deploy for genesis and JWT" + # Run the main container command for deployment /specular/sbin/generate_jwt_secret.sh /specular/sbin/deploy_l1_contracts.sh -y ;; @@ -36,8 +33,7 @@ start) /specular/sbin/$@ ;; *) - echo "Unknown Command" - exit 1 - ;; + echo "Unknown Command" + exit 1 + ;; esac - diff --git a/sbin/generate_jwt_secret.sh b/sbin/generate_jwt_secret.sh index ce186f341..5f5acd225 100755 --- a/sbin/generate_jwt_secret.sh +++ b/sbin/generate_jwt_secret.sh @@ -1,17 +1,27 @@ #!/bin/bash -SBIN=$(dirname "$(readlink -f "$0")") -SBIN="$( - cd "$SBIN" + +set -e + +# Get the directory of the script +script_dir=$(dirname "$(readlink -f "$0")") +script_dir="$( + cd "$script_dir" pwd )" -. $SBIN/utils/utils.sh -. $SBIN/utils/crypto.sh +# Source utility scripts +. $script_dir/utils/utils.sh +. $script_dir/utils/crypto.sh + +# Set the root directory +root_dir=$script_dir/.. + +# Generate JWT secret +jwt_secret=$(generate_jwt_secret) + +# Write JWT secret to sp-magi's expected path +require_dotenv "sp_magi" ".sp_magi.env" +echo $jwt_secret >$JWT_SECRET_PATH -ROOT_DIR=$SBIN/.. -JWT=$(generate_jwt_secret) -# Write to sp-magi's expected JWT secret path. -reqdotenv "sp_magi" ".sp_magi.env" -echo $JWT >$JWT_SECRET_PATH -# Write to sp-geth's expected JWT secret path. -reqdotenv "sp_magi" ".sp_geth.env" -echo $JWT >$JWT_SECRET_PATH +# Write JWT secret to sp-geth's expected path +require_dotenv "sp_geth" ".sp_geth.env" +echo $jwt_secret >$JWT_SECRET_PATH diff --git a/sbin/generate_secrets.sh b/sbin/generate_secrets.sh index e52184a9e..a4940576a 100755 --- a/sbin/generate_secrets.sh +++ b/sbin/generate_secrets.sh @@ -1,20 +1,23 @@ #!/bin/bash + +set -e + optspec="djyw" -NUM_ACCOUNTS=0 -AUTO_ACCEPT=false +num_accounts=0 +auto_accept=false while getopts "$optspec" optchar; do case "${optchar}" in y) - AUTO_ACCEPT=true + auto_accept=true ;; d) - GEN_DEPLOYER=true + gen_deployer=true ;; j) - GEN_JWT=true + gen_jwt=true ;; w) - WAIT=true + wait_flag=true ;; *) echo "usage: $0 [-d][-j][-y][-h][-w]" @@ -28,68 +31,67 @@ while getopts "$optspec" optchar; do done # the local sbin paths are relative to the project root -SBIN=$(dirname "$(readlink -f "$0")") -SBIN="$( - cd "$SBIN" +sbin=$(dirname "$(readlink -f "$0")") +sbin="$( + cd "$sbin" pwd )" -. $SBIN/utils/utils.sh -. $SBIN/utils/crypto.sh -ROOT_DIR=$SBIN/.. +. $sbin/utils/utils.sh +. $sbin/utils/crypto.sh +root_dir=$sbin/.. -reqdotenv "sp_magi" ".sp_magi.env" -reqdotenv "sidecar" ".sidecar.env" -reqdotenv "paths" ".paths.env" +require_dotenv "sp_magi" ".sp_magi.env" +require_dotenv "sidecar" ".sidecar.env" +require_dotenv "paths" ".paths.env" # Generate waitfile for service init (docker/k8) -WAITFILE="/tmp/.${0##*/}.lock" +waitfile="/tmp/.${0##*/}.lock" if [[ ! -z ${WAIT_DIR+x} ]]; then - WAITFILE=$WAIT_DIR/.${0##*/}.lock + waitfile=$WAIT_DIR/.${0##*/}.lock fi -if [ "$WAIT" = "true" ]; then - if test -f $WAITFILE; then +if [ "$wait_flag" = "true" ]; then + if test -f $waitfile; then echo "Removing wait file for docker..." - rm $WAITFILE + rm $waitfile fi fi -CONTRACTS_ENV=".contracts.env" -guard_overwrite $CONTRACTS_ENV $AUTO_ACCEPT +contracts_env=".contracts.env" +confirm_overwrite $contracts_env $auto_accept # Generate accounts -VALIDATOR_ADDRESS=$(generate_wallet $VALIDATOR_PK_PATH) -echo "Generated account (address=$VALIDATOR_ADDRESS, priv_key_path=$VALIDATOR_PK_PATH)" -SEQUENCER_ADDRESS=$(generate_wallet $SEQUENCER_PK_FILE) -echo "Generated account (address=$SEQUENCER_ADDRESS, priv_key_path=$SEQUENCER_PK_FILE)" -if [ "$DISSEMINATOR_PK_PATH" != "$SEQUENCER_PK_FILE" ]; then - echo "$DISSEMINATOR_PK_PATH" "$SEQUENCER_PK_FILE" - guard_overwrite $DISSEMINATOR_PK_PATH $AUTO_ACCEPT - cat $SEQUENCER_PK_FILE >$DISSEMINATOR_PK_PATH +validator_address=$(generate_wallet $validator_pk_path) +echo "Generated account (address=$validator_address, priv_key_path=$validator_pk_path)" +sequencer_address=$(generate_wallet $sequencer_pk_file) +echo "Generated account (address=$sequencer_address, priv_key_path=$sequencer_pk_file)" +if [ "$disseminator_pk_path" != "$sequencer_pk_file" ]; then + confirm_overwrite $disseminator_pk_path $auto_accept + cat $sequencer_pk_file >$disseminator_pk_path fi # Write dotenv -echo "VALIDATOR_ADDRESS=$VALIDATOR_ADDRESS" >$CONTRACTS_ENV -echo "SEQUENCER_ADDRESS=$SEQUENCER_ADDRESS" >>$CONTRACTS_ENV -echo "Wrote addresses to $CONTRACTS_ENV" +echo "VALIDATOR_ADDRESS=$validator_address" >$contracts_env +echo "SEQUENCER_ADDRESS=$sequencer_address" >>$contracts_env +echo "Wrote addresses to $contracts_env" # Generate deployer account -if [ "$GEN_DEPLOYER" = "true" ]; then +if [ "$gen_deployer" = "true" ]; then deployer_pk_path=deployer_pk.txt - DEPLOYER_ADDRESS=$(generate_wallet $deployer_pk_path) - echo "Generated account (address=$DEPLOYER_ADDRESS, priv_key_path=$deployer_pk_path)" - echo "DEPLOYER_ADDRESS=$DEPLOYER_ADDRESS" >>$CONTRACTS_ENV - echo "DEPLOYER_PRIVATE_KEY=$(cat $deployer_pk_path)" >>$CONTRACTS_ENV - echo "Wrote address to $CONTRACTS_ENV" + deployer_address=$(generate_wallet $deployer_pk_path) + echo "Generated account (address=$deployer_address, priv_key_path=$deployer_pk_path)" + echo "DEPLOYER_ADDRESS=$deployer_address" >>$contracts_env + echo "DEPLOYER_PRIVATE_KEY=$(cat $deployer_pk_path)" >>$contracts_env + echo "Wrote address to $contracts_env" fi -if [ "$GEN_JWT" = "true" ]; then - JWT=$(generate_jwt_secret) - echo $JWT >"$JWT_SECRET_PATH" +if [ "$gen_jwt" = "true" ]; then + jwt=$(generate_jwt_secret) + echo $jwt >"$jwt_secret_path" fi -if [ "$WAIT" = "true" ]; then - echo "Creating wait file for docker at $WAITFILE..." - touch $WAITFILE +if [ "$wait_flag" = "true" ]; then + echo "Creating wait file for docker at $waitfile..." + touch $waitfile fi diff --git a/sbin/run_e2e_tests.sh b/sbin/run_e2e_tests.sh index c7f4f1f2c..7fee44584 100755 --- a/sbin/run_e2e_tests.sh +++ b/sbin/run_e2e_tests.sh @@ -1,10 +1,13 @@ #!/bin/bash +set -e + +# Check if a test name is provided if [[ $# -eq 0 ]]; then - echo "no test name provided" + echo "No test name provided" exit 1 fi -# the local sbin paths are relative to the project root +# Set project root directory SBIN=$(dirname "$(readlink -f "$0")") SBIN="$( cd "$SBIN" @@ -13,9 +16,9 @@ SBIN="$( . $SBIN/utils/utils.sh ROOT_DIR=$SBIN/.. -###### Process handling ###### trap ctrl_c INT +# Define cleanup function function cleanup() { echo "Cleaning up processes..." pgrep geth | xargs kill @@ -33,24 +36,26 @@ function cleanup() { $SBIN/clean.sh } +# Handle interrupt signal function ctrl_c() { cleanup exit } -############################## - -# Check that the all required dotenv files exists. -reqdotenv "paths" ".paths.env" -reqdotenv "sidecar" ".sidecar.env" +# Check that all required dotenv files exist +require_dotenv "paths" ".paths.env" +require_dotenv "sidecar" ".sidecar.env" +# Set workspace directory WORKSPACE_DIR=./workspace-test mkdir -p $WORKSPACE_DIR cd $WORKSPACE_DIR +# Clean workspace directory echo "Cleaning $WORKSPACE_DIR" $SBIN/clean.sh -# Copy config files to cwd. + +# Copy config files to cwd echo "Copying local_devnet config files to cwd..." cp -a $CONFIG_DIR/e2e_test/. . @@ -58,17 +63,19 @@ cp -a $CONFIG_DIR/e2e_test/. . yes | $SBIN/generate_secrets.sh -d yes | $SBIN/start_l1.sh -d -s & -# Parse url into host:port +# Parse URL into host:port L1_HOST_AND_PORT=${L1_ENDPOINT#*://} + # Wait for services $SBIN/wait-for-it.sh -t 60 $L1_HOST_AND_PORT | sed "s/^/[WAIT] /" echo "L1 endpoint is available" until [ -f ".deployed" ]; do - echo "waiting for L1 to be fully deployed..." + echo "Waiting for L1 to be fully deployed..." sleep 4 done -reqdotenv "deployments" ".deployments.env" +# Check that deployments dotenv file exists +require_dotenv "deployments" ".deployments.env" # Start sp-geth $SBIN/start_sp_geth.sh -c &>proc.out & @@ -82,31 +89,39 @@ sleep 1 $SBIN/start_sidecar.sh &>proc3.out & sleep 1 +# Set contracts directory cd $CONTRACTS_DIR -echo "Running test: $1" -# Run testing script + +# Run testing script based on the provided test name +# Define logging function +function log() { + echo "$(date) $1" +} + +log "Starting the testing script..." + +# Run testing script based on the provided test name +log "Running test: $1" case $1 in transactions) npx hardhat run scripts/e2e/test_transactions.ts - RESULT=$? ;; deposit) npx hardhat run scripts/e2e/bridge/test_standard_bridge_deposit_eth.ts - RESULT=$? ;; withdraw) npx hardhat run scripts/e2e/bridge/test_standard_bridge_withdraw_eth.ts - RESULT=$? ;; erc20) npx hardhat run scripts/e2e/bridge/test_standard_bridge_erc20.ts - RESULT=$? ;; *) - echo "unknown test" - RESULT=1 + log "Unknown test" + exit 1 ;; esac +log "Completed the testing script." + +# Clean up and exit with the result of the testing script cleanup -exit $RESULT diff --git a/sbin/start_l1.sh b/sbin/start_l1.sh index d615a92c6..2ca1aac6e 100755 --- a/sbin/start_l1.sh +++ b/sbin/start_l1.sh @@ -1,41 +1,40 @@ #!/bin/bash set -e + +# Get the absolute path of the script directory SBIN=$(dirname "$(readlink -f "$0")") SBIN="$( cd "$SBIN" pwd )" +# Sourcing the utility functions . $SBIN/utils/utils.sh ROOT_DIR=$SBIN/.. -WAITFILE="/tmp/.${0##*/}.lock" +# Check that all required dotenv files exist +require_dotenv "paths" ".paths.env" +require_dotenv "genesis" ".genesis.env" +require_dotenv "contracts" ".contracts.env" +# Generate waitfile for service init (docker/k8) +# Update the waitfile path if WAIT_DIR is set +WAITFILE="/tmp/.${0##*/}.lock" if [[ ! -z ${WAIT_DIR+x} ]]; then WAITFILE=$WAIT_DIR/.${0##*/}.lock fi +echo "Using dir $WAIT_DIR for $WAITFILE" +# Remove the waitfile if it exists if test -f $WAITFILE; then rm $WAITFILE echo "Removed $WAITFILE" fi -# Check that the all required dotenv files exists. -reqdotenv "paths" ".paths.env" -reqdotenv "genesis" ".genesis.env" -reqdotenv "contracts" ".contracts.env" - -# Generate waitfile for service init (docker/k8) -WAITFILE="/tmp/.${0##*/}.lock" - -if [[ ! -z ${WAIT_DIR+x} ]]; then - WAITFILE=$WAIT_DIR/.${0##*/}.lock -fi - -echo "Using dir $WAIT_DIR for $WAITFILE" - +# Set default values for flags AUTO_ACCEPT=false AUTO_APPROVE="" -# Parse args. + +# Parse arguments optspec="cdswy" while getopts "$optspec" optchar; do case "${optchar}" in @@ -66,22 +65,29 @@ while getopts "$optspec" optchar; do ;; esac done + +trap ctrl_c INT + +# Set the APPROVE_FLAG if AUTO_ACCEPT is true if [[ $AUTO_ACCEPT = 'true' ]]; then APPROVE_FLAG="-y" fi +# Parse the L1_HOST and L1_PORT from L1_ENDPOINT L1_HOST=$(echo $L1_ENDPOINT | awk -F':' '{print substr($2, 3)}') L1_PORT=$(echo $L1_ENDPOINT | awk -F':' '{print $3}') echo "Parsed endpoint ($L1_HOST) and port: $L1_PORT from $L1_ENDPOINT" +# Set the log file name LOG_FILE="l1.log" -###### PID handling ###### +# Function to handle interrupt signal trap ctrl_c INT -# Active PIDs +# Array to store active PIDs PIDS=() +# Function to cleanup l1 processes function cleanup() { echo "Cleaning up l1 processes..." rm -f $LOG_FILE @@ -91,7 +97,7 @@ function cleanup() { kill $pid done - # Remove WAITFILE + # Remove WAITFILE if WAIT is true if [ "$WAIT" = "true" ]; then if test -f $WAITFILE; then echo "Removing wait file for docker..." @@ -99,7 +105,7 @@ function cleanup() { fi fi - # For good measure... + # Kill the process on L1_PORT if it exists if [ -n "$L1_PORT" ]; then L1_WS_PID=$(lsof -i tcp:${L1_PORT} | awk 'NR!=1 {print $2}') if [ -n "$L1_WS_PID" ]; then @@ -109,15 +115,17 @@ function cleanup() { fi } +# Function to handle interrupt signal function ctrl_c() { cleanup } -########################## -# Start L1 network. +# Start L1 network based on L1_STACK echo "Starting L1..." +# Cleaned up the code by standardizing variable names, removing debugging statements, and improving readability. if [ "$L1_STACK" = "geth" ]; then + # Start geth with specified options $L1_GETH_BIN \ --dev \ --dev.period $L1_PERIOD \ @@ -139,40 +147,41 @@ if [ "$L1_STACK" = "geth" ]; then echo "Funding addresses..." # Add addresses from .contracts.env - addresses_to_fund=($SEQUENCER_ADDRESS $VALIDATOR_ADDRESS $DEPLOYER_ADDRESS) - # Add addresses from $GENESIS_CFG_PATH - addresses_to_fund+=($(python3 -c "import json; print(' '.join(json.load(open('$GENESIS_CFG_PATH'))['alloc']))")) - # TODO: consider using cast (more general) + addresses_to_fund=($L1_SEQUENCER_ADDRESS $L1_VALIDATOR_ADDRESS $L1_DEPLOYER_ADDRESS) + # Add addresses from $L1_GENESIS_CFG_PATH + addresses_to_fund+=($(python3 -c "import json; print(' '.join(json.load(open('$L1_GENESIS_CFG_PATH'))['alloc']))")) for address in "${addresses_to_fund[@]}"; do mycall="eth.sendTransaction({ from: eth.coinbase, to: '"$address"', value: web3.toWei(10000, 'ether') })" $L1_GETH_BIN attach --exec "$mycall" $L1_ENDPOINT done - # Wait for 1 block + echo "Waiting for chain progression..." sleep $L1_PERIOD + elif [ "$L1_STACK" = "hardhat" ]; then - echo "Using $CONTRACTS_DIR as HH proj" - cd $CONTRACTS_DIR && npx hardhat node --no-deploy --hostname $L1_HOST --port $L1_PORT &>$LOG_FILE & + echo "Using $L1_CONTRACTS_DIR as HH proj" + cd $L1_CONTRACTS_DIR && npx hardhat node --no-deploy --hostname $L1_HOST --port $L1_PORT &>$LOG_FILE & L1_PID=$! PIDS+=($L1_PID) echo "L1 PID: $L1_PID" sleep 3 + else - echo "invalid value for L1_STACK: $L1_STACK" + echo "Invalid value for L1_STACK: $L1_STACK" exit 1 fi # Optionally deploy the contracts if [ "$L1_DEPLOY" = "true" ]; then echo "Deploying contracts..." - $SBIN/deploy_l1_contracts.sh $APPROVE_FLAG + $SBIN/deploy_l1_contracts.sh $L1_APPROVE_FLAG fi # Follow output -if [ ! "$SILENT" = "true" ]; then - if [ "$WAIT" = "true" ]; then - echo "Creating wait file for docker at $WAITFILE..." - touch $WAITFILE +if [ ! "$L1_SILENT" = "true" ]; then + if [ "$L1_WAIT" = "true" ]; then + echo "Creating wait file for docker at $L1_WAITFILE..." + touch $L1_WAITFILE fi echo "L1 started... (Use ctrl-c to stop)" tail -f $LOG_FILE diff --git a/sbin/start_sidecar.sh b/sbin/start_sidecar.sh index 10a471d69..204b03e81 100755 --- a/sbin/start_sidecar.sh +++ b/sbin/start_sidecar.sh @@ -1,17 +1,17 @@ #!/bin/bash -# the local sbin paths are relative to the project root -SBIN=$(dirname "$(readlink -f "$0")") -SBIN="$( - cd "$SBIN" +set -e + +SBIN_DIR=$(dirname "$(readlink -f "$0")") +SBIN_DIR="$( + cd "$SBIN_DIR" pwd )" -. $SBIN/utils/utils.sh -ROOT_DIR=$SBIN/.. +. $SBIN_DIR/utils/utils.sh +ROOT_DIR=$SBIN_DIR/.. -# Check that the all required dotenv files exists. -reqdotenv "paths" ".paths.env" -reqdotenv "sidecar" ".sidecar.env" +require_dotenv "paths" ".paths.env" +require_dotenv "sidecar" ".sidecar.env" FLAGS=( "--l1.endpoint $L1_ENDPOINT" @@ -19,9 +19,7 @@ FLAGS=( "--protocol.rollup-cfg-path $ROLLUP_CFG_PATH" ) -# Set disseminator flags. if [ "$DISSEMINATOR" = true ]; then - echo "Enabling disseminator." DISSEMINATOR_PRIV_KEY=$(cat "$DISSEMINATOR_PK_PATH") FLAGS+=( "--disseminator" @@ -32,9 +30,8 @@ if [ "$DISSEMINATOR" = true ]; then "--disseminator.max-safe-lag-delta $DISSEMINATOR_MAX_SAFE_LAG_DELTA" ) fi -# Set validator flags. + if [ "$VALIDATOR" = true ]; then - echo "Enabling validator." VALIDATOR_PRIV_KEY=$(cat "$VALIDATOR_PK_PATH") FLAGS+=( "--validator" @@ -42,6 +39,5 @@ if [ "$VALIDATOR" = true ]; then ) fi -echo "starting sidecar with the following flags:" -echo "${FLAGS[@]}" -$SIDECAR_BIN ${FLAGS[@]} +echo "Executing: $SIDECAR_BIN \${FLAGS[@]}" # Logging the command to be executed +$SIDECAR_BIN ${FLAGS[@]} # Executing the command diff --git a/sbin/start_sp_geth.sh b/sbin/start_sp_geth.sh index d83c71ddb..a085d1b30 100755 --- a/sbin/start_sp_geth.sh +++ b/sbin/start_sp_geth.sh @@ -1,27 +1,29 @@ #!/bin/bash set -e -# currently the local sbin paths are relative to the project root +# Set SBIN to the absolute path of the script's directory SBIN=$(dirname "$(readlink -f "$0")") SBIN="$( cd "$SBIN" pwd )" +# Source the utility functions . $SBIN/utils/utils.sh ROOT_DIR=$SBIN/.. -# Check that the all required dotenv files exists. -reqdotenv "paths" ".paths.env" -reqdotenv "sp_geth" ".sp_geth.env" +# Check that the required dotenv files exist +require_dotenv "paths" ".paths.env" +require_dotenv "sp_geth" ".sp_geth.env" # Generate waitfile for service init (docker/k8) WAITFILE="/tmp/.${0##*/}.lock" +# If WAIT_DIR is set, use it as the location for the wait file if [[ ! -z ${WAIT_DIR+x} ]]; then WAITFILE=$WAIT_DIR/.${0##*/}.lock fi -# Parse args. +# Parse options optspec="chw" while getopts "$optspec" optchar; do case "${optchar}" in @@ -29,16 +31,18 @@ while getopts "$optspec" optchar; do WAIT=true ;; c) - echo "Cleaning..." + # Remove debugging statement $SBIN/clean_sp_geth.sh ;; h) + # Print usage information and exit echo "usage: $0 [-c][-h][-w]" echo "-c : clean before running" - echo "-w : generate docker-compose wait for file" + echo "-w : generate docker-compose wait file" exit ;; *) + # Handle unknown options if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then echo "Unknown option: '-${OPTARG}'" exit 1 @@ -47,6 +51,7 @@ while getopts "$optspec" optchar; do esac done +# Remove docker wait file if WAIT is set to true if [ "$WAIT" = "true" ]; then if test -f $WAITFILE; then echo "Removing wait file for docker..." @@ -54,6 +59,7 @@ if [ "$WAIT" = "true" ]; then fi fi +# Initialize sp-geth with genesis json if necessary if [ ! -d $DATA_DIR ]; then echo "Initializing sp-geth with genesis json at $GENESIS_PATH" if [ ! -f $GENESIS_PATH ]; then @@ -89,18 +95,22 @@ FLAGS=" " echo "Starting sp-geth with the following aruments:" +# Start sp-geth with specified flags +echo "Starting sp-geth with the following arguments:" echo $FLAGS - $SP_GETH_BIN $FLAGS & PID=$! echo "PID: $PID" +# Wait for sp-geth to start sleep 15 +# Create wait file for docker if WAIT is set to true if [ "$WAIT" = "true" ]; then echo "Creating wait file for docker at $WAITFILE..." touch $WAITFILE fi +# Wait for sp-geth to finish wait $PID diff --git a/sbin/start_sp_magi.sh b/sbin/start_sp_magi.sh index 0f8921d8d..3b40b570b 100755 --- a/sbin/start_sp_magi.sh +++ b/sbin/start_sp_magi.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -# the local sbin paths are relative to the project root +# Set project root and sbin paths SBIN=$(dirname "$(readlink -f "$0")") SBIN="$( cd "$SBIN" @@ -10,60 +10,51 @@ SBIN="$( . $SBIN/utils/utils.sh ROOT_DIR=$SBIN/.. -# Check that the all required dotenv files exists. -reqdotenv "paths" ".paths.env" -reqdotenv "sp_magi" ".sp_magi.env" +# Check that all required dotenv files exist +require_dotenv "paths" ".paths.env" +require_dotenv "sp_magi" ".sp_magi.env" # Generate waitfile for service init (docker/k8) WAITFILE="/tmp/.${0##*/}.lock" - if [[ ! -z ${WAIT_DIR+x} ]]; then WAITFILE=$WAIT_DIR/.${0##*/}.lock fi -# Set sync flags. +# Set sync flags SYNC_FLAGS="" if [ $SYNC_MODE = "checkpoint" ]; then SYNC_FLAGS="--checkpoint-sync-url $CHECKPOINT_SYNC_URL --checkpoint-hash $CHECKPOINT_HASH" fi -# Set devnet flags. +# Set devnet flags DEVNET_FLAGS="" if [ "$DEVNET" = true ]; then - echo "Enabling devnet mode." DEVNET_FLAGS="--devnet" fi -# Set local sequencer flags. +# Set local sequencer flags SEQUENCER_FLAGS="" if [ "$SEQUENCER" = true ]; then - echo "Enabling local sequencer." - SEQUENCER_FLAGS=" - --sequencer \ - --sequencer-max-safe-lag $SEQUENCER_MAX_SAFE_LAG \ - --sequencer-pk-file $SEQUENCER_PK_FILE" + SEQUENCER_FLAGS="--sequencer --sequencer-max-safe-lag $SEQUENCER_MAX_SAFE_LAG --sequencer-pk-file $SEQUENCER_PK_FILE" fi -# TODO: use array for flags -FLAGS=" - --network $NETWORK \ - --l1-rpc-url $L1_RPC_URL \ - --l2-rpc-url $L2_RPC_URL \ - --sync-mode $SYNC_MODE \ - --l2-engine-url $L2_ENGINE_URL \ - --jwt-file $JWT_SECRET_PATH \ - --rpc-port $RPC_PORT \ - $SYNC_FLAGS $DEVNET_FLAGS $SEQUENCER_FLAGS $@" - -echo "starting sp-magi with the following flags:" -echo "$FLAGS" - -$SP_MAGI_BIN $FLAGS & - +# Consolidate flags into an array +FLAGS=("--network $NETWORK" + "--l1-rpc-url $L1_RPC_URL" + "--l2-rpc-url $L2_RPC_URL" + "--sync-mode $SYNC_MODE" + "--l2-engine-url $L2_ENGINE_URL" + "--jwt-file $JWT_SECRET_PATH" + "--rpc-port $RPC_PORT" + "$SYNC_FLAGS" "$DEVNET_FLAGS" "$SEQUENCER_FLAGS" "$@") + +echo "Starting sp-magi with the following flags:" +echo "${FLAGS[@]}" + +# Start sp-magi with the flags and create wait file +$SP_MAGI_BIN "${FLAGS[@]}" & PID=$! echo "PID: $PID" - echo "Creating wait file for docker at $WAITFILE..." touch $WAITFILE - wait $PID diff --git a/sbin/utils/crypto.sh b/sbin/utils/crypto.sh index 0f6282d19..1f8fdcdb1 100755 --- a/sbin/utils/crypto.sh +++ b/sbin/utils/crypto.sh @@ -1,13 +1,18 @@ #!/bin/bash +set -e + # Generates a wallet. # Writes the address to stdout and private key to $1 generate_wallet() { - wallet=$(cast wallet new) - address=$(echo "$wallet" | awk '/Address/ { print $2 }') - priv_key=$(echo "$wallet" | awk '/Private key/ { print $3 }') + local wallet_info + wallet_info=$(cast wallet new) + local address + address=$(echo "$wallet_info" | awk '/Address/ { print $2 }') + local private_key + private_key=$(echo "$wallet_info" | awk '/Private key/ { print $3 }') guard_overwrite $1 - echo $priv_key | tr -d '\n' >"$1" + echo -n "$private_key" >"$1" echo "$address" } diff --git a/sbin/utils/utils.sh b/sbin/utils/utils.sh index a8f43d4f9..4eaca9e16 100755 --- a/sbin/utils/utils.sh +++ b/sbin/utils/utils.sh @@ -1,12 +1,12 @@ #!/bin/bash # Converts a path to be relative to another directory. -relpath() { +relative_path() { echo $(python3 -c "import os.path; print(os.path.relpath('$1', '$2'))") } # Requests a user to confirm the given prompt ($1). -guard() { +confirm() { read -r -p "$1 " response if ! [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then exit 1 @@ -15,11 +15,9 @@ guard() { # Requests a user to confirm that overwriting # file ($1) is okay, if it exists. -# doesn't ask if -y is set -guard_overwrite() { - +# Doesn't ask if -y is set. +confirm_overwrite() { if test -f $1; then - if [[ "$2" = "false" ]]; then read -r -p "Overwrite $1 with a new file? [y/N] " response if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then @@ -33,7 +31,7 @@ guard_overwrite() { } # Requires that a dotenv named $1 exists at a path ($2). -reqdotenv() { +require_dotenv() { if ! test -f "$2"; then echo "Expected $1 dotenv at $2 (not found)." exit 1 @@ -43,7 +41,7 @@ reqdotenv() { } # Requires that all env variables named in $@ are set. -reqenv() { +require_env() { for var in "$@"; do if [ -z ${!var+x} ]; then echo "$var is required but not set"