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

feat: add rpc docker image for hive testing #454

Merged
merged 24 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
da3b1be
dev: update madara genesis
ftupas Aug 18, 2023
7791da2
feat: add genesis dump
ftupas Aug 18, 2023
b3d4536
feat: add Dockerfile with Madara + RPC for hive
ftupas Aug 18, 2023
4c8b360
ci: add build-hive job
ftupas Aug 18, 2023
ba1fa38
chore: update CHANGELOG.md
ftupas Aug 21, 2023
8872528
dev: move to Dockerfile to hive-utils
ftupas Aug 18, 2023
6157c5f
chore: add comment on Dockerfile
ftupas Aug 18, 2023
3a188f0
ci: add make_with_env to dump genesis
ftupas Aug 18, 2023
c321791
ci: add Python setup and use built Kakarot contracts
ftupas Aug 18, 2023
c6d61f8
chore: reorder change log
ftupas Aug 21, 2023
a3ac497
dev: add foundry to setup
ftupas Aug 18, 2023
7953993
chore: remove duplicate setup
ftupas Aug 18, 2023
c295c45
dev: use hive test port
ftupas Aug 18, 2023
b128384
feat: add deployer
ftupas Aug 21, 2023
bff9da9
chore: reorder change log
ftupas Aug 21, 2023
f2fc8a7
dev: rename env
ftupas Aug 21, 2023
da60f3d
Merge branch 'main' of github.com:kkrt-labs/kakarot-rpc into feat/rpc…
ftupas Aug 21, 2023
df40abe
chore: update madara genesis
ftupas Aug 21, 2023
70042d4
dev: add sleep for Madara
ftupas Aug 22, 2023
95f2d5e
Merge branch 'main' of github.com:kkrt-labs/kakarot-rpc into feat/rpc…
ftupas Aug 22, 2023
27e0385
dev: add loop to check Madara
ftupas Aug 22, 2023
8d8623e
Merge branch 'main' of github.com:kkrt-labs/kakarot-rpc into feat/rpc…
ftupas Aug 22, 2023
daf8b90
Merge branch 'main' of github.com:kkrt-labs/kakarot-rpc into feat/rpc…
ftupas Aug 22, 2023
7042e54
Merge branch 'main' of github.com:kkrt-labs/kakarot-rpc into feat/rpc…
ftupas Aug 23, 2023
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
64 changes: 64 additions & 0 deletions .github/workflows/kakarot_rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,67 @@ jobs:
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:latest

build-hive:
Eikix marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
Eikix marked this conversation as resolved.
Show resolved Hide resolved
# Latest Kakarot RPC image is required to build Hive RPC image
needs:
- merge
steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Retrieve cached dependencies
uses: Swatinem/rust-cache@v2
# foundry
- name: install foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
# Python setup
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-${{ runner.os }}
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- run: cd lib/kakarot && poetry config installer.modern-installation false
- name: Dump Genesis
run: ./scripts/make_with_env.sh dump-genesis
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
Eikix marked this conversation as resolved.
Show resolved Hide resolved
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ env.REGISTRY_IMAGE }}-hive:latest
context: .
file: crates/hive-utils/Dockerfile
platforms: linux/amd64,linux/arm64
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@
.env
vscode
broadcast

# ignore genesis.json
.hive
Eikix marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ and this project adheres to

### Added

- feat: add automatic deployment of eoa from RPC if an account doesn't exist on chain
- feat: add rpc docker image for hive testing
- feat: add automatic deployment of eoa from RPC if an account doesn't exist on
chain
- ci: decrease the rate which we send transactions in benchmark CI
- fix: update the hive genesis utils for missing Kakarot requirements.
- ci: use madara binary for benchmark CI
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ madara-rpc-down:
dump-katana:
cargo run --bin dump-katana

dump-genesis: build-kakarot
cargo run --bin dump-genesis

test: dump-katana
cargo test --all

Expand Down
4 changes: 4 additions & 0 deletions crates/hive-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ lazy_static = { workspace = true }
cargo-husky = { workspace = true }
katana-core = { workspace = true }
rstest = { workspace = true }

[[bin]]
name = "dump-genesis"
path = "src/hive/bin/dump-genesis.rs"
67 changes: 67 additions & 0 deletions crates/hive-utils/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# TODO: Use official madara image when https://github.com/keep-starknet-strange/madara/issues/982 is closed
# FROM ghcr.io/keep-starknet-strange/madara:v0.1.0.experimental.3 as madara
FROM fredtupas/madara as madara

FROM ghcr.io/kkrt-labs/kakarot-rpc/node:latest

# Install svn to download Madara genesis config files
RUN apt-get -y update; \
apt-get install -y --no-install-recommends subversion; \
apt-get autoremove -y; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*

# Copy Madara binary
COPY --from=madara /madara-bin /madara-bin

# Madara Path
ENV MADARA_PATH=/root/.madara
ENV MADARA_CONFIG_PATH=${MADARA_PATH}/configs
ENV KAKAROT_CONTRACTS_PATH=${MADARA_PATH}/cairo-contracts/kakarot

# Download Madara genesis config to source path
RUN svn export https://github.com/keep-starknet-strange/madara/trunk/configs ${MADARA_CONFIG_PATH}

# Copy combined genesis.json to source path
COPY .hive/genesis.json ${MADARA_CONFIG_PATH}/genesis-assets/genesis.json

# Copy compiled Kakarot contracts to destination path of compiled contracts
COPY ./lib/kakarot/build ${KAKAROT_CONTRACTS_PATH}

# RPC environment variables
# Test running on this port https://github.com/ethereum/hive/blob/master/simulators/ethereum/rpc/helper.go#L50
ENV KAKAROT_HTTP_RPC_ADDRESS="0.0.0.0:8545"
ENV STARKNET_NETWORK=http://0.0.0.0:9944
ENV RUST_LOG=trace
# https://github.com/kkrt-labs/kakarot-rpc/blob/main/crates/hive-utils/src/hive/genesis.rs#L59
ENV KAKAROT_ADDRESS="0x9001"
ftupas marked this conversation as resolved.
Show resolved Hide resolved
ENV DEPLOYER_ACCOUNT_ADDRESS="0x9003"
# https://github.com/kkrt-labs/kakarot-rpc/blob/main/crates/core/src/test_utils/constants.rs#L14
ENV DEPLOYER_ACCOUNT_PRIVATE_KEY="0x0288a51c164874bb6a1ca7bd1cb71823c234a86d0f7b150d70fa8f06de645396"

# Add a health check to make sure the service is healthy
HEALTHCHECK --interval=3s --timeout=5s --start-period=1s --retries=5 \
CMD curl --request POST \
--header "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "method": "eth_chainId", "id": 1}' http://${KAKAROT_HTTP_RPC_ADDRESS} || exit 1

# 9444 JSON-RPC server
# 9615 Prometheus exporter
# 30333 P2P communication
EXPOSE 9944 9615 30333

# Expose the port that the RPC server will run on
EXPOSE 8545

# Misc
RUN curl https://get.starkli.sh | sh
Eikix marked this conversation as resolved.
Show resolved Hide resolved
ENV PATH="${PATH}:/root/.starkli/bin"
RUN starkliup

# Copy start script
COPY crates/hive-utils/scripts/start.sh /start.sh
RUN chmod +x /start.sh

ENTRYPOINT ["/usr/bin/tini", "--", "/start.sh"]

CMD []
31 changes: 31 additions & 0 deletions crates/hive-utils/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

# Compute the proxy account class hash
export PROXY_ACCOUNT_CLASS_HASH=$(starkli class-hash ${MADARA_PATH}/cairo-contracts/kakarot/proxy.json)
Eikix marked this conversation as resolved.
Show resolved Hide resolved

# Start madara-bin in the background
/madara-bin \
--rpc-external \
--rpc-methods=unsafe \
--rpc-cors=all \
--tmp \
--dev &
Eikix marked this conversation as resolved.
Show resolved Hide resolved

# Loop until the curl command succeeds
until
curl --silent --request POST \
--header "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "starknet_getClassHashAt",
"params": [{"block_number": 0}, "0x9001"],
"id": 1
}' \
"${STARKNET_NETWORK}" # Use the provided network address
do
echo "Waiting for Madara to start..."
sleep 5
done

# Once Madara is ready, start RPC
/usr/local/bin/kakarot-rpc
21 changes: 21 additions & 0 deletions crates/hive-utils/src/hive/bin/dump-genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::path::Path;

use hive_utils::hive::genesis::{serialize_hive_to_madara_genesis_config, GenesisLoader, HiveGenesisConfig};

#[tokio::main]
async fn main() {
Eikix marked this conversation as resolved.
Show resolved Hide resolved
// Read the hive genesis
let hive_genesis = HiveGenesisConfig::from_file("crates/hive-utils/src/test_data/hive_genesis.json").unwrap();

// Read the madara genesis
let madara_loader =
serde_json::from_str::<GenesisLoader>(std::include_str!("../../test_data/madara_genesis.json")).unwrap();
let combined_genesis = Path::new(".hive/genesis.json");
let compiled_path = Path::new("cairo-contracts/kakarot");

// Dump the genesis
std::fs::create_dir_all(".hive/").expect("Failed to create Hive dump dir");
serialize_hive_to_madara_genesis_config(hive_genesis, madara_loader, combined_genesis, compiled_path)
.await
.unwrap();
Eikix marked this conversation as resolved.
Show resolved Hide resolved
}
28 changes: 14 additions & 14 deletions crates/hive-utils/src/test_data/madara_genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,65 @@
[
"0x0279d77db761fba82e0054125a6fdb5f6baa6286fa3fb73450cc44d193c2d37f",
{
"path": "./cairo-contracts/NoValidateAccount.json",
"path": "cairo-contracts/NoValidateAccount.json",
"version": 0
}
],
[
"0x06f0d6f6ae72e1a507ff4b65181291642889742dbf8f1a53e9ec1c595d01ba7d",
{
"path": "./cairo-contracts/ArgentAccount.json",
"path": "cairo-contracts/ArgentAccount.json",
"version": 0
}
],
[
"0x0424b7f61e3c5dfd74400d96fdea7e1f0bf2757f31df04387eaa957f095dd7b9",
{ "path": "./cairo-contracts/Proxy.json", "version": 0 }
{ "path": "cairo-contracts/Proxy.json", "version": 0 }
],
[
"0x2c2b8f559e1221468140ad7b2352b1a5be32660d0bf1a3ae3a054a4ec5254e4",
{ "path": "./genesis-assets/Account.json", "version": 0 }
{ "path": "genesis-assets/Account.json", "version": 0 }
],
[
"0x5aa23d5bb71ddaa783da7ea79d405315bafa7cf0387a74f4593578c3e9e6570",
{
"path": "./genesis-assets/AccountBaseImpl.json",
"path": "genesis-assets/AccountBaseImpl.json",
"version": 0
}
],
[
"0x07db5c2c2676c2a5bfc892ee4f596b49514e3056a0eee8ad125870b4fb1dd909",
{
"path": "./genesis-assets/CallAggregator.json",
"path": "genesis-assets/CallAggregator.json",
"version": 0
}
],
[
"0x3131fa018d520a037686ce3efddeab8f28895662f019ca3ca18a626650f7d1e",
{ "path": "./cairo-contracts/Proxy.json", "version": 0 }
{ "path": "cairo-contracts/Proxy.json", "version": 0 }
],
[
"0x006280083f8c2a2db9f737320d5e3029b380e0e820fe24b8d312a6a34fdba0cd",
{
"path": "./cairo-contracts/OpenzeppelinAccount.json",
"path": "cairo-contracts/OpenzeppelinAccount.json",
"version": 0
}
],
[
"0x35ccefcf9d5656da623468e27e682271cd327af196785df99e7fee1436b6276",
{
"path": "./cairo-contracts/NoValidateAccount.casm.json",
"path": "cairo-contracts/NoValidateAccount.casm.json",
"version": 1
}
],
["0x1000", { "path": "./cairo-contracts/test.json", "version": 0 }],
["0x10000", { "path": "./cairo-contracts/ERC20.json", "version": 0 }],
["0x20000", { "path": "./cairo-contracts/ERC20.json", "version": 0 }],
["0x80000", { "path": "./cairo-contracts/ERC721.json", "version": 0 }],
["0x1000", { "path": "cairo-contracts/test.json", "version": 0 }],
["0x10000", { "path": "cairo-contracts/ERC20.json", "version": 0 }],
["0x20000", { "path": "cairo-contracts/ERC20.json", "version": 0 }],
["0x80000", { "path": "cairo-contracts/ERC721.json", "version": 0 }],
[
"0x90000",
{
"path": "./cairo-contracts/UniversalDeployer.json",
"path": "cairo-contracts/UniversalDeployer.json",
"version": 0
}
]
Expand Down
Loading