Skip to content

Commit

Permalink
feat: add kakarot staging (#895)
Browse files Browse the repository at this point in the history
* feat: add kakarot staging

* fix chain id edge case

* make big chainid smaller

* undox myself - not rewriting git history 🤷‍♂️

* make big chainid u64 at most

* rebase and fix

* docker changes

* feat: fix comments

* use latest individual tag

* new deployment

* use snapshots of juno

* new rpc tag

* take chainid as modulo u32::max

* new upgrade

* latest tag for rpc

* decouple mongo database

* bump kakarot, fix docker

* bump kakarot v0.6.2

* bump kakarot

* re-deploy kakarot on staging

* fix rangecheck

* fix mongo

* fix benchmark

* use kkrt labs docker image

---------

Co-authored-by: Gregory Edison <gregory.edison1993@gmail.com>
  • Loading branch information
Eikix and greged93 authored Apr 9, 2024
1 parent 0e05b3f commit 97cc275
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 112 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ KAKAROT_ADDRESS=
UNINITIALIZED_ACCOUNT_CLASS_HASH=
ACCOUNT_CONTRACT_CLASS_HASH=

## Docker compose configurations
# Ethereum chain RPC websocket connection
ETH_NODE_WS=wss://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY

## configurations for testing
COMPILED_KAKAROT_PATH=lib/kakarot/build

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
build-args: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
APIBARA_STARKNET_BIN_DIR=dsrifc349xgnwsv661shqljxb8pbxx2j
APIBARA_SINK_BIN_DIR=vr6f0crii7571q19j122dfqb1ha1m4i9
APIBARA_SINK_BIN_DIR=sci7y4a8r7yz05094pl88h3d7vv1s98f
outputs: type=docker,dest=./artifacts/kakarot_image.tar
- name: Checkout hive tests
uses: actions/checkout@v4
Expand Down
51 changes: 32 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,8 @@ load-env:
run-dev: load-env
RUST_LOG=trace cargo run --bin kakarot-rpc

docker-build: setup
docker build -t kakarot-rpc . -f docker/rpc/Dockerfile

# Run Katana, Deploy Kakarot, Run Kakarot RPC
katana-rpc-up:
docker compose up -d --force-recreate

# Run Madara, Deploy Kakarot, Run Kakarot RPC
madara-rpc-up:
docker compose -f docker-compose.madara.yaml up -d --force-recreate

docker-down:
docker compose down -v --remove-orphans && docker compose rm

### Kakarot tests and local development:
install-katana:
cargo install --git https://github.com/dojoengine/dojo --locked --tag v0.6.0-alpha.6 katana

Expand All @@ -52,18 +40,43 @@ katana-genesis: install-katana
run-katana: katana-genesis
katana --disable-fee --chain-id=kkrt --genesis .katana/genesis.json

# Total test suite.
test: katana-genesis load-env
cargo test --all --features testing

# Make sure to have a Kakarot RPC running and the correct port set in your .env and an underlying Starknet client running.
benchmark-madara:
cd benchmarks && bun i && bun run benchmark-madara

# Run a specific test target. Need to run make katana-genesis once first.
# Example: `make test-target TARGET=test_raw_transaction`
test-target: load-env
cargo test --tests --features "testing,hive" $(TARGET) -- --nocapture

benchmark-katana:
cd benchmarks && bun i && bun run benchmark-katana
benchmark:
cd benchmarks && bun i && bun run benchmark


### Running the Kakarot stack locally:

docker-build: setup
docker build -t kakarot-rpc . -f docker/rpc/Dockerfile

# Runs a local instance of the entire Kakarot stack: RPC, Indexer, Starknet client, Kakarot contracts deployed.
# This is equivalent to running a local anvil.
local-rpc-up:
docker compose up -d --force-recreate

# Runs a local instance of the Kakarot RPC layer, pointing to the Kakarot Sepolia Testnet in production
# This is equivalent to locally running a Geth instance that syncs with Sepolia.
testnet-rpc-up:
docker compose -f docker-compose.prod.yaml up -d --force-recreate

# Runs a local instance of the Kakarot RPC layer, pointing to the Kakarot Staging environment.
# The staging environment is in all things equivalent to the production environment, but with a different chain ID.
# It is meant to be used for testing and development before pushing things to the public production-ready Testnet.
staging-rpc-up:
docker compose -f docker-compose.staging.yaml up -d --force-recreate

# To stop the dockerized local instances, run: docker compose -f <NAME OF THE FILE> down
# To delete volumes, add the `--volumes` flag to the command above.
# Example: docker compose -f docker-compose.prod.yaml down --remove-orphans --volumes


.PHONY: test
1 change: 1 addition & 0 deletions benchmarks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ while (isRunningFlag) {
to: recipient,
nonce,
value: SEND_AMOUNT,
gasPrice: 0,
});
} catch (e) {
// We expect to get an error:
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"ethers": "^6.9.2"
},
"scripts": {
"benchmark-katana": "INTER_TRANSACTION_MS_DELAY=50 bun run index.ts",
"benchmark-madara": "INTER_TRANSACTION_MS_DELAY=250 bun run index.ts"
"benchmark": "INTER_TRANSACTION_MS_DELAY=200 bun run index.ts"
}
}
65 changes: 0 additions & 65 deletions docker-compose.madara.yaml

This file was deleted.

23 changes: 16 additions & 7 deletions docker-compose.sepolia.yaml → docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
--http-host 0.0.0.0
--http-port 6060
--db-path /var/lib/juno
--eth-node wss://eth-sepolia.g.alchemy.com/v2/WIUR5JUZXieEBkze6Xs3IOXWhsS840TX
--eth-node ${ETH_NODE_WS}
--cn-name kakarot-sepolia
--cn-feeder-url https://gateway.kakarot.sw-dev.io/feeder_gateway/
--cn-gateway-url https://gateway.kakarot.sw-dev.io/gateway/
Expand Down Expand Up @@ -99,23 +99,31 @@ services:

### MongoDB with Mongo Express
mongo:
extends:
file: docker-compose.yaml
service: mongo
image: mongo:6.0.8
restart: always
ports:
- 27017:27017
volumes:
- mongo_data_prod:/data/db
networks:
- internal
environment:
MONGO_INITDB_ROOT_USERNAME: mongo
MONGO_INITDB_ROOT_PASSWORD: mongo

clone-repo:
extends:
file: docker-compose.yaml
service: clone-repo

indexer:
image: quay.io/apibara/sink-mongo
image: quay.io/apibara/sink-mongo:0.7.0
command:
- run
- /code/kakarot-indexer/src/main.ts
environment:
# Whitelist environment variables
- ALLOW_ENV_FROM_ENV=DEBUG,APIBARA_AUTH_TOKEN,STARTING_BLOCK,STREAM_URL,SINK_TYPE,MONGO_CONNECTION_STRING,MONGO_DATABASE_NAME,STARKNET_NETWORK,KAKAROT_ADDRESS,ALLOW_NET
- ALLOW_ENV_FROM_ENV=DEBUG,APIBARA_AUTH_TOKEN,STARTING_BLOCK,STREAM_URL,SINK_TYPE,MONGO_CONNECTION_STRING,MONGO_DATABASE_NAME,STARKNET_NETWORK,KAKAROT_ADDRESS,ALLOW_NET,MONGO_REPLACE_DATA_INSIDE_TRANSACTION
- DEBUG=""
- APIBARA_AUTH_TOKEN=""
- MONGO_CONNECTION_STRING=mongodb://mongo:mongo@mongo:27017
Expand All @@ -125,6 +133,7 @@ services:
- SINK_TYPE=mongo
- STARKNET_NETWORK=http://starknet:6060
- ALLOW_NET=
- MONGO_REPLACE_DATA_INSIDE_TRANSACTION=false
- KAKAROT_ADDRESS=0x1a18210c20241ea7a06224246264a59add11c8358d69826e8bd51f4ba6d3be7
restart: on-failure
volumes:
Expand All @@ -147,7 +156,7 @@ networks:

volumes:
apibara:
mongo_data:
mongo_data_prod:
indexer_code:
pgadmin_data:
juno_files:
Expand Down
156 changes: 156 additions & 0 deletions docker-compose.staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# trunk-ignore-all(yamllint/empty-values)
version: "3.8"

services:
starknet:
image: nethermind/juno:v0.11.1
ports:
- 6060:6060
volumes:
- ${HOME}/code/kkrt-labs/snapshots/juno_sepolia:/var/lib/juno
command: >
--pending-poll-interval "1s"
--http
--http-host 0.0.0.0
--http-port 6060
--db-path /var/lib/juno
--eth-node ${ETH_NODE_WS}
--network sepolia
networks:
- internal
starknet-explorer:
image: public.ecr.aws/o5q6k5w4/stark_compass_explorer:latest
ports:
- 4000:4000
environment:
- PHX_HOST=localhost
- PORT=4000
- RPC_API_HOST=http://host.docker.internal:6060
- TESTNET_RPC_API_HOST=http://host.docker.internal:6060
- SEPOLIA_RPC_API_HOST=http://host.docker.internal:6060
- DISABLE_MAINNET_SYNC=true
- DISABLE_SEPOLIA_SYNC=true
- DATABASE_PATH=ecto://postgres:postgres@starknet-explorer-db:5432/starknet_explorer_dev
- DB_TYPE=postgres
- SECRET_KEY_BASE=JyULoT5cLBifW+XNEuCTVoAb+SaFgQt9j227RN0cKpR3wTsrApGd1HNcgeopemyl
- ENABLE_LISTENER=true
depends_on:
starknet-explorer-db:
condition: service_started
starknet:
condition: service_started
extra_hosts:
- host.docker.internal:172.17.0.1
networks:
- internal

starknet-explorer-db:
image: postgres:15.3
ports:
- 5432:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=starknet_explorer_dev
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- starknet_explorer_staging:/var/lib/postgresql/data/

kakarot-rpc:
image: ghcr.io/kkrt-labs/kakarot-rpc/node:latest
pull_policy: always
ports:
- 3030:3030
environment:
- KAKAROT_RPC_URL=0.0.0.0:3030
- STARKNET_NETWORK=http://starknet:6060
- RUST_LOG=kakarot_rpc=info
- MONGO_CONNECTION_STRING=mongodb://mongo:mongo@mongo:27017
- MONGO_DATABASE_NAME=kakarot-local
# These values are unique to Sepolia Testnet
# They'll need to be manually changed in case the testnet is reset
# To add robustness: parse the `deployments/starknet-sepolia` folder in `kkrt-labs/kakarot` repo
- KAKAROT_ADDRESS=0x464f7e37179d2f93ea208795bdb2d0912e8257f6fb5f67ae2559251523aee19
- UNINITIALIZED_ACCOUNT_CLASS_HASH=0x1d8b8047e26b484d3f6262d1967217d980d0f2dfc69afa5661492bd5bfe2954
- ACCOUNT_CONTRACT_CLASS_HASH=0x56d311021950bf65ee500426e007b9e3ced0db97f9c1e0d29a9e03d79a9bf6c
restart: on-failure
depends_on:
starknet:
condition: service_started
networks:
- internal

apibara-dna:
extends:
file: docker-compose.yaml
service: apibara-dna
command:
- start
- --rpc=http://starknet:6060
- --wait-for-rpc
- --data=/data

### MongoDB with Mongo Express
mongo:
image: mongo:6.0.8
restart: always
ports:
- 27017:27017
volumes:
- mongo_data_staging:/data/db
networks:
- internal
environment:
MONGO_INITDB_ROOT_USERNAME: mongo
MONGO_INITDB_ROOT_PASSWORD: mongo

clone-repo:
extends:
file: docker-compose.yaml
service: clone-repo

indexer:
image: quay.io/apibara/sink-mongo:0.7.0
command:
- run
- /code/kakarot-indexer/src/main.ts
environment:
# Whitelist environment variables
- ALLOW_ENV_FROM_ENV=DEBUG,APIBARA_AUTH_TOKEN,STARTING_BLOCK,STREAM_URL,SINK_TYPE,MONGO_CONNECTION_STRING,MONGO_DATABASE_NAME,STARKNET_NETWORK,KAKAROT_ADDRESS,ALLOW_NET,MONGO_REPLACE_DATA_INSIDE_TRANSACTION
- DEBUG=""
- APIBARA_AUTH_TOKEN=""
- MONGO_CONNECTION_STRING=mongodb://mongo:mongo@mongo:27017
- MONGO_DATABASE_NAME=kakarot-local
- STARTING_BLOCK=0
- STREAM_URL=http://apibara-dna:7171
- SINK_TYPE=mongo
- STARKNET_NETWORK=http://starknet:6060
- ALLOW_NET=
- MONGO_REPLACE_DATA_INSIDE_TRANSACTION=false
- KAKAROT_ADDRESS=0x464f7e37179d2f93ea208795bdb2d0912e8257f6fb5f67ae2559251523aee19
restart: on-failure
volumes:
- indexer_code:/code
networks:
- internal
depends_on:
clone-repo:
condition: service_completed_successfully
starknet:
condition: service_started

networks:
internal:
driver: bridge
default:
driver: bridge
close:
driver: bridge

volumes:
apibara:
mongo_data_staging:
indexer_code:
pgadmin_data:
starknet_explorer_staging:
juno_files_staging:
Loading

0 comments on commit 97cc275

Please sign in to comment.