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: deploy multiple op l2s #20

Merged
merged 43 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e3364b0
deploy multiple l2s
tedim52 Jun 11, 2024
cd5c11c
separate deploying factory contract and l2 contracts
tedim52 Jun 11, 2024
d1903b8
adjust network params
tedim52 Jun 11, 2024
ead655a
Merge pull request #1 from tedim52/tedi/multil2
tedim52 Jun 11, 2024
023bc7b
adjust locator
tedim52 Jun 11, 2024
bba66fe
remove redundant steps
tedim52 Jun 11, 2024
db87257
add package icon
tedim52 Jun 11, 2024
0aae947
remove priv key
tedim52 Jun 11, 2024
d3025c1
add back funding
tedim52 Jun 11, 2024
05b4a80
remove unused vars
tedim52 Jun 11, 2024
1aafeef
Apply suggestions from code review
tedim52 Jun 12, 2024
a0272aa
only add service suffix if > 1 l2s
tedim52 Jun 12, 2024
38a7a40
elaborate on deploy contract timing
tedim52 Jun 12, 2024
1bb1ca0
clarify comments
tedim52 Jun 12, 2024
4249230
redirect ethereum package
tedim52 Jun 13, 2024
6987bbf
prefund l2 accounts
tedim52 Jun 13, 2024
f88243f
switch to ethpandaops
tedim52 Jun 13, 2024
3fee4f2
fix json
tedim52 Jun 13, 2024
269be6b
create separate op genesis files artifacts for each roll up
tedim52 Jun 14, 2024
9900c98
Merge branch 'tedi/multil2'
tedim52 Jun 14, 2024
d9a0851
fix typo
tedim52 Jun 14, 2024
18d18b9
update locator
tedim52 Jun 14, 2024
3044b6f
use l2 rpc url
tedim52 Jun 17, 2024
682a970
address pr comments
tedim52 Jun 17, 2024
581bcb0
fix nested if else
tedim52 Jun 17, 2024
7c3925f
get private keys once
tedim52 Jun 17, 2024
ca3407d
add name
tedim52 Jun 17, 2024
75753d0
Merge branch 'main' into tedi/multil2
tedim52 Jun 17, 2024
47b4518
remove edit script
tedim52 Jun 17, 2024
4585858
add multi l2 config to readme
tedim52 Jun 17, 2024
3e0fc36
re order config
tedim52 Jun 17, 2024
87c27ba
rename locator
tedim52 Jun 17, 2024
8e88b7f
update readme
tedim52 Jun 17, 2024
bf13744
rm num from prefix
tedim52 Jun 17, 2024
ccfcaf6
add multi roll up yaml
tedim52 Jun 17, 2024
08bbfa0
- -> _
tedim52 Jun 17, 2024
d72c769
fix typo
tedim52 Jun 17, 2024
e8010a8
adjust docstring
tedim52 Jun 17, 2024
e88592f
rm commented sections
tedim52 Jun 17, 2024
e61f875
suffix only if multiple l2s
tedim52 Jun 18, 2024
3dd1ca2
add sanity check
barnabasbusa Jun 18, 2024
71489ac
add some tests
barnabasbusa Jun 18, 2024
332020b
add some tests
barnabasbusa Jun 18, 2024
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
Binary file added kurtosis-package-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion kurtosis.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
name: "github.com/ethpandaops/optimism-package"
name: "github.com/tedim52/optimism-package"
tedim52 marked this conversation as resolved.
Show resolved Hide resolved
125 changes: 30 additions & 95 deletions main.star
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
input_parser = import_module("./src/package_io/input_parser.star")
ethereum_package = import_module("github.com/kurtosis-tech/ethereum-package/main.star")
contract_deployer = import_module("./src/contracts/contract_deployer.star")
static_files = import_module(
"github.com/kurtosis-tech/ethereum-package/src/static_files/static_files.star"
)
participant_network = import_module("./src/participant_network.star")
blockscout = import_module("./src/blockscout/blockscout_launcher.star")
l2_launcher = import_module("./src/l2.star")

def run(plan, args={}):
"""Deploy Optimism L2s on an Ethereum L1.

def get_l1_stuff(all_l1_participants, l1_network_params):
Args:
args(yaml): Configures other aspects of the environment.
Returns:
Full Optimism L2s.
"""
plan.print("Parsing the L1 input args")
ethereum_args = args["l1"]

# Deploy the L1
plan.print("Deploying a local L1")
l1 = ethereum_package.run(plan, ethereum_args)

# Get L1 info
all_l1_participants = l1.all_participants
l1_network_params = l1.network_params
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)

# 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)

# Deploy L2s
for l2_num, l2_args in enumerate(args["l2s"]):
plan.print("deploying l2 with name {0}".format(l2_args["name"]))
l2_launcher.launch_l2(plan, l2_args, l1_config_env_vars, l1_priv_key, all_l1_participants[0].el_context)

def get_l1_config(all_l1_participants, l1_network_params):
env_vars = {}
env_vars["L1_RPC_KIND"] = "any"
env_vars["WEB3_RPC_URL"] = str(all_l1_participants[0].el_context.rpc_http_url)
Expand All @@ -30,94 +56,3 @@ def get_l1_stuff(all_l1_participants, l1_network_params):
return env_vars


def run(plan, args={}):
"""Deploy a Optimism L2 with a local L1.

Args:
args(yaml): Configures other aspects of the environment.
Returns:
A full deployment of Optimism L2
"""

# Parse the values for the args
plan.print("Parsing the L1 input args")

ethereum_args = args["ethereum_package"]

# Deploy the L1
plan.print("Deploying a local L1")
l1 = ethereum_package.run(plan, ethereum_args)
all_l1_participants = l1.all_participants
l1_network_params = l1.network_params
l1_priv_key = l1.pre_funded_accounts[
12
].private_key # reserved for L2 contract deployer
# Deploy L2 smart contracts
# Parse the values for the args
plan.print("Parsing the L2 input args")
optimism_args = args["optimism_package"]

l1_config_env_vars = get_l1_stuff(all_l1_participants, l1_network_params)

args_with_right_defaults = input_parser.input_parser(plan, optimism_args)
network_params = args_with_right_defaults.network_params

l2_config_env_vars = {}
l2_config_env_vars["L2_CHAIN_ID"] = str(network_params.network_id)
l2_config_env_vars["L2_BLOCK_TIME"] = str(network_params.seconds_per_slot)

(
el_cl_data,
gs_private_keys,
l2oo_address,
l1_bridge_address,
blockscout_env_variables,
) = contract_deployer.launch_contract_deployer(
plan,
l1_priv_key,
l1_config_env_vars,
l2_config_env_vars,
)

# Deploy the L2
plan.print("Deploying a local L2")

jwt_file = plan.upload_files(
src=static_files.JWT_PATH_FILEPATH,
name="op_jwt_file",
)

all_l2_participants = participant_network.launch_participant_network(
plan,
args_with_right_defaults.participants,
jwt_file,
network_params,
el_cl_data,
gs_private_keys,
l1_config_env_vars,
l2oo_address,
)

all_el_contexts = []
all_cl_contexts = []
for participant in all_l2_participants:
all_el_contexts.append(participant.el_context)
all_cl_contexts.append(participant.cl_context)

for additional_service in args_with_right_defaults.additional_services:
if additional_service == "blockscout":
plan.print("Launching op-blockscout")
blockscout_launcher = blockscout.launch_blockscout(
plan,
all_l1_participants[0].el_context, # first L1 EL url,
l2oo_address,
blockscout_env_variables,
)
plan.print("Successfully launched op-blockscout")

plan.print(all_l2_participants)
plan.print(
"Begin your L2 adventures by depositing some L1 Kurtosis ETH to: {0}".format(
l1_bridge_address
)
)
27 changes: 17 additions & 10 deletions network_params.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
optimism_package:
participants:
- el_type: op-geth
- el_type: op-reth
additional_services:
- blockscout
ethereum_package:
l1:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- dora
l2s:
- name: "rollup_two"
participants:
- el_type: op-geth
tedim52 marked this conversation as resolved.
Show resolved Hide resolved
additional_services:
- blockscout
tedim52 marked this conversation as resolved.
Show resolved Hide resolved
network_params:
preset: minimal
tedim52 marked this conversation as resolved.
Show resolved Hide resolved
tedim52 marked this conversation as resolved.
Show resolved Hide resolved
network_id: "3151909"
- name: "rollup_one"
participants:
- el_type: op-geth
tedim52 marked this conversation as resolved.
Show resolved Hide resolved
network_params:
preset: minimal
tedim52 marked this conversation as resolved.
Show resolved Hide resolved
network_id: "3151910"
additional_services:
- blockscout
tedim52 marked this conversation as resolved.
Show resolved Hide resolved

8 changes: 4 additions & 4 deletions src/blockscout/blockscout_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ VERIF_USED_PORTS = {
)
}


def launch_blockscout(
plan,
network_id,
el_context,
l2oo_address,
additional_env_vars,
):
postgres_output = postgres.run(
plan,
service_name="{0}-postgres".format(SERVICE_NAME_BLOCKSCOUT),
service_name="{0}-{1}-postgres".format(SERVICE_NAME_BLOCKSCOUT, network_id),
database="blockscout",
extra_configs=["max_connections=1000"],
)

config_verif = get_config_verif()
verif_service_name = "{}-verif".format(SERVICE_NAME_BLOCKSCOUT)
verif_service_name = "{0}-{1}-verif".format(SERVICE_NAME_BLOCKSCOUT, network_id)
verif_service = plan.add_service(verif_service_name, config_verif)
verif_url = "http://{}:{}/api".format(
verif_service.hostname, verif_service.ports["http"].number
Expand All @@ -70,7 +70,7 @@ def launch_blockscout(
l2oo_address,
additional_env_vars,
)
blockscout_service = plan.add_service(SERVICE_NAME_BLOCKSCOUT, config_backend)
blockscout_service = plan.add_service("{0}-{1}".format(SERVICE_NAME_BLOCKSCOUT, network_id) , config_backend)
plan.print(blockscout_service)

blockscout_url = "http://{}:{}".format(
Expand Down
56 changes: 49 additions & 7 deletions src/contracts/contract_deployer.star
Original file line number Diff line number Diff line change
@@ -1,12 +1,57 @@
IMAGE = "ethpandaops/optimism-contract-deployer:latest"

ENVRC_PATH = "/workspace/optimism/.envrc"

FACTORY_DEPLOYER_ADDRESS = "0x3fAB184622Dc19b6109349B94811493BF2a45362"
# raw tx data for deploying Create2Factory contract to L1
FACTORY_DEPLOYER_CODE = "0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222"

def deploy_factory_contract(
plan,
priv_key,
l1_config_env_vars,
):
factory_deployment_result = plan.run_sh(
description="Deploying L2 factory contract to L1 (will take a second, need to wait for L1 to finalize)",
image=IMAGE,
env_vars={
"WEB3_PRIVATE_KEY": str(priv_key),
"FUND_VALUE": "10",
"DEPLOY_CONFIG_PATH": "/workspace/optimism/packages/contracts-bedrock/deploy-config/getting-started.json",
"DEPLOYMENT_CONTEXT": "getting-started",
}
| l1_config_env_vars,
run=" && ".join([
"./packages/contracts-bedrock/scripts/getting-started/wallets.sh >> {0}".format(
ENVRC_PATH
),
"sed -i '1d' {0}".format(
ENVRC_PATH
), # Remove the first line (not commented out)
"echo 'export IMPL_SALT=$(openssl rand -hex 32)' >> {0}".format(
ENVRC_PATH
),
". {0}".format(ENVRC_PATH),
"mkdir -p /network-configs",
"web3 transfer $FUND_VALUE to $GS_ADMIN_ADDRESS", # Fund Admin
"sleep 3",
"web3 transfer $FUND_VALUE to $GS_BATCHER_ADDRESS", # Fund Batcher
"sleep 3",
"web3 transfer $FUND_VALUE to $GS_PROPOSER_ADDRESS", # Fund Proposer
"sleep 3",
"web3 transfer $FUND_VALUE to {0}".format(
FACTORY_DEPLOYER_ADDRESS
), # Fund Factory deployer
"sleep 3",
# 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 10",
"cast codesize {0} --rpc-url $L1_RPC_URL".format(FACTORY_DEPLOYER_ADDRESS),
]),
wait="2000s",
)

def launch_contract_deployer(
def deploy_l2_contracts(
plan,
priv_key,
l1_config_env_vars,
tedim52 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -47,14 +92,11 @@ def launch_contract_deployer(
"sleep 3",
"web3 transfer $FUND_VALUE to {0}".format(
FACTORY_DEPLOYER_ADDRESS
), # Fund Factory deployer
),
"sleep 3",
# 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",
"cd /workspace/optimism/packages/contracts-bedrock",
"./scripts/getting-started/config.sh",
"cast publish --rpc-url $L1_RPC_URL {0}".format(FACTORY_DEPLOYER_CODE),
"sleep 12",
"sleep 5",
"forge script scripts/Deploy.s.sol:Deploy --private-key $GS_ADMIN_PRIVATE_KEY --broadcast --rpc-url $L1_RPC_URL",
"sleep 3",
"CONTRACT_ADDRESSES_PATH=$DEPLOYMENT_OUTFILE forge script scripts/L2Genesis.s.sol:L2Genesis --sig 'runWithStateDump()' --chain-id $L2_CHAIN_ID",
Expand Down
4 changes: 2 additions & 2 deletions src/el_cl_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def launch(
# Zero-pad the index using the calculated zfill value
index_str = shared_utils.zfill_custom(index + 1, len(str(len(participants))))

el_service_name = "op-el-{0}-{1}-{2}".format(index_str, el_type, cl_type)
cl_service_name = "op-cl-{0}-{1}-{2}".format(index_str, cl_type, el_type)
el_service_name = "op-el-{0}-{1}-{2}-{3}".format(index_str, el_type, cl_type, network_params.network_id)
cl_service_name = "op-cl-{0}-{1}-{2}-{3}".format(index_str, cl_type, el_type, network_params.network_id)

el_context = el_launch_method(
plan,
Expand Down
73 changes: 73 additions & 0 deletions src/l2.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
participant_network = import_module("./participant_network.star")
blockscout = import_module("./blockscout/blockscout_launcher.star")
contract_deployer = import_module("./contracts/contract_deployer.star")
input_parser = import_module("./package_io/input_parser.star")
static_files = import_module(
"github.com/kurtosis-tech/ethereum-package/src/static_files/static_files.star"
)

def launch_l2(plan, l2_args, l1_config, l1_priv_key, l1_bootnode_context):
# Deploy L2 smart contracts
# Parse the values for the args
plan.print("Parsing the L2 input args")
args_with_right_defaults = input_parser.input_parser(plan, l2_args)
network_params = args_with_right_defaults.network_params
l2_config_env_vars = {}
l2_config_env_vars["L2_CHAIN_ID"] = str(network_params.network_id)
l2_config_env_vars["L2_BLOCK_TIME"] = str(network_params.seconds_per_slot)

(
el_cl_data,
gs_private_keys,
l2oo_address,
l1_bridge_address,
blockscout_env_variables,
) = contract_deployer.deploy_l2_contracts(
plan,
l1_priv_key, # get private key of contract deployer for this l2
l1_config,
l2_config_env_vars,
)

# Deploy the L2
plan.print("Deploying a local L2")
jwt_file = plan.upload_files(
src=static_files.JWT_PATH_FILEPATH,
name="op_jwt_file-{0}".format(network_params.network_id),
)

all_l2_participants = participant_network.launch_participant_network(
plan,
args_with_right_defaults.participants,
jwt_file,
network_params,
el_cl_data,
gs_private_keys,
l1_config,
l2oo_address,
)

all_el_contexts = []
all_cl_contexts = []
for participant in all_l2_participants:
all_el_contexts.append(participant.el_context)
all_cl_contexts.append(participant.cl_context)

for additional_service in args_with_right_defaults.additional_services:
if additional_service == "blockscout":
plan.print("Launching op-blockscout")
blockscout_launcher = blockscout.launch_blockscout(
plan,
network_params.network_id,
l1_bootnode_context, # first l1 EL url
l2oo_address,
blockscout_env_variables,
)
plan.print("Successfully launched op-blockscout")

plan.print(all_l2_participants)
plan.print(
"Begin your L2 adventures by depositing some L1 Kurtosis ETH to: {0}".format(
l1_bridge_address
)
)
4 changes: 2 additions & 2 deletions src/participant_network.star
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def launch_participant_network(

op_batcher_launcher.launch(
plan,
"op-batcher",
"op-batcher-{0}".format(network_params.network_id),
input_parser.DEFAULT_BATCHER_IMAGES["op-batcher"],
all_el_contexts[0],
all_cl_contexts[0],
Expand All @@ -58,7 +58,7 @@ def launch_participant_network(

op_proposer_launcher.launch(
plan,
"op-proposer",
"op-proposer-{0}".format(network_params.network_id),
input_parser.DEFAULT_PROPOSER_IMAGES["op-proposer"],
all_cl_contexts[0],
l1_config_env_vars,
Expand Down