Skip to content

Commit

Permalink
feat: hive chain (#818)
Browse files Browse the repository at this point in the history
* wip hive chain

* functional hive-chain parsing

* fix provider url

* update the start.sh script
  • Loading branch information
greged93 authored Mar 5, 2024
1 parent 3dd1f6d commit ec0e322
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lint:
- [email protected]
- [email protected]
- [email protected]
- [email protected].3
- [email protected].4
- [email protected]
ignore:
- linters: [ALL]
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"**/.git": false
},
"rust-analyzer.check.command": "clippy",
"rust-analyzer.cargo.features": ["testing", "hive"]
"rust-analyzer.cargo.features": ["testing", "hive", "hive-chain"]
}
15 changes: 4 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ alloy-rlp = { version = "0.3", default-features = false }
ethers = { version = "2.0.9", default-features = false }
ethers-solc = { version = "2.0.9", default-features = false }
jsonrpsee = { version = "0.21.0", features = ["macros", "server"] }
reth-rpc-types = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.18", default-features = false }
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.18", default-features = false }
reth-rpc-types = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.18", default-features = false }

# Serde
serde = { version = "1.0.188", default-features = false, features = ["derive"] }
Expand Down Expand Up @@ -70,6 +70,10 @@ rstest = { version = "0.18.1", default-features = false }
testcontainers = { version = "0.15.0", default-features = false, optional = true }
thiserror = { version = "1.0.38", default-features = false }
tokio = { version = "1.21.2", features = ["macros"] }
tokio-util = { version = "0.7.10", features = [
"codec",
], default-features = false, optional = true }
tokio-stream = { version = "0.1.14", default-features = false, optional = true }
tower = { version = "0.4.12", default-features = false }
tower-http = { version = "0.4.4", default-features = false }
tracing = { version = "0.1.37", default-features = false }
Expand Down Expand Up @@ -105,6 +109,7 @@ toml = { version = "0.7.5", default-features = false }
[features]
testing = ["testcontainers", "rayon", "sequencer", "ef-testing"]
hive = []
hive-chain = ["testing", "tokio-util", "tokio-stream"]

[[bin]]
name = "katana_genesis"
Expand All @@ -113,3 +118,7 @@ required-features = ["testing"]
[[bin]]
name = "hive_genesis"
required-features = ["testing"]

[[bin]]
name = "hive_chain"
required-features = ["hive-chain"]
11 changes: 6 additions & 5 deletions docker/hive/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ FROM ghcr.io/dojoengine/dojo:v0.6.0-alpha.2 as katana

# Indexer service
### Apibara DNA indexer and indexer
FROM quay.io/apibara/starknet:1.2.0 as apibara
FROM quay.io/apibara/sink-mongo as indexer
FROM quay.io/apibara/starknet:1.4.0 as apibara
FROM quay.io/apibara/sink-mongo:0.5.3 as indexer
FROM debian:bookworm as apibara-build
RUN apt-get update && apt-get install -y patchelf && rm -rf /var/lib/apt/lists/*
# Run `docker image inspect apibara/starknet:1.2.0` to get the exact path
COPY --from=apibara /nix/store/swzxd9vbhhj92qzh16j48vb011q57v59-apibara-starknet-1.2.0/bin/apibara-starknet /usr/local/bin/starknet
# Run `docker image inspect apibara/starknet:1.4.0` to get the exact path
COPY --from=apibara /nix/store/nkskc1iii2s658r2mx8bsgk11p6ibz82-apibara-starknet-1.4.0/bin/apibara-starknet /usr/local/bin/starknet
COPY --from=indexer /nix/store/3iqnrcirqpg4s7zdy1wdh0dq17jwzmlc-apibara-sink-mongo-0.5.3/bin/apibara-sink-mongo /usr/local/bin/sink-mongo
# Change the interpreter path.
ARG BUILDPLATFORM
Expand Down Expand Up @@ -39,7 +39,7 @@ RUN git clone -v "https://github.com/kkrt-labs/kakarot-indexer.git"
FROM mongo:6.0.8 as mongo

# Ethereum RPC Server
FROM ghcr.io/kkrt-labs/kakarot-rpc/node:v0.2.4 as rpc
FROM ghcr.io/kkrt-labs/kakarot-rpc/node:v0.2.6 as rpc

FROM debian:bookworm-slim as base
# Install any necessary dependencies
Expand Down Expand Up @@ -99,6 +99,7 @@ RUN mkdir -p /data/db
# Generate the genesis
COPY --from=rpc /usr/local/bin/kakarot-rpc-hive /usr/local/bin/kakarot-rpc
COPY --from=rpc /usr/local/bin/hive_genesis /usr/local/bin
COPY --from=rpc /usr/local/bin/hive_chain /usr/local/bin
RUN mkdir -p /genesis/contracts
COPY ./lib/kakarot/build /genesis/contracts

Expand Down
Binary file modified docker/hive/chain.rlp
Binary file not shown.
107 changes: 28 additions & 79 deletions docker/hive/genesis-2.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"config": {
"chainId": 3503995874084926,
"chainId": 1337,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
Expand All @@ -14,103 +15,51 @@
"londonBlock": 0,
"arrowGlacierBlock": 0,
"grayGlacierBlock": 0,
"mergeNetsplitBlock": 0,
"shanghaiTime": 0,
"cancunTime": 0,
"terminalTotalDifficulty": 131072,
"terminalTotalDifficulty": 0,
"terminalTotalDifficultyPassed": true,
"ethash": {}
},
"nonce": "0x0",
"timestamp": "0x0",
"extraData": "0x68697665636861696e",
"gasLimit": "0x23f3e20",
"difficulty": "0x20000",
"extraData": "0x",
"gasLimit": "0x4c4b40",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"000f3df6d732807ef1319fb7b8bb8522d0beac02": {
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500",
"balance": "0x2a"
"0000000000000000000000000000000000031ec7": {
"code": "0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063a9059cbb14610030575b600080fd5b61004a6004803603810190610045919061016a565b610060565b60405161005791906101c5565b60405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516100bf91906101ef565b60405180910390a36001905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610101826100d6565b9050919050565b610111816100f6565b811461011c57600080fd5b50565b60008135905061012e81610108565b92915050565b6000819050919050565b61014781610134565b811461015257600080fd5b50565b6000813590506101648161013e565b92915050565b60008060408385031215610181576101806100d1565b5b600061018f8582860161011f565b92505060206101a085828601610155565b9150509250929050565b60008115159050919050565b6101bf816101aa565b82525050565b60006020820190506101da60008301846101b6565b92915050565b6101e981610134565b82525050565b600060208201905061020460008301846101e0565b9291505056fea2646970667358221220b469033f4b77b9565ee84e0a2f04d496b18160d26034d54f9487e57788fd36d564736f6c63430008120033",
"balance": "0xde0b6b3a7640000"
},
"0c2c51a0990aee1d73c1228de158688341557508": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
"658bdf435d810c91414ec09147daa6db62406379": {
"balance": "0x487a9a304539440000"
},
"14e46043e63d0e3cdcf2530519f4cfaf35058cb2": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"16c57edf7fa9d9525378b0b81bf8a3ced0620c1c": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"1f4924b14f34e24159387c0a4cdbaa32f3ddb0cf": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"1f5bde34b4afc686f136c7a3cb6ec376f7357759": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"2d389075be5be9f2246ad654ce152cf05990b209": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"3ae75c08b4c907eb63a8960c45b86e1e9ab6123c": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"4340ee1b812acb40a1eb561c019c327b243b92df": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"4a0f1452281bcec5bd90c3dce6162a5995bfe9df": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"4dde844b71bcdf95512fb4dc94e84fb67b512ed8": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"5f552da00dfb4d3749d9e62dcee3c918855a86a0": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"654aa64f5fbefb84c270ec74211b81ca8c44a72e": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"717f8aa2b982bee0e29f573d31df288663e1ce16": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"7435ed30a8b4aeb0877cef0c6e8cffe834eb865f": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"7dcd17433742f4c0ca53122ab541d0ba67fc27df": {
"code": "0x3680600080376000206000548082558060010160005560005263656d697460206000a2",
"balance": "0x0"
},
"83c7e323d189f18725ac510004fdc2941f8c4a78": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"84e75c28348fb86acea1a93a39426d7d60f4cc46": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"8bebc8ba651aee624937e7d897853ac30c95a067": {
"aa00000000000000000000000000000000000000": {
"code": "0x6042",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000002": "0x0000000000000000000000000000000000000000000000000000000000000002",
"0x0000000000000000000000000000000000000000000000000000000000000003": "0x0000000000000000000000000000000000000000000000000000000000000003"
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000000000000000000000000000",
"0x0100000000000000000000000000000000000000000000000000000000000000": "0x0100000000000000000000000000000000000000000000000000000000000000",
"0x0200000000000000000000000000000000000000000000000000000000000000": "0x0200000000000000000000000000000000000000000000000000000000000000",
"0x0300000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000000000000000000000000303"
},
"balance": "0x1",
"nonce": "0x1"
},
"c7b99a164efd027a93f147376cc7da7c67c6bbe0": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"d803681e487e6ac18053afc5a6cd813c86ec3e4d": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"e7d13f7aa2a838d24c59b40186a0aca1e21cffcc": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
},
"eda8645ba6948855e3b3cd596bbb07596d59c603": {
"balance": "0xc097ce7bc90715b34b9f1000000000"
"bb00000000000000000000000000000000000000": {
"code": "0x600154600354",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000000000000000000000000000",
"0x0100000000000000000000000000000000000000000000000000000000000000": "0x0100000000000000000000000000000000000000000000000000000000000000",
"0x0200000000000000000000000000000000000000000000000000000000000000": "0x0200000000000000000000000000000000000000000000000000000000000000",
"0x0300000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000000000000000000000000303"
},
"balance": "0x2",
"nonce": "0x1"
}
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": "0x3b9aca00",
"excessBlobGas": null,
"blobGasUsed": null
"baseFeePerGas": "0x3b9aca00"
}
18 changes: 13 additions & 5 deletions docker/hive/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ mv /genesis/hive-genesis.json /hive-genesis.json && rm -fr /genesis

# 2. Start Katana
echo "Launching Katana..."
RUST_LOG=warn katana --block-time 2000 --disable-fee --chain-id=0x$(jq -r '.config.chainId' hive-genesis.json) --genesis genesis.json &
chain_id=$(printf '%x' $(jq -r '.config.chainId' hive-genesis.json))
RUST_LOG=warn katana --block-time 2000 --disable-fee --chain-id=0x$chain_id --genesis genesis.json &
###### 2.5. Await Katana to be healthy
# Loop until the curl command succeeds
until
Expand All @@ -30,6 +31,17 @@ do
sleep 1
done

export PROXY_ACCOUNT_CLASS_HASH=$(jq -r '.declarations.proxy' manifest.json)
export CONTRACT_ACCOUNT_CLASS_HASH=$(jq -r '.declarations.contract_account' manifest.json)
export EXTERNALLY_OWNED_ACCOUNT_CLASS_HASH=$(jq -r '.declarations.externally_owned_account' manifest.json)
export KAKAROT_ADDRESS=$(jq -r '.deployments.kakarot_address' manifest.json)

# Only launch the Hive Chain if the chain file exists
if test -f "/chain.rlp"; then
echo "Launching Hive Chain..."
CHAIN_PATH="/chain.rlp" hive_chain
fi

# 3. Start the Indexer service: DNA Indexer, Indexer transformer, and MongoDB
## MongoDB
echo "Launching mongo..."
Expand All @@ -47,8 +59,4 @@ sleep 3

# 4. Start the Kakarot RPC service
echo "Launching Kakarot RPC..."
export PROXY_ACCOUNT_CLASS_HASH=$(jq -r '.declarations.proxy' manifest.json)
export CONTRACT_ACCOUNT_CLASS_HASH=$(jq -r '.declarations.contract_account' manifest.json)
export EXTERNALLY_OWNED_ACCOUNT_CLASS_HASH=$(jq -r '.declarations.externally_owned_account' manifest.json)
export KAKAROT_ADDRESS=$(jq -r '.deployments.kakarot_address' manifest.json)
kakarot-rpc
6 changes: 6 additions & 0 deletions docker/rpc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ RUN build_platform() { \
--bin hive_genesis --features testing --target=$ARCH; \
# Copy the genesis binary to a common release directory
cp /usr/src/rpc/target/$ARCH/release/hive_genesis /usr/src/rpc/target/release/; \
# Build the hive chain binary
BINDGEN_EXTRA_CLANG_ARGS=$BINDGEN_EXTRA_CLANG_ARGS cargo build --all --release \
--bin hive_chain --features hive-chain --target=$ARCH; \
# Copy the genesis binary to a common release directory
cp /usr/src/rpc/target/$ARCH/release/hive_chain /usr/src/rpc/target/release/; \
} \
&& rustup self update \
&& case "$TARGETPLATFORM" in \
Expand Down Expand Up @@ -103,6 +108,7 @@ WORKDIR /usr/src/app
COPY --from=builder /usr/src/rpc/target/release/kakarot-rpc /usr/local/bin
COPY --from=builder /usr/src/rpc/target/release/kakarot-rpc-hive /usr/local/bin
COPY --from=builder /usr/src/rpc/target/release/hive_genesis /usr/local/bin
COPY --from=builder /usr/src/rpc/target/release/hive_chain /usr/local/bin

# Expose the port that the RPC server will run on
EXPOSE 9545
Expand Down
Loading

0 comments on commit ec0e322

Please sign in to comment.