Skip to content

Commit

Permalink
chore: remove Python executor
Browse files Browse the repository at this point in the history
It's unused now. :)

References are removed from:

- README and docs
- GitHub Actions workflows (CI & Docker)
- Dockerfile
  • Loading branch information
kkovaacs committed Aug 29, 2023
1 parent a2af66d commit 30736fd
Show file tree
Hide file tree
Showing 29 changed files with 6 additions and 7,068 deletions.
95 changes: 0 additions & 95 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
needs: python-starkhash
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
Expand All @@ -27,37 +26,13 @@ jobs:
remove-haskell: 'true'
remove-codeql: 'true'
remove-docker-images: 'true'
# Required for the python environment
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install protoc
run: |
sudo apt-get install -y protobuf-compiler
- uses: taiki-e/install-action@nextest
- uses: actions/setup-python@v4
id: setup_python
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: 'py/requirements*.txt'
# Workaround for setup-python issue #330 (https://github.com/actions/setup-python/issues/330)
- uses: actions/cache@v3
id: python_cache
with:
path: ${{ env.pythonLocation }}/**/site-packages
key: site-packages-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('py/requirements*.txt') }}-${{ hashFiles('py/pyproject.toml') }}
- run: |
pip install -r py/requirements-dev.txt
pip install -e py/.
# Install fresh starknet_pathfinder_crypto
- uses: actions/download-artifact@v3
with:
name: pathfinder-starkhash-wheels
- name: Install Pedersen hash Python wrapper
run: |
pip install --no-index --force-reinstall ./starknet_pathfinder_crypto-*.whl
- name: Compile unit tests
run: timeout 25m cargo nextest run --all-targets --all-features --workspace --locked --no-run

Expand Down Expand Up @@ -133,76 +108,6 @@ jobs:
- name: check
run: cargo check

python:
runs-on: ubuntu-latest
needs: python-starkhash
steps:
- name: Checkout sources
uses: actions/checkout@v3
- uses: actions/setup-python@v4
id: setup_python
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: 'py/requirements*.txt'
# Workaround for setup-python issue #330 (https://github.com/actions/setup-python/issues/330)
- uses: actions/cache@v3
id: python_cache
with:
path: ${{ env.pythonLocation }}/**/site-packages
key: site-packages-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('py/requirements*.txt') }}-${{ hashFiles('py/pyproject.toml') }}
- name: Install Python dependencies
run: |
pip install -r py/requirements-dev.txt
pip install -e py/.[dev]
- uses: actions/download-artifact@v3
with:
name: pathfinder-starkhash-wheels
- name: Install Pedersen hash Python wrapper
run: |
pip install --no-index --force-reinstall ./starknet_pathfinder_crypto-*.whl
- name: Test (python)
run: |
cd py
python -m pytest
- name: Formatting (python)
run: |
cd py
python -m black --check .
- name: Lints (python)
run: |
cd py
python -m flake8 src/ tests/ tools/
python-starkhash:
name: Compile Python Pedersen hash wrapper
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
workspaces: "crates/stark_hash_python"
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: 'py/requirements*.txt'
- uses: messense/maturin-action@v1
with:
command: build
container: off
working-directory: crates/stark_hash_python
args: --release -o dist
- uses: actions/upload-artifact@v3
with:
name: pathfinder-starkhash-wheels
path: crates/stark_hash_python/dist/starknet_pathfinder_crypto*.whl
if-no-files-found: error

fuzz_targets:
runs-on: ubuntu-latest
steps:
Expand Down
64 changes: 2 additions & 62 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,78 +37,18 @@ RUN TARGETARCH=${TARGETARCH} \
./cargo-build.sh --locked --release -p pathfinder --bin pathfinder \
&& cp target/*-unknown-linux-gnu/release/pathfinder pathfinder-${TARGETARCH}


#############################################
# Stage 1.5: Build the Python Pedersen hash #
#############################################
FROM --platform=$BUILDPLATFORM cargo-chef AS rust-python-starkhash-planner
COPY Cargo.toml Cargo.toml
COPY crates/stark_curve crates/stark_curve
COPY crates/stark_hash crates/stark_hash
COPY crates/stark_poseidon crates/stark_poseidon
COPY crates/stark_hash_python crates/stark_hash_python
RUN cd crates/stark_hash_python && \
cargo chef prepare --recipe-path recipe.json


FROM --platform=$BUILDPLATFORM cargo-chef AS rust-python-starkhash-builder
ARG TARGETARCH
COPY ./build/prepare-stark_hash_python.sh prepare-stark_hash_python.sh
RUN TARGETARCH=${TARGETARCH} ./prepare-stark_hash_python.sh
COPY --from=rust-python-starkhash-planner /usr/src/pathfinder/crates/stark_hash_python/recipe.json /usr/src/pathfinder/crates/stark_hash_python/recipe.json
COPY Cargo.toml Cargo.toml
COPY crates/stark_curve crates/stark_curve
COPY crates/stark_hash crates/stark_hash
COPY crates/stark_poseidon crates/stark_poseidon
COPY ./build/cargo-chef-cook.sh ./crates/stark_hash_python/cargo-chef-cook.sh
RUN cd crates/stark_hash_python && TARGETARCH=${TARGETARCH} ./cargo-chef-cook.sh --release --recipe-path recipe.json

COPY crates/stark_hash_python crates/stark_hash_python
COPY ./build/cargo-build.sh ./crates/stark_hash_python/cargo-build.sh
RUN cd crates/stark_hash_python \
&& TARGETARCH=${TARGETARCH} ./cargo-build.sh --locked --release \
&& cp target/*-unknown-linux-gnu/release/libstarknet_pathfinder_crypto.so starknet_pathfinder_crypto.so-${TARGETARCH}

#######################################
# Stage 2: Build the Python libraries #
#######################################
FROM python:3.9-slim-bullseye AS python-builder
ARG TARGETARCH

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libgmp-dev gcc && rm -rf /var/lib/apt/lists/*

WORKDIR /usr/share/pathfinder
COPY py py
RUN --mount=type=cache,target=/root/.cache/pip python3 -m pip --disable-pip-version-check install py/.
COPY --from=rust-python-starkhash-builder /usr/src/pathfinder/crates/stark_hash_python/starknet_pathfinder_crypto.so-${TARGETARCH} /usr/local/lib/python3.9/site-packages/starknet_pathfinder_crypto.so

# This reduces the size of the python libs by about 50%
ENV PY_PATH=/usr/local/lib/python3.9/
RUN find ${PY_PATH} -type d -a -name test -exec rm -rf '{}' + \
&& find ${PY_PATH} -type d -a -name tests -exec rm -rf '{}' + \
&& find ${PY_PATH} -type f -a -name '*.pyc' -exec rm -rf '{}' + \
&& find ${PY_PATH} -type f -a -name '*.pyo' -exec rm -rf '{}' +

###############################
# Stage 3: Cairo 1.0 compiler #
###############################
FROM starknet/cairo:2.1.0-rc1 AS cairo-compiler

#######################
# Final Stage: Runner #
#######################
# Note that we're explicitly using the Debian bullseye image to make sure we're
# compatible with the Rust builder we've built the pathfinder executable in.
FROM python:3.9-slim-bullseye AS runner
FROM debian:bullseye-slim AS runner
ARG TARGETARCH

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libgmp10 tini && rm -rf /var/lib/apt/lists/*
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates libgmp10 tini && rm -rf /var/lib/apt/lists/*
RUN groupadd --gid 1000 pathfinder && useradd --no-log-init --uid 1000 --gid pathfinder --no-create-home pathfinder

COPY --from=rust-builder /usr/src/pathfinder/pathfinder-${TARGETARCH} /usr/local/bin/pathfinder
COPY --from=python-builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
COPY --from=cairo-compiler /usr/bin/starknet-compile /usr/bin/starknet-sierra-compile /usr/local/lib/python3.9/site-packages/starkware/starknet/compiler/v1/bin/
COPY --from=python-builder /usr/local/bin/pathfinder_python_worker /usr/local/bin

# Create directory and volume for persistent data
RUN install --owner 1000 --group 1000 --mode 0755 -d /usr/share/pathfinder/data
Expand Down
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For help or to submit bug reports or feature requests, please open an issue or a

The `pathfinder` node can be run in the provided Docker image.
Using the Docker image is the easiest way to start `pathfinder`. If for any reason you're interested in how to set up all the
dependencies and the Python environment yourself please check the [Installation from source](doc/install-from-source.md) guide.
dependencies yourself please check the [Installation from source](doc/install-from-source.md) guide.

The following assumes you have [Docker installed](https://docs.docker.com/get-docker/) and ready to go.
(In case of Ubuntu installing docker is as easy as running `sudo snap install docker`.)
Expand Down Expand Up @@ -236,12 +236,6 @@ You may also use the label key `version` to specify a particular version of the
rpc_method_calls_total{method="starknet_getEvents", version="v0.3"}
```

#### Python subprocess related counters

- `extpy_processes_launched_total` incremented each time python subprocess is launched
- `extpy_processes_exited_total` with labels, incremented each time python subprocess exits normally
- `extpy_processes_failed_total` incremented each time python subprocess exits abnormally

#### Feeder Gateway and Gateway related counters

- `gateway_requests_total`
Expand Down Expand Up @@ -323,16 +317,9 @@ Questions are welcome! If you have any questions regarding Pathfinder, feel free

* [Error compiling Pathfinder (rust)](https://www.newton.so/view/63a066c2407c7621270c0208)

* [Python issues with Pathfinder](https://www.newton.so/view/63a06669620f9c99ad981fd1)


## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.

If you would like to contribute to the `py/` parts, which interface with
[`cairo-lang`](https://github.com/starkware-libs/cairo-lang), please include a
mention that you agree to relicense the python parts as necessary to abide with
future `cairo-lang` license. See `contributing.md` for more information.
21 changes: 0 additions & 21 deletions build/prepare-stark_hash_python.sh

This file was deleted.

3 changes: 0 additions & 3 deletions crates/gateway-types/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,6 @@ pub mod add_transaction {
pub nonce: TransactionNonce,

// Required for declare v2 transactions
//
// `pathfinder_rpc::cairo::ext_py::ser::ChildCommand` uses `#[serde(flatten)]`
// which is incompatible with `#[skip_serializing_none]`
#[serde(default, skip_serializing_if = "Option::is_none")]
pub compiled_class_hash: Option<CasmHash>,
}
Expand Down
23 changes: 3 additions & 20 deletions crates/pathfinder/src/bin/pathfinder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pathfinder_common::{consts::VERGEN_GIT_DESCRIBE, BlockNumber, Chain, ChainId
use pathfinder_ethereum::{EthereumApi, EthereumClient};
use pathfinder_lib::state::SyncContext;
use pathfinder_lib::{monitoring, state};
use pathfinder_rpc::{cairo, metrics::logger::RpcMetricsLogger, SyncState};
use pathfinder_rpc::{metrics::logger::RpcMetricsLogger, SyncState};
use pathfinder_storage::Storage;
use primitive_types::H160;
use starknet_gateway_client::GatewayApi;
Expand Down Expand Up @@ -120,24 +120,13 @@ Hint: This is usually caused by exceeding the file descriptor limit of your syse
let sync_state = Arc::new(SyncState::default());
let pending_state = PendingData::default();

let (call_handle, cairo_handle) = cairo::ext_py::start(
rpc_storage.path().into(),
config.python_subprocesses,
futures::future::pending(),
pathfinder_context.network,
)
.await
.context(
"Creating python process for call handling. Have you setup our Python dependencies?",
)?;

let context = pathfinder_rpc::context::RpcContext::new(
rpc_storage,
sync_state.clone(),
pathfinder_context.network_id,
pathfinder_context.gateway.clone(),
)
.with_call_handling(call_handle);
);

let context = match config.poll_pending {
true => context.with_pending_data(pending_state.clone()),
false => context,
Expand Down Expand Up @@ -211,12 +200,6 @@ Hint: This is usually caused by exceeding the file descriptor limit of your syse
Err(err) => tracing::error!("Sync process ended unexpected; failed to join task handle: {:?}", err),
}
}
result = cairo_handle => {
match result {
Ok(task_result) => tracing::error!("Cairo process ended unexpected with: {:?}", task_result),
Err(err) => tracing::error!("Cairo process ended unexpected; failed to join task handle: {:?}", err),
}
}
_result = rpc_handle.stopped() => {
// This handle returns () so its not very useful.
tracing::error!("RPC server process ended unexpected");
Expand Down
1 change: 0 additions & 1 deletion crates/rpc/src/cairo.rs

This file was deleted.

Loading

0 comments on commit 30736fd

Please sign in to comment.