Skip to content

Commit

Permalink
Merge branch 'master' into feature/json-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
kantai committed Apr 5, 2020
2 parents 412af17 + b0a9000 commit 5f46bab
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 133 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ path = "src/blockstack_cli.rs"
name = "marf_bench"
harness = false

[features]
developer-mode = []
default = ["developer-mode"]

[dependencies]
byteorder = "1.1"
rust-ini = "0.13"
Expand All @@ -47,6 +43,8 @@ libc = "0.2"
lazy_static = "1.4.0"
toml = "0.5.6"
url = "2.1.1"
sha2 = { version = "0.8.0", optional = true }
sha2-asm = { version="0.5.3", optional = true }

[dependencies.serde_json]
version = "1.0"
Expand All @@ -68,10 +66,6 @@ features = ["serde"]
version = "=2.0.0"
features = ["serde"]

[dependencies.sha2]
version = "0.8.0"
features = ["asm"]

[dependencies.time]
version = "0.2.1"
features = ["std"]
Expand All @@ -80,3 +74,9 @@ features = ["std"]
assert-json-diff = "1.0.0"
criterion = "0.3"
reqwest = { version = "0.10", features = ["blocking", "json"] }

[features]
developer-mode = []
asm = ["sha2", "sha2-asm"]
aarch64 = ["developer-mode", "sha2"]
default = ["developer-mode", "asm"]
59 changes: 31 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,31 @@ Reference implementation of the [Blockstack Technical Whitepaper](https://blocks

## Repository

| Blockstack Topic/Tech | Where to learn more more |
|---------------------------------|------------------------------------------------------------------------------|
| Stacks 2.0 | [master branch](https://github.com/blockstack/stacks-blockchain/tree/master) |
| Stacks 1.0 | [legacy branch](https://github.com/blockstack/stacks-blockchain/tree/stacks-1.0) |
| Use the package | [our core docs](https://docs.blockstack.org/core/naming/introduction.html) |
| Develop a Blockstack App | [our developer docs](https://docs.blockstack.org/browser/hello-blockstack.html) |
| Use a Blockstack App | [our browser docs](https://docs.blockstack.org/browser/browser-introduction.html) |
| Blockstack the company | [our website](https://blockstack.org) |
| Blockstack Topic/Tech | Where to learn more more |
| ------------------------ | --------------------------------------------------------------------------------- |
| Stacks 2.0 | [master branch](https://github.com/blockstack/stacks-blockchain/tree/master) |
| Stacks 1.0 | [legacy branch](https://github.com/blockstack/stacks-blockchain/tree/stacks-1.0) |
| Use the package | [our core docs](https://docs.blockstack.org/core/naming/introduction.html) |
| Develop a Blockstack App | [our developer docs](https://docs.blockstack.org/browser/hello-blockstack.html) |
| Use a Blockstack App | [our browser docs](https://docs.blockstack.org/browser/browser-introduction.html) |
| Blockstack the company | [our website](https://blockstack.org) |

## Design Thesis

Stacks 2.0 is an open-membership replicated state machine produced by the coordination of a non-enumerable set of peers.

To unpack this definition:

- A replicated state machine is two or more copies (“replicas”) of a given set of rules (a “machine”) that, in processing a common input (such as the same sequence of transactions), will arrive at the same configuration (“state”). Bitcoin is a replicated state machine — its state is the set of UTXOs, which each peer has a full copy of, and given a block, all peers will independently calculate the same new UTXO set from the existing one.
- A replicated state machine is two or more copies (“replicas”) of a given set of rules (a “machine”) that, in processing a common input (such as the same sequence of transactions), will arrive at the same configuration (“state”). Bitcoin is a replicated state machine — its state is the set of UTXOs, which each peer has a full copy of, and given a block, all peers will independently calculate the same new UTXO set from the existing one.
- Open-membership means that any host on the Internet can join the blockchain and independently calculate the same full replica as all other peers.
- Non-enumerable means that the set of peers that are producing the blocks don’t know about one another — they don’t know their identities, or even how many exist and are online. They are indistinguishable.
- Non-enumerable means that the set of peers that are producing the blocks don’t know about one another — they don’t know their identities, or even how many exist and are online. They are indistinguishable.

## Roadmap

- [x] [SIP 001: Burn Election](https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-001-burn-election.md)
- [x] [SIP 002: Clarity, a language for predictable smart contracts](https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-002-smart-contract-language.md)
- [x] [SIP 004: Cryptographic Committment to Materialized Views](https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-004-materialized-view.md)
- [x] [SIP 005: Blocks, Transactions, and Accounts](https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-005-blocks-and-transactions.md
)
- [x] [SIP 005: Blocks, Transactions, and Accounts](https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-005-blocks-and-transactions.md)
- [ ] [SIP 003: Peer Network](https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-003-peer-network.md) (Q1 2020)
- [ ] SIP 006: Clarity Execution Cost Assessment (Q1 2020)

Expand All @@ -43,9 +42,9 @@ See [SIP 000](https://github.com/blockstack/stacks-blockchain/blob/master/sip/si

- [x] **Local Testnet** is a developer local setup, mono-node, assembling SIP 001, SIP 002, SIP 004 and SIP 005. With this version, developers can not only run Stacks 2.0 on their development machines, but also write, execute, and test smart contracts. See the instructions below for more details.

- [ ] **Open Testnet** is the upcoming version of our public testnet, that we're anticipating will ship in Q1 2020. This testnet will ship with SIP 003, and will be an open-membership public network, where participants will be able to validate and participate in mining testnet blocks.
- [ ] **Open Testnet** is the upcoming version of our public testnet, that we're anticipating will ship in Q2 2020. This testnet will ship with SIP 003, and will be an open-membership public network, where participants will be able to validate and participate in mining testnet blocks.

- [ ] **Mainet** is the fully functional version, that we're intending to ship in Q2 2020.
- [ ] **Mainet** is the fully functional version, that we're intending to ship in Q3 2020.

## Getting started

Expand All @@ -71,7 +70,13 @@ Then build the project:
cargo build
```

And run the tests:
Building the project on ARM:

```bash
cargo build --features "aarch64" --no-default-features
```

Run the tests:

```bash
cargo test testnet -- --test-threads=1
Expand Down Expand Up @@ -134,16 +139,12 @@ cargo run --bin blockstack-cli publish b8d99fd45da58038d630d9855d3ca2466e8e0f89d
You can observe the state machine in action locally by running:

```bash
cargo run --bin blockstack-core testnet
cargo run --bin blockstack-core testnet ./Stacks.toml
```

In your console, you should observe an output with a similar:
`Stacks.toml` is a configuration file that you can use for setting genesis balances or configuring Event observers.

```bash
*** mempool path: /tmp/stacks-testnet-5fc814cf78dc0636/L1/mempool
```

The testnet is watching this directory, decoding and ingesting the transactions materialized as files. This mechanism is a shortcut for simulating a mempool. A RPC server will soon be integrated.
The testnet is watching the directory specified by the key `mempool.path`. The transactions, materialized as files, will be decoded and ingested. This mechanism is a shortcut for simulating a mempool. A RPC server will soon be integrated.

### Publish your contract

Expand All @@ -152,7 +153,7 @@ 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:

```bash
cp ./tx1.bin /tmp/stacks-testnet-5fc814cf78dc0636/L1/mempool
cp ./tx1.bin /tmp/mempool
```

In the terminal window running the testnet, you can observe the state machine's reactions.
Expand Down Expand Up @@ -180,7 +181,7 @@ Note: the third argument `1` is a nonce, that must be increased monotonically wi
We can submit the transaction by moving it to the mempool path:

```bash
cp ./tx2.bin /tmp/stacks-testnet-5fc814cf78dc0636/L1/mempool
cp ./tx2.bin /tmp/mempool
```

Similarly, we can generate a transaction that would be setting the key `foo` to the value `bar`:
Expand All @@ -192,7 +193,7 @@ cargo run --bin blockstack-cli contract-call b8d99fd45da58038d630d9855d3ca2466e8
And submit it by moving it to the mempool path:

```bash
cp ./tx3.bin /tmp/stacks-testnet-5fc814cf78dc0636/L1/mempool
cp ./tx3.bin /tmp/mempool
```

Finally, we can issue a third transaction, reading the key `foo` again, for ensuring that the previous transaction has successfully updated the state machine:
Expand All @@ -204,7 +205,7 @@ cargo run --bin blockstack-cli contract-call b8d99fd45da58038d630d9855d3ca2466e8
And submit this last transaction by moving it to the mempool path:

```bash
cp ./tx4.bin /tmp/stacks-testnet-5fc814cf78dc0636/L1/mempool
cp ./tx4.bin /tmp/mempool
```

Congratulations, you can now [write your own smart contracts with Clarity](https://docs.blockstack.org/core/smart/overview.html).
Expand All @@ -213,17 +214,19 @@ Congratulations, you can now [write your own smart contracts with Clarity](https

Beyond this Github project,
Blockstack maintains a public [forum](https://forum.blockstack.org) and an
opened [Discord](https://discordapp.com/invite/9r94Xkj) channel. In addition, the project
opened [Discord](https://discordapp.com/invite/9r94Xkj) channel. In addition, the project
maintains a [mailing list](https://blockstack.org/signup) which sends out
community announcements.

The greater Blockstack community regularly hosts in-person
[meetups](https://www.meetup.com/topics/blockstack/). The project's
[meetups](https://www.meetup.com/topics/blockstack/). The project's
[YouTube channel](https://www.youtube.com/channel/UC3J2iHnyt2JtOvtGVf_jpHQ) includes
videos from some of these meetups, as well as video tutorials to help new
users get started and help developers wrap their heads around the system's
design.

For help cross-compiling on memory-constrained devices, please see the community supported documentation here: [Cross Compiling](https://github.com/dantrevino/cross-compiling-stacks-blockchain/blob/master/README.md).

## Further Reading

You can learn more by visiting [the Blockstack Website](https://blockstack.org) and checking out the in-depth articles and documentation:
Expand Down
18 changes: 18 additions & 0 deletions Stacks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@ amount = 100000
[[mstx_balance]]
address = "ST2VHM28V9E5QCRD6C73215KAPSBKQGPWTEE5CMQT"
amount = 10000

# Event dispatcher
# The stacks blockchain can be observed by sidecar processes, notified through TCP socket, of events such as:
# - print
# - stx-transfer / stx-burn
# - ft-mint / ft-transfer
# - nft-mint / nft-transfer
# A demo is available here: https://github.com/blockstack/stacks-blockchain-sidecar
#
# [[events_observer]]
# port = 8080
# address = "127.0.0.1"
# events_keys = [
# "STGT7GSMZG7EA0TS6MVSKT5JC1DCDFGZWJJZXN8A.store::print",
# "STGT7GSMZG7EA0TS6MVSKT5JC1DCDFGZWJJZXN8A.contract.ft-token",
# "STGT7GSMZG7EA0TS6MVSKT5JC1DCDFGZWJJZXN8A.contract.nft-token",
# "stx"
# ]
5 changes: 2 additions & 3 deletions src/burnchains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,9 @@ pub mod test {

let last_snapshot_with_sortition = match parent_block_snapshot {
Some(sn) => sn.clone(),
None => BurnDB::get_last_snapshot_with_sortition(tx, self.block_height - 1, &self.parent_snapshot.burn_header_hash)
.expect("FATAL: failed to read last snapshot with sortition")
None => BurnDB::get_first_block_snapshot(tx).unwrap()
};

// prove on the last-ever sortition's hash to produce the new seed
let proof = miner.make_proof(&leader_key.public_key, &last_snapshot.sortition_hash)
.expect(&format!("FATAL: no private key for {}", leader_key.public_key.to_hex()));
Expand Down
2 changes: 1 addition & 1 deletion src/chainstate/burn/db/burndb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ impl BurnDB {
num_headers
};

let tip_block_hash = tip_snapshot.burn_header_hash.clone();
let tip_block_hash = tip_snapshot.burn_header_hash;
if tip_snapshot.sortition {
ret.push((tip_block_hash.clone(), Some(tip_snapshot.winning_stacks_block_hash)));
}
Expand Down
Loading

0 comments on commit 5f46bab

Please sign in to comment.