Skip to content

Commit

Permalink
Merge pull request #41 from hirosystems/feat/signer
Browse files Browse the repository at this point in the history
Update main
  • Loading branch information
CharlieC3 authored Sep 4, 2024
2 parents 4a0fcd7 + 3c7ed71 commit d40cfb4
Show file tree
Hide file tree
Showing 25 changed files with 1,724 additions and 309 deletions.
44 changes: 17 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ on:
push:

env:
STACKS_BLOCKCHAIN_COMMIT: "feat/epoch-2.4"
STACKS_BLOCKCHAIN_COMMIT: d0f5712332619b3140badc2d25856975d2747004

jobs:
cancel-previous-runs:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-stacks-node:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -28,21 +24,15 @@ jobs:
key: cache-stacks-node-${{ env.STACKS_BLOCKCHAIN_COMMIT }}
- name: Install Rust - linux/amd64
if: steps.cache.outputs.cache-hit != 'true'
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: x86_64-unknown-linux-gnu
run: rustup toolchain install stable
- name: Install Rust - linux/arm64
if: steps.cache.outputs.cache-hit != 'true'
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: aarch64-unknown-linux-gnu
run: rustup target add aarch64-unknown-linux-gnu
- name: Install compilation tooling
if: steps.cache.outputs.cache-hit != 'true'
run: |
sudo apt-get update
sudo apt-get install -y g++-aarch64-linux-gnu libc6-dev-arm64-cross gcc-aarch64-linux-gnu
sudo apt-get install -y g++-aarch64-linux-gnu gcc-aarch64-linux-gnu libgcc-11-dev-arm64-cross
- name: Fetch Stacks node repo
if: steps.cache.outputs.cache-hit != 'true'
env:
Expand Down Expand Up @@ -94,7 +84,7 @@ jobs:
build-push-docker:
needs: build-stacks-node
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -115,13 +105,13 @@ jobs:
images: hirosystems/stacks-api-e2e
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=stacks2.4,enable={{is_default_branch}}
type=raw,value=stacks2.4-{{branch}}-{{sha}}
type=ref,event=branch,prefix=stacks2.4-
type=ref,event=pr,prefix=stacks2.4-
type=semver,pattern={{version}},prefix=stacks2.4-
type=semver,pattern={{major}}.{{minor}},prefix=stacks2.4-
type=sha,prefix=stacks2.4-
type=raw,value=stacks3.0,enable={{is_default_branch}}
type=raw,value=stacks3.0-{{branch}}-{{sha}}
type=ref,event=branch,prefix=stacks3.0-
type=ref,event=pr,prefix=stacks3.0-
type=semver,pattern={{version}},prefix=stacks3.0-
type=semver,pattern={{major}}.{{minor}},prefix=stacks3.0-
type=sha,prefix=stacks3.0-
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
stacking/node_modules
package-lock.json
6 changes: 3 additions & 3 deletions Dockerfile.btc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM debian:bullseye-backports
FROM debian:bookworm

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

RUN apt-get update && apt-get install -y curl/bullseye-backports jq zstd
RUN apt-get update && apt-get install -y curl jq zstd
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
CMD ["/bin/bash"]
103 changes: 77 additions & 26 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# syntax=docker/dockerfile:1

FROM rust:bullseye as builder
FROM rust:bookworm as builder

# A commit hash, tag, or branch
ARG GIT_COMMIT=feat/epoch-2.4
ARG GIT_COMMIT=d0f5712332619b3140badc2d25856975d2747004
ARG BLOCKCHAIN_REPO=https://github.com/stacks-network/stacks-blockchain.git

ARG TARGETPLATFORM
Expand Down Expand Up @@ -38,17 +38,20 @@ RUN <<EOF
git reset --hard FETCH_HEAD
fi

apt-get update && apt-get install -y libclang-dev
rustup toolchain install stable
rustup component add rustfmt --toolchain stable
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --package stacks-node --bin stacks-node --release
EOF

FROM debian:bullseye-backports
FROM debian:bookworm-backports

COPY --from=builder /stacks/target/release/stacks-node /usr/local/bin/
COPY --from=ruimarinho/bitcoin-core:0.21.1 /opt/bitcoin-*/bin /usr/local/bin
COPY --from=dobtc/bitcoin:25.1 /opt/bitcoin-*/bin /usr/local/bin

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y curl/bullseye-backports gettext-base jq
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
RUN apt-get update && apt-get install -y curl gettext-base jq
RUN curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh && chmod 500 nsolid_setup_deb.sh && ./nsolid_setup_deb.sh 20 && apt-get install nodejs -y
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

VOLUME /chainstate
Expand Down Expand Up @@ -94,6 +97,15 @@ ENV STACKS_23_HEIGHT=$STACKS_23_HEIGHT
ARG STACKS_24_HEIGHT=111
ENV STACKS_24_HEIGHT=$STACKS_24_HEIGHT

ARG STACKS_25_HEIGHT=112
ENV STACKS_25_HEIGHT=$STACKS_25_HEIGHT

ARG STACKS_30_HEIGHT=132
ENV STACKS_30_HEIGHT=$STACKS_30_HEIGHT

ARG STACKS_PREHEAT_FINISH_HEIGHT=150
ENV STACKS_PREHEAT_FINISH_HEIGHT=$STACKS_PREHEAT_FINISH_HEIGHT

# priv: 6ad9cadb42d4edbfbe0c5bfb3b8a4125ddced021c4174f829b714ccbf527f02001
# ARG REWARD_RECIPIENT=STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN
ARG REWARD_RECIPIENT
Expand Down Expand Up @@ -124,6 +136,33 @@ const server = http.createServer((req, res) => {
EOM
EOF

# Create Stacking script
RUN npm init -y && npm i @stacks/stacking@6
RUN <<EOF
cat > /root/stack.js <<'EOM'
const { StackingClient } = require('@stacks/stacking');
const { StacksTestnet } = require('@stacks/network');
console.log('Stacking with args:', process.argv.slice(2));
const network = new StacksTestnet({ url: 'http://localhost:20443' });
const address = 'ST18MDW2PDTBSCR1ACXYRJP2JX70FWNM6YY2VX4SS';
const client = new StackingClient(address, network);
client.stack({
amountMicroStx: parseInt(process.argv[2]),
burnBlockHeight: parseInt(process.argv[3]),
poxAddress: 'mvuYDknzDtPgGqm2GnbAbmGMLwiyW3AwFP',
cycles: 12,
privateKey: '6a1a754ba863d7bab14adbbc3f8ebb090af9e871ace621d3e5ab634e1422885e01',
fee: 1000,
nonce: 0,
})
.then(r => console.log('Stacked', r))
.catch(e => {
console.error('Error stacking', e);
process.exit(1);
});
EOM
EOF

# Bootstrap chainstates
SHELL ["/bin/bash", "-ce"]
RUN <<EOF
Expand All @@ -135,8 +174,8 @@ RUN <<EOF
bitcoind &
BTCD_PID=$!
bitcoin-cli -rpcwait getmininginfo
bitcoin-cli createwallet ""
bitcoin-cli importprivkey $BTC_ADDR_WIF "" false
bitcoin-cli -named createwallet wallet_name=main descriptors=false load_on_startup=true
bitcoin-cli -rpcwallet=main importprivkey $BTC_ADDR_WIF "" false
bitcoin-cli generatetoaddress 101 $BTC_ADDR

node event-observer.js &
Expand All @@ -145,7 +184,7 @@ RUN <<EOF
export STACKS_EVENT_OBSERVER="127.0.0.1:3998"
mkdir -p /chainstate/stacks-blockchain-data
envsubst < config.toml.in > config.toml
stacks-node start --config=config.toml &
stacks-node start --config config.toml &
STACKS_PID=$!

while true; do
Expand All @@ -157,27 +196,39 @@ RUN <<EOF
sleep 0.5s
done

DEFAULT_TIMEOUT=$(($(date +%s) + 30))
SENT_STACKING=0
while true; do
TX=$(bitcoin-cli listtransactions '*' 1 0 true)
TX=$(bitcoin-cli -rpcwallet=main listtransactions '*' 1 0 true)
CONFS=$(echo "$TX" | jq '.[].confirmations')
if [ "$CONFS" = "0" ]; then
echo "Detected Stacks mining mempool tx, mining btc block..."
if [ "$CONFS" = "0" ] || [ $(date +%s) -gt $DEFAULT_TIMEOUT ]; then
if [ $(date +%s) -gt $DEFAULT_TIMEOUT ]; then
echo "Timed out waiting for a mempool tx, mining a btc block..."
else
echo "Detected Stacks mining mempool tx, mining btc block..."
fi
bitcoin-cli generatetoaddress 1 $BTC_ADDR
DEFAULT_TIMEOUT=$(($(date +%s) + 30))
chain_height=$(bitcoin-cli getblockcount)
echo "Current Bitcoin chain height: $chain_height"

while true; do
HEIGHT=$(curl -s localhost:20443/v2/info | jq '.burn_block_height')
if [ "$HEIGHT" = "$chain_height" ]; then
echo "Stacks node caught up to Bitcoin block $HEIGHT"
break
else
echo "Stacks node burn height: $HEIGHT, waiting for $chain_height"
fi
sleep 0.1s
done

if [ "$chain_height" = "$STACKS_24_HEIGHT" ]; then
POX_CONTRACT=$(curl -s localhost:20443/v2/pox | jq -r '.contract_id')
BURN_HEIGHT=$(curl -s localhost:20443/v2/pox | jq -r '.current_burnchain_block_height')
echo "POX contract check $BURN_HEIGHT $POX_CONTRACT"
if [ "$POX_CONTRACT" = "ST000000000000000000002AMW42H.pox-4" ] && [ "$SENT_STACKING" = "0" ]; then
echo "POX contract is pox-4"
SENT_STACKING=1
# issue a stack-stx tx, required for epoch3.0 transition
POX_STATE=$(curl -s localhost:20443/v2/pox)
echo "Stack STX tx for epoch3.0 transition"
echo "$POX_STATE" | jq '.'
MIN_STACKING_AMOUNT="8500000000000000"
BURN_HEIGHT=$(echo $POX_STATE | jq '.current_burnchain_block_height + 1')
node /root/stack.js $MIN_STACKING_AMOUNT $BURN_HEIGHT
sleep 5s
fi

if [ "$chain_height" = "$STACKS_PREHEAT_FINISH_HEIGHT" ]; then
break
fi

Expand Down Expand Up @@ -223,12 +274,12 @@ cat > run.sh <<'EOM'
bitcoin-cli -rpcwait generatetoaddress 1 $BTC_ADDR

envsubst < config.toml.in > config.toml
stacks-node start --config=config.toml &
stacks-node start --config config.toml &
STACKS_PID=$!

function start_miner() {
while true; do
TX=$(bitcoin-cli listtransactions '*' 1 0 true)
TX=$(bitcoin-cli -rpcwallet=main listtransactions '*' 1 0 true)
CONFS=$(echo "$TX" | jq '.[].confirmations')
if [ "$CONFS" = "0" ]; then
echo "Detected Stacks mining mempool tx, mining btc block..."
Expand Down
11 changes: 11 additions & 0 deletions Dockerfile.stacker
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:20-bookworm as builder

RUN apt-get update && apt-get install -y curl gettext-base jq

WORKDIR /root
COPY ./stacking/package.json /root/
RUN npm i

COPY ./stacking/stacking.ts ./stacking/common.ts ./stacking/monitor.ts ./stacking/tx-broadcaster.ts /root/

CMD ["npx", "tsx", "/root/stacking.ts"]
5 changes: 2 additions & 3 deletions Dockerfile.stacks-api
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-bullseye as builder
FROM node:20-bookworm as builder

ARG GIT_COMMIT
RUN test -n "$GIT_COMMIT" || (echo "GIT_COMMIT not set" && false)
Expand All @@ -17,9 +17,8 @@ RUN git describe --tags --abbrev=0 || git -c user.name='user' -c user.email='ema
RUN echo "GIT_TAG=$(git tag --points-at HEAD)" >> .env

RUN npm config set update-notifier false && \
npm config set unsafe-perm true && \
npm ci --audit=false && \
npm run build && \
npm prune --production
npm prune --omit=dev

CMD ["node", "./lib/index.js"]
17 changes: 11 additions & 6 deletions Dockerfile.stacks-node
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
FROM rust:bullseye as builder
FROM rust:bookworm as builder

# TODO: is there a built-in required arg syntax?
ARG GIT_COMMIT
RUN test -n "$GIT_COMMIT" || (echo "GIT_COMMIT not set" && false)

RUN echo "Building stacks-node from commit: https://github.com/stacks-network/stacks-blockchain/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 /stacks
RUN git init && \
git remote add origin https://github.com/stacks-network/stacks-blockchain.git && \
git -c protocol.version=2 fetch --depth=1 origin "$GIT_COMMIT" && \
git reset --hard FETCH_HEAD

RUN cargo build --package stacks-node --bin stacks-node --release
RUN cargo build --package stacks-node --package stacks-signer --bin stacks-node --bin stacks-signer

FROM debian:bullseye-backports
FROM debian:bookworm

COPY --from=builder /stacks/target/release/stacks-node /usr/local/bin/
COPY --from=builder /stacks/target/debug/stacks-node /usr/local/bin/
COPY --from=builder /stacks/target/debug/stacks-signer /usr/local/bin/

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

RUN apt-get update && apt-get install -y curl/bullseye-backports gettext-base jq
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
Expand Down
Loading

0 comments on commit d40cfb4

Please sign in to comment.