From 5ca6d01bb43f10e08c0e1720411a7e23a9e95003 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 12 Dec 2023 21:04:12 +0100 Subject: [PATCH 01/29] feat: almost activating epoch3 --- Dockerfile.e2e | 67 +++++++++++++++++++++++++++++++++++---- stacks-krypton-miner.toml | 1 + 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/Dockerfile.e2e b/Dockerfile.e2e index 6532c27..cac2800 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -3,7 +3,7 @@ FROM rust:bookworm as builder # A commit hash, tag, or branch -ARG GIT_COMMIT=f8ffd1dbe8990234391def4611b2611be9a3e4ba +ARG GIT_COMMIT=16bb6887f84a299b5bbbe4c469337169849ce6ed ARG BLOCKCHAIN_REPO=https://github.com/stacks-network/stacks-blockchain.git ARG TARGETPLATFORM @@ -47,7 +47,7 @@ EOF 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=btcpayserver/bitcoin:25.1 /usr/local/bin/bitcoind /usr/local/bin/bitcoin-cli /usr/local/bin/ ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get install -y curl gettext-base jq @@ -100,10 +100,12 @@ ENV STACKS_24_HEIGHT=$STACKS_24_HEIGHT ARG STACKS_25_HEIGHT=112 ENV STACKS_25_HEIGHT=$STACKS_25_HEIGHT -# do not boot into epoch3.0 for now (it doesn't work yet) -ARG STACKS_30_HEIGHT=999999 +ARG STACKS_30_HEIGHT=121 ENV STACKS_30_HEIGHT=$STACKS_30_HEIGHT +ARG STACKS_PREHEAT_FINISH_HEIGHT=130 +ENV STACKS_PREHEAT_FINISH_HEIGHT=$STACKS_PREHEAT_FINISH_HEIGHT + # priv: 6ad9cadb42d4edbfbe0c5bfb3b8a4125ddced021c4174f829b714ccbf527f02001 # ARG REWARD_RECIPIENT=STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN ARG REWARD_RECIPIENT @@ -134,6 +136,33 @@ const server = http.createServer((req, res) => { EOM EOF +# Create Stacking script +RUN npm init -y && npm i @stacks/stacking@6 +RUN < /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: '08c14a1eada0dd42b667b40f59f7c8dedb12113613448dc04980aea20b268ddb01', + 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 < Date: Tue, 12 Dec 2023 15:38:22 -0600 Subject: [PATCH 02/29] stashing some close to working changes --- Dockerfile.e2e | 16 +++++++++++----- stacks-krypton-miner.toml | 23 ++++++++++++++++------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Dockerfile.e2e b/Dockerfile.e2e index cac2800..a8ad2af 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -3,7 +3,7 @@ FROM rust:bookworm as builder # A commit hash, tag, or branch -ARG GIT_COMMIT=16bb6887f84a299b5bbbe4c469337169849ce6ed +ARG GIT_COMMIT=390dffc7e3593711c1f55505d3308063a2039df6 ARG BLOCKCHAIN_REPO=https://github.com/stacks-network/stacks-blockchain.git ARG TARGETPLATFORM @@ -41,12 +41,12 @@ RUN < run.sh <<'EOM' STACKS_PID=$! function start_miner() { + DEFAULT_TIMEOUT=$(date -v+30S +%s) while true; do TX=$(bitcoin-cli listtransactions '*' 1 0 true) CONFS=$(echo "$TX" | jq '.[].confirmations') + NOW=$(date +%s) if [ "$CONFS" = "0" ]; then echo "Detected Stacks mining mempool tx, mining btc block..." bitcoin-cli generatetoaddress 1 $BTC_ADDR + DEFAULT_TIMEOUT=$(date -v+30S +%s) + elif [[ $NOW -ge $DEFAULT_TIMEOUT ]]; then + bitcoin-cli generatetoaddress 1 $BTC_ADDR + DEFAULT_TIMEOUT=$(date -v+30S +%s) fi sleep $MINE_INTERVAL done diff --git a/stacks-krypton-miner.toml b/stacks-krypton-miner.toml index 7667611..c715eb1 100644 --- a/stacks-krypton-miner.toml +++ b/stacks-krypton-miner.toml @@ -2,6 +2,8 @@ name = "krypton-node" rpc_bind = "0.0.0.0:20443" p2p_bind = "0.0.0.0:20444" +data_url = "http://127.0.0.1:20443" +p2p_address = "127.0.0.1:20443" working_dir = "$DATA_DIR" seed = "$MINER_SEED" @@ -10,15 +12,20 @@ local_peer_seed = "$MINER_SEED" miner = true use_test_genesis_chainstate = true pox_sync_sample_secs = 0 -wait_time_for_blocks = 0 -wait_time_for_microblocks = 50 +wait_time_for_blocks = 200 +wait_time_for_microblocks = 0 +mine_microblocks = false microblock_frequency = 1000 # mine_microblocks = true # max_microblocks = 10 [miner] -first_attempt_time_ms = 5000 -subsequent_attempt_time_ms = 5000 +min_tx_fee = 1 +first_attempt_time_ms = 180_000 +second_attempt_time_ms = 360_000 +wait_for_block_download = false +microblock_attempt_time_ms = 10 +self_signing_seed = 1 $REWARD_RECIPIENT_CONF [connection_options] @@ -32,10 +39,12 @@ public_ip_address = "1.1.1.1:1234" [burnchain] chain = "bitcoin" -mode = "neon" +mode = "nakamoto-neon" poll_time_secs = 1 -pox_prepare_length = 3 -pox_2_activation = $STACKS_POX2_HEIGHT +magic_bytes = "T3" +pox_prepare_length = 5 +pox_reward_length = 10 +burn_fee_cap = 20_000 ### bitcoind-regtest connection info peer_host = "$BITCOIN_PEER_HOST" From dec3fe536b3dbfba4f6a4d4239c373f7452462c5 Mon Sep 17 00:00:00 2001 From: Aaron Blankstein Date: Tue, 12 Dec 2023 19:39:50 -0600 Subject: [PATCH 03/29] okay, working-ish version --- Dockerfile.e2e | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/Dockerfile.e2e b/Dockerfile.e2e index a8ad2af..f352c11 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -100,7 +100,7 @@ ENV STACKS_24_HEIGHT=$STACKS_24_HEIGHT ARG STACKS_25_HEIGHT=112 ENV STACKS_25_HEIGHT=$STACKS_25_HEIGHT -ARG STACKS_30_HEIGHT=131 +ARG STACKS_30_HEIGHT=132 ENV STACKS_30_HEIGHT=$STACKS_30_HEIGHT ARG STACKS_PREHEAT_FINISH_HEIGHT=150 @@ -196,26 +196,21 @@ RUN < run.sh <<'EOM' STACKS_PID=$! function start_miner() { - DEFAULT_TIMEOUT=$(date -v+30S +%s) while true; do TX=$(bitcoin-cli listtransactions '*' 1 0 true) CONFS=$(echo "$TX" | jq '.[].confirmations') - NOW=$(date +%s) if [ "$CONFS" = "0" ]; then echo "Detected Stacks mining mempool tx, mining btc block..." bitcoin-cli generatetoaddress 1 $BTC_ADDR - DEFAULT_TIMEOUT=$(date -v+30S +%s) - elif [[ $NOW -ge $DEFAULT_TIMEOUT ]]; then - bitcoin-cli generatetoaddress 1 $BTC_ADDR - DEFAULT_TIMEOUT=$(date -v+30S +%s) fi sleep $MINE_INTERVAL done From f801252c9e4a7e1379ae0b9a3a1892db3880eb05 Mon Sep 17 00:00:00 2001 From: Aaron Blankstein Date: Tue, 12 Dec 2023 20:06:43 -0600 Subject: [PATCH 04/29] ah, better working version --- Dockerfile.e2e | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile.e2e b/Dockerfile.e2e index f352c11..088dda8 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -197,6 +197,7 @@ RUN < Date: Wed, 13 Dec 2023 13:21:24 +0100 Subject: [PATCH 05/29] build for release --- Dockerfile.e2e | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.e2e b/Dockerfile.e2e index 088dda8..3972083 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -41,7 +41,7 @@ RUN < Date: Wed, 13 Dec 2023 13:22:06 +0100 Subject: [PATCH 06/29] build for release --- Dockerfile.e2e | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.e2e b/Dockerfile.e2e index 3972083..69f4667 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -46,7 +46,7 @@ EOF FROM debian:bookworm-backports -COPY --from=builder /stacks/target/debug/stacks-node /usr/local/bin/ +COPY --from=builder /stacks/target/release/stacks-node /usr/local/bin/ COPY --from=btcpayserver/bitcoin:25.1 /usr/local/bin/bitcoind /usr/local/bin/bitcoin-cli /usr/local/bin/ ENV DEBIAN_FRONTEND noninteractive From 8f95e53d3795cc797092c62c5c2c9ff51bf1ecc9 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Wed, 13 Dec 2023 13:25:24 +0100 Subject: [PATCH 07/29] ci: bump stacks-node commit --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b25a19..360187a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: env: - STACKS_BLOCKCHAIN_COMMIT: f8ffd1dbe8990234391def4611b2611be9a3e4ba + STACKS_BLOCKCHAIN_COMMIT: 390dffc7e3593711c1f55505d3308063a2039df6 concurrency: group: ${{ github.workflow }}-${{ github.ref }} From 9c369a1cb630e2efe759b532698c53ffb8bfa4d6 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Sat, 16 Dec 2023 11:13:58 +0100 Subject: [PATCH 08/29] feat: epoch3 working with docker-compose --- .github/workflows/build.yml | 2 +- Dockerfile.btc | 6 ++--- Dockerfile.stacker | 34 ++++++++++++++++++++++++ Dockerfile.stacks-api | 2 +- Dockerfile.stacks-node | 8 +++--- docker-compose-miner.yml | 53 ++++++++++++++++++++++++++++++++++--- 6 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 Dockerfile.stacker diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 360187a..5657bbf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: env: - STACKS_BLOCKCHAIN_COMMIT: 390dffc7e3593711c1f55505d3308063a2039df6 + STACKS_BLOCKCHAIN_COMMIT: 8cffc3892f6451fdff525952a025f77482a8f728 concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/Dockerfile.btc b/Dockerfile.btc index f60b6ea..d581ebb 100644 --- a/Dockerfile.btc +++ b/Dockerfile.btc @@ -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"] diff --git a/Dockerfile.stacker b/Dockerfile.stacker new file mode 100644 index 0000000..b73aab7 --- /dev/null +++ b/Dockerfile.stacker @@ -0,0 +1,34 @@ +FROM node:18-bookworm as builder + +RUN apt-get update && apt-get install -y curl gettext-base jq + +WORKDIR /root + +# Create Stacking script +RUN npm init -y && npm i @stacks/stacking@6 +RUN < /root/stack.js <<'EOM' + const { StackingClient } = require('@stacks/stacking'); + const { StacksTestnet } = require('@stacks/network'); + console.log('Stacking with args:', process.argv.slice(2)); + const url = `http://${process.env.STACKS_CORE_RPC_HOST}:${process.env.STACKS_CORE_RPC_PORT}`; + const network = new StacksTestnet({ url }); + 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: '08c14a1eada0dd42b667b40f59f7c8dedb12113613448dc04980aea20b268ddb01', + fee: 1000, + nonce: 0, + }) + .then(r => console.log('Stacked', r)) + .catch(e => { + console.error('Error stacking', e); + process.exit(1); + }); +EOM +EOF + diff --git a/Dockerfile.stacks-api b/Dockerfile.stacks-api index 95749f4..746be2b 100644 --- a/Dockerfile.stacks-api +++ b/Dockerfile.stacks-api @@ -1,4 +1,4 @@ -FROM node:16-bullseye as builder +FROM node:18-bookworm as builder ARG GIT_COMMIT RUN test -n "$GIT_COMMIT" || (echo "GIT_COMMIT not set" && false) diff --git a/Dockerfile.stacks-node b/Dockerfile.stacks-node index 7691a26..122d896 100644 --- a/Dockerfile.stacks-node +++ b/Dockerfile.stacks-node @@ -1,4 +1,4 @@ -FROM rust:bullseye as builder +FROM rust:bookworm as builder # TODO: is there a built-in required arg syntax? ARG GIT_COMMIT @@ -18,13 +18,13 @@ RUN git init && \ RUN cargo build --package stacks-node --bin stacks-node --release -FROM debian:bullseye-backports +FROM debian:bookworm 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 -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 diff --git a/docker-compose-miner.yml b/docker-compose-miner.yml index 8faf9a5..42bc31f 100644 --- a/docker-compose-miner.yml +++ b/docker-compose-miner.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT feat/naka-neon + - &STACKS_BLOCKCHAIN_COMMIT 8cffc3892f6451fdff525952a025f77482a8f728 - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 @@ -17,7 +17,7 @@ x-common-vars: - &STACKS_23_HEIGHT ${STACKS_23_HEIGHT:-106} - &STACKS_24_HEIGHT ${STACKS_24_HEIGHT:-107} - &STACKS_25_HEIGHT ${STACKS_25_HEIGHT:-108} - - &STACKS_30_HEIGHT ${STACKS_30_HEIGHT:-999999} # do not boot into epoch3.0 for now (it doesn't work yet) + - &STACKS_30_HEIGHT ${STACKS_30_HEIGHT:-125} - &REWARD_RECIPIENT ${REWARD_RECIPIENT:-STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN} # priv: 6ad9cadb42d4edbfbe0c5bfb3b8a4125ddced021c4174f829b714ccbf527f02001 services: @@ -67,7 +67,7 @@ services: trap "exit" INT TERM trap "kill 0" EXIT bitcoin-cli -rpcconnect=bitcoind -rpcwait getmininginfo - bitcoin-cli -rpcconnect=bitcoind createwallet "" + bitcoin-cli -rpcconnect=bitcoind -named createwallet wallet_name="" descriptors=false bitcoin-cli -rpcconnect=bitcoind importaddress $${BTC_ADDR} "" false bitcoin-cli -rpcconnect=bitcoind generatetoaddress $${INIT_BLOCKS} $${BTC_ADDR} while true; do @@ -132,9 +132,54 @@ services: mkdir -p $${DATA_DIR} rm -rf $${DATA_DIR}/* envsubst < config.toml.in > config.toml - # bitcoin-cli -rpcwait -rpcconnect=bitcoind getmininginfo + bitcoin-cli -rpcwait -rpcconnect=bitcoind getmininginfo exec stacks-node start --config=config.toml + + stacker: + networks: + - stacks + build: + context: . + dockerfile: Dockerfile.stacker + environment: + STACKS_CORE_RPC_HOST: stacks-node-miner + STACKS_CORE_RPC_PORT: 20443 + depends_on: + - stacks-node-miner + entrypoint: + - /bin/bash + - -c + - | + SENT_STACKING=0 + while true; do + POX_STATE=$$(curl -s http://stacks-node-miner:20443/v2/pox) || { + echo "Curl /v2/pox failed, sleeping for 2 seconds..." + sleep 2s + continue + } + INFO_STATE=$$(curl -s http://stacks-node-miner:20443/v2/info) || { + echo "Curl /v2/info failed, sleeping for 2 seconds..." + sleep 2s + continue + } + STACKS_HEIGHT=$$(echo $${INFO_STATE} | jq -r '.stacks_tip_height') + POX_CONTRACT=$$(echo $${POX_STATE} | jq -r '.contract_id') + BURN_HEIGHT=$$(echo $${POX_STATE} | jq -r '.current_burnchain_block_height') + echo "POX check, stacks=$$STACKS_HEIGHT, burn=$$BURN_HEIGHT, $$POX_CONTRACT" + if [ "$$POX_CONTRACT" = "ST000000000000000000002AMW42H.pox-4" ] && [ "$$SENT_STACKING" = "0" ]; then + SENT_STACKING=1 + echo "Stack STX tx for epoch3.0 transition" + echo "$$POX_STATE" | jq '.' + echo "$$INFO_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 + sleep 2s + done + ################################## ##### UNCOMMENT IF USING API ##### ################################## From 4551d1322c90160742078e230d30a4750824034d Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Sat, 16 Dec 2023 12:37:54 +0100 Subject: [PATCH 09/29] fix: add timeout to bitcoin mining --- Dockerfile.stacker | 20 ++++++++++---------- docker-compose-miner.yml | 31 +++++++++++++++++++++++-------- stacks-krypton-miner.toml | 2 +- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Dockerfile.stacker b/Dockerfile.stacker index b73aab7..1d5c6b5 100644 --- a/Dockerfile.stacker +++ b/Dockerfile.stacker @@ -10,21 +10,21 @@ RUN < /root/stack.js <<'EOM' const { StackingClient } = require('@stacks/stacking'); const { StacksTestnet } = require('@stacks/network'); - console.log('Stacking with args:', process.argv.slice(2)); const url = `http://${process.env.STACKS_CORE_RPC_HOST}:${process.env.STACKS_CORE_RPC_PORT}`; const network = new StacksTestnet({ url }); - const address = 'ST18MDW2PDTBSCR1ACXYRJP2JX70FWNM6YY2VX4SS'; - const client = new StackingClient(address, network); - client.stack({ + const client = new StackingClient(process.env.STACKS_ADDR, network); + const stackingArgs = { + poxAddress: process.env.POX_ADDR, + privateKey: process.env.STACKS_PRIVKEY, amountMicroStx: parseInt(process.argv[2]), burnBlockHeight: parseInt(process.argv[3]), - poxAddress: 'mvuYDknzDtPgGqm2GnbAbmGMLwiyW3AwFP', - cycles: 12, - privateKey: '08c14a1eada0dd42b667b40f59f7c8dedb12113613448dc04980aea20b268ddb01', + cycles: parseInt(process.argv[4]), fee: 1000, - nonce: 0, - }) - .then(r => console.log('Stacked', r)) + // nonce: 0, + }; + console.log('Stacking with args:', stackingArgs); + client.stack(stackingArgs) + .then(r => console.log('Stacking tx result', r)) .catch(e => { console.error('Error stacking', e); process.exit(1); diff --git a/docker-compose-miner.yml b/docker-compose-miner.yml index 42bc31f..e526ba8 100644 --- a/docker-compose-miner.yml +++ b/docker-compose-miner.yml @@ -70,12 +70,18 @@ services: bitcoin-cli -rpcconnect=bitcoind -named createwallet wallet_name="" descriptors=false bitcoin-cli -rpcconnect=bitcoind importaddress $${BTC_ADDR} "" false bitcoin-cli -rpcconnect=bitcoind generatetoaddress $${INIT_BLOCKS} $${BTC_ADDR} + DEFAULT_TIMEOUT=$$(($$(date +%s) + 30)) while true; do TX=$$(bitcoin-cli -rpcconnect=bitcoind 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 -rpcconnect=bitcoind generatetoaddress 1 "$${BTC_ADDR}" + DEFAULT_TIMEOUT=$$(($$(date +%s) + 30)) else echo "No Stacks mining tx detected" fi @@ -145,6 +151,9 @@ services: environment: STACKS_CORE_RPC_HOST: stacks-node-miner STACKS_CORE_RPC_PORT: 20443 + STACKS_ADDR: ST18MDW2PDTBSCR1ACXYRJP2JX70FWNM6YY2VX4SS + STACKS_PRIVKEY: 08c14a1eada0dd42b667b40f59f7c8dedb12113613448dc04980aea20b268ddb01 + POX_ADDR: mvuYDknzDtPgGqm2GnbAbmGMLwiyW3AwFP depends_on: - stacks-node-miner entrypoint: @@ -163,18 +172,24 @@ services: sleep 2s continue } - STACKS_HEIGHT=$$(echo $${INFO_STATE} | jq -r '.stacks_tip_height') - POX_CONTRACT=$$(echo $${POX_STATE} | jq -r '.contract_id') - BURN_HEIGHT=$$(echo $${POX_STATE} | jq -r '.current_burnchain_block_height') - echo "POX check, stacks=$$STACKS_HEIGHT, burn=$$BURN_HEIGHT, $$POX_CONTRACT" + ACCOUNT_STATE=$$(curl -s http://stacks-node-miner:20443/v2/accounts/$${STACKS_ADDR}?proof=0) || { + echo "Curl /v2/accounts/$$STACKS_ADDR failed, sleeping for 2 seconds..." + sleep 2s + continue + } + STACKS_HEIGHT=$$(echo $$INFO_STATE | jq -r '.stacks_tip_height') + POX_CONTRACT=$$(echo $$POX_STATE | jq -r '.contract_id') + BURN_HEIGHT=$$(echo $$POX_STATE | jq -r '.current_burnchain_block_height') + LOCKED=$$(echo $$ACCOUNT_STATE | jq -r '.locked') + echo "POX check, stacks=$$STACKS_HEIGHT, burn=$$BURN_HEIGHT, locked=$$LOCKED, $$POX_CONTRACT" if [ "$$POX_CONTRACT" = "ST000000000000000000002AMW42H.pox-4" ] && [ "$$SENT_STACKING" = "0" ]; then SENT_STACKING=1 echo "Stack STX tx for epoch3.0 transition" echo "$$POX_STATE" | jq '.' echo "$$INFO_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 + BURN_HEIGHT=$$(echo $$POX_STATE | jq '.current_burnchain_block_height') + node /root/stack.js $$MIN_STACKING_AMOUNT $$BURN_HEIGHT 4 sleep 5s fi sleep 2s diff --git a/stacks-krypton-miner.toml b/stacks-krypton-miner.toml index c715eb1..662ee1f 100644 --- a/stacks-krypton-miner.toml +++ b/stacks-krypton-miner.toml @@ -12,7 +12,7 @@ local_peer_seed = "$MINER_SEED" miner = true use_test_genesis_chainstate = true pox_sync_sample_secs = 0 -wait_time_for_blocks = 200 +wait_time_for_blocks = 0 wait_time_for_microblocks = 0 mine_microblocks = false microblock_frequency = 1000 From 0e7f57efb419094fbc4236bdf4991b8cc91fdd2d Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Sat, 16 Dec 2023 16:32:40 +0100 Subject: [PATCH 10/29] feat: robust stacking script --- .gitignore | 2 + Dockerfile.stacker | 31 +-------- ...er-compose-miner.yml => docker-compose.yml | 42 +----------- stacking/package.json | 13 ++++ stacking/stacking.js | 67 +++++++++++++++++++ 5 files changed, 86 insertions(+), 69 deletions(-) create mode 100644 .gitignore rename docker-compose-miner.yml => docker-compose.yml (78%) create mode 100644 stacking/package.json create mode 100644 stacking/stacking.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef5738c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +stacking/node_modules +package-lock.json diff --git a/Dockerfile.stacker b/Dockerfile.stacker index 1d5c6b5..ef6f0bf 100644 --- a/Dockerfile.stacker +++ b/Dockerfile.stacker @@ -3,32 +3,7 @@ FROM node:18-bookworm as builder RUN apt-get update && apt-get install -y curl gettext-base jq WORKDIR /root +COPY ./stacking/stacking.js ./stacking/package.json /root/ +RUN npm i -# Create Stacking script -RUN npm init -y && npm i @stacks/stacking@6 -RUN < /root/stack.js <<'EOM' - const { StackingClient } = require('@stacks/stacking'); - const { StacksTestnet } = require('@stacks/network'); - const url = `http://${process.env.STACKS_CORE_RPC_HOST}:${process.env.STACKS_CORE_RPC_PORT}`; - const network = new StacksTestnet({ url }); - const client = new StackingClient(process.env.STACKS_ADDR, network); - const stackingArgs = { - poxAddress: process.env.POX_ADDR, - privateKey: process.env.STACKS_PRIVKEY, - amountMicroStx: parseInt(process.argv[2]), - burnBlockHeight: parseInt(process.argv[3]), - cycles: parseInt(process.argv[4]), - fee: 1000, - // nonce: 0, - }; - console.log('Stacking with args:', stackingArgs); - client.stack(stackingArgs) - .then(r => console.log('Stacking tx result', r)) - .catch(e => { - console.error('Error stacking', e); - process.exit(1); - }); -EOM -EOF - +CMD ["node", "/root/stacking.js"] \ No newline at end of file diff --git a/docker-compose-miner.yml b/docker-compose.yml similarity index 78% rename from docker-compose-miner.yml rename to docker-compose.yml index e526ba8..8dd5f0b 100644 --- a/docker-compose-miner.yml +++ b/docker-compose.yml @@ -151,49 +151,9 @@ services: environment: STACKS_CORE_RPC_HOST: stacks-node-miner STACKS_CORE_RPC_PORT: 20443 - STACKS_ADDR: ST18MDW2PDTBSCR1ACXYRJP2JX70FWNM6YY2VX4SS - STACKS_PRIVKEY: 08c14a1eada0dd42b667b40f59f7c8dedb12113613448dc04980aea20b268ddb01 - POX_ADDR: mvuYDknzDtPgGqm2GnbAbmGMLwiyW3AwFP + STACKING_KEYS: 08c14a1eada0dd42b667b40f59f7c8dedb12113613448dc04980aea20b268ddb01,ce109fee08860bb16337c76647dcbc02df0c06b455dd69bcf30af74d4eedd19301,e75dcb66f84287eaf347955e94fa04337298dbd95aa0dbb985771104ef1913db01 depends_on: - stacks-node-miner - entrypoint: - - /bin/bash - - -c - - | - SENT_STACKING=0 - while true; do - POX_STATE=$$(curl -s http://stacks-node-miner:20443/v2/pox) || { - echo "Curl /v2/pox failed, sleeping for 2 seconds..." - sleep 2s - continue - } - INFO_STATE=$$(curl -s http://stacks-node-miner:20443/v2/info) || { - echo "Curl /v2/info failed, sleeping for 2 seconds..." - sleep 2s - continue - } - ACCOUNT_STATE=$$(curl -s http://stacks-node-miner:20443/v2/accounts/$${STACKS_ADDR}?proof=0) || { - echo "Curl /v2/accounts/$$STACKS_ADDR failed, sleeping for 2 seconds..." - sleep 2s - continue - } - STACKS_HEIGHT=$$(echo $$INFO_STATE | jq -r '.stacks_tip_height') - POX_CONTRACT=$$(echo $$POX_STATE | jq -r '.contract_id') - BURN_HEIGHT=$$(echo $$POX_STATE | jq -r '.current_burnchain_block_height') - LOCKED=$$(echo $$ACCOUNT_STATE | jq -r '.locked') - echo "POX check, stacks=$$STACKS_HEIGHT, burn=$$BURN_HEIGHT, locked=$$LOCKED, $$POX_CONTRACT" - if [ "$$POX_CONTRACT" = "ST000000000000000000002AMW42H.pox-4" ] && [ "$$SENT_STACKING" = "0" ]; then - SENT_STACKING=1 - echo "Stack STX tx for epoch3.0 transition" - echo "$$POX_STATE" | jq '.' - echo "$$INFO_STATE" | jq '.' - MIN_STACKING_AMOUNT="8500000000000000" - BURN_HEIGHT=$$(echo $$POX_STATE | jq '.current_burnchain_block_height') - node /root/stack.js $$MIN_STACKING_AMOUNT $$BURN_HEIGHT 4 - sleep 5s - fi - sleep 2s - done ################################## ##### UNCOMMENT IF USING API ##### diff --git a/stacking/package.json b/stacking/package.json new file mode 100644 index 0000000..830d00e --- /dev/null +++ b/stacking/package.json @@ -0,0 +1,13 @@ +{ + "name": "stacking", + "version": "1.0.0", + "description": "", + "main": "stacking.js", + "scripts": {}, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@stacks/stacking": "^6.10.0" + } +} diff --git a/stacking/stacking.js b/stacking/stacking.js new file mode 100644 index 0000000..4ec752d --- /dev/null +++ b/stacking/stacking.js @@ -0,0 +1,67 @@ +const { StackingClient } = require('@stacks/stacking'); +const { StacksTestnet } = require('@stacks/network'); +const { getAddressFromPrivateKey, TransactionVersion } = require('@stacks/transactions'); +const { getPublicKeyFromPrivate, publicKeyToBtcAddress } = require('@stacks/encryption'); + +const stackingInterval = process.env.STACKING_INTERVAL ?? 2; +const postTxWait = process.env.POST_TX_WAIT ?? 10; +const url = `http://${process.env.STACKS_CORE_RPC_HOST}:${process.env.STACKS_CORE_RPC_PORT}`; +const network = new StacksTestnet({ url }); + +const accounts = process.env.STACKING_KEYS.split(',').map(privKey => { + const pubKey = getPublicKeyFromPrivate(privKey); + const stxAddress = getAddressFromPrivateKey(privKey, TransactionVersion.Testnet); + return { + privKey, pubKey, stxAddress, + btcAddr: publicKeyToBtcAddress(pubKey), + client: new StackingClient(stxAddress, network), + }; +}); + +async function run() { + const poxInfo = await accounts[0].client.getPoxInfo(); + if (!poxInfo.contract_id.endsWith('.pox-4')) { + console.log(`Pox contract is not .pox-4, skipping stacking (contract=${poxInfo.contract_id})`); + return; + } + const nextCycleStx = poxInfo.next_cycle.stacked_ustx; + const minStx = poxInfo.next_cycle.min_threshold_ustx; + if (nextCycleStx >= minStx) { + console.log(`Next cycle has enough stacked, skipping stacking (stacked=${nextCycleStx}, min=${minStx})`); + return; + } + let account; + for (const a of accounts) { + const lockedHeight = await a.client.getAccountBalanceLocked(); + if (lockedHeight === 0n) { + account = a; + break; + } + } + if (!account) { + console.log(`No unlocked account available for stacking`); + return; + } + const stackingArgs = { + poxAddress: account.btcAddr, + privateKey: account.privKey, + amountMicroStx: minStx, + burnBlockHeight: poxInfo.current_burnchain_block_height, + cycles: 1, + fee: 1000, + }; + console.log('Stacking with args:', { addr: account.stxAddress, ...stackingArgs }); + const stackResult = await account.client.stack(stackingArgs) + console.log('Stacking tx result', stackResult); + await new Promise(resolve => setTimeout(resolve, postTxWait * 1000)); +} + +async function loop() { + try { + await run(); + } catch (e) { + console.error('Error running stacking:', e); + } + setTimeout(loop, stackingInterval * 1000); +} +loop(); From 658bb90195f76844a6a9c2aca1524dc5e72a4fb7 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Sun, 17 Dec 2023 10:57:39 +0100 Subject: [PATCH 11/29] chore: re-enable stacks-api --- Dockerfile.stacks-api | 3 +- docker-compose.yml | 108 +++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 57 deletions(-) diff --git a/Dockerfile.stacks-api b/Dockerfile.stacks-api index 746be2b..9d32a7b 100644 --- a/Dockerfile.stacks-api +++ b/Dockerfile.stacks-api @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml index 8dd5f0b..845c217 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -89,7 +89,7 @@ services: wait || exit 0 done - stacks-node-miner: + stacks-node: networks: - stacks build: @@ -109,7 +109,7 @@ services: environment: # STACKS_LOG_TRACE: 1 # uncomment for trace logging # STACKS_LOG_DEBUG: 1 - # STACKS_EVENT_OBSERVER: stacks-api:3700 # uncomment if using API + STACKS_EVENT_OBSERVER: stacks-api:3700 DATA_DIR: /chainstate/stacks-blockchain-miner-data BITCOIN_PEER_HOST: bitcoind BITCOIN_PEER_PORT: *BITCOIN_PEER_PORT @@ -149,64 +149,62 @@ services: context: . dockerfile: Dockerfile.stacker environment: - STACKS_CORE_RPC_HOST: stacks-node-miner + STACKS_CORE_RPC_HOST: stacks-node STACKS_CORE_RPC_PORT: 20443 STACKING_KEYS: 08c14a1eada0dd42b667b40f59f7c8dedb12113613448dc04980aea20b268ddb01,ce109fee08860bb16337c76647dcbc02df0c06b455dd69bcf30af74d4eedd19301,e75dcb66f84287eaf347955e94fa04337298dbd95aa0dbb985771104ef1913db01 depends_on: - - stacks-node-miner + - stacks-node - ################################## - ##### UNCOMMENT IF USING API ##### - ################################## - # postgres: - # image: "postgres:15" - # ports: - # - "5490:5490" - # volumes: - # - chainstate:/chainstate - # environment: - # POSTGRES_USER: postgres - # POSTGRES_PASSWORD: postgres - # POSTGRES_DB: stacks_blockchain_api - # PGPORT: 5490 - # PGDATA: /chainstate/pg-data + postgres: + networks: + - stacks + image: "postgres:15" + ports: + - "5490:5490" + volumes: + - chainstate:/chainstate + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: stacks_blockchain_api + PGPORT: 5490 + PGDATA: /chainstate/pg-data - # stacks-api: - # build: - # context: . - # dockerfile: Dockerfile.stacks-api - # args: - # GIT_COMMIT: 4a332f353ee10802fa7b04e888b32e54d010a69d - # depends_on: - # - postgres - # ports: - # - "3999:3999" - # expose: - # - "3700" - # environment: - # NODE_ENVIRONMENT: production - # STACKS_API_LOG_LEVEL: debug - # STACKS_CHAIN_ID: "0x80000000" - # STACKS_BLOCKCHAIN_API_HOST: "0.0.0.0" - # STACKS_BLOCKCHAIN_API_PORT: 3999 - # STACKS_CORE_EVENT_HOST: "0.0.0.0" - # STACKS_CORE_EVENT_PORT: 3700 - # PG_HOST: postgres - # PG_PORT: 5490 - # PG_USER: postgres - # PG_PASSWORD: postgres - # PG_DATABASE: stacks_blockchain_api - # PG_SCHEMA: public - # STACKS_CORE_RPC_HOST: stacks-node - # STACKS_CORE_RPC_PORT: 20443 - # BTC_RPC_HOST: http://bitcoind - # BTC_RPC_PORT: 18443 - # BTC_RPC_USER: btc - # BTC_RPC_PW: btc - # BTC_FAUCET_PK: *MINER_SEED - ################################## - ##### UNCOMMENT IF USING API ##### - ################################## + stacks-api: + networks: + - stacks + build: + context: . + dockerfile: Dockerfile.stacks-api + args: + GIT_COMMIT: 94687ae0b393c31c7993174380c91566c62d7fc5 + depends_on: + - postgres + ports: + - "3999:3999" + expose: + - "3700" + environment: + NODE_ENVIRONMENT: production + STACKS_API_LOG_LEVEL: debug + STACKS_CHAIN_ID: "0x80000000" + STACKS_BLOCKCHAIN_API_HOST: "0.0.0.0" + STACKS_BLOCKCHAIN_API_PORT: 3999 + STACKS_CORE_EVENT_HOST: "0.0.0.0" + STACKS_CORE_EVENT_PORT: 3700 + PG_HOST: postgres + PG_PORT: 5490 + PG_USER: postgres + PG_PASSWORD: postgres + PG_DATABASE: stacks_blockchain_api + PG_SCHEMA: public + STACKS_CORE_RPC_HOST: stacks-node + STACKS_CORE_RPC_PORT: 20443 + BTC_RPC_HOST: http://bitcoind + BTC_RPC_PORT: 18443 + BTC_RPC_USER: btc + BTC_RPC_PW: btc + BTC_FAUCET_PK: *MINER_SEED networks: stacks: From 0bc6dc8588c62d3e8bbce37b1356008cdb4fcfe4 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Wed, 20 Dec 2023 16:06:50 +0100 Subject: [PATCH 12/29] bump stacks-core next branch, include tx-broadcasting script --- Dockerfile.tx-broadcaster | 9 +++++++ docker-compose.yml | 16 +++++++++-- stacking/tx-broadcaster.js | 54 ++++++++++++++++++++++++++++++++++++++ stacks-krypton-miner.toml | 10 +++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.tx-broadcaster create mode 100644 stacking/tx-broadcaster.js diff --git a/Dockerfile.tx-broadcaster b/Dockerfile.tx-broadcaster new file mode 100644 index 0000000..391d9cd --- /dev/null +++ b/Dockerfile.tx-broadcaster @@ -0,0 +1,9 @@ +FROM node:18-bookworm as builder + +RUN apt-get update && apt-get install -y curl gettext-base jq + +WORKDIR /root +COPY ./stacking/tx-broadcaster.js ./stacking/package.json /root/ +RUN npm i + +CMD ["node", "/root/tx-broadcaster.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 845c217..f5670e4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 8cffc3892f6451fdff525952a025f77482a8f728 + - &STACKS_BLOCKCHAIN_COMMIT 2789b184ef301734f0af2132fac4b303ef0f9a7c - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 @@ -141,7 +141,6 @@ services: bitcoin-cli -rpcwait -rpcconnect=bitcoind getmininginfo exec stacks-node start --config=config.toml - stacker: networks: - stacks @@ -155,6 +154,19 @@ services: depends_on: - stacks-node + tx-broadcaster: + networks: + - stacks + build: + context: . + dockerfile: Dockerfile.tx-broadcaster + environment: + STACKS_CORE_RPC_HOST: stacks-node + STACKS_CORE_RPC_PORT: 20443 + ACCOUNT_KEYS: 0d2f965b472a82efd5a96e6513c8b9f7edc725d5c96c7d35d6c722cedeb80d1b01,975b251dd7809469ef0c26ec3917971b75c51cd73a022024df4bf3b232cc2dc001,c71700b07d520a8c9731e4d0f095aa6efb91e16e25fb27ce2b72e7b698f8127a01 + depends_on: + - stacks-node + postgres: networks: - stacks diff --git a/stacking/tx-broadcaster.js b/stacking/tx-broadcaster.js new file mode 100644 index 0000000..0fbcbf8 --- /dev/null +++ b/stacking/tx-broadcaster.js @@ -0,0 +1,54 @@ +const { StacksTestnet } = require('@stacks/network'); +const { TransactionVersion, getAddressFromPrivateKey, getNonce, makeSTXTokenTransfer, broadcastTransaction } = require('@stacks/transactions'); + +const broadcastInterval = process.env.BROADCAST_INTERVAL ?? 2; +const postTxWait = process.env.POST_TX_WAIT ?? 2; +const url = `http://${process.env.STACKS_CORE_RPC_HOST}:${process.env.STACKS_CORE_RPC_PORT}`; +const network = new StacksTestnet({ url }); + +const accounts = process.env.ACCOUNT_KEYS.split(',').map(privKey => ({ + privKey, + stxAddress: getAddressFromPrivateKey(privKey, TransactionVersion.Testnet), +})); + +async function run() { + const accountNonces = await Promise.all(accounts.map(async (account) => { + const nonce = await getNonce(account.stxAddress, network); + return { ...account, nonce }; + })); + + // Send from account with lowest nonce + accountNonces.sort((a, b) => Number(a.nonce) - Number(b.nonce)); + const sender = accountNonces[0]; + const recipient = accountNonces[1]; + + console.log(`Sending stx-transfer from ${sender.stxAddress} (nonce=${sender.nonce}) to ${recipient.stxAddress}`); + + const tx = await makeSTXTokenTransfer({ + recipient: recipient.stxAddress, + amount: 1000, + senderKey: sender.privKey, + network, + nonce: sender.nonce, + fee: 300, + }); + + const broadcastResult = await broadcastTransaction(tx, network); + if (broadcastResult.error) { + console.error('Error broadcasting stx-transfer', broadcastResult); + } else { + console.log(`Broadcast stx-transfer tx=${broadcastResult.txid}`); + } + + await new Promise(resolve => setTimeout(resolve, postTxWait * 1000)); +} + +async function loop() { + try { + await run(); + } catch (e) { + console.error('Error submitting stx-transfer tx:', e); + } + setTimeout(loop, broadcastInterval * 1000); +} +loop(); diff --git a/stacks-krypton-miner.toml b/stacks-krypton-miner.toml index 662ee1f..65bfac4 100644 --- a/stacks-krypton-miner.toml +++ b/stacks-krypton-miner.toml @@ -107,6 +107,16 @@ address = "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR" amount = 10000000000000000 # secretKey = "c71700b07d520a8c9731e4d0f095aa6efb91e16e25fb27ce2b72e7b698f8127a01" +[[ustx_balance]] +address = "ST2PGGD0ZXAWEMY4EZ025RD1X47EEVH287SQKA8BC" +amount = 10000000000000000 +# secretKey = "975b251dd7809469ef0c26ec3917971b75c51cd73a022024df4bf3b232cc2dc001" + +[[ustx_balance]] +address = "ST29V10QEA7BRZBTWRFC4M70NJ4J6RJB5P1C6EE84" +amount = 10000000000000000 +# secretKey = "0d2f965b472a82efd5a96e6513c8b9f7edc725d5c96c7d35d6c722cedeb80d1b01" + [[ustx_balance]] address = "STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP" amount = 10000000000000000 From 6913eb49361d77617c0ed8133b04faa4d4054936 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Thu, 21 Dec 2023 14:08:05 +0100 Subject: [PATCH 13/29] chore: bump stacks-node with stability fixes --- .github/workflows/build.yml | 2 +- Dockerfile.e2e | 2 +- docker-compose.yml | 2 +- stacking/stacking.js | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5657bbf..18545b7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: env: - STACKS_BLOCKCHAIN_COMMIT: 8cffc3892f6451fdff525952a025f77482a8f728 + STACKS_BLOCKCHAIN_COMMIT: d0882a7ac6bfdd970b1366ead6cc725d79c8f91d concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/Dockerfile.e2e b/Dockerfile.e2e index 69f4667..74bc0d6 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -3,7 +3,7 @@ FROM rust:bookworm as builder # A commit hash, tag, or branch -ARG GIT_COMMIT=390dffc7e3593711c1f55505d3308063a2039df6 +ARG GIT_COMMIT=d0882a7ac6bfdd970b1366ead6cc725d79c8f91d ARG BLOCKCHAIN_REPO=https://github.com/stacks-network/stacks-blockchain.git ARG TARGETPLATFORM diff --git a/docker-compose.yml b/docker-compose.yml index f5670e4..90e415f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 2789b184ef301734f0af2132fac4b303ef0f9a7c + - &STACKS_BLOCKCHAIN_COMMIT d0882a7ac6bfdd970b1366ead6cc725d79c8f91d - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 diff --git a/stacking/stacking.js b/stacking/stacking.js index 4ec752d..1beee28 100644 --- a/stacking/stacking.js +++ b/stacking/stacking.js @@ -25,7 +25,9 @@ async function run() { return; } const nextCycleStx = poxInfo.next_cycle.stacked_ustx; - const minStx = poxInfo.next_cycle.min_threshold_ustx; + let minStx = poxInfo.next_cycle.min_threshold_ustx; + // Bump min threshold by 50% to avoid getting stuck if threshold increases + minStx = Math.floor(minStx * 1.5); if (nextCycleStx >= minStx) { console.log(`Next cycle has enough stacked, skipping stacking (stacked=${nextCycleStx}, min=${minStx})`); return; From eb4b12fbe3f08f6826b6d5cbae1ab77e9af79176 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Thu, 21 Dec 2023 14:53:54 +0100 Subject: [PATCH 14/29] feat: slow down bitcoin block mining in epoch3 --- docker-compose.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 90e415f..24e8c04 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ x-common-vars: - &BITCOIN_RPC_USER btc - &BITCOIN_RPC_PASS btc - &MINE_INTERVAL ${MINE_INTERVAL:-0.5s} + - &MINE_INTERVAL_EPOCH3 ${MINE_INTERVAL_EPOCH3:-60s} - &STACKS_20_HEIGHT ${STACKS_20_HEIGHT:-101} - &STACKS_2_05_HEIGHT ${STACKS_2_05_HEIGHT:-102} - &STACKS_21_HEIGHT ${STACKS_21_HEIGHT:-103} @@ -58,7 +59,9 @@ services: environment: BTC_ADDR: *BTC_ADDR MINE_INTERVAL: *MINE_INTERVAL + MINE_INTERVAL_EPOCH3: *MINE_INTERVAL_EPOCH3 INIT_BLOCKS: 101 + STACKS_30_HEIGHT: *STACKS_30_HEIGHT entrypoint: - /bin/bash - -c @@ -85,7 +88,14 @@ services: else echo "No Stacks mining tx detected" fi - sleep $${MINE_INTERVAL} & + + SLEEP_DURATION=$${MINE_INTERVAL} + BLOCK_HEIGHT=$$(bitcoin-cli -rpcconnect=bitcoind getblockcount) + if [ "$${BLOCK_HEIGHT}" -gt $$(( $${STACKS_30_HEIGHT} + 5 )) ]; then + echo "In Epoch3, sleeping for $${MINE_INTERVAL_EPOCH3} seconds..." + SLEEP_DURATION=$${MINE_INTERVAL_EPOCH3} + fi + sleep $${SLEEP_DURATION} & wait || exit 0 done @@ -189,7 +199,7 @@ services: context: . dockerfile: Dockerfile.stacks-api args: - GIT_COMMIT: 94687ae0b393c31c7993174380c91566c62d7fc5 + GIT_COMMIT: db859ae980368db22b9d1c4c7096918d5f7f4c4b depends_on: - postgres ports: From 74ce0fb8e3cb653e926c806dab7cd59eccc0ad0e Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Thu, 21 Dec 2023 15:46:13 +0100 Subject: [PATCH 15/29] chore: stack for multiple cycles to reduce pox activation flakiness --- docker-compose.yml | 3 ++- stacking/stacking.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 24e8c04..83178ed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ x-common-vars: - &BITCOIN_RPC_USER btc - &BITCOIN_RPC_PASS btc - &MINE_INTERVAL ${MINE_INTERVAL:-0.5s} - - &MINE_INTERVAL_EPOCH3 ${MINE_INTERVAL_EPOCH3:-60s} + - &MINE_INTERVAL_EPOCH3 ${MINE_INTERVAL_EPOCH3:-600s} # 10 minute bitcoin block times in epoch 3 - &STACKS_20_HEIGHT ${STACKS_20_HEIGHT:-101} - &STACKS_2_05_HEIGHT ${STACKS_2_05_HEIGHT:-102} - &STACKS_21_HEIGHT ${STACKS_21_HEIGHT:-103} @@ -160,6 +160,7 @@ services: environment: STACKS_CORE_RPC_HOST: stacks-node STACKS_CORE_RPC_PORT: 20443 + STACKING_CYCLES: 2 STACKING_KEYS: 08c14a1eada0dd42b667b40f59f7c8dedb12113613448dc04980aea20b268ddb01,ce109fee08860bb16337c76647dcbc02df0c06b455dd69bcf30af74d4eedd19301,e75dcb66f84287eaf347955e94fa04337298dbd95aa0dbb985771104ef1913db01 depends_on: - stacks-node diff --git a/stacking/stacking.js b/stacking/stacking.js index 1beee28..e0ea730 100644 --- a/stacking/stacking.js +++ b/stacking/stacking.js @@ -5,6 +5,7 @@ const { getPublicKeyFromPrivate, publicKeyToBtcAddress } = require('@stacks/encr const stackingInterval = process.env.STACKING_INTERVAL ?? 2; const postTxWait = process.env.POST_TX_WAIT ?? 10; +const stackingCycles = process.env.STACKING_CYCLES ?? 1; const url = `http://${process.env.STACKS_CORE_RPC_HOST}:${process.env.STACKS_CORE_RPC_PORT}`; const network = new StacksTestnet({ url }); @@ -49,7 +50,7 @@ async function run() { privateKey: account.privKey, amountMicroStx: minStx, burnBlockHeight: poxInfo.current_burnchain_block_height, - cycles: 1, + cycles: stackingCycles, fee: 1000, }; console.log('Stacking with args:', { addr: account.stxAddress, ...stackingArgs }); From 3d6541251eb63deeab314c61590479132ffba262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20C=C3=A1rdenas?= Date: Tue, 23 Jan 2024 10:09:40 -0600 Subject: [PATCH 16/29] update stacks core commit hash for next (#28) --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 83178ed..9fe78e3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT d0882a7ac6bfdd970b1366ead6cc725d79c8f91d + - &STACKS_BLOCKCHAIN_COMMIT 951becfd97bd865caa6d78377ac936ba12af555a - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 From 269b14013a81884fdbff7a5a28e4a9dac620c385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20C=C3=A1rdenas?= Date: Thu, 25 Jan 2024 14:15:56 -0600 Subject: [PATCH 17/29] fix: stacking with latest version of stack-stx (#30) --- stacking/package.json | 2 +- stacking/stacking.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stacking/package.json b/stacking/package.json index 830d00e..9783a07 100644 --- a/stacking/package.json +++ b/stacking/package.json @@ -8,6 +8,6 @@ "author": "", "license": "ISC", "dependencies": { - "@stacks/stacking": "^6.10.0" + "@stacks/stacking": "6.11.2-pr.3560789.0" } } diff --git a/stacking/stacking.js b/stacking/stacking.js index e0ea730..e14d78d 100644 --- a/stacking/stacking.js +++ b/stacking/stacking.js @@ -2,6 +2,7 @@ const { StackingClient } = require('@stacks/stacking'); const { StacksTestnet } = require('@stacks/network'); const { getAddressFromPrivateKey, TransactionVersion } = require('@stacks/transactions'); const { getPublicKeyFromPrivate, publicKeyToBtcAddress } = require('@stacks/encryption'); +const crypto = require('crypto'); const stackingInterval = process.env.STACKING_INTERVAL ?? 2; const postTxWait = process.env.POST_TX_WAIT ?? 10; @@ -15,6 +16,7 @@ const accounts = process.env.STACKING_KEYS.split(',').map(privKey => { return { privKey, pubKey, stxAddress, btcAddr: publicKeyToBtcAddress(pubKey), + signerKey: crypto.randomBytes(33).toString('hex'), client: new StackingClient(stxAddress, network), }; }); @@ -52,6 +54,7 @@ async function run() { burnBlockHeight: poxInfo.current_burnchain_block_height, cycles: stackingCycles, fee: 1000, + signerKey: account.signerKey, }; console.log('Stacking with args:', { addr: account.stxAddress, ...stackingArgs }); const stackResult = await account.client.stack(stackingArgs) From 4a8c53fdc7b7b5b9d7b359b748631edf38c4424d Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Fri, 26 Jan 2024 13:54:55 +0100 Subject: [PATCH 18/29] fix: add `mining_key` for epoch3.0 --- docker-compose.yml | 2 +- stacks-krypton-miner.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9fe78e3..f2fd0a8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -200,7 +200,7 @@ services: context: . dockerfile: Dockerfile.stacks-api args: - GIT_COMMIT: db859ae980368db22b9d1c4c7096918d5f7f4c4b + GIT_COMMIT: 7521dc3a7cb146109f0277364acad2e48bb51594 depends_on: - postgres ports: diff --git a/stacks-krypton-miner.toml b/stacks-krypton-miner.toml index 65bfac4..9222c07 100644 --- a/stacks-krypton-miner.toml +++ b/stacks-krypton-miner.toml @@ -26,6 +26,7 @@ second_attempt_time_ms = 360_000 wait_for_block_download = false microblock_attempt_time_ms = 10 self_signing_seed = 1 +mining_key = "19ec1c3e31d139c989a23a27eac60d1abfad5277d3ae9604242514c738258efa01" $REWARD_RECIPIENT_CONF [connection_options] From c8f17f3bb9d4c92e86058eb1eb294c265bbf724c Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Fri, 26 Jan 2024 16:26:30 +0100 Subject: [PATCH 19/29] chore: bump stacks-api --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index f2fd0a8..c79a7fd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -200,7 +200,7 @@ services: context: . dockerfile: Dockerfile.stacks-api args: - GIT_COMMIT: 7521dc3a7cb146109f0277364acad2e48bb51594 + GIT_COMMIT: 12473c8fdbf4fb18cdf679994b51710499f2c0ec depends_on: - postgres ports: From ce0db115eec7a87f87b729c28469d9be10aeb6c2 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Thu, 1 Feb 2024 19:37:22 +0100 Subject: [PATCH 20/29] chore: bump stacks-node --- .github/workflows/build.yml | 2 +- Dockerfile.e2e | 2 +- docker-compose-follower.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 360187a..d4639fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: env: - STACKS_BLOCKCHAIN_COMMIT: 390dffc7e3593711c1f55505d3308063a2039df6 + STACKS_BLOCKCHAIN_COMMIT: 74e3cedeec5215f3286af6565c1503e578a848fb concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/Dockerfile.e2e b/Dockerfile.e2e index 69f4667..62290d2 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -3,7 +3,7 @@ FROM rust:bookworm as builder # A commit hash, tag, or branch -ARG GIT_COMMIT=390dffc7e3593711c1f55505d3308063a2039df6 +ARG GIT_COMMIT=74e3cedeec5215f3286af6565c1503e578a848fb ARG BLOCKCHAIN_REPO=https://github.com/stacks-network/stacks-blockchain.git ARG TARGETPLATFORM diff --git a/docker-compose-follower.yml b/docker-compose-follower.yml index a946c06..6d1509c 100644 --- a/docker-compose-follower.yml +++ b/docker-compose-follower.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT master + - &STACKS_BLOCKCHAIN_COMMIT 74e3cedeec5215f3286af6565c1503e578a848fb - &MINER_PUB_KEY 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c - &BITCOIN_PEER_PORT 18444 - &BITCOIN_RPC_PORT 18443 From 2b232706f3ef4cd28413391075e73b47ddbb4f1c Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Thu, 1 Feb 2024 19:45:07 +0100 Subject: [PATCH 21/29] chore: bump stacks-node in miner docker compose --- docker-compose-miner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-miner.yml b/docker-compose-miner.yml index 0e566ab..0b0bc74 100644 --- a/docker-compose-miner.yml +++ b/docker-compose-miner.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 9af9c0b5b80f948e90916a45f3f316c81a7ac481 + - &STACKS_BLOCKCHAIN_COMMIT 74e3cedeec5215f3286af6565c1503e578a848fb - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 From 2fd5faf518ba861a91a95eea507b777731b61008 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Fri, 2 Feb 2024 16:38:27 +0100 Subject: [PATCH 22/29] fix: add wallet name in bitcoind command --- .github/workflows/build.yml | 2 +- Dockerfile.e2e | 2 +- docker-compose-follower.yml | 2 +- docker-compose.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d4639fa..0f7bf98 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: env: - STACKS_BLOCKCHAIN_COMMIT: 74e3cedeec5215f3286af6565c1503e578a848fb + STACKS_BLOCKCHAIN_COMMIT: 5c14a440d26c012a0df59f1de0ede7b7a0ea76cd concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/Dockerfile.e2e b/Dockerfile.e2e index 322bfc1..3e6ab9b 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -3,7 +3,7 @@ FROM rust:bookworm as builder # A commit hash, tag, or branch -ARG GIT_COMMIT=74e3cedeec5215f3286af6565c1503e578a848fb +ARG GIT_COMMIT=5c14a440d26c012a0df59f1de0ede7b7a0ea76cd ARG BLOCKCHAIN_REPO=https://github.com/stacks-network/stacks-blockchain.git ARG TARGETPLATFORM diff --git a/docker-compose-follower.yml b/docker-compose-follower.yml index 6d1509c..764101c 100644 --- a/docker-compose-follower.yml +++ b/docker-compose-follower.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 74e3cedeec5215f3286af6565c1503e578a848fb + - &STACKS_BLOCKCHAIN_COMMIT 5c14a440d26c012a0df59f1de0ede7b7a0ea76cd - &MINER_PUB_KEY 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c - &BITCOIN_PEER_PORT 18444 - &BITCOIN_RPC_PORT 18443 diff --git a/docker-compose.yml b/docker-compose.yml index ff64c61..e170209 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 74e3cedeec5215f3286af6565c1503e578a848fb + - &STACKS_BLOCKCHAIN_COMMIT 5c14a440d26c012a0df59f1de0ede7b7a0ea76cd - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 @@ -70,7 +70,7 @@ services: trap "exit" INT TERM trap "kill 0" EXIT bitcoin-cli -rpcconnect=bitcoind -rpcwait getmininginfo - bitcoin-cli -rpcconnect=bitcoind -named createwallet wallet_name="" descriptors=false + bitcoin-cli -rpcconnect=bitcoind -named createwallet wallet_name=main descriptors=false bitcoin-cli -rpcconnect=bitcoind importaddress $${BTC_ADDR} "" false bitcoin-cli -rpcconnect=bitcoind generatetoaddress $${INIT_BLOCKS} $${BTC_ADDR} DEFAULT_TIMEOUT=$$(($$(date +%s) + 30)) From ad24eb64927e4b71a528d10d690f8a23fc02d11d Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 6 Feb 2024 16:56:26 +0100 Subject: [PATCH 23/29] chore: bump stacks-api --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index e170209..afb733d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -200,7 +200,7 @@ services: context: . dockerfile: Dockerfile.stacks-api args: - GIT_COMMIT: 12473c8fdbf4fb18cdf679994b51710499f2c0ec + GIT_COMMIT: 191c6f572a137cb601b7fb59ed2fa5c1eee22bc1 depends_on: - postgres ports: From c5e985e1ad96e7d308287cfb9902fe502e9ed65a Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 6 Feb 2024 17:03:13 +0100 Subject: [PATCH 24/29] chore: bump latest next --- .github/workflows/build.yml | 2 +- Dockerfile.e2e | 2 +- docker-compose-follower.yml | 2 +- docker-compose.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0f7bf98..a2054ec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: env: - STACKS_BLOCKCHAIN_COMMIT: 5c14a440d26c012a0df59f1de0ede7b7a0ea76cd + STACKS_BLOCKCHAIN_COMMIT: 7c7a5277eaa6b03b73c36021c087658f89851234 concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/Dockerfile.e2e b/Dockerfile.e2e index 3e6ab9b..f3502f0 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -3,7 +3,7 @@ FROM rust:bookworm as builder # A commit hash, tag, or branch -ARG GIT_COMMIT=5c14a440d26c012a0df59f1de0ede7b7a0ea76cd +ARG GIT_COMMIT=7c7a5277eaa6b03b73c36021c087658f89851234 ARG BLOCKCHAIN_REPO=https://github.com/stacks-network/stacks-blockchain.git ARG TARGETPLATFORM diff --git a/docker-compose-follower.yml b/docker-compose-follower.yml index 764101c..8efab66 100644 --- a/docker-compose-follower.yml +++ b/docker-compose-follower.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 5c14a440d26c012a0df59f1de0ede7b7a0ea76cd + - &STACKS_BLOCKCHAIN_COMMIT 7c7a5277eaa6b03b73c36021c087658f89851234 - &MINER_PUB_KEY 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c - &BITCOIN_PEER_PORT 18444 - &BITCOIN_RPC_PORT 18443 diff --git a/docker-compose.yml b/docker-compose.yml index afb733d..fd7beee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 5c14a440d26c012a0df59f1de0ede7b7a0ea76cd + - &STACKS_BLOCKCHAIN_COMMIT 7c7a5277eaa6b03b73c36021c087658f89851234 - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 From e40a25b112b5bfa91d37c1699ddbf1717cb9acae Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 6 Feb 2024 17:14:27 +0100 Subject: [PATCH 25/29] fix: stacks-node --config option change --- Dockerfile.e2e | 4 ++-- docker-compose-follower.yml | 2 +- docker-compose.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile.e2e b/Dockerfile.e2e index f3502f0..29ac816 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -184,7 +184,7 @@ RUN < config.toml - stacks-node start --config=config.toml & + stacks-node start --config config.toml & STACKS_PID=$! while true; do @@ -274,7 +274,7 @@ 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() { diff --git a/docker-compose-follower.yml b/docker-compose-follower.yml index 8efab66..61e9558 100644 --- a/docker-compose-follower.yml +++ b/docker-compose-follower.yml @@ -60,7 +60,7 @@ services: until $(curl -o /dev/null -s stacks-node-miner:20443); do sleep 5 done - exec stacks-node start --config=config.toml + exec stacks-node start --config config.toml networks: stacks: diff --git a/docker-compose.yml b/docker-compose.yml index fd7beee..a61e1bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -149,7 +149,7 @@ services: rm -rf $${DATA_DIR}/* envsubst < config.toml.in > config.toml bitcoin-cli -rpcwait -rpcconnect=bitcoind getmininginfo - exec stacks-node start --config=config.toml + exec stacks-node start --config config.toml stacker: networks: From 7966530153eb1a8bc3c7afcbaf5c198ce7c2e38e Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 20 Feb 2024 17:56:52 +0100 Subject: [PATCH 26/29] chore: update to next and add pox signer logic --- .github/workflows/build.yml | 2 +- Dockerfile.e2e | 2 +- docker-compose-follower.yml | 2 +- docker-compose.yml | 10 +++++++--- stacking/package.json | 2 +- stacking/stacking.js | 22 +++++++++++++++++----- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a2054ec..851fbd1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: env: - STACKS_BLOCKCHAIN_COMMIT: 7c7a5277eaa6b03b73c36021c087658f89851234 + STACKS_BLOCKCHAIN_COMMIT: 5a4b3882e6f1d80dce73302c44e87271894103b8 concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/Dockerfile.e2e b/Dockerfile.e2e index 29ac816..b236487 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -3,7 +3,7 @@ FROM rust:bookworm as builder # A commit hash, tag, or branch -ARG GIT_COMMIT=7c7a5277eaa6b03b73c36021c087658f89851234 +ARG GIT_COMMIT=5a4b3882e6f1d80dce73302c44e87271894103b8 ARG BLOCKCHAIN_REPO=https://github.com/stacks-network/stacks-blockchain.git ARG TARGETPLATFORM diff --git a/docker-compose-follower.yml b/docker-compose-follower.yml index 61e9558..ac03fb9 100644 --- a/docker-compose-follower.yml +++ b/docker-compose-follower.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 7c7a5277eaa6b03b73c36021c087658f89851234 + - &STACKS_BLOCKCHAIN_COMMIT 5a4b3882e6f1d80dce73302c44e87271894103b8 - &MINER_PUB_KEY 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c - &BITCOIN_PEER_PORT 18444 - &BITCOIN_RPC_PORT 18443 diff --git a/docker-compose.yml b/docker-compose.yml index a61e1bc..80e375a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 7c7a5277eaa6b03b73c36021c087658f89851234 + - &STACKS_BLOCKCHAIN_COMMIT 5a4b3882e6f1d80dce73302c44e87271894103b8 - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 @@ -9,7 +9,7 @@ x-common-vars: - &BITCOIN_RPC_USER btc - &BITCOIN_RPC_PASS btc - &MINE_INTERVAL ${MINE_INTERVAL:-0.5s} - - &MINE_INTERVAL_EPOCH3 ${MINE_INTERVAL_EPOCH3:-600s} # 10 minute bitcoin block times in epoch 3 + - &MINE_INTERVAL_EPOCH3 ${MINE_INTERVAL_EPOCH3:-5s} # 10 minute bitcoin block times in epoch 3 - &STACKS_20_HEIGHT ${STACKS_20_HEIGHT:-101} - &STACKS_2_05_HEIGHT ${STACKS_2_05_HEIGHT:-102} - &STACKS_21_HEIGHT ${STACKS_21_HEIGHT:-103} @@ -119,7 +119,7 @@ services: environment: # STACKS_LOG_TRACE: 1 # uncomment for trace logging # STACKS_LOG_DEBUG: 1 - STACKS_EVENT_OBSERVER: stacks-api:3700 + # STACKS_EVENT_OBSERVER: stacks-api:3700 DATA_DIR: /chainstate/stacks-blockchain-miner-data BITCOIN_PEER_HOST: bitcoind BITCOIN_PEER_PORT: *BITCOIN_PEER_PORT @@ -179,6 +179,8 @@ services: - stacks-node postgres: + profiles: + - disabled networks: - stacks image: "postgres:15" @@ -194,6 +196,8 @@ services: PGDATA: /chainstate/pg-data stacks-api: + profiles: + - disabled networks: - stacks build: diff --git a/stacking/package.json b/stacking/package.json index 9783a07..61dba34 100644 --- a/stacking/package.json +++ b/stacking/package.json @@ -8,6 +8,6 @@ "author": "", "license": "ISC", "dependencies": { - "@stacks/stacking": "6.11.2-pr.3560789.0" + "@stacks/stacking": "6.11.4-pr.3d89ca1.0" } } diff --git a/stacking/stacking.js b/stacking/stacking.js index e14d78d..3aba767 100644 --- a/stacking/stacking.js +++ b/stacking/stacking.js @@ -1,6 +1,6 @@ const { StackingClient } = require('@stacks/stacking'); const { StacksTestnet } = require('@stacks/network'); -const { getAddressFromPrivateKey, TransactionVersion } = require('@stacks/transactions'); +const { getAddressFromPrivateKey, TransactionVersion, makeRandomPrivKey } = require('@stacks/transactions'); const { getPublicKeyFromPrivate, publicKeyToBtcAddress } = require('@stacks/encryption'); const crypto = require('crypto'); @@ -13,10 +13,13 @@ const network = new StacksTestnet({ url }); const accounts = process.env.STACKING_KEYS.split(',').map(privKey => { const pubKey = getPublicKeyFromPrivate(privKey); const stxAddress = getAddressFromPrivateKey(privKey, TransactionVersion.Testnet); + const signerPrivKey = makeRandomPrivKey(); + const signerPubKey = getPublicKeyFromPrivate(signerPrivKey); return { privKey, pubKey, stxAddress, btcAddr: publicKeyToBtcAddress(pubKey), - signerKey: crypto.randomBytes(33).toString('hex'), + signerPrivKey: signerPrivKey, + signerPubKey: signerPubKey, client: new StackingClient(stxAddress, network), }; }); @@ -47,6 +50,14 @@ async function run() { console.log(`No unlocked account available for stacking`); return; } + + const signerSignature = account.client.signPoxSignature({ + topic: 'stack-stx', + rewardCycle: poxInfo.current_cycle.id, + poxAddress, + period: cycles, + signerPrivateKey: account.signerPrivKey, + }); const stackingArgs = { poxAddress: account.btcAddr, privateKey: account.privKey, @@ -54,10 +65,11 @@ async function run() { burnBlockHeight: poxInfo.current_burnchain_block_height, cycles: stackingCycles, fee: 1000, - signerKey: account.signerKey, + signerKey: account.signerPubKey, + signerSignature, }; - console.log('Stacking with args:', { addr: account.stxAddress, ...stackingArgs }); - const stackResult = await account.client.stack(stackingArgs) + console.log('Stacking with args:', { addr: account.stxAddress, ...stackingArgs, ...signerSignature }); + const stackResult = await account.client.stack(stackingArgs); console.log('Stacking tx result', stackResult); await new Promise(resolve => setTimeout(resolve, postTxWait * 1000)); } From b0a8c8e84f3997d085d34083d59102a0e312ad4b Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Wed, 21 Feb 2024 11:41:31 +0100 Subject: [PATCH 27/29] fix: stacks signature logic --- stacking/stacking.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stacking/stacking.js b/stacking/stacking.js index 3aba767..a808e11 100644 --- a/stacking/stacking.js +++ b/stacking/stacking.js @@ -14,7 +14,7 @@ const accounts = process.env.STACKING_KEYS.split(',').map(privKey => { const pubKey = getPublicKeyFromPrivate(privKey); const stxAddress = getAddressFromPrivateKey(privKey, TransactionVersion.Testnet); const signerPrivKey = makeRandomPrivKey(); - const signerPubKey = getPublicKeyFromPrivate(signerPrivKey); + const signerPubKey = getPublicKeyFromPrivate(signerPrivKey.data); return { privKey, pubKey, stxAddress, btcAddr: publicKeyToBtcAddress(pubKey), @@ -51,13 +51,14 @@ async function run() { return; } - const signerSignature = account.client.signPoxSignature({ + const sigArgs = { topic: 'stack-stx', - rewardCycle: poxInfo.current_cycle.id, - poxAddress, - period: cycles, + rewardCycle: poxInfo.reward_cycle_id, + poxAddress: account.btcAddr, + period: stackingCycles, signerPrivateKey: account.signerPrivKey, - }); + }; + const signerSignature = account.client.signPoxSignature(sigArgs); const stackingArgs = { poxAddress: account.btcAddr, privateKey: account.privKey, @@ -68,7 +69,7 @@ async function run() { signerKey: account.signerPubKey, signerSignature, }; - console.log('Stacking with args:', { addr: account.stxAddress, ...stackingArgs, ...signerSignature }); + console.log('Stacking with args:', { addr: account.stxAddress, ...stackingArgs, ...sigArgs }); const stackResult = await account.client.stack(stackingArgs); console.log('Stacking tx result', stackResult); await new Promise(resolve => setTimeout(resolve, postTxWait * 1000)); From 1e6ad6aa9b37ac2dad0a1ed790da01a1ac692b87 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Wed, 21 Feb 2024 12:00:01 +0100 Subject: [PATCH 28/29] chore: revert debug changes --- docker-compose.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 80e375a..a21bc7f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ x-common-vars: - &BITCOIN_RPC_USER btc - &BITCOIN_RPC_PASS btc - &MINE_INTERVAL ${MINE_INTERVAL:-0.5s} - - &MINE_INTERVAL_EPOCH3 ${MINE_INTERVAL_EPOCH3:-5s} # 10 minute bitcoin block times in epoch 3 + - &MINE_INTERVAL_EPOCH3 ${MINE_INTERVAL_EPOCH3:-600s} # 10 minute bitcoin block times in epoch 3 - &STACKS_20_HEIGHT ${STACKS_20_HEIGHT:-101} - &STACKS_2_05_HEIGHT ${STACKS_2_05_HEIGHT:-102} - &STACKS_21_HEIGHT ${STACKS_21_HEIGHT:-103} @@ -119,7 +119,7 @@ services: environment: # STACKS_LOG_TRACE: 1 # uncomment for trace logging # STACKS_LOG_DEBUG: 1 - # STACKS_EVENT_OBSERVER: stacks-api:3700 + STACKS_EVENT_OBSERVER: stacks-api:3700 DATA_DIR: /chainstate/stacks-blockchain-miner-data BITCOIN_PEER_HOST: bitcoind BITCOIN_PEER_PORT: *BITCOIN_PEER_PORT @@ -179,8 +179,6 @@ services: - stacks-node postgres: - profiles: - - disabled networks: - stacks image: "postgres:15" @@ -196,15 +194,13 @@ services: PGDATA: /chainstate/pg-data stacks-api: - profiles: - - disabled networks: - stacks build: context: . dockerfile: Dockerfile.stacks-api args: - GIT_COMMIT: 191c6f572a137cb601b7fb59ed2fa5c1eee22bc1 + GIT_COMMIT: a5487312613a3179599fb7c128af9cfadc92d9a3 depends_on: - postgres ports: From 777bf3620a4b002693578ebaf7143266dc52c8e1 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Wed, 28 Feb 2024 14:51:16 +0100 Subject: [PATCH 29/29] chore: bump stacks-node next and stacks.js stacking script --- .github/workflows/build.yml | 2 +- Dockerfile.e2e | 2 +- docker-compose-follower.yml | 2 +- docker-compose.yml | 4 ++-- stacking/package.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 851fbd1..08bbf38 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: env: - STACKS_BLOCKCHAIN_COMMIT: 5a4b3882e6f1d80dce73302c44e87271894103b8 + STACKS_BLOCKCHAIN_COMMIT: 9385b423609f0b5dabe7ffb66ed4db9f2f68a485 concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/Dockerfile.e2e b/Dockerfile.e2e index b236487..e66b037 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -3,7 +3,7 @@ FROM rust:bookworm as builder # A commit hash, tag, or branch -ARG GIT_COMMIT=5a4b3882e6f1d80dce73302c44e87271894103b8 +ARG GIT_COMMIT=9385b423609f0b5dabe7ffb66ed4db9f2f68a485 ARG BLOCKCHAIN_REPO=https://github.com/stacks-network/stacks-blockchain.git ARG TARGETPLATFORM diff --git a/docker-compose-follower.yml b/docker-compose-follower.yml index ac03fb9..1e18a4a 100644 --- a/docker-compose-follower.yml +++ b/docker-compose-follower.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 5a4b3882e6f1d80dce73302c44e87271894103b8 + - &STACKS_BLOCKCHAIN_COMMIT 9385b423609f0b5dabe7ffb66ed4db9f2f68a485 - &MINER_PUB_KEY 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c - &BITCOIN_PEER_PORT 18444 - &BITCOIN_RPC_PORT 18443 diff --git a/docker-compose.yml b/docker-compose.yml index a21bc7f..faf7f46 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" x-common-vars: - - &STACKS_BLOCKCHAIN_COMMIT 5a4b3882e6f1d80dce73302c44e87271894103b8 + - &STACKS_BLOCKCHAIN_COMMIT 9385b423609f0b5dabe7ffb66ed4db9f2f68a485 - &BTC_ADDR miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT - &MINER_SEED 9e446f6b0c6a96cf2190e54bcd5a8569c3e386f091605499464389b8d4e0bfc201 # stx: STEW4ZNT093ZHK4NEQKX8QJGM2Y7WWJ2FQQS5C19, btc: miEJtNKa3ASpA19v5ZhvbKTEieYjLpzCYT, pub_key: 035379aa40c02890d253cfa577964116eb5295570ae9f7287cbae5f2585f5b2c7c, wif: cStMQXkK5yTFGP3KbNXYQ3sJf2qwQiKrZwR9QJnksp32eKzef1za - &BITCOIN_PEER_PORT 18444 @@ -18,7 +18,7 @@ x-common-vars: - &STACKS_23_HEIGHT ${STACKS_23_HEIGHT:-106} - &STACKS_24_HEIGHT ${STACKS_24_HEIGHT:-107} - &STACKS_25_HEIGHT ${STACKS_25_HEIGHT:-108} - - &STACKS_30_HEIGHT ${STACKS_30_HEIGHT:-125} + - &STACKS_30_HEIGHT ${STACKS_30_HEIGHT:-122} - &REWARD_RECIPIENT ${REWARD_RECIPIENT:-STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN} # priv: 6ad9cadb42d4edbfbe0c5bfb3b8a4125ddced021c4174f829b714ccbf527f02001 services: diff --git a/stacking/package.json b/stacking/package.json index 61dba34..a4a6a87 100644 --- a/stacking/package.json +++ b/stacking/package.json @@ -8,6 +8,6 @@ "author": "", "license": "ISC", "dependencies": { - "@stacks/stacking": "6.11.4-pr.3d89ca1.0" + "@stacks/stacking": "6.11.4-pr.a8fa50e.0" } }