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

refactor: Simplify Web3 configuration #251

Merged
merged 1 commit into from
May 17, 2022
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ plugins/gw-schema/tmp
/docker/layer2/config/rollup-genesis-deployment.json
/docker/layer2/config/godwoken-config.toml
/docker/layer2/config/polyjuice-root-account-id
/docker/layer2/config/web3-config.env
/docker/layer2/config/web3-indexer-config.toml
/docker/manual-artifacts/
/docker/layer2-v0/data/
Expand Down
5 changes: 1 addition & 4 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ services:
RUST_BACKTRACE: full
STORE_PATH: /var/lib/layer2/data
ACCOUNTS_DIR: /accounts
POSTGRES_USER: user
POSTGRES_DB: lumos
POSTGRES_PASSWORD: password
GITHUB_RUN_ID: ${GITHUB_RUN_ID:-""}
volumes:
- ./layer2:/var/lib/layer2
Expand All @@ -111,7 +108,7 @@ services:
condition: service_completed_successfully

web3:
image: nervos/godwoken-web3-prebuilds:v1.1.0-beta
image: ghcr.io/nervosnetwork/godwoken-web3-prebuilds:compatibility-breaking-changes-871b301
healthcheck:
test: curl http://127.0.0.1:8024 || exit 1
start_period: 10s
Expand Down
8 changes: 8 additions & 0 deletions docker/layer2/config/web3-config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# see: https://github.com/nervosnetwork/godwoken-web3/tree/compatibility-breaking-changes#config-database

DATABASE_URL=postgres://user:password@postgres:5432/lumos
REDIS_URL=redis://redis:6379

GODWOKEN_JSON_RPC=http://godwoken:8119
# TODO: add Godwoken readonly node
# GODWOKEN_READONLY_JSON_RPC=<optional, default equals to GODWOKEN_JSON_RPC>
74 changes: 12 additions & 62 deletions docker/layer2/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,77 +180,28 @@ function create-polyjuice-root-account() {
log "Generate file \"$CONFIG_DIR/polyjuice-root-account-id\""
}

function generate-web3-config() {
function generate-web3-indexer-config() {
log "Start"
if [ -s "$CONFIG_DIR/web3-config.env" ]; then
log "$CONFIG_DIR/web3-config.env already exists, skip"
if [ -s "$CONFIG_DIR/web3-indexer-config.toml" ]; then
log "$CONFIG_DIR/web3-indexer-config.toml already exists, skip"
return 0
fi

if ! command -v jq &> /dev/null; then
apt-get install -y jq &>/dev/null
fi

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


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)

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 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://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

# 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).
#
# Usually, ID(3) indicates the first deposited Godwoken account.
DEFAULT_FROM_ID=3
DEFAULT_FROM_ADDRESS=0x2e9df163055245bfadd35e3a1f05f06096447c85

# 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\""
log "Finished"
}

function generate-web3-indexer-config() {
log "Start"
if [ -s "$CONFIG_DIR/web3-indexer-config.toml" ]; then
log "$CONFIG_DIR/web3-indexer-config.toml already exists, skip"
return 0
fi

source $CONFIG_DIR/web3-config.env
cat <<EOF > $CONFIG_DIR/web3-indexer-config.toml
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"
godwoken_rpc_url="$GODWOKEN_JSON_RPC"
pg_url="$DATABASE_URL"
ws_rpc_url="$GODWOKEN_WS_RPC_URL"
l2_sudt_type_script_hash="$(jq -r '.l2_sudt_validator.script_type_hash' $CONFIG_DIR/scripts-deployment.json)"
polyjuice_type_script_hash="$(jq -r '.polyjuice_validator.script_type_hash' $CONFIG_DIR/scripts-deployment.json)"
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)"

godwoken_rpc_url="http://godwoken:8119"
ws_rpc_url="ws://godwoken:8120"

pg_url="postgres://user:password@postgres:5432/lumos"
EOF

log "Generate file \"$CONFIG_DIR/web3-indexer-config.toml\""
Expand All @@ -275,7 +226,6 @@ 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

# Godwoken daemon
Expand Down
2 changes: 0 additions & 2 deletions kicker
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ function clean() {
echo "rm -f docker/layer2/config/rollup-genesis-deployment.json"
echo "rm -f docker/layer2/config/godwoken-config.toml"
echo "rm -f docker/layer2/config/polyjuice-root-account-id"
echo "rm -f docker/layer2/config/web3-config.env"
echo "rm -f docker/layer2/config/web3-indexer-config.toml"
echo "rm -rf docker/ckb-indexer/"
echo "rm -rf docker/layer1/ckb/data/"
Expand All @@ -186,7 +185,6 @@ function clean() {
rm -f docker/layer2/config/rollup-genesis-deployment.json
rm -f docker/layer2/config/godwoken-config.toml
rm -f docker/layer2/config/polyjuice-root-account-id
rm -f docker/layer2/config/web3-config.env
rm -f docker/layer2/config/web3-indexer-config.toml
rm -rf docker/ckb-indexer/
rm -rf docker/layer1/ckb/data/
Expand Down