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: add wait for sync for non kurtosis chains #49

Merged
merged 3 commits into from
Jul 4, 2024
Merged
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
15 changes: 15 additions & 0 deletions .github/tests/helder-op.yaml_norun
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
optimism_package:
participants:
- el_type: op-geth
additional_services:
- blockscout
ethereum_package:
participants:
- el_type: nethermind
network_params:
network: helder-devnet-0
devnet_repo: commit-boost
checkpoint_sync_enabled: true
checkpoint_sync_url: https://bn.bootnode.helder-devnets.xyz
additional_services:
- dora
17 changes: 12 additions & 5 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ static_files = import_module(
"github.com/ethpandaops/ethereum-package/src/static_files/static_files.star"
)
l2_launcher = import_module("./src/l2.star")
wait_for_sync = import_module("./src/wait/wait_for_sync.star")


def run(plan, args):
Expand All @@ -24,10 +25,16 @@ def run(plan, args):
# Get L1 info
all_l1_participants = l1.all_participants
l1_network_params = l1.network_params
l1_network_id = l1.network_id
l1_priv_key = l1.pre_funded_accounts[
12
].private_key # reserved for L2 contract deployers
l1_config_env_vars = get_l1_config(all_l1_participants, l1_network_params)
l1_config_env_vars = get_l1_config(
all_l1_participants, l1_network_params, l1_network_id
)

if l1_network_params.network != "kurtosis":
wait_for_sync.wait_for_sync(plan, l1_config_env_vars)

# Deploy Create2 Factory contract (only need to do this once for multiple l2s)
contract_deployer.deploy_factory_contract(plan, l1_priv_key, l1_config_env_vars)
Expand Down Expand Up @@ -77,22 +84,22 @@ def run(plan, args):
fail("invalid type provided for param: `optimism-package`")


def get_l1_config(all_l1_participants, l1_network_params):
def get_l1_config(all_l1_participants, l1_network_params, l1_network_id):
env_vars = {}
env_vars["L1_RPC_KIND"] = "any"
env_vars["WEB3_RPC_URL"] = str(all_l1_participants[0].el_context.rpc_http_url)
env_vars["L1_RPC_URL"] = str(all_l1_participants[0].el_context.rpc_http_url)
env_vars["CL_RPC_URL"] = str(all_l1_participants[0].cl_context.beacon_http_url)
env_vars["L1_CHAIN_ID"] = str(l1_network_params.network_id)
env_vars["L1_CHAIN_ID"] = str(l1_network_id)
env_vars["L1_BLOCK_TIME"] = str(l1_network_params.seconds_per_slot)
env_vars["DEPLOYMENT_OUTFILE"] = (
"/workspace/optimism/packages/contracts-bedrock/deployments/"
+ str(l1_network_params.network_id)
+ str(l1_network_id)
+ "/kurtosis.json"
)
env_vars["STATE_DUMP_PATH"] = (
"/workspace/optimism/packages/contracts-bedrock/deployments/"
+ str(l1_network_params.network_id)
+ str(l1_network_id)
+ "/state-dump.json"
)

Expand Down
9 changes: 6 additions & 3 deletions src/contracts/contract_deployer.star
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ IMAGE = "ethpandaops/optimism-contract-deployer:latest"

ENVRC_PATH = "/workspace/optimism/.envrc"
FACTORY_DEPLOYER_ADDRESS = "0x3fAB184622Dc19b6109349B94811493BF2a45362"
FACTORY_ADDRESS = "0x4e59b44847b379578588920cA78FbF26c0B4956C"
# raw tx data for deploying Create2Factory contract to L1
FACTORY_DEPLOYER_CODE = "0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222"

Expand All @@ -26,12 +27,14 @@ def deploy_factory_contract(
[
"web3 transfer $FUND_VALUE to {0}".format(FACTORY_DEPLOYER_ADDRESS),
"sleep 3",
"if [ $(cast codesize {0} --rpc-url $L1_RPC_URL) -gt 0 ]; then echo 'Factory contract already deployed!'; exit 0; fi".format(
FACTORY_ADDRESS
),
# sleep till chain is finalized
"while true; do sleep 3; echo 'Chain is not yet finalized...'; if [ \"$(curl -s $CL_RPC_URL/eth/v1/beacon/states/head/finality_checkpoints | jq -r '.data.finalized.epoch')\" != \"0\" ]; then echo 'Chain is finalized!'; break; fi; done",
"cast publish --rpc-url $L1_RPC_URL {0}".format(FACTORY_DEPLOYER_CODE),
"sleep 5",
"cast codesize {0} --rpc-url $L1_RPC_URL".format(
FACTORY_DEPLOYER_ADDRESS
"while true; do sleep 3; echo 'Factory code is not yet deployed...'; if [ $(cast codesize {0} --rpc-url $L1_RPC_URL) -gt 0 ]; then echo 'Factory contract already deployed!'; break; fi; done".format(
FACTORY_ADDRESS
),
]
),
Expand Down
21 changes: 21 additions & 0 deletions src/wait/wait_for_sync.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def wait_for_sync(plan, l1_config_env_vars):
plan.run_sh(
name="wait-for-l1-sync",
description="Wait for L1 to sync up to network - this can take up to 3days",
env_vars=l1_config_env_vars,
run='while true; do sleep 5; \
current_head=$(curl -s $CL_RPC_URL/eth/v1/node/syncing | jq -r \'.data.head_slot\'); \
sync_distance=$(curl -s $CL_RPC_URL/eth/v1/node/syncing | jq -r \'.data.sync_distance\'); \
is_optimistic=$(curl -s $CL_RPC_URL/eth/v1/node/syncing | jq -r \'.data.is_optimistic\'); \
el_sync=$(curl -s -X POST -H "Content-Type: application/json" -d \'{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}\' $L1_RPC_URL | jq -r \'.result\'); \
if [ "$el_sync" == "false" ]; then echo \'Node is starting up\'; else \
el_current_block_hex=$(echo $el_sync | jq -r \'.currentBlock\'); \
el_highest_block_hex=$(echo $el_sync | jq -r \'.highestBlock\'); \
el_current_block=$(printf %d $el_current_block_hex); \
el_highest_block=$(printf %d $el_highest_block_hex); \
number_of_blocks_left=$(($current_head - $el_highest_block)); \
fi; \
echo "Your L1 is still syncing. Current CL head is $current_head and CL sync distance is $sync_distance. EL current head is: $el_current_block and highest block is: $el_highest_block. Number of blocks left ~$number_of_blocks_left"; \
if [ "$is_optimistic" == "false" ]; then echo \'Node is synced!\'; break; fi; done',
wait="72h",
)