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/slow mining #25

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
75 changes: 8 additions & 67 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:

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

jobs:
cancel-previous-runs:
Expand Down Expand Up @@ -115,13 +115,13 @@ jobs:
images: hirosystems/stacks-api-e2e
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=stacks2.1,enable={{is_default_branch}}
type=raw,value=stacks2.1-{{branch}}-{{sha}}
type=ref,event=branch,prefix=stacks2.1-
type=ref,event=pr,prefix=stacks2.1-
type=semver,pattern={{version}},prefix=stacks2.1-
type=semver,pattern={{major}}.{{minor}},prefix=stacks2.1-
type=sha,prefix=stacks2.1-
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-
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand All @@ -146,62 +146,3 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=hirosystems/stacks-api-e2e:latest
cache-to: type=inline

build-push-stacks2_1-transition-docker:
needs: build-stacks-node
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: stacks-node-bin
path: stacks-blockchain-binaries
- name: Process of downloaded artifacts
working-directory: stacks-blockchain-binaries
run: |
ls -R
chmod +x x86_64-unknown-linux-gnu/stacks-node
chmod +x aarch64-unknown-linux-gnu/stacks-node
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: hirosystems/stacks-api-e2e
flavor: |
latest=false
tags: |
type=raw,value=stacks2.1-transition,enable={{is_default_branch}}
type=raw,value=stacks2.1-transition-{{branch}}-{{sha}}
type=ref,event=branch,prefix=stacks2.1-transition-
type=ref,event=pr,prefix=stacks2.1-transition-
type=semver,pattern={{version}},prefix=stacks2.1-transition-
type=semver,pattern={{major}}.{{minor}},prefix=stacks2.1-transition-
type=sha,prefix=stacks2.1-transition-
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN || secrets.DOCKERHUB_PASSWORD }}
- name: Build Docker images
uses: docker/build-push-action@v3
with:
file: Dockerfile.e2e
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=hirosystems/stacks-api-e2e:stacks2.1-transition
cache-to: type=inline
build-args: |
STACKS_21_HEIGHT=120
STACKS_POX2_HEIGHT=136
47 changes: 43 additions & 4 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FROM rust:bullseye as builder

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

ARG TARGETPLATFORM
Expand Down Expand Up @@ -85,6 +85,15 @@ ENV STACKS_21_HEIGHT=$STACKS_21_HEIGHT
ARG STACKS_POX2_HEIGHT=107
ENV STACKS_POX2_HEIGHT=$STACKS_POX2_HEIGHT

ARG STACKS_22_HEIGHT=108
ENV STACKS_22_HEIGHT=$STACKS_22_HEIGHT

ARG STACKS_23_HEIGHT=109
ENV STACKS_23_HEIGHT=$STACKS_23_HEIGHT

ARG STACKS_24_HEIGHT=111
ENV STACKS_24_HEIGHT=$STACKS_24_HEIGHT

# priv: 6ad9cadb42d4edbfbe0c5bfb3b8a4125ddced021c4174f829b714ccbf527f02001
# ARG REWARD_RECIPIENT=STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN
ARG REWARD_RECIPIENT
Expand Down Expand Up @@ -128,7 +137,7 @@ RUN <<EOF
bitcoin-cli -rpcwait getmininginfo
bitcoin-cli createwallet ""
bitcoin-cli importprivkey $BTC_ADDR_WIF "" false
bitcoin-cli generatetoaddress 100 $BTC_ADDR
bitcoin-cli generatetoaddress 101 $BTC_ADDR

node event-observer.js &
EVENT_OBSERVER_PID=$!
Expand All @@ -141,13 +150,43 @@ RUN <<EOF

while true; do
HEIGHT=$(curl -s localhost:20443/v2/info | jq '.burn_block_height')
if [ "$HEIGHT" = "100" ]; then
echo "Stacks node caught up to block 100"
if [ "$HEIGHT" = "101" ]; then
echo "Stacks node caught up to Bitcoin block $HEIGHT"
break
fi
sleep 0.5s
done

while true; do
TX=$(bitcoin-cli listtransactions '*' 1 0 true)
CONFS=$(echo "$TX" | jq '.[].confirmations')
if [ "$CONFS" = "0" ]; then
echo "Detected Stacks mining mempool tx, mining btc block..."
bitcoin-cli generatetoaddress 1 $BTC_ADDR
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
break
fi

else
sleep 0.1s
fi
done


kill $STACKS_PID
wait $STACKS_PID

Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ x-common-vars:
- &MINE_INTERVAL ${MINE_INTERVAL:-0.5s}
- &STACKS_21_HEIGHT ${STACKS_21_HEIGHT:-103}
- &STACKS_POX2_HEIGHT ${STACKS_POX2_HEIGHT:-104} # 104 is is stacks_block=1, 106 is stacks_block=3
- &STACKS_22_HEIGHT ${STACKS_22_HEIGHT:-105}
- &STACKS_23_HEIGHT ${STACKS_23_HEIGHT:-106}
- &STACKS_24_HEIGHT ${STACKS_24_HEIGHT:-107}
- &REWARD_RECIPIENT ${REWARD_RECIPIENT:-STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN} # priv: 6ad9cadb42d4edbfbe0c5bfb3b8a4125ddced021c4174f829b714ccbf527f02001

services:
Expand Down Expand Up @@ -39,6 +42,9 @@ services:
INIT_BLOCKS: 101
STACKS_21_HEIGHT: *STACKS_21_HEIGHT
STACKS_POX2_HEIGHT: *STACKS_POX2_HEIGHT
STACKS_22_HEIGHT: *STACKS_22_HEIGHT
STACKS_23_HEIGHT: *STACKS_23_HEIGHT
STACKS_24_HEIGHT: *STACKS_24_HEIGHT
REWARD_RECIPIENT: *REWARD_RECIPIENT
entrypoint:
- /bin/bash
Expand Down Expand Up @@ -168,6 +174,9 @@ services:
MINER_SEED: *MINER_SEED
STACKS_21_HEIGHT: *STACKS_21_HEIGHT
STACKS_POX2_HEIGHT: *STACKS_POX2_HEIGHT
STACKS_22_HEIGHT: *STACKS_22_HEIGHT
STACKS_23_HEIGHT: *STACKS_23_HEIGHT
STACKS_24_HEIGHT: *STACKS_24_HEIGHT
REWARD_RECIPIENT: *REWARD_RECIPIENT
entrypoint:
- /bin/bash
Expand Down
30 changes: 21 additions & 9 deletions stacks-krypton-miner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ local_peer_seed = "$MINER_SEED"

miner = true
use_test_genesis_chainstate = true
pox_sync_sample_secs = 0
pox_sync_sample_secs = 5
wait_time_for_blocks = 0
wait_time_for_microblocks = 50
microblock_frequency = 1000
# mine_microblocks = true
mine_microblocks = false
# max_microblocks = 10

[miner]
Expand All @@ -22,18 +22,18 @@ subsequent_attempt_time_ms = 5000
$REWARD_RECIPIENT_CONF

[connection_options]
# inv_sync_interval = 10
# download_interval = 10
# walk_interval = 10
disable_block_download = true
disable_inbound_handshakes = true
disable_inbound_walks = true
inv_sync_interval = 10
download_interval = 10
walk_interval = 10
disable_block_download = false
disable_inbound_handshakes = false
disable_inbound_walks = false
public_ip_address = "1.1.1.1:1234"

[burnchain]
chain = "bitcoin"
mode = "krypton"
poll_time_secs = 1
poll_time_secs = 5
pox_2_activation = $STACKS_POX2_HEIGHT

### bitcoind-regtest connection info
Expand Down Expand Up @@ -61,6 +61,18 @@ start_height = $STACKS_2_05_HEIGHT
epoch_name = "2.1"
start_height = $STACKS_21_HEIGHT

[[burnchain.epochs]]
epoch_name = "2.2"
start_height = $STACKS_22_HEIGHT

[[burnchain.epochs]]
epoch_name = "2.3"
start_height = $STACKS_23_HEIGHT

[[burnchain.epochs]]
epoch_name = "2.4"
start_height = $STACKS_24_HEIGHT

[[ustx_balance]]
address = "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6"
amount = 10000000000000000
Expand Down
11 changes: 11 additions & 0 deletions wip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* First build the image:
```shell
docker build -t e2e-test -f Dockerfile.e2e .
```

* Then run the image:
```shell
docker run --rm -p "20443:20443" -e MINE_INTERVAL=5s e2e-test
```

* If everything works, visit http://localhost:20443/v2/pox