Reference implementation of the Stacks blockchain in Rust.
Stacks 2.0 is a layer-1 blockchain that connects to Bitcoin for security and enables decentralized apps and predictable smart contracts. Stacks 2.0 implements Proof of Transfer (PoX) mining that anchors to Bitcoin security. Leader election happens at the Bitcoin blockchain and Stacks (STX) miners write new blocks on the separate Stacks blockchain. With PoX there is no need to modify Bitcoin to enable smart contracts and apps around it. See this page for more details and resources.
Blockstack Topic/Tech | Where to learn more more |
---|---|
Stacks 2.0 | master branch |
Stacks 1.0 | legacy branch |
Use the package | our core docs |
Develop a Blockstack App | our developer docs |
Use a Blockstack App | our browser docs |
Blockstack PBC the company | our website |
Normal releases in this repository that add features such as improved RPC endpoints, improved boot-up time, new eventobserver fields or event types, etc., are released on a monthly schedule. The currently staged changes for such releasesare in the develop branch. It is generally safe to runa stacks-node
from that branch, though it has received less rigorous testing than release tags. If bugs are found inthe develop
branch, please do report them as issues on this repository.
For fixes that impact the correct functioning or liveness of the network, hotfixes may be issued. These are patchesto the main branch which are backported to the develop branch after merging. These hotfixes are categorized by priorityaccording to the following rubric:
This repository uses a 5 part version number.
X.Y.Z.A.n
X = 2 and does not change in practice unless there’s another Stacks 2.0 type event
Y increments on consensus-breaking changes
Z increments on non-consensus-breaking changes that require a fresh chainstate (akin to semantic MAJOR)
A increments on non-consensus-breaking changes that do not require a fresh chainstate, but introduce new features (akin to semantic MINOR)
n increments on patches and hot-fixes (akin to semantic PATCH)
For example, a node operator running version 2.0.10.0.0
would not need to wipe and refresh their chainstateto upgrade to 2.0.10.1.0
or 2.0.10.0.1
. However, upgrading to 2.0.11.0.0
would require a new chainstate.
Stacks improvement proposals (SIPs) are aimed at describing the implementation of the Stacks blockchain, as well as proposing improvements. They should contain concise technical specifications of features or standards and the rationale behind it. SIPs are intended to be the primary medium for proposing new features, for collecting community input on a system-wide issue, and for documenting design decisions.
See SIP 000 for more details.
The SIPs are now located in the stacksgov/sips repository as part of the Stacks Community Governance organization.
Krypton is a Stacks 2 testnet with a fixed, two-minute block time, called regtest
. Regtest is generally unstable for regular use, and is reset often. See the regtest documentation for more information on using regtest.
Xenon is the Stacks 2 public testnet, which runs PoX against the Bitcoin testnet. It is the full implementation of the Stacks 2 blockchain, and should be considered a stable testnet for developing Clarity smart contracts. See the testnet documentation for more information on the public testnet.
Mainnet is the fully functional Stacks 2 blockchain, see the Stacks overview for information on running a Stacks node, mining, stacking, and writing Clarity smart contracts.
The first step is to ensure that you have Rust and the support software installed.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
For building on Windows, follow the rustup installer instructions at https://rustup.rs/
From there, you can clone this repository:
git clone --depth=1 https://github.com/blockstack/stacks-blockchain.git
cd stacks-blockchain
Then build the project:
cargo build
Run the tests:
cargo test testnet -- --test-threads=1
Here, we have generated a keypair that will be used for signing the upcoming transactions:
cargo run --bin blockstack-cli generate-sk --testnet
# Output
# {
# secretKey: "b8d99fd45da58038d630d9855d3ca2466e8e0f89d3894c4724f0efc9ff4b51f001",
# publicKey: "02781d2d3a545afdb7f6013a8241b9e400475397516a0d0f76863c6742210539b5",
# stacksAddress: "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH"
# }
This keypair is already registered in the testnet-follower-conf.toml
file, so it can be used as presented here.
We will interact with the following simple contract kv-store
. In our examples, we will assume this contract is saved to ./kv-store.clar
:
(define-map store { key: (string-ascii 32) } { value: (string-ascii 32) })
(define-public (get-value (key (string-ascii 32)))
(match (map-get? store { key: key })
entry (ok (get value entry))
(err 0)))
(define-public (set-value (key (string-ascii 32)) (value (string-ascii 32)))
(begin
(map-set store { key: key } { value: value })
(ok true)))
We want to publish this contract on chain, then issue some transactions that interact with it by setting some keys and getting some values, so we can observe read and writes.
Our first step is to generate and sign, using your private key, the transaction that will publish the contract kv-store
.To do that, we will use the subcommand:
cargo run --bin blockstack-cli publish --help
With the following arguments:
cargo run --bin blockstack-cli publish b8d99fd45da58038d630d9855d3ca2466e8e0f89d3894c4724f0efc9ff4b51f001 515 0 kv-store ./kv-store.clar --testnet
The 515
is the transaction fee, denominated in microSTX. Right now, thetestnet requires one microSTX per byte minimum, and this transaction should beless than 515 bytes.The third argument 0
is a nonce, that must be increased monotonically with each new transaction.
This command will output the binary format of the transaction. In our case, we want to pipe this output and dump it to a file that will be used later in this tutorial.
cargo run --bin blockstack-cli publish b8d99fd45da58038d630d9855d3ca2466e8e0f89d3894c4724f0efc9ff4b51f001 515 0 kv-store ./kv-store.clar --testnet | xxd -r -p > tx1.bin
You can observe the state machine in action locally by running:
cargo stacks-node start --config=./testnet/stacks-node/conf/testnet-follower-conf.toml
testnet-follower-conf.toml
is a configuration file that you can use for setting genesis balances or configuring Event observers. You can grant an address an initial account balance by adding the following entries:
[[ustx_balance]]
address = "ST2VHM28V9E5QCRD6C73215KAPSBKQGPWTEE5CMQT"
amount = 100000000
The address
field is the Stacks testnet address, and the amount
field is thenumber of microSTX to grant to it in the genesis block. The addresses of theprivate keys used in the tutorial below are already added.
Assuming that the testnet is running, we can publish our kv-store
contract.
In another terminal (or file explorer), you can move the tx1.bin
generated earlier, to the mempool:
curl -X POST -H "Content-Type: application/octet-stream" --data-binary @./tx1.bin http://localhost:20443/v2/transactions
In the terminal window running the testnet, you can observe the state machine's reactions.
Now that our contract has been published on chain, let's try to submit some read / write transactions.We will start by trying to read the value associated with the key foo
.
To do that, we will use the subcommand:
cargo run --bin blockstack-cli contract-call --help
With the following arguments:
cargo run --bin blockstack-cli contract-call b8d99fd45da58038d630d9855d3ca2466e8e0f89d3894c4724f0efc9ff4b51f001 500 1 ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH kv-store get-value -e \"foo\" --testnet | xxd -r -p > tx2.bin
contract-call
generates and signs a contract-call transaction.
We can submit the transaction by moving it to the mempool path:
curl -X POST -H "Content-Type: application/octet-stream" --data-binary @./tx2.bin http://localhost:20443/v2/transactions
Similarly, we can generate a transaction that would be setting the key foo
to the value bar
:
cargo run --bin blockstack-cli contract-call b8d99fd45da58038d630d9855d3ca2466e8e0f89d3894c4724f0efc9ff4b51f001 500 2 ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH kv-store set-value -e \"foo\" -e \"bar\" --testnet | xxd -r -p > tx3.bin
And submit it by moving it to the mempool path:
curl -X POST -H "Content-Type: application/octet-stream" --data-binary @./tx3.bin http://localhost:20443/v2/transactions
Finally, we can issue a third transaction, reading the key foo
again, for ensuring that the previous transaction has successfully updated the state machine:
cargo run --bin blockstack-cli contract-call b8d99fd45da58038d630d9855d3ca2466e8e0f89d3894c4724f0efc9ff4b51f001 500 3 ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH kv-store get-value -e \"foo\" --testnet | xxd -r -p > tx4.bin
And submit this last transaction by moving it to the mempool path:
curl -X POST -H "Content-Type: application/octet-stream" --data-binary @./tx4.bin http://localhost:20443/v2/transactions
Congratulations, you can now write your own smart contracts with Clarity.
Officially supported platforms: Linux 64-bit
, MacOS 64-bit
, Windows 64-bit
.
Platforms with second-tier status (builds are provided but not tested): Linux ARMv7
, Linux ARM64
.
For help cross-compiling on memory-constrained devices, please see the community supported documentation here: Cross Compiling.
Beyond this Github project,Blockstack maintains a public forum and anopened Discord channel. In addition, the projectmaintains a mailing list which sends outcommunity announcements.
The greater Blockstack community regularly hosts in-personmeetups. The project'sYouTube channel includesvideos from some of these meetups, as well as video tutorials to help newusers get started and help developers wrap their heads around the system'sdesign.
You can learn more by visiting the Blockstack Website and checking out the documentation:
You can also read the technical papers:
If you have high-level questions about Blockstack, try searching our forum and start a new question if your question is not answered there.
PRs must include test coverage. However, if your PR includes large tests or tests which cannot run in parallel(which is the default operation of the cargo test
command), these tests should be decorated with #[ignore]
.If you add #[ignore]
tests, you should add your branch to the filters for the all_tests
job in our circle.yml(or if you are working on net code or marf code, your branch should be named such that it matches the existingfilters there).
A test should be marked #[ignore]
if:
cargo test
in a vanilla environment (i.e., it does not need to run with --test-threads 1
).cargo test
execution (the cargo test
command will warn if this is not the case).This repository uses the default rustfmt formatting style. PRs will be checked against rustfmt
and will fail if notproperly formatted.
You can check the formatting locally via:
cargo fmt --all -- --check
You can automatically reformat your commit via:
cargo fmt --all
Stacks tokens (STX) are mined by transferring BTC via PoX. To run as a miner,you should make sure to add the following config fields to your config file:
[node]
# Run as a miner
miner = True
# Bitcoin private key to spend
seed = "YOUR PRIVATE KEY"
# How long to wait for microblocks to arrive before mining a block to confirm them (in milliseconds)
wait_time_for_microblocks = 10000
# Run as a mock-miner, to test mining without spending BTC.
# Mutually exclusive with `miner`.
#mock_miner = True
[miner]
# Smallest allowed tx fee, in microSTX
min_tx_fee = 100
# Time to spend on the first attempt to make a block.
# This can be small, so your node gets a block-commit into the Bitcoin mempool early.
first_attempt_time_ms: 1000
# Time to spend on subsequent attempts to make a block.
# This can be bigger -- new block-commits will be RBF'ed.
subsequent_attempt_time_ms: 60000
You can verify that your node is operating as a miner by checking its log outputto verify that it was able to find its Bitcoin UTXOs:
$ head -n 100 /path/to/your/node/logs | grep -i utxo
INFO [1630127492.031042] [testnet/stacks-node/src/run_loop/neon.rs:146] [main] Miner node: checking UTXOs at address: <redacted>
INFO [1630127492.062652] [testnet/stacks-node/src/run_loop/neon.rs:164] [main] UTXOs found - will run as a Miner node
For non-consensus breaking releases, this project uses the following release process:
The release must be timed so that it does not interfere with a preparephase. The timing of the next Stacking cycle can be foundhere. A release to mainnet
should happenat least 24 hours before the start of a new cycle, to avoid interferingwith the prepare phase. So, start by being aware of when the release canhappen.
Before creating the release, the release manager must determine the versionnumber for this release. The factors that determine the version number arediscussed in Versioning. We assume, in this section,that the change is not consensus-breaking. So, the release manager must firstdetermine whether there are any "non-consensus-breaking changes that require afresh chainstate". This means, in other words, that the database schema haschanged. Then, the release manager should determine whether this is a featurerelease, as opposed to a hot fix or a patch. Given the answers to thesequestions, the version number can be computed.
The release manager enumerates the PRs or issues that would blockthe release. A label should be applied to each such issue/PR as2.0.x.y.z-blocker
. The release manager should ping theseissue/PR owners for updates on whether or not those issues/PRs haveany blockers or are waiting on feedback.
The release manager should open a develop -> master
PR. This can be done beforeall the blocker PRs have merged, as it is helpful for the manager and othersto see the staged changes.
The release manager must update the CHANGELOG.md
file with summaries whatwas Added
, Changed
, and Fixed
. The pull requests merged into develop
can be foundhere. Note, however, that GitHub apparently does not allow sorting bymerge time, so, when sorting by some proxy criterion, some care shouldbe used to understand which PR's were merged after the last develop -> master
release PR. This CHANGELOG.md
should also be used as the descriptionof the develop -> master
so that it acts as release notes when the branchis tagged.
Once the blocker PRs have merged, the release manager will create a new tagby manually triggering the stacks-blockchain
Github Actions workflowagainst the develop
branch, inputting the release candidate tag, 2.0.x.y.z-rc0
,in the Action's input textbox.
Once the release candidate has been built, and docker images, etc. are available,the release manager will notify various ecosystem participants to test the releasecandidate on various staging infrastructure:
The release candidate should be announced in the #stacks-core-devs
channel in theStacks Discord. For coordinating rollouts on specific infrastructure, the releasemanager should contact the above participants directly either through e-mail orDiscord DM. The release manager should also confirm that the built release on theGithub releasespage is marked as Pre-Release
.
The release manager will test that the release candidate successfully syncs withthe current chain from genesis both in testnet and mainnet. This requires startingthe release candidate with an empty chainstate and confirming that it synchronizeswith the current chain tip.
If bugs or issues emerge from the rollout on staging infrastructure, the releasewill be delayed until those regressions are resolved. As regressions are resolved,additional release candidates should be tagged. The release manager is responsiblefor updating the develop -> master
PR with information about the discovered issues,even if other community members and developers may be addressing the discoveredissues.
Once the final release candidate has rolled out successfully without issue on theabove staging infrastructure, the release manager tags 2 additional stacks-blockchain
team members to review the develop -> master
PR.
Once reviewed and approved, the release manager merges the PR, and tags the releasevia the stacks-blockchain
Github actionby clicking "Run workflow" and providing the release version as the tag (e.g.,2.0.11.1.0
) This creates a release and release images. Once the release has beencreated, the release manager should update the Github release text with theCHANGELOG.md
"top-matter" for the release.
The code and documentation copyright are attributed to blockstack.org for the year of 2020.
This code is released under the GPL v3 license, and the docs are released under the Creative Commons license.
堆栈有时称为外部数据队列,但我们遵循常见用法并将其称为堆栈。 它是一块逻辑上在Rexx外部的内存块。 像push和queue这样的指令将数据放入堆栈,拉取和解析等指令从中提取数据。 排队的内置函数报告堆栈中有多少项。 我们来看一个堆栈的例子。 /* STACK: */ /* */ /* This program shows how to use the Rexx Stack as either
stacks-cli Check website stack from the terminal. In fact I know there's already a pretty good Chrome extension called Wappalyzer, but I still wanna make a CLI tool for myself. There's 2 major reasons
Jupyter Docker Stacks Jupyter Docker Stacks are a set of ready-to-run Docker imagescontaining Jupyter applications and interactive computing tools. Quick Start You can try a relatively recent build of
Awesome Stacks Deploy 80+ open-source web apps with one Docker command. Features Traefik compatibility Portainer compatibility No need to manage configuration files Distributed storage compatibility (
C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构。 操作 比较和分配堆栈 empty() 堆栈为空则返回真 pop() 移除栈顶元素 push() 在栈顶增加元素 size() 返回栈中元素数目 top() 返回栈顶元素
操作语法: == <= >= < > != 所有的这些操作可以被用于堆栈. 相等指堆栈有相同的元素并有着相同的顺序。 empty语法: bool empty(); 如当前堆栈为空,empty() 函数 返回 true 否则返回false. pop语法: void pop(); pop() 函数移除堆栈中最顶层元素。相关主题: top