Skip to content

Commit

Permalink
Adapt Godwoken v1.1 (#221)
Browse files Browse the repository at this point in the history
* Adapt Godwoken v1.1

* docs: add some comments in layer2/entrypoint.sh
  • Loading branch information
Flouse authored Apr 15, 2022
1 parent 976f03e commit 99ace12
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 53 deletions.
6 changes: 3 additions & 3 deletions docker/.build.mode.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ KAFKA_PREBUILD_IMAGE_TAG=2.13-2.8.1

####[packages]
GODWOKEN_GIT_URL=https://github.com/nervosnetwork/godwoken.git
GODWOKEN_GIT_CHECKOUT=refs/pull/634/head
GODWOKEN_GIT_CHECKOUT=refs/pull/649/head
POLYMAN_GIT_URL=https://github.com/retricsu/godwoken-polyman.git
POLYMAN_GIT_CHECKOUT=compatibility-changes
WEB3_GIT_URL=https://github.com/nervosnetwork/godwoken-web3.git
WEB3_GIT_CHECKOUT=compatibility-breaking-changes
SCRIPTS_GIT_URL=https://github.com/nervosnetwork/godwoken-scripts.git
SCRIPTS_GIT_CHECKOUT=compatibility-breaking-changes
SCRIPTS_GIT_CHECKOUT=refs/pull/116/head
POLYJUICE_GIT_URL=https://github.com/nervosnetwork/godwoken-polyjuice.git
POLYJUICE_GIT_CHECKOUT=refs/pull/134/head
POLYJUICE_GIT_CHECKOUT=refs/pull/135/head
OMNI_LOCK_GIT_URL=https://github.com/nervosnetwork/ckb-production-scripts/
OMNI_LOCK_GIT_CHECKOUT=rc_lock

Expand Down
6 changes: 3 additions & 3 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ services:
condition: service_completed_successfully

godwoken:
image: ghcr.io/keroro520/godwoken-prebuilds:v1-godwoken-pull-652-202204130926
image: ghcr.io/flouse/godwoken-prebuilds:dev-202204131032
healthcheck:
test: cat /var/lib/layer2/config/polyjuice-root-account-id && curl http://127.0.0.1:8119 || exit 1
interval: 5s
Expand Down Expand Up @@ -111,7 +111,7 @@ services:
condition: service_completed_successfully

web3:
image: ghcr.io/nervosnetwork/godwoken-web3-prebuilds:compatibility-breaking-changes-1a52afb
image: ghcr.io/nervosnetwork/godwoken-web3-prebuilds:refactor-sudt-with-registry-address-c49d410
healthcheck:
test: curl http://127.0.0.1:8024 || exit 1
volumes:
Expand Down Expand Up @@ -141,7 +141,7 @@ services:
condition: service_started

web3-indexer:
image: ghcr.io/nervosnetwork/godwoken-web3-indexer-prebuilds:compatibility-breaking-changes-94e2025
image: ghcr.io/nervosnetwork/godwoken-web3-indexer-prebuilds:refactor-sudt-with-registry-address-c49d410
volumes:
- ./layer2/config:/var/lib/layer2/config
- ./web3/indexer_entrypoint.sh:/var/lib/web3-indexer/entrypoint.sh
Expand Down
1 change: 1 addition & 0 deletions docker/layer2/config/rollup-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"challenge_maturity_blocks" : 100,
"compatible_chain_id" : 1984,
"chain_id": 71400,
"finality_blocks" : 3,
"l1_sudt_cell_dep" : {
"dep_type" : "code",
Expand Down
6 changes: 3 additions & 3 deletions docker/layer2/config/scripts-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"state_validator" : "/scripts/godwoken-scripts/state-validator",
"tron_account_lock" : "/scripts/godwoken-scripts/tron-account-lock",
"withdrawal_lock" : "/scripts/godwoken-scripts/withdrawal-lock",
"eth_addr_reg_validator": "/scripts/godwoken-polyjuice/eth_addr_reg_validator",
"eth_addr_reg_generator": "/scripts/godwoken-polyjuice/eth_addr_reg_generator",
"eth_addr_reg_validator": "/scripts/godwoken-scripts/eth-addr-reg-validator",
"eth_addr_reg_generator": "/scripts/godwoken-scripts/eth-addr-reg-generator",
"omni_lock": "/scripts/godwoken-scripts/omni_lock"
},
"lock" : {
Expand All @@ -36,7 +36,7 @@
"state_validator" : "/scripts/godwoken-scripts/state-validator",
"tron_account_lock" : "/scripts/godwoken-scripts/tron-account-lock",
"withdrawal_lock" : "/scripts/godwoken-scripts/withdrawal-lock",
"eth_addr_reg_validator": "/scripts/godwoken-polyjuice/eth_addr_reg_validator",
"eth_addr_reg_validator": "/scripts/godwoken-scripts/eth-addr-reg-validator",
"omni_lock": "/scripts/godwoken-scripts/omni_lock"
}
}
69 changes: 25 additions & 44 deletions docker/layer2/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CONFIG_DIR="$WORKSPACE/config"
ACCOUNTS_DIR="${ACCOUNTS_DIR:-"ACCOUNTS_DIR is required"}"
CKB_MINER_PID=""
GODWOKEN_PID=""
COMPATIBLE_CHAIN_ID=1984
CHAIN_ID=71400

function start-ckb-miner-at-background() {
ckb -C $CONFIG_DIR miner &> /dev/null &
Expand Down Expand Up @@ -118,6 +118,8 @@ function generate-godwoken-config() {
return 0
fi

# Node: 0x2e9df163055245bfadd35e3a1f05f06096447c85 is the eth_address of
# `godwoken-block-producer.key`
RUST_BACKTRACE=full gw-tools generate-config \
--ckb-rpc http://ckb:8114 \
--ckb-indexer-rpc http://ckb-indexer:8116 \
Expand All @@ -126,9 +128,10 @@ function generate-godwoken-config() {
--omni-lock-config-path $CONFIG_DIR/scripts-deployment.json \
-g $CONFIG_DIR/rollup-genesis-deployment.json \
--rollup-config $CONFIG_DIR/rollup-config.json \
--privkey-path $ACCOUNTS_DIR/godwoken-block-producer.key \
-o $CONFIG_DIR/godwoken-config.toml \
--rpc-server-url 0.0.0.0:8119
--rpc-server-url 0.0.0.0:8119 \
--privkey-path $ACCOUNTS_DIR/godwoken-block-producer.key \
--block-producer-address 0x2e9df163055245bfadd35e3a1f05f06096447c85

# some dirty modification
if [ ! -z "$GODWOKEN_MODE" ]; then
Expand All @@ -138,7 +141,6 @@ function generate-godwoken-config() {
sed -i 's#^path = .*$#path = '"'$STORE_PATH'"'#' $CONFIG_DIR/godwoken-config.toml
fi
sed -i 's#enable_methods = \[\]#err_receipt_ws_listen = '"'0.0.0.0:8120'"'#' $CONFIG_DIR/godwoken-config.toml
config-godwoken-eoa-register

log "Generate file \"$CONFIG_DIR/godwoken-config.toml\""
}
Expand All @@ -160,8 +162,6 @@ function create-polyjuice-root-account() {
--scripts-deployment-path $CONFIG_DIR/scripts-deployment.json \
--config-path $CONFIG_DIR/godwoken-config.toml \
--capacity 2000
# update block_producer.account_id to 2, which is the first deposit account
sed -i 's#^account_id = .*$#account_id = 2#' $CONFIG_DIR/godwoken-config.toml

# Create Polyjuice root account (this is a layer2 transaction)
RUST_BACKTRACE=full gw-tools create-creator-account \
Expand All @@ -179,30 +179,6 @@ function create-polyjuice-root-account() {
log "Generate file \"$CONFIG_DIR/polyjuice-root-account-id\""
}

function config-godwoken-eoa-register() {
log "start"

# Without `eth_eoa_mapping_config` configuration, godwoken can runs, but
# everything you want to interact with godwoken will be failed.
configured_eoa_register=$(grep -q eth_eoa_mapping_config $CONFIG_DIR/godwoken-config.toml || echo "not found")
if [ ! "$configured_eoa_register" = "not found" ]; then
log "eth_eoa_mapping_config configuration already exists, skip"
return 0
fi

# User block_producer account as eth_eoa_mapping register,
# so we don't need to spend time to create (deposit) another layer2 account.
echo "" >> $CONFIG_DIR/godwoken-config.toml
echo "[eth_eoa_mapping_config.register_wallet_config]" >> $CONFIG_DIR/godwoken-config.toml
echo "privkey_path = '$ACCOUNTS_DIR/godwoken-block-producer.key'" >> $CONFIG_DIR/godwoken-config.toml
echo "[eth_eoa_mapping_config.register_wallet_config.lock]" >> $CONFIG_DIR/godwoken-config.toml
echo "args = '0x1d4b2a15f55ba1aa035f64ad6080e0943cc5ec0b'" >> $CONFIG_DIR/godwoken-config.toml
echo "hash_type = 'type'" >> $CONFIG_DIR/godwoken-config.toml
echo "code_hash = '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8'" >> $CONFIG_DIR/godwoken-config.toml

log "Configured Godwoken EOA register"
}

function generate-web3-config() {
log "Start"
if [ -s "$CONFIG_DIR/web3-config.env" ]; then
Expand All @@ -216,39 +192,41 @@ function generate-web3-config() {

creator_account_id=$(cat $CONFIG_DIR/polyjuice-root-account-id)

# TODO: get ETH_ADDRESS_REGISTRY_ACCOUNT_ID from the args of creator_script.args

cat <<EOF > $CONFIG_DIR/web3-config.env
ROLLUP_TYPE_HASH=$(jq -r '.rollup_type_hash' $CONFIG_DIR/rollup-genesis-deployment.json)
ETH_ACCOUNT_LOCK_HASH=$(jq -r '.eth_account_lock.script_type_hash' $CONFIG_DIR/scripts-deployment.json)
POLYJUICE_VALIDATOR_TYPE_HASH=$(jq -r '.polyjuice_validator.script_type_hash' $CONFIG_DIR/scripts-deployment.json)
L2_SUDT_VALIDATOR_SCRIPT_TYPE_HASH=$(jq -r '.l2_sudt_validator.script_type_hash' $CONFIG_DIR/scripts-deployment.json)
TRON_ACCOUNT_LOCK_HASH=$(jq -r '.tron_account_lock.script_type_hash' $CONFIG_DIR/scripts-deployment.json)
DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:5432/$POSTGRES_DB
REDIS_URL=redis://redis:6379
GODWOKEN_JSON_RPC=http://godwoken:8119
GODWOKEN_WS_RPC_URL=ws://godwoken:8120
PORT=8024
# the COMPATIBLE_CHAIN_ID is the identifier of our godwoken devnet;
# then we can calculate the CHAIN_ID by:
#
# eth_chain_id = [0; 24] | rollup_config.compatible_chain_id::u32 | creator_account_id::u32
# The CHAIN_ID is the identifier of our Godwoken devnet, which is defined in
# Godwoken [RollupConfig#chain_id](https://github.com/nervosnetwork/godwoken/blob/a099f2010b212355f5504a8d464b6b70d29640a5/crates/types/schemas/godwoken.mol#L64).
#
# More about chain id:
# * https://github.com/nervosnetwork/godwoken/pull/561
# * https://eips.ethereum.org/EIPS/eip-1344#specification
CHAIN_ID=$CHAIN_ID
# Polyjuice Root Account
# see: https://github.com/nervosnetwork/godwoken/blob/develop/docs/life_of_a_polyjuice_transaction.md#root-account--deployment
CREATOR_ACCOUNT_ID=$creator_account_id
COMPATIBLE_CHAIN_ID=$COMPATIBLE_CHAIN_ID
CHAIN_ID=$((($COMPATIBLE_CHAIN_ID << 32) + $creator_account_id))
# When requests "executeTransaction" RPC interface, the RawL2Transaction's
# When requesting to "executeTransaction" RPC interface, the RawL2Transaction's
# signature can be omit. Therefore we fill the RawL2Transaction.from_id
# with this DEFAULT_FROM_ID (corresponding to DEFAULT_FROM_ADDRESS).
DEFAULT_FROM_ID=2
#
# Usually, ID(3) indicates the first deposited Godwoken account.
DEFAULT_FROM_ID=3
DEFAULT_FROM_ADDRESS=0x2e9df163055245bfadd35e3a1f05f06096447c85
ETH_ADDRESS_REGISTRY_ACCOUNT_ID=3
# The builtin ETH_ADDRESS_REGISTRY_ACCOUNT_ID is 2.
# see: https://github.com/nervosnetwork/godwoken/blob/6180f04/crates/common/src/builtins.rs#L5
ETH_ADDRESS_REGISTRY_ACCOUNT_ID=2
EOF

log "Generate file \"$CONFIG_DIR/web3-config.env\""
Expand All @@ -264,12 +242,11 @@ function generate-web3-indexer-config() {

source $CONFIG_DIR/web3-config.env
cat <<EOF > $CONFIG_DIR/web3-indexer-config.toml
compatible_chain_id=$COMPATIBLE_CHAIN_ID
chain_id=$CHAIN_ID
l2_sudt_type_script_hash="$L2_SUDT_VALIDATOR_SCRIPT_TYPE_HASH"
polyjuice_type_script_hash="$POLYJUICE_VALIDATOR_TYPE_HASH"
rollup_type_hash="$ROLLUP_TYPE_HASH"
eth_account_lock_hash="$ETH_ACCOUNT_LOCK_HASH"
tron_account_lock_hash="$TRON_ACCOUNT_LOCK_HASH"
godwoken_rpc_url="$GODWOKEN_JSON_RPC"
pg_url="$DATABASE_URL"
ws_rpc_url="$GODWOKEN_WS_RPC_URL"
Expand Down Expand Up @@ -307,6 +284,9 @@ function log() {
}

function main() {
godwoken --version
gw-tools --version

# Setup Godwoken at the first time
deploy-scripts
deploy-rollup-genesis
Expand All @@ -316,6 +296,7 @@ function main() {

# Should make sure that the Polyjuice root account was created and the layer2 block was synced
create-polyjuice-root-account

generate-web3-config
generate-web3-indexer-config

Expand Down

0 comments on commit 99ace12

Please sign in to comment.