Skip to content

Commit

Permalink
feat: add chainhook
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Oct 22, 2024
1 parent b457877 commit 9d76c50
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 9 deletions.
30 changes: 30 additions & 0 deletions Dockerfile.chainhook
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM rust:bookworm AS builder

ARG GIT_COMMIT
RUN test -n "$GIT_COMMIT" || (echo "GIT_COMMIT not set" && false)

RUN echo "Building chainhook from commit: https://github.com/hirosystems/chainhook/commit/$GIT_COMMIT"

RUN apt-get update && apt-get install -y libclang-dev
RUN rustup toolchain install stable
# RUN rustup component add rustfmt --toolchain stable

WORKDIR /chainhook
RUN git init && \
git remote add origin https://github.com/hirosystems/chainhook.git && \
git -c protocol.version=2 fetch --depth=1 origin "$GIT_COMMIT" && \
git reset --hard FETCH_HEAD

RUN cargo build --package chainhook

FROM debian:bookworm

COPY --from=builder /chainhook/target/debug/chainhook /usr/local/bin/

COPY --from=dobtc/bitcoin:25.1 /opt/bitcoin-*/bin /usr/local/bin

RUN apt-get update && apt-get install -y curl gettext-base jq
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

WORKDIR /root
CMD ["chainhook"]
46 changes: 46 additions & 0 deletions chainhook.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[storage]
working_dir = "cache"

# The HTTP API allows you to register / deregister
# predicates dynamically.
# This is disabled by default.
#
[http_api]
http_port = 20456
database_uri = "redis://redis:6379/"

[network]
mode = "devnet"
bitcoind_rpc_url = "http://$BITCOIN_PEER_HOST:$BITCOIN_RPC_PORT"
bitcoind_rpc_username = "$BITCOIN_RPC_USER"
bitcoind_rpc_password = "$BITCOIN_RPC_PASS"

# Chainhook must be able to receive Bitcoin block events.
# These events can originate from either a Stacks node or a Bitcoin node's ZeroMQ interface.

# By default, the service is set to receive Bitcoin block events from the Stacks node:
stacks_node_rpc_url = "http://$STACKS_NODE_HOST"
stacks_events_ingestion_port = 20455

# However, events can also be received directly from a Bitcoin node.
# To achieve this, comment out the `stacks_node_rpc_url` line and uncomment the following line:
# bitcoind_zmq_url = "tcp://0.0.0.0:18543"

[limits]
max_number_of_bitcoin_predicates = 100
max_number_of_concurrent_bitcoin_scans = 100
max_number_of_stacks_predicates = 10
max_number_of_concurrent_stacks_scans = 10
max_number_of_processing_threads = 16
max_number_of_networking_threads = 16
max_caching_memory_size_mb = 32000

# The TSV file is required for downloading historical data for your predicates.
# If this is not a requirement, you can comment out the `tsv_file_url` line.
# [[event_source]]
# tsv_file_url = "https://archive.hiro.so/regtest/stacks-blockchain-api/regtest-stacks-blockchain-api-latest"

# Enables a server that provides metrics that can be scraped by Prometheus.
# This is disabled by default.
# [monitoring]
# prometheus_monitoring_port = 20457
48 changes: 44 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: "3.9"

x-common-vars:
- &STACKS_BLOCKCHAIN_COMMIT e2bd98230483a3ee18d03cbfccfc795dbdcb2004 # develop, Oct 14, 12:20 PST
- &STACKS_API_COMMIT f6e50f6d28f292d79dbebd70b2b00831c95997f6 # 7.13.2
- &STACKS_BLOCKCHAIN_COMMIT 607e3f115f811fb5d012ad03f19f6980f9ca8bea # develop, Oct 14, 12:20 PST
- &STACKS_API_COMMIT 65d5422c8458c127b6629b44a4ccfe2d6306301c # 7.13.2
- &CHAINHOOK_COMMIT f48cda533dfc58bb630737fb29cf1bc9c966a638 # develop, Oct 22
- &BITCOIN_ADDRESSES miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT
- &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za
- &BITCOIN_PEER_PORT 18444
Expand Down Expand Up @@ -477,6 +476,47 @@ services:
envsubst < config.toml.in > config.toml
exec stacks-signer run --config config.toml
redis:
networks:
- stacks
image: "redis:latest"
ports:
- "6379:6379"

chainhook:
networks:
- stacks
build:
context: .
dockerfile: Dockerfile.chainhook
args:
GIT_COMMIT: *CHAINHOOK_COMMIT
depends_on:
- bitcoind
- redis
ports:
- "20456:20456"
- "20455:20455"
volumes:
- ./chainhook.toml/:/root/chainhook.toml.in
- ./bitcoin.conf:/root/.bitcoin/bitcoin.conf
environment:
BITCOIN_PEER_HOST: bitcoind
BITCOIN_RPC_PORT: *BITCOIN_RPC_PORT
BITCOIN_RPC_USER: *BITCOIN_RPC_USER
BITCOIN_RPC_PASS: *BITCOIN_RPC_PASS
STACKS_NODE_HOST: stacks-node:20443
entrypoint:
- /bin/bash
- -c
- |
set -e
envsubst < chainhook.toml.in > chainhook.toml
echo "Waiting for bitcoind to be ready..."
bitcoin-cli -rpcwait -rpcconnect=bitcoind getmininginfo
echo "Starting Chainhook with config: $$(cat chainhook.toml)"
exec chainhook service start --config-path=chainhook.toml
networks:
stacks:
volumes:
Expand Down
17 changes: 12 additions & 5 deletions stacks-krypton-miner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ disable_inbound_walks = true
public_ip_address = "1.1.1.1:1234"
auth_token = "12345"

# Add stacks-api as an event observer
[[events_observer]]
endpoint = "stacks-api:3700"
events_keys = ["*"]

# Add stacks-signer as an event observer
[[events_observer]]
endpoint = "stacks-signer-1:30001"
Expand All @@ -55,6 +50,18 @@ events_keys = ["stackerdb", "block_proposal", "burn_blocks"]
endpoint = "stacks-signer-3:30003"
events_keys = ["stackerdb", "block_proposal", "burn_blocks"]

# Add stacks-api as an event observer
[[events_observer]]
endpoint = "stacks-api:3700"
events_keys = ["*"]
timeout_ms = 300_000

# Add chainhook as an event observer
[[events_observer]]
endpoint = "chainhook:20455"
events_keys = ["*"]
timeout_ms = 300_000

[burnchain]
chain = "bitcoin"
mode = "nakamoto-neon"
Expand Down

0 comments on commit 9d76c50

Please sign in to comment.