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

Test/broken pox2 activation #16

Open
wants to merge 8 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
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=zone117x/stacks-api-e2e:latest
cache-to: type=inline
build-args: |
STACKS_21_HEIGHT=3
STACKS_POX2_HEIGHT=4

build-push-stacks2_1-transition-docker:
needs: build-stacks-node
Expand Down
62 changes: 29 additions & 33 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

FROM rust:bullseye as builder

ARG GIT_COMMIT=fe314a0b6650ecfa138e15c7ed4014fa829037ef
ARG GIT_COMMIT=3c6e4eb2e30dedd018085fc7ff3b340bd7dfcb2f
ARG TARGETPLATFORM
ENV DEBIAN_FRONTEND noninteractive

Expand Down Expand Up @@ -40,6 +40,13 @@ ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y curl/bullseye-backports gettext-base jq
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install NodeJS
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && apt-get install -y nodejs

WORKDIR /root

RUN npm init -y && npm install [email protected]

VOLUME /chainstate

# Stacks-node RPC
Expand All @@ -61,25 +68,34 @@ ENV BITCOIN_RPC_PASS=btc
ARG MINE_INTERVAL=5s
ENV MINE_INTERVAL=$MINE_INTERVAL

ARG STACKS_21_HEIGHT=103
ARG STACKS_20_HEIGHT=103
ENV STACKS_20_HEIGHT=$STACKS_20_HEIGHT

ARG STACKS_2_05_HEIGHT=104
ENV STACKS_2_05_HEIGHT=$STACKS_2_05_HEIGHT

ARG STACKS_21_HEIGHT=105
ENV STACKS_21_HEIGHT=$STACKS_21_HEIGHT

ARG STACKS_POX2_HEIGHT=104
ARG STACKS_POX2_HEIGHT=106
ENV STACKS_POX2_HEIGHT=$STACKS_POX2_HEIGHT

ARG STACKS_LOG_DEBUG=0
ENV STACKS_LOG_DEBUG=$STACKS_LOG_DEBUG

# priv: 6ad9cadb42d4edbfbe0c5bfb3b8a4125ddced021c4174f829b714ccbf527f02001
# ARG REWARD_RECIPIENT=STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN
ARG REWARD_RECIPIENT
ENV REWARD_RECIPIENT=$REWARD_RECIPIENT

COPY ./bitcoin.conf /root/.bitcoin/bitcoin.conf
COPY ./stacks-krypton-miner.toml /root/config.toml.in
COPY ./event-observer.js /root/event-observer.js

WORKDIR /root

# Bootstrap chainstates
SHELL ["/bin/bash", "-ce"]
# Create run script
RUN <<EOF
cat > run.sh <<'EOM'
#!/bin/bash -e
if [[ ! -z "${REWARD_RECIPIENT}" ]]; then
export REWARD_RECIPIENT_CONF="block_reward_recipient = \"$REWARD_RECIPIENT\""
fi
Expand All @@ -92,6 +108,9 @@ RUN <<EOF
bitcoin-cli importaddress $BTC_ADDR "" false
bitcoin-cli generatetoaddress 101 $BTC_ADDR

node event-observer.js &
EVENT_OBSERVER_PID=$!

mkdir -p /chainstate/stacks-blockchain-data
envsubst < config.toml.in > config.toml
stacks-node start --config=config.toml &
Expand All @@ -103,35 +122,10 @@ RUN <<EOF
echo "Stacks node caught up to block 101"
break
fi
sleep 0.5s
sleep 1.5s
done

kill $STACKS_PID
wait $STACKS_PID

bitcoin-cli stop
wait $BTCD_PID
EOF

# Create run script
RUN <<EOF
cat > run.sh <<'EOM'
#!/bin/bash -e
if [[ ! -z "${REWARD_RECIPIENT}" ]]; then
export REWARD_RECIPIENT_CONF="block_reward_recipient = \"$REWARD_RECIPIENT\""
fi

bitcoind &
BTCD_PID=$!

bitcoin-cli -rpcwait getmininginfo

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

function start_miner() {
bitcoin-cli -rpcwait generatetoaddress 1 $BTC_ADDR
while true; do
TX=$(bitcoin-cli listtransactions '*' 1 0 true)
CONFS=$(echo "$TX" | jq '.[].confirmations')
Expand All @@ -148,6 +142,8 @@ cat > run.sh <<'EOM'
echo "Exiting, signal: $1"
kill $STACKS_PID 2>/dev/null && echo "Stacks exiting.."
wait $STACKS_PID 2>/dev/null && echo "Stacks exited"
kill $EVENT_OBSERVER_PID 2>/dev/null && echo "Event-observer exiting.."
wait $EVENT_OBSERVER_PID 2>/dev/null && echo "Event-observer exited"
kill $BTCD_PID 2>/dev/null && echo "Bitcoind exiting.."
wait $BTCD_PID 2>/dev/null && echo "Bitcoind exited"
}
Expand Down
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ x-common-vars:
- &BITCOIN_RPC_USER btc
- &BITCOIN_RPC_PASS btc
- &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_20_HEIGHT ${STACKS_20_HEIGHT:-104}
- &STACKS_2_05_HEIGHT ${STACKS_2_05_HEIGHT:-105}
- &STACKS_21_HEIGHT ${STACKS_21_HEIGHT:-106}
- &STACKS_POX2_HEIGHT ${STACKS_POX2_HEIGHT:-106} # 104 is is stacks_block=1, 106 is stacks_block=3
- &REWARD_RECIPIENT ${REWARD_RECIPIENT:-STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN} # priv: 6ad9cadb42d4edbfbe0c5bfb3b8a4125ddced021c4174f829b714ccbf527f02001

services:
Expand Down Expand Up @@ -203,7 +205,7 @@ services:
context: .
dockerfile: Dockerfile.stacks-api
args:
GIT_COMMIT: 4a332f353ee10802fa7b04e888b32e54d010a69d
GIT_COMMIT: e34fab5e5d92222433b19021c584da903b64f27a
depends_on:
- postgres
ports:
Expand Down
1 change: 1 addition & 0 deletions event-log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

33 changes: 33 additions & 0 deletions event-observer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node

const http = require('http');
const fs = require('fs');
const decodeTransaction = require('stacks-encoding-native-js').decodeTransaction;

const server = http.createServer((request, response) => {
const { headers, method, url } = request;
let body = [];
request.on('error', (err) => {
console.error(err);
response.writeHead(500).end();
}).on('data', (chunk) => {
body.push(chunk);
}).on('end', () => {
body = JSON.parse(Buffer.concat(body).toString());
if (body.transactions) {
for (const transaction of body.transactions) {
transaction.decoded_tx = decodeTransaction(transaction.raw_tx)
}
}
console.log(url, body);
fs.appendFileSync('/event-log.json', `["${url}",${JSON.stringify(body)}]\n`);
response.writeHead(200).end();
});
});
server.listen(3998, '0.0.0.0', () => {
console.log(`Event-observer started on: ${server.address().address}:${server.address().port}`);
});

process.on('exit', (code) => {
console.log(`Event-observer to exit with code: ${code}`);
});
11 changes: 11 additions & 0 deletions readme-dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Locally build and test e2e dockerfile

First build:
```shell
docker build -t e2e-test -f Dockerfile.e2e .
```

Then run:
```shell
docker run --rm -p "20443:20443" -e MINE_INTERVAL=0.01s -v "$(pwd)"/event-log.json:/event-log.json e2e-test
```
13 changes: 9 additions & 4 deletions stacks-krypton-miner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ local_peer_seed = "$MINER_SEED"

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

[[events_observer]]
endpoint = "localhost:3998"
retry_count = 255
events_keys = ["*"]

[miner]
first_attempt_time_ms = 5000
first_attempt_time_ms = 30000
subsequent_attempt_time_ms = 5000
$REWARD_RECIPIENT_CONF

Expand Down Expand Up @@ -51,11 +56,11 @@ start_height = 0

[[burnchain.epochs]]
epoch_name = "2.0"
start_height = 1
start_height = $STACKS_20_HEIGHT

[[burnchain.epochs]]
epoch_name = "2.05"
start_height = 2
start_height = $STACKS_2_05_HEIGHT

[[burnchain.epochs]]
epoch_name = "2.1"
Expand Down