From a6a4d9e2c315014a13171f1446597822e9026ae5 Mon Sep 17 00:00:00 2001 From: Levi Schoen Date: Fri, 17 Nov 2023 15:31:30 -0800 Subject: [PATCH 1/2] add docs and dockerfile for portable blockscout rapid development --- DEVELOPMENT.md | 52 +++++++++++++++++++++++++++++++++ Makefile | 4 +++ blockscout/local.Dockerfile | 57 +++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 blockscout/local.Dockerfile diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index e7462df..9937842 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -152,6 +152,58 @@ cd ../../ make refresh ``` +#### Portable Docker Dev Environment + +Requires + - vscode + - docker + +Build an image that has all elixir and node dependnecies to run the app, and all current source code and compiled assets + +```bash +make local +``` + +run a docker container using the above image + +```bash +docker run -it -d -v ./blockscout/blockscout-base:/src/blockscout -v ./blockscout/patches:/src/patches kava-blockscout:local + +# apply current patches +cd /blockscout/blockscout-base && git apply ../patches/*.patch && git add ./ && git commit -m "REVERT-ME-PATCH-COMMIT" +# REVERT this commit before pushing to origin for a PR) +``` + +Attach a [vs code editor dev container](https://code.visualstudio.com/docs/devcontainers/containers) to the running container (open command member, type/select Dev Containers: Attach to running container) + +Now any code changes you make inside the container will be persisted on your local machine, and you can use the patch workflow below to upstream your code changes. + +Create a patch of your changes to be applied when the development or production docker image is built + +```bash +# from your host machine +cd /blockcout/blockscout-base +git diff > ../patches/NAME_OF_PATCH.patch +``` + +Some helpful commands + +```bash +# from inside /src/blockscout of dev container +# fetch dependencies from all apps +mix deps.get +# compile sources for all apps (indexer, explorer) +mix compile + +# if you want to just update / compile a single app, such as the indexer +# from inside /src/blockscout of dev container +cd /apps/indexer +# fetch dependencies for just this app +mix deps.get +# compile sources for just this app +mix compile +``` + #### Indexer status To see how far back the block explorer has indexed blocks, connect to the database and query to see what is the earliest block it has indexed, if these values change that means earlier and earlier blocks are being indexed (`refetch_needed` indicates whether the indexing was successful) diff --git a/Makefile b/Makefile index eeefd1c..f388b41 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,10 @@ build: cd blockscout && \ docker build ./ -f Dockerfile -t ${IMAGE_NAME}:${LOCAL_IMAGE_TAG} --build-arg BLOCKSCOUT_VERSION=${BLOCKSCOUT_DOCKER_VERSION} +local: + cd blockscout && \ + docker build ./ -f local.Dockerfile -t ${IMAGE_NAME}:${LOCAL_IMAGE_TAG} --build-arg BLOCKSCOUT_VERSION=${BLOCKSCOUT_DOCKER_VERSION} + .PHONY: build-db-exporter # build the exporter image build-db-exporter: diff --git a/blockscout/local.Dockerfile b/blockscout/local.Dockerfile new file mode 100644 index 0000000..250d146 --- /dev/null +++ b/blockscout/local.Dockerfile @@ -0,0 +1,57 @@ +# Raw version representing v5.3.1-beta +ARG BLOCKSCOUT_VERSION=5.3.1 + +# +# The backend-builder uses the official exlixir docker image that contains +# Elixir, Erlang, compatiable OTP version, and mix. +# +FROM elixir:1.14-otp-25 as backend-builder +ARG BLOCKSCOUT_VERSION + +WORKDIR /src + +# All elixir dependencies are already installed +# We only need git to clone and apply patches +RUN apt-get update \ + && apt-get install -y git \ + && rm -rf /var/lib/apt/lists/* + +# COPY patches first, since we want to apply after clone, but before compiling +# This does force a re-clone if there are patch changes, but also reduces our layers. +# +COPY ./patches /src/patches + +# The order of the below steps must be kept the same +# +# Clone the blockscout repository +RUN git clone --depth 1 --branch v${BLOCKSCOUT_VERSION}-beta https://github.com/blockscout/blockscout.git +WORKDIR blockscout +# apply patches +RUN git apply /src/patches/*.patch +RUN mix local.hex --force +RUN mix local.rebar --force +# install prod dependencies +RUN mix deps.get +# compile minimal production optimized version of application +RUN mix compile +# The order of the above steps must be kept the same +# + +WORKDIR /src + +RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ + apt-get install -y nodejs \ + build-essential && \ + node --version && \ + npm --version +# Build the user interface (block_scout_web/assets) and then install the solc npm package (explorer) +RUN cd blockscout/apps/block_scout_web/assets \ + && npm install \ + && NODE_ENV=prod npm run deploy \ + && cd ../../explorer \ + && npm install + +WORKDIR /src/blockscout + +# +CMD tail -f /dev/null From 800a045cd1a0659aa80bbf69df2c770dcedba32b Mon Sep 17 00:00:00 2001 From: Levi Schoen Date: Fri, 1 Dec 2023 14:44:15 -0800 Subject: [PATCH 2/2] account for cases where eth api says tx that exhausted block gas meter succeeded --- .env | 1 + DEVELOPMENT.md | 13 +++++++- Makefile | 2 ++ ...ernal-tx-call-validation-constraints.patch | 31 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 blockscout/patches/0004-loosen-internal-tx-call-validation-constraints.patch diff --git a/.env b/.env index 56e4038..984c158 100644 --- a/.env +++ b/.env @@ -60,6 +60,7 @@ BLOCKSCOUT_VERSION=v5.1.5-kava INDEXER_CATCHUP_BLOCKS_BATCH_SIZE=1 INDEXER_CATCHUP_BLOCKS_CONCURRENCY=1 INDEXER_INTERNAL_TRANSACTIONS_CONCURRENCY=1 +INDEXER_INTERNAL_TRANSACTIONS_BATCH_SIZE=1 INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER=false INDEXER_BLOCK_REWARD_CONCURRENCY=1 INDEXER_RECEIPTS_CONCURRENCY=1 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 9937842..af00095 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -202,8 +202,19 @@ cd /apps/indexer mix deps.get # compile sources for just this app mix compile + +# run the entire blockscout system +mix run + +# run just a specific app +mix run indexer ``` + +Note that you should only run the above commands in the docker container, running them on your host may lead to conflicts in library binaries being different when installed on the host machine and the docker linux environment (if such an issue does occur, blowing away the `/_build` and `deps` in `blockscout-base/` should resolve such conflicts) + +Since all dependencies and compiled artifacts are saved to the host, restarting the dev container and re-attaching vs code to it will not require re-fetching deps (unless the dependency list has changed) or re-compiling (unless the source code has changed from the last time it was compiled) + #### Indexer status To see how far back the block explorer has indexed blocks, connect to the database and query to see what is the earliest block it has indexed, if these values change that means earlier and earlier blocks are being indexed (`refetch_needed` indicates whether the indexing was successful) @@ -288,7 +299,7 @@ count 1808591 ``` -Query for blockscout database state for a given transaction (removing the `0x` prefix from the transaciton of interest) +Query for blockscout database state for a given transaction (removing the `0x` prefix from the transaction of interest) ```sql select * from transactions where hash = decode('080a9c8c6bde6320dac69dd8639172aca893d357904f7a1ad37debf17bfec79f','hex'); diff --git a/Makefile b/Makefile index f388b41..3d7eea4 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ local: cd blockscout && \ docker build ./ -f local.Dockerfile -t ${IMAGE_NAME}:${LOCAL_IMAGE_TAG} --build-arg BLOCKSCOUT_VERSION=${BLOCKSCOUT_DOCKER_VERSION} + .PHONY: build-db-exporter # build the exporter image build-db-exporter: @@ -82,6 +83,7 @@ restart-postgres: .PHONY: reset # wipe state and restart the service and all it's dependencies reset: + rm -rf postgres-data && \ docker compose up -d --build --remove-orphans --renew-anon-volumes --force-recreate # wipe just the database state and restart just the database diff --git a/blockscout/patches/0004-loosen-internal-tx-call-validation-constraints.patch b/blockscout/patches/0004-loosen-internal-tx-call-validation-constraints.patch new file mode 100644 index 0000000..dce64b5 --- /dev/null +++ b/blockscout/patches/0004-loosen-internal-tx-call-validation-constraints.patch @@ -0,0 +1,31 @@ +diff --git a/apps/explorer/lib/explorer/chain/internal_transaction.ex b/apps/explorer/lib/explorer/chain/internal_transaction.ex +index c86bfa699f..1b2d0cbac6 100644 +--- a/apps/explorer/lib/explorer/chain/internal_transaction.ex ++++ b/apps/explorer/lib/explorer/chain/internal_transaction.ex +@@ -3,6 +3,8 @@ defmodule Explorer.Chain.InternalTransaction do + + use Explorer.Schema + ++ require Logger ++ + alias Explorer.Chain.{Address, Block, Data, Gas, Hash, PendingBlockOperation, Transaction, Wei} + alias Explorer.Chain.InternalTransaction.{Action, CallType, Result, Type} + +@@ -502,7 +504,16 @@ defmodule Explorer.Chain.InternalTransaction do + # Validates that :call `type` changeset either has an `error` or both `gas_used` and `output` + defp validate_call_error_or_result(changeset) do + case get_field(changeset, :error) do +- nil -> validate_required(changeset, [:gas_used, :output], message: "can't be blank for successful call") ++ nil -> ++ if get_field(changeset, :gas_used) == nil && get_field(changeset, :output) == nil do ++ changeset |> ++ IO.inspect() |> ++ Ecto.Changeset.change( ++ error: "execution reverted" ++ ) ++ else ++ validate_required(changeset, [:gas_used, :output], message: "can't be blank for successful call") ++ end + _ -> validate_disallowed(changeset, [:output], message: "can't be present for failed call") + end + end