diff --git a/build/Dockerfile b/build/Dockerfile index 8f5774b5d..0ec818399 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -16,6 +16,8 @@ ARG GO_BUILD_PATH=${GO_BASE_PATH}/cartesi-rollups-node ARG GO_BIN_PATH=${GO_BASE_PATH}/bin ARG RUNTIME_DIR=/var/opt/cartesi ARG MACHINE_SNAPSHOT_PATH=/var/opt/cartesi/machine-snapshots +ARG DEVNET_SHARE_PATH=/usr/share/devnet +ARG DEVNET_ANVIL_TIMEOUT=10 # # Machine snapshot generation @@ -54,6 +56,50 @@ RUN ln -s ${MACHINE_SNAPSHOT_PATH}/0_0 ${MACHINE_SNAPSHOT_PATH}/latest WORKDIR ${MACHINE_SNAPSHOT_PATH} CMD [ "/bin/bash" ] +# +# Create devnet for local tests +# +FROM ghcr.io/foundry-rs/foundry:latest as devnet + +RUN apk add --no-cache \ + bash \ + curl \ + jq + +ARG RUNTIME_DIR +WORKDIR ${RUNTIME_DIR} +COPY scripts scripts + +ARG DEVNET_SHARE_PATH +WORKDIR ${DEVNET_SHARE_PATH} + +# Copy machine snapshot hash +ARG MACHINE_SNAPSHOT_PATH +COPY --from=machine-snapshot ${MACHINE_SNAPSHOT_PATH}/0_0/hash 0_0_hash + +# Generate devnet +ARG DEVNET_ANVIL_TIMEOUT +ENV DEVNET_ANVIL_TIMEOUT=${DEVNET_ANVIL_TIMEOUT} +RUN ${RUNTIME_DIR}/scripts/devnet/gen-devnet.sh \ + -t 0_0_hash + +# Install utilities +RUN ln -s ${RUNTIME_DIR}/scripts/devnet/cmd/anvil_net_listening.sh \ + /usr/local/bin/anvil_net_listening.sh +RUN ln -s ${RUNTIME_DIR}/scripts/devnet/cmd/anvil_up.sh \ + /usr/local/bin/anvil_up.sh + +HEALTHCHECK --start-period=20s --interval=10s --timeout=1s --retries=5 \ + CMD anvil_net_listening.sh +#CMD ${RUNTIME_DIR}/scripts/devnet/cmd/anvil_net_listening.sh + +ENTRYPOINT ["anvil_up.sh"]} +#CMD ["/usr/share/devnet/anvil_state.hex"] + +#CMD ["anvil", "--block-time", "5"] +#CMD ${RUNTIME_DIR}/scripts/devnet/cmd/anvil_loadState.sh \ +# "${DEVNET_SHARE_PATH}/anvil_state.hex" + # # Cargo chef # @@ -90,7 +136,7 @@ RUN cargo chef cook --release --recipe-path recipe.json # Build application COPY ./offchain/ . # needed to log commit hash in runtime -COPY ./.git ../ +COPY ./.git ../ RUN cargo build --release # diff --git a/build/deps-compose.yml b/build/deps-compose.yml index e2d55c2b3..2d18341e2 100644 --- a/build/deps-compose.yml +++ b/build/deps-compose.yml @@ -3,58 +3,17 @@ version: "3.9" name: rollups-node services: devnet: - image: sunodo/devnet:1.1.1 - command: - [ - "anvil", - "--block-time", - "${BLOCK_TIME:-5}", - "--load-state", - "/usr/share/sunodo/anvil_state.json", - ] + image: cartesi/rollups-devnet:devel ports: - 8545:8545 - healthcheck: - test: ["CMD", "eth_isready"] - interval: 10s - timeout: 1s - retries: 5 environment: ANVIL_IP_ADDR: 0.0.0.0 - volumes: - - blockchain-data:/usr/share/sunodo machine_snapshot_setup: image: cartesi/rollups-machine-snapshot:devel volumes: - machine:/var/opt/cartesi/machine-snapshots - dapp_deployer: - image: cartesi/rollups-cli:1.0.2 - restart: on-failure - depends_on: - devnet: - condition: service_started - machine_snapshot_setup: - condition: service_completed_successfully - command: - [ - "create", - "--rpc", - "http://devnet:8545", - "--deploymentFile", - "/usr/share/sunodo/localhost.json", - "--mnemonic", - "test test test test test test test test test test test junk", - "--templateHashFile", - "/var/opt/cartesi/machine-snapshots/0_0/hash", - "--outputFile", - "/usr/share/sunodo/dapp.json", - ] - volumes: - - machine:/var/opt/cartesi/machine-snapshots:ro - - blockchain-data:/usr/share/sunodo - database: image: postgres:13-alpine ports: @@ -68,5 +27,4 @@ services: - POSTGRES_PASSWORD=password volumes: - blockchain-data: {} machine: {} diff --git a/build/docker-bake.hcl b/build/docker-bake.hcl index 306c1b9af..54faf2d23 100644 --- a/build/docker-bake.hcl +++ b/build/docker-bake.hcl @@ -6,7 +6,7 @@ target "docker-platforms" {} group "default" { targets = [ - "rollups-node", "machine-snapshot" + "rollups-node", "machine-snapshot", "devnet" ] } @@ -23,3 +23,10 @@ target "machine-snapshot" { target = "machine-snapshot" context = ".." } + +target "devnet" { + inherits = ["docker-platforms"] + dockerfile = "./build/Dockerfile" + target = "devnet" + context = ".." +} diff --git a/build/docker-bake.override.hcl b/build/docker-bake.override.hcl index 536f4dab0..70a87a894 100644 --- a/build/docker-bake.override.hcl +++ b/build/docker-bake.override.hcl @@ -16,3 +16,7 @@ target "rollups-node" { target "machine-snapshot" { tags = ["${DOCKER_ORGANIZATION}/rollups-machine-snapshot:${TAG}"] } + +target "devnet" { + tags = ["${DOCKER_ORGANIZATION}/rollups-devnet:${TAG}"] +} diff --git a/build/node-compose.yml b/build/node-compose.yml index 4a2cfd9f2..90008a3af 100644 --- a/build/node-compose.yml +++ b/build/node-compose.yml @@ -11,8 +11,6 @@ services: depends_on: devnet: condition: service_healthy - dapp_deployer: - condition: service_completed_successfully machine_snapshot_setup: condition: service_completed_successfully database: @@ -29,11 +27,11 @@ services: CARTESI_BLOCKCHAIN_IS_LEGACY: "false" CARTESI_BLOCKCHAIN_GENESIS_BLOCK: "1" CARTESI_BLOCKCHAIN_READ_DEPTH: "1" - CARTESI_CONTRACTS_DAPP_ADDRESS: "0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C" + CARTESI_CONTRACTS_DAPP_ADDRESS: "0x4e5BE025E498EF85FfAD28124Ffc74fE8ad10c4c" CARTESI_CONTRACTS_DAPP_DEPLOYMENT_BLOCK_NUMBER: "1" - CARTESI_CONTRACTS_HISTORY_ADDRESS: "0x4FF8BD9122b7D91d56Dd5c88FE6891Fb3c0b5281" - CARTESI_CONTRACTS_AUTHORITY_ADDRESS: "0x5050F233F2312B1636eb7CF6c7876D9cC6ac4785" - CARTESI_CONTRACTS_INPUT_BOX_ADDRESS: "0x59b22D57D4f067708AB0c00552767405926dc768" + CARTESI_CONTRACTS_HISTORY_ADDRESS: "0x35861Aa3cf766C8E9b83924e1Ad6053b4039d6d6" + CARTESI_CONTRACTS_AUTHORITY_ADDRESS: "0xc2A807938914398ccD5F8Df2d36fD64C9F78B3C0" + CARTESI_CONTRACTS_INPUT_BOX_ADDRESS: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" CARTESI_SNAPSHOT_DIR: "/var/opt/cartesi/machine-snapshots" CARTESI_AUTH_MNEMONIC: "test test test test test test test test test test test junk" CARTESI_POSTGRES_ENDPOINT: "postgres://postgres:password@database:5432/postgres" diff --git a/scripts/devnet/cmd/anvil_up.sh b/scripts/devnet/cmd/anvil_up.sh index 9512b5a43..2fdca56ac 100755 --- a/scripts/devnet/cmd/anvil_up.sh +++ b/scripts/devnet/cmd/anvil_up.sh @@ -3,11 +3,14 @@ # SPDX-License-Identifier: Apache-2.0 (see LICENSE) ANVIL_IP_ADDR=${ANVIL_IP_ADDR:-"0.0.0.0"} -hex_state_file="$1" +#hex_state_file="$1" +hex_state_file="/usr/share/devnet/anvil_state.hex" -anvil \ +nohup anvil \ --block-time 5 & +timeout=5 +sleep "$timeout" hex_state_str="\"$(cat $hex_state_file)\"" curl -X \ POST \ @@ -15,3 +18,9 @@ curl -X \ -H 'Content-Type: application/json' \ -d "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"method\":\"anvil_loadState\",\"params\":[${hex_state_str}]}" \ "http://$ANVIL_IP_ADDR:8545" + +while true +do + # loop infinitely + sleep 5 +done diff --git a/scripts/devnet/gen-devnet.sh b/scripts/devnet/gen-devnet.sh index 35f22ebcc..489ce77bd 100755 --- a/scripts/devnet/gen-devnet.sh +++ b/scripts/devnet/gen-devnet.sh @@ -20,7 +20,7 @@ DEVNET_FOUNDRY_ACCOUNT_0_ADDRESS="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" DEVNET_FOUNDRY_ACCOUNT_0_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" # keccak256("salt") DEVNET_DEFAULT_SALT="0xa05e334153147e75f3f416139b5109d1179cb56fef6a4ecb4c4cbc92a7c37b70" -DEVNET_ANVIL_TIMEOUT=5 +DEVNET_ANVIL_TIMEOUT=${DEVNET_ANVIL_TIMEOUT:-5} readonly ROLLUPS_CONTRACTS_VERSION \ DEVNET_RPC_URL \ DEVNET_FOUNDRY_ACCOUNT_0_ADDRESS \ @@ -339,8 +339,7 @@ verbose "created $work_dir" anvil_pid="" anvil_up \ - anvil_pid\ - "$devnet_anvil_state_file" + anvil_pid check_error $? "failed to start anvil" log "started anvil (pid=$anvil_pid)" @@ -365,6 +364,8 @@ create_dapp \ "$dapp_factory_address" log "created CartesiDApp" +anvil_dump_state \ + "$devnet_anvil_state_file" generate_deployment_file \ "$devnet_deployment_file" diff --git a/scripts/devnet/lib/anvil.sh b/scripts/devnet/lib/anvil.sh old mode 100755 new mode 100644 index 260ddfb14..fa78a93cd --- a/scripts/devnet/lib/anvil.sh +++ b/scripts/devnet/lib/anvil.sh @@ -8,7 +8,8 @@ lib_dir="$( cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" _is_anvil_up() { local -n ready=$1 - local result=$(. $lib_dir/../cmd/anvil_net_listening.sh) + local result + result=$("$lib_dir"/../cmd/anvil_net_listening.sh) ready="false" if [[ -n "$result" ]]; then @@ -18,8 +19,6 @@ _is_anvil_up() { anvil_up() { local -n ret="$1" - shift - local anvil_state_file="$1" # check if there's another instance of anvil up listening on the same port _is_anvil_up is_up @@ -29,13 +28,12 @@ anvil_up() { fi anvil \ - --host $ANVIL_IP_ADDR \ - --dump-state "$anvil_state_file" \ + --host "$ANVIL_IP_ADDR" \ > /dev/null & local pid=$! # check if anvil is up - sleep $DEVNET_ANVIL_TIMEOUT + sleep "$DEVNET_ANVIL_TIMEOUT" _is_anvil_up is_up if [[ "$is_up" != "true" ]]; then err "anvil has not started" @@ -48,9 +46,7 @@ anvil_up() { anvil_down() { local anvil_pid="$1" - verbose "waiting $DEVNET_ANVIL_TIMEOUT seconds before killing anvil..." - sleep $DEVNET_ANVIL_TIMEOUT kill "$anvil_pid" - check_error $? "failed to kill anvil" + check_error "$?" "failed to kill anvil" verbose "killed anvil (pid=$anvil_pid)" }