Skip to content

Commit

Permalink
feat: weave vm da integration (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
allnil authored Jan 19, 2025
1 parent eb5a8a4 commit b6b3747
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export EXECUTABLE="rollapp-evm"
export the following variables:

```shell
export DA_CLIENT="" # choose DA client: celestia, weavevm, next configuration can depends on it

export CELESTIA_NETWORK="mock" # for a testnet RollApp use "mocha", for mainnet - "celestia"
export CELESTIA_HOME_DIR="${HOME}/.da"

Expand Down
79 changes: 55 additions & 24 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#!/bin/bash
EXECUTABLE=$(which rollapp-evm)

if ! command -v "$EXECUTABLE" >/dev/null; then
echo "$EXECUTABLE does not exist"
echo "please run make install"
exit 1
fi

if [ "$ROLLAPP_CHAIN_ID" = "" ]; then
echo "ROLLAPP_CHAIN_ID is not set" exit 1
echo "ROLLAPP_CHAIN_ID is not set"
exit 1
fi


if [ "$BASE_DENOM" = "" ]; then
echo "BASE_DENOM is not set" exit 1
echo "BASE_DENOM is not set"
exit 1
fi


# ---------------------------- initial parameters ---------------------------- #
CONFIG_DIRECTORY="$ROLLAPP_HOME_DIR/config"
APP_CONFIG_FILE="$CONFIG_DIRECTORY/app.toml"
GENESIS_FILE="$CONFIG_DIRECTORY/genesis.json"

# ---------------------------- check variables ---------------------------- #
if [ "$MONIKER" = "" ]; then
MONIKER="${ROLLAPP_CHAIN_ID}-sequencer" # Default moniker value
MONIKER="${ROLLAPP_CHAIN_ID}-sequencer" # Default moniker value
fi

if [ "$KEY_NAME_ROLLAPP" = "" ]; then
KEY_NAME_ROLLAPP="rol-user" # Default key name value
KEY_NAME_ROLLAPP="rol-user" # Default key name value
fi

# Default to 1,000,000,000 tokens
if [ "$TOTAL_SUPPLY" = "" ]; then
TOTAL_SUPPLY="1000000000000000000000000000"
TOTAL_SUPPLY="1000000000000000000000000000"
fi

if [ "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH" = "" ]; then
Expand All @@ -43,6 +43,11 @@ if [ "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH" = "" ]; then
ROLLAPP_SETTLEMENT_INIT_DIR_PATH="${ROLLAPP_HOME_DIR}/init"
fi

if [ "$DA_CLIENT" = "" ]; then
echo "DA_CLIENT type is not set"
exit 1
fi

# FIXME: rename to DA_NETWORK
if [ "$CELESTIA_NETWORK" = "" ]; then
echo "CELESTIA_NETWORK is not set"
Expand Down Expand Up @@ -81,7 +86,7 @@ update_genesis_params() {
dasel put -f "$GENESIS_FILE" '.app_state.gov.voting_params.voting_period' -v "300s" || success=false
dasel put -f "$GENESIS_FILE" '.app_state.gov.tally_params.threshold' -v "0.490000000000000000" || success=false
dasel put -f "$GENESIS_FILE" '.app_state.sequencers.params.unbonding_time' -v "1814400s" || success=false # 2 weeks
dasel put -f "$GENESIS_FILE" '.app_state.staking.params.unbonding_time' -v "1814400s" || success=false # 2 weeks
dasel put -f "$GENESIS_FILE" '.app_state.staking.params.unbonding_time' -v "1814400s" || success=false # 2 weeks

if [ "$success" = false ]; then
echo "An error occurred. Please refer to README.md"
Expand Down Expand Up @@ -119,8 +124,8 @@ add_denom_metadata_to_genesis() {

#denom_metadata=$(cat "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH"/denommetadata.json)
#dasel put -f "$GENESIS_FILE" '.app_state.bank.denom_metadata' -v "$denom_metadata" || success=false
jq --argjson metadata "$(cat "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH"/denommetadata.json)" '.app_state.bank.denom_metadata = $metadata' "$GENESIS_FILE" > temp.json && mv temp.json "$GENESIS_FILE"
jq --argjson metadata "$(cat "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH"/denommetadata.json)" '.app_state.bank.denom_metadata = $metadata' "$GENESIS_FILE" >temp.json && mv temp.json "$GENESIS_FILE"

if [ "$success" = false ]; then
echo "An error occurred. Please refer to README.md"
return 1
Expand All @@ -133,20 +138,24 @@ set_consensus_params() {
BLOCK_SIZE="500000"
COMMIT=$(git log -1 --format='%H')

DA="mock"
case $CELESTIA_NETWORK in

case $DA_CLIENT in
"celestia")
case $CELESTIA_NETWORK in
"celestia" | "mocha")
DA="celestia"
DA="celestia"
;;
"mock" | *)
DA="mock"
;;
esac
;;
"mock")
DA="mock"
"weavevm")
DA="weavevm"
;;
"grpc")
"grpc")
DA="grpc"
;;

*)
*)
DA="mock"
;;
esac
Expand Down Expand Up @@ -183,8 +192,20 @@ set_EVM_params() {
fi
}

update_configuration() {
if [[ $CELESTIA_NETWORK != "mock" && $CELESTIA_NETWORK != "grpc" ]]; then
update_configuration_weavevm_da() {
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS-specific sed
sed -i '' "s|da_layer =.*|da_layer = \"weavevm\"|" "${CONFIG_DIRECTORY}/dymint.toml"
sed -i '' "s|da_config =.*|da_config = \"{\\\\\"endpoint\\\\\":\\\\\"https:\/\/testnet-rpc.wvm.dev\\\\\",\\\\\"chain_id\\\\\":9496,\\\\\"timeout\\\\\":60000000000,\\\\\"private_key_hex\\\\\":\\\\\"${WVM_PRIV_KEY}\\\\\"}\"|" "${CONFIG_DIRECTORY}/dymint.toml"
else
# Linux/Other OS-specific sed
sed -i "s|da_layer =.*|da_layer = \"weavevm\"|" "${CONFIG_DIRECTORY}/dymint.toml"
sed -i "s|da_config =.*|da_config = \"{\\\\\"endpoint\\\\\":\\\\\"https:\/\/testnet-rpc.wvm.dev\\\\\",\\\\\"chain_id\\\\\":9496,\\\\\"timeout\\\\\":60000000000,\\\\\"private_key_hex\\\\\":\\\\\"${WVM_PRIV_KEY}\\\\\"}\"|" "${CONFIG_DIRECTORY}/dymint.toml"
fi
}

update_configuration_celestia_da() {
if [[ $CELESTIA_NETWORK != "mock" && $CELESTIA_NETWORK != "grpc" ]]; then
celestia_namespace_id=$(openssl rand -hex 10)
if [ ! -d "$CELESTIA_HOME_DIR" ]; then
echo "Celestia light client is expected to be initialized in this directory: $CELESTIA_HOME_DIR"
Expand All @@ -205,6 +226,17 @@ update_configuration() {
sed -i "s/da_config .*/da_config = \"{\\\\\"base_url\\\\\": \\\\\"http:\/\/localhost:26658\\\\\", \\\\\"timeout\\\\\": 60000000000, \\\\\"gas_prices\\\\\":1.0, \\\\\"gas_adjustment\\\\\": 1.3, \\\\\"namespace_id\\\\\": \\\\\"${celestia_namespace_id}\\\\\", \\\\\"auth_token\\\\\":\\\\\"${celestia_token}\\\\\"}\"/" "${CONFIG_DIRECTORY}/dymint.toml"
fi
fi
}

update_configuration() {
case $DA_CLIENT in
"weavevm")
update_configuration_weavevm_da
;;
"celestia")
update_configuration_celestia_da
;;
esac

if [[ ! $SETTLEMENT_LAYER == "mock" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
Expand All @@ -225,7 +257,6 @@ update_configuration() {
sed -i '/rollapp_id =/c\rollapp_id = '\""$ROLLAPP_CHAIN_ID"\" "${CONFIG_DIRECTORY}/dymint.toml"
sed -i '/minimum-gas-prices =/c\minimum-gas-prices = '\"1000000000"$BASE_DENOM"\" "${CONFIG_DIRECTORY}/app.toml"
fi

}

# --------------------------------- run init --------------------------------- #
Expand Down Expand Up @@ -277,7 +308,7 @@ update_configuration
# Ask if to include a governor on genesis
echo "Do you want to include a governor on genesis? (Y/n) "
read -r answer
if [ ! "$answer" != "${answer#[Nn]}" ] ;then
if [ ! "$answer" != "${answer#[Nn]}" ]; then
STAKING_AMOUNT="500000000000000000000000$BASE_DENOM"
"$EXECUTABLE" gentx "$KEY_NAME_ROLLAPP" "$STAKING_AMOUNT" --chain-id "$ROLLAPP_CHAIN_ID" --keyring-backend test --home "$ROLLAPP_HOME_DIR" --fees 4000000000000"$BASE_DENOM"
"$EXECUTABLE" collect-gentxs --home "$ROLLAPP_HOME_DIR"
Expand Down

0 comments on commit b6b3747

Please sign in to comment.