Skip to content

Commit

Permalink
reuse zkevm-contracts container
Browse files Browse the repository at this point in the history
  • Loading branch information
minhd-vu committed Oct 25, 2024
1 parent d376d42 commit cb78ffc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 56 deletions.
52 changes: 4 additions & 48 deletions deploy_l2_contracts.star
Original file line number Diff line number Diff line change
@@ -1,62 +1,18 @@
service_package = import_module("./lib/service.star")

ARTIFACTS = [
{
"name": "run-l2-contract-setup.sh",
"file": "./templates/contract-deploy/run-l2-contract-setup.sh",
},
]


def run(plan, args):
l2_rpc_url = service_package.get_l2_rpc_url(plan, args)

artifact_paths = list(ARTIFACTS)
artifacts = []
for artifact_cfg in artifact_paths:
template = read_file(src=artifact_cfg["file"])
artifact = plan.render_templates(
name=artifact_cfg["name"],
config={
artifact_cfg["name"]: struct(
template=template,
data=args
| {
"l2_rpc_url": l2_rpc_url.http,
"deterministic_deployment_proxy_branch": "master",
},
)
},
)
artifacts.append(artifact)

# Create helper service to deploy contracts
contracts_service_name = "contracts-l2" + args["deployment_suffix"]
plan.add_service(
name=contracts_service_name,
config=ServiceConfig(
image=args["l2_contracts_image"],
files={
"/opt/zkevm": Directory(persistent_key="zkevm-l2-artifacts"),
"/opt/contract-deploy/": Directory(artifact_names=artifacts),
},
# These two lines are only necessary to deploy to any Kubernetes environment (e.g. GKE).
entrypoint=["bash", "-c"],
cmd=["sleep infinity"],
user=User(uid=0, gid=0), # Run the container as root user.
),
)

# Deploy contracts.
plan.exec(
description="Deploying contracts on L2",
service_name=contracts_service_name,
service_name="contracts" + args["deployment_suffix"],
recipe=ExecRecipe(
command=[
"/bin/sh",
"-c",
"chmod +x {0} && {0}".format(
"/opt/contract-deploy/run-l2-contract-setup.sh"
"export l2_rpc_url={0} && chmod +x {1} && {1}".format(
l2_rpc_url.http,
"/opt/contract-deploy/run-l2-contract-setup.sh",
),
]
),
Expand Down
4 changes: 4 additions & 0 deletions deploy_zkevm_contracts.star
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ ARTIFACTS = [
"name": "update-ger.sh",
"file": "./templates/contract-deploy/update-ger.sh",
},
{
"name": "run-l2-contract-setup.sh",
"file": "./templates/contract-deploy/run-l2-contract-setup.sh",
},
]


Expand Down
2 changes: 1 addition & 1 deletion input_parser.star
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ DEFAULT_IMAGES = {
"zkevm_bridge_proxy_image": "haproxy:3.0-bookworm", # https://hub.docker.com/_/haproxy/tags
"zkevm_bridge_service_image": "hermeznetwork/zkevm-bridge-service:v0.6.0-RC1", # https://hub.docker.com/r/hermeznetwork/zkevm-bridge-service/tags
"zkevm_bridge_ui_image": "leovct/zkevm-bridge-ui:multi-network-2", # https://hub.docker.com/r/leovct/zkevm-bridge-ui/tags
"zkevm_contracts_image": "leovct/zkevm-contracts:v8.0.0-rc.4-fork.12", # https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags
"zkevm_contracts_image": "minhdvu/zkevm-contracts:v8.0.0-rc.4-fork.12", # https://hub.docker.com/repository/docker/leovct/zkevm-contracts/tags
"zkevm_da_image": "0xpolygon/cdk-data-availability:0.0.10", # https://hub.docker.com/r/0xpolygon/cdk-data-availability/tags
"zkevm_node_image": "hermeznetwork/zkevm-node:v0.7.3", # https://hub.docker.com/r/hermeznetwork/zkevm-node/tags
"zkevm_pool_manager_image": "hermeznetwork/zkevm-pool-manager:v0.1.1", # https://hub.docker.com/r/hermeznetwork/zkevm-pool-manager/tags
Expand Down
14 changes: 7 additions & 7 deletions templates/contract-deploy/run-l2-contract-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ wait_for_rpc_to_be_available() {
local retry_interval=5

until cast send --legacy \
--rpc-url "{{.l2_rpc_url}}" \
--rpc-url "$l2_rpc_url" \
--private-key "{{.zkevm_l2_admin_private_key}}" \
--value 0 "{{.zkevm_l2_sequencer_address}}" &> /dev/null; do
((counter++))
Expand All @@ -38,13 +38,13 @@ fund_account_on_l2() {
echo_ts "Funding $address"
cast send \
--legacy \
--rpc-url "{{.l2_rpc_url}}" \
--rpc-url "$l2_rpc_url" \
--private-key "{{.zkevm_l2_admin_private_key}}" \
--value "{{.l2_funding_amount}}" \
"$address"
}

if [[ -e "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock" ]]; then
if [[ -e "/opt/zkevm/.init-l2-complete{{.deployment_suffix}}.lock" ]]; then
echo_ts "This script has already been executed"
exit 1
fi
Expand Down Expand Up @@ -87,15 +87,15 @@ fi
echo_ts "Deploying deterministic deployment proxy on l2"
cast send \
--legacy \
--rpc-url "{{.l2_rpc_url}}" \
--rpc-url "$l2_rpc_url" \
--private-key "{{.zkevm_l2_admin_private_key}}" \
--value "$gas_cost" \
"$signer_address"
cast publish --rpc-url "{{.l2_rpc_url}}" "$transaction"
if [[ $(cast code --rpc-url "{{.l2_rpc_url}}" $deployer_address) == "0x" ]]; then
cast publish --rpc-url "$l2_rpc_url" "$transaction"
if [[ $(cast code --rpc-url "$l2_rpc_url" $deployer_address) == "0x" ]]; then
echo_ts "No code at expected l2 address: $deployer_address"
exit 1;
fi

# The contract setup is done!
touch "/opt/zkevm/.init-complete{{.deployment_suffix}}.lock"
touch "/opt/zkevm/.init-l2-complete{{.deployment_suffix}}.lock"

0 comments on commit cb78ffc

Please sign in to comment.