Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Sep 25, 2024
1 parent b0deb29 commit e9155c4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 27 deletions.
11 changes: 9 additions & 2 deletions charts/scroll-sdk/templates/init-db-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
- --timeout
- "0"
containers:
- name: init-db
- name: init-db-and-get-batch-info
image: postgres:latest
env:
- name: PG_HOST
Expand Down Expand Up @@ -49,15 +49,22 @@ spec:
value: {{ .Values.db.scroll_rds_rollup_node_password }}
- name: SCROLL_RDS_PG_PORT
value: {{ .Values.db.scroll_rds_pg_port | quote }}
command: ["bash", "-c", "./init-db.sh"]
command: ["/bin/bash", "-c", "./init-db.sh && ./wait-l1-and-get-batch-info.sh"]
volumeMounts:
- name: init-db
mountPath: /init-db.sh
subPath: init-db.sh
- name: wait-l1-and-get-batch-info
mountPath: /wait-l1-and-get-batch-info.sh
subPath: wait-l1-and-get-batch-info.sh
restartPolicy: Never
volumes:
- name: init-db
configMap:
name: init-db
defaultMode: 0777
- name: wait-l1-and-get-batch-info
configMap:
name: wait-l1-and-get-batch-info
defaultMode: 0777
backoffLimit: 4
22 changes: 0 additions & 22 deletions charts/scroll-sdk/templates/init-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,3 @@ data:
psql -h $PG_HOST -p $PG_PORT -U $PG_USER -c "alter default privileges in schema public grant select, update, insert on tables to $DB_USER;"
psql -h $PG_HOST -p $PG_PORT -U $PG_USER -c "grant usage, select on all sequences in schema public to $DB_USER;"
psql -h $PG_HOST -p $PG_PORT -U $PG_USER -c "alter default privileges in schema public grant usage, select on sequences to $DB_USER;"
echo "Getting batch information..."
# Get last finalized batch
export LAST_FINALIZED_BATCH=$(cast call "${L1_SCROLL_CHAIN_PROXY_ADDR}" "lastFinalizedBatchIndex()(uint256)" --rpc-url ${L1_RPC_ENDPOINT} | awk '{print $1}')
# Calculate last committed batch
FIRST_UNCOMMITTED_BATCH=$((LAST_FINALIZED_BATCH + 1))
while true; do
BATCH_HASH=$(cast call "${L1_SCROLL_CHAIN_PROXY_ADDR}" "committedBatches(uint256)(bytes32)" "$FIRST_UNCOMMITTED_BATCH" --rpc-url ${L1_RPC_ENDPOINT})
if [[ $BATCH_HASH == "0x0000000000000000000000000000000000000000000000000000000000000000" ]]; then
break
fi
FIRST_UNCOMMITTED_BATCH=$((FIRST_UNCOMMITTED_BATCH + 1))
done
export LAST_COMMITTED_BATCH=$((FIRST_UNCOMMITTED_BATCH - 1))
echo "SHADOW: Last Finalized Batch: $LAST_FINALIZED_BATCH Last Committed Batch: $LAST_COMMITTED_BATCH"
# Export the variables to be used by other processes
echo "export LAST_FINALIZED_BATCH=$LAST_FINALIZED_BATCH"
echo "export LAST_COMMITTED_BATCH=$LAST_COMMITTED_BATCH"
55 changes: 55 additions & 0 deletions charts/scroll-sdk/templates/wait-l1-and-get-batch-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
{{- include "scroll-sdk.labels" $ | nindent 4 }}
name: wait-l1-and-get-batch-info
data:
wait-l1-and-get-batch-info.sh: |
#!/bin/bash
apt-get update && apt-get install -y curl git
echo "Waiting for L1 contract to be ready..."
while true; do
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}' -H "Content-Type: application/json" $L1_RPC_ENDPOINT)
if [ "$HTTP_CODE" -eq 200 ]; then
echo "L1 contract is ready!"
break
else
echo "L1 contract is not responding, HTTP code: $HTTP_CODE. Retrying in 5 seconds..."
sleep 5
fi
done
echo "Getting batch information..."
curl -L https://foundry.paradigm.xyz | bash
source /root/.bashrc
foundryup
# Get last finalized batch
export LAST_FINALIZED_BATCH=$(cast call "${L1_SCROLL_CHAIN_PROXY_ADDR}" "lastFinalizedBatchIndex()(uint256)" --rpc-url ${L1_RPC_ENDPOINT} | awk '{print $1}')
# Calculate last committed batch
FIRST_UNCOMMITTED_BATCH=$((LAST_FINALIZED_BATCH + 1))
echo "Starting search from batch: $FIRST_UNCOMMITTED_BATCH"
while true; do
BATCH_HASH=$(cast call "${L1_SCROLL_CHAIN_PROXY_ADDR}" "committedBatches(uint256)(bytes32)" "$FIRST_UNCOMMITTED_BATCH" --rpc-url ${L1_RPC_ENDPOINT})
echo "Batch $FIRST_UNCOMMITTED_BATCH - Hash: $BATCH_HASH"
if [[ $BATCH_HASH == "0x0000000000000000000000000000000000000000000000000000000000000000" ]]; then
echo "Found first uncommitted batch: $FIRST_UNCOMMITTED_BATCH"
break
fi
FIRST_UNCOMMITTED_BATCH=$((FIRST_UNCOMMITTED_BATCH + 1))
done
export LAST_COMMITTED_BATCH=$((FIRST_UNCOMMITTED_BATCH - 1))
echo "Last committed batch: $LAST_COMMITTED_BATCH"
echo "SHADOW: Last Finalized Batch: $LAST_FINALIZED_BATCH Last Committed Batch: $LAST_COMMITTED_BATCH"
# Export the variables to be used by other processes
echo "export LAST_FINALIZED_BATCH=$LAST_FINALIZED_BATCH"
echo "export LAST_COMMITTED_BATCH=$LAST_COMMITTED_BATCH"
# TODO: Add logic for copying database here
6 changes: 3 additions & 3 deletions charts/scroll-sdk/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ db:
gas_oracle_password: "test1234"
rollup_node_password: "test1234"
rpc_gateway_password: "test1234"
scroll_rds_host: "xxx"
scroll_rds_user: "yyy"
scroll_rds_host: "rds-mainnet-rollup-2.c3bqxa4vukow.us-west-2.rds.amazonaws.com"
scroll_rds_user: "mainnet_infra_team_read_only"
scroll_rds_rollup_node_database: "mainnet_rollup"
scroll_rds_rollup_node_password: "zzz"
scroll_rds_rollup_node_password: "xxx"
scroll_rds_pg_port: "5432"

l1:
Expand Down

0 comments on commit e9155c4

Please sign in to comment.