diff --git a/.github/actions/bitcoin-int-tests/Dockerfile.rustfmt b/.github/actions/bitcoin-int-tests/Dockerfile.rustfmt index 793d8e4668..456ad19f15 100644 --- a/.github/actions/bitcoin-int-tests/Dockerfile.rustfmt +++ b/.github/actions/bitcoin-int-tests/Dockerfile.rustfmt @@ -9,4 +9,4 @@ RUN rustup component add rustfmt COPY . . -RUN cargo fmt --all -- --check +RUN cargo fmt --all -- --check --config group_imports=StdExternalCrate,imports_granularity=Module diff --git a/.github/workflows/stacks-blockchain-tests.yml b/.github/workflows/stacks-blockchain-tests.yml index 13835da95a..7c90c25bda 100644 --- a/.github/workflows/stacks-blockchain-tests.yml +++ b/.github/workflows/stacks-blockchain-tests.yml @@ -19,6 +19,19 @@ jobs: - name: Checkout the latest code id: git_checkout uses: actions/checkout@v3 + - name: Reclaim disk space + id: cleanup + run: | + sudo apt-get update + sudo apt-get remove -y '^dotnet-.*' + sudo apt-get remove -y '^llvm-.*' + sudo apt-get remove -y 'php.*' + sudo apt-get remove -y '^mongodb-.*' + sudo apt-get remove -y '^mysql-.*' + sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri + sudo apt-get autoremove -y + sudo apt-get clean + docker system prune --force - name: Single full genesis integration test id: full_genesis_test env: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d1812dfc37..ce6dbb2cd0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -101,8 +101,8 @@ you push your code. Follow these instruction to set it up: 2. Change the content of `.git/hooks/pre-commit` to be the following ```sh #!/bin/sh -git diff --name-only --staged | grep '\.rs$' | xargs -P 8 -I {} rustfmt {} --edition 2021 --check --config group_imports=StdExternalCrate || ( - echo 'rustfmt failed: run "cargo fmt --all -- --config group_imports=StdExternalCrate"'; +git diff --name-only --staged | grep '\.rs$' | xargs -P 8 -I {} rustfmt {} --edition 2021 --check --config group_imports=StdExternalCrate,imports_granularity=Module || ( + echo 'rustfmt failed: run "cargo fmt --all -- --config group_imports=StdExternalCrate,imports_granularity=Module"'; exit 1 ) ``` @@ -384,19 +384,24 @@ A test should be marked `#[ignore]` if: ## Formatting -This repository uses the default rustfmt formatting style. PRs will be checked against `rustfmt` and will _fail_ if not -properly formatted. +PRs will be checked against `rustfmt` and will _fail_ if not properly formatted. +Unfortunately, some config options that we require cannot currently be set in `.rustfmt` files currently, so arguments must be passed via the command line. +There is a Makefile target to simplify calling `cargo fmt` with the desired config. You can check the formatting locally via: ```bash -cargo fmt --all -- --check --config group_imports=StdExternalCrate +cargo fmt --all -- --check --config group_imports=StdExternalCrate,imports_granularity=Module +# Or +make fmt-check ``` You can automatically reformat your commit via: ```bash -cargo fmt --all -- --config group_imports=StdExternalCrate +cargo fmt --all -- --config group_imports=StdExternalCrate,imports_granularity=Module +# Or +make fmt ``` ## Comments diff --git a/Cargo.lock b/Cargo.lock index 3210b439f3..cc29c2b768 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -440,32 +440,16 @@ dependencies = [ ] [[package]] -name = "bindgen" -version = "0.64.0" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" -dependencies = [ - "bitflags", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 1.0.109", - "which", -] +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "bitvec" @@ -589,15 +573,6 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfg-if" version = "0.1.10" @@ -650,24 +625,13 @@ dependencies = [ "inout", ] -[[package]] -name = "clang-sys" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "clap" version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "textwrap", "unicode-width", ] @@ -793,6 +757,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -1209,6 +1183,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -1224,7 +1213,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" dependencies = [ - "bitflags", + "bitflags 1.3.2", "fuchsia-zircon-sys", ] @@ -1417,12 +1406,6 @@ version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - [[package]] name = "gloo-timers" version = "0.2.6" @@ -1502,7 +1485,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" dependencies = [ "base64 0.13.1", - "bitflags", + "bitflags 1.3.2", "bytes", "headers-core", "http", @@ -1679,6 +1662,19 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" version = "0.1.53" @@ -1870,12 +1866,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" version = "0.2.140" @@ -1902,16 +1892,6 @@ dependencies = [ "rle-decode-fast", ] -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if 1.0.0", - "winapi 0.3.9", -] - [[package]] name = "libsigner" version = "0.0.1" @@ -2031,12 +2011,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.6.2" @@ -2107,6 +2081,24 @@ dependencies = [ "version_check", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "net2" version = "0.2.38" @@ -2124,23 +2116,13 @@ version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if 1.0.0", "libc", "memoffset 0.6.5", ] -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -2222,6 +2204,50 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "openssl" +version = "0.10.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" +dependencies = [ + "bitflags 2.4.0", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.29", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "overload" version = "0.1.1" @@ -2230,11 +2256,8 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "p256k1" -version = "5.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79583032ab00c9e23e8afadf907e9cdc862c72c01fd57048fb07f1107a05c88a" +version = "5.5.0" dependencies = [ - "bindgen", "bitvec", "bs58 0.4.0", "cc", @@ -2283,12 +2306,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "percent-encoding" version = "2.2.0" @@ -2384,7 +2401,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e1f879b2998099c2d69ab9605d145d5b661195627eccc680002c4918a7fb6fa" dependencies = [ "autocfg", - "bitflags", + "bitflags 1.3.2", "cfg-if 1.0.0", "concurrent-queue", "libc", @@ -2644,7 +2661,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -2653,7 +2670,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -2695,9 +2712,9 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "reqwest" -version = "0.11.20" +version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ "base64 0.21.0", "bytes", @@ -2709,10 +2726,12 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", + "hyper-tls", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -2721,7 +2740,9 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "system-configuration", "tokio", + "tokio-native-tls", "tokio-rustls", "tower-service", "url", @@ -2830,7 +2851,7 @@ version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38ee71cbab2c827ec0ac24e76f82eca723cee92c509a65f67dee393c25112" dependencies = [ - "bitflags", + "bitflags 1.3.2", "byteorder", "fallible-iterator", "fallible-streaming-iterator", @@ -2847,12 +2868,6 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc-hex" version = "2.1.0" @@ -2905,7 +2920,7 @@ version = "0.37.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", @@ -2965,6 +2980,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -3012,6 +3036,29 @@ dependencies = [ "cc", ] +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "0.9.0" @@ -3225,12 +3272,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "shlex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" - [[package]] name = "simple-mutex" version = "1.1.5" @@ -3407,6 +3448,7 @@ dependencies = [ "libstackerdb", "p256k1", "rand_core 0.6.4", + "reqwest", "secp256k1", "serde", "serde_derive", @@ -3416,6 +3458,7 @@ dependencies = [ "slog-json", "slog-term", "stacks-common", + "stackslib", "thiserror", "toml", "tracing", @@ -3580,6 +3623,27 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tap" version = "1.0.1" @@ -3790,6 +3854,16 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.24.1" @@ -4266,17 +4340,6 @@ version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" -[[package]] -name = "which" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" -dependencies = [ - "either", - "libc", - "once_cell", -] - [[package]] name = "winapi" version = "0.2.8" @@ -4499,7 +4562,6 @@ dependencies = [ [[package]] name = "wsts" version = "4.0.0" -source = "git+https://github.com/Trust-Machines/wsts?tag=4.0.0rc2#e87f997781c0e9d9b2951d75059d673296311eec" dependencies = [ "aes-gcm 0.10.2", "bs58 0.5.0", diff --git a/Cargo.toml b/Cargo.toml index 7a87639a02..956eabb5a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,7 @@ opt-level = 3 [profile.release] debug = true + +[patch.crates-io] +p256k1 = { path = "/home/jude/pkg/p256k1/p256k1", version = "5.5.0" } +wsts = { path = "/home/jude/pkg/wsts" } diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..3264146b46 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +# Shortcuts for common commands + +.PHONY: fmt fmt-check + +# Run `cargo fmt` with CLI options not available in rustfmt.toml +fmt: + cargo fmt -- --config group_imports=StdExternalCrate,imports_granularity=Module + +# Run `cargo fmt` with CLI options not available in rustfmt.toml (check only) +fmt-check: + cargo fmt -- --check --config group_imports=StdExternalCrate,imports_granularity=Module diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000000..e59229b3a1 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,82 @@ +# Security Policy + + +## Supported Versions +Please see [Releases](https://github.com/stacks-network/stacks-blockchain/releases). It is recommended to use the [most recently released version](https://github.com/stacks-network/stacks-blockchain/releases/latest). + + +## Reporting a vulnerability +**Please do not file a public issue or PR mentioning the vulnerability.** + +The Stacks Foundation has partnered with [ImmuneFi](https://immunefi.com/) to reward honest researchers who find and responsibly disclose security vulnerabilities in our critical code. Bounties are payable in the Stacks token ([STX](https://www.coingecko.com/en/coins/stacks)) for accepted, high-quality submissions. + +Learn more here: [https://bounty.stacks.org](https://bounty.stacks.org) + +## Want to get in touch? + +Please visit [https://stacks.org/security](https://stacks.org/security) for the most up-to-date information on our security policy. + +You may also contact us with any questions or to report a vulnerabilty using the following key(s): + + +| Name | Fingerprint | +| ------- | ------------------ | +| security@stacks.org | 8A8B 3C3B 803A 0603 8FB5 3F69 357C 80AB 0885 87A | + + +``` +----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBGSBJLgBEACb6bnuvchM5wzmCBh8tvb5Fc90AGmUC9Bfiw85kTNr5N+6Y+fj +Gcyy2ohUEh+5hQE2pJLYzWcEM8ZFomxuwuDkjEkwJHnMofTwPgeP5P9CJUgcOHDa +v/mzzSXze8nhcADiez6QMP1f1m32FoeLpjFyAPkxSzGDv1L8gMHCJn/d1lZyyl52 +1VO6kN6eazEuA9fCCK+ZjUWz5pZCs6QVQ2+3clOoEX+ycomult4/yJhwMHucIPbL +uUGJvpKXkHEi05G2H57mz8sHvz0euRNGTiEUQeVIzaLUmUuViij9KsKk0DSGj3yq +kI+zOcgjAGTMSK00i6bdBV+XZfZlg0uIATr7EGHnb3Lzbvn8lfo/3jaJlQu5elEf +ZlA2nE2dPUfhzY3t8GoroHrbqJaJFd9eZtfTMzwW11KdOzqa0V5FRUkxcBIb81+p +jb2o/YKGWPExX2cHOTYmUdQFM6AtLpif4pMeV11d52vy8LCsjZDwUSZM6lmcg+rL +o2dbBgLvBblHXRtS4UFvx7tHitl5DOk5ZZik3r3jWQmAUXVDBBpq2gaVkponliYv +iVeG+mRLoe+qpvQRMCaw5Rlth0MhqQ26tmpGUIavaFbDqARC8FeIfdov6bUP5/sJ +gaktJrED5T5hNks/N661/AJ8N7JCHJx1exW4TK052PZ2/hHxNSuUEm96VwARAQAB +tClzZWN1cml0eUBzdGFja3Mub3JnIDxzZWN1cml0eUBzdGFja3Mub3JnPokCVAQT +AQgAPhYhBIqLPDuAOgYDj7U/aTV8gKsIhYegBQJkgSS4AhsDBQkHhh87BQsJCAcC +BhUKCQgLAgQWAgMBAh4BAheAAAoJEDV8gKsIhYegWg8P/RsoODRC8QWYnc5oq2Yb +cJSR/0uRcWZVZC/guC553ax89Aro50YsWvd8Z2uakuKKRoc8aPfC4SL1Mufrncwo +9/pIoiB9NQhTAbnp7hBnF5dnIX+Jq4lQIqwG5E36juNiU23qglx3ZZxM5wZrkRi0 +5lsFHpjU4XRkaNgNs6vyiHmtzyR+iESEBY9szfWCRTK8DgOJPLrfDAnc5JWTq7iL +H8pUpClo5p0XFN39lgdhbEISRXaMqY0HJqAI9JKE5UxxRG2uuGbdeHTYu6ji+gz+ +g+gooyVYIVzXVAJHgD9tDsazD+n61epglF0qK0hb+NaRL/2F6KBpmpzY+iDmDkPu +5TTybS52Cm8zSUAsk5w/GSnknep929Cj5hhaD9ijHcLEV0VKSiN0edIPe+Nd57KK +sfggS4l8deD1OjcTxhawRiaKcthdWjm15DzP9WuYEURSpJZAmdSd5Cqx3bSconhW +iYjxAlgZb7t/OJr6N6YQZjga14kwjxia94WNiTz2UQLr/vYAJWQj9RypxL0IrFwr +pJcFnLKec68jLk8opg4LrY9O/gKHQuPDT1EEQ4ssknJAzKxCwrOwCrDvuIzeqzIx +L1mBAtCzF4Q/J1BlmFEIZ7022BycpzPL0VuOrgmyQ6FzEqiKme7Vy/PVWN7H7HhC +qmL2/g9lYt0+gPZazsc8f3NGuQINBGSBJLgBEADTnQe5mX60ClQqigDjAhypkFZY +6k1V850Gp93YsfMYMgzLcyywMo25RT904AF0X72mjF82YZmzOE/b1oSF4ns3nBIg +vCIiEsWTtFMZgerWKcHlYPE0VWR4iGC5DiOLbmrECPQ0JucEErJZWvypgot2R3p/ +hAkEV0CjZp8qObgBf+ViZmfMAkclVtJ5AFB0SQjx6m4ounpKV9euO2db302oMIbM +ssM1F2Dsl7oicAreHOdVZ5OLUkk5nrXmLHtIt6QppPVbWkJA9ArBwAHZ39vLQTBZ +YbehZxWDxzW/HK00CEzb70BwK0HZYFYt9lQwGRUou8dvtk3+nFRsfpAlFoHSLXjp +N+uZBnqQhUeyzT81PkavHpAGTq5ExgT13nyE9vJCPuf5lpthuWiUQYBHu5tUym6G +vHRpT1OyqcbUQUlS+iK24dwxglk2S/NYYOsKyRJ8AhLFQGqMHxlpqNsQ5wxFthZo +ayiP7CwaJFfB5TUe4zWpbMM545BPNQodcB8Njb62tj0ZoAgEbhXerMGrVfUGf6AL +FxcyGhGpjkRI4+e8HfDpiObMw2notIUMXJoYQv3Yf7X/n8QPX2EZDaB8dG43r2Hh +EeEDi6+WOI77LtdVDck71ZXqLukCrusO9HZ6GlB0ohqndRgueGztP82Af3W74Ohj +dEOcK0HC26dKPWhk2wARAQABiQI8BBgBCAAmFiEEios8O4A6BgOPtT9pNXyAqwiF +h6AFAmSBJLgCGwwFCQeGHzsACgkQNXyAqwiFh6CT4A//aOMVH/XIXngvfC/xOdDy +3JnZLtu4kmLfcvxbqEGrNhz1AW4t0Uivt9dgBb4VemgQajhYZyjdLgFhYGvCf446 +V1C79qWa1lwESmSWL63+rXNZMNV+siqnVhICrXw4FhCKP2tfnZ5uT03qTbu0S+9N +4bARjXkfYSxhVqeGmO/ZwuuHXQUojt/XNWBFbbKKM1Y6PlvfWrmX/S2cDAf0QgBd +MMLu7phbUjMzQDsenwiueWaRvDnsQB5GzwOiJheQuKLS1rYlJGnW2cwqjQtQnnC3 +YVb4iCialhAL/GWwjR/r7a6ZxuAB0j2zjKsaxtEMoTaVX3EW3Aoy73dvew0wyakq +OCchiIIJVvB6uXGufqAVVBJAgG7MQIEZLt7M6YSu0gYTdsEnNo7WZYMsX+/NGQ8G +5hguIJZl3MRtax1yPK0e0ergaDaetAhfWwQH2ltAVQColm3LfuLpcyoxYMhdiN86 +ggy4c1t0dS8owuAEdoKScOkOdENYEGF4mkd7nLkU5miaOMxg2NO9prCSpwwxDtt3 +XLkl0yw+0W0rM2Wu5pC0Xw21Cva+uBm3+kfyIRqrtc1Vb3ZrGKzCNQcAvvxq9XM5 +VeE6JLwVj8OP1TFuwmpJJeD5LTZDT0SvmjRB8OuxLwEHHjYtdm0ae0n2Cbou9Y0X +hmf6grobEcyS0PCsLHn3r7Y= +=/YN2 +-----END PGP PUBLIC KEY BLOCK----- +``` + + diff --git a/clarity/src/libclarity.rs b/clarity/src/libclarity.rs index dad6eac908..def9435dbb 100644 --- a/clarity/src/libclarity.rs +++ b/clarity/src/libclarity.rs @@ -63,10 +63,12 @@ pub extern crate stacks_common; pub mod vm; pub mod boot_util { + use std::convert::TryFrom; + + use stacks_common::types::chainstate::StacksAddress; + use crate::vm::representations::ContractName; use crate::vm::types::QualifiedContractIdentifier; - use stacks_common::types::chainstate::StacksAddress; - use std::convert::TryFrom; pub fn boot_code_id(name: &str, mainnet: bool) -> QualifiedContractIdentifier { let addr = boot_code_addr(mainnet); diff --git a/clarity/src/vm/analysis/analysis_db.rs b/clarity/src/vm/analysis/analysis_db.rs index 7fdfbdfab5..b278bc5ef7 100644 --- a/clarity/src/vm/analysis/analysis_db.rs +++ b/clarity/src/vm/analysis/analysis_db.rs @@ -26,7 +26,6 @@ use crate::vm::database::{ use crate::vm::representations::ClarityName; use crate::vm::types::signatures::FunctionSignature; use crate::vm::types::{FunctionType, QualifiedContractIdentifier, TraitIdentifier, TypeSignature}; - use crate::vm::ClarityVersion; pub struct AnalysisDatabase<'a> { diff --git a/clarity/src/vm/analysis/arithmetic_checker/mod.rs b/clarity/src/vm/analysis/arithmetic_checker/mod.rs index d258b39af4..c38451c747 100644 --- a/clarity/src/vm/analysis/arithmetic_checker/mod.rs +++ b/clarity/src/vm/analysis/arithmetic_checker/mod.rs @@ -14,10 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::collections::HashMap; + +pub use super::errors::{ + check_argument_count, check_arguments_at_least, CheckError, CheckErrors, CheckResult, +}; +use super::AnalysisDatabase; use crate::vm::analysis::types::{AnalysisPass, ContractAnalysis}; use crate::vm::functions::define::{DefineFunctions, DefineFunctionsParsed}; -use crate::vm::functions::tuples; -use crate::vm::functions::NativeFunctions; +use crate::vm::functions::{tuples, NativeFunctions}; use crate::vm::representations::SymbolicExpressionType::{ Atom, AtomValue, Field, List, LiteralValue, TraitReference, }; @@ -25,17 +30,9 @@ use crate::vm::representations::{ClarityName, SymbolicExpression, SymbolicExpres use crate::vm::types::{ parse_name_type_pairs, PrincipalData, TupleTypeSignature, TypeSignature, Value, }; - use crate::vm::variables::NativeVariables; -use std::collections::HashMap; - use crate::vm::ClarityVersion; -pub use super::errors::{ - check_argument_count, check_arguments_at_least, CheckError, CheckErrors, CheckResult, -}; -use super::AnalysisDatabase; - #[cfg(test)] mod tests; diff --git a/clarity/src/vm/analysis/arithmetic_checker/tests.rs b/clarity/src/vm/analysis/arithmetic_checker/tests.rs index d1a1de2453..4ad02c08d5 100644 --- a/clarity/src/vm/analysis/arithmetic_checker/tests.rs +++ b/clarity/src/vm/analysis/arithmetic_checker/tests.rs @@ -14,18 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::ClarityVersion; #[cfg(test)] use rstest::rstest; #[cfg(test)] use rstest_reuse::{self, *}; use stacks_common::types::StacksEpochId; -use crate::vm::analysis::mem_type_check; -use crate::vm::analysis::{ - arithmetic_checker::ArithmeticOnlyChecker, arithmetic_checker::Error, - arithmetic_checker::Error::*, ContractAnalysis, -}; +use crate::vm::analysis::arithmetic_checker::Error::*; +use crate::vm::analysis::arithmetic_checker::{ArithmeticOnlyChecker, Error}; +use crate::vm::analysis::{mem_type_check, ContractAnalysis}; use crate::vm::ast::parse; use crate::vm::costs::LimitedCostTracker; use crate::vm::functions::define::DefineFunctions; @@ -33,6 +30,7 @@ use crate::vm::functions::NativeFunctions; use crate::vm::tests::test_clarity_versions; use crate::vm::types::QualifiedContractIdentifier; use crate::vm::variables::NativeVariables; +use crate::vm::ClarityVersion; /// Checks whether or not a contract only contains arithmetic expressions (for example, defining a /// map would not pass this check). diff --git a/clarity/src/vm/analysis/contract_interface_builder/mod.rs b/clarity/src/vm/analysis/contract_interface_builder/mod.rs index 201d2e2316..a418d9f66f 100644 --- a/clarity/src/vm/analysis/contract_interface_builder/mod.rs +++ b/clarity/src/vm/analysis/contract_interface_builder/mod.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::collections::{BTreeMap, BTreeSet}; + use stacks_common::types::StacksEpochId; use crate::vm::analysis::types::ContractAnalysis; @@ -21,10 +23,7 @@ use crate::vm::types::signatures::CallableSubtype; use crate::vm::types::{ FixedFunction, FunctionArg, FunctionType, TupleTypeSignature, TypeSignature, }; -use crate::vm::ClarityName; -use std::collections::{BTreeMap, BTreeSet}; - -use crate::vm::ClarityVersion; +use crate::vm::{ClarityName, ClarityVersion}; pub fn build_contract_interface(contract_analysis: &ContractAnalysis) -> ContractInterface { let mut contract_interface = @@ -180,8 +179,9 @@ impl ContractInterfaceAtomType { } pub fn from_type_signature(sig: &TypeSignature) -> ContractInterfaceAtomType { + use crate::vm::types::SequenceSubtype::*; + use crate::vm::types::StringSubtype::*; use crate::vm::types::TypeSignature::*; - use crate::vm::types::{SequenceSubtype::*, StringSubtype::*}; match sig { NoType => ContractInterfaceAtomType::none, diff --git a/clarity/src/vm/analysis/errors.rs b/clarity/src/vm/analysis/errors.rs index bb51b42b49..9aeb878f2d 100644 --- a/clarity/src/vm/analysis/errors.rs +++ b/clarity/src/vm/analysis/errors.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::{error, fmt}; + use crate::vm::costs::{CostErrors, ExecutionCost}; use crate::vm::diagnostic::{DiagnosableError, Diagnostic}; use crate::vm::representations::SymbolicExpression; use crate::vm::types::{TraitIdentifier, TupleTypeSignature, TypeSignature, Value}; -use std::error; -use std::fmt; pub type CheckResult = Result; diff --git a/clarity/src/vm/analysis/mod.rs b/clarity/src/vm/analysis/mod.rs index b83f4a4fdc..50c5b1e7d5 100644 --- a/clarity/src/vm/analysis/mod.rs +++ b/clarity/src/vm/analysis/mod.rs @@ -24,28 +24,23 @@ pub mod trait_checker; pub mod type_checker; pub mod types; -use crate::vm::database::MemoryBackingStore; use stacks_common::types::StacksEpochId; -pub use self::types::{AnalysisPass, ContractAnalysis}; - -use crate::vm::costs::LimitedCostTracker; -use crate::vm::database::STORE_CONTRACT_SRC_INTERFACE; -use crate::vm::representations::SymbolicExpression; -use crate::vm::types::{QualifiedContractIdentifier, TypeSignature}; -use crate::vm::ClarityVersion; - pub use self::analysis_db::AnalysisDatabase; -pub use self::errors::{CheckError, CheckErrors, CheckResult}; - use self::arithmetic_checker::ArithmeticOnlyChecker; use self::contract_interface_builder::build_contract_interface; +pub use self::errors::{CheckError, CheckErrors, CheckResult}; use self::read_only_checker::ReadOnlyChecker; use self::trait_checker::TraitChecker; use self::type_checker::v2_05::TypeChecker as TypeChecker2_05; use self::type_checker::v2_1::TypeChecker as TypeChecker2_1; -use crate::vm::ast::build_ast_with_rules; -use crate::vm::ast::ASTRules; +pub use self::types::{AnalysisPass, ContractAnalysis}; +use crate::vm::ast::{build_ast_with_rules, ASTRules}; +use crate::vm::costs::LimitedCostTracker; +use crate::vm::database::{MemoryBackingStore, STORE_CONTRACT_SRC_INTERFACE}; +use crate::vm::representations::SymbolicExpression; +use crate::vm::types::{QualifiedContractIdentifier, TypeSignature}; +use crate::vm::ClarityVersion; /// Used by CLI tools like the docs generator. Not used in production pub fn mem_type_check( diff --git a/clarity/src/vm/analysis/read_only_checker/mod.rs b/clarity/src/vm/analysis/read_only_checker/mod.rs index 7b2491f356..8261eb8eec 100644 --- a/clarity/src/vm/analysis/read_only_checker/mod.rs +++ b/clarity/src/vm/analysis/read_only_checker/mod.rs @@ -14,12 +14,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::collections::HashMap; + use stacks_common::types::StacksEpochId; +pub use super::errors::{ + check_argument_count, check_arguments_at_least, CheckError, CheckErrors, CheckResult, +}; +use super::AnalysisDatabase; use crate::vm::analysis::types::{AnalysisPass, ContractAnalysis}; use crate::vm::functions::define::DefineFunctionsParsed; -use crate::vm::functions::tuples; -use crate::vm::functions::NativeFunctions; +use crate::vm::functions::{tuples, NativeFunctions}; use crate::vm::representations::SymbolicExpressionType::{ Atom, AtomValue, Field, List, LiteralValue, TraitReference, }; @@ -27,17 +32,9 @@ use crate::vm::representations::{ClarityName, SymbolicExpression, SymbolicExpres use crate::vm::types::{ parse_name_type_pairs, PrincipalData, TupleTypeSignature, TypeSignature, Value, }; - use crate::vm::variables::NativeVariables; -use std::collections::HashMap; - use crate::vm::ClarityVersion; -pub use super::errors::{ - check_argument_count, check_arguments_at_least, CheckError, CheckErrors, CheckResult, -}; -use super::AnalysisDatabase; - #[cfg(test)] mod tests; diff --git a/clarity/src/vm/analysis/read_only_checker/tests.rs b/clarity/src/vm/analysis/read_only_checker/tests.rs index ea9802da98..828e5d42bc 100644 --- a/clarity/src/vm/analysis/read_only_checker/tests.rs +++ b/clarity/src/vm/analysis/read_only_checker/tests.rs @@ -18,16 +18,15 @@ use rstest::rstest; #[cfg(test)] use rstest_reuse::{self, *}; +use stacks_common::types::StacksEpochId; -use crate::vm::analysis::type_check; use crate::vm::analysis::type_checker::v2_1::tests::mem_type_check; -use crate::vm::analysis::{CheckError, CheckErrors}; +use crate::vm::analysis::{type_check, CheckError, CheckErrors}; use crate::vm::ast::parse; use crate::vm::database::MemoryBackingStore; use crate::vm::tests::test_clarity_versions; use crate::vm::types::QualifiedContractIdentifier; use crate::vm::ClarityVersion; -use stacks_common::types::StacksEpochId; #[test] fn test_argument_count_violations() { diff --git a/clarity/src/vm/analysis/tests/mod.rs b/clarity/src/vm/analysis/tests/mod.rs index 2f64266f78..adb36b94fb 100644 --- a/clarity/src/vm/analysis/tests/mod.rs +++ b/clarity/src/vm/analysis/tests/mod.rs @@ -16,8 +16,7 @@ use crate::vm::analysis::errors::CheckErrors; use crate::vm::analysis::type_checker::v2_1::tests::mem_type_check; -use crate::vm::analysis::AnalysisDatabase; -use crate::vm::analysis::{type_check, ContractAnalysis}; +use crate::vm::analysis::{type_check, AnalysisDatabase, ContractAnalysis}; use crate::vm::ast::parse; #[test] diff --git a/clarity/src/vm/analysis/trait_checker/tests.rs b/clarity/src/vm/analysis/trait_checker/tests.rs index c2f1338616..bc3f996284 100644 --- a/clarity/src/vm/analysis/trait_checker/tests.rs +++ b/clarity/src/vm/analysis/trait_checker/tests.rs @@ -18,17 +18,17 @@ use rstest::rstest; #[cfg(test)] use rstest_reuse::{self, *}; +use stacks_common::types::StacksEpochId; +use crate::vm::analysis::contract_interface_builder::build_contract_interface; use crate::vm::analysis::errors::CheckErrors; -use crate::vm::analysis::{contract_interface_builder::build_contract_interface, AnalysisDatabase}; -use crate::vm::analysis::{type_check, CheckError}; +use crate::vm::analysis::{type_check, AnalysisDatabase, CheckError}; use crate::vm::ast::errors::ParseErrors; use crate::vm::ast::{build_ast, parse}; use crate::vm::database::MemoryBackingStore; use crate::vm::tests::test_clarity_versions; use crate::vm::types::{QualifiedContractIdentifier, TypeSignature}; use crate::vm::ClarityVersion; -use stacks_common::types::StacksEpochId; #[apply(test_clarity_versions)] fn test_dynamic_dispatch_by_defining_trait( diff --git a/clarity/src/vm/analysis/type_checker/contexts.rs b/clarity/src/vm/analysis/type_checker/contexts.rs index 8df33bad6d..03968a186c 100644 --- a/clarity/src/vm/analysis/type_checker/contexts.rs +++ b/clarity/src/vm/analysis/type_checker/contexts.rs @@ -20,11 +20,8 @@ use stacks_common::types::StacksEpochId; use crate::vm::analysis::errors::{CheckError, CheckErrors, CheckResult}; use crate::vm::types::signatures::CallableSubtype; -use crate::vm::{ - types::{TraitIdentifier, TypeSignature}, - ClarityName, SymbolicExpression, -}; -use crate::vm::{ClarityVersion, MAX_CONTEXT_DEPTH}; +use crate::vm::types::{TraitIdentifier, TypeSignature}; +use crate::vm::{ClarityName, ClarityVersion, SymbolicExpression, MAX_CONTEXT_DEPTH}; #[derive(Debug, PartialEq, Eq, Clone)] pub struct TypeMap { diff --git a/clarity/src/vm/analysis/type_checker/mod.rs b/clarity/src/vm/analysis/type_checker/mod.rs index 70ed9e1759..862d4d7b33 100644 --- a/clarity/src/vm/analysis/type_checker/mod.rs +++ b/clarity/src/vm/analysis/type_checker/mod.rs @@ -20,23 +20,20 @@ pub mod v2_1; use stacks_common::types::StacksEpochId; -use crate::vm::{ - costs::{analysis_typecheck_cost, CostTracker, LimitedCostTracker}, - types::{ - signatures::{CallableSubtype, FunctionArgSignature, FunctionReturnsSignature}, - FixedFunction, FunctionType, PrincipalData, SequenceSubtype, StringSubtype, TypeSignature, - }, - ClarityVersion, Value, +use super::errors::{ + check_argument_count, check_arguments_at_least, check_arguments_at_most, CheckError, + CheckErrors, CheckResult, }; - pub use super::types::{AnalysisPass, ContractAnalysis}; -use super::{ - errors::{ - check_argument_count, check_arguments_at_least, check_arguments_at_most, CheckError, - CheckErrors, CheckResult, - }, - AnalysisDatabase, +use super::AnalysisDatabase; +use crate::vm::costs::{analysis_typecheck_cost, CostTracker, LimitedCostTracker}; +use crate::vm::types::signatures::{ + CallableSubtype, FunctionArgSignature, FunctionReturnsSignature, +}; +use crate::vm::types::{ + FixedFunction, FunctionType, PrincipalData, SequenceSubtype, StringSubtype, TypeSignature, }; +use crate::vm::{ClarityVersion, Value}; impl FunctionType { pub fn check_args( diff --git a/clarity/src/vm/analysis/type_checker/v2_05/contexts.rs b/clarity/src/vm/analysis/type_checker/v2_05/contexts.rs index 743039476e..8e23dd0824 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/contexts.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/contexts.rs @@ -14,15 +14,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::representations::{ClarityName, SymbolicExpression}; -use crate::vm::types::signatures::FunctionSignature; -use crate::vm::types::{FunctionType, TraitIdentifier, TypeSignature}; use std::collections::{BTreeMap, HashMap, HashSet}; -use crate::vm::contexts::MAX_CONTEXT_DEPTH; - use crate::vm::analysis::errors::{CheckError, CheckErrors, CheckResult}; use crate::vm::analysis::types::ContractAnalysis; +use crate::vm::contexts::MAX_CONTEXT_DEPTH; +use crate::vm::representations::{ClarityName, SymbolicExpression}; +use crate::vm::types::signatures::FunctionSignature; +use crate::vm::types::{FunctionType, TraitIdentifier, TypeSignature}; pub struct ContractContext { map_types: HashMap, diff --git a/clarity/src/vm/analysis/type_checker/v2_05/mod.rs b/clarity/src/vm/analysis/type_checker/v2_05/mod.rs index 243003ce83..ad80733f80 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/mod.rs @@ -18,8 +18,21 @@ pub mod contexts; //mod maps; pub mod natives; +use std::collections::{BTreeMap, HashMap}; +use std::convert::TryInto; + use stacks_common::types::StacksEpochId; +use self::contexts::ContractContext; +pub use self::natives::{SimpleNativeFunction, TypedNativeFunction}; +use super::contexts::{TypeMap, TypingContext}; +use super::{AnalysisPass, ContractAnalysis}; +pub use crate::vm::analysis::errors::{ + check_argument_count, check_arguments_at_least, CheckError, CheckErrors, CheckResult, +}; +use crate::vm::analysis::AnalysisDatabase; +use crate::vm::contexts::Environment; +use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{ analysis_typecheck_cost, cost_functions, runtime_cost, ClarityCostFunctionReference, CostErrors, CostOverflowingMath, CostTracker, ExecutionCost, LimitedCostTracker, @@ -37,22 +50,6 @@ use crate::vm::types::{ }; use crate::vm::variables::NativeVariables; use crate::vm::ClarityVersion; -use std::collections::{BTreeMap, HashMap}; -use std::convert::TryInto; - -use super::{AnalysisPass, ContractAnalysis}; -use crate::vm::analysis::AnalysisDatabase; - -use self::contexts::ContractContext; -use super::contexts::{TypeMap, TypingContext}; - -pub use self::natives::{SimpleNativeFunction, TypedNativeFunction}; - -pub use crate::vm::analysis::errors::{ - check_argument_count, check_arguments_at_least, CheckError, CheckErrors, CheckResult, -}; -use crate::vm::contexts::Environment; -use crate::vm::costs::cost_functions::ClarityCostFunction; #[cfg(test)] mod tests; diff --git a/clarity/src/vm/analysis/type_checker/v2_05/natives/maps.rs b/clarity/src/vm/analysis/type_checker/v2_05/natives/maps.rs index 556a8766b8..497a01da2b 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/natives/maps.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/natives/maps.rs @@ -16,19 +16,16 @@ use stacks_common::types::StacksEpochId; -use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; -use crate::vm::types::{PrincipalData, TypeSignature, Value}; - -use crate::vm::functions::tuples; - use super::check_special_tuple_cons; use crate::vm::analysis::type_checker::v2_05::{ check_arguments_at_least, no_type, CheckError, CheckErrors, TypeChecker, TypeResult, TypingContext, }; - use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{analysis_typecheck_cost, cost_functions, runtime_cost}; +use crate::vm::functions::tuples; +use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; +use crate::vm::types::{PrincipalData, TypeSignature, Value}; pub fn check_special_fetch_entry( checker: &mut TypeChecker, diff --git a/clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs b/clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs index f1dcc89c83..67a90ae5a5 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/natives/mod.rs @@ -14,12 +14,18 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::convert::TryFrom; + use stacks_common::types::StacksEpochId; use super::{ check_argument_count, check_arguments_at_least, no_type, TypeChecker, TypeResult, TypingContext, }; use crate::vm::analysis::errors::{CheckError, CheckErrors, CheckResult}; +use crate::vm::costs::cost_functions::ClarityCostFunction; +use crate::vm::costs::{ + analysis_typecheck_cost, cost_functions, runtime_cost, CostOverflowingMath, +}; use crate::vm::errors::{Error as InterpError, RuntimeErrorType}; use crate::vm::functions::{handle_binding_list, NativeFunctions}; use crate::vm::types::{ @@ -28,12 +34,6 @@ use crate::vm::types::{ MAX_VALUE_SIZE, }; use crate::vm::{ClarityName, ClarityVersion, SymbolicExpression, SymbolicExpressionType}; -use std::convert::TryFrom; - -use crate::vm::costs::cost_functions::ClarityCostFunction; -use crate::vm::costs::{ - analysis_typecheck_cost, cost_functions, runtime_cost, CostOverflowingMath, -}; mod assets; mod maps; diff --git a/clarity/src/vm/analysis/type_checker/v2_05/natives/options.rs b/clarity/src/vm/analysis/type_checker/v2_05/natives/options.rs index 27fe92f9ce..b04f38b44f 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/natives/options.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/natives/options.rs @@ -16,16 +16,14 @@ use stacks_common::types::StacksEpochId; -use crate::vm::representations::{ClarityName, SymbolicExpression}; -use crate::vm::types::TypeSignature; - use crate::vm::analysis::type_checker::v2_05::{ check_argument_count, check_arguments_at_least, no_type, CheckError, CheckErrors, TypeChecker, TypeResult, TypingContext, }; - use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{analysis_typecheck_cost, cost_functions, runtime_cost}; +use crate::vm::representations::{ClarityName, SymbolicExpression}; +use crate::vm::types::TypeSignature; pub fn check_special_okay( checker: &mut TypeChecker, diff --git a/clarity/src/vm/analysis/type_checker/v2_05/natives/sequences.rs b/clarity/src/vm/analysis/type_checker/v2_05/natives/sequences.rs index 7f865526b2..48978dcef1 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/natives/sequences.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/natives/sequences.rs @@ -14,26 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use stacks_common::types::StacksEpochId; +use std::convert::{TryFrom, TryInto}; -use crate::vm::functions::NativeFunctions; -use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; -pub use crate::vm::types::signatures::{BufferLength, ListTypeData, StringUTF8Length, BUFF_1}; -use crate::vm::types::{FunctionType, TypeSignature}; -use crate::vm::types::{SequenceSubtype::*, StringSubtype::*}; -use crate::vm::types::{Value, MAX_VALUE_SIZE}; -use crate::vm::ClarityVersion; -use std::convert::TryFrom; -use std::convert::TryInto; +use stacks_common::types::StacksEpochId; use super::{SimpleNativeFunction, TypedNativeFunction}; use crate::vm::analysis::type_checker::v2_05::{ check_argument_count, check_arguments_at_least, no_type, CheckErrors, CheckResult, TypeChecker, TypeResult, TypingContext, }; - use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{analysis_typecheck_cost, cost_functions, runtime_cost}; +use crate::vm::functions::NativeFunctions; +use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; +pub use crate::vm::types::signatures::{BufferLength, ListTypeData, StringUTF8Length, BUFF_1}; +use crate::vm::types::SequenceSubtype::*; +use crate::vm::types::StringSubtype::*; +use crate::vm::types::{FunctionType, TypeSignature, Value, MAX_VALUE_SIZE}; +use crate::vm::ClarityVersion; fn get_simple_native_or_user_define( function_name: &str, diff --git a/clarity/src/vm/analysis/type_checker/v2_05/tests/assets.rs b/clarity/src/vm/analysis/type_checker/v2_05/tests/assets.rs index a858c531d9..918e099671 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/tests/assets.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/tests/assets.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::convert::TryInto; + use stacks_common::types::StacksEpochId; use crate::vm::analysis::errors::CheckErrors; @@ -24,7 +26,6 @@ use crate::vm::types::{ QualifiedContractIdentifier, SequenceSubtype, StringSubtype, TypeSignature, }; use crate::vm::ClarityVersion; -use std::convert::TryInto; fn string_ascii_type(size: u32) -> TypeSignature { TypeSignature::SequenceType(SequenceSubtype::StringType(StringSubtype::ASCII( diff --git a/clarity/src/vm/analysis/type_checker/v2_05/tests/contracts.rs b/clarity/src/vm/analysis/type_checker/v2_05/tests/contracts.rs index 73c109382c..edab6db397 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/tests/contracts.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/tests/contracts.rs @@ -14,23 +14,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use assert_json_diff; -use serde_json; use stacks_common::types::StacksEpochId; +use {assert_json_diff, serde_json}; +use crate::vm::analysis::contract_interface_builder::build_contract_interface; use crate::vm::analysis::errors::CheckErrors; -use crate::vm::analysis::mem_type_check; -use crate::vm::analysis::type_check; -use crate::vm::analysis::{contract_interface_builder::build_contract_interface, AnalysisDatabase}; +use crate::vm::analysis::{ + mem_type_check, type_check, AnalysisDatabase, CheckError, ContractAnalysis, +}; use crate::vm::ast::parse; +use crate::vm::costs::LimitedCostTracker; use crate::vm::database::MemoryBackingStore; use crate::vm::types::QualifiedContractIdentifier; -use crate::vm::ClarityVersion; -use crate::vm::{ - analysis::{CheckError, ContractAnalysis}, - costs::LimitedCostTracker, - SymbolicExpression, -}; +use crate::vm::{ClarityVersion, SymbolicExpression}; const SIMPLE_TOKENS: &str = "(define-map tokens { account: principal } { balance: uint }) (define-read-only (my-get-token-balance (account principal)) diff --git a/clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs b/clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs index 6e321e50c6..22b87e4256 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/tests/mod.rs @@ -14,30 +14,28 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::convert::TryInto; + use stacks_common::types::StacksEpochId; use crate::vm::analysis::errors::CheckErrors; -use crate::vm::analysis::mem_type_check; -use crate::vm::analysis::type_check; use crate::vm::analysis::type_checker::v2_05::{TypeChecker, TypeResult, TypingContext}; use crate::vm::analysis::types::ContractAnalysis; -use crate::vm::analysis::AnalysisDatabase; +use crate::vm::analysis::{mem_type_check, type_check, AnalysisDatabase}; use crate::vm::ast::errors::ParseErrors; use crate::vm::ast::{build_ast, parse}; use crate::vm::contexts::OwnedEnvironment; +use crate::vm::database::MemoryBackingStore; use crate::vm::representations::SymbolicExpression; +use crate::vm::types::SequenceSubtype::*; +use crate::vm::types::StringSubtype::*; +use crate::vm::types::TypeSignature::{BoolType, IntType, PrincipalType, SequenceType, UIntType}; use crate::vm::types::{ FixedFunction, FunctionType, PrincipalData, QualifiedContractIdentifier, TypeSignature, Value, BUFF_32, BUFF_64, }; use crate::vm::ClarityVersion; -use crate::vm::database::MemoryBackingStore; -use crate::vm::types::TypeSignature::{BoolType, IntType, PrincipalType, SequenceType, UIntType}; -use crate::vm::types::{SequenceSubtype::*, StringSubtype::*}; - -use std::convert::TryInto; - mod assets; mod contracts; diff --git a/clarity/src/vm/analysis/type_checker/v2_1/contexts.rs b/clarity/src/vm/analysis/type_checker/v2_1/contexts.rs index 3218794b67..95b856b88b 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/contexts.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/contexts.rs @@ -14,16 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::representations::{ClarityName, SymbolicExpression}; -use crate::vm::types::signatures::{CallableSubtype, FunctionSignature}; -use crate::vm::types::{FunctionType, QualifiedContractIdentifier, TraitIdentifier, TypeSignature}; -use crate::vm::ClarityVersion; use std::collections::{BTreeMap, HashMap, HashSet}; -use crate::vm::contexts::MAX_CONTEXT_DEPTH; - use crate::vm::analysis::errors::{CheckError, CheckErrors, CheckResult}; use crate::vm::analysis::types::ContractAnalysis; +use crate::vm::contexts::MAX_CONTEXT_DEPTH; +use crate::vm::representations::{ClarityName, SymbolicExpression}; +use crate::vm::types::signatures::{CallableSubtype, FunctionSignature}; +use crate::vm::types::{FunctionType, QualifiedContractIdentifier, TraitIdentifier, TypeSignature}; +use crate::vm::ClarityVersion; enum TraitContext { /// Traits stored in this context use the trait type-checking behavior defined in Clarity1 diff --git a/clarity/src/vm/analysis/type_checker/v2_1/mod.rs b/clarity/src/vm/analysis/type_checker/v2_1/mod.rs index 457b18dae4..1686c5c2a2 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/mod.rs @@ -17,8 +17,22 @@ pub mod contexts; pub mod natives; +use std::collections::{BTreeMap, HashMap}; +use std::convert::TryInto; + use stacks_common::types::StacksEpochId; +use self::contexts::ContractContext; +pub use self::natives::{SimpleNativeFunction, TypedNativeFunction}; +use super::contexts::{TypeMap, TypingContext}; +use super::{AnalysisPass, ContractAnalysis}; +pub use crate::vm::analysis::errors::{ + check_argument_count, check_arguments_at_least, check_arguments_at_most, CheckError, + CheckErrors, CheckResult, +}; +use crate::vm::analysis::AnalysisDatabase; +use crate::vm::contexts::Environment; +use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{ analysis_typecheck_cost, cost_functions, runtime_cost, ClarityCostFunctionReference, CostErrors, CostOverflowingMath, CostTracker, ExecutionCost, LimitedCostTracker, @@ -39,25 +53,8 @@ use crate::vm::types::{ TypeSignature, Value, MAX_TYPE_DEPTH, }; use crate::vm::variables::NativeVariables; -use std::collections::{BTreeMap, HashMap}; -use std::convert::TryInto; - use crate::vm::ClarityVersion; -use self::contexts::ContractContext; -use super::contexts::{TypeMap, TypingContext}; -use super::{AnalysisPass, ContractAnalysis}; -use crate::vm::analysis::AnalysisDatabase; - -pub use self::natives::{SimpleNativeFunction, TypedNativeFunction}; - -pub use crate::vm::analysis::errors::{ - check_argument_count, check_arguments_at_least, check_arguments_at_most, CheckError, - CheckErrors, CheckResult, -}; -use crate::vm::contexts::Environment; -use crate::vm::costs::cost_functions::ClarityCostFunction; - #[cfg(test)] pub mod tests; diff --git a/clarity/src/vm/analysis/type_checker/v2_1/natives/assets.rs b/clarity/src/vm/analysis/type_checker/v2_1/natives/assets.rs index f22ab4104e..65ad452332 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/natives/assets.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/natives/assets.rs @@ -14,8 +14,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use super::{no_type, FunctionType, TypeChecker, TypeResult, TypingContext}; +use stacks_common::consts::TOKEN_TRANSFER_MEMO_LENGTH; +use super::{no_type, FunctionType, TypeChecker, TypeResult, TypingContext}; use crate::vm::analysis::errors::{check_argument_count, CheckError, CheckErrors, CheckResult}; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{cost_functions, runtime_cost}; @@ -24,7 +25,6 @@ use crate::vm::types::{ BlockInfoProperty, BufferLength, SequenceSubtype, TupleTypeSignature, TypeSignature, MAX_VALUE_SIZE, }; -use stacks_common::consts::TOKEN_TRANSFER_MEMO_LENGTH; pub fn check_special_get_owner( checker: &mut TypeChecker, diff --git a/clarity/src/vm/analysis/type_checker/v2_1/natives/maps.rs b/clarity/src/vm/analysis/type_checker/v2_1/natives/maps.rs index 767fec341a..7ce4cfad22 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/natives/maps.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/natives/maps.rs @@ -16,18 +16,15 @@ use stacks_common::types::StacksEpochId; -use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; -use crate::vm::types::{PrincipalData, TypeSignature, Value}; - -use crate::vm::functions::tuples; - use super::check_special_tuple_cons; use crate::vm::analysis::type_checker::v2_1::{ check_arguments_at_least, CheckError, CheckErrors, TypeChecker, TypeResult, TypingContext, }; - use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{analysis_typecheck_cost, cost_functions, runtime_cost}; +use crate::vm::functions::tuples; +use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; +use crate::vm::types::{PrincipalData, TypeSignature, Value}; pub fn check_special_fetch_entry( checker: &mut TypeChecker, diff --git a/clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs b/clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs index 948fb52732..55401f1817 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/natives/mod.rs @@ -14,21 +14,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::convert::TryFrom; + use stacks_common::types::StacksEpochId; use super::{ check_argument_count, check_arguments_at_least, check_arguments_at_most, no_type, TypeChecker, TypeResult, TypingContext, }; -use std::convert::TryFrom; - use crate::vm::analysis::errors::{CheckError, CheckErrors, CheckResult}; +use crate::vm::costs::cost_functions::ClarityCostFunction; +use crate::vm::costs::{ + analysis_typecheck_cost, cost_functions, runtime_cost, CostOverflowingMath, +}; use crate::vm::errors::{Error as InterpError, RuntimeErrorType}; use crate::vm::functions::{handle_binding_list, NativeFunctions}; use crate::vm::types::signatures::{ - CallableSubtype, FunctionArgSignature, FunctionReturnsSignature, SequenceSubtype, + CallableSubtype, FunctionArgSignature, FunctionReturnsSignature, SequenceSubtype, ASCII_40, + UTF8_40, }; -use crate::vm::types::signatures::{ASCII_40, UTF8_40}; use crate::vm::types::TypeSignature::SequenceType; use crate::vm::types::{ BlockInfoProperty, BufferLength, BurnBlockInfoProperty, FixedFunction, FunctionArg, @@ -37,11 +41,6 @@ use crate::vm::types::{ }; use crate::vm::{ClarityName, ClarityVersion, SymbolicExpression, SymbolicExpressionType}; -use crate::vm::costs::cost_functions::ClarityCostFunction; -use crate::vm::costs::{ - analysis_typecheck_cost, cost_functions, runtime_cost, CostOverflowingMath, -}; - mod assets; mod conversions; mod maps; diff --git a/clarity/src/vm/analysis/type_checker/v2_1/natives/options.rs b/clarity/src/vm/analysis/type_checker/v2_1/natives/options.rs index 8b2ab6ab18..207308745f 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/natives/options.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/natives/options.rs @@ -16,19 +16,17 @@ use stacks_common::types::StacksEpochId; -use crate::vm::representations::{ClarityName, SymbolicExpression}; -use crate::vm::types::TypeSignature; -use crate::vm::ClarityVersion; - use super::{ check_argument_count, check_arguments_at_least, no_type, CheckError, CheckErrors, TypeChecker, TypeResult, }; use crate::vm::analysis::type_checker::contexts::TypingContext; - use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{analysis_typecheck_cost, cost_functions, runtime_cost}; +use crate::vm::representations::{ClarityName, SymbolicExpression}; use crate::vm::types::signatures::CallableSubtype; +use crate::vm::types::TypeSignature; +use crate::vm::ClarityVersion; pub fn check_special_okay( checker: &mut TypeChecker, diff --git a/clarity/src/vm/analysis/type_checker/v2_1/natives/sequences.rs b/clarity/src/vm/analysis/type_checker/v2_1/natives/sequences.rs index 66b8c80214..5317487d73 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/natives/sequences.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/natives/sequences.rs @@ -14,25 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use stacks_common::types::StacksEpochId; +use std::convert::{TryFrom, TryInto}; -use crate::vm::functions::NativeFunctions; -use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; -pub use crate::vm::types::signatures::{BufferLength, ListTypeData, StringUTF8Length, BUFF_1}; -use crate::vm::types::{FunctionType, TypeSignature}; -use crate::vm::types::{SequenceSubtype::*, StringSubtype::*}; -use crate::vm::types::{Value, MAX_VALUE_SIZE}; -use std::convert::TryFrom; -use std::convert::TryInto; +use stacks_common::types::StacksEpochId; use super::{SimpleNativeFunction, TypedNativeFunction}; use crate::vm::analysis::type_checker::v2_1::{ check_argument_count, check_arguments_at_least, CheckErrors, CheckResult, TypeChecker, TypeResult, TypingContext, }; - use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{analysis_typecheck_cost, cost_functions, runtime_cost}; +use crate::vm::functions::NativeFunctions; +use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; +pub use crate::vm::types::signatures::{BufferLength, ListTypeData, StringUTF8Length, BUFF_1}; +use crate::vm::types::SequenceSubtype::*; +use crate::vm::types::StringSubtype::*; +use crate::vm::types::{FunctionType, TypeSignature, Value, MAX_VALUE_SIZE}; use crate::vm::ClarityVersion; fn get_simple_native_or_user_define( diff --git a/clarity/src/vm/analysis/type_checker/v2_1/tests/assets.rs b/clarity/src/vm/analysis/type_checker/v2_1/tests/assets.rs index aed8e3c014..8989fb295e 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/tests/assets.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/tests/assets.rs @@ -14,12 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use super::contracts::type_check; +use std::convert::TryInto; + #[cfg(test)] use rstest::rstest; #[cfg(test)] use rstest_reuse::{self, *}; +use stacks_common::types::StacksEpochId; +use super::contracts::type_check; use crate::vm::analysis::errors::CheckErrors; use crate::vm::analysis::type_checker::v2_1::tests::mem_type_check; use crate::vm::analysis::AnalysisDatabase; @@ -30,8 +33,6 @@ use crate::vm::types::{ QualifiedContractIdentifier, SequenceSubtype, StringSubtype, TypeSignature, }; use crate::vm::ClarityVersion; -use stacks_common::types::StacksEpochId; -use std::convert::TryInto; fn string_ascii_type(size: u32) -> TypeSignature { TypeSignature::SequenceType(SequenceSubtype::StringType(StringSubtype::ASCII( diff --git a/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs b/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs index eb6473e8a1..6f700df9a3 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/tests/contracts.rs @@ -17,14 +17,18 @@ use std::convert::TryFrom; use std::fs::read_to_string; -use assert_json_diff; -use serde_json; +use stacks_common::types::StacksEpochId; +use {assert_json_diff, serde_json}; +use crate::vm::analysis::contract_interface_builder::build_contract_interface; use crate::vm::analysis::errors::CheckErrors; use crate::vm::analysis::type_checker::v2_1::tests::mem_type_check; -use crate::vm::analysis::{contract_interface_builder::build_contract_interface, AnalysisDatabase}; -use crate::vm::analysis::{mem_type_check as mem_run_analysis, run_analysis, CheckResult}; +use crate::vm::analysis::{ + mem_type_check as mem_run_analysis, run_analysis, AnalysisDatabase, CheckError, CheckResult, + ContractAnalysis, +}; use crate::vm::ast::parse; +use crate::vm::costs::LimitedCostTracker; use crate::vm::database::MemoryBackingStore; use crate::vm::errors::Error; use crate::vm::tests::test_clarity_versions; @@ -32,13 +36,7 @@ use crate::vm::types::signatures::CallableSubtype; use crate::vm::types::{ PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, TypeSignature, }; -use crate::vm::ContractName; -use crate::vm::{ - analysis::{CheckError, ContractAnalysis}, - costs::LimitedCostTracker, - ClarityVersion, SymbolicExpression, -}; -use stacks_common::types::StacksEpochId; +use crate::vm::{ClarityVersion, ContractName, SymbolicExpression}; fn mem_type_check_v1(snippet: &str) -> CheckResult<(Option, ContractAnalysis)> { mem_run_analysis(snippet, ClarityVersion::Clarity1, StacksEpochId::latest()) diff --git a/clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs b/clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs index 4aff12aef5..24263c7a8d 100644 --- a/clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_1/tests/mod.rs @@ -14,42 +14,37 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::convert::{TryFrom, TryInto}; + #[cfg(test)] use rstest::rstest; #[cfg(test)] use rstest_reuse::{self, *}; +use stacks_common::types::StacksEpochId; +use super::CheckResult; use crate::vm::analysis::errors::CheckErrors; -use crate::vm::analysis::mem_type_check as mem_run_analysis; use crate::vm::analysis::type_checker::v2_1::{TypeChecker, TypeResult, TypingContext}; +use crate::vm::analysis::type_checker::SequenceSubtype; use crate::vm::analysis::types::ContractAnalysis; -use crate::vm::analysis::AnalysisDatabase; +use crate::vm::analysis::{mem_type_check as mem_run_analysis, AnalysisDatabase}; use crate::vm::ast::errors::ParseErrors; use crate::vm::ast::{build_ast, parse}; use crate::vm::contexts::OwnedEnvironment; +use crate::vm::database::MemoryBackingStore; use crate::vm::representations::SymbolicExpression; +use crate::vm::tests::test_clarity_versions; +use crate::vm::types::signatures::TypeSignature::OptionalType; +use crate::vm::types::signatures::{ListTypeData, StringUTF8Length}; +use crate::vm::types::SequenceSubtype::*; +use crate::vm::types::StringSubtype::*; +use crate::vm::types::TypeSignature::{BoolType, IntType, PrincipalType, SequenceType, UIntType}; +use crate::vm::types::Value::Sequence; use crate::vm::types::{ BufferLength, FixedFunction, FunctionType, PrincipalData, QualifiedContractIdentifier, TraitIdentifier, TypeSignature, Value, BUFF_1, BUFF_20, BUFF_21, BUFF_32, BUFF_64, }; -use crate::vm::{execute_v2, ClarityName}; -use stacks_common::types::StacksEpochId; - -use crate::vm::database::MemoryBackingStore; -use crate::vm::types::TypeSignature::{BoolType, IntType, PrincipalType, SequenceType, UIntType}; -use crate::vm::types::{SequenceSubtype::*, StringSubtype::*}; - -use crate::vm::types::signatures::TypeSignature::OptionalType; -use crate::vm::types::signatures::{ListTypeData, StringUTF8Length}; -use crate::vm::types::Value::Sequence; -use std::convert::TryFrom; -use std::convert::TryInto; - -use super::CheckResult; -use crate::vm::ClarityVersion; - -use crate::vm::analysis::type_checker::SequenceSubtype; -use crate::vm::tests::test_clarity_versions; +use crate::vm::{execute_v2, ClarityName, ClarityVersion}; mod assets; pub mod contracts; diff --git a/clarity/src/vm/analysis/types.rs b/clarity/src/vm/analysis/types.rs index 6771c5c514..f82f7f0591 100644 --- a/clarity/src/vm/analysis/types.rs +++ b/clarity/src/vm/analysis/types.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::collections::{BTreeMap, BTreeSet, HashMap}; + use stacks_common::types::StacksEpochId; use crate::vm::analysis::analysis_db::AnalysisDatabase; @@ -24,7 +26,6 @@ use crate::vm::costs::{CostTracker, ExecutionCost, LimitedCostTracker}; use crate::vm::types::signatures::FunctionSignature; use crate::vm::types::{FunctionType, QualifiedContractIdentifier, TraitIdentifier, TypeSignature}; use crate::vm::{ClarityName, ClarityVersion, SymbolicExpression}; -use std::collections::{BTreeMap, BTreeSet, HashMap}; const DESERIALIZE_FAIL_MESSAGE: &str = "PANIC: Failed to deserialize bad database data in contract analysis."; @@ -269,13 +270,11 @@ impl ContractAnalysis { #[cfg(test)] mod test { use super::*; - use crate::vm::{ - analysis::ContractAnalysis, - costs::LimitedCostTracker, - types::{ - signatures::CallableSubtype, FixedFunction, FunctionArg, QualifiedContractIdentifier, - StandardPrincipalData, - }, + use crate::vm::analysis::ContractAnalysis; + use crate::vm::costs::LimitedCostTracker; + use crate::vm::types::signatures::CallableSubtype; + use crate::vm::types::{ + FixedFunction, FunctionArg, QualifiedContractIdentifier, StandardPrincipalData, }; #[test] diff --git a/clarity/src/vm/ast/definition_sorter/mod.rs b/clarity/src/vm/ast/definition_sorter/mod.rs index b63a96d80e..b7d5b67387 100644 --- a/clarity/src/vm/ast/definition_sorter/mod.rs +++ b/clarity/src/vm/ast/definition_sorter/mod.rs @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::collections::{HashMap, HashSet}; +use std::iter::FromIterator; + use crate::vm::ast::errors::{ParseError, ParseErrors, ParseResult}; use crate::vm::ast::types::{BuildASTPass, ContractAST}; use crate::vm::costs::cost_functions::ClarityCostFunction; @@ -26,9 +29,6 @@ use crate::vm::representations::PreSymbolicExpressionType::{ }; use crate::vm::representations::{ClarityName, PreSymbolicExpression}; use crate::vm::types::Value; -use std::collections::{HashMap, HashSet}; -use std::iter::FromIterator; - use crate::vm::ClarityVersion; #[cfg(test)] diff --git a/clarity/src/vm/ast/definition_sorter/tests.rs b/clarity/src/vm/ast/definition_sorter/tests.rs index 77e8f8cde5..02996004a7 100644 --- a/clarity/src/vm/ast/definition_sorter/tests.rs +++ b/clarity/src/vm/ast/definition_sorter/tests.rs @@ -21,8 +21,7 @@ use rstest_reuse::{self, *}; use crate::vm::analysis::type_checker::v2_1::tests::mem_type_check as run_analysis_helper; use crate::vm::ast::definition_sorter::DefinitionSorter; -use crate::vm::ast::errors::ParseErrors; -use crate::vm::ast::errors::ParseResult; +use crate::vm::ast::errors::{ParseErrors, ParseResult}; use crate::vm::ast::expression_identifier::ExpressionIdentifier; use crate::vm::ast::parser; use crate::vm::ast::types::{BuildASTPass, ContractAST}; diff --git a/clarity/src/vm/ast/errors.rs b/clarity/src/vm/ast/errors.rs index 95f2ec2a43..ce34f09e80 100644 --- a/clarity/src/vm/ast/errors.rs +++ b/clarity/src/vm/ast/errors.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::{error, fmt}; + use crate::vm::ast::parser::v2::lexer::error::LexerError; use crate::vm::ast::parser::v2::lexer::token::Token; use crate::vm::costs::{CostErrors, ExecutionCost}; @@ -21,8 +23,6 @@ use crate::vm::diagnostic::{DiagnosableError, Diagnostic, Level}; use crate::vm::representations::{PreSymbolicExpression, Span}; use crate::vm::types::{TupleTypeSignature, TypeSignature}; use crate::vm::MAX_CALL_STACK_DEPTH; -use std::error; -use std::fmt; pub type ParseResult = Result; diff --git a/clarity/src/vm/ast/mod.rs b/clarity/src/vm/ast/mod.rs index 994f151ec4..7bfa61b7f1 100644 --- a/clarity/src/vm/ast/mod.rs +++ b/clarity/src/vm/ast/mod.rs @@ -23,29 +23,25 @@ pub mod errors; pub mod stack_depth_checker; pub mod sugar_expander; pub mod types; -use crate::vm::costs::{cost_functions, runtime_cost, CostTracker, LimitedCostTracker}; -use crate::vm::errors::{Error, RuntimeErrorType}; - -use crate::vm::representations::SymbolicExpression; -use crate::vm::types::QualifiedContractIdentifier; +use stacks_common::types::StacksEpochId; use self::definition_sorter::DefinitionSorter; use self::errors::ParseResult; use self::expression_identifier::ExpressionIdentifier; -use self::parser::v1::parse as parse_v1; -use self::parser::v1::parse_no_stack_limit as parse_v1_no_stack_limit; +use self::parser::v1::{parse as parse_v1, parse_no_stack_limit as parse_v1_no_stack_limit}; use self::parser::v2::parse as parse_v2; -use self::stack_depth_checker::StackDepthChecker; -use self::stack_depth_checker::VaryStackDepthChecker; +use self::stack_depth_checker::{StackDepthChecker, VaryStackDepthChecker}; use self::sugar_expander::SugarExpander; use self::traits_resolver::TraitsResolver; use self::types::BuildASTPass; pub use self::types::ContractAST; use crate::vm::costs::cost_functions::ClarityCostFunction; +use crate::vm::costs::{cost_functions, runtime_cost, CostTracker, LimitedCostTracker}; use crate::vm::diagnostic::{Diagnostic, Level}; -use crate::vm::representations::PreSymbolicExpression; +use crate::vm::errors::{Error, RuntimeErrorType}; +use crate::vm::representations::{PreSymbolicExpression, SymbolicExpression}; +use crate::vm::types::QualifiedContractIdentifier; use crate::vm::ClarityVersion; -use stacks_common::types::StacksEpochId; /// Legacy function #[cfg(any(test, features = "testing"))] @@ -322,19 +318,17 @@ pub fn build_ast( #[cfg(test)] mod test { + use std::collections::HashMap; + + use stacks_common::types::StacksEpochId; + use crate::vm::ast::errors::ParseErrors; use crate::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; use crate::vm::ast::{build_ast, build_ast_with_rules, ASTRules}; - use crate::vm::costs::LimitedCostTracker; - use crate::vm::costs::*; + use crate::vm::costs::{LimitedCostTracker, *}; use crate::vm::representations::depth_traverse; use crate::vm::types::QualifiedContractIdentifier; - use crate::vm::ClarityCostFunction; - use crate::vm::ClarityName; - use crate::vm::ClarityVersion; - use crate::vm::MAX_CALL_STACK_DEPTH; - use stacks_common::types::StacksEpochId; - use std::collections::HashMap; + use crate::vm::{ClarityCostFunction, ClarityName, ClarityVersion, MAX_CALL_STACK_DEPTH}; #[derive(PartialEq, Debug)] struct UnitTestTracker { diff --git a/clarity/src/vm/ast/parser/v1.rs b/clarity/src/vm/ast/parser/v1.rs index bf459675b7..d3cfb2c62c 100644 --- a/clarity/src/vm/ast/parser/v1.rs +++ b/clarity/src/vm/ast/parser/v1.rs @@ -14,19 +14,20 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::cmp; +use std::convert::TryInto; + +use regex::{Captures, Regex}; +use stacks_common::address::c32::c32_address_decode; +use stacks_common::util::hash::hex_bytes; + use crate::vm::ast::errors::{ParseError, ParseErrors, ParseResult}; +use crate::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; use crate::vm::errors::{InterpreterResult as Result, RuntimeErrorType}; use crate::vm::representations::{ ClarityName, ContractName, PreSymbolicExpression, PreSymbolicExpressionType, MAX_STRING_LEN, }; use crate::vm::types::{PrincipalData, QualifiedContractIdentifier, TraitIdentifier, Value}; -use regex::{Captures, Regex}; -use stacks_common::address::c32::c32_address_decode; -use stacks_common::util::hash::hex_bytes; -use std::cmp; -use std::convert::TryInto; - -use crate::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; use crate::vm::MAX_CALL_STACK_DEPTH; pub const CONTRACT_MIN_NAME_LENGTH: usize = 1; @@ -731,15 +732,13 @@ pub fn parse_no_stack_limit(input: &str) -> ParseResult = Result; diff --git a/clarity/src/vm/ast/parser/v2/lexer/token.rs b/clarity/src/vm/ast/parser/v2/lexer/token.rs index d2b6a23073..d83a7717a6 100644 --- a/clarity/src/vm/ast/parser/v2/lexer/token.rs +++ b/clarity/src/vm/ast/parser/v2/lexer/token.rs @@ -3,7 +3,8 @@ use std::fmt::Display; use stacks_common::util::hash; use super::error::LexerError; -use crate::vm::{representations::Span, types::UTF8Data}; +use crate::vm::representations::Span; +use crate::vm::types::UTF8Data; #[derive(Debug, PartialEq, Clone)] pub enum Token { diff --git a/clarity/src/vm/ast/parser/v2/mod.rs b/clarity/src/vm/ast/parser/v2/mod.rs index cea85b2326..582bfe14e0 100644 --- a/clarity/src/vm/ast/parser/v2/mod.rs +++ b/clarity/src/vm/ast/parser/v2/mod.rs @@ -1128,14 +1128,11 @@ pub fn parse_collect_diagnostics( #[cfg(test)] #[cfg(feature = "developer-mode")] mod tests { - use crate::vm::{ - diagnostic::Level, - types::{ - ASCIIData, CharType, PrincipalData, SequenceData, StandardPrincipalData, UTF8Data, - }, - }; - use super::*; + use crate::vm::diagnostic::Level; + use crate::vm::types::{ + ASCIIData, CharType, PrincipalData, SequenceData, StandardPrincipalData, UTF8Data, + }; #[test] fn test_parse_int() { diff --git a/clarity/src/vm/ast/stack_depth_checker.rs b/clarity/src/vm/ast/stack_depth_checker.rs index e9a62d8ecc..172e6be6c3 100644 --- a/clarity/src/vm/ast/stack_depth_checker.rs +++ b/clarity/src/vm/ast/stack_depth_checker.rs @@ -17,9 +17,7 @@ use crate::vm::ast::errors::{ParseError, ParseErrors, ParseResult}; use crate::vm::ast::types::{BuildASTPass, ContractAST}; use crate::vm::representations::PreSymbolicExpression; -use crate::vm::representations::PreSymbolicExpressionType::List; -use crate::vm::representations::PreSymbolicExpressionType::Tuple; - +use crate::vm::representations::PreSymbolicExpressionType::{List, Tuple}; use crate::vm::{ClarityVersion, MAX_CALL_STACK_DEPTH}; // allow the AST to get deeper than the max call stack depth, diff --git a/clarity/src/vm/ast/sugar_expander/mod.rs b/clarity/src/vm/ast/sugar_expander/mod.rs index 1e1d978e44..8f0f3c9d7f 100644 --- a/clarity/src/vm/ast/sugar_expander/mod.rs +++ b/clarity/src/vm/ast/sugar_expander/mod.rs @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::collections::{HashMap, HashSet}; +use std::convert::TryInto; + use crate::vm::ast::errors::{ParseError, ParseErrors, ParseResult}; use crate::vm::ast::types::{BuildASTPass, ContractAST, PreExpressionsDrain}; use crate::vm::functions::define::{DefineFunctions, DefineFunctionsParsed}; @@ -27,9 +30,6 @@ use crate::vm::types::{ }; use crate::vm::ClarityVersion; -use std::collections::{HashMap, HashSet}; -use std::convert::TryInto; - pub struct SugarExpander { issuer: StandardPrincipalData, defined_traits: HashSet, diff --git a/clarity/src/vm/ast/types.rs b/clarity/src/vm/ast/types.rs index 7191601ad0..79c5513b36 100644 --- a/clarity/src/vm/ast/types.rs +++ b/clarity/src/vm/ast/types.rs @@ -14,13 +14,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::collections::{HashMap, HashSet}; +use std::vec::Drain; + use crate::vm::ast::errors::ParseResult; use crate::vm::representations::{PreSymbolicExpression, SymbolicExpression, TraitDefinition}; use crate::vm::types::signatures::FunctionSignature; use crate::vm::types::{QualifiedContractIdentifier, TraitIdentifier}; use crate::vm::{ClarityName, ClarityVersion}; -use std::collections::{HashMap, HashSet}; -use std::vec::Drain; pub trait BuildASTPass { fn run_pass(contract_ast: &mut ContractAST, _version: ClarityVersion) -> ParseResult<()>; diff --git a/clarity/src/vm/callables.rs b/clarity/src/vm/callables.rs index e9edd2fe46..c589e4b397 100644 --- a/clarity/src/vm/callables.rs +++ b/clarity/src/vm/callables.rs @@ -21,11 +21,13 @@ use std::iter::FromIterator; use stacks_common::types::StacksEpochId; -use crate::vm::costs::{cost_functions, runtime_cost}; - +use super::costs::CostOverflowingMath; +use super::types::signatures::CallableSubtype; +use super::ClarityVersion; use crate::vm::analysis::errors::CheckErrors; use crate::vm::contexts::ContractContext; use crate::vm::costs::cost_functions::ClarityCostFunction; +use crate::vm::costs::{cost_functions, runtime_cost}; use crate::vm::errors::{check_argument_count, Error, InterpreterResult as Result}; use crate::vm::representations::{ClarityName, Span, SymbolicExpression}; use crate::vm::types::Value::UInt; @@ -36,10 +38,6 @@ use crate::vm::types::{ }; use crate::vm::{eval, Environment, LocalContext, Value}; -use super::costs::CostOverflowingMath; -use super::types::signatures::CallableSubtype; -use super::ClarityVersion; - type SpecialFunctionType = dyn Fn(&[SymbolicExpression], &mut Environment, &LocalContext) -> Result; @@ -503,9 +501,8 @@ fn clarity2_implicit_cast(type_sig: &TypeSignature, value: &Value) -> Result. +use std::convert::TryInto; + use stacks_common::types::StacksEpochId; use crate::vm::ast::ContractAST; @@ -24,7 +26,6 @@ use crate::vm::representations::SymbolicExpression; use crate::vm::types::{PrincipalData, QualifiedContractIdentifier}; use crate::vm::version::ClarityVersion; use crate::vm::{apply, eval_all, Value}; -use std::convert::TryInto; #[derive(Serialize, Deserialize)] pub struct Contract { diff --git a/clarity/src/vm/costs/mod.rs b/clarity/src/vm/costs/mod.rs index add63a9c47..c2c257755b 100644 --- a/clarity/src/vm/costs/mod.rs +++ b/clarity/src/vm/costs/mod.rs @@ -20,12 +20,14 @@ use std::{cmp, fmt}; use rusqlite::types::{FromSql, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; use serde::{Deserialize, Serialize}; +use stacks_common::types::StacksEpochId; use crate::boot_util::boot_code_id; use crate::vm::ast::ContractAST; use crate::vm::contexts::{ContractContext, Environment, GlobalContext, OwnedEnvironment}; use crate::vm::costs::cost_functions::ClarityCostFunction; -use crate::vm::database::{clarity_store::NullBackingStore, ClarityDatabase}; +use crate::vm::database::clarity_store::NullBackingStore; +use crate::vm::database::ClarityDatabase; use crate::vm::errors::{Error, InterpreterResult}; use crate::vm::types::signatures::FunctionType::Fixed; use crate::vm::types::signatures::{FunctionSignature, TupleTypeSignature}; @@ -35,7 +37,6 @@ use crate::vm::types::{ TypeSignature, NONE, }; use crate::vm::{ast, eval_all, ClarityName, SymbolicExpression, Value}; -use stacks_common::types::StacksEpochId; pub mod constants; pub mod cost_functions; diff --git a/clarity/src/vm/coverage.rs b/clarity/src/vm/coverage.rs index 1d07564571..4ac9d459a7 100644 --- a/clarity/src/vm/coverage.rs +++ b/clarity/src/vm/coverage.rs @@ -1,14 +1,13 @@ -use std::{ - collections::{BTreeMap, HashMap, HashSet}, - fs::File, - io::Write, -}; +use std::collections::{BTreeMap, HashMap, HashSet}; +use std::fs::File; +use std::io::Write; -use crate::vm::types::QualifiedContractIdentifier; -use crate::vm::SymbolicExpression; use serde_json::Value as JsonValue; -use super::{functions::define::DefineFunctionsParsed, EvalHook}; +use super::functions::define::DefineFunctionsParsed; +use super::EvalHook; +use crate::vm::types::QualifiedContractIdentifier; +use crate::vm::SymbolicExpression; pub struct CoverageReporter { executed_lines: HashMap>, diff --git a/clarity/src/vm/database/clarity_db.rs b/clarity/src/vm/database/clarity_db.rs index 0585f20059..7a74357f5e 100644 --- a/clarity/src/vm/database/clarity_db.rs +++ b/clarity/src/vm/database/clarity_db.rs @@ -17,56 +17,45 @@ use std::collections::{HashMap, VecDeque}; use std::convert::{TryFrom, TryInto}; +use serde_json; +use stacks_common::address::AddressHashMode; +use stacks_common::consts::{ + BITCOIN_REGTEST_FIRST_BLOCK_HASH, BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT, + BITCOIN_REGTEST_FIRST_BLOCK_TIMESTAMP, FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, + MINER_REWARD_MATURITY, +}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, SortitionId, StacksAddress, StacksBlockId, + VRFSeed, +}; +use stacks_common::types::{ + Address, StacksEpoch as GenericStacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_2_0, +}; +use stacks_common::util::hash::{to_hex, Hash160, Sha256Sum, Sha512Trunc256Sum}; + +use super::clarity_store::SpecialCaseHandler; +use super::key_value_wrapper::ValueResult; use crate::vm::analysis::{AnalysisDatabase, ContractAnalysis}; use crate::vm::ast::ASTRules; use crate::vm::contracts::Contract; -use crate::vm::costs::CostOverflowingMath; -use crate::vm::costs::ExecutionCost; +use crate::vm::costs::{CostOverflowingMath, ExecutionCost}; use crate::vm::database::structures::{ ClarityDeserializable, ClaritySerializable, ContractMetadata, DataMapMetadata, DataVariableMetadata, FungibleTokenMetadata, NonFungibleTokenMetadata, STXBalance, STXBalanceSnapshot, SimmedBlock, }; -use crate::vm::database::ClarityBackingStore; -use crate::vm::database::RollbackWrapper; +use crate::vm::database::{ClarityBackingStore, RollbackWrapper}; use crate::vm::errors::{ CheckErrors, Error, IncomparableError, InterpreterError, InterpreterResult as Result, RuntimeErrorType, }; use crate::vm::representations::ClarityName; -use crate::vm::types::serialization::SerializationError; +use crate::vm::types::serialization::{SerializationError, NONE_SERIALIZATION_LEN}; use crate::vm::types::{ - serialization::NONE_SERIALIZATION_LEN, OptionalData, PrincipalData, - QualifiedContractIdentifier, SequenceData, StandardPrincipalData, TupleData, - TupleTypeSignature, TypeSignature, Value, NONE, -}; -use stacks_common::util::hash::{to_hex, Hash160, Sha256Sum, Sha512Trunc256Sum}; - -use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksAddress, StacksBlockId, VRFSeed, -}; - -use crate::vm::types::byte_len_of_serialization; - -use stacks_common::types::{ - StacksEpoch as GenericStacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_2_0, + byte_len_of_serialization, OptionalData, PrincipalData, QualifiedContractIdentifier, + SequenceData, StandardPrincipalData, TupleData, TupleTypeSignature, TypeSignature, Value, NONE, }; -use stacks_common::consts::MINER_REWARD_MATURITY; -use stacks_common::consts::{ - BITCOIN_REGTEST_FIRST_BLOCK_HASH, BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT, - BITCOIN_REGTEST_FIRST_BLOCK_TIMESTAMP, FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, -}; - -use stacks_common::address::AddressHashMode; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::Address; - -use super::clarity_store::SpecialCaseHandler; -use super::key_value_wrapper::ValueResult; - -use serde_json; - pub const STORE_CONTRACT_SRC_INTERFACE: bool = true; pub type StacksEpoch = GenericStacksEpoch; diff --git a/clarity/src/vm/database/clarity_store.rs b/clarity/src/vm/database/clarity_store.rs index 0a2c13aa45..b9400c227a 100644 --- a/clarity/src/vm/database/clarity_store.rs +++ b/clarity/src/vm/database/clarity_store.rs @@ -18,8 +18,11 @@ use std::convert::TryInto; use std::path::PathBuf; use rusqlite::Connection; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId, VRFSeed}; +use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, Sha512Trunc256Sum}; use crate::vm::analysis::AnalysisDatabase; +use crate::vm::contexts::GlobalContext; use crate::vm::database::{ BurnStateDB, ClarityDatabase, ClarityDeserializable, ClaritySerializable, HeadersDB, SqliteConnection, NULL_BURN_STATE_DB, NULL_HEADER_DB, @@ -29,13 +32,8 @@ use crate::vm::errors::{ InterpreterResult, RuntimeErrorType, }; use crate::vm::events::StacksTransactionEvent; -use crate::vm::types::QualifiedContractIdentifier; -use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, Sha512Trunc256Sum}; - -use crate::vm::contexts::GlobalContext; -use crate::vm::types::PrincipalData; +use crate::vm::types::{PrincipalData, QualifiedContractIdentifier}; use crate::vm::Value; -use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId, VRFSeed}; pub struct NullBackingStore {} diff --git a/clarity/src/vm/database/key_value_wrapper.rs b/clarity/src/vm/database/key_value_wrapper.rs index 778ba8396b..8431a1742a 100644 --- a/clarity/src/vm/database/key_value_wrapper.rs +++ b/clarity/src/vm/database/key_value_wrapper.rs @@ -14,9 +14,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::clone::Clone; +use std::cmp::Eq; use std::collections::HashMap; -use std::{clone::Clone, cmp::Eq, hash::Hash}; +use std::hash::Hash; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::StacksEpochId; +use stacks_common::util::hash::Sha512Trunc256Sum; + +use super::clarity_store::SpecialCaseHandler; +use super::{ClarityBackingStore, ClarityDeserializable}; use crate::vm::database::clarity_store::make_contract_hash_key; use crate::vm::errors::InterpreterResult; use crate::vm::types::serialization::SerializationError; @@ -24,13 +32,6 @@ use crate::vm::types::{ QualifiedContractIdentifier, SequenceData, SequenceSubtype, TupleData, TypeSignature, }; use crate::vm::{StacksEpoch, Value}; -use stacks_common::types::StacksEpochId; -use stacks_common::util::hash::Sha512Trunc256Sum; - -use stacks_common::types::chainstate::StacksBlockId; - -use super::clarity_store::SpecialCaseHandler; -use super::{ClarityBackingStore, ClarityDeserializable}; #[cfg(rollback_value_check)] type RollbackValueCheck = String; diff --git a/clarity/src/vm/database/mod.rs b/clarity/src/vm/database/mod.rs index fd1f06557f..e02aee5c33 100644 --- a/clarity/src/vm/database/mod.rs +++ b/clarity/src/vm/database/mod.rs @@ -20,8 +20,7 @@ pub use self::clarity_db::{ BurnStateDB, ClarityDatabase, HeadersDB, StoreType, NULL_BURN_STATE_DB, NULL_HEADER_DB, STORE_CONTRACT_SRC_INTERFACE, }; -pub use self::clarity_store::MemoryBackingStore; -pub use self::clarity_store::{ClarityBackingStore, SpecialCaseHandler}; +pub use self::clarity_store::{ClarityBackingStore, MemoryBackingStore, SpecialCaseHandler}; pub use self::key_value_wrapper::{RollbackWrapper, RollbackWrapperPersistedLog}; pub use self::sqlite::SqliteConnection; pub use self::structures::{ diff --git a/clarity/src/vm/database/sqlite.rs b/clarity/src/vm/database/sqlite.rs index 9fd48656eb..273473c9b3 100644 --- a/clarity/src/vm/database/sqlite.rs +++ b/clarity/src/vm/database/sqlite.rs @@ -19,9 +19,7 @@ use rusqlite::{ Connection, Error as SqliteError, ErrorCode as SqliteErrorCode, OptionalExtension, Row, Savepoint, NO_PARAMS, }; - use stacks_common::types::chainstate::StacksBlockId; - use stacks_common::util::db_common::tx_busy_handler; use crate::vm::contracts::Contract; diff --git a/clarity/src/vm/database/structures.rs b/clarity/src/vm/database/structures.rs index b96563aa4e..89a635765e 100644 --- a/clarity/src/vm/database/structures.rs +++ b/clarity/src/vm/database/structures.rs @@ -14,6 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::convert::TryInto; +use std::io::Write; + +use serde::Deserialize; +use stacks_common::util::hash::{hex_bytes, to_hex}; + use crate::vm::analysis::ContractAnalysis; use crate::vm::contracts::Contract; use crate::vm::database::ClarityDatabase; @@ -23,10 +29,6 @@ use crate::vm::errors::{ use crate::vm::types::{ OptionalData, PrincipalData, TupleTypeSignature, TypeSignature, Value, NONE, }; -use serde::Deserialize; -use stacks_common::util::hash::{hex_bytes, to_hex}; -use std::convert::TryInto; -use std::io::Write; pub trait ClaritySerializable { fn serialize(&self) -> String; diff --git a/clarity/src/vm/diagnostic.rs b/clarity/src/vm/diagnostic.rs index f07b53d8be..ee0ac0b56d 100644 --- a/clarity/src/vm/diagnostic.rs +++ b/clarity/src/vm/diagnostic.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::representations::Span; use std::fmt; +use crate::vm::representations::Span; + /// In a near future, we can go further in our static analysis and provide different levels /// of diagnostics, such as warnings, hints, best practices, etc. #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)] diff --git a/clarity/src/vm/docs/contracts.rs b/clarity/src/vm/docs/contracts.rs index 05b7de4222..a8b9a5e3f9 100644 --- a/clarity/src/vm/docs/contracts.rs +++ b/clarity/src/vm/docs/contracts.rs @@ -1,20 +1,18 @@ -use crate::vm::analysis::{mem_type_check, ContractAnalysis}; -use crate::vm::docs::{get_input_type_string, get_output_type_string, get_signature}; -use crate::vm::types::{FunctionType, Value}; - use std::collections::{BTreeMap, HashMap, HashSet}; use std::iter::FromIterator; +use stacks_common::consts::CHAIN_ID_TESTNET; +use stacks_common::types::StacksEpochId; + +use crate::vm::analysis::{mem_type_check, ContractAnalysis}; use crate::vm::ast::{build_ast_with_rules, ASTRules}; use crate::vm::contexts::GlobalContext; use crate::vm::costs::LimitedCostTracker; use crate::vm::database::MemoryBackingStore; -use crate::vm::types::QualifiedContractIdentifier; +use crate::vm::docs::{get_input_type_string, get_output_type_string, get_signature}; +use crate::vm::types::{FunctionType, QualifiedContractIdentifier, Value}; use crate::vm::version::ClarityVersion; use crate::vm::{self, ContractContext}; -use stacks_common::types::StacksEpochId; - -use stacks_common::consts::CHAIN_ID_TESTNET; const DOCS_GENERATION_EPOCH: StacksEpochId = StacksEpochId::Epoch2_05; diff --git a/clarity/src/vm/docs/mod.rs b/clarity/src/vm/docs/mod.rs index 24587da826..81e4ce3434 100644 --- a/clarity/src/vm/docs/mod.rs +++ b/clarity/src/vm/docs/mod.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use super::types::signatures::{FunctionArgSignature, FunctionReturnsSignature}; use crate::vm::analysis::type_checker::v2_1::natives::SimpleNativeFunction; use crate::vm::analysis::type_checker::v2_1::TypedNativeFunction; use crate::vm::costs::ExecutionCost; @@ -24,8 +25,6 @@ use crate::vm::types::{FixedFunction, FunctionType, SequenceSubtype, StringSubty use crate::vm::variables::NativeVariables; use crate::vm::ClarityVersion; -use super::types::signatures::{FunctionArgSignature, FunctionReturnsSignature}; - pub mod contracts; #[derive(Serialize)] @@ -2630,39 +2629,33 @@ pub fn make_json_api_reference() -> String { #[cfg(test)] mod test { - use crate::vm::{ - ast, - contexts::OwnedEnvironment, - database::{BurnStateDB, HeadersDB, STXBalance}, - docs::get_output_type_string, - eval_all, execute, - types::{ - signatures::{FunctionArgSignature, FunctionReturnsSignature, ASCII_40}, - BufferLength, FunctionType, PrincipalData, SequenceSubtype, StringSubtype, - TypeSignature, - }, - ClarityVersion, ContractContext, Error, GlobalContext, LimitedCostTracker, - QualifiedContractIdentifier, Value, - }; - use stacks_common::types::{StacksEpochId, PEER_VERSION_EPOCH_2_1}; - use stacks_common::util::hash::hex_bytes; - - use super::make_json_api_reference; - use super::{get_input_type_string, make_all_api_reference}; - use crate::vm::analysis::type_check; - use crate::vm::database::{ClarityDatabase, MemoryBackingStore}; - use crate::vm::types::TupleData; - use crate::vm::StacksEpoch; use stacks_common::address::AddressHashMode; + use stacks_common::consts::CHAIN_ID_TESTNET; use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, VRFSeed, + BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, SortitionId, StacksAddress, + StacksBlockId, VRFSeed, }; - use stacks_common::types::chainstate::{SortitionId, StacksAddress, StacksBlockId}; - use stacks_common::types::Address; + use stacks_common::types::{Address, StacksEpochId, PEER_VERSION_EPOCH_2_1}; + use stacks_common::util::hash::hex_bytes; + use super::{get_input_type_string, make_all_api_reference, make_json_api_reference}; + use crate::vm::analysis::type_check; use crate::vm::ast::ASTRules; + use crate::vm::contexts::OwnedEnvironment; use crate::vm::costs::ExecutionCost; - use stacks_common::consts::CHAIN_ID_TESTNET; + use crate::vm::database::{ + BurnStateDB, ClarityDatabase, HeadersDB, MemoryBackingStore, STXBalance, + }; + use crate::vm::docs::get_output_type_string; + use crate::vm::types::signatures::{FunctionArgSignature, FunctionReturnsSignature, ASCII_40}; + use crate::vm::types::{ + BufferLength, FunctionType, PrincipalData, SequenceSubtype, StringSubtype, TupleData, + TypeSignature, + }; + use crate::vm::{ + ast, eval_all, execute, ClarityVersion, ContractContext, Error, GlobalContext, + LimitedCostTracker, QualifiedContractIdentifier, StacksEpoch, Value, + }; struct DocHeadersDB {} const DOC_HEADER_DB: DocHeadersDB = DocHeadersDB {}; diff --git a/clarity/src/vm/errors.rs b/clarity/src/vm/errors.rs index 71dc0a21d7..d03e75e034 100644 --- a/clarity/src/vm/errors.rs +++ b/clarity/src/vm/errors.rs @@ -14,20 +14,20 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -pub use crate::vm::analysis::errors::CheckErrors; +use std::error::Error as ErrorTrait; +use std::{error, fmt}; + +use rusqlite::Error as SqliteError; +use serde_json::Error as SerdeJSONErr; +use stacks_common::types::chainstate::BlockHeaderHash; + pub use crate::vm::analysis::errors::{ - check_argument_count, check_arguments_at_least, check_arguments_at_most, + check_argument_count, check_arguments_at_least, check_arguments_at_most, CheckErrors, }; use crate::vm::ast::errors::ParseError; use crate::vm::contexts::StackTrace; use crate::vm::costs::CostErrors; use crate::vm::types::{TypeSignature, Value}; -use rusqlite::Error as SqliteError; -use serde_json::Error as SerdeJSONErr; -use stacks_common::types::chainstate::BlockHeaderHash; -use std::error; -use std::error::Error as ErrorTrait; -use std::fmt; #[derive(Debug)] pub struct IncomparableError { diff --git a/clarity/src/vm/events.rs b/clarity/src/vm/events.rs index 8b693ea9f6..18fc84bb2e 100644 --- a/clarity/src/vm/events.rs +++ b/clarity/src/vm/events.rs @@ -14,14 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::StacksAddress; + use crate::vm::analysis::ContractAnalysis; use crate::vm::costs::ExecutionCost; use crate::vm::types::{ AssetIdentifier, BuffData, PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, Value, }; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::StacksAddress; #[derive(Debug, Clone, PartialEq)] pub enum StacksTransactionEvent { diff --git a/clarity/src/vm/functions/arithmetic.rs b/clarity/src/vm/functions/arithmetic.rs index ec493d9dee..6b30ce0852 100644 --- a/clarity/src/vm/functions/arithmetic.rs +++ b/clarity/src/vm/functions/arithmetic.rs @@ -14,19 +14,20 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::costs::cost_functions::ClarityCostFunction; -use crate::vm::errors::{check_argument_count, CheckErrors, InterpreterResult, RuntimeErrorType}; -use crate::vm::types::{ - ASCIIData, BuffData, CharType, SequenceData, TypeSignature, UTF8Data, Value, -}; use std::cmp; use std::convert::TryFrom; -use crate::vm::costs::runtime_cost; use integer_sqrt::IntegerSquareRoot; +use crate::vm::costs::cost_functions::ClarityCostFunction; +use crate::vm::costs::runtime_cost; +use crate::vm::errors::{check_argument_count, CheckErrors, InterpreterResult, RuntimeErrorType}; use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; -use crate::vm::types::{signatures::ListTypeData, ListData, TypeSignature::BoolType}; +use crate::vm::types::signatures::ListTypeData; +use crate::vm::types::TypeSignature::BoolType; +use crate::vm::types::{ + ASCIIData, BuffData, CharType, ListData, SequenceData, TypeSignature, UTF8Data, Value, +}; use crate::vm::version::ClarityVersion; use crate::vm::{apply, eval, lookup_function, CallableType, Environment, LocalContext}; diff --git a/clarity/src/vm/functions/assets.rs b/clarity/src/vm/functions/assets.rs index 8b621b9d2a..e117b81afc 100644 --- a/clarity/src/vm/functions/assets.rs +++ b/clarity/src/vm/functions/assets.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::functions::tuples; use std::convert::{TryFrom, TryInto}; +use stacks_common::types::StacksEpochId; + use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{cost_functions, runtime_cost, CostTracker}; use crate::vm::database::{ClarityDatabase, ClaritySerializable, STXBalance}; @@ -24,17 +25,14 @@ use crate::vm::errors::{ check_argument_count, CheckErrors, Error, InterpreterError, InterpreterResult as Result, RuntimeErrorType, }; +use crate::vm::functions::tuples; use crate::vm::representations::SymbolicExpression; use crate::vm::types::{ AssetIdentifier, BlockInfoProperty, BuffData, CharType, OptionalData, PrincipalData, - SequenceData, TypeSignature, Value, + SequenceData, TupleData, TypeSignature, Value, }; use crate::vm::{eval, Environment, LocalContext}; -use stacks_common::types::StacksEpochId; - -use crate::vm::types::TupleData; - enum MintAssetErrorCodes { ALREADY_EXIST = 1, } diff --git a/clarity/src/vm/functions/conversions.rs b/clarity/src/vm/functions/conversions.rs index 5f362c7078..b42e8490cb 100644 --- a/clarity/src/vm/functions/conversions.rs +++ b/clarity/src/vm/functions/conversions.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::convert::TryFrom; + use stacks_common::codec::StacksMessageCodec; use stacks_common::types::StacksEpochId; @@ -28,7 +30,6 @@ use crate::vm::types::{ ASCIIData, BuffData, BufferLength, CharType, SequenceData, TypeSignature, UTF8Data, Value, }; use crate::vm::{apply, eval, lookup_function, Environment, LocalContext}; -use std::convert::TryFrom; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum EndianDirection { diff --git a/clarity/src/vm/functions/crypto.rs b/clarity/src/vm/functions/crypto.rs index 4ef4dd76f8..30de1e9afd 100644 --- a/clarity/src/vm/functions/crypto.rs +++ b/clarity/src/vm/functions/crypto.rs @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use stacks_common::address::{ + AddressHashMode, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, +}; +use stacks_common::types::chainstate::StacksAddress; +use stacks_common::util::hash; +use stacks_common::util::secp256k1::{secp256k1_recover, secp256k1_verify, Secp256k1PublicKey}; + use crate::vm::callables::{CallableType, NativeHandle}; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{ @@ -25,20 +32,11 @@ use crate::vm::errors::{ }; use crate::vm::representations::SymbolicExpressionType::{Atom, List}; use crate::vm::representations::{ClarityName, SymbolicExpression, SymbolicExpressionType}; -use crate::vm::types::StacksAddressExtensions; use crate::vm::types::{ - BuffData, CharType, PrincipalData, ResponseData, SequenceData, TypeSignature, Value, BUFF_32, - BUFF_33, BUFF_65, + BuffData, CharType, PrincipalData, ResponseData, SequenceData, StacksAddressExtensions, + TypeSignature, Value, BUFF_32, BUFF_33, BUFF_65, }; use crate::vm::{eval, ClarityVersion, Environment, LocalContext}; -use stacks_common::address::AddressHashMode; -use stacks_common::address::{ - C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, -}; -use stacks_common::util::hash; -use stacks_common::util::secp256k1::{secp256k1_recover, secp256k1_verify, Secp256k1PublicKey}; - -use stacks_common::types::chainstate::StacksAddress; macro_rules! native_hash_func { ($name:ident, $module:ty) => { diff --git a/clarity/src/vm/functions/database.rs b/clarity/src/vm/functions/database.rs index 664140f86e..ead11ab0eb 100644 --- a/clarity/src/vm/functions/database.rs +++ b/clarity/src/vm/functions/database.rs @@ -17,9 +17,11 @@ use std::cmp; use std::convert::{TryFrom, TryInto}; -use crate::vm::functions::tuples; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::StacksEpochId; use crate::vm::callables::DefineType; +use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{ constants as cost_constants, cost_functions, runtime_cost, CostTracker, MemoryConsumer, }; @@ -27,16 +29,13 @@ use crate::vm::errors::{ check_argument_count, check_arguments_at_least, CheckErrors, InterpreterError, InterpreterResult as Result, RuntimeErrorType, }; +use crate::vm::functions::tuples; use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; use crate::vm::types::{ BlockInfoProperty, BuffData, BurnBlockInfoProperty, OptionalData, PrincipalData, SequenceData, TupleData, TypeSignature, Value, BUFF_32, }; use crate::vm::{eval, Environment, LocalContext}; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::StacksEpochId; - -use crate::vm::costs::cost_functions::ClarityCostFunction; switch_on_global_epoch!(special_fetch_variable( special_fetch_variable_v200, diff --git a/clarity/src/vm/functions/define.rs b/clarity/src/vm/functions/define.rs index fbe8f99f95..9451f17ff9 100644 --- a/clarity/src/vm/functions/define.rs +++ b/clarity/src/vm/functions/define.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::collections::{BTreeMap, HashMap}; + use crate::vm::callables::{DefineType, DefinedFunction}; use crate::vm::contexts::{ContractContext, Environment, LocalContext}; use crate::vm::errors::{ @@ -30,7 +32,6 @@ use crate::vm::types::{ parse_name_type_pairs, PrincipalData, QualifiedContractIdentifier, TraitIdentifier, TupleTypeSignature, TypeSignature, Value, }; -use std::collections::{BTreeMap, HashMap}; define_named_enum!(DefineFunctions { Constant("define-constant"), diff --git a/clarity/src/vm/functions/mod.rs b/clarity/src/vm/functions/mod.rs index 9c3a9551d9..d81a4b2ab9 100644 --- a/clarity/src/vm/functions/mod.rs +++ b/clarity/src/vm/functions/mod.rs @@ -14,7 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::callables::{CallableType, NativeHandle}; +use stacks_common::address::AddressHashMode; +use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::StacksEpochId; +use stacks_common::util::hash; + +use crate::vm::callables::{cost_input_sized_vararg, CallableType, NativeHandle}; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{ constants as cost_constants, cost_functions, runtime_cost, CostTracker, MemoryConsumer, @@ -24,7 +29,6 @@ use crate::vm::errors::{ InterpreterResult as Result, RuntimeErrorType, ShortReturnType, }; pub use crate::vm::functions::assets::stx_transfer_consolidated; -use crate::vm::is_reserved; use crate::vm::representations::SymbolicExpressionType::{Atom, List}; use crate::vm::representations::{ClarityName, SymbolicExpression, SymbolicExpressionType}; use crate::vm::types::{ @@ -32,14 +36,7 @@ use crate::vm::types::{ BUFF_33, BUFF_65, }; use crate::vm::Value::CallableContract; -use crate::vm::{eval, Environment, LocalContext}; -use stacks_common::address::AddressHashMode; -use stacks_common::util::hash; - -use crate::vm::callables::cost_input_sized_vararg; -use stacks_common::types::chainstate::StacksAddress; - -use stacks_common::types::StacksEpochId; +use crate::vm::{eval, is_reserved, Environment, LocalContext}; macro_rules! switch_on_global_epoch { ($Name:ident ($Epoch2Version:ident, $Epoch205Version:ident)) => { diff --git a/clarity/src/vm/functions/options.rs b/clarity/src/vm/functions/options.rs index 70ea138a99..b03d464be8 100644 --- a/clarity/src/vm/functions/options.rs +++ b/clarity/src/vm/functions/options.rs @@ -23,8 +23,7 @@ use crate::vm::errors::{ }; use crate::vm::types::{CallableData, OptionalData, ResponseData, TypeSignature, Value}; use crate::vm::Value::CallableContract; -use crate::vm::{self, ClarityVersion}; -use crate::vm::{ClarityName, SymbolicExpression}; +use crate::vm::{self, ClarityName, ClarityVersion, SymbolicExpression}; fn inner_unwrap(to_unwrap: Value) -> Result> { let result = match to_unwrap { diff --git a/clarity/src/vm/functions/principals.rs b/clarity/src/vm/functions/principals.rs index cecfbb65cf..579761dfae 100644 --- a/clarity/src/vm/functions/principals.rs +++ b/clarity/src/vm/functions/principals.rs @@ -1,3 +1,11 @@ +use std::convert::TryFrom; + +use stacks_common::address::{ + C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, + C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, +}; +use stacks_common::util::hash::hex_bytes; + use crate::vm::contexts::GlobalContext; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{cost_functions, runtime_cost, CostTracker}; @@ -5,23 +13,16 @@ use crate::vm::errors::{ check_argument_count, check_arguments_at_least, check_arguments_at_most, CheckErrors, Error, InterpreterError, InterpreterResult as Result, RuntimeErrorType, }; -use crate::vm::representations::ClarityName; -use crate::vm::representations::SymbolicExpression; +use crate::vm::representations::{ + ClarityName, SymbolicExpression, CONTRACT_MAX_NAME_LENGTH, CONTRACT_MIN_NAME_LENGTH, +}; +use crate::vm::types::signatures::{BUFF_1, BUFF_20}; use crate::vm::types::{ - signatures::BUFF_1, signatures::BUFF_20, ASCIIData, BuffData, BufferLength, CharType, - OptionalData, PrincipalData, QualifiedContractIdentifier, ResponseData, SequenceData, - SequenceSubtype, StandardPrincipalData, TupleData, TypeSignature, Value, + ASCIIData, BuffData, BufferLength, CharType, OptionalData, PrincipalData, + QualifiedContractIdentifier, ResponseData, SequenceData, SequenceSubtype, + StandardPrincipalData, TupleData, TypeSignature, Value, }; use crate::vm::{eval, ContractName, Environment, LocalContext}; -use stacks_common::util::hash::hex_bytes; -use std::convert::TryFrom; - -use stacks_common::address::{ - C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, - C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, -}; - -use crate::vm::representations::{CONTRACT_MAX_NAME_LENGTH, CONTRACT_MIN_NAME_LENGTH}; pub enum PrincipalConstructErrorCode { VERSION_BYTE = 0, diff --git a/clarity/src/vm/functions/sequences.rs b/clarity/src/vm/functions/sequences.rs index 3beee74016..16e7d8d077 100644 --- a/clarity/src/vm/functions/sequences.rs +++ b/clarity/src/vm/functions/sequences.rs @@ -14,6 +14,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::cmp; +use std::convert::{TryFrom, TryInto}; + +use stacks_common::types::StacksEpochId; + use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{cost_functions, runtime_cost, CostOverflowingMath}; use crate::vm::errors::{ @@ -21,14 +26,10 @@ use crate::vm::errors::{ RuntimeErrorType, }; use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; -use crate::vm::types::{ - signatures::ListTypeData, CharType, ListData, SequenceData, TypeSignature, - TypeSignature::BoolType, Value, -}; +use crate::vm::types::signatures::ListTypeData; +use crate::vm::types::TypeSignature::BoolType; +use crate::vm::types::{CharType, ListData, SequenceData, TypeSignature, Value}; use crate::vm::{apply, eval, lookup_function, CallableType, Environment, LocalContext}; -use stacks_common::types::StacksEpochId; -use std::cmp; -use std::convert::{TryFrom, TryInto}; pub fn list_cons( args: &[SymbolicExpression], diff --git a/clarity/src/vm/mod.rs b/clarity/src/vm/mod.rs index 18bc734c55..dcdc02574a 100644 --- a/clarity/src/vm/mod.rs +++ b/clarity/src/vm/mod.rs @@ -52,44 +52,41 @@ pub mod test_util; #[allow(clippy::result_large_err)] pub mod clarity; -use serde_json; +use std::collections::BTreeMap; +use std::convert::{TryFrom, TryInto}; -// publish the non-generic StacksEpoch form for use throughout module -pub use crate::vm::database::clarity_db::StacksEpoch; +use serde_json; use stacks_common::types::StacksEpochId; +use self::analysis::ContractAnalysis; +use self::ast::{ASTRules, ContractAST}; +use self::costs::ExecutionCost; +use self::diagnostic::Diagnostic; use crate::vm::callables::CallableType; use crate::vm::contexts::GlobalContext; -pub use crate::vm::contexts::{CallStack, ContractContext, Environment, LocalContext}; +pub use crate::vm::contexts::{ + CallStack, ContractContext, Environment, LocalContext, MAX_CONTEXT_DEPTH, +}; +use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{ cost_functions, runtime_cost, CostOverflowingMath, CostTracker, LimitedCostTracker, MemoryConsumer, }; +// publish the non-generic StacksEpoch form for use throughout module +pub use crate::vm::database::clarity_db::StacksEpoch; use crate::vm::errors::{ CheckErrors, Error, InterpreterError, InterpreterResult as Result, RuntimeErrorType, }; use crate::vm::functions::define::DefineResult; +pub use crate::vm::functions::stx_transfer_consolidated; +pub use crate::vm::representations::{ + ClarityName, ContractName, SymbolicExpression, SymbolicExpressionType, +}; pub use crate::vm::types::Value; use crate::vm::types::{ PrincipalData, QualifiedContractIdentifier, TraitIdentifier, TypeSignature, }; - -pub use crate::vm::representations::{ - ClarityName, ContractName, SymbolicExpression, SymbolicExpressionType, -}; - -pub use crate::vm::contexts::MAX_CONTEXT_DEPTH; -use crate::vm::costs::cost_functions::ClarityCostFunction; -pub use crate::vm::functions::stx_transfer_consolidated; pub use crate::vm::version::ClarityVersion; -use std::collections::BTreeMap; -use std::convert::{TryFrom, TryInto}; - -use self::analysis::ContractAnalysis; -use self::ast::ASTRules; -use self::ast::ContractAST; -use self::costs::ExecutionCost; -use self::diagnostic::Diagnostic; pub const MAX_CALL_STACK_DEPTH: usize = 64; @@ -581,23 +578,21 @@ pub fn execute_v2(program: &str) -> Result> { #[cfg(test)] mod test { + use std::collections::HashMap; + + use stacks_common::consts::CHAIN_ID_TESTNET; + use stacks_common::types::StacksEpochId; + + use super::ClarityVersion; use crate::vm::callables::{DefineType, DefinedFunction}; use crate::vm::costs::LimitedCostTracker; use crate::vm::database::MemoryBackingStore; use crate::vm::errors::RuntimeErrorType; - use crate::vm::eval; - use crate::vm::execute; use crate::vm::types::{QualifiedContractIdentifier, TypeSignature}; use crate::vm::{ - CallStack, ContractContext, Environment, GlobalContext, LocalContext, SymbolicExpression, - Value, + eval, execute, CallStack, ContractContext, Environment, GlobalContext, LocalContext, + SymbolicExpression, Value, }; - use stacks_common::types::StacksEpochId; - use std::collections::HashMap; - - use super::ClarityVersion; - - use stacks_common::consts::CHAIN_ID_TESTNET; #[test] fn test_simple_user_function() { diff --git a/clarity/src/vm/representations.rs b/clarity/src/vm/representations.rs index b8a751bfdd..a7cc12fcef 100644 --- a/clarity/src/vm/representations.rs +++ b/clarity/src/vm/representations.rs @@ -14,11 +14,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::errors::RuntimeErrorType; -use crate::vm::types::{QualifiedContractIdentifier, TraitIdentifier, Value}; -use regex::Regex; -use stacks_common::codec::Error as codec_error; -use stacks_common::codec::{read_next, read_next_at_most, write_next, StacksMessageCodec}; use std::borrow::Borrow; use std::cmp::Ordering; use std::convert::TryFrom; @@ -26,6 +21,14 @@ use std::fmt; use std::io::{Read, Write}; use std::ops::Deref; +use regex::Regex; +use stacks_common::codec::{ + read_next, read_next_at_most, write_next, Error as codec_error, StacksMessageCodec, +}; + +use crate::vm::errors::RuntimeErrorType; +use crate::vm::types::{QualifiedContractIdentifier, TraitIdentifier, Value}; + pub const CONTRACT_MIN_NAME_LENGTH: usize = 1; pub const CONTRACT_MAX_NAME_LENGTH: usize = 40; pub const MAX_STRING_LEN: u8 = 128; diff --git a/clarity/src/vm/test_util/mod.rs b/clarity/src/vm/test_util/mod.rs index fa751026ee..1368660275 100644 --- a/clarity/src/vm/test_util/mod.rs +++ b/clarity/src/vm/test_util/mod.rs @@ -1,24 +1,21 @@ -use crate::vm::ast::ASTRules; -use crate::vm::costs::ExecutionCost; -use crate::vm::database::{BurnStateDB, HeadersDB}; -use crate::vm::execute as vm_execute; -use crate::vm::execute_on_network as vm_execute_on_network; -use crate::vm::representations::SymbolicExpression; -use crate::vm::types::StandardPrincipalData; -use crate::vm::types::{PrincipalData, ResponseData, TupleData, Value}; -use crate::vm::StacksEpoch; use stacks_common::address::{AddressHashMode, C32_ADDRESS_VERSION_TESTNET_SINGLESIG}; use stacks_common::consts::{ BITCOIN_REGTEST_FIRST_BLOCK_HASH, BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT, BITCOIN_REGTEST_FIRST_BLOCK_TIMESTAMP, FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, }; -use stacks_common::types::chainstate::ConsensusHash; use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksAddress, StacksBlockId, VRFSeed, + BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, SortitionId, StacksAddress, StacksBlockId, + StacksPrivateKey, StacksPublicKey, VRFSeed, }; -use stacks_common::types::chainstate::{StacksPrivateKey, StacksPublicKey}; use stacks_common::types::{StacksEpochId, PEER_VERSION_EPOCH_2_0}; +use crate::vm::ast::ASTRules; +use crate::vm::costs::ExecutionCost; +use crate::vm::database::{BurnStateDB, HeadersDB}; +use crate::vm::representations::SymbolicExpression; +use crate::vm::types::{PrincipalData, ResponseData, StandardPrincipalData, TupleData, Value}; +use crate::vm::{execute as vm_execute, execute_on_network as vm_execute_on_network, StacksEpoch}; + pub struct UnitTestBurnStateDB { pub epoch_id: StacksEpochId, pub ast_rules: ASTRules, diff --git a/clarity/src/vm/tests/assets.rs b/clarity/src/vm/tests/assets.rs index f257bd95fa..0f6551c366 100644 --- a/clarity/src/vm/tests/assets.rs +++ b/clarity/src/vm/tests/assets.rs @@ -14,20 +14,20 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use stacks_common::types::StacksEpochId; + use crate::vm::ast::ASTRules; use crate::vm::contexts::{AssetMap, AssetMapEntry, OwnedEnvironment}; use crate::vm::errors::{CheckErrors, Error, RuntimeErrorType}; use crate::vm::events::StacksTransactionEvent; use crate::vm::representations::SymbolicExpression; -use crate::vm::tests::{execute, is_committed, is_err_code, symbols_from_values}; use crate::vm::tests::{ - test_clarity_versions, test_epochs, tl_env_factory as env_factory, - TopLevelMemoryEnvironmentGenerator, + execute, is_committed, is_err_code, symbols_from_values, test_clarity_versions, test_epochs, + tl_env_factory as env_factory, TopLevelMemoryEnvironmentGenerator, }; use crate::vm::types::{AssetIdentifier, PrincipalData, QualifiedContractIdentifier, Value}; use crate::vm::version::ClarityVersion; use crate::vm::ContractContext; -use stacks_common::types::StacksEpochId; const FIRST_CLASS_TOKENS: &str = "(define-fungible-token stackaroos) (define-read-only (my-ft-get-balance (account principal)) diff --git a/clarity/src/vm/tests/contracts.rs b/clarity/src/vm/tests/contracts.rs index 10061417e3..4f30b9f777 100644 --- a/clarity/src/vm/tests/contracts.rs +++ b/clarity/src/vm/tests/contracts.rs @@ -14,27 +14,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#[cfg(any(test, feature = "testing"))] +use rstest::rstest; +use stacks_common::types::chainstate::BlockHeaderHash; +use stacks_common::types::StacksEpochId; + use crate::vm::ast::errors::ParseErrors; use crate::vm::ast::ASTRules; use crate::vm::contexts::Environment; use crate::vm::errors::{CheckErrors, Error, RuntimeErrorType}; -use crate::vm::execute as vm_execute; use crate::vm::tests::{ env_factory, execute, is_committed, is_err_code_i128 as is_err_code, symbols_from_values, - tl_env_factory, MemoryEnvironmentGenerator, TopLevelMemoryEnvironmentGenerator, + test_clarity_versions, test_epochs, tl_env_factory, MemoryEnvironmentGenerator, + TopLevelMemoryEnvironmentGenerator, }; -use crate::vm::tests::{test_clarity_versions, test_epochs}; use crate::vm::types::{ OptionalData, PrincipalData, QualifiedContractIdentifier, ResponseData, StandardPrincipalData, TypeSignature, Value, }; -use crate::vm::ClarityVersion; -#[cfg(any(test, feature = "testing"))] -use rstest::rstest; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::StacksEpochId; - -use crate::vm::ContractContext; +use crate::vm::{execute as vm_execute, ClarityVersion, ContractContext}; const FACTORIAL_CONTRACT: &str = "(define-map factorials { id: int } { current: int, index: int }) (define-private (init-factorial (id int) (factorial int)) diff --git a/clarity/src/vm/tests/datamaps.rs b/clarity/src/vm/tests/datamaps.rs index dbf8d74f0a..87f5dbcf30 100644 --- a/clarity/src/vm/tests/datamaps.rs +++ b/clarity/src/vm/tests/datamaps.rs @@ -14,14 +14,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::convert::{From, TryFrom}; + use crate::vm::errors::{CheckErrors, Error, ShortReturnType}; -use crate::vm::execute; use crate::vm::types::{ ListData, SequenceData, TupleData, TupleTypeSignature, TypeSignature, Value, }; -use crate::vm::ClarityName; -use std::convert::From; -use std::convert::TryFrom; +use crate::vm::{execute, ClarityName}; fn assert_executes(expected: Result, input: &str) { assert_eq!(expected.unwrap(), execute(input).unwrap().unwrap()); diff --git a/clarity/src/vm/tests/defines.rs b/clarity/src/vm/tests/defines.rs index 9d8e511f24..d77b693aa2 100644 --- a/clarity/src/vm/tests/defines.rs +++ b/clarity/src/vm/tests/defines.rs @@ -14,19 +14,18 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::tests::test_clarity_versions; - #[cfg(test)] use rstest::rstest; #[cfg(test)] use rstest_reuse::{self, *}; +use stacks_common::types::StacksEpochId; use crate::vm::ast::build_ast; use crate::vm::ast::errors::{ParseError, ParseErrors}; use crate::vm::errors::{CheckErrors, Error, RuntimeErrorType}; +use crate::vm::tests::test_clarity_versions; use crate::vm::types::{QualifiedContractIdentifier, TypeSignature, Value}; use crate::vm::{execute, ClarityVersion}; -use stacks_common::types::StacksEpochId; fn assert_eq_err(e1: CheckErrors, e2: Error) { let e1: Error = e1.into(); diff --git a/clarity/src/vm/tests/mod.rs b/clarity/src/vm/tests/mod.rs index 518b063e41..2f5da7e0a8 100644 --- a/clarity/src/vm/tests/mod.rs +++ b/clarity/src/vm/tests/mod.rs @@ -13,18 +13,16 @@ // // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::contexts::OwnedEnvironment; -use crate::vm::database::MemoryBackingStore; -use crate::vm::errors::Error; -use crate::vm::types::Value; - -use stacks_common::types::StacksEpochId; - -pub use crate::vm::database::BurnStateDB; use stacks_common::consts::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET}; +use stacks_common::types::StacksEpochId; pub use super::test_util::*; use super::ClarityVersion; +use crate::vm::contexts::OwnedEnvironment; +pub use crate::vm::database::BurnStateDB; +use crate::vm::database::MemoryBackingStore; +use crate::vm::errors::Error; +use crate::vm::types::Value; mod assets; mod contracts; diff --git a/clarity/src/vm/tests/principals.rs b/clarity/src/vm/tests/principals.rs index 684347406c..92de68254d 100644 --- a/clarity/src/vm/tests/principals.rs +++ b/clarity/src/vm/tests/principals.rs @@ -1,19 +1,16 @@ -use crate::vm::ast::ASTRules; -use crate::vm::execute_with_parameters; -use crate::vm::types::TypeSignature::PrincipalType; -use crate::vm::types::{ASCIIData, BuffData, CharType, SequenceData, Value}; -use crate::vm::ClarityVersion; +use stacks_common::types::StacksEpochId; +use stacks_common::util::hash::hex_bytes; +use crate::vm::ast::ASTRules; use crate::vm::errors::CheckErrors; +use crate::vm::functions::principals::PrincipalConstructErrorCode; +use crate::vm::types::TypeSignature::PrincipalType; use crate::vm::types::{ - OptionalData, PrincipalData, QualifiedContractIdentifier, ResponseData, StandardPrincipalData, - TupleData, TypeSignature, BUFF_1, BUFF_20, + ASCIIData, BuffData, CharType, OptionalData, PrincipalData, QualifiedContractIdentifier, + ResponseData, SequenceData, StandardPrincipalData, TupleData, TypeSignature, Value, BUFF_1, + BUFF_20, }; -use stacks_common::types::StacksEpochId; - -use crate::vm::functions::principals::PrincipalConstructErrorCode; - -use stacks_common::util::hash::hex_bytes; +use crate::vm::{execute_with_parameters, ClarityVersion}; #[test] fn test_simple_is_standard_check_inputs() { diff --git a/clarity/src/vm/tests/sequences.rs b/clarity/src/vm/tests/sequences.rs index 29704fd390..62cca99e67 100644 --- a/clarity/src/vm/tests/sequences.rs +++ b/clarity/src/vm/tests/sequences.rs @@ -14,20 +14,20 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::vm::types::signatures::SequenceSubtype; -use crate::vm::types::TypeSignature::{BoolType, IntType, SequenceType, UIntType}; -use crate::vm::types::{StringSubtype, StringUTF8Length, TypeSignature, Value}; +use std::convert::{TryFrom, TryInto}; + use rstest::rstest; use rstest_reuse::{self, *}; +use stacks_common::types::StacksEpochId; use crate::vm::errors::{CheckErrors, Error, RuntimeErrorType}; use crate::vm::tests::test_clarity_versions; +use crate::vm::types::signatures::SequenceSubtype; use crate::vm::types::signatures::SequenceSubtype::{BufferType, StringType}; use crate::vm::types::signatures::StringSubtype::ASCII; -use crate::vm::types::BufferLength; +use crate::vm::types::TypeSignature::{BoolType, IntType, SequenceType, UIntType}; +use crate::vm::types::{BufferLength, StringSubtype, StringUTF8Length, TypeSignature, Value}; use crate::vm::{execute, execute_v2, ClarityVersion}; -use stacks_common::types::StacksEpochId; -use std::convert::{TryFrom, TryInto}; #[test] fn test_simple_list_admission() { diff --git a/clarity/src/vm/tests/simple_apply_eval.rs b/clarity/src/vm/tests/simple_apply_eval.rs index ff17accf2b..86818063c4 100644 --- a/clarity/src/vm/tests/simple_apply_eval.rs +++ b/clarity/src/vm/tests/simple_apply_eval.rs @@ -16,35 +16,30 @@ use rstest::rstest; use rstest_reuse::{self, *}; +use stacks_common::address::{ + AddressHashMode, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, +}; +use stacks_common::consts::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET}; +use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey}; +use stacks_common::types::StacksEpochId; +use stacks_common::util::hash::{hex_bytes, to_hex}; -use crate::vm::ast::parse; - -use crate::vm::ast::ASTRules; +use crate::vm::ast::{parse, ASTRules}; use crate::vm::callables::DefinedFunction; use crate::vm::contexts::OwnedEnvironment; use crate::vm::costs::LimitedCostTracker; use crate::vm::database::MemoryBackingStore; use crate::vm::errors::{CheckErrors, Error, RuntimeErrorType, ShortReturnType}; -use crate::vm::tests::execute; -use crate::vm::tests::test_clarity_versions; +use crate::vm::tests::{execute, test_clarity_versions}; use crate::vm::types::signatures::*; -use crate::vm::types::StacksAddressExtensions; -use crate::vm::types::{ASCIIData, BuffData, CharType, QualifiedContractIdentifier, TypeSignature}; -use crate::vm::types::{PrincipalData, SequenceData}; -use crate::vm::ClarityVersion; +use crate::vm::types::{ + ASCIIData, BuffData, CharType, PrincipalData, QualifiedContractIdentifier, SequenceData, + StacksAddressExtensions, TypeSignature, +}; use crate::vm::{ - eval, execute as vm_execute, execute_v2 as vm_execute_v2, execute_with_parameters, + eval, execute as vm_execute, execute_v2 as vm_execute_v2, execute_with_parameters, CallStack, + ClarityVersion, ContractContext, Environment, GlobalContext, LocalContext, Value, }; -use crate::vm::{CallStack, ContractContext, Environment, GlobalContext, LocalContext, Value}; -use stacks_common::address::AddressHashMode; -use stacks_common::address::C32_ADDRESS_VERSION_MAINNET_SINGLESIG; -use stacks_common::address::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; -use stacks_common::consts::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET}; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksPrivateKey; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::types::StacksEpochId; -use stacks_common::util::hash::{hex_bytes, to_hex}; #[test] fn test_doubly_defined_persisted_vars() { diff --git a/clarity/src/vm/tests/traits.rs b/clarity/src/vm/tests/traits.rs index 6d231f55dd..1905031789 100644 --- a/clarity/src/vm/tests/traits.rs +++ b/clarity/src/vm/tests/traits.rs @@ -16,19 +16,16 @@ use stacks_common::types::StacksEpochId; +use super::MemoryEnvironmentGenerator; use crate::vm::ast::ASTRules; use crate::vm::errors::{CheckErrors, Error}; -use crate::vm::tests::{execute, symbols_from_values}; +use crate::vm::tests::{ + env_factory, execute, symbols_from_values, test_clarity_versions, test_epochs, +}; use crate::vm::types::{PrincipalData, QualifiedContractIdentifier, Value}; - -use crate::vm::tests::env_factory; -use crate::vm::tests::test_clarity_versions; -use crate::vm::tests::test_epochs; use crate::vm::version::ClarityVersion; use crate::vm::ContractContext; -use super::MemoryEnvironmentGenerator; - #[apply(test_clarity_versions)] fn test_dynamic_dispatch_by_defining_trait( version: ClarityVersion, diff --git a/clarity/src/vm/types/mod.rs b/clarity/src/vm/types/mod.rs index 39694bf18a..5aa298a139 100644 --- a/clarity/src/vm/types/mod.rs +++ b/clarity/src/vm/types/mod.rs @@ -21,31 +21,26 @@ pub mod signatures; use std::collections::BTreeMap; use std::convert::{TryFrom, TryInto}; -use std::{char, str}; -use std::{cmp, fmt}; +use std::{char, cmp, fmt, str}; use regex::Regex; - use stacks_common::address::c32; +use stacks_common::types::chainstate::StacksAddress; use stacks_common::types::StacksEpochId; use stacks_common::util::hash; -use stacks_common::types::chainstate::StacksAddress; - use crate::vm::errors::{ CheckErrors, IncomparableError, InterpreterError, InterpreterResult as Result, RuntimeErrorType, }; use crate::vm::representations::{ ClarityName, ContractName, SymbolicExpression, SymbolicExpressionType, }; - pub use crate::vm::types::signatures::{ parse_name_type_pairs, AssetIdentifier, BufferLength, FixedFunction, FunctionArg, FunctionSignature, FunctionType, ListTypeData, SequenceSubtype, StringSubtype, StringUTF8Length, TupleTypeSignature, TypeSignature, BUFF_1, BUFF_20, BUFF_21, BUFF_32, BUFF_33, BUFF_64, BUFF_65, }; - use crate::vm::ClarityVersion; pub const MAX_VALUE_SIZE: u32 = 1024 * 1024; // 1MB diff --git a/clarity/src/vm/types/serialization.rs b/clarity/src/vm/types/serialization.rs index cebd2f6eb9..6862f24b1e 100644 --- a/clarity/src/vm/types/serialization.rs +++ b/clarity/src/vm/types/serialization.rs @@ -21,8 +21,12 @@ use std::io::{Read, Write}; use std::{cmp, error, fmt, str}; use serde_json::Value as JSONValue; +use stacks_common::codec::{Error as codec_error, StacksMessageCodec}; use stacks_common::types::StacksEpochId; +use stacks_common::util::hash::{hex_bytes, to_hex}; +use stacks_common::util::retry::BoundReader; +use super::{ListTypeData, TupleTypeSignature}; use crate::vm::database::{ClarityDeserializable, ClaritySerializable}; use crate::vm::errors::{ CheckErrors, Error as ClarityError, IncomparableError, InterpreterError, InterpreterResult, @@ -31,18 +35,11 @@ use crate::vm::errors::{ use crate::vm::representations::{ClarityName, ContractName, MAX_STRING_LEN}; use crate::vm::types::signatures::CallableSubtype; use crate::vm::types::{ - BufferLength, CallableData, CharType, OptionalData, PrincipalData, QualifiedContractIdentifier, - ResponseData, SequenceData, SequenceSubtype, StandardPrincipalData, StringSubtype, - StringUTF8Length, TupleData, TypeSignature, Value, BOUND_VALUE_SERIALIZATION_BYTES, - MAX_TYPE_DEPTH, MAX_VALUE_SIZE, + byte_len_of_serialization, BufferLength, CallableData, CharType, OptionalData, PrincipalData, + QualifiedContractIdentifier, ResponseData, SequenceData, SequenceSubtype, + StandardPrincipalData, StringSubtype, StringUTF8Length, TupleData, TypeSignature, Value, + BOUND_VALUE_SERIALIZATION_BYTES, MAX_TYPE_DEPTH, MAX_VALUE_SIZE, }; -use stacks_common::util::hash::{hex_bytes, to_hex}; -use stacks_common::util::retry::BoundReader; - -use crate::vm::types::byte_len_of_serialization; -use stacks_common::codec::{Error as codec_error, StacksMessageCodec}; - -use super::{ListTypeData, TupleTypeSignature}; /// Errors that may occur in serialization or deserialization /// If deserialization failed because the described type is a bad type and @@ -1348,20 +1345,19 @@ impl std::hash::Hash for Value { #[cfg(test)] pub mod tests { + use std::io::Write; + use rstest::rstest; use rstest_reuse::{self, *}; + use stacks_common::types::StacksEpochId; - use std::io::Write; - + use super::super::*; + use super::SerializationError; use crate::vm::database::{ClarityDeserializable, ClaritySerializable, RollbackWrapper}; use crate::vm::errors::Error; use crate::vm::tests::test_clarity_versions; use crate::vm::types::TypeSignature::{BoolType, IntType}; - - use super::super::*; - use super::SerializationError; use crate::vm::ClarityVersion; - use stacks_common::types::StacksEpochId; fn buff_type(size: u32) -> TypeSignature { TypeSignature::SequenceType(SequenceSubtype::BufferType(size.try_into().unwrap())) diff --git a/clarity/src/vm/types/signatures.rs b/clarity/src/vm/types/signatures.rs index 4179364357..88b59c3ba5 100644 --- a/clarity/src/vm/types/signatures.rs +++ b/clarity/src/vm/types/signatures.rs @@ -21,20 +21,21 @@ use std::convert::{TryFrom, TryInto}; use std::hash::{Hash, Hasher}; use std::{cmp, fmt}; +use stacks_common::address::c32; +use stacks_common::types::StacksEpochId; +use stacks_common::util::hash; + use crate::vm::costs::{cost_functions, runtime_cost, CostOverflowingMath}; use crate::vm::errors::{CheckErrors, Error as VMError, IncomparableError, RuntimeErrorType}; -use crate::vm::representations::CONTRACT_MAX_NAME_LENGTH; use crate::vm::representations::{ ClarityName, ContractName, SymbolicExpression, SymbolicExpressionType, TraitDefinition, + CONTRACT_MAX_NAME_LENGTH, }; use crate::vm::types::{ CharType, PrincipalData, QualifiedContractIdentifier, SequenceData, SequencedValue, StandardPrincipalData, TraitIdentifier, Value, MAX_TYPE_DEPTH, MAX_VALUE_SIZE, WRAPPER_VALUE_SIZE, }; -use stacks_common::address::c32; -use stacks_common::types::StacksEpochId; -use stacks_common::util::hash; type Result = std::result::Result; @@ -1932,15 +1933,15 @@ impl fmt::Display for FunctionArg { #[cfg(test)] mod test { - use super::CheckErrors::*; - use super::*; - use crate::vm::{execute, ClarityVersion}; #[cfg(test)] use rstest::rstest; #[cfg(test)] use rstest_reuse::{self, *}; + use super::CheckErrors::*; + use super::*; use crate::vm::tests::test_clarity_versions; + use crate::vm::{execute, ClarityVersion}; fn fail_parse(val: &str, version: ClarityVersion, epoch: StacksEpochId) -> CheckErrors { use crate::vm::ast::parse; diff --git a/clarity/src/vm/variables.rs b/clarity/src/vm/variables.rs index ca5154b81b..286d661b41 100644 --- a/clarity/src/vm/variables.rs +++ b/clarity/src/vm/variables.rs @@ -16,13 +16,11 @@ use std::convert::TryFrom; use crate::vm::contexts::{Environment, LocalContext}; -use crate::vm::errors::{InterpreterResult as Result, RuntimeErrorType}; -use crate::vm::types::BuffData; -use crate::vm::types::Value; -use crate::vm::ClarityVersion; - use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::runtime_cost; +use crate::vm::errors::{InterpreterResult as Result, RuntimeErrorType}; +use crate::vm::types::{BuffData, Value}; +use crate::vm::ClarityVersion; define_versioned_named_enum!(NativeVariables(ClarityVersion) { ContractCaller("contract-caller", ClarityVersion::Clarity1), diff --git a/clarity/src/vm/version.rs b/clarity/src/vm/version.rs index 62b625e0a6..7da1f744f6 100644 --- a/clarity/src/vm/version.rs +++ b/clarity/src/vm/version.rs @@ -1,8 +1,10 @@ -use crate::vm::errors::{Error, RuntimeErrorType}; -use stacks_common::types::StacksEpochId; use std::fmt; use std::str::FromStr; +use stacks_common::types::StacksEpochId; + +use crate::vm::errors::{Error, RuntimeErrorType}; + #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, PartialOrd)] pub enum ClarityVersion { Clarity1, diff --git a/libsigner/src/events.rs b/libsigner/src/events.rs index 8ca2547d1e..23f5d0e4bf 100644 --- a/libsigner/src/events.rs +++ b/libsigner/src/events.rs @@ -14,22 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::sync::mpsc::Sender; - +use std::io::{Read, Write}; +use std::net::{SocketAddr, TcpListener, TcpStream}; use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::mpsc::Sender; use std::sync::Arc; -use std::net::SocketAddr; -use std::net::TcpListener; -use std::net::TcpStream; - -use std::io::{Read, Write}; - use clarity::vm::types::QualifiedContractIdentifier; use libstackerdb::StackerDBChunkData; - use serde::{Deserialize, Serialize}; - use tiny_http::{ Method as HttpMethod, Request as HttpRequest, Response as HttpResponse, Server as HttpServer, }; diff --git a/libsigner/src/http.rs b/libsigner/src/http.rs index 7bb7045e56..8926a3c4ef 100644 --- a/libsigner/src/http.rs +++ b/libsigner/src/http.rs @@ -17,15 +17,13 @@ use std::collections::HashMap; use std::io; use std::io::{Read, Write}; - use std::net::SocketAddr; use stacks_common::codec::MAX_MESSAGE_LEN; use stacks_common::deps_common::httparse; use stacks_common::util::chunked_encoding::*; -use crate::error::EventError; -use crate::error::RPCError; +use crate::error::{EventError, RPCError}; pub const MAX_HTTP_HEADERS: usize = 32; pub const MAX_HTTP_HEADER_LEN: usize = 4096; diff --git a/libsigner/src/libsigner.rs b/libsigner/src/libsigner.rs index 38819b7f52..3ab25f46e9 100644 --- a/libsigner/src/libsigner.rs +++ b/libsigner/src/libsigner.rs @@ -42,13 +42,10 @@ mod http; mod runloop; mod session; -pub use crate::session::{SignerSession, StackerDBSession}; - pub use crate::error::{EventError, RPCError}; - -pub use crate::runloop::{RunningSigner, Signer, SignerRunLoop}; - pub use crate::events::{ EventReceiver, EventStopSignaler, StackerDBChunksEvent, StackerDBEventReceiver, StackerDBStopSignaler, }; +pub use crate::runloop::{RunningSigner, Signer, SignerRunLoop}; +pub use crate::session::{SignerSession, StackerDBSession}; diff --git a/libsigner/src/runloop.rs b/libsigner/src/runloop.rs index 03c50bae41..2f4bbcf46b 100644 --- a/libsigner/src/runloop.rs +++ b/libsigner/src/runloop.rs @@ -24,13 +24,12 @@ use std::thread; use std::thread::JoinHandle; use std::time::Duration; -use crate::events::{EventReceiver, EventStopSignaler, StackerDBChunksEvent}; - -use crate::error::EventError; - use stacks_common::deps_common::ctrlc as termination; use stacks_common::deps_common::ctrlc::SignalId; +use crate::error::EventError; +use crate::events::{EventReceiver, EventStopSignaler, StackerDBChunksEvent}; + /// Some libcs, like musl, have a very small stack size. /// Make sure it's big enough. const THREAD_STACK_SIZE: usize = 128 * 1024 * 1024; // 128 MB @@ -134,6 +133,12 @@ impl RunningSigner { // kill event receiver self.stop_signal.send(); + self.join() + } + + /// Wait for the signer to terminate, and get the final state. + /// WARNING: This will hang forever if the event receiver stop signal was never sent/no error occurs. + pub fn join(self) -> Option { debug!("Try join event loop..."); // wait for event receiver join let _ = self.event_join.join().map_err(|thread_panic| { diff --git a/libsigner/src/session.rs b/libsigner/src/session.rs index 75b64dc5a2..b65e43467c 100644 --- a/libsigner/src/session.rs +++ b/libsigner/src/session.rs @@ -14,17 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::SocketAddr; -use std::net::TcpStream; +use std::net::{SocketAddr, TcpStream}; use std::str; +use clarity::vm::types::QualifiedContractIdentifier; use libstackerdb::{ stackerdb_get_chunk_path, stackerdb_get_metadata_path, stackerdb_post_chunk_path, SlotMetadata, StackerDBChunkAckData, StackerDBChunkData, }; -use clarity::vm::types::QualifiedContractIdentifier; - use crate::error::RPCError; use crate::http::run_http_request; diff --git a/libsigner/src/tests/http.rs b/libsigner/src/tests/http.rs index be34036ff0..eb187700e8 100644 --- a/libsigner/src/tests/http.rs +++ b/libsigner/src/tests/http.rs @@ -15,17 +15,14 @@ // along with this program. If not, see . use std::collections::HashMap; -use std::io; -use std::io::Read; -use std::io::Write; -use std::str; - -use crate::error::EventError; -use crate::error::RPCError; -use crate::http::{decode_http_body, decode_http_request, decode_http_response, run_http_request}; +use std::io::{Read, Write}; +use std::{io, str}; use stacks_common::util::chunked_encoding::*; +use crate::error::{EventError, RPCError}; +use crate::http::{decode_http_body, decode_http_request, decode_http_response, run_http_request}; + #[test] fn test_decode_http_request_ok() { let tests = vec![ diff --git a/libsigner/src/tests/mod.rs b/libsigner/src/tests/mod.rs index fc4d45ddfb..ffe8d4d9ee 100644 --- a/libsigner/src/tests/mod.rs +++ b/libsigner/src/tests/mod.rs @@ -17,20 +17,17 @@ mod http; use std::io::Write; -use std::mem; use std::net::{SocketAddr, TcpStream, ToSocketAddrs}; use std::sync::mpsc::{channel, Receiver, Sender}; -use std::thread; use std::time::Duration; - -use crate::{Signer, SignerRunLoop, StackerDBChunksEvent, StackerDBEventReceiver}; +use std::{mem, thread}; use clarity::vm::types::QualifiedContractIdentifier; - +use libstackerdb::StackerDBChunkData; use stacks_common::util::secp256k1::Secp256k1PrivateKey; use stacks_common::util::sleep_ms; -use libstackerdb::StackerDBChunkData; +use crate::{Signer, SignerRunLoop, StackerDBChunksEvent, StackerDBEventReceiver}; /// Simple runloop implementation. It receives `max_events` events and returns `events` from the /// last call to `run_one_pass` as its final state. diff --git a/libstackerdb/src/libstackerdb.rs b/libstackerdb/src/libstackerdb.rs index 34136433ec..d4ae0740bc 100644 --- a/libstackerdb/src/libstackerdb.rs +++ b/libstackerdb/src/libstackerdb.rs @@ -19,28 +19,20 @@ extern crate serde; extern crate sha2; extern crate stacks_common; -use std::error; -use std::fmt; use std::io::{Read, Write}; +use std::{error, fmt}; +use clarity::vm::types::QualifiedContractIdentifier; +use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha512_256}; - +use stacks_common::codec::{ + read_next, read_next_at_most, write_next, Error as CodecError, StacksMessageCodec, +}; use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey}; use stacks_common::types::PrivateKey; use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, Sha512Trunc256Sum}; - -use stacks_common::codec::read_next; -use stacks_common::codec::read_next_at_most; -use stacks_common::codec::write_next; -use stacks_common::codec::Error as CodecError; -use stacks_common::codec::StacksMessageCodec; - use stacks_common::util::secp256k1::MessageSignature; -use serde::{Deserialize, Serialize}; - -use clarity::vm::types::QualifiedContractIdentifier; - /// maximum chunk size (1 MB) pub const STACKERDB_MAX_CHUNK_SIZE: u32 = 1024 * 1024; diff --git a/libstackerdb/src/tests/mod.rs b/libstackerdb/src/tests/mod.rs index 357e2c8e44..bd63ae7c56 100644 --- a/libstackerdb/src/tests/mod.rs +++ b/libstackerdb/src/tests/mod.rs @@ -14,19 +14,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use stacks_common::types::chainstate::StacksAddress; - -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::secp256k1::MessageSignature; - +use clarity::vm::types::QualifiedContractIdentifier; use stacks_common::address::{AddressHashMode, C32_ADDRESS_VERSION_MAINNET_SINGLESIG}; -use stacks_common::types::chainstate::{StacksPrivateKey, StacksPublicKey}; +use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey}; +use stacks_common::util::hash::{Hash160, Sha512Trunc256Sum}; +use stacks_common::util::secp256k1::MessageSignature; use crate::*; -use clarity::vm::types::QualifiedContractIdentifier; - #[test] fn test_stackerdb_slot_metadata_sign_verify() { let pk = StacksPrivateKey::new(); diff --git a/pox-locking/src/events.rs b/pox-locking/src/events.rs index f37fdc68e4..9f44330c33 100644 --- a/pox-locking/src/events.rs +++ b/pox-locking/src/events.rs @@ -335,7 +335,7 @@ fn create_event_info_data_code(function_name: &str, args: &[Value]) -> String { pox_addr = &args[3], ) } - _ => format!("{{ data: {{ unimplemented: true }} }}"), + _ => "{{ data: {{ unimplemented: true }} }}".into(), } } diff --git a/pox-locking/src/lib.rs b/pox-locking/src/lib.rs index 9d8da81482..b195f4cc9b 100644 --- a/pox-locking/src/lib.rs +++ b/pox-locking/src/lib.rs @@ -49,9 +49,9 @@ pub enum LockingError { PoxInvalidIncrease, } -pub const POX_1_NAME: &'static str = "pox"; -pub const POX_2_NAME: &'static str = "pox-2"; -pub const POX_3_NAME: &'static str = "pox-3"; +pub const POX_1_NAME: &str = "pox"; +pub const POX_2_NAME: &str = "pox-2"; +pub const POX_3_NAME: &str = "pox-3"; /// Handle special cases of contract-calls -- namely, those into PoX that should lock up STX pub fn handle_contract_call_special_cases( diff --git a/pox-locking/src/pox_1.rs b/pox-locking/src/pox_1.rs index 2f9a1010d9..95e44809d3 100644 --- a/pox-locking/src/pox_1.rs +++ b/pox-locking/src/pox_1.rs @@ -19,8 +19,7 @@ use clarity::vm::contexts::GlobalContext; use clarity::vm::costs::cost_functions::ClarityCostFunction; use clarity::vm::costs::runtime_cost; use clarity::vm::database::ClarityDatabase; -use clarity::vm::errors::Error as ClarityError; -use clarity::vm::errors::RuntimeErrorType; +use clarity::vm::errors::{Error as ClarityError, RuntimeErrorType}; use clarity::vm::events::{STXEventType, STXLockEventData, StacksTransactionEvent}; use clarity::vm::types::PrincipalData; use clarity::vm::Value; @@ -41,19 +40,19 @@ fn parse_pox_stacking_result_v1( let tuple_data = res.expect_tuple(); let stacker = tuple_data .get("stacker") - .expect(&format!("FATAL: no 'stacker'")) + .expect("FATAL: no 'stacker'") .to_owned() .expect_principal(); let lock_amount = tuple_data .get("lock-amount") - .expect(&format!("FATAL: no 'lock-amount'")) + .expect("FATAL: no 'lock-amount'") .to_owned() .expect_u128(); let unlock_burn_height = tuple_data .get("unlock-burn-height") - .expect(&format!("FATAL: no 'unlock-burn-height'")) + .expect("FATAL: no 'unlock-burn-height'") .to_owned() .expect_u128() .try_into() @@ -120,6 +119,7 @@ pub fn pox_lock_v1( } /// Handle special cases when calling into the PoX v1 contract +#[allow(clippy::needless_return)] pub fn handle_contract_call( global_context: &mut GlobalContext, _sender_opt: Option<&PrincipalData>, @@ -159,7 +159,7 @@ pub fn handle_contract_call( &mut global_context.database, &stacker, locked_amount, - unlock_height as u64, + unlock_height, ) { Ok(_) => { if let Some(batch) = global_context.event_batches.last_mut() { @@ -172,12 +172,13 @@ pub fn handle_contract_call( }), )); } + return Ok(()); } Err(LockingError::DefunctPoxContract) => { return Err(ClarityError::Runtime( RuntimeErrorType::DefunctPoxContract, None, - )) + )); } Err(LockingError::PoxAlreadyLocked) => { // the caller tried to lock tokens into both pox-1 and pox-2 @@ -193,6 +194,4 @@ pub fn handle_contract_call( ); } } - - Ok(()) } diff --git a/pox-locking/src/pox_2.rs b/pox-locking/src/pox_2.rs index e49b99257d..34c2f3a957 100644 --- a/pox-locking/src/pox_2.rs +++ b/pox-locking/src/pox_2.rs @@ -19,13 +19,11 @@ use clarity::vm::contexts::GlobalContext; use clarity::vm::costs::cost_functions::ClarityCostFunction; use clarity::vm::costs::runtime_cost; use clarity::vm::database::{ClarityDatabase, STXBalance}; -use clarity::vm::errors::Error as ClarityError; -use clarity::vm::errors::RuntimeErrorType; +use clarity::vm::errors::{Error as ClarityError, RuntimeErrorType}; use clarity::vm::events::{STXEventType, STXLockEventData, StacksTransactionEvent}; use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; use clarity::vm::{Environment, Value}; -use slog::slog_debug; -use slog::slog_error; +use slog::{slog_debug, slog_error}; use stacks_common::{debug, error}; use crate::events::synthesize_pox_2_or_3_event_info; @@ -70,19 +68,19 @@ pub fn parse_pox_stacking_result( let tuple_data = res.expect_tuple(); let stacker = tuple_data .get("stacker") - .expect(&format!("FATAL: no 'stacker'")) + .expect("FATAL: no 'stacker'") .to_owned() .expect_principal(); let lock_amount = tuple_data .get("lock-amount") - .expect(&format!("FATAL: no 'lock-amount'")) + .expect("FATAL: no 'lock-amount'") .to_owned() .expect_u128(); let unlock_burn_height = tuple_data .get("unlock-burn-height") - .expect(&format!("FATAL: no 'unlock-burn-height'")) + .expect("FATAL: no 'unlock-burn-height'") .to_owned() .expect_u128() .try_into() @@ -104,13 +102,13 @@ pub fn parse_pox_extend_result(result: &Value) -> std::result::Result<(Principal let tuple_data = res.expect_tuple(); let stacker = tuple_data .get("stacker") - .expect(&format!("FATAL: no 'stacker'")) + .expect("FATAL: no 'stacker'") .to_owned() .expect_principal(); let unlock_burn_height = tuple_data .get("unlock-burn-height") - .expect(&format!("FATAL: no 'unlock-burn-height'")) + .expect("FATAL: no 'unlock-burn-height'") .to_owned() .expect_u128() .try_into() @@ -133,13 +131,13 @@ pub fn parse_pox_increase(result: &Value) -> std::result::Result<(PrincipalData, let tuple_data = res.expect_tuple(); let stacker = tuple_data .get("stacker") - .expect(&format!("FATAL: no 'stacker'")) + .expect("FATAL: no 'stacker'") .to_owned() .expect_principal(); let total_locked = tuple_data .get("total-locked") - .expect(&format!("FATAL: no 'total-locked'")) + .expect("FATAL: no 'total-locked'") .to_owned() .expect_u128(); @@ -274,6 +272,7 @@ fn pox_lock_v2( } /// Handle responses from stack-stx and delegate-stack-stx -- functions that *lock up* STX +#[allow(clippy::needless_return)] fn handle_stack_lockup_pox_v2( global_context: &mut GlobalContext, function_name: &str, @@ -302,7 +301,7 @@ fn handle_stack_lockup_pox_v2( &mut global_context.database, &stacker, locked_amount, - unlock_height as u64, + unlock_height, ) { Ok(_) => { let event = @@ -338,6 +337,7 @@ fn handle_stack_lockup_pox_v2( /// Handle responses from stack-extend and delegate-stack-extend -- functions that *extend /// already-locked* STX. +#[allow(clippy::needless_return)] fn handle_stack_lockup_extension_pox_v2( global_context: &mut GlobalContext, function_name: &str, @@ -370,7 +370,7 @@ fn handle_stack_lockup_extension_pox_v2( } }; - match pox_lock_extend_v2(&mut global_context.database, &stacker, unlock_height as u64) { + match pox_lock_extend_v2(&mut global_context.database, &stacker, unlock_height) { Ok(locked_amount) => { let event = StacksTransactionEvent::STXEvent(STXEventType::STXLockEvent(STXLockEventData { @@ -385,7 +385,7 @@ fn handle_stack_lockup_extension_pox_v2( return Err(ClarityError::Runtime( RuntimeErrorType::DefunctPoxContract, None, - )) + )); } Err(e) => { // Error results *other* than a DefunctPoxContract panic, because @@ -401,6 +401,7 @@ fn handle_stack_lockup_extension_pox_v2( /// Handle responses from stack-increase and delegate-stack-increase -- functions that *increase /// already-locked* STX amounts. +#[allow(clippy::needless_return)] fn handle_stack_lockup_increase_pox_v2( global_context: &mut GlobalContext, function_name: &str, @@ -447,7 +448,7 @@ fn handle_stack_lockup_increase_pox_v2( return Err(ClarityError::Runtime( RuntimeErrorType::DefunctPoxContract, None, - )) + )); } Err(e) => { // Error results *other* than a DefunctPoxContract panic, because diff --git a/pox-locking/src/pox_3.rs b/pox-locking/src/pox_3.rs index 7e045a9429..cccfbb2644 100644 --- a/pox-locking/src/pox_3.rs +++ b/pox-locking/src/pox_3.rs @@ -19,20 +19,17 @@ use clarity::vm::contexts::GlobalContext; use clarity::vm::costs::cost_functions::ClarityCostFunction; use clarity::vm::costs::runtime_cost; use clarity::vm::database::{ClarityDatabase, STXBalance}; -use clarity::vm::errors::Error as ClarityError; -use clarity::vm::errors::RuntimeErrorType; +use clarity::vm::errors::{Error as ClarityError, RuntimeErrorType}; use clarity::vm::events::{STXEventType, STXLockEventData, StacksTransactionEvent}; use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; use clarity::vm::{Environment, Value}; -use slog::slog_debug; -use slog::slog_error; +use slog::{slog_debug, slog_error}; use stacks_common::{debug, error}; use crate::events::synthesize_pox_2_or_3_event_info; -use crate::LockingError; -use crate::POX_3_NAME; // Note: PoX-3 uses the same contract-call result parsing routines as PoX-2 use crate::pox_2::{parse_pox_extend_result, parse_pox_increase, parse_pox_stacking_result}; +use crate::{LockingError, POX_3_NAME}; /////////////////////// PoX-3 ///////////////////////////////// @@ -156,6 +153,7 @@ pub fn pox_lock_increase_v3( /////////////// PoX-3 ////////////////////////////////////////// /// Handle responses from stack-stx and delegate-stack-stx in pox-3 -- functions that *lock up* STX +#[allow(clippy::needless_return)] fn handle_stack_lockup_pox_v3( global_context: &mut GlobalContext, function_name: &str, @@ -186,7 +184,7 @@ fn handle_stack_lockup_pox_v3( &mut global_context.database, &stacker, locked_amount, - unlock_height as u64, + unlock_height, ) { Ok(_) => { let event = @@ -222,6 +220,7 @@ fn handle_stack_lockup_pox_v3( /// Handle responses from stack-extend and delegate-stack-extend in pox-3 -- functions that *extend /// already-locked* STX. +#[allow(clippy::needless_return)] fn handle_stack_lockup_extension_pox_v3( global_context: &mut GlobalContext, function_name: &str, @@ -254,7 +253,7 @@ fn handle_stack_lockup_extension_pox_v3( } }; - match pox_lock_extend_v3(&mut global_context.database, &stacker, unlock_height as u64) { + match pox_lock_extend_v3(&mut global_context.database, &stacker, unlock_height) { Ok(locked_amount) => { let event = StacksTransactionEvent::STXEvent(STXEventType::STXLockEvent(STXLockEventData { @@ -269,7 +268,7 @@ fn handle_stack_lockup_extension_pox_v3( return Err(ClarityError::Runtime( RuntimeErrorType::DefunctPoxContract, None, - )) + )); } Err(e) => { // Error results *other* than a DefunctPoxContract panic, because @@ -285,6 +284,7 @@ fn handle_stack_lockup_extension_pox_v3( /// Handle responses from stack-increase and delegate-stack-increase in PoX-3 -- functions /// that *increase already-locked* STX amounts. +#[allow(clippy::needless_return)] fn handle_stack_lockup_increase_pox_v3( global_context: &mut GlobalContext, function_name: &str, @@ -330,7 +330,7 @@ fn handle_stack_lockup_increase_pox_v3( return Err(ClarityError::Runtime( RuntimeErrorType::DefunctPoxContract, None, - )) + )); } Err(e) => { // Error results *other* than a DefunctPoxContract panic, because diff --git a/stacks-common/src/address/b58.rs b/stacks-common/src/address/b58.rs index fd83bfdef1..6a135392e5 100644 --- a/stacks-common/src/address/b58.rs +++ b/stacks-common/src/address/b58.rs @@ -19,7 +19,7 @@ use std::{error, fmt, str}; use crate::address::Error; use crate::util::hash::DoubleSha256; -static BASE58_CHARS: &'static [u8] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; +static BASE58_CHARS: &[u8] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; static BASE58_DIGITS: [Option; 128] = [ None, @@ -242,9 +242,7 @@ where } // ... then reverse it and convert to chars - for _ in 0..leading_zero_count { - ret.push(0); - } + ret.extend(vec![0; leading_zero_count]); ret.reverse(); for ch in ret.iter_mut() { *ch = BASE58_CHARS[*ch as usize]; @@ -277,14 +275,14 @@ pub fn encode_slice(data: &[u8]) -> String { /// Obtain a string with the base58check encoding of a slice /// (Tack the first 4 256-digits of the object's Bitcoin hash onto the end.) pub fn check_encode_slice(data: &[u8]) -> String { - let checksum = DoubleSha256::from_data(&data); + let checksum = DoubleSha256::from_data(data); encode_iter(data.iter().cloned().chain(checksum[0..4].iter().cloned())) } /// Obtain a string with the base58check encoding of a slice /// (Tack the first 4 256-digits of the object's Bitcoin hash onto the end.) pub fn check_encode_slice_to_fmt(fmt: &mut fmt::Formatter, data: &[u8]) -> fmt::Result { - let checksum = DoubleSha256::from_data(&data); + let checksum = DoubleSha256::from_data(data); let iter = data.iter().cloned().chain(checksum[0..4].iter().cloned()); encode_iter_to_fmt(fmt, iter) } diff --git a/stacks-common/src/address/c32.rs b/stacks-common/src/address/c32.rs index 1978a661a1..60fa7e6552 100644 --- a/stacks-common/src/address/c32.rs +++ b/stacks-common/src/address/c32.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use super::Error; - -use sha2::Digest; -use sha2::Sha256; use std::convert::TryFrom; +use sha2::{Digest, Sha256}; + +use super::Error; + const C32_CHARACTERS: &[u8; 32] = b"0123456789ABCDEFGHJKMNPQRSTVWXYZ"; /// C32 chars as an array, indexed by their ASCII code for O(1) lookups. @@ -195,8 +195,8 @@ fn c32_encode(input_bytes: &[u8]) -> String { if carry_bits >= 5 { let c32_value = carry & ((1 << 5) - 1); result.push(C32_CHARACTERS[c32_value as usize]); - carry_bits = carry_bits - 5; - carry = carry >> 5; + carry_bits -= 5; + carry >>= 5; } } @@ -241,9 +241,8 @@ fn c32_decode_ascii(input_str: &str) -> Result, Error> { let mut iter_c32_digits = Vec::::with_capacity(input_str.len()); for x in input_str.as_bytes().iter().rev() { - match C32_CHARACTERS_MAP.get(*x as usize) { - Some(&Some(x)) => iter_c32_digits.push(x), - _ => {} + if let Some(Some(x)) = C32_CHARACTERS_MAP.get(*x as usize) { + iter_c32_digits.push(*x) } } @@ -259,7 +258,7 @@ fn c32_decode_ascii(input_str: &str) -> Result, Error> { if carry_bits >= 8 { result.push((carry & ((1 << 8) - 1)) as u8); carry_bits -= 8; - carry = carry >> 8; + carry >>= 8; } } @@ -370,12 +369,13 @@ pub fn c32_address(version: u8, data: &[u8]) -> Result { #[cfg(test)] mod test { + use rand::Rng; + use super::super::c32_old::{ c32_address as c32_address_old, c32_address_decode as c32_address_decode_old, }; use super::*; use crate::util::hash::hex_bytes; - use rand::Rng; #[test] fn old_c32_validation() { @@ -462,17 +462,15 @@ mod test { ], ]; - for i in 0..hex_strs.len() { - for j in 0..versions.len() { - let h = hex_strs[i]; - let v = versions[j]; + for (i, h) in hex_strs.iter().enumerate() { + for (j, v) in versions.iter().enumerate() { let b = hex_bytes(h).unwrap(); - let z = c32_address(v, &b).unwrap(); + let z = c32_address(*v, &b).unwrap(); assert_eq!(z, c32_addrs[j][i]); let (decoded_version, decoded_bytes) = c32_address_decode(&z).unwrap(); - assert_eq!(decoded_version, v); + assert_eq!(decoded_version, *v); assert_eq!(decoded_bytes, b); } } @@ -566,11 +564,9 @@ mod test { #[test] fn test_ascii_only() { - match c32_address_decode("S\u{1D7D8}2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE") { - Err(Error::InvalidCrockford32) => {} - _ => { - assert!(false); - } - } + assert!(matches!( + c32_address_decode("S\u{1D7D8}2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKPVKG2CE"), + Err(Error::InvalidCrockford32) + )); } } diff --git a/stacks-common/src/address/c32_old.rs b/stacks-common/src/address/c32_old.rs index d4ac6dbf77..37cd599304 100644 --- a/stacks-common/src/address/c32_old.rs +++ b/stacks-common/src/address/c32_old.rs @@ -17,10 +17,9 @@ //! This module (`c32_old`) is only here to test compatibility with the new `c32` //! module. It will be removed in the next network upgrade. -use super::Error; +use sha2::{Digest, Sha256}; -use sha2::Digest; -use sha2::Sha256; +use super::Error; const C32_CHARACTERS: &str = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; @@ -42,8 +41,8 @@ fn c32_encode(input_bytes: &[u8]) -> String { if carry_bits >= 5 { let c32_value = carry & ((1 << 5) - 1); result.push(c32_chars[c32_value as usize]); - carry_bits = carry_bits - 5; - carry = carry >> 5; + carry_bits -= 5; + carry >>= 5; } } @@ -75,9 +74,8 @@ fn c32_encode(input_bytes: &[u8]) -> String { fn c32_normalize(input_str: &str) -> String { let norm_str: String = input_str .to_uppercase() - .replace("O", "0") - .replace("L", "1") - .replace("I", "1"); + .replace('O', "0") + .replace(['L', 'I'], "1"); norm_str } @@ -100,7 +98,7 @@ fn c32_decode(input_str: &str) -> Result, Error> { let iter_c32_digits: Vec = iter_c32_digits_opts .iter() .filter_map(|x| x.as_ref()) - .map(|ref_x| *ref_x) + .copied() .collect(); if iter_c32_digits.len() != iter_c32_digits_opts.len() { @@ -115,7 +113,7 @@ fn c32_decode(input_str: &str) -> Result, Error> { if carry_bits >= 8 { result.push((carry & ((1 << 8) - 1)) as u8); carry_bits -= 8; - carry = carry >> 8; + carry >>= 8; } } @@ -153,7 +151,7 @@ fn double_sha256_checksum(data: &[u8]) -> Vec { tmp.copy_from_slice(sha2.finalize().as_slice()); let mut sha2_2 = Sha256::new(); - sha2_2.update(&tmp); + sha2_2.update(tmp); tmp_2.copy_from_slice(sha2_2.finalize().as_slice()); tmp_2[0..4].to_vec() diff --git a/stacks-common/src/address/mod.rs b/stacks-common/src/address/mod.rs index d89b863347..ad8545dca7 100644 --- a/stacks-common/src/address/mod.rs +++ b/stacks-common/src/address/mod.rs @@ -14,21 +14,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::error; -use std::fmt; +use std::convert::TryFrom; +use std::{error, fmt}; -use crate::types::PublicKey; +use sha2::{Digest, Sha256}; use crate::deps_common::bitcoin::blockdata::opcodes::All as btc_opcodes; use crate::deps_common::bitcoin::blockdata::script::{Builder, Instruction, Script}; - +use crate::types::PublicKey; use crate::util::hash::Hash160; -use sha2::Digest; -use sha2::Sha256; - -use std::convert::TryFrom; - pub mod b58; pub mod c32; #[cfg(test)] @@ -156,8 +151,7 @@ impl TryFrom for AddressHashMode { /// single-sig address (p2pkh) /// Get back the hash of the address fn to_bits_p2pkh(pubk: &K) -> Hash160 { - let key_hash = Hash160::from_data(&pubk.to_bytes()); - key_hash + Hash160::from_data(&pubk.to_bytes()) } /// Internally, the Stacks blockchain encodes address the same as Bitcoin @@ -172,8 +166,7 @@ fn to_bits_p2sh(num_sigs: usize, pubkeys: &Vec) -> Hash160 { bldr = bldr.push_opcode(btc_opcodes::OP_CHECKMULTISIG); let script = bldr.into_script(); - let script_hash = Hash160::from_data(&script.as_bytes()); - script_hash + Hash160::from_data(script.as_bytes()) } /// Internally, the Stacks blockchain encodes address the same as Bitcoin @@ -184,8 +177,7 @@ fn to_bits_p2sh_p2wpkh(pubk: &K) -> Hash160 { let bldr = Builder::new().push_int(0).push_slice(key_hash.as_bytes()); let script = bldr.into_script(); - let script_hash = Hash160::from_data(&script.as_bytes()); - script_hash + Hash160::from_data(script.as_bytes()) } /// Internally, the Stacks blockchain encodes address the same as Bitcoin @@ -206,8 +198,7 @@ fn to_bits_p2sh_p2wsh(num_sigs: usize, pubkeys: &Vec) -> Hash16 d.copy_from_slice(digest.finalize().as_slice()); let ws = Builder::new().push_int(0).push_slice(&d).into_script(); - let ws_hash = Hash160::from_data(&ws.as_bytes()); - ws_hash + Hash160::from_data(ws.as_bytes()) } /// Convert a number of required signatures and a list of public keys into a byte-vec to hash to an @@ -290,12 +281,10 @@ mod test { } else { AddressHashMode::SerializeP2SH } + } else if pubkey_fixture.num_required == 1 { + AddressHashMode::SerializeP2WPKH } else { - if pubkey_fixture.num_required == 1 { - AddressHashMode::SerializeP2WPKH - } else { - AddressHashMode::SerializeP2WSH - } + AddressHashMode::SerializeP2WSH }; let result_hash = public_keys_to_address_hash( diff --git a/stacks-common/src/codec/mod.rs b/stacks-common/src/codec/mod.rs index 6145e60b22..c2d9fd9610 100644 --- a/stacks-common/src/codec/mod.rs +++ b/stacks-common/src/codec/mod.rs @@ -143,14 +143,12 @@ fn read_next_vec( len, max_items ))); } - } else { - if len != num_items { - // inexact item count - return Err(Error::DeserializeError(format!( - "Array has incorrect number of items ({} != {})", - len, num_items - ))); - } + } else if len != num_items { + // inexact item count + return Err(Error::DeserializeError(format!( + "Array has incorrect number of items ({} != {})", + len, num_items + ))); } if (mem::size_of::() as u128) * (len as u128) > MAX_MESSAGE_LEN as u128 { @@ -192,8 +190,8 @@ where fn consensus_serialize(&self, fd: &mut W) -> Result<(), Error> { let len = self.len() as u32; write_next(fd, &len)?; - for i in 0..self.len() { - write_next(fd, &self[i])?; + for item in self { + write_next(fd, item)?; } Ok(()) } diff --git a/stacks-common/src/deps_common/bech32/mod.rs b/stacks-common/src/deps_common/bech32/mod.rs index 95580ec263..5151267962 100644 --- a/stacks-common/src/deps_common/bech32/mod.rs +++ b/stacks-common/src/deps_common/bech32/mod.rs @@ -62,16 +62,14 @@ extern crate alloc; #[cfg(any(test, feature = "std"))] extern crate core; -#[cfg(all(not(feature = "std"), not(test)))] -use alloc::{string::String, vec::Vec}; - #[cfg(all(not(feature = "std"), not(test)))] use alloc::borrow::Cow; +#[cfg(all(not(feature = "std"), not(test)))] +use alloc::{string::String, vec::Vec}; +use core::{fmt, mem}; #[cfg(any(feature = "std", test))] use std::borrow::Cow; -use core::{fmt, mem}; - /// Integer in the range `0..32` #[derive(PartialEq, Eq, Debug, Copy, Clone, Default, PartialOrd, Ord, Hash)] #[allow(non_camel_case_types)] @@ -376,9 +374,9 @@ fn check_hrp(hrp: &str) -> Result { return Err(Error::InvalidChar(b as char)); } - if (b'a'..=b'z').contains(&b) { + if b.is_ascii_lowercase() { has_lower = true; - } else if (b'A'..=b'Z').contains(&b) { + } else if b.is_ascii_uppercase() { has_upper = true; }; diff --git a/stacks-common/src/deps_common/bitcoin/blockdata/block.rs b/stacks-common/src/deps_common/bitcoin/blockdata/block.rs index 40a1037711..af064511b5 100644 --- a/stacks-common/src/deps_common/bitcoin/blockdata/block.rs +++ b/stacks-common/src/deps_common/bitcoin/blockdata/block.rs @@ -20,8 +20,6 @@ //! these blocks and the blockchain. //! -use crate::util::uint::Uint256; - use crate::deps_common::bitcoin::blockdata::constants::max_target; use crate::deps_common::bitcoin::blockdata::transaction::Transaction; use crate::deps_common::bitcoin::network::constants::Network; @@ -31,6 +29,7 @@ use crate::deps_common::bitcoin::util; use crate::deps_common::bitcoin::util::hash::Sha256dHash; use crate::deps_common::bitcoin::util::Error; use crate::deps_common::bitcoin::util::Error::{SpvBadProofOfWork, SpvBadTarget}; +use crate::util::uint::Uint256; /// A block header, which contains all the block's information except /// the actual transactions @@ -179,10 +178,9 @@ impl_consensus_encoding!(LoneBlockHeader, header, tx_count); #[cfg(test)] mod tests { - use crate::util::hash::hex_bytes as hex_decode; - use crate::deps_common::bitcoin::blockdata::block::{Block, BlockHeader}; use crate::deps_common::bitcoin::network::serialize::{deserialize, serialize}; + use crate::util::hash::hex_bytes as hex_decode; #[test] fn block_test() { diff --git a/stacks-common/src/deps_common/bitcoin/blockdata/constants.rs b/stacks-common/src/deps_common/bitcoin/blockdata/constants.rs index 20656276ee..4a9cfddef7 100644 --- a/stacks-common/src/deps_common/bitcoin/blockdata/constants.rs +++ b/stacks-common/src/deps_common/bitcoin/blockdata/constants.rs @@ -22,9 +22,8 @@ use std::default::Default; use crate::deps_common::bitcoin::blockdata::block::{Block, BlockHeader}; -use crate::deps_common::bitcoin::blockdata::opcodes; -use crate::deps_common::bitcoin::blockdata::script; use crate::deps_common::bitcoin::blockdata::transaction::{OutPoint, Transaction, TxIn, TxOut}; +use crate::deps_common::bitcoin::blockdata::{opcodes, script}; use crate::deps_common::bitcoin::network::constants::Network; use crate::deps_common::bitcoin::util::hash::MerkleRoot; use crate::util::hash::hex_bytes; @@ -104,7 +103,7 @@ pub fn genesis_block(network: Network) -> Block { bits: 0x1d00ffff, nonce: 2083236893, }, - txdata: txdata, + txdata, } } Network::Testnet => { @@ -118,7 +117,7 @@ pub fn genesis_block(network: Network) -> Block { bits: 0x1d00ffff, nonce: 414098458, }, - txdata: txdata, + txdata, } } Network::Regtest => { @@ -132,7 +131,7 @@ pub fn genesis_block(network: Network) -> Block { bits: 0x207fffff, nonce: 2, }, - txdata: txdata, + txdata, } } } @@ -140,13 +139,14 @@ pub fn genesis_block(network: Network) -> Block { #[cfg(test)] mod test { - use crate::util::hash::hex_bytes as hex_decode; use std::default::Default; - use crate::deps_common::bitcoin::blockdata::constants::{bitcoin_genesis_tx, genesis_block}; - use crate::deps_common::bitcoin::blockdata::constants::{COIN_VALUE, MAX_SEQUENCE}; + use crate::deps_common::bitcoin::blockdata::constants::{ + bitcoin_genesis_tx, genesis_block, COIN_VALUE, MAX_SEQUENCE, + }; use crate::deps_common::bitcoin::network::constants::Network; use crate::deps_common::bitcoin::network::serialize::{serialize, BitcoinHash}; + use crate::util::hash::hex_bytes as hex_decode; #[test] fn bitcoin_genesis_first_transaction() { diff --git a/stacks-common/src/deps_common/bitcoin/blockdata/opcodes.rs b/stacks-common/src/deps_common/bitcoin/blockdata/opcodes.rs index 1f2cf1f9a7..5e628b06f8 100644 --- a/stacks-common/src/deps_common/bitcoin/blockdata/opcodes.rs +++ b/stacks-common/src/deps_common/bitcoin/blockdata/opcodes.rs @@ -20,12 +20,12 @@ #![allow(non_camel_case_types)] -#[cfg(feature = "serde")] -use serde; - // Heavy stick to translate between opcode types use std::mem::transmute; +#[cfg(feature = "serde")] +use serde; + use crate::deps_common::bitcoin::network::encodable::{ConsensusDecodable, ConsensusEncodable}; use crate::deps_common::bitcoin::network::serialize::{self, SimpleDecoder, SimpleEncoder}; diff --git a/stacks-common/src/deps_common/bitcoin/blockdata/script.rs b/stacks-common/src/deps_common/bitcoin/blockdata/script.rs index 22cbc29f92..748f9e2eec 100644 --- a/stacks-common/src/deps_common/bitcoin/blockdata/script.rs +++ b/stacks-common/src/deps_common/bitcoin/blockdata/script.rs @@ -28,17 +28,14 @@ use std::default::Default; use std::{error, fmt}; use serde; +use sha2::{Digest, Sha256}; use crate::deps_common::bitcoin::blockdata::opcodes; use crate::deps_common::bitcoin::network::encodable::{ConsensusDecodable, ConsensusEncodable}; use crate::deps_common::bitcoin::network::serialize::{self, SimpleDecoder, SimpleEncoder}; - // careful... use crate::deps_common::bitcoin::util::hash::Hash160; -use sha2::Digest; -use sha2::Sha256; - #[derive(Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)] /// A Bitcoin script pub struct Script(Box<[u8]>); @@ -64,7 +61,7 @@ impl fmt::Debug for Script { match read_uint(&self.0[index..], 1) { Ok(n) => { index += 1; - n as usize + n } Err(_) => { f.write_str("")?; @@ -80,7 +77,7 @@ impl fmt::Debug for Script { match read_uint(&self.0[index..], 2) { Ok(n) => { index += 2; - n as usize + n } Err(_) => { f.write_str("")?; @@ -96,7 +93,7 @@ impl fmt::Debug for Script { match read_uint(&self.0[index..], 4) { Ok(n) => { index += 4; - n as usize + n } Err(_) => { f.write_str("")?; @@ -297,7 +294,7 @@ impl Script { /// Returns the script data pub fn as_bytes(&self) -> &[u8] { - &*self.0 + &self.0 } /// Returns a copy of the script data @@ -325,7 +322,7 @@ impl Script { let mut tmp = [0; 32]; let mut sha2 = Sha256::new(); sha2.update(&self.0); - tmp.copy_from_slice(&sha2.finalize().as_slice()); + tmp.copy_from_slice(sha2.finalize().as_slice()); Builder::new().push_int(0).push_slice(&tmp).into_script() } @@ -392,7 +389,7 @@ impl Script { pub fn iter(&self, enforce_minimal: bool) -> Instructions { Instructions { data: &self.0[..], - enforce_minimal: enforce_minimal, + enforce_minimal, } } } @@ -438,12 +435,12 @@ impl<'a> Iterator for Instructions<'a> { self.data = &[]; // Kill iterator so that it does not return an infinite stream of errors return Some(Instruction::Error(Error::EarlyEndOfScript)); } - if self.enforce_minimal { - if n == 1 && (self.data[1] == 0x81 || (self.data[1] > 0 && self.data[1] <= 16)) - { - self.data = &[]; - return Some(Instruction::Error(Error::NonMinimalPush)); - } + if self.enforce_minimal + && n == 1 + && (self.data[1] == 0x81 || (self.data[1] > 0 && self.data[1] <= 16)) + { + self.data = &[]; + return Some(Instruction::Error(Error::NonMinimalPush)); } let ret = Some(Instruction::PushBytes(&self.data[1..n + 1])); self.data = &self.data[n + 1..]; @@ -552,7 +549,7 @@ impl Builder { /// dedicated opcodes to push some small integers. pub fn push_int(mut self, data: i64) -> Builder { // We can special-case -1, 1-16 - if data == -1 || (data >= 1 && data <= 16) { + if data == -1 || (1..=16).contains(&data) { self.0.push((data - 1 + opcodes::OP_TRUE as i64) as u8); self } @@ -702,13 +699,10 @@ impl ConsensusDecodable for Script { #[cfg(test)] mod test { - use crate::util::hash::hex_bytes as hex_decode; - - use super::build_scriptint; - use super::*; - + use super::{build_scriptint, *}; use crate::deps_common::bitcoin::blockdata::opcodes; use crate::deps_common::bitcoin::network::serialize::{deserialize, serialize}; + use crate::util::hash::hex_bytes as hex_decode; #[test] fn script() { @@ -819,32 +813,24 @@ mod test { #[test] fn provably_unspendable_test() { // p2pk - assert_eq!(hex_script!("410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac").is_provably_unspendable(), false); - assert_eq!(hex_script!("4104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac").is_provably_unspendable(), false); + assert!(!hex_script!("410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac").is_provably_unspendable()); + assert!(!hex_script!("4104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac").is_provably_unspendable()); // p2pkhash - assert_eq!( - hex_script!("76a914ee61d57ab51b9d212335b1dba62794ac20d2bcf988ac") - .is_provably_unspendable(), - false + assert!( + !hex_script!("76a914ee61d57ab51b9d212335b1dba62794ac20d2bcf988ac") + .is_provably_unspendable() ); - assert_eq!( + assert!( hex_script!("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87") - .is_provably_unspendable(), - true + .is_provably_unspendable() ); } #[test] fn op_return_test() { - assert_eq!( - hex_script!("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87").is_op_return(), - true - ); - assert_eq!( - hex_script!("76a914ee61d57ab51b9d212335b1dba62794ac20d2bcf988ac").is_op_return(), - false - ); - assert_eq!(hex_script!("").is_op_return(), false); + assert!(hex_script!("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87").is_op_return()); + assert!(!hex_script!("76a914ee61d57ab51b9d212335b1dba62794ac20d2bcf988ac").is_op_return()); + assert!(!hex_script!("").is_op_return()); } #[test] diff --git a/stacks-common/src/deps_common/bitcoin/blockdata/transaction.rs b/stacks-common/src/deps_common/bitcoin/blockdata/transaction.rs index 441483e741..87708334fc 100644 --- a/stacks-common/src/deps_common/bitcoin/blockdata/transaction.rs +++ b/stacks-common/src/deps_common/bitcoin/blockdata/transaction.rs @@ -35,7 +35,6 @@ use crate::deps_common::bitcoin::network::serialize::{ self, serialize, BitcoinHash, SimpleDecoder, SimpleEncoder, }; use crate::deps_common::bitcoin::util::hash::Sha256dHash; - use crate::util::hash::to_hex; /// A reference to a transaction output @@ -575,8 +574,8 @@ impl ConsensusDecodable for Transaction { match segwit_flag { // Empty tx 0 => Ok(Transaction { - version: version, - input: input, + version, + input, output: vec![], lock_time: ConsensusDecodable::consensus_decode(d)?, }), @@ -593,9 +592,9 @@ impl ConsensusDecodable for Transaction { )) } else { Ok(Transaction { - version: version, - input: input, - output: output, + version, + input, + output, lock_time: ConsensusDecodable::consensus_decode(d)?, }) } @@ -606,8 +605,8 @@ impl ConsensusDecodable for Transaction { // non-segwit } else { Ok(Transaction { - version: version, - input: input, + version, + input, output: ConsensusDecodable::consensus_decode(d)?, lock_time: ConsensusDecodable::consensus_decode(d)?, }) @@ -674,11 +673,9 @@ impl SigHashType { #[cfg(test)] mod tests { use super::{SigHashType, Transaction, TxIn}; - use crate::deps_common; use crate::deps_common::bitcoin::blockdata::script::Script; - use crate::deps_common::bitcoin::network::serialize::deserialize; - use crate::deps_common::bitcoin::network::serialize::BitcoinHash; + use crate::deps_common::bitcoin::network::serialize::{deserialize, BitcoinHash}; use crate::deps_common::bitcoin::util::hash::Sha256dHash; use crate::util::hash::hex_bytes; diff --git a/stacks-common/src/deps_common/bitcoin/network/address.rs b/stacks-common/src/deps_common/bitcoin/network/address.rs index 3fff2bfee0..af77e06464 100644 --- a/stacks-common/src/deps_common/bitcoin/network/address.rs +++ b/stacks-common/src/deps_common/bitcoin/network/address.rs @@ -18,9 +18,8 @@ //! network addresses in Bitcoin messages. //! -use std::fmt; -use std::io; use std::net::{Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; +use std::{fmt, io}; use crate::deps_common::bitcoin::network::encodable::{ConsensusDecodable, ConsensusEncodable}; use crate::deps_common::bitcoin::network::serialize::{self, SimpleDecoder, SimpleEncoder}; @@ -41,13 +40,13 @@ impl Address { /// Create an address message for a socket pub fn new(socket: &SocketAddr, services: u64) -> Address { let (address, port) = match socket { - &SocketAddr::V4(ref addr) => (addr.ip().to_ipv6_mapped().segments(), addr.port()), - &SocketAddr::V6(ref addr) => (addr.ip().segments(), addr.port()), + SocketAddr::V4(addr) => (addr.ip().to_ipv6_mapped().segments(), addr.port()), + SocketAddr::V6(addr) => (addr.ip().segments(), addr.port()), }; Address { - address: address, - port: port, - services: services, + address, + port, + services, } } @@ -128,7 +127,7 @@ impl Clone for Address { impl PartialEq for Address { fn eq(&self, other: &Address) -> bool { self.services == other.services - && &self.address[..] == &other.address[..] + && self.address[..] == other.address[..] && self.port == other.port } } @@ -137,10 +136,10 @@ impl Eq for Address {} #[cfg(test)] mod test { - use super::Address; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; use std::str::FromStr; + use super::Address; use crate::deps_common::bitcoin::network::serialize::{deserialize, serialize}; #[test] @@ -167,10 +166,7 @@ mod test { ]); assert!(addr.is_ok()); let full = addr.unwrap(); - assert!(match full.socket_addr().unwrap() { - SocketAddr::V4(_) => true, - _ => false, - }); + assert!(matches!(full.socket_addr().unwrap(), SocketAddr::V4(_))); assert_eq!(full.services, 1); assert_eq!(full.address, [0, 0, 0, 0, 0, 0xffff, 0x0a00, 0x0001]); assert_eq!(full.port, 8333); diff --git a/stacks-common/src/deps_common/bitcoin/network/constants.rs b/stacks-common/src/deps_common/bitcoin/network/constants.rs index 1d67740ea4..b60c448c0b 100644 --- a/stacks-common/src/deps_common/bitcoin/network/constants.rs +++ b/stacks-common/src/deps_common/bitcoin/network/constants.rs @@ -45,7 +45,7 @@ pub const PROTOCOL_VERSION: u32 = 70001; /// Bitfield of services provided by this node pub const SERVICES: u64 = 0; /// User agent as it appears in the version message -pub const USER_AGENT: &'static str = "bitcoin-rust v0.1"; +pub const USER_AGENT: &str = "bitcoin-rust v0.1"; user_enum! { /// The cryptocurrency to act on diff --git a/stacks-common/src/deps_common/bitcoin/network/encodable.rs b/stacks-common/src/deps_common/bitcoin/network/encodable.rs index 7cfeeafd3c..1054e28463 100644 --- a/stacks-common/src/deps_common/bitcoin/network/encodable.rs +++ b/stacks-common/src/deps_common/bitcoin/network/encodable.rs @@ -117,7 +117,7 @@ impl ConsensusEncodable for VarInt { } _ => { s.emit_u8(0xFF)?; - (self.0 as u64).consensus_encode(s) + (self.0).consensus_encode(s) } } } @@ -242,7 +242,7 @@ impl> ConsensusEncodable for [T] { impl> ConsensusEncodable for Vec { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), serialize::Error> { - (&self[..]).consensus_encode(s) + (self[..]).consensus_encode(s) } } @@ -270,7 +270,7 @@ impl> ConsensusDecodable for Vec> ConsensusEncodable for Box<[T]> { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), serialize::Error> { - (&self[..]).consensus_encode(s) + (self[..]).consensus_encode(s) } } @@ -449,7 +449,6 @@ where #[cfg(test)] mod tests { use super::{CheckedData, VarInt}; - use crate::deps_common::bitcoin::network::serialize::{deserialize, serialize, Error}; #[test] diff --git a/stacks-common/src/deps_common/bitcoin/network/message.rs b/stacks-common/src/deps_common/bitcoin/network/message.rs index ca116dee37..6057dcee25 100644 --- a/stacks-common/src/deps_common/bitcoin/network/message.rs +++ b/stacks-common/src/deps_common/bitcoin/network/message.rs @@ -22,16 +22,15 @@ use std::io::Cursor; use std::iter; -use crate::deps_common::bitcoin::blockdata::block; -use crate::deps_common::bitcoin::blockdata::transaction; +use crate::deps_common::bitcoin::blockdata::{block, transaction}; use crate::deps_common::bitcoin::network::address::Address; -use crate::deps_common::bitcoin::network::encodable::CheckedData; -use crate::deps_common::bitcoin::network::encodable::{ConsensusDecodable, ConsensusEncodable}; -use crate::deps_common::bitcoin::network::message_blockdata; -use crate::deps_common::bitcoin::network::message_network; +use crate::deps_common::bitcoin::network::encodable::{ + CheckedData, ConsensusDecodable, ConsensusEncodable, +}; use crate::deps_common::bitcoin::network::serialize::{ self, serialize, RawDecoder, SimpleDecoder, SimpleEncoder, }; +use crate::deps_common::bitcoin::network::{message_blockdata, message_network}; /// Serializer for command string #[derive(PartialEq, Eq, Clone, Debug)] @@ -40,15 +39,13 @@ pub struct CommandString(pub String); impl ConsensusEncodable for CommandString { #[inline] fn consensus_encode(&self, s: &mut S) -> Result<(), serialize::Error> { - let &CommandString(ref inner_str) = self; + let CommandString(ref inner_str) = self; let mut rawbytes = [0u8; 12]; let strbytes = inner_str.as_bytes(); if strbytes.len() > 12 { panic!("Command string longer than 12 bytes"); } - for x in 0..strbytes.len() { - rawbytes[x] = strbytes[x]; - } + rawbytes[..strbytes.len()].copy_from_slice(strbytes); rawbytes.consensus_encode(s) } } @@ -201,17 +198,13 @@ impl ConsensusDecodable for RawNetworkMessage { "alert" => NetworkMessage::Alert(ConsensusDecodable::consensus_decode(&mut mem_d)?), _ => return Err(serialize::Error::UnrecognizedNetworkCommand(cmd)), }; - Ok(RawNetworkMessage { - magic: magic, - payload: payload, - }) + Ok(RawNetworkMessage { magic, payload }) } } #[cfg(test)] mod test { use super::{CommandString, NetworkMessage, RawNetworkMessage}; - use crate::deps_common::bitcoin::network::serialize::{deserialize, serialize}; #[test] diff --git a/stacks-common/src/deps_common/bitcoin/network/message_blockdata.rs b/stacks-common/src/deps_common/bitcoin/network/message_blockdata.rs index a3662b8ce4..099acca559 100644 --- a/stacks-common/src/deps_common/bitcoin/network/message_blockdata.rs +++ b/stacks-common/src/deps_common/bitcoin/network/message_blockdata.rs @@ -80,8 +80,8 @@ impl GetBlocksMessage { pub fn new(locator_hashes: Vec, stop_hash: Sha256dHash) -> GetBlocksMessage { GetBlocksMessage { version: constants::PROTOCOL_VERSION, - locator_hashes: locator_hashes, - stop_hash: stop_hash, + locator_hashes, + stop_hash, } } } @@ -93,8 +93,8 @@ impl GetHeadersMessage { pub fn new(locator_hashes: Vec, stop_hash: Sha256dHash) -> GetHeadersMessage { GetHeadersMessage { version: constants::PROTOCOL_VERSION, - locator_hashes: locator_hashes, - stop_hash: stop_hash, + locator_hashes, + stop_hash, } } } @@ -135,12 +135,11 @@ impl ConsensusDecodable for Inventory { #[cfg(test)] mod tests { - use super::{GetBlocksMessage, GetHeadersMessage}; - - use crate::util::hash::hex_bytes as hex_decode; + use std::default::Default; + use super::{GetBlocksMessage, GetHeadersMessage}; use crate::deps_common::bitcoin::network::serialize::{deserialize, serialize}; - use std::default::Default; + use crate::util::hash::hex_bytes as hex_decode; #[test] fn getblocks_message_test() { diff --git a/stacks-common/src/deps_common/bitcoin/network/message_network.rs b/stacks-common/src/deps_common/bitcoin/network/message_network.rs index bd2a9cf1a7..4f913ee48f 100644 --- a/stacks-common/src/deps_common/bitcoin/network/message_network.rs +++ b/stacks-common/src/deps_common/bitcoin/network/message_network.rs @@ -65,10 +65,8 @@ impl_consensus_encoding!( #[cfg(test)] mod tests { use super::VersionMessage; - - use crate::util::hash::hex_bytes as hex_decode; - use crate::deps_common::bitcoin::network::serialize::{deserialize, serialize}; + use crate::util::hash::hex_bytes as hex_decode; #[test] fn version_message_test() { @@ -85,7 +83,7 @@ mod tests { assert_eq!(real_decode.nonce, 16735069437859780935); assert_eq!(real_decode.user_agent, "/Satoshi:0.9.99/".to_string()); assert_eq!(real_decode.start_height, 302892); - assert_eq!(real_decode.relay, true); + assert!(real_decode.relay); assert_eq!(serialize(&real_decode).ok(), Some(from_sat)); } diff --git a/stacks-common/src/deps_common/bitcoin/network/mod.rs b/stacks-common/src/deps_common/bitcoin/network/mod.rs index 43745f10d1..e4dbdaae2b 100644 --- a/stacks-common/src/deps_common/bitcoin/network/mod.rs +++ b/stacks-common/src/deps_common/bitcoin/network/mod.rs @@ -18,9 +18,7 @@ //! of Bitcoin data and network messages. //! -use std::error; -use std::fmt; -use std::io; +use std::{error, fmt, io}; pub mod address; pub mod constants; diff --git a/stacks-common/src/deps_common/bitcoin/network/serialize.rs b/stacks-common/src/deps_common/bitcoin/network/serialize.rs index 64c68295b1..f33a347133 100644 --- a/stacks-common/src/deps_common/bitcoin/network/serialize.rs +++ b/stacks-common/src/deps_common/bitcoin/network/serialize.rs @@ -19,16 +19,13 @@ //! It also defines (de)serialization routines for many primitives. //! -use crate::util::hash::to_hex as hex_encode; -use std::error; -use std::fmt; -use std::io; use std::io::{Cursor, Read, Write}; +use std::{error, fmt, io}; use crate::address; - use crate::deps_common::bitcoin::network::encodable::{ConsensusDecodable, ConsensusEncodable}; use crate::deps_common::bitcoin::util::hash::Sha256dHash; +use crate::util::hash::to_hex as hex_encode; /// Serialization error #[derive(Debug)] @@ -210,7 +207,7 @@ pub struct RawDecoder { impl RawEncoder { /// Constructor pub fn new(writer: W) -> RawEncoder { - RawEncoder { writer: writer } + RawEncoder { writer } } /// Returns the underlying Writer pub fn into_inner(self) -> W { @@ -221,7 +218,7 @@ impl RawEncoder { impl RawDecoder { /// Constructor pub fn new(reader: R) -> RawDecoder { - RawDecoder { reader: reader } + RawDecoder { reader } } /// Returns the underlying Reader pub fn into_inner(self) -> R { diff --git a/stacks-common/src/deps_common/bitcoin/util/hash.rs b/stacks-common/src/deps_common/bitcoin/util/hash.rs index c4680a09eb..2c64dca01e 100644 --- a/stacks-common/src/deps_common/bitcoin/util/hash.rs +++ b/stacks-common/src/deps_common/bitcoin/util/hash.rs @@ -15,19 +15,16 @@ //! //! Utility functions related to hashing data, including merkleization -#[cfg(feature = "serde")] -use serde; use std::char::from_digit; use std::cmp::min; use std::default::Default; -use std::error; -use std::fmt; use std::io::{Cursor, Write}; -use std::mem; +use std::{error, fmt, mem}; use ripemd::Ripemd160; -use sha2::Digest; -use sha2::Sha256; +#[cfg(feature = "serde")] +use serde; +use sha2::{Digest, Sha256}; use crate::deps_common::bitcoin::network::encodable::{ConsensusDecodable, ConsensusEncodable}; use crate::deps_common::bitcoin::network::serialize::{ @@ -37,6 +34,9 @@ use crate::util::uint::Uint256; use crate::util::HexError; /// A Bitcoin hash, 32-bytes, computed from x as SHA256(SHA256(x)) +// This doesn't make much sense to me, but is implicit behaviour +// in the C++ reference client, so we need it for consensus. +#[derive(Default)] pub struct Sha256dHash(pub [u8; 32]); impl_array_newtype!(Sha256dHash, u8, 32); @@ -51,6 +51,12 @@ impl_array_newtype!(Ripemd160Hash, u8, 20); pub struct Hash160([u8; 20]); impl_array_newtype!(Hash160, u8, 20); +impl Default for Sha256dEncoder { + fn default() -> Self { + Self::new() + } +} + impl Sha256dEncoder { /// Create a new encoder pub fn new() -> Sha256dEncoder { @@ -62,7 +68,7 @@ impl Sha256dEncoder { let mut second_sha = Sha256::new(); let mut tmp = [0; 32]; tmp.copy_from_slice(self.0.finalize().as_slice()); - second_sha.update(&tmp); + second_sha.update(tmp); tmp.copy_from_slice(second_sha.finalize().as_slice()); Sha256dHash(tmp) } @@ -72,57 +78,57 @@ impl SimpleEncoder for Sha256dEncoder { fn emit_u64(&mut self, v: u64) -> Result<(), serialize::Error> { let mut data = [0; 8]; (&mut data[..]).write_all(&v.to_le_bytes()).unwrap(); - self.0.update(&data); + self.0.update(data); Ok(()) } fn emit_u32(&mut self, v: u32) -> Result<(), serialize::Error> { let mut data = [0; 4]; (&mut data[..]).write_all(&v.to_le_bytes()).unwrap(); - self.0.update(&data); + self.0.update(data); Ok(()) } fn emit_u16(&mut self, v: u16) -> Result<(), serialize::Error> { let mut data = [0; 2]; (&mut data[..]).write_all(&v.to_le_bytes()).unwrap(); - self.0.update(&data); + self.0.update(data); Ok(()) } fn emit_i64(&mut self, v: i64) -> Result<(), serialize::Error> { let mut data = [0; 8]; (&mut data[..]).write_all(&v.to_le_bytes()).unwrap(); - self.0.update(&data); + self.0.update(data); Ok(()) } fn emit_i32(&mut self, v: i32) -> Result<(), serialize::Error> { let mut data = [0; 4]; (&mut data[..]).write_all(&v.to_le_bytes()).unwrap(); - self.0.update(&data); + self.0.update(data); Ok(()) } fn emit_i16(&mut self, v: i16) -> Result<(), serialize::Error> { let mut data = [0; 2]; (&mut data[..]).write_all(&v.to_le_bytes()).unwrap(); - self.0.update(&data); + self.0.update(data); Ok(()) } fn emit_i8(&mut self, v: i8) -> Result<(), serialize::Error> { - self.0.update(&[v as u8]); + self.0.update([v as u8]); Ok(()) } fn emit_u8(&mut self, v: u8) -> Result<(), serialize::Error> { - self.0.update(&[v]); + self.0.update([v]); Ok(()) } fn emit_bool(&mut self, v: bool) -> Result<(), serialize::Error> { - self.0.update(&[if v { 1 } else { 0 }]); + self.0.update([if v { 1 } else { 0 }]); Ok(()) } } @@ -147,21 +153,12 @@ impl Hash160 { let mut rmd = Ripemd160::new(); sha2.update(data); tmp.copy_from_slice(sha2.finalize().as_slice()); - rmd.update(&tmp); + rmd.update(tmp); ret.copy_from_slice(rmd.finalize().as_slice()); Hash160(ret) } } -// This doesn't make much sense to me, but is implicit behaviour -// in the C++ reference client, so we need it for consensus. -impl Default for Sha256dHash { - #[inline] - fn default() -> Sha256dHash { - Sha256dHash([0u8; 32]) - } -} - impl Sha256dHash { /// Create a hash by hashing some data pub fn from_data(data: &[u8]) -> Sha256dHash { @@ -172,7 +169,7 @@ impl Sha256dHash { let mut sha2_2 = Sha256::new(); sha2.update(data); ret.copy_from_slice(sha2.finalize().as_slice()); - sha2_2.update(&ret); + sha2_2.update(ret); ret.copy_from_slice(sha2_2.finalize().as_slice()); Sha256dHash(ret) } @@ -182,7 +179,7 @@ impl Sha256dHash { pub fn into_le(self) -> Uint256 { let Sha256dHash(data) = self; let mut ret: [u64; 4] = unsafe { mem::transmute(data) }; - for x in (&mut ret).iter_mut() { + for x in ret.iter_mut() { *x = x.to_le(); } Uint256(ret) @@ -194,7 +191,7 @@ impl Sha256dHash { let Sha256dHash(mut data) = self; data.reverse(); let mut ret: [u64; 4] = unsafe { mem::transmute(data) }; - for x in (&mut ret).iter_mut() { + for x in ret.iter_mut() { *x = x.to_be(); } Uint256(ret) @@ -213,15 +210,15 @@ impl Sha256dHash { let mut ret = [0; 32]; for i in 0..32 { let hi = match bytes[2 * i] { - b @ b'0'..=b'9' => (b - b'0') as u8, - b @ b'a'..=b'f' => (b - b'a' + 10) as u8, - b @ b'A'..=b'F' => (b - b'A' + 10) as u8, + b @ b'0'..=b'9' => b - b'0', + b @ b'a'..=b'f' => b - b'a' + 10, + b @ b'A'..=b'F' => b - b'A' + 10, b => return Err(HexError::BadCharacter(b as char)), }; let lo = match bytes[2 * i + 1] { - b @ b'0'..=b'9' => (b - b'0') as u8, - b @ b'a'..=b'f' => (b - b'a' + 10) as u8, - b @ b'A'..=b'F' => (b - b'A' + 10) as u8, + b @ b'0'..=b'9' => b - b'0', + b @ b'a'..=b'f' => b - b'a' + 10, + b @ b'A'..=b'F' => b - b'A' + 10, b => return Err(HexError::BadCharacter(b as char)), }; ret[31 - i] = hi * 0x10 + lo; @@ -240,15 +237,15 @@ impl Sha256dHash { let mut ret = [0; 32]; for i in 0..32 { let hi = match bytes[2 * i] { - b @ b'0'..=b'9' => (b - b'0') as u8, - b @ b'a'..=b'f' => (b - b'a' + 10) as u8, - b @ b'A'..=b'F' => (b - b'A' + 10) as u8, + b @ b'0'..=b'9' => b - b'0', + b @ b'a'..=b'f' => b - b'a' + 10, + b @ b'A'..=b'F' => b - b'A' + 10, b => return Err(HexError::BadCharacter(b as char)), }; let lo = match bytes[2 * i + 1] { - b @ b'0'..=b'9' => (b - b'0') as u8, - b @ b'a'..=b'f' => (b - b'a' + 10) as u8, - b @ b'A'..=b'F' => (b - b'A' + 10) as u8, + b @ b'0'..=b'9' => b - b'0', + b @ b'a'..=b'f' => b - b'a' + 10, + b @ b'A'..=b'F' => b - b'A' + 10, b => return Err(HexError::BadCharacter(b as char)), }; ret[i] = hi * 0x10 + lo; @@ -415,10 +412,10 @@ pub trait MerkleRoot { /// Calculates the merkle root of a list of txids hashes directly pub fn bitcoin_merkle_root(data: Vec) -> Sha256dHash { // Base case - if data.len() < 1 { + if data.is_empty() { return Default::default(); } - if data.len() < 2 { + if data.len() == 1 { return data[0]; } // Recursion diff --git a/stacks-common/src/deps_common/ctrlc/error.rs b/stacks-common/src/deps_common/ctrlc/error.rs index 5d18cf41c3..81bb981b87 100644 --- a/stacks-common/src/deps_common/ctrlc/error.rs +++ b/stacks-common/src/deps_common/ctrlc/error.rs @@ -1,6 +1,7 @@ -use crate::deps_common::ctrlc::platform; use std::fmt; +use crate::deps_common::ctrlc::platform; + /// Ctrl-C error. #[derive(Debug)] pub enum Error { diff --git a/stacks-common/src/deps_common/ctrlc/mod.rs b/stacks-common/src/deps_common/ctrlc/mod.rs index 2d62628d71..836ae7dfb6 100644 --- a/stacks-common/src/deps_common/ctrlc/mod.rs +++ b/stacks-common/src/deps_common/ctrlc/mod.rs @@ -11,10 +11,11 @@ mod error; mod platform; -pub use self::error::Error; use std::sync::atomic::{AtomicBool, Ordering}; use std::thread; +pub use self::error::Error; + #[cfg(test)] mod tests; @@ -63,7 +64,7 @@ static INIT: AtomicBool = AtomicBool::new(false); /// pub fn set_handler(mut user_handler: F) -> Result<(), Error> where - F: FnMut(SignalId) -> () + 'static + Send, + F: FnMut(SignalId) + 'static + Send, { if INIT .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) diff --git a/stacks-common/src/deps_common/ctrlc/platform/mod.rs b/stacks-common/src/deps_common/ctrlc/platform/mod.rs index f3b37e9581..a6ec544a05 100644 --- a/stacks-common/src/deps_common/ctrlc/platform/mod.rs +++ b/stacks-common/src/deps_common/ctrlc/platform/mod.rs @@ -15,6 +15,5 @@ mod windows; #[cfg(unix)] pub use self::unix::*; - #[cfg(windows)] pub use self::windows::*; diff --git a/stacks-common/src/deps_common/ctrlc/platform/unix/mod.rs b/stacks-common/src/deps_common/ctrlc/platform/unix/mod.rs index c60aead514..840c977c14 100644 --- a/stacks-common/src/deps_common/ctrlc/platform/unix/mod.rs +++ b/stacks-common/src/deps_common/ctrlc/platform/unix/mod.rs @@ -7,10 +7,12 @@ // notice may not be copied, modified, or distributed except // according to those terms. +use std::os::unix::io::RawFd; + +use nix::unistd; + use crate::deps_common::ctrlc::error::Error as CtrlcError; use crate::deps_common::ctrlc::SignalId; -use nix::unistd; -use std::os::unix::io::RawFd; static mut PIPE: (RawFd, RawFd) = (-1, -1); diff --git a/stacks-common/src/deps_common/ctrlc/platform/windows/mod.rs b/stacks-common/src/deps_common/ctrlc/platform/windows/mod.rs index c4b9ca54a6..1a79f6b128 100644 --- a/stacks-common/src/deps_common/ctrlc/platform/windows/mod.rs +++ b/stacks-common/src/deps_common/ctrlc/platform/windows/mod.rs @@ -7,8 +7,8 @@ // notice may not be copied, modified, or distributed except // according to those terms. -use std::io; -use std::ptr; +use std::{io, ptr}; + use winapi::ctypes::c_long; use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE}; use winapi::shared::ntdef::HANDLE; diff --git a/stacks-common/src/deps_common/ctrlc/tests.rs b/stacks-common/src/deps_common/ctrlc/tests.rs index 8d46f8d3d6..de2743892b 100644 --- a/stacks-common/src/deps_common/ctrlc/tests.rs +++ b/stacks-common/src/deps_common/ctrlc/tests.rs @@ -34,8 +34,7 @@ mod platform { #[cfg(windows)] mod platform { - use std::io; - use std::ptr; + use std::{io, ptr}; use winapi::shared::minwindef::DWORD; use winapi::shared::ntdef::{CHAR, HANDLE}; diff --git a/stacks-common/src/deps_common/httparse/mod.rs b/stacks-common/src/deps_common/httparse/mod.rs index b4e114ccd2..5d572585b8 100644 --- a/stacks-common/src/deps_common/httparse/mod.rs +++ b/stacks-common/src/deps_common/httparse/mod.rs @@ -31,11 +31,7 @@ //! Originally written by Sean McArthur. //! //! Modified by Jude Nelson to remove all unsafe code. -use std::error; -use std::fmt; -use std::mem; -use std::result; -use std::str; +use std::{error, fmt, mem, result, str}; macro_rules! next { ($bytes:ident) => {{ @@ -105,7 +101,7 @@ impl<'a> Bytes<'a> { #[inline] pub fn new(slice: &'a [u8]) -> Bytes<'a> { Bytes { - slice: slice, + slice, pos: 0, skipped_pos: 0, } @@ -123,7 +119,7 @@ impl<'a> Bytes<'a> { #[inline] pub fn bump(&mut self) { - assert!(self.pos + 1 <= self.slice_peek().len(), "overflow"); + assert!(self.pos < self.slice_peek().len(), "overflow"); self.pos += 1; } @@ -139,6 +135,11 @@ impl<'a> Bytes<'a> { self.slice_peek().len() } + #[inline] + pub fn is_empty(&self) -> bool { + self.slice_peek().is_empty() + } + #[inline] pub fn slice_peek(&self) -> &'a [u8] { &self.slice[self.skipped_pos..] @@ -230,10 +231,7 @@ impl<'a, 'b: 'a> Bytes8<'a, 'b> { #[inline] fn new(bytes: &'a mut Bytes<'b>) -> Bytes8<'a, 'b> { - Bytes8 { - bytes: bytes, - pos: 0, - } + Bytes8 { bytes, pos: 0 } } #[inline] @@ -246,7 +244,7 @@ impl<'a, 'b: 'a> Bytes8<'a, 'b> { #[inline] fn shrink(slice: &mut &mut [T], len: usize) { assert!(slice.len() >= len); - let full = mem::replace(slice, &mut []); + let full = mem::take(slice); *slice = &mut full[..len]; } @@ -453,7 +451,7 @@ impl<'h, 'b> Request<'h, 'b> { method: None, path: None, version: None, - headers: headers, + headers, } } @@ -520,7 +518,7 @@ impl<'h, 'b> Response<'h, 'b> { version: None, code: None, reason: None, - headers: headers, + headers, } } @@ -645,7 +643,7 @@ fn parse_reason<'a>(bytes: &mut Bytes<'a>) -> Result<&'a str> { } else if b == b'\n' { let res = str::from_utf8(bytes.slice_skip(1)).map_err(|_e| Error::Status)?; return Ok(Status::Complete(res)); - } else if !((b >= 0x20 && b <= 0x7E) || b == b'\t') { + } else if !((0x20..=0x7E).contains(&b) || b == b'\t') { return Err(Error::Status); } } @@ -704,10 +702,7 @@ pub fn parse_headers<'b: 'h, 'h>( } #[inline] -fn parse_headers_iter<'a, 'b>( - headers: &mut &mut [Header<'a>], - bytes: &'b mut Bytes<'a>, -) -> Result { +fn parse_headers_iter<'a>(headers: &mut &mut [Header<'a>], bytes: &mut Bytes<'a>) -> Result { let mut num_headers: usize = 0; let mut count: usize = 0; let mut result = Err(Error::TooManyHeaders); @@ -1208,7 +1203,7 @@ mod tests { } } - static RESPONSE_REASON_WITH_OBS_TEXT_BYTE: &'static [u8] = b"HTTP/1.1 200 X\xFFZ\r\n\r\n"; + static RESPONSE_REASON_WITH_OBS_TEXT_BYTE: &[u8] = b"HTTP/1.1 200 X\xFFZ\r\n\r\n"; res! { test_response_reason_with_obsolete_text_byte, RESPONSE_REASON_WITH_OBS_TEXT_BYTE, @@ -1288,8 +1283,9 @@ mod tests { #[cfg(feature = "std")] #[test] fn test_std_error() { - use super::Error; use std::error::Error as StdError; + + use super::Error; let err = Error::HeaderName; assert_eq!(err.to_string(), err.description_str()); } diff --git a/stacks-common/src/libcommon.rs b/stacks-common/src/libcommon.rs index 79954d2ef1..f759e9ca34 100644 --- a/stacks-common/src/libcommon.rs +++ b/stacks-common/src/libcommon.rs @@ -5,6 +5,7 @@ #![allow(non_snake_case)] #![allow(non_upper_case_globals)] #![cfg_attr(test, allow(unused_variables, unused_assignments))] +#![allow(clippy::assertions_on_constants)] extern crate curve25519_dalek; extern crate ed25519_dalek; @@ -52,8 +53,7 @@ pub mod deps_common; use crate::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksBlockId}; pub mod consts { - use crate::types::chainstate::BlockHeaderHash; - use crate::types::chainstate::ConsensusHash; + use crate::types::chainstate::{BlockHeaderHash, ConsensusHash}; pub const TOKEN_TRANSFER_MEMO_LENGTH: usize = 34; // same as it is in Stacks v1 diff --git a/stacks-common/src/types/chainstate.rs b/stacks-common/src/types/chainstate.rs index eb36948107..46a9afb0e2 100644 --- a/stacks-common/src/types/chainstate.rs +++ b/stacks-common/src/types/chainstate.rs @@ -1,51 +1,33 @@ use std::fmt; -use std::io::Read; -use std::io::Write; +use std::io::{Read, Write}; use std::str::FromStr; use curve25519_dalek::digest::Digest; -use sha2::Sha256; -use sha2::{Digest as Sha2Digest, Sha512_256}; - -use crate::util::hash::{to_hex, Hash160, Sha512Trunc256Sum, HASH160_ENCODED_SIZE}; -use crate::util::secp256k1::MessageSignature; -use crate::util::uint::Uint256; -use crate::util::vrf::VRFProof; - -use serde::de::Deserialize; -use serde::de::Error as de_Error; +use rand::{Rng, SeedableRng}; +use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; +use serde::de::{Deserialize, Error as de_Error}; use serde::ser::Error as ser_Error; use serde::Serialize; - -use crate::util::secp256k1::Secp256k1PrivateKey; -use crate::util::secp256k1::Secp256k1PublicKey; -use crate::util::vrf::VRF_PROOF_ENCODED_SIZE; +use sha2::{Digest as Sha2Digest, Sha256, Sha512_256}; use crate::codec::{read_next, write_next, Error as CodecError, StacksMessageCodec}; - use crate::deps_common::bitcoin::util::hash::Sha256dHash; -use rand::Rng; -use rand::SeedableRng; -use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; - -use crate::util::hash::DoubleSha256; +use crate::util::hash::{to_hex, DoubleSha256, Hash160, Sha512Trunc256Sum, HASH160_ENCODED_SIZE}; +use crate::util::secp256k1::{MessageSignature, Secp256k1PrivateKey, Secp256k1PublicKey}; +use crate::util::uint::Uint256; +use crate::util::vrf::{VRFProof, VRF_PROOF_ENCODED_SIZE}; pub type StacksPublicKey = Secp256k1PublicKey; pub type StacksPrivateKey = Secp256k1PrivateKey; /// Hash of a Trie node. This is a SHA2-512/256. +#[derive(Default)] pub struct TrieHash(pub [u8; 32]); impl_array_newtype!(TrieHash, u8, 32); impl_array_hexstring_fmt!(TrieHash); impl_byte_array_newtype!(TrieHash, u8, 32); impl_byte_array_serde!(TrieHash); -impl Default for TrieHash { - fn default() -> TrieHash { - TrieHash([0x00; 32]) - } -} - pub const TRIEHASH_ENCODED_SIZE: usize = 32; #[derive(Serialize, Deserialize)] @@ -96,7 +78,7 @@ impl SortitionId { pub fn new(bhh: &BurnchainHeaderHash, pox: &PoxId) -> SortitionId { if pox == &PoxId::stubbed() { - SortitionId(bhh.0.clone()) + SortitionId(bhh.0) } else { let mut hasher = Sha512_256::new(); hasher.update(bhh); @@ -145,6 +127,10 @@ impl PoxId { self.0.len() } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn bit_slice(&self, start: usize, len: usize) -> (Vec, u64) { let mut ret = vec![0x00]; let mut count = 0; @@ -232,7 +218,7 @@ impl StacksMessageCodec for StacksAddress { let version: u8 = read_next(fd)?; let hash160: Hash160 = read_next(fd)?; Ok(StacksAddress { - version: version, + version, bytes: hash160, }) } diff --git a/stacks-common/src/types/mod.rs b/stacks-common/src/types/mod.rs index 6893d863d3..8d84666f2d 100644 --- a/stacks-common/src/types/mod.rs +++ b/stacks-common/src/types/mod.rs @@ -1,22 +1,17 @@ -use crate::address::public_keys_to_address_hash; -use crate::types::chainstate::StacksPublicKey; -use crate::util::secp256k1::MessageSignature; -use crate::util::secp256k1::Secp256k1PublicKey; +use std::cmp::Ordering; use std::convert::TryFrom; use std::fmt; +use crate::address::c32::{c32_address, c32_address_decode}; use crate::address::{ - C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, - C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, + public_keys_to_address_hash, AddressHashMode, C32_ADDRESS_VERSION_MAINNET_MULTISIG, + C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_MULTISIG, + C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; - -use crate::address::c32::c32_address; -use crate::address::c32::c32_address_decode; -use crate::address::AddressHashMode; use crate::deps_common::bitcoin::blockdata::transaction::TxOut; -use crate::types::chainstate::StacksAddress; +use crate::types::chainstate::{StacksAddress, StacksPublicKey}; use crate::util::hash::Hash160; -use std::cmp::Ordering; +use crate::util::secp256k1::{MessageSignature, Secp256k1PublicKey}; pub mod chainstate; pub mod net; @@ -241,7 +236,7 @@ impl Address for StacksAddress { let mut hash_bytes = [0u8; 20]; hash_bytes.copy_from_slice(&bytes[..]); Some(StacksAddress { - version: version, + version, bytes: Hash160(hash_bytes), }) } diff --git a/stacks-common/src/types/net.rs b/stacks-common/src/types/net.rs index 890db4b3f0..45b6fb43ef 100644 --- a/stacks-common/src/types/net.rs +++ b/stacks-common/src/types/net.rs @@ -15,22 +15,15 @@ // along with this program. If not, see . use std::fmt; -use std::hash::Hash; -use std::hash::Hasher; +use std::hash::{Hash, Hasher}; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; use std::str::FromStr; -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::Ipv6Addr; -use std::net::SocketAddr; - -use serde::de::Deserialize; +use serde::de::{Deserialize, Error as de_Error}; use serde::ser::Serialize; use crate::util::hash::to_bin; -use serde::de::Error as de_Error; - #[derive(Debug)] pub enum Error { DecodeError(String), diff --git a/stacks-common/src/util/chunked_encoding.rs b/stacks-common/src/util/chunked_encoding.rs index 65133580c9..bb1b869eee 100644 --- a/stacks-common/src/util/chunked_encoding.rs +++ b/stacks-common/src/util/chunked_encoding.rs @@ -14,10 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::error; -use std::fmt; -use std::io; use std::io::{Read, Write}; +use std::{error, fmt, io}; use crate::codec::MAX_MESSAGE_LEN; use crate::deps_common::httparse; @@ -48,6 +46,7 @@ impl error::Error for ChunkedError { } } +#[allow(clippy::upper_case_acronyms)] #[derive(Debug, Clone, PartialEq, Copy)] enum HttpChunkedTransferParseMode { ChunkBoundary, @@ -77,7 +76,7 @@ impl HttpChunkedTransferReaderState { parse_step: HttpChunkedTransferParseMode::ChunkBoundary, chunk_size: 0, chunk_read: 0, - max_size: max_size, + max_size, total_size: 0, last_chunk_size: u64::MAX, // if this ever becomes 0, then we should expect chunk boundary '0\r\n\r\n' and EOF chunk_buffer: [0u8; 18], @@ -108,10 +107,7 @@ impl<'a, R: Read> HttpChunkedTransferReader<'a, R> { r: &'a mut R, state: HttpChunkedTransferReaderState, ) -> HttpChunkedTransferReader<'a, R> { - HttpChunkedTransferReader { - fd: r, - state: state, - } + HttpChunkedTransferReader { fd: r, state } } } @@ -198,12 +194,11 @@ impl HttpChunkedTransferReaderState { )); } - let remaining = - if self.chunk_size - self.chunk_read <= (self.max_size - self.total_size) as u64 { - self.chunk_size - self.chunk_read - } else { - (self.max_size - self.total_size) as u64 - }; + let remaining = if self.chunk_size - self.chunk_read <= (self.max_size - self.total_size) { + self.chunk_size - self.chunk_read + } else { + self.max_size - self.total_size + }; let nr = if (buf.len() as u64) < remaining { // can fill buffer @@ -257,7 +252,7 @@ impl HttpChunkedTransferReaderState { if self.i == 2 { // expect '\r\n' - if &self.chunk_buffer[0..2] != &[0x0d, 0x0a] { + if self.chunk_buffer[0..2] != [0x0d, 0x0a] { return Err(io::Error::new( io::ErrorKind::InvalidData, ChunkedError::DeserializeError("Invalid chunk trailer".to_string()), @@ -325,9 +320,7 @@ impl<'a, R: Read> Read for HttpChunkedTransferReader<'a, R> { /// Read a HTTP chunk-encoded stream. /// Returns number of decoded bytes (i.e. number of bytes copied to buf, as expected) fn read(&mut self, buf: &mut [u8]) -> io::Result { - self.state - .do_read(self.fd, buf) - .and_then(|(decoded, _)| Ok(decoded)) + self.state.do_read(self.fd, buf).map(|(decoded, _)| decoded) } } @@ -340,7 +333,7 @@ pub struct HttpChunkedTransferWriterState { impl HttpChunkedTransferWriterState { pub fn new(chunk_size: usize) -> HttpChunkedTransferWriterState { HttpChunkedTransferWriterState { - chunk_size: chunk_size, + chunk_size, chunk_buf: vec![], corked: false, } @@ -361,10 +354,7 @@ impl<'a, 'state, W: Write> HttpChunkedTransferWriter<'a, 'state, W> { fd: &'a mut W, state: &'state mut HttpChunkedTransferWriterState, ) -> HttpChunkedTransferWriter<'a, 'state, W> { - HttpChunkedTransferWriter { - fd: fd, - state: state, - } + HttpChunkedTransferWriter { fd, state } } fn send_chunk(fd: &mut W, chunk_size: usize, bytes: &[u8]) -> io::Result { @@ -401,7 +391,7 @@ impl<'a, 'state, W: Write> HttpChunkedTransferWriter<'a, 'state, W> { to_copy } - pub fn cork(&mut self) -> () { + pub fn cork(&mut self) { // block future flushes from sending trailing empty chunks -- we're done sending self.state.corked = true; } @@ -415,7 +405,7 @@ impl<'a, 'state, W: Write> Write for HttpChunkedTransferWriter<'a, 'state, W> { fn write(&mut self, buf: &[u8]) -> io::Result { let mut written = 0; while written < buf.len() && !self.state.corked { - if self.state.chunk_buf.len() > 0 { + if !self.state.chunk_buf.is_empty() { if self.state.chunk_buf.len() < self.state.chunk_size { let nw = self.buf_chunk(&buf[written..]); written += nw; @@ -423,18 +413,16 @@ impl<'a, 'state, W: Write> Write for HttpChunkedTransferWriter<'a, 'state, W> { if self.state.chunk_buf.len() >= self.state.chunk_size { self.flush_chunk()?; } + } else if written + self.state.chunk_size < buf.len() { + let nw = HttpChunkedTransferWriter::send_chunk( + &mut self.fd, + self.state.chunk_size, + &buf[written..(written + self.state.chunk_size)], + )?; + written += nw; } else { - if written + self.state.chunk_size < buf.len() { - let nw = HttpChunkedTransferWriter::send_chunk( - &mut self.fd, - self.state.chunk_size, - &buf[written..(written + self.state.chunk_size)], - )?; - written += nw; - } else { - let nw = self.buf_chunk(&buf[written..]); - written += nw; - } + let nw = self.buf_chunk(&buf[written..]); + written += nw; } } Ok(written) @@ -446,9 +434,7 @@ impl<'a, 'state, W: Write> Write for HttpChunkedTransferWriter<'a, 'state, W> { self.flush_chunk().and_then(|nw| { if nw > 0 { // send empty chunk - self.fd - .write_all(format!("0\r\n\r\n").as_bytes()) - .and_then(|_nw| Ok(())) + self.fd.write_all(b"0\r\n\r\n").map(|_nw| ()) } else { Ok(()) } @@ -460,12 +446,13 @@ impl<'a, 'state, W: Write> Write for HttpChunkedTransferWriter<'a, 'state, W> { } mod test { - use super::*; use std::io; use std::io::{Read, Write}; use rand::RngCore; + use super::*; + /// Simulate reading variable-length segments struct SegmentReader { segments: Vec>, @@ -476,7 +463,7 @@ mod test { impl SegmentReader { pub fn new(segments: Vec>) -> SegmentReader { SegmentReader { - segments: segments, + segments, i: 0, j: 0, } @@ -744,7 +731,7 @@ mod test { let errstr = format!("{:?}", &err); assert!( - errstr.find(expected).is_some(), + errstr.contains(expected), "Expected '{}' in '{:?}'", expected, errstr diff --git a/stacks-common/src/util/hash.rs b/stacks-common/src/util/hash.rs index 3f7c165518..f365aaa508 100644 --- a/stacks-common/src/util/hash.rs +++ b/stacks-common/src/util/hash.rs @@ -16,27 +16,21 @@ use std::char::from_digit; use std::convert::TryInto; -use std::fmt; use std::fmt::Write; -use std::mem; - -use crate::util::log; -use crate::util::pair::*; -use crate::util::secp256k1::Secp256k1PublicKey; -use crate::util::HexError; +use std::{fmt, mem}; use ripemd::Ripemd160; +use serde::de::{Deserialize, Error as de_Error}; +use serde::ser::Error as ser_Error; +use serde::Serialize; use sha2::{Digest, Sha256, Sha512, Sha512_256}; use sha3::Keccak256; -use crate::util::uint::Uint256; - use crate::types::StacksPublicKeyBuffer; - -use serde::de::Deserialize; -use serde::de::Error as de_Error; -use serde::ser::Error as ser_Error; -use serde::Serialize; +use crate::util::pair::*; +use crate::util::secp256k1::Secp256k1PublicKey; +use crate::util::uint::Uint256; +use crate::util::{log, HexError}; // hash function for Merkle trees pub trait MerkleHashFunc { @@ -226,7 +220,7 @@ impl MerkleHashFunc for Hash160 { fn from_tagged_data(tag: u8, data: &[u8]) -> Hash160 { let mut tmp = [0u8; 32]; let mut sha2 = Sha256::new(); - sha2.update(&[tag]); + sha2.update([tag]); sha2.update(data); tmp.copy_from_slice(sha2.finalize().as_slice()); Hash160::from_sha256(&tmp) @@ -246,7 +240,7 @@ impl MerkleHashFunc for Sha256Sum { let mut tmp = [0u8; 32]; let mut sha2 = Sha256::new(); - sha2.update(&[tag]); + sha2.update([tag]); sha2.update(data); tmp.copy_from_slice(sha2.finalize().as_slice()); @@ -268,12 +262,12 @@ impl MerkleHashFunc for DoubleSha256 { let mut tmp2 = [0u8; 32]; let mut sha2_1 = Sha256::new(); - sha2_1.update(&[tag]); + sha2_1.update([tag]); sha2_1.update(data); tmp.copy_from_slice(sha2_1.finalize().as_slice()); let mut sha2_2 = Sha256::new(); - sha2_2.update(&tmp); + sha2_2.update(tmp); tmp2.copy_from_slice(sha2_2.finalize().as_slice()); DoubleSha256(tmp2) @@ -294,7 +288,7 @@ impl MerkleHashFunc for Sha512Trunc256Sum { let mut tmp = [0u8; 32]; let mut sha2 = Sha512_256::new(); - sha2.update(&[tag]); + sha2.update([tag]); sha2.update(data); tmp.copy_from_slice(sha2.finalize().as_slice()); @@ -332,7 +326,7 @@ impl DoubleSha256 { pub fn into_le(self) -> Uint256 { let DoubleSha256(data) = self; let mut ret: [u64; 4] = unsafe { mem::transmute(data) }; - for x in (&mut ret).iter_mut() { + for x in ret.iter_mut() { *x = x.to_le(); } Uint256(ret) @@ -344,7 +338,7 @@ impl DoubleSha256 { let DoubleSha256(mut data) = self; data.reverse(); let mut ret: [u64; 4] = unsafe { mem::transmute(data) }; - for x in (&mut ret).iter_mut() { + for x in ret.iter_mut() { *x = x.to_be(); } Uint256(ret) @@ -404,7 +398,7 @@ where } pub fn new(data: &Vec>) -> MerkleTree { - if data.len() == 0 { + if data.is_empty() { return MerkleTree { nodes: vec![] }; } @@ -447,7 +441,7 @@ where nodes.push(row_hashes); } - MerkleTree { nodes: nodes } + MerkleTree { nodes } } /// Get the leaf hash @@ -472,13 +466,7 @@ where self.nodes.len() ); } - - for i in 0..self.nodes[row_index].len() { - if self.nodes[row_index][i] == *hash { - return Some(i); - } - } - None + (0..self.nodes[row_index].len()).find(|&i| self.nodes[row_index][i] == *hash) } /// Given an index into the Merkle tree, find the pair of hashes @@ -533,8 +521,8 @@ where /// Get the Merkle root hash. /// will be all 0's if the tree is empty. pub fn root(&self) -> H { - if self.nodes.len() > 0 { - if self.nodes[self.nodes.len() - 1].len() > 0 { + if !self.nodes.is_empty() { + if !self.nodes[self.nodes.len() - 1].is_empty() { self.nodes[self.nodes.len() - 1][0].clone() } else { H::empty() @@ -547,7 +535,7 @@ where /// Get the path from the given data's leaf up to the root. /// will be None if the data isn't a leaf. pub fn path(&self, data: &[u8]) -> Option> { - let leaf_hash = MerkleTree::get_leaf_hash(&data[..]); + let leaf_hash = MerkleTree::get_leaf_hash(data); let mut hash_index = match self.find_hash_index(&leaf_hash, 0) { None => { return None; @@ -590,19 +578,19 @@ where /// Verify a datum and its Merkle path against a Merkle root pub fn path_verify(data: &[u8], path: &MerklePath, root: &H) -> bool { - if path.len() < 1 { + if path.is_empty() { // invalid path return false; } - let mut hash_acc = MerkleTree::get_leaf_hash(&data[..]); - for i in 0..path.len() { - match path[i].order { + let mut hash_acc = MerkleTree::get_leaf_hash(data); + for path_point in path { + match path_point.order { MerklePathOrder::Left => { - hash_acc = MerkleTree::get_node_hash(&hash_acc, &path[i].hash); + hash_acc = MerkleTree::get_node_hash(&hash_acc, &path_point.hash); } MerklePathOrder::Right => { - hash_acc = MerkleTree::get_node_hash(&path[i].hash, &hash_acc); + hash_acc = MerkleTree::get_node_hash(&path_point.hash, &hash_acc); } } } @@ -667,7 +655,7 @@ pub fn to_hex(s: &[u8]) -> String { for b in s.iter() { write!(r, "{:02x}", b).unwrap(); } - return r; + r } /// Convert a slice of u8 into a binary string @@ -676,23 +664,19 @@ pub fn to_bin(s: &[u8]) -> String { for b in s.iter() { write!(r, "{:08b}", b).unwrap(); } - return r; + r } /// Convert a vec of u8 to a hex string pub fn bytes_to_hex(s: &[u8]) -> String { - to_hex(&s[..]) + to_hex(s) } #[cfg(test)] mod test { - use super::bin_bytes; - use super::hex_bytes; - use super::to_bin; - use super::DoubleSha256; - use super::MerkleHashFunc; - use super::MerklePath; - use super::MerkleTree; + use super::{ + bin_bytes, hex_bytes, to_bin, DoubleSha256, MerkleHashFunc, MerklePath, MerkleTree, + }; struct MerkleTreeFixture { data: Vec>, @@ -806,7 +790,7 @@ mod test { if fixture.res.is_some() { let nodes = fixture.res.unwrap().nodes; - if nodes.len() > 0 { + if !nodes.is_empty() { assert_eq!(tree.root(), nodes[nodes.len() - 1][0]); } else { assert_eq!(tree.root(), DoubleSha256::empty()); @@ -818,7 +802,7 @@ mod test { assert!(MerkleTree::path_verify(&d, &path, &tree.root())); } - if nodes.len() > 0 { + if !nodes.is_empty() { let no_path = tree.path(&hex_bytes("012345").unwrap()); assert!(no_path.is_none()); } diff --git a/stacks-common/src/util/log.rs b/stacks-common/src/util/log.rs index 73463cc45f..0889fc6a8f 100644 --- a/stacks-common/src/util/log.rs +++ b/stacks-common/src/util/log.rs @@ -14,15 +14,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use chrono::prelude::*; -use slog::{BorrowedKV, Drain, FnValue, Level, Logger, OwnedKVList, Record, KV}; -use slog_term::{CountingWriter, Decorator, RecordDecorator, Serializer}; -use std::env; -use std::io; use std::io::Write; use std::sync::Mutex; -use std::thread; use std::time::{Duration, SystemTime}; +use std::{env, io, thread}; + +use chrono::prelude::*; +use slog::{BorrowedKV, Drain, FnValue, Level, Logger, OwnedKVList, Record, KV}; +use slog_term::{CountingWriter, Decorator, RecordDecorator, Serializer}; lazy_static! { pub static ref LOGGER: Logger = make_logger(); @@ -52,7 +51,7 @@ fn print_msg_header(mut rd: &mut dyn RecordDecorator, record: &Record) -> io::Re rd, "[{:5}.{:06}]", elapsed.as_secs(), - elapsed.subsec_nanos() / 1000 + elapsed.subsec_micros() )?; } Some(ref format) => { @@ -247,9 +246,9 @@ fn make_logger() -> Logger { fn inner_get_loglevel() -> slog::Level { if env::var("STACKS_LOG_TRACE") == Ok("1".into()) { slog::Level::Trace - } else if env::var("STACKS_LOG_DEBUG") == Ok("1".into()) { - slog::Level::Debug - } else if env::var("BLOCKSTACK_DEBUG") == Ok("1".into()) { + } else if env::var("STACKS_LOG_DEBUG") == Ok("1".into()) + || env::var("BLOCKSTACK_DEBUG") == Ok("1".into()) + { slog::Level::Debug } else { slog::Level::Info @@ -337,7 +336,7 @@ enum Stream { Stderr, } -#[cfg(all(unix))] +#[cfg(unix)] fn isatty(stream: Stream) -> bool { extern crate libc; let fd = match stream { diff --git a/stacks-common/src/util/macros.rs b/stacks-common/src/util/macros.rs index d087307d0d..16320c948d 100644 --- a/stacks-common/src/util/macros.rs +++ b/stacks-common/src/util/macros.rs @@ -141,6 +141,7 @@ macro_rules! define_versioned_named_enum { } } +#[allow(clippy::crate_in_macro_def)] #[macro_export] macro_rules! guarded_string { ($Name:ident, $Label:literal, $Regex:expr, $MaxStringLength:expr, $ErrorType:ty, $ErrorVariant:path) => { diff --git a/stacks-common/src/util/mod.rs b/stacks-common/src/util/mod.rs index db8901ccd7..97cbc4104f 100644 --- a/stacks-common/src/util/mod.rs +++ b/stacks-common/src/util/mod.rs @@ -27,18 +27,15 @@ pub mod secp256k1; pub mod uint; pub mod vrf; -use std::error; -use std::fmt; -use std::thread; -use std::time; use std::time::{SystemTime, UNIX_EPOCH}; +use std::{error, fmt, thread, time}; pub fn get_epoch_time_secs() -> u64 { let start = SystemTime::now(); let since_the_epoch = start .duration_since(UNIX_EPOCH) .expect("Time went backwards"); - return since_the_epoch.as_secs(); + since_the_epoch.as_secs() } pub fn get_epoch_time_ms() -> u128 { @@ -46,10 +43,10 @@ pub fn get_epoch_time_ms() -> u128 { let since_the_epoch = start .duration_since(UNIX_EPOCH) .expect("Time went backwards"); - return since_the_epoch.as_millis(); + since_the_epoch.as_millis() } -pub fn sleep_ms(millis: u64) -> () { +pub fn sleep_ms(millis: u64) { let t = time::Duration::from_millis(millis); thread::sleep(t); } @@ -98,9 +95,9 @@ pub fn slice_partialeq(s1: &[T], s2: &[T]) -> bool { } pub mod db_common { + use std::{thread, time}; + use rand::{thread_rng, Rng}; - use std::thread; - use std::time; pub fn tx_busy_handler(run_count: i32) -> bool { let mut sleep_count = 10; diff --git a/stacks-common/src/util/pair.rs b/stacks-common/src/util/pair.rs index b82a3777b6..730e64cf40 100644 --- a/stacks-common/src/util/pair.rs +++ b/stacks-common/src/util/pair.rs @@ -30,16 +30,15 @@ impl Iterator for Pair { #[inline] fn next(&mut self) -> Option<(I::Item, I::Item)> { let elem1 = self.iter.next(); - if elem1.is_none() { - None - } else { - let elem2 = self.iter.next(); - if elem2.is_none() { - self.last_elem = elem1; - None + if let Some(elem1) = elem1 { + if let Some(elem2) = self.iter.next() { + Some((elem1, elem2)) } else { - Some((elem1.unwrap(), elem2.unwrap())) + self.last_elem = Some(elem1); + None } + } else { + None } } diff --git a/stacks-common/src/util/pipe.rs b/stacks-common/src/util/pipe.rs index fed0d3c8db..d850826fd4 100644 --- a/stacks-common/src/util/pipe.rs +++ b/stacks-common/src/util/pipe.rs @@ -19,12 +19,7 @@ use std::io; use std::io::{Read, Write}; - -use std::sync::mpsc::sync_channel; -use std::sync::mpsc::Receiver; -use std::sync::mpsc::SyncSender; -use std::sync::mpsc::TryRecvError; -use std::sync::mpsc::TrySendError; +use std::sync::mpsc::{sync_channel, Receiver, SyncSender, TryRecvError, TrySendError}; use crate::util::log; @@ -50,6 +45,7 @@ pub struct PipeWrite { pub struct Pipe {} +#[allow(clippy::new_ret_no_self)] impl Pipe { pub fn new() -> (PipeRead, PipeWrite) { let (send, recv) = sync_channel(1); @@ -60,14 +56,14 @@ impl Pipe { impl PipeRead { fn new(input: Receiver>) -> PipeRead { PipeRead { - input: input, + input, buf: vec![], i: 0, block: true, } } - pub fn set_nonblocking(&mut self, flag: bool) -> () { + pub fn set_nonblocking(&mut self, flag: bool) { self.block = !flag; } @@ -172,12 +168,12 @@ impl PipeRead { } } - if disconnected && copied == 0 && self.buf.len() == 0 { + if disconnected && copied == 0 && self.buf.is_empty() { // out of data, and will never get more return Err(io::Error::from(io::ErrorKind::BrokenPipe)); } - if blocked && copied == 0 && self.buf.len() == 0 { + if blocked && copied == 0 && self.buf.is_empty() { return Err(io::Error::from(io::ErrorKind::WouldBlock)); } @@ -187,10 +183,7 @@ impl PipeRead { impl PipeWrite { fn new(output: SyncSender>) -> PipeWrite { - PipeWrite { - output: output, - buf: None, - } + PipeWrite { output, buf: None } } fn write_or_buffer(&mut self, buf: &[u8]) -> io::Result { @@ -236,30 +229,25 @@ impl PipeWrite { /// Return True if we succeeded; False if not. pub fn try_flush(&mut self) -> io::Result { let data = self.buf.take(); - match data { - Some(bytes) => { - match self.output.try_send(bytes) { - Ok(_) => { - // sent! - Ok(true) - } - Err(send_err) => match send_err { - TrySendError::Full(ret_bytes) => { - // try again - self.buf = Some(ret_bytes); - Ok(false) - } - TrySendError::Disconnected(_) => { - // broken - Err(io::Error::from(io::ErrorKind::BrokenPipe)) - } - }, + if let Some(bytes) = data { + match self.output.try_send(bytes) { + Err(TrySendError::Full(ret_bytes)) => { + // try again + self.buf = Some(ret_bytes); + Ok(false) + } + Err(TrySendError::Disconnected(_)) => { + // broken + Err(io::Error::from(io::ErrorKind::BrokenPipe)) + } + Ok(_) => { + // sent! + Ok(true) } } - None => { - // done! - Ok(true) - } + } else { + // done! + Ok(true) } } } @@ -309,17 +297,13 @@ impl Write for PipeWrite { } fn flush(&mut self) -> io::Result<()> { - let data = self.buf.take(); - match data { - Some(bytes) => { - let _len = bytes.len(); - self.output - .send(bytes) - .map_err(|_e| io::Error::from(io::ErrorKind::BrokenPipe))?; - - trace!("Pipe wrote {} bytes on flush", _len); - } - None => {} + if let Some(bytes) = self.buf.take() { + let _len = bytes.len(); + self.output + .send(bytes) + .map_err(|_e| io::Error::from(io::ErrorKind::BrokenPipe))?; + + trace!("Pipe wrote {} bytes on flush", _len); } Ok(()) } @@ -327,14 +311,15 @@ impl Write for PipeWrite { #[cfg(test)] mod test { - use super::*; - use crate::util::*; - use rand; - use rand::RngCore; - use std::io; use std::io::prelude::*; use std::io::{Read, Write}; - use std::thread; + use std::{io, thread}; + + use rand; + use rand::RngCore; + + use super::*; + use crate::util::*; #[test] fn test_connection_pipe_oneshot() { @@ -369,7 +354,7 @@ mod test { let expected_recv_buf = send_bytes.clone(); pipe_read.set_nonblocking(true); - pipe_write.write(&send_bytes[..]).unwrap(); + let _ = pipe_write.write(&send_bytes[..]).unwrap(); for i in 0..recv_list.len() { let mut buf = vec![0u8; recv_list[i]]; @@ -382,7 +367,7 @@ mod test { num_bytes ); - let num_bytes_expected = outputs[i].as_ref().ok().clone().unwrap(); + let num_bytes_expected = outputs[i].as_ref().ok().unwrap(); assert_eq!( num_bytes, *num_bytes_expected, "Expected {}, got {}", @@ -421,7 +406,7 @@ mod test { buf.resize(1048576, 0); let mut rng = rand::thread_rng(); - rng.fill_bytes(&mut *buf); + rng.fill_bytes(&mut buf); let buf_compare = buf.clone(); // for use in the consumer @@ -533,7 +518,7 @@ mod test { let res = pipe_read.read(&mut bytes).unwrap_err(); assert_eq!(res.kind(), io::ErrorKind::WouldBlock); - pipe_write.write(segment).unwrap(); + let _ = pipe_write.write(segment).unwrap(); // should should succeed since the data is in the receiver's inbox let res = pipe_write.try_flush().unwrap(); @@ -575,8 +560,8 @@ mod test { assert_eq!(res.kind(), io::ErrorKind::WouldBlock); // write each _byte_ - for i in 0..segment.len() { - pipe_write.write(&[segment[i]]).unwrap(); + for (i, byte) in segment.iter().enumerate() { + let _ = pipe_write.write(&[*byte]).unwrap(); let res = pipe_write.try_flush().unwrap(); // first write flushes; subsequent ones don't diff --git a/stacks-common/src/util/retry.rs b/stacks-common/src/util/retry.rs index 6e9c0b909b..d296e4ae79 100644 --- a/stacks-common/src/util/retry.rs +++ b/stacks-common/src/util/retry.rs @@ -35,13 +35,13 @@ pub struct RetryReader<'a, R: Read> { impl<'a, R: Read> RetryReader<'a, R> { pub fn new(fd: &'a mut R) -> RetryReader<'a, R> { RetryReader { - fd: fd, + fd, buf: vec![], i: 0, } } - pub fn set_position(&mut self, offset: usize) -> () { + pub fn set_position(&mut self, offset: usize) { if offset <= self.buf.len() { self.i = offset } else { @@ -88,7 +88,7 @@ impl<'a, R: Read> BoundReader<'a, R> { pub fn from_reader(reader: &'a mut R, max_len: u64) -> BoundReader<'a, R> { BoundReader { fd: reader, - max_len: max_len, + max_len, read_so_far: 0, } } @@ -126,10 +126,7 @@ pub struct LogReader<'a, R: Read> { impl<'a, R: Read> LogReader<'a, R> { pub fn from_reader(fd: &'a mut R) -> LogReader<'a, R> { - LogReader { - fd: fd, - reads: vec![], - } + LogReader { fd, reads: vec![] } } pub fn log(&self) -> &Vec> { diff --git a/stacks-common/src/util/secp256k1.rs b/stacks-common/src/util/secp256k1.rs index 47a0421297..7b6134b8b2 100644 --- a/stacks-common/src/util/secp256k1.rs +++ b/stacks-common/src/util/secp256k1.rs @@ -14,30 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use rand::{thread_rng, RngCore}; use secp256k1; -use secp256k1::constants as LibSecp256k1Constants; -use secp256k1::ecdsa::RecoverableSignature as LibSecp256k1RecoverableSignature; -use secp256k1::ecdsa::RecoveryId as LibSecp256k1RecoveryID; -use secp256k1::ecdsa::Signature as LibSecp256k1Signature; -use secp256k1::Error as LibSecp256k1Error; -use secp256k1::Message as LibSecp256k1Message; -use secp256k1::PublicKey as LibSecp256k1PublicKey; -use secp256k1::Secp256k1; -use secp256k1::SecretKey as LibSecp256k1PrivateKey; - -use crate::types::PrivateKey; -use crate::types::PublicKey; -use crate::util::hash::{hex_bytes, to_hex}; - -use serde::de::Deserialize; -use serde::de::Error as de_Error; +use secp256k1::ecdsa::{ + RecoverableSignature as LibSecp256k1RecoverableSignature, RecoveryId as LibSecp256k1RecoveryID, + Signature as LibSecp256k1Signature, +}; +use secp256k1::{ + constants as LibSecp256k1Constants, Error as LibSecp256k1Error, Message as LibSecp256k1Message, + PublicKey as LibSecp256k1PublicKey, Secp256k1, SecretKey as LibSecp256k1PrivateKey, +}; +use serde::de::{Deserialize, Error as de_Error}; use serde::ser::Error as ser_Error; use serde::Serialize; -use rand::thread_rng; -use rand::RngCore; - use super::hash::Sha256Sum; +use crate::types::{PrivateKey, PublicKey}; +use crate::util::hash::{hex_bytes, to_hex}; // per-thread Secp256k1 context thread_local!(static _secp256k1: Secp256k1 = Secp256k1::new()); @@ -94,9 +87,7 @@ impl MessageSignature { let mut ret_bytes = [0u8; 65]; let recovery_id_byte = recid.to_i32() as u8; // recovery ID will be 0, 1, 2, or 3 ret_bytes[0] = recovery_id_byte; - for i in 0..64 { - ret_bytes[i + 1] = bytes[i]; - } + ret_bytes[1..=64].copy_from_slice(&bytes[..64]); MessageSignature(ret_bytes) } @@ -108,9 +99,7 @@ impl MessageSignature { } }; let mut sig_bytes = [0u8; 64]; - for i in 0..64 { - sig_bytes[i] = self.0[i + 1]; - } + sig_bytes[..64].copy_from_slice(&self.0[1..=64]); match LibSecp256k1RecoverableSignature::from_compact(&sig_bytes, recid) { Ok(sig) => Some(sig), @@ -119,6 +108,13 @@ impl MessageSignature { } } +#[cfg(any(test, feature = "testing"))] +impl Default for Secp256k1PublicKey { + fn default() -> Self { + Self::new() + } +} + impl Secp256k1PublicKey { #[cfg(any(test, feature = "testing"))] pub fn new() -> Secp256k1PublicKey { @@ -142,7 +138,7 @@ impl Secp256k1PublicKey { pub fn from_private(privk: &Secp256k1PrivateKey) -> Secp256k1PublicKey { _secp256k1.with(|ctx| { - let pubk = LibSecp256k1PublicKey::from_secret_key(&ctx, &privk.key); + let pubk = LibSecp256k1PublicKey::from_secret_key(ctx, &privk.key); Secp256k1PublicKey { key: pubk, compressed: privk.compress_public, @@ -237,7 +233,7 @@ impl PublicKey for Secp256k1PublicKey { let secp256k1_sig_standard = secp256k1_sig.to_standard(); // must be low-S - let mut secp256k1_sig_low_s = secp256k1_sig_standard.clone(); + let mut secp256k1_sig_low_s = secp256k1_sig_standard; secp256k1_sig_low_s.normalize_s(); if secp256k1_sig_low_s != secp256k1_sig_standard { return Err("Invalid signature: high-S"); @@ -248,6 +244,12 @@ impl PublicKey for Secp256k1PublicKey { } } +impl Default for Secp256k1PrivateKey { + fn default() -> Self { + Self::new() + } +} + impl Secp256k1PrivateKey { pub fn new() -> Secp256k1PrivateKey { let mut rng = rand::thread_rng(); @@ -315,7 +317,7 @@ impl Secp256k1PrivateKey { match LibSecp256k1PrivateKey::from_slice(&data[0..32]) { Ok(privkey_res) => Ok(Secp256k1PrivateKey { key: privkey_res, - compress_public: compress_public, + compress_public, }), Err(_e) => Err("Invalid private key: failed to load"), } @@ -363,8 +365,8 @@ fn secp256k1_pubkey_serialize( pubk: &LibSecp256k1PublicKey, s: S, ) -> Result { - let key_hex = to_hex(&pubk.serialize().to_vec()); - s.serialize_str(&key_hex.as_str()) + let key_hex = to_hex(&pubk.serialize()); + s.serialize_str(key_hex.as_str()) } fn secp256k1_pubkey_deserialize<'de, D: serde::Deserializer<'de>>( @@ -373,15 +375,15 @@ fn secp256k1_pubkey_deserialize<'de, D: serde::Deserializer<'de>>( let key_hex = String::deserialize(d)?; let key_bytes = hex_bytes(&key_hex).map_err(de_Error::custom)?; - LibSecp256k1PublicKey::from_slice(&key_bytes[..]).map_err(de_Error::custom) + LibSecp256k1PublicKey::from_slice(&key_bytes).map_err(de_Error::custom) } fn secp256k1_privkey_serialize( privk: &LibSecp256k1PrivateKey, s: S, ) -> Result { - let key_hex = to_hex(&privk[..].to_vec()); - s.serialize_str(&key_hex.as_str()) + let key_hex = to_hex(&privk[..]); + s.serialize_str(key_hex.as_str()) } fn secp256k1_privkey_deserialize<'de, D: serde::Deserializer<'de>>( @@ -427,16 +429,12 @@ pub fn secp256k1_verify( #[cfg(test)] mod tests { - use super::*; - - use crate::util::hash::hex_bytes; - use secp256k1; - use secp256k1::PublicKey as LibSecp256k1PublicKey; - use secp256k1::Secp256k1; + use secp256k1::{PublicKey as LibSecp256k1PublicKey, Secp256k1}; - use crate::util::get_epoch_time_ms; - use crate::util::log; + use super::*; + use crate::util::hash::hex_bytes; + use crate::util::{get_epoch_time_ms, log}; struct KeyFixture { input: I, @@ -459,7 +457,7 @@ mod tests { t1.set_compress_public(false); let h_uncomp = t1.to_hex(); - assert!(&h_comp != &h_uncomp); + assert!(h_comp != h_uncomp); assert_eq!(h_comp.len(), 66); assert_eq!(h_uncomp.len(), 64); @@ -551,7 +549,7 @@ mod tests { (_, _) => { // either got a key when we didn't expect one, or didn't get a key when we did // expect one. - assert!(false); + assert!(false, "Unexpected result: we either got a key when we didn't expect one, or didn't get a key when we did expect one."); } } } @@ -621,18 +619,18 @@ mod tests { (Err(e1), Err(e2)) => assert_eq!(e1, e2), (Err(e1), _) => { test_debug!("Failed to verify signature: {}", e1); - eprintln!( + assert!( + false, "failed fixture (verification: {:?}): {:#?}", &ver_res, &fixture ); - assert!(false); } (_, _) => { - eprintln!( + assert!( + false, "failed fixture (verification: {:?}): {:#?}", &ver_res, &fixture ); - assert!(false); } } } diff --git a/stacks-common/src/util/uint.rs b/stacks-common/src/util/uint.rs index 87fc881a65..75824f46d3 100644 --- a/stacks-common/src/util/uint.rs +++ b/stacks-common/src/util/uint.rs @@ -19,10 +19,11 @@ //! Implementation of a various large-but-fixed sized unsigned integer types. //! The functions here are designed to be fast. //! -use crate::util::hash::{hex_bytes, to_hex}; /// Borrowed with gratitude from Andrew Poelstra's rust-bitcoin library use std::fmt; +use crate::util::hash::{hex_bytes, to_hex}; + /// A trait which allows numbers to act as fixed-size bit arrays pub trait BitArray { /// Is bit set? @@ -497,25 +498,20 @@ impl Uint512 { /// from Uint256 pub fn from_uint256(n: &Uint256) -> Uint512 { let mut tmp = [0u64; 8]; - for i in 0..4 { - tmp[i] = n.0[i]; - } + tmp[..4].copy_from_slice(&n.0[0..4]); Uint512(tmp) } pub fn to_uint256(&self) -> Uint256 { let mut tmp = [0u64; 4]; - for i in 0..4 { - tmp[i] = self.0[i]; - } + tmp[..4].copy_from_slice(&self.0[0..4]); Uint256(tmp) } } #[cfg(test)] mod tests { - use crate::util::uint::BitArray; - use crate::util::uint::Uint256; + use crate::util::uint::{BitArray, Uint256}; #[test] pub fn uint256_bits_test() { @@ -741,13 +737,13 @@ mod tests { // little-endian representation let hex_init = "0807060504030201efbeaddeefbeadde00000000000000000000000000000000"; - assert_eq!(Uint256::from_hex_le(&hex_init).unwrap(), init); + assert_eq!(Uint256::from_hex_le(hex_init).unwrap(), init); assert_eq!(&init.to_hex_le(), hex_init); assert_eq!(Uint256::from_hex_le(&init.to_hex_le()).unwrap(), init); // big-endian representation let hex_init = "00000000000000000000000000000000deadbeefdeadbeef0102030405060708"; - assert_eq!(Uint256::from_hex_be(&hex_init).unwrap(), init); + assert_eq!(Uint256::from_hex_be(hex_init).unwrap(), init); assert_eq!(&init.to_hex_be(), hex_init); assert_eq!(Uint256::from_hex_be(&init.to_hex_be()).unwrap(), init); } diff --git a/stacks-common/src/util/vrf.rs b/stacks-common/src/util/vrf.rs index 7a628d1a99..3553275414 100644 --- a/stacks-common/src/util/vrf.rs +++ b/stacks-common/src/util/vrf.rs @@ -17,35 +17,26 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] -use crate::util::hash::to_hex; use std::clone::Clone; -use std::cmp::Eq; -use std::cmp::Ord; -use std::cmp::Ordering; -use std::cmp::PartialEq; +use std::cmp::{Eq, Ord, Ordering, PartialEq}; use std::fmt::Debug; use std::hash::{Hash, Hasher}; /// This codebase is based on routines defined in the IETF draft for verifiable random functions /// over elliptic curves (https://tools.ietf.org/id/draft-irtf-cfrg-vrf-02.html). use std::ops::Deref; use std::ops::DerefMut; - -use ed25519_dalek::Keypair as VRFKeypair; -use ed25519_dalek::PublicKey as ed25519_PublicKey; -use ed25519_dalek::SecretKey as ed25519_PrivateKey; +use std::{error, fmt}; use curve25519_dalek::constants::ED25519_BASEPOINT_POINT; use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint}; use curve25519_dalek::scalar::Scalar as ed25519_Scalar; - -use sha2::Digest; -use sha2::Sha512; - -use std::error; -use std::fmt; - -use crate::util::hash::hex_bytes; +use ed25519_dalek::{ + Keypair as VRFKeypair, PublicKey as ed25519_PublicKey, SecretKey as ed25519_PrivateKey, +}; use rand; +use sha2::{Digest, Sha512}; + +use crate::util::hash::{hex_bytes, to_hex}; #[derive(Clone)] pub struct VRFPublicKey(pub ed25519_PublicKey); @@ -149,6 +140,12 @@ impl PartialEq for VRFPrivateKey { } } +impl Default for VRFPrivateKey { + fn default() -> Self { + Self::new() + } +} + impl VRFPrivateKey { pub fn new() -> VRFPrivateKey { let mut rng = rand::thread_rng(); @@ -265,7 +262,7 @@ impl Debug for VRFProof { } impl Hash for VRFProof { - fn hash(&self, h: &mut H) -> () { + fn hash(&self, h: &mut H) { let bytes = self.to_bytes(); bytes.hash(h); } @@ -286,16 +283,17 @@ impl VRFProof { &self.c } + #[allow(clippy::needless_range_loop)] pub fn check_c(c: &ed25519_Scalar) -> bool { let c_bytes = c.reduce().to_bytes(); // upper 16 bytes of c must be 0's - for i in 16..32 { - if c_bytes[i] != 0 { + for c_byte in c_bytes[16..32].iter() { + if *c_byte != 0 { return false; } } - return true; + true } pub fn empty() -> VRFProof { @@ -336,28 +334,19 @@ impl VRFProof { let mut c_buf = [0u8; 32]; let mut s_buf = [0u8; 32]; - for i in 0..16 { - c_buf[i] = bytes[32 + i]; - } - for i in 0..32 { - s_buf[i] = bytes[48 + i]; - } - + c_buf[..16].copy_from_slice(&bytes[32..(16 + 32)]); + s_buf[..32].copy_from_slice(&bytes[48..(32 + 48)]); let c = ed25519_Scalar::from_canonical_bytes(c_buf)?; let s = ed25519_Scalar::from_canonical_bytes(s_buf)?; - Some(VRFProof { - Gamma: gamma, - c: c, - s: s, - }) + Some(VRFProof { Gamma: gamma, c, s }) } _ => None, } } pub fn from_bytes(bytes: &[u8]) -> Option { - VRFProof::from_slice(&bytes[..]) + VRFProof::from_slice(bytes) } pub fn from_hex(hex_str: &str) -> Option { @@ -419,18 +408,18 @@ impl VRF { let h: EdwardsPoint = loop { let mut hasher = Sha512::new(); - hasher.update(&[SUITE, 0x01]); + hasher.update([SUITE, 0x01]); hasher.update(y.as_bytes()); hasher.update(alpha); if ctr == 0 { - hasher.update(&[0u8]); + hasher.update([0u8]); } else { // 2**64 - 1 is an artificial cap -- the RFC implies that you should count forever let ctr_bytes = ctr.to_le_bytes(); - for i in 0..8 { + for (i, ctr_byte) in ctr_bytes.iter().enumerate() { if ctr > 1u64 << (8 * i) { - hasher.update(&[ctr_bytes[i]]); + hasher.update([*ctr_byte]); } } } @@ -445,8 +434,7 @@ impl VRF { .expect("Too many attempts at try-and-increment hash-to-curve"); }; - let ed = h.mul_by_cofactor(); - ed + h.mul_by_cofactor() } /// Hash four points to a 16-byte string. @@ -461,11 +449,11 @@ impl VRF { let mut hash128 = [0u8; 16]; // hasher.input(&[SUITE, 0x02]); - hasher.update(&[0x03, 0x02]); - hasher.update(&p1.compress().to_bytes()); - hasher.update(&p2.compress().to_bytes()); - hasher.update(&p3.compress().to_bytes()); - hasher.update(&p4.compress().to_bytes()); + hasher.update([0x03, 0x02]); + hasher.update(p1.compress().to_bytes()); + hasher.update(p2.compress().to_bytes()); + hasher.update(p3.compress().to_bytes()); + hasher.update(p4.compress().to_bytes()); hash128.copy_from_slice(&hasher.finalize()[0..16]); hash128 @@ -511,7 +499,7 @@ impl VRF { let h_string = H_point.compress().to_bytes(); hasher.update(trunc_hash); - hasher.update(&h_string); + hasher.update(h_string); let rs = &hasher.finalize()[..]; k_string.copy_from_slice(rs); @@ -529,6 +517,7 @@ impl VRF { /// ECVRF proof routine /// https://tools.ietf.org/id/draft-irtf-cfrg-vrf-02.html#rfc.section.5.1 + #[allow(clippy::op_ref)] pub fn prove(secret: &VRFPrivateKey, alpha: &[u8]) -> VRFProof { let (Y_point, x_scalar, trunc_hash) = VRF::expand_privkey(secret); let H_point = VRF::hash_to_curve(&Y_point, alpha); @@ -556,6 +545,7 @@ impl VRF { /// Return Ok(false) if not /// Return Err(Error) if the public key is invalid, or we are unable to do one of the /// necessary internal data conversions. + #[allow(clippy::op_ref)] pub fn verify(Y_point: &VRFPublicKey, proof: &VRFProof, alpha: &[u8]) -> Result { let H_point = VRF::hash_to_curve(Y_point, alpha); let s_reduced = proof.s().reduce(); @@ -588,16 +578,13 @@ impl VRF { #[cfg(test)] mod tests { - use super::*; - - use crate::util::hash::hex_bytes; - use curve25519_dalek::scalar::Scalar as ed25519_Scalar; - - use sha2::Sha512; - use rand; use rand::RngCore; + use sha2::Sha512; + + use super::*; + use crate::util::hash::hex_bytes; #[derive(Debug)] struct VRF_Proof_Fixture { @@ -642,7 +629,7 @@ mod tests { ]; for proof_fixture in proof_fixtures { - let alpha = hex_bytes(&proof_fixture.message).unwrap(); + let alpha = hex_bytes(proof_fixture.message).unwrap(); let privk = VRFPrivateKey::from_bytes(&proof_fixture.privkey[..]).unwrap(); let expected_proof_bytes = &proof_fixture.proof[..]; @@ -668,8 +655,8 @@ mod tests { let mut msg = [0u8; 1024]; rng.fill_bytes(&mut msg); - let proof = VRF::prove(&secret_key, &msg.to_vec()); - let res = VRF::verify(&public_key, &proof, &msg.to_vec()).unwrap(); + let proof = VRF::prove(&secret_key, &msg); + let res = VRF::verify(&public_key, &proof, &msg).unwrap(); assert!(res); } @@ -715,7 +702,7 @@ mod tests { let proof_res = VRFProof::from_bytes(&proof_fixture.proof); if proof_fixture.result { // should decode - assert!(!proof_res.is_none()); + assert!(proof_res.is_some()); // should re-encode assert!(proof_res.unwrap().to_bytes().to_vec() == proof_fixture.proof.to_vec()); diff --git a/stacks-signer/Cargo.toml b/stacks-signer/Cargo.toml index 9293d82668..ff48884531 100644 --- a/stacks-signer/Cargo.toml +++ b/stacks-signer/Cargo.toml @@ -26,8 +26,9 @@ clap = { version = "4.1.1", features = ["derive", "env"] } hashbrown = "0.14" libsigner = { path = "../libsigner" } libstackerdb = { path = "../libstackerdb" } -p256k1 = "5.4" +p256k1 = "5.5" rand_core = "0.6" +reqwest = { version = "0.11.22", features = ["blocking", "json"] } serde = "1" serde_derive = "1" serde_stacker = "0.1" @@ -35,11 +36,12 @@ slog = { version = "2.5.2", features = [ "max_level_trace" ] } slog-json = { version = "2.3.0", optional = true } slog-term = "2.6.0" stacks-common = { path = "../stacks-common" } +stackslib = { path = "../stackslib"} thiserror = "1.0" toml = "0.5.6" tracing = "0.1.37" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } -wsts = { git = "https://github.com/Trust-Machines/wsts", tag = "4.0.0rc2" } +wsts = "4.0.0" [dependencies.serde_json] version = "1.0" diff --git a/stacks-signer/src/cli.rs b/stacks-signer/src/cli.rs index 5614c42191..ab0e6649a3 100644 --- a/stacks-signer/src/cli.rs +++ b/stacks-signer/src/cli.rs @@ -1,15 +1,16 @@ -use std::{ - io::{self, Read}, - net::SocketAddr, - path::PathBuf, -}; +use std::io::{self, Read}; +use std::net::SocketAddr; +use std::path::PathBuf; use clap::Parser; use clarity::vm::types::QualifiedContractIdentifier; +use stacks_common::address::b58; use stacks_common::types::chainstate::StacksPrivateKey; use crate::config::Network; +extern crate alloc; + #[derive(Parser, Debug)] #[command(author, version, about)] /// The CLI arguments for the stacks signer @@ -95,7 +96,9 @@ pub struct PutChunkArgs { pub slot_version: u32, /// The data to upload #[arg(required = false, value_parser = parse_data)] - pub data: Vec, + // Note this weirdness is due to https://github.com/clap-rs/clap/discussions/4695 + // Need to specify the long name here due to invalid parsing in Clap which looks at the NAME rather than the TYPE which causes issues in how it handles Vec's. + pub data: alloc::vec::Vec, } #[derive(Parser, Debug, Clone)] @@ -106,7 +109,9 @@ pub struct SignArgs { pub config: PathBuf, /// The data to sign #[arg(required = false, value_parser = parse_data)] - pub data: Vec, + // Note this weirdness is due to https://github.com/clap-rs/clap/discussions/4695 + // Need to specify the long name here due to invalid parsing in Clap which looks at the NAME rather than the TYPE which causes issues in how it handles Vec's. + pub data: alloc::vec::Vec, } #[derive(Parser, Debug, Clone)] @@ -137,7 +142,7 @@ pub struct GenerateFilesArgs { /// The total number of key ids to distribute among the signers pub num_keys: u32, #[arg(long, value_parser = parse_network)] - /// The network to use. One of "mainnet" or "testnet". + /// The network to use. One of "mainnet", "testnet", or "mocknet". pub network: Network, /// The directory to write the test data files to #[arg(long, default_value = ".")] @@ -159,25 +164,28 @@ fn parse_private_key(private_key: &str) -> Result { /// Parse the input data fn parse_data(data: &str) -> Result, String> { - let data = if data == "-" { + let encoded_data = if data == "-" { // Parse the data from stdin - let mut buf = vec![]; - io::stdin().read_to_end(&mut buf).unwrap(); - buf + let mut data = String::new(); + io::stdin().read_to_string(&mut data).unwrap(); + data } else { - data.as_bytes().to_vec() + data.to_string() }; + let data = + b58::from(&encoded_data).map_err(|e| format!("Failed to decode provided data: {}", e))?; Ok(data) } -/// Parse the network. Must be one of "mainnet" or "testnet". +/// Parse the network. Must be one of "mainnet", "testnet", or "mocknet". fn parse_network(network: &str) -> Result { Ok(match network.to_lowercase().as_str() { "mainnet" => Network::Mainnet, "testnet" => Network::Testnet, + "mocknet" => Network::Mocknet, _ => { return Err(format!( - "Invalid network: {}. Must be one of \"mainnet\" or \"testnet\".", + "Invalid network: {}. Must be one of \"mainnet\", \"testnet\", or \"mocknet\".", network )) } diff --git a/stacks-signer/src/config.rs b/stacks-signer/src/config.rs index 8bd556c859..4251913cff 100644 --- a/stacks-signer/src/config.rs +++ b/stacks-signer/src/config.rs @@ -14,18 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::convert::TryFrom; +use std::fs; +use std::net::{SocketAddr, ToSocketAddrs}; +use std::path::PathBuf; +use std::time::Duration; + +use blockstack_lib::chainstate::stacks::TransactionVersion; use clarity::vm::types::QualifiedContractIdentifier; use hashbrown::HashMap; -use p256k1::{ecdsa, scalar::Scalar}; +use p256k1::ecdsa; +use p256k1::scalar::Scalar; use serde::Deserialize; -use stacks_common::types::chainstate::StacksPrivateKey; -use std::{ - convert::TryFrom, - fs, - net::{SocketAddr, ToSocketAddrs}, - path::PathBuf, - time::Duration, +use stacks_common::address::{ + AddressHashMode, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; +use stacks_common::consts::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET}; +use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey}; use wsts::state_machine::PublicKeys; /// List of key_ids for each signer_id @@ -45,6 +50,9 @@ pub enum ConfigError { /// A field was malformed #[error("identifier={0}, value={1}")] BadField(String, String), + /// An unsupported address version + #[error("Failed to convert private key to address: unsupported address version.")] + UnsupportedAddressVersion, } #[derive(serde::Deserialize, Debug, Clone)] @@ -55,6 +63,34 @@ pub enum Network { Mainnet, /// The testnet network Testnet, + /// The mocknet network + Mocknet, +} + +impl Network { + /// Converts a Network enum variant to a corresponding chain id + pub fn to_chain_id(&self) -> u32 { + match self { + Self::Mainnet => CHAIN_ID_MAINNET, + Self::Testnet | Self::Mocknet => CHAIN_ID_TESTNET, + } + } + + /// Convert a Network enum variant to a corresponding address version + pub fn to_address_version(&self) -> u8 { + match self { + Self::Mainnet => C32_ADDRESS_VERSION_MAINNET_SINGLESIG, + Self::Testnet | Self::Mocknet => C32_ADDRESS_VERSION_TESTNET_SINGLESIG, + } + } + + /// Convert a Network enum variant to a Transaction Version + pub fn to_transaction_version(&self) -> TransactionVersion { + match self { + Self::Mainnet => TransactionVersion::Mainnet, + Self::Testnet | Self::Mocknet => TransactionVersion::Testnet, + } + } } /// The parsed configuration for the signer @@ -69,9 +105,11 @@ pub struct Config { pub message_private_key: Scalar, /// The signer's Stacks private key pub stacks_private_key: StacksPrivateKey, + /// The signer's Stacks address + pub stacks_address: StacksAddress, /// The network to use. One of "mainnet" or "testnet". pub network: Network, - /// The signer ID and key ids mapped to a pulbic key + /// The signer ID and key ids mapped to a public key pub signer_ids_public_keys: PublicKeys, /// The signer IDs mapped to their Key IDs pub signer_key_ids: SignerKeyIds, @@ -191,6 +229,14 @@ impl TryFrom for Config { raw_data.stacks_private_key.clone(), ) })?; + let stacks_public_key = StacksPublicKey::from_private(&stacks_private_key); + let stacks_address = StacksAddress::from_public_keys( + raw_data.network.to_address_version(), + &AddressHashMode::SerializeP2PKH, + 1, + &vec![stacks_public_key], + ) + .ok_or(ConfigError::UnsupportedAddressVersion)?; let mut public_keys = PublicKeys::default(); let mut signer_key_ids = SignerKeyIds::default(); for (i, s) in raw_data.signers.iter().enumerate() { @@ -221,6 +267,7 @@ impl TryFrom for Config { stackerdb_contract_id, message_private_key, stacks_private_key, + stacks_address, network: raw_data.network, signer_ids_public_keys: public_keys, signer_id: raw_data.signer_id, diff --git a/stacks-signer/src/main.rs b/stacks-signer/src/main.rs index 09139be156..cf8b4bd72b 100644 --- a/stacks-signer/src/main.rs +++ b/stacks-signer/src/main.rs @@ -26,41 +26,35 @@ extern crate serde; extern crate serde_json; extern crate toml; +use std::fs::File; +use std::io::{self, BufRead, Write}; +use std::net::SocketAddr; +use std::path::PathBuf; +use std::sync::mpsc::{channel, Receiver, Sender}; +use std::time::Duration; + use clap::Parser; use clarity::vm::types::QualifiedContractIdentifier; use libsigner::{RunningSigner, Signer, SignerSession, StackerDBEventReceiver, StackerDBSession}; use libstackerdb::StackerDBChunkData; use slog::slog_debug; -use stacks_common::{ - address::{ - AddressHashMode, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, - C32_ADDRESS_VERSION_TESTNET_SINGLESIG, - }, - debug, - types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey}, -}; -use stacks_signer::{ - cli::{ - Cli, Command, GenerateFilesArgs, GetChunkArgs, GetLatestChunkArgs, PutChunkArgs, - RunDkgArgs, SignArgs, StackerDBArgs, - }, - config::{Config, Network}, - runloop::{RunLoop, RunLoopCommand}, - utils::{build_signer_config_tomls, build_stackerdb_contract}, +use stacks_common::address::{ + AddressHashMode, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; -use std::{ - fs::File, - io::{self, BufRead, Write}, - net::SocketAddr, - path::PathBuf, - sync::mpsc::{channel, Receiver, Sender}, - time::Duration, -}; -use tracing_subscriber::{fmt, prelude::*, EnvFilter}; -use wsts::{ - state_machine::{coordinator::Coordinator as FrostCoordinator, OperationResult}, - v2, +use stacks_common::debug; +use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey}; +use stacks_signer::cli::{ + Cli, Command, GenerateFilesArgs, GetChunkArgs, GetLatestChunkArgs, PutChunkArgs, RunDkgArgs, + SignArgs, StackerDBArgs, }; +use stacks_signer::config::{Config, Network}; +use stacks_signer::runloop::{RunLoop, RunLoopCommand}; +use stacks_signer::utils::{build_signer_config_tomls, build_stackerdb_contract}; +use tracing_subscriber::prelude::*; +use tracing_subscriber::{fmt, EnvFilter}; +use wsts::state_machine::coordinator::frost::Coordinator as FrostCoordinator; +use wsts::state_machine::OperationResult; +use wsts::v2; struct SpawnedSigner { running_signer: RunningSigner>, @@ -101,7 +95,7 @@ fn spawn_running_signer(path: &PathBuf) -> SpawnedSigner { RunLoop>, StackerDBEventReceiver, > = Signer::new(runloop, ev, cmd_recv, res_send); - let endpoint = config.node_host; + let endpoint = config.endpoint; let running_signer = signer.spawn(endpoint).unwrap(); SpawnedSigner { running_signer, @@ -180,7 +174,7 @@ fn handle_list_chunks(args: StackerDBArgs) { fn handle_put_chunk(args: PutChunkArgs) { debug!("Putting chunk..."); let mut session = stackerdb_session(args.db_args.host, args.db_args.contract); - let mut chunk = StackerDBChunkData::new(args.slot_id, args.slot_version, args.data.clone()); + let mut chunk = StackerDBChunkData::new(args.slot_id, args.slot_version, args.data); chunk.sign(&args.private_key).unwrap(); let chunk_ack = session.put_chunk(chunk).unwrap(); println!("{}", serde_json::to_string(&chunk_ack).unwrap()); @@ -192,7 +186,7 @@ fn handle_dkg(args: RunDkgArgs) { spawned_signer.cmd_send.send(RunLoopCommand::Dkg).unwrap(); let dkg_res = spawned_signer.res_recv.recv().unwrap(); process_dkg_result(&dkg_res); - spawned_signer.running_signer.stop().unwrap(); + spawned_signer.running_signer.stop(); } fn handle_sign(args: SignArgs) { @@ -208,7 +202,7 @@ fn handle_sign(args: SignArgs) { .unwrap(); let sign_res = spawned_signer.res_recv.recv().unwrap(); process_sign_result(&sign_res); - spawned_signer.running_signer.stop().unwrap(); + spawned_signer.running_signer.stop(); } fn handle_dkg_sign(args: SignArgs) { @@ -228,13 +222,15 @@ fn handle_dkg_sign(args: SignArgs) { process_dkg_result(&dkg_res); let sign_res = spawned_signer.res_recv.recv().unwrap(); process_sign_result(&sign_res); - spawned_signer.running_signer.stop().unwrap(); + spawned_signer.running_signer.stop(); } fn handle_run(args: RunDkgArgs) { debug!("Running signer..."); - let _spawned_signer = spawn_running_signer(&args.config); - println!("Signer spawned successfully. Waiting for messages to process."); + let spawned_signer = spawn_running_signer(&args.config); + println!("Signer spawned successfully. Waiting for messages to process..."); + // Wait for the spawned signer to stop (will only occur if an error occurs) + let _ = spawned_signer.running_signer.join(); } fn handle_generate_files(args: GenerateFilesArgs) { @@ -339,7 +335,7 @@ fn main() { fn to_addr(stacks_private_key: &StacksPrivateKey, network: &Network) -> StacksAddress { let version = match network { Network::Mainnet => C32_ADDRESS_VERSION_MAINNET_SINGLESIG, - Network::Testnet => C32_ADDRESS_VERSION_TESTNET_SINGLESIG, + Network::Testnet | Network::Mocknet => C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; StacksAddress::from_public_keys( version, diff --git a/stacks-signer/src/runloop.rs b/stacks-signer/src/runloop.rs index 8035878b23..69a1904e00 100644 --- a/stacks-signer/src/runloop.rs +++ b/stacks-signer/src/runloop.rs @@ -1,19 +1,21 @@ -use crate::{config::Config, stacks_client::StacksClient}; +use std::collections::VecDeque; +use std::sync::mpsc::Sender; +use std::time::Duration; + use libsigner::{SignerRunLoop, StackerDBChunksEvent}; use p256k1::ecdsa; use slog::{slog_debug, slog_error, slog_info, slog_warn}; use stacks_common::{debug, error, info, warn}; -use std::{collections::VecDeque, sync::mpsc::Sender, time::Duration}; -use wsts::{ - common::MerkleRoot, - net::{Message, Packet, Signable}, - state_machine::{ - coordinator::{Coordinatable, Coordinator as FrostCoordinator}, - signer::SigningRound, - OperationResult, PublicKeys, - }, - v2, -}; +use wsts::common::MerkleRoot; +use wsts::net::{Message, Packet, Signable}; +use wsts::state_machine::coordinator::frost::Coordinator as FrostCoordinator; +use wsts::state_machine::coordinator::Coordinatable; +use wsts::state_machine::signer::SigningRound; +use wsts::state_machine::{OperationResult, PublicKeys}; +use wsts::v2; + +use crate::config::Config; +use crate::stacks_client::StacksClient; /// Which operation to perform #[derive(PartialEq, Clone)] @@ -161,12 +163,12 @@ impl RunLoop { // First process all messages as a signer let mut outbound_messages = self .signing_round - .process_inbound_messages(inbound_messages.clone()) + .process_inbound_messages(&inbound_messages) .unwrap_or_default(); // If the signer is the coordinator, then next process the message as the coordinator let (messages, results) = if self.signing_round.signer_id == coordinator_id { self.coordinator - .process_inbound_messages(inbound_messages) + .process_inbound_messages(&inbound_messages) .unwrap_or_default() } else { (vec![], vec![]) diff --git a/stacks-signer/src/stacks_client.rs b/stacks-signer/src/stacks_client.rs index 68e1cb60a0..68ce997056 100644 --- a/stacks-signer/src/stacks_client.rs +++ b/stacks-signer/src/stacks_client.rs @@ -1,9 +1,18 @@ use bincode::Error as BincodeError; +use blockstack_lib::chainstate::stacks::{ + StacksTransaction, StacksTransactionSigner, TransactionAnchorMode, TransactionAuth, + TransactionContractCall, TransactionPayload, TransactionPostConditionMode, + TransactionSpendingCondition, TransactionVersion, +}; +use clarity::vm::{ClarityName, ContractName, Value as ClarityValue}; use hashbrown::HashMap; use libsigner::{RPCError, SignerSession, StackerDBSession}; use libstackerdb::{Error as StackerDBError, StackerDBChunkAckData, StackerDBChunkData}; +use serde_json::json; use slog::{slog_debug, slog_warn}; -use stacks_common::{debug, types::chainstate::StacksPrivateKey, warn}; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey}; +use stacks_common::{codec, debug, warn}; use wsts::net::{Message, Packet}; use crate::config::Config; @@ -28,17 +37,56 @@ pub enum ClientError { /// Stacker-db instance rejected the chunk #[error("Stacker-db rejected the chunk. Reason: {0}")] PutChunkRejected(String), + /// Failed to find a given json entry + #[error("Invalid JSON entry: {0}")] + InvalidJsonEntry(String), + /// Failed to call a read only function + #[error("Failed to call read only function. {0}")] + ReadOnlyFailure(String), + /// Reqwest specific error occurred + #[error("{0}")] + ReqwestError(#[from] reqwest::Error), + /// Failure to submit a read only contract call + #[error("Failure to submit tx")] + TransactionSubmissionFailure, + /// Failed to sign with the provided private key + #[error("Failed to sign with the given private key")] + SignatureGenerationFailure, + /// Failed to sign with the provided private key + #[error("Failed to sign with the sponsor private key")] + SponsorSignatureGenerationFailure, + /// Failed to sign with the provided private key + #[error("Failed to serialize tx {0}")] + FailureToSerializeTx(String), + /// Failed to sign with the provided private key + #[error("{0}")] + FailureToDeserializeTx(#[from] codec::Error), + /// Failed to create a p2pkh spending condition + #[error("Failed to create p2pkh spending condition from public key {0}")] + FailureToCreateSpendingFromPublicKey(String), + /// Stacks node client request failed + #[error("Stacks node client request failed: {0}")] + RequestFailure(reqwest::StatusCode), } -/// TODO: Add stacks node communication to this /// The Stacks signer client used to communicate with the stacker-db instance pub struct StacksClient { /// The stacker-db session stackerdb_session: StackerDBSession, + /// The stacks address of the signer + stacks_address: StacksAddress, /// The private key used in all stacks node communications stacks_private_key: StacksPrivateKey, /// A map of a slot ID to last chunk version slot_versions: HashMap, + /// The RPC endpoint used to communicate HTTP endpoints with + http_origin: String, + /// The types of transactions + tx_version: TransactionVersion, + /// The chain we are interacting with + chain_id: u32, + /// The Client used to make HTTP connects + stacks_node_client: reqwest::blocking::Client, } impl From<&Config> for StacksClient { @@ -49,7 +97,12 @@ impl From<&Config> for StacksClient { config.stackerdb_contract_id.clone(), ), stacks_private_key: config.stacks_private_key, + stacks_address: config.stacks_address, slot_versions: HashMap::new(), + http_origin: format!("http://{}", config.node_host), + tx_version: config.network.to_transaction_version(), + chain_id: config.network.to_chain_id(), + stacks_node_client: reqwest::blocking::Client::new(), } } } @@ -98,6 +151,169 @@ impl StacksClient { // See: https://github.com/stacks-network/stacks-blockchain/issues/3921 SLOTS_PER_USER } + + fn serialize_sign_sig_tx_anchor_mode_version( + &self, + payload: TransactionPayload, + sender_nonce: u64, + tx_fee: u64, + anchor_mode: TransactionAnchorMode, + ) -> Result, ClientError> { + self.seralize_sign_sponsored_tx_anchor_mode_version( + payload, + None, + sender_nonce, + None, + tx_fee, + anchor_mode, + ) + } + + fn seralize_sign_sponsored_tx_anchor_mode_version( + &self, + payload: TransactionPayload, + payer: Option<&StacksPrivateKey>, + sender_nonce: u64, + payer_nonce: Option, + tx_fee: u64, + anchor_mode: TransactionAnchorMode, + ) -> Result, ClientError> { + let pubkey = StacksPublicKey::from_private(&self.stacks_private_key); + let mut sender_spending_condition = + TransactionSpendingCondition::new_singlesig_p2pkh(pubkey).ok_or( + ClientError::FailureToCreateSpendingFromPublicKey(pubkey.to_hex()), + )?; + sender_spending_condition.set_nonce(sender_nonce); + + let auth = match (payer, payer_nonce) { + (Some(payer), Some(payer_nonce)) => { + let pubkey = StacksPublicKey::from_private(payer); + let mut payer_spending_condition = + TransactionSpendingCondition::new_singlesig_p2pkh(pubkey).ok_or( + ClientError::FailureToCreateSpendingFromPublicKey(pubkey.to_hex()), + )?; + payer_spending_condition.set_nonce(payer_nonce); + payer_spending_condition.set_tx_fee(tx_fee); + TransactionAuth::Sponsored(sender_spending_condition, payer_spending_condition) + } + _ => { + sender_spending_condition.set_tx_fee(tx_fee); + TransactionAuth::Standard(sender_spending_condition) + } + }; + let mut unsigned_tx = StacksTransaction::new(self.tx_version, auth, payload); + unsigned_tx.anchor_mode = anchor_mode; + unsigned_tx.post_condition_mode = TransactionPostConditionMode::Allow; + unsigned_tx.chain_id = self.chain_id; + + let mut tx_signer = StacksTransactionSigner::new(&unsigned_tx); + tx_signer + .sign_origin(&self.stacks_private_key) + .map_err(|_| ClientError::SignatureGenerationFailure)?; + if let (Some(payer), Some(_)) = (payer, payer_nonce) { + tx_signer + .sign_sponsor(payer) + .map_err(|_| ClientError::SponsorSignatureGenerationFailure)?; + } + + let Some(tx) = tx_signer.get_tx() else { + return Err(ClientError::SignatureGenerationFailure); + }; + + Ok(tx.serialize_to_vec()) + } + + /// Creates a transaction for a contract call that can be submitted to a stacks node + pub fn transaction_contract_call( + &self, + nonce: u64, + contract_addr: &StacksAddress, + contract_name: ContractName, + function_name: ClarityName, + function_args: &[ClarityValue], + ) -> Result, ClientError> { + let payload = TransactionContractCall { + address: *contract_addr, + contract_name, + function_name, + function_args: function_args.to_vec(), + }; + + let tx_fee = 0; + + self.serialize_sign_sig_tx_anchor_mode_version( + payload.into(), + nonce, + tx_fee, + TransactionAnchorMode::OnChainOnly, + ) + } + + /// Submits a transaction to the Stacks node + pub fn submit_tx(&self, tx: Vec) -> Result { + let path = format!("{}/v2/transactions", self.http_origin); + let res = self + .stacks_node_client + .post(path) + .header("Content-Type", "application/octet-stream") + .body(tx.clone()) + .send()?; + if res.status().is_success() { + let res: String = res.json()?; + let tx_deserialized = StacksTransaction::consensus_deserialize(&mut &tx[..])?; + assert_eq!(res, tx_deserialized.txid().to_string()); + Ok(res) + } else { + Err(ClientError::TransactionSubmissionFailure) + } + } + + /// Makes a read only contract call to a stacks contract + pub fn read_only_contract_call( + &self, + contract_addr: &StacksAddress, + contract_name: ContractName, + function_name: ClarityName, + function_args: &[ClarityValue], + ) -> Result { + debug!("Calling read-only function {}...", function_name); + let body = json!({"sender": self.stacks_address.to_string(), "arguments": function_args}) + .to_string(); + let path = format!( + "{}/v2/contracts/call-read/{contract_addr}/{contract_name}/{function_name}", + self.http_origin + ); + let response = self + .stacks_node_client + .post(path) + .header("Content-Type", "application/json") + .body(body) + .send()?; + if !response.status().is_success() { + return Err(ClientError::RequestFailure(response.status())); + } + let response = response.json::()?; + if !response + .get("okay") + .map(|val| val.as_bool().unwrap_or(false)) + .unwrap_or(false) + { + let cause = response + .get("cause") + .ok_or(ClientError::InvalidJsonEntry("cause".to_string()))?; + return Err(ClientError::ReadOnlyFailure(format!( + "{}: {}", + function_name, cause + ))); + } + let result = response + .get("result") + .ok_or(ClientError::InvalidJsonEntry("result".to_string()))? + .as_str() + .ok_or_else(|| ClientError::ReadOnlyFailure("Expected string result.".to_string()))? + .to_string(); + Ok(result) + } } /// Helper function to determine the slot ID for the provided stacker-db writer id and the message type @@ -115,3 +331,128 @@ fn slot_id(id: u32, message: &Message) -> u32 { }; SLOTS_PER_USER * id + slot_id } + +#[cfg(test)] +mod tests { + use std::io::{Read, Write}; + use std::net::{SocketAddr, TcpListener}; + use std::thread::spawn; + + use super::*; + + struct TestConfig { + mock_server: TcpListener, + client: StacksClient, + } + + impl TestConfig { + pub fn new() -> Self { + let mut config = Config::load_from_file("./src/tests/conf/signer-0.toml").unwrap(); + + let mut mock_server_addr = SocketAddr::from(([127, 0, 0, 1], 0)); + // Ask the OS to assign a random port to listen on by passing 0 + let mock_server = TcpListener::bind(mock_server_addr).unwrap(); + + // Update the config to use this port + mock_server_addr.set_port(mock_server.local_addr().unwrap().port()); + config.node_host = mock_server_addr; + + let client = StacksClient::from(&config); + Self { + mock_server, + client, + } + } + } + + fn write_response(mock_server: TcpListener, bytes: &[u8]) -> [u8; 1024] { + debug!("Writing a response..."); + let mut request_bytes = [0u8; 1024]; + { + let mut stream = mock_server.accept().unwrap().0; + let _ = stream.read(&mut request_bytes).unwrap(); + stream.write_all(bytes).unwrap(); + } + request_bytes + } + + #[test] + fn read_only_contract_call_200_success() { + let config = TestConfig::new(); + let h = spawn(move || { + config.client.read_only_contract_call( + &config.client.stacks_address, + ContractName::try_from("contract-name").unwrap(), + ClarityName::try_from("function-name").unwrap(), + &[], + ) + }); + write_response( + config.mock_server, + b"HTTP/1.1 200 OK\n\n{\"okay\":true,\"result\":\"0x070d0000000473425443\"}", + ); + let result = h.join().unwrap().unwrap(); + assert_eq!(result, "0x070d0000000473425443"); + } + + #[test] + fn read_only_contract_call_200_failure() { + let config = TestConfig::new(); + let h = spawn(move || { + config.client.read_only_contract_call( + &config.client.stacks_address, + ContractName::try_from("contract-name").unwrap(), + ClarityName::try_from("function-name").unwrap(), + &[], + ) + }); + write_response( + config.mock_server, + b"HTTP/1.1 200 OK\n\n{\"okay\":false,\"cause\":\"Some reason\"}", + ); + let result = h.join().unwrap(); + assert!(matches!(result, Err(ClientError::ReadOnlyFailure(_)))); + } + + #[test] + fn read_only_contract_call_400_failure() { + let config = TestConfig::new(); + // Simulate a 400 Bad Request response + let h = spawn(move || { + config.client.read_only_contract_call( + &config.client.stacks_address, + ContractName::try_from("contract-name").unwrap(), + ClarityName::try_from("function-name").unwrap(), + &[], + ) + }); + write_response(config.mock_server, b"HTTP/1.1 400 Bad Request\n\n"); + let result = h.join().unwrap(); + assert!(matches!( + dbg!(result), + Err(ClientError::RequestFailure( + reqwest::StatusCode::BAD_REQUEST + )) + )); + } + + #[test] + fn read_only_contract_call_404_failure() { + let config = TestConfig::new(); + // Simulate a 400 Bad Request response + let h = spawn(move || { + config.client.read_only_contract_call( + &config.client.stacks_address, + ContractName::try_from("contract-name").unwrap(), + ClarityName::try_from("function-name").unwrap(), + &[], + ) + }); + write_response(config.mock_server, b"HTTP/1.1 404 Not Found\n\n"); + let result = h.join().unwrap(); + assert!(matches!( + dbg!(result), + Err(ClientError::RequestFailure(reqwest::StatusCode::NOT_FOUND)) + )); + } +} diff --git a/stacks-signer/src/utils.rs b/stacks-signer/src/utils.rs index d4b5f51266..3c1e1b36cd 100644 --- a/stacks-signer/src/utils.rs +++ b/stacks-signer/src/utils.rs @@ -3,10 +3,8 @@ use std::time::Duration; use p256k1::ecdsa; use rand_core::OsRng; use slog::slog_debug; -use stacks_common::{ - debug, - types::chainstate::{StacksAddress, StacksPrivateKey}, -}; +use stacks_common::debug; +use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey}; use wsts::Scalar; use crate::stacks_client::SLOTS_PER_USER; diff --git a/stackslib/src/blockstack_cli.rs b/stackslib/src/blockstack_cli.rs index 27a57b545c..e85d02bc7f 100644 --- a/stackslib/src/blockstack_cli.rs +++ b/stackslib/src/blockstack_cli.rs @@ -32,11 +32,10 @@ use blockstack_lib::burnchains::bitcoin::address::{ ADDRESS_VERSION_MAINNET_SINGLESIG, ADDRESS_VERSION_TESTNET_SINGLESIG, }; use blockstack_lib::burnchains::Address; -use blockstack_lib::chainstate::stacks::StacksBlockHeader; use blockstack_lib::chainstate::stacks::{ - StacksBlock, StacksMicroblock, StacksPrivateKey, StacksPublicKey, StacksTransaction, - StacksTransactionSigner, TokenTransferMemo, TransactionAnchorMode, TransactionAuth, - TransactionContractCall, TransactionPayload, TransactionSmartContract, + StacksBlock, StacksBlockHeader, StacksMicroblock, StacksPrivateKey, StacksPublicKey, + StacksTransaction, StacksTransactionSigner, TokenTransferMemo, TransactionAnchorMode, + TransactionAuth, TransactionContractCall, TransactionPayload, TransactionSmartContract, TransactionSpendingCondition, TransactionVersion, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; @@ -44,18 +43,13 @@ use blockstack_lib::clarity_cli::vm_execute; use blockstack_lib::core::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET}; use blockstack_lib::net::Error as NetError; use blockstack_lib::util_lib::strings::StacksString; -use clarity::vm::ClarityVersion; -use clarity::vm::{ - errors::{Error as ClarityError, RuntimeErrorType}, - types::PrincipalData, - ClarityName, ContractName, Value, -}; -use stacks_common::address::b58; -use stacks_common::address::AddressHashMode; +use clarity::vm::errors::{Error as ClarityError, RuntimeErrorType}; +use clarity::vm::types::PrincipalData; +use clarity::vm::{ClarityName, ClarityVersion, ContractName, Value}; +use stacks_common::address::{b58, AddressHashMode}; use stacks_common::codec::{Error as CodecError, StacksMessageCodec}; use stacks_common::types::chainstate::StacksAddress; -use stacks_common::util::hash::hex_bytes; -use stacks_common::util::hash::to_hex; +use stacks_common::util::hash::{hex_bytes, to_hex}; use stacks_common::util::retry::LogReader; const USAGE: &str = "blockstack-cli (options) [method] [args...] diff --git a/stackslib/src/burnchains/affirmation.rs b/stackslib/src/burnchains/affirmation.rs index f7bde0ac50..b7a83f2f1b 100644 --- a/stackslib/src/burnchains/affirmation.rs +++ b/stackslib/src/burnchains/affirmation.rs @@ -238,31 +238,27 @@ use std::fmt::Write; use std::sync::mpsc::SyncSender; use std::time::Duration; -use crate::burnchains::{ - db::{BurnchainBlockData, BurnchainDB, BurnchainDBTransaction, BurnchainHeaderReader}, - Address, Burnchain, BurnchainBlockHeader, Error, PoxConstants, Txid, +use serde::de::Error as de_Error; +use serde::ser::Error as ser_Error; +use serde::{Deserialize, Serialize}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksAddress, StacksBlockId, +}; + +use crate::burnchains::db::{ + BurnchainBlockData, BurnchainDB, BurnchainDBTransaction, BurnchainHeaderReader, }; -use crate::chainstate::burn::{ - db::sortdb::SortitionDB, - operations::leader_block_commit::{RewardSetInfo, BURN_BLOCK_MINED_AT_MODULUS}, - operations::BlockstackOperationType, - operations::LeaderBlockCommitOp, - BlockSnapshot, ConsensusHash, +use crate::burnchains::{Address, Burnchain, BurnchainBlockHeader, Error, PoxConstants, Txid}; +use crate::chainstate::burn::db::sortdb::SortitionDB; +use crate::chainstate::burn::operations::leader_block_commit::{ + RewardSetInfo, BURN_BLOCK_MINED_AT_MODULUS, }; +use crate::chainstate::burn::operations::{BlockstackOperationType, LeaderBlockCommitOp}; +use crate::chainstate::burn::{BlockSnapshot, ConsensusHash}; use crate::chainstate::stacks::StacksBlockHeader; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - use crate::core::StacksEpochId; - use crate::util_lib::boot::boot_code_id; -use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksAddress, StacksBlockId, -}; - -use serde::de::Error as de_Error; -use serde::ser::Error as ser_Error; -use serde::{Deserialize, Serialize}; +use crate::util_lib::db::{DBConn, Error as DBError}; /// Affirmation map entries. By building on a PoX-mined block, /// a PoB-mined block (in a PoX reward cycle), diff --git a/stackslib/src/burnchains/bitcoin/address.rs b/stackslib/src/burnchains/bitcoin/address.rs index 165906203f..bc5ab4b459 100644 --- a/stackslib/src/burnchains/bitcoin/address.rs +++ b/stackslib/src/burnchains/bitcoin/address.rs @@ -14,9 +14,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::burnchains::bitcoin::BitcoinNetworkType; -use crate::burnchains::bitcoin::Error as btc_error; -use crate::burnchains::Address; use stacks_common::address::b58 as base58; use stacks_common::address::c32::c32_address; use stacks_common::deps_common::bech32; @@ -27,6 +24,8 @@ use stacks_common::deps_common::bitcoin::blockdata::transaction::TxOut; use stacks_common::util::hash::{hex_bytes, to_hex, Hash160}; use stacks_common::util::log; +use crate::burnchains::bitcoin::{BitcoinNetworkType, Error as btc_error}; +use crate::burnchains::Address; use crate::chainstate::stacks::{ C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, @@ -699,7 +698,6 @@ impl Address for BitcoinAddress { #[cfg(test)] mod tests { - use crate::burnchains::bitcoin::BitcoinNetworkType; use stacks_common::types::Address; use stacks_common::util::hash::{hex_bytes, Hash160}; use stacks_common::util::log; @@ -707,6 +705,7 @@ mod tests { use super::{ BitcoinAddress, LegacyBitcoinAddress, LegacyBitcoinAddressType, SegwitBitcoinAddress, }; + use crate::burnchains::bitcoin::BitcoinNetworkType; struct AddressFixture { addr: String, diff --git a/stackslib/src/burnchains/bitcoin/bits.rs b/stackslib/src/burnchains/bitcoin/bits.rs index 6fd387ea13..ec721fba3e 100644 --- a/stackslib/src/burnchains/bitcoin/bits.rs +++ b/stackslib/src/burnchains/bitcoin/bits.rs @@ -14,34 +14,29 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use sha2::Digest; -use sha2::Sha256; - -use crate::burnchains::bitcoin::address::{BitcoinAddress, LegacyBitcoinAddressType}; -use crate::burnchains::bitcoin::keys::BitcoinPublicKey; -use crate::burnchains::bitcoin::BitcoinNetworkType; -use crate::burnchains::bitcoin::Error as btc_error; -use crate::burnchains::bitcoin::{ - BitcoinInputType, BitcoinTxInput, BitcoinTxInputRaw, BitcoinTxInputStructured, BitcoinTxOutput, -}; -use crate::burnchains::PublicKey; -use crate::burnchains::Txid; -use stacks_common::address::public_keys_to_address_hash; -use stacks_common::address::AddressHashMode; -use stacks_common::deps_common::bitcoin::blockdata::opcodes::All as btc_opcodes; -use stacks_common::deps_common::bitcoin::blockdata::opcodes::Class; +use sha2::{Digest, Sha256}; +use stacks_common::address::{public_keys_to_address_hash, AddressHashMode}; +use stacks_common::deps_common::bitcoin::blockdata::opcodes::{All as btc_opcodes, Class}; use stacks_common::deps_common::bitcoin::blockdata::script::{Builder, Instruction, Script}; -use stacks_common::deps_common::bitcoin::blockdata::transaction::TxIn as BtcTxIn; -use stacks_common::deps_common::bitcoin::blockdata::transaction::TxOut as BtcTxOut; +use stacks_common::deps_common::bitcoin::blockdata::transaction::{ + TxIn as BtcTxIn, TxOut as BtcTxOut, +}; use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash; +use stacks_common::types::chainstate::BurnchainHeaderHash; use stacks_common::util::hash::{hex_bytes, Hash160}; use stacks_common::util::log; +use crate::burnchains::bitcoin::address::{BitcoinAddress, LegacyBitcoinAddressType}; +use crate::burnchains::bitcoin::keys::BitcoinPublicKey; +use crate::burnchains::bitcoin::{ + BitcoinInputType, BitcoinNetworkType, BitcoinTxInput, BitcoinTxInputRaw, + BitcoinTxInputStructured, BitcoinTxOutput, Error as btc_error, +}; +use crate::burnchains::{PublicKey, Txid}; use crate::chainstate::stacks::{ C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; -use stacks_common::types::chainstate::BurnchainHeaderHash; /// Parse a script into its structured constituant opcodes and data and collect them pub fn parse_script<'a>(script: &'a Script) -> Vec> { @@ -639,24 +634,22 @@ impl BitcoinTxOutput { #[cfg(test)] mod tests { - use crate::burnchains::bitcoin::address::{ - BitcoinAddress, LegacyBitcoinAddress, LegacyBitcoinAddressType, SegwitBitcoinAddress, - }; - use crate::burnchains::bitcoin::keys::BitcoinPublicKey; - use crate::burnchains::bitcoin::BitcoinInputType; - use crate::burnchains::bitcoin::BitcoinNetworkType; - use crate::burnchains::Txid; use stacks_common::deps_common::bitcoin::blockdata::script::{Builder, Script}; use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; + use stacks_common::deps_common::bitcoin::network::serialize::deserialize as bitcoinlib_deserialize; use stacks_common::util::hash::hex_bytes; use stacks_common::util::log; - use super::parse_script; - use super::to_txid; - use super::BitcoinTxOutput; - use super::{BitcoinTxInput, BitcoinTxInputRaw, BitcoinTxInputStructured}; - - use stacks_common::deps_common::bitcoin::network::serialize::deserialize as bitcoinlib_deserialize; + use super::{ + parse_script, to_txid, BitcoinTxInput, BitcoinTxInputRaw, BitcoinTxInputStructured, + BitcoinTxOutput, + }; + use crate::burnchains::bitcoin::address::{ + BitcoinAddress, LegacyBitcoinAddress, LegacyBitcoinAddressType, SegwitBitcoinAddress, + }; + use crate::burnchains::bitcoin::keys::BitcoinPublicKey; + use crate::burnchains::bitcoin::{BitcoinInputType, BitcoinNetworkType}; + use crate::burnchains::Txid; struct ScriptFixture { script: Script, diff --git a/stackslib/src/burnchains/bitcoin/blocks.rs b/stackslib/src/burnchains/bitcoin/blocks.rs index 3123d66c3e..0cee9e60e6 100644 --- a/stackslib/src/burnchains/bitcoin/blocks.rs +++ b/stackslib/src/burnchains/bitcoin/blocks.rs @@ -16,39 +16,34 @@ use std::ops::Deref; +use stacks_common::deps_common::bitcoin::blockdata::block::{Block, LoneBlockHeader}; +use stacks_common::deps_common::bitcoin::blockdata::opcodes::All as btc_opcodes; +use stacks_common::deps_common::bitcoin::blockdata::script::{Instruction, Script}; +use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; +use stacks_common::deps_common::bitcoin::network::message as btc_message; +use stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; +use stacks_common::deps_common::bitcoin::util::hash::bitcoin_merkle_root; +use stacks_common::types::chainstate::BurnchainHeaderHash; +use stacks_common::util::hash::to_hex; +use stacks_common::util::log; + use crate::burnchains::bitcoin::address::BitcoinAddress; -use crate::burnchains::bitcoin::bits; use crate::burnchains::bitcoin::indexer::BitcoinIndexer; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; use crate::burnchains::bitcoin::messages::BitcoinMessageHandler; -use crate::burnchains::bitcoin::BitcoinInputType; -use crate::burnchains::bitcoin::BitcoinNetworkType; -use crate::burnchains::bitcoin::Error as btc_error; -use crate::burnchains::bitcoin::PeerMessage; use crate::burnchains::bitcoin::{ - BitcoinBlock, BitcoinTransaction, BitcoinTxInput, BitcoinTxOutput, + bits, BitcoinBlock, BitcoinInputType, BitcoinNetworkType, BitcoinTransaction, BitcoinTxInput, + BitcoinTxOutput, Error as btc_error, PeerMessage, }; use crate::burnchains::indexer::{ BurnBlockIPC, BurnHeaderIPC, BurnchainBlockDownloader, BurnchainBlockParser, }; -use crate::burnchains::Error as burnchain_error; use crate::burnchains::{ - BurnchainBlock, BurnchainTransaction, MagicBytes, Txid, MAGIC_BYTES_LENGTH, + BurnchainBlock, BurnchainTransaction, Error as burnchain_error, MagicBytes, Txid, + MAGIC_BYTES_LENGTH, }; -use crate::deps; -use stacks_common::deps_common::bitcoin::blockdata::block::{Block, LoneBlockHeader}; -use stacks_common::deps_common::bitcoin::blockdata::opcodes::All as btc_opcodes; -use stacks_common::deps_common::bitcoin::blockdata::script::{Instruction, Script}; -use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; -use stacks_common::deps_common::bitcoin::network::message as btc_message; -use stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; -use stacks_common::deps_common::bitcoin::util::hash::bitcoin_merkle_root; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; - -use stacks_common::types::chainstate::BurnchainHeaderHash; - use crate::core::StacksEpochId; +use crate::deps; #[derive(Debug, Clone, PartialEq)] pub struct BitcoinHeaderIPC { @@ -548,26 +543,24 @@ impl BurnchainBlockParser for BitcoinBlockParser { #[cfg(test)] mod tests { - use crate::burnchains::bitcoin::address::{BitcoinAddress, LegacyBitcoinAddressType}; - use crate::burnchains::bitcoin::keys::BitcoinPublicKey; - use crate::burnchains::bitcoin::BitcoinNetworkType; - use crate::burnchains::bitcoin::{ - BitcoinBlock, BitcoinInputType, BitcoinTransaction, BitcoinTxInput, BitcoinTxInputRaw, - BitcoinTxInputStructured, BitcoinTxOutput, - }; - use crate::burnchains::{BurnchainBlock, BurnchainTransaction, MagicBytes, Txid}; - use crate::core::StacksEpochId; use stacks_common::deps_common::bitcoin::blockdata::block::{Block, LoneBlockHeader}; use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; use stacks_common::deps_common::bitcoin::network::encodable::VarInt; use stacks_common::deps_common::bitcoin::network::serialize::deserialize; + use stacks_common::types::chainstate::BurnchainHeaderHash; use stacks_common::types::Address; use stacks_common::util::hash::hex_bytes; use stacks_common::util::log; - use stacks_common::types::chainstate::BurnchainHeaderHash; - use super::BitcoinBlockParser; + use crate::burnchains::bitcoin::address::{BitcoinAddress, LegacyBitcoinAddressType}; + use crate::burnchains::bitcoin::keys::BitcoinPublicKey; + use crate::burnchains::bitcoin::{ + BitcoinBlock, BitcoinInputType, BitcoinNetworkType, BitcoinTransaction, BitcoinTxInput, + BitcoinTxInputRaw, BitcoinTxInputStructured, BitcoinTxOutput, + }; + use crate::burnchains::{BurnchainBlock, BurnchainTransaction, MagicBytes, Txid}; + use crate::core::StacksEpochId; struct TxFixture { txstr: String, diff --git a/stackslib/src/burnchains/bitcoin/indexer.rs b/stackslib/src/burnchains/bitcoin/indexer.rs index 5b78b9c478..c273a38de4 100644 --- a/stackslib/src/burnchains/bitcoin/indexer.rs +++ b/stackslib/src/burnchains/bitcoin/indexer.rs @@ -14,52 +14,41 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use rand::{thread_rng, Rng}; -use std::cmp; -use std::fs; -use std::net; +use std::convert::TryFrom; use std::net::Shutdown; -use std::ops::Deref; -use std::ops::DerefMut; -use std::path; +use std::ops::{Deref, DerefMut}; use std::path::PathBuf; -use std::time; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; use std::time::Duration; +use std::{cmp, fs, net, path, time}; -use crate::burnchains::bitcoin::blocks::BitcoinHeaderIPC; -use crate::burnchains::bitcoin::messages::BitcoinMessageHandler; -use crate::burnchains::bitcoin::spv::*; -use crate::burnchains::bitcoin::Error as btc_error; -use crate::burnchains::db::BurnchainHeaderReader; -use crate::burnchains::indexer::BurnchainIndexer; -use crate::burnchains::indexer::*; -use crate::burnchains::Burnchain; -use crate::util_lib::db::Error as DBError; - -use crate::burnchains::bitcoin::blocks::{BitcoinBlockDownloader, BitcoinBlockParser}; -use crate::burnchains::bitcoin::BitcoinNetworkType; - -use crate::burnchains::BurnchainBlockHeader; -use crate::burnchains::Error as burnchain_error; -use crate::burnchains::MagicBytes; -use crate::burnchains::BLOCKSTACK_MAGIC_MAINNET; -use stacks_common::types::chainstate::BurnchainHeaderHash; - +use rand::{thread_rng, Rng}; use stacks_common::deps_common::bitcoin::blockdata::block::{BlockHeader, LoneBlockHeader}; use stacks_common::deps_common::bitcoin::network::encodable::VarInt; use stacks_common::deps_common::bitcoin::network::message::NetworkMessage; -use stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; -use stacks_common::deps_common::bitcoin::network::serialize::Error as btc_serialization_err; +use stacks_common::deps_common::bitcoin::network::serialize::{ + BitcoinHash, Error as btc_serialization_err, +}; use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::log; +use stacks_common::types::chainstate::BurnchainHeaderHash; +use stacks_common::util::{get_epoch_time_secs, log}; +use crate::burnchains::bitcoin::blocks::{ + BitcoinBlockDownloader, BitcoinBlockParser, BitcoinHeaderIPC, +}; +use crate::burnchains::bitcoin::messages::BitcoinMessageHandler; +use crate::burnchains::bitcoin::spv::*; +use crate::burnchains::bitcoin::{BitcoinNetworkType, Error as btc_error}; +use crate::burnchains::db::BurnchainHeaderReader; +use crate::burnchains::indexer::{BurnchainIndexer, *}; +use crate::burnchains::{ + Burnchain, BurnchainBlockHeader, Error as burnchain_error, MagicBytes, BLOCKSTACK_MAGIC_MAINNET, +}; use crate::core::{ StacksEpoch, STACKS_EPOCHS_MAINNET, STACKS_EPOCHS_REGTEST, STACKS_EPOCHS_TESTNET, }; -use std::convert::TryFrom; -use std::sync::atomic::AtomicBool; -use std::sync::Arc; +use crate::util_lib::db::Error as DBError; pub const USER_AGENT: &'static str = "Stacks/2.1"; @@ -1202,11 +1191,8 @@ impl BurnchainHeaderReader for BitcoinIndexer { #[cfg(test)] mod test { - use super::*; - use crate::burnchains::bitcoin::Error as btc_error; - use crate::burnchains::bitcoin::*; - use crate::burnchains::Error as burnchain_error; - use crate::burnchains::*; + use std::sync::atomic::Ordering; + use std::{env, thread}; use stacks_common::deps_common::bitcoin::blockdata::block::{BlockHeader, LoneBlockHeader}; use stacks_common::deps_common::bitcoin::network::encodable::VarInt; @@ -1217,8 +1203,9 @@ mod test { use stacks_common::util::get_epoch_time_secs; use stacks_common::util::uint::Uint256; - use std::sync::atomic::Ordering; - use std::{env, thread}; + use super::*; + use crate::burnchains::bitcoin::{Error as btc_error, *}; + use crate::burnchains::{Error as burnchain_error, *}; #[test] fn test_indexer_find_bitcoin_reorg_genesis() { diff --git a/stackslib/src/burnchains/bitcoin/messages.rs b/stackslib/src/burnchains/bitcoin/messages.rs index 21dba22078..a58f7c0395 100644 --- a/stackslib/src/burnchains/bitcoin/messages.rs +++ b/stackslib/src/burnchains/bitcoin/messages.rs @@ -15,8 +15,7 @@ // along with this program. If not, see . use crate::burnchains::bitcoin::indexer::BitcoinIndexer; -use crate::burnchains::bitcoin::Error as btc_error; -use crate::burnchains::bitcoin::PeerMessage; +use crate::burnchains::bitcoin::{Error as btc_error, PeerMessage}; pub trait BitcoinMessageHandler { fn begin_session(&mut self, indexer: &mut BitcoinIndexer) -> Result; diff --git a/stackslib/src/burnchains/bitcoin/mod.rs b/stackslib/src/burnchains/bitcoin/mod.rs index bfbd5cfa1d..d273b1f5f8 100644 --- a/stackslib/src/burnchains/bitcoin/mod.rs +++ b/stackslib/src/burnchains/bitcoin/mod.rs @@ -17,10 +17,12 @@ // This module is concerned with the implementation of the BitcoinIndexer // structure and its methods and traits. -use std::error; -use std::fmt; -use std::io; use std::sync::Arc; +use std::{error, fmt, io}; + +use stacks_common::deps_common::bitcoin::network::serialize::Error as btc_serialize_error; +use stacks_common::types::chainstate::BurnchainHeaderHash; +use stacks_common::util::HexError as btc_hex_error; use crate::burnchains::bitcoin::address::BitcoinAddress; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; @@ -28,10 +30,6 @@ use crate::burnchains::Txid; use crate::chainstate::burn::operations::BlockstackOperationType; use crate::deps; use crate::util_lib::db::Error as db_error; -use stacks_common::deps_common::bitcoin::network::serialize::Error as btc_serialize_error; -use stacks_common::util::HexError as btc_hex_error; - -use stacks_common::types::chainstate::BurnchainHeaderHash; pub mod address; pub mod bits; diff --git a/stackslib/src/burnchains/bitcoin/network.rs b/stackslib/src/burnchains/bitcoin/network.rs index 124430018f..d29c7b2aaf 100644 --- a/stackslib/src/burnchains/bitcoin/network.rs +++ b/stackslib/src/burnchains/bitcoin/network.rs @@ -14,39 +14,31 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::io; use std::io::Write; use std::net::SocketAddr; use std::ops::Deref; use std::sync::atomic::Ordering; -use std::thread; -use std::time; use std::time::{SystemTime, UNIX_EPOCH}; +use std::{io, thread, time}; use rand::{thread_rng, Rng}; - -use stacks_common::deps_common::bitcoin::network::address as btc_network_address; -use stacks_common::deps_common::bitcoin::network::constants as btc_constants; use stacks_common::deps_common::bitcoin::network::encodable::{ ConsensusDecodable, ConsensusEncodable, }; -use stacks_common::deps_common::bitcoin::network::message as btc_message; -use stacks_common::deps_common::bitcoin::network::message_blockdata as btc_message_blockdata; -use stacks_common::deps_common::bitcoin::network::message_network as btc_message_network; -use stacks_common::deps_common::bitcoin::network::serialize as btc_serialize; use stacks_common::deps_common::bitcoin::network::serialize::{RawDecoder, RawEncoder}; - +use stacks_common::deps_common::bitcoin::network::{ + address as btc_network_address, constants as btc_constants, message as btc_message, + message_blockdata as btc_message_blockdata, message_network as btc_message_network, + serialize as btc_serialize, +}; use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash; +use stacks_common::util::{get_epoch_time_secs, log}; use crate::burnchains::bitcoin::indexer::{network_id_to_bytes, BitcoinIndexer}; use crate::burnchains::bitcoin::messages::BitcoinMessageHandler; -use crate::burnchains::bitcoin::Error as btc_error; -use crate::burnchains::bitcoin::PeerMessage; +use crate::burnchains::bitcoin::{Error as btc_error, PeerMessage}; use crate::burnchains::indexer::BurnchainIndexer; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::log; - // Based on Andrew Poelstra's rust-bitcoin library. impl BitcoinIndexer { /// Send a Bitcoin protocol message on the wire diff --git a/stackslib/src/burnchains/bitcoin/spv.rs b/stackslib/src/burnchains/bitcoin/spv.rs index 28746fcdaf..a5627db4df 100644 --- a/stackslib/src/burnchains/bitcoin/spv.rs +++ b/stackslib/src/burnchains/bitcoin/spv.rs @@ -14,12 +14,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::cmp; use std::collections::VecDeque; -use std::fs; use std::io::{Read, Seek, SeekFrom, Write}; use std::ops::Deref; +use std::{cmp, fs}; +use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; +use rusqlite::{Connection, OpenFlags, OptionalExtension, Row, Transaction, NO_PARAMS}; use stacks_common::deps_common::bitcoin::blockdata::block::{BlockHeader, LoneBlockHeader}; use stacks_common::deps_common::bitcoin::blockdata::constants::genesis_block; use stacks_common::deps_common::bitcoin::network::constants::Network; @@ -29,30 +30,18 @@ use stacks_common::deps_common::bitcoin::network::serialize::{ deserialize, serialize, BitcoinHash, }; use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash; - +use stacks_common::types::chainstate::BurnchainHeaderHash; +use stacks_common::util::hash::{hex_bytes, to_hex}; use stacks_common::util::uint::Uint256; +use stacks_common::util::{get_epoch_time_secs, log}; use crate::burnchains::bitcoin::indexer::BitcoinIndexer; use crate::burnchains::bitcoin::messages::BitcoinMessageHandler; -use crate::burnchains::bitcoin::BitcoinNetworkType; -use crate::burnchains::bitcoin::Error as btc_error; -use crate::burnchains::bitcoin::PeerMessage; - -use stacks_common::types::chainstate::BurnchainHeaderHash; - -use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; -use rusqlite::OptionalExtension; -use rusqlite::Row; -use rusqlite::Transaction; -use rusqlite::{Connection, OpenFlags, NO_PARAMS}; - +use crate::burnchains::bitcoin::{BitcoinNetworkType, Error as btc_error, PeerMessage}; use crate::util_lib::db::{ query_int, query_row, query_rows, sqlite_open, tx_begin_immediate, tx_busy_handler, u64_to_sql, DBConn, DBTx, Error as db_error, FromColumn, FromRow, }; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::{hex_bytes, to_hex}; -use stacks_common::util::log; const BLOCK_HEADER_SIZE: u64 = 81; @@ -1318,10 +1307,7 @@ impl BitcoinMessageHandler for SpvClient { #[cfg(test)] mod test { - use super::*; - use crate::burnchains::bitcoin::Error as btc_error; - use crate::burnchains::bitcoin::*; - + use std::env; use std::fs::*; use stacks_common::deps_common::bitcoin::blockdata::block::{BlockHeader, LoneBlockHeader}; @@ -1329,10 +1315,10 @@ mod test { deserialize, serialize, BitcoinHash, }; use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash; - use stacks_common::util::log; - use std::env; + use super::*; + use crate::burnchains::bitcoin::{Error as btc_error, *}; fn get_genesis_regtest_header() -> LoneBlockHeader { let genesis_regtest_header = LoneBlockHeader { @@ -1797,12 +1783,11 @@ mod test { #[test] fn test_witness_size() { - use stacks_common::deps_common::bitcoin::blockdata::script::Script; - use stacks_common::deps_common::bitcoin::blockdata::transaction::OutPoint; - use stacks_common::deps_common::bitcoin::blockdata::transaction::TxIn; - use stacks_common::deps_common::bitcoin::blockdata::transaction::TxOut; use std::mem; + use stacks_common::deps_common::bitcoin::blockdata::script::Script; + use stacks_common::deps_common::bitcoin::blockdata::transaction::{OutPoint, TxIn, TxOut}; + println!("OutPoint size in memory {}", mem::size_of::()); println!("TxIn in memory {}", mem::size_of::()); println!("TxOut size in memory {}", mem::size_of::()); diff --git a/stackslib/src/burnchains/burnchain.rs b/stackslib/src/burnchains/burnchain.rs index 7b4d97c73b..4ba47f804e 100644 --- a/stackslib/src/burnchains/burnchain.rs +++ b/stackslib/src/burnchains/burnchain.rs @@ -14,80 +14,61 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::collections::HashMap; -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; -use std::fs; use std::marker::Send; use std::path::PathBuf; +use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::mpsc::sync_channel; -use std::sync::{ - atomic::{AtomicBool, AtomicU64, Ordering}, - Arc, -}; -use std::thread; +use std::sync::Arc; use std::time::{Duration, Instant}; +use std::{fs, thread}; + +use stacks_common::address::{public_keys_to_address_hash, AddressHashMode}; +use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash as BitcoinSha256dHash; +use stacks_common::types::chainstate::{BurnchainHeaderHash, PoxId, StacksAddress, TrieHash}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::vrf::VRFPublicKey; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs, log, sleep_ms}; use crate::burnchains::affirmation::update_pox_affirmation_maps; -use crate::burnchains::bitcoin::address::to_c32_version_byte; -use crate::burnchains::bitcoin::address::BitcoinAddress; -use crate::burnchains::bitcoin::address::LegacyBitcoinAddressType; -use crate::burnchains::bitcoin::BitcoinNetworkType; -use crate::burnchains::bitcoin::{BitcoinInputType, BitcoinTxInput, BitcoinTxOutput}; +use crate::burnchains::bitcoin::address::{ + to_c32_version_byte, BitcoinAddress, LegacyBitcoinAddressType, +}; +use crate::burnchains::bitcoin::indexer::BitcoinIndexer; +use crate::burnchains::bitcoin::{ + BitcoinInputType, BitcoinNetworkType, BitcoinTxInput, BitcoinTxOutput, +}; use crate::burnchains::db::{BurnchainDB, BurnchainHeaderReader}; use crate::burnchains::indexer::{ BurnBlockIPC, BurnHeaderIPC, BurnchainBlockDownloader, BurnchainBlockParser, BurnchainIndexer, }; -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::PublicKey; -use crate::burnchains::Txid; use crate::burnchains::{ - BurnchainBlock, BurnchainBlockHeader, BurnchainParameters, BurnchainRecipient, BurnchainSigner, - BurnchainStateTransition, BurnchainStateTransitionOps, BurnchainTransaction, - Error as burnchain_error, PoxConstants, + Address, Burnchain, BurnchainBlock, BurnchainBlockHeader, BurnchainParameters, + BurnchainRecipient, BurnchainSigner, BurnchainStateTransition, BurnchainStateTransitionOps, + BurnchainTransaction, Error as burnchain_error, PoxConstants, PublicKey, Txid, +}; +use crate::chainstate::burn::db::sortdb::{ + SortitionDB, SortitionHandle, SortitionHandleConn, SortitionHandleTx, }; -use crate::chainstate::burn::db::sortdb::SortitionHandle; -use crate::chainstate::burn::db::sortdb::{SortitionDB, SortitionHandleConn, SortitionHandleTx}; use crate::chainstate::burn::distribution::BurnSamplePoint; +use crate::chainstate::burn::operations::leader_block_commit::MissedBlockCommit; use crate::chainstate::burn::operations::{ - leader_block_commit::MissedBlockCommit, BlockstackOperationType, DelegateStxOp, - LeaderBlockCommitOp, LeaderKeyRegisterOp, PreStxOp, StackStxOp, TransferStxOp, - UserBurnSupportOp, + BlockstackOperationType, DelegateStxOp, LeaderBlockCommitOp, LeaderKeyRegisterOp, PreStxOp, + StackStxOp, TransferStxOp, UserBurnSupportOp, }; use crate::chainstate::burn::{BlockSnapshot, Opcodes}; use crate::chainstate::coordinator::comm::CoordinatorChannels; -use crate::chainstate::stacks::address::PoxAddress; +use crate::chainstate::stacks::address::{PoxAddress, StacksAddressExtensions}; +use crate::chainstate::stacks::boot::{POX_2_MAINNET_CODE, POX_2_TESTNET_CODE}; use crate::chainstate::stacks::StacksPublicKey; -use crate::core::MINING_COMMITMENT_WINDOW; -use crate::core::NETWORK_ID_MAINNET; -use crate::core::NETWORK_ID_TESTNET; -use crate::core::PEER_VERSION_MAINNET; -use crate::core::PEER_VERSION_TESTNET; -use crate::core::{StacksEpoch, StacksEpochId}; +use crate::core::{ + StacksEpoch, StacksEpochId, MINING_COMMITMENT_WINDOW, NETWORK_ID_MAINNET, NETWORK_ID_TESTNET, + PEER_VERSION_MAINNET, PEER_VERSION_TESTNET, STACKS_2_0_LAST_BLOCK_TO_PROCESS, +}; use crate::deps; use crate::monitoring::update_burnchain_height; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::DBTx; -use crate::util_lib::db::Error as db_error; -use stacks_common::address::public_keys_to_address_hash; -use stacks_common::address::AddressHashMode; -use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash as BitcoinSha256dHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; -use stacks_common::util::vrf::VRFPublicKey; -use stacks_common::util::{get_epoch_time_ms, sleep_ms}; - -use crate::burnchains::bitcoin::indexer::BitcoinIndexer; -use crate::chainstate::stacks::boot::POX_2_MAINNET_CODE; -use crate::chainstate::stacks::boot::POX_2_TESTNET_CODE; -use crate::core::STACKS_2_0_LAST_BLOCK_TO_PROCESS; -use stacks_common::types::chainstate::{BurnchainHeaderHash, PoxId}; - -use crate::chainstate::stacks::address::StacksAddressExtensions; +use crate::util_lib::db::{DBConn, DBTx, Error as db_error}; impl BurnchainStateTransitionOps { pub fn noop() -> BurnchainStateTransitionOps { @@ -577,8 +558,7 @@ impl Burnchain { first_block_hash: &BurnchainHeaderHash, ) -> Burnchain { use rand::rngs::ThreadRng; - use rand::thread_rng; - use rand::RngCore; + use rand::{thread_rng, RngCore}; let mut rng = thread_rng(); let mut byte_tail = [0u8; 16]; diff --git a/stackslib/src/burnchains/db.rs b/stackslib/src/burnchains/db.rs index c9f817cb48..e9b9f640b2 100644 --- a/stackslib/src/burnchains/db.rs +++ b/stackslib/src/burnchains/db.rs @@ -14,33 +14,28 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::fmt; - use std::collections::{HashMap, HashSet}; -use std::{cmp, fs, io, path::Path}; +use std::path::Path; +use std::{cmp, fmt, fs, io}; -use rusqlite::{ - types::ToSql, Connection, OpenFlags, OptionalExtension, Row, Transaction, NO_PARAMS, -}; +use rusqlite::types::ToSql; +use rusqlite::{Connection, OpenFlags, OptionalExtension, Row, Transaction, NO_PARAMS}; use serde_json; +use stacks_common::types::chainstate::BurnchainHeaderHash; use crate::burnchains::affirmation::*; -use crate::burnchains::Txid; -use crate::burnchains::{Burnchain, BurnchainBlock, BurnchainBlockHeader, Error as BurnchainError}; -use crate::chainstate::burn::operations::BlockstackOperationType; -use crate::chainstate::burn::operations::LeaderBlockCommitOp; +use crate::burnchains::{ + Burnchain, BurnchainBlock, BurnchainBlockHeader, Error as BurnchainError, Txid, +}; +use crate::chainstate::burn::operations::{BlockstackOperationType, LeaderBlockCommitOp}; use crate::chainstate::burn::BlockSnapshot; -use crate::chainstate::stacks::index::MarfTrieId; +use crate::chainstate::stacks::index::{ClarityMarfTrieId, MarfTrieId}; +use crate::core::StacksEpochId; use crate::util_lib::db::{ opt_u64_to_sql, query_row, query_row_panic, query_rows, sql_pragma, sqlite_open, tx_begin_immediate, tx_busy_handler, u64_to_sql, DBConn, Error as DBError, FromColumn, FromRow, }; -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use stacks_common::types::chainstate::BurnchainHeaderHash; - -use crate::core::StacksEpochId; - pub struct BurnchainDB { conn: Connection, } diff --git a/stackslib/src/burnchains/indexer.rs b/stackslib/src/burnchains/indexer.rs index a53c3286ad..5d8eef99a6 100644 --- a/stackslib/src/burnchains/indexer.rs +++ b/stackslib/src/burnchains/indexer.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::burnchains::BurnchainBlock; -use crate::burnchains::Error as burnchain_error; -use crate::burnchains::*; +use stacks_common::types::chainstate::BurnchainHeaderHash; +use crate::burnchains::{BurnchainBlock, Error as burnchain_error, *}; use crate::core::{StacksEpoch, StacksEpochId}; -use stacks_common::types::chainstate::BurnchainHeaderHash; // IPC messages between threads pub trait BurnHeaderIPC { diff --git a/stackslib/src/burnchains/mod.rs b/stackslib/src/burnchains/mod.rs index 427f30f18b..431629526d 100644 --- a/stackslib/src/burnchains/mod.rs +++ b/stackslib/src/burnchains/mod.rs @@ -17,48 +17,38 @@ use std::collections::HashMap; use std::convert::TryFrom; use std::default::Default; -use std::error; -use std::fmt; -use std::io; use std::marker::PhantomData; +use std::{error, fmt, io}; use rusqlite::Error as sqlite_error; - -use crate::chainstate::burn::distribution::BurnSamplePoint; -use crate::chainstate::burn::operations::leader_block_commit::OUTPUTS_PER_COMMIT; -use crate::chainstate::burn::operations::BlockstackOperationType; -use crate::chainstate::burn::operations::Error as op_error; -use crate::chainstate::burn::operations::LeaderKeyRegisterOp; -use crate::chainstate::stacks::address::PoxAddress; -use crate::chainstate::stacks::boot::POX_3_NAME; -use crate::chainstate::stacks::StacksPublicKey; -use crate::core::*; -use crate::net::neighbors::MAX_NEIGHBOR_BLOCK_DELAY; -use crate::util_lib::db::Error as db_error; use stacks_common::address::AddressHashMode; -use stacks_common::util::hash::Hash160; +use stacks_common::types::chainstate::{ + BurnchainHeaderHash, ConsensusHash, PoxId, StacksAddress, TrieHash, +}; +pub use stacks_common::types::{Address, PrivateKey, PublicKey}; +use stacks_common::util::hash::{Hash160, Sha512Trunc256Sum}; use stacks_common::util::secp256k1::MessageSignature; -use crate::chainstate::stacks::boot::{POX_1_NAME, POX_2_NAME}; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::PoxId; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::TrieHash; - -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::util::hash::Sha512Trunc256Sum; - use self::bitcoin::indexer::{ BITCOIN_MAINNET as BITCOIN_NETWORK_ID_MAINNET, BITCOIN_MAINNET_NAME, BITCOIN_REGTEST as BITCOIN_NETWORK_ID_REGTEST, BITCOIN_REGTEST_NAME, BITCOIN_TESTNET as BITCOIN_NETWORK_ID_TESTNET, BITCOIN_TESTNET_NAME, }; -use self::bitcoin::Error as btc_error; use self::bitcoin::{ BitcoinBlock, BitcoinInputType, BitcoinTransaction, BitcoinTxInput, BitcoinTxOutput, + Error as btc_error, }; - -pub use stacks_common::types::{Address, PrivateKey, PublicKey}; +use crate::chainstate::burn::distribution::BurnSamplePoint; +use crate::chainstate::burn::operations::leader_block_commit::OUTPUTS_PER_COMMIT; +use crate::chainstate::burn::operations::{ + BlockstackOperationType, Error as op_error, LeaderKeyRegisterOp, +}; +use crate::chainstate::stacks::address::PoxAddress; +use crate::chainstate::stacks::boot::{POX_1_NAME, POX_2_NAME, POX_3_NAME}; +use crate::chainstate::stacks::StacksPublicKey; +use crate::core::*; +use crate::net::neighbors::MAX_NEIGHBOR_BLOCK_DELAY; +use crate::util_lib::db::Error as db_error; /// This module contains drivers and types for all burn chains we support. pub mod affirmation; @@ -696,8 +686,7 @@ impl BurnchainView { ret.insert(i, self.burn_block_hash.clone()); } else { let data = { - use sha2::Digest; - use sha2::Sha256; + use sha2::{Digest, Sha256}; let mut hasher = Sha256::new(); hasher.update(&i.to_le_bytes()); hasher.finalize() diff --git a/stackslib/src/burnchains/tests/affirmation.rs b/stackslib/src/burnchains/tests/affirmation.rs index b5cbc61aee..27de7113a7 100644 --- a/stackslib/src/burnchains/tests/affirmation.rs +++ b/stackslib/src/burnchains/tests/affirmation.rs @@ -15,52 +15,41 @@ // along with this program. If not, see . use std::cmp; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::sync::{ - atomic::{AtomicBool, AtomicU64, Ordering}, - mpsc::sync_channel, - Arc, RwLock, -}; - +use std::collections::{HashSet, VecDeque}; +use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::sync::mpsc::sync_channel; +use std::sync::{Arc, RwLock}; + +use clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; +use clarity::vm::Value; use rusqlite::Connection; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksAddress, StacksBlockId, VRFSeed, +}; +use stacks_common::util::hash::{hex_bytes, Hash160}; +use stacks_common::util::vrf::*; +use stacks_common::{address, types, util}; use crate::burnchains::affirmation::*; use crate::burnchains::bitcoin::address::{BitcoinAddress, LegacyBitcoinAddress}; use crate::burnchains::bitcoin::indexer::BitcoinIndexer; use crate::burnchains::bitcoin::BitcoinNetworkType; +use crate::burnchains::db::*; use crate::burnchains::tests::db::*; -use crate::burnchains::{db::*, *}; -use crate::burnchains::{BurnchainBlock, BurnchainBlockHeader, Txid}; -use crate::chainstate; +use crate::burnchains::{BurnchainBlock, BurnchainBlockHeader, Txid, *}; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::burn::operations::leader_block_commit::*; use crate::chainstate::burn::operations::*; use crate::chainstate::burn::*; +use crate::chainstate::coordinator::tests::*; use crate::chainstate::coordinator::{Error as CoordError, *}; +use crate::chainstate::stacks::address::StacksAddressExtensions; use crate::chainstate::stacks::*; use crate::clarity_vm::clarity::ClarityConnection; -use crate::core; use crate::core::*; use crate::monitoring::increment_stx_blocks_processed_counter; -use clarity::vm::{ - costs::{ExecutionCost, LimitedCostTracker}, - types::PrincipalData, - types::QualifiedContractIdentifier, - Value, -}; -use stacks_common::address; -use stacks_common::util::hash::{hex_bytes, Hash160}; -use stacks_common::util::vrf::*; - -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksAddress, VRFSeed, -}; -use stacks_common::{types, util}; - -use crate::chainstate::coordinator::tests::*; -use crate::chainstate::stacks::address::StacksAddressExtensions; +use crate::{chainstate, core}; #[test] fn affirmation_map_encode_decode() { diff --git a/stackslib/src/burnchains/tests/burnchain.rs b/stackslib/src/burnchains/tests/burnchain.rs index 8c6b1fe265..acead0710d 100644 --- a/stackslib/src/burnchains/tests/burnchain.rs +++ b/stackslib/src/burnchains/tests/burnchain.rs @@ -14,47 +14,38 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::chainstate::burn::ConsensusHashExtensions; -use crate::chainstate::stacks::address::StacksAddressExtensions; -use crate::chainstate::stacks::index::TrieHashExtension; use ed25519_dalek::Keypair as VRFKeypair; use rand::rngs::ThreadRng; use rand::thread_rng; use serde::Serialize; use sha2::Sha512; +use stacks_common::address::AddressHashMode; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksAddress, TrieHash, VRFSeed, +}; +use stacks_common::util::hash::{hex_bytes, to_hex, Hash160}; +use stacks_common::util::secp256k1::Secp256k1PrivateKey; +use stacks_common::util::uint::{BitArray, Uint256, Uint512}; +use stacks_common::util::vrf::{VRFPrivateKey, VRFPublicKey}; +use stacks_common::util::{get_epoch_time_secs, log}; use crate::burnchains::bitcoin::address::*; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; use crate::burnchains::bitcoin::*; -use crate::burnchains::Txid; -use crate::burnchains::*; +use crate::burnchains::{Txid, *}; use crate::chainstate::burn::db::sortdb::{SortitionDB, SortitionHandleTx}; use crate::chainstate::burn::distribution::BurnSamplePoint; +use crate::chainstate::burn::operations::leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS; use crate::chainstate::burn::operations::{ - leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS, BlockstackOperationType, LeaderBlockCommitOp, - LeaderKeyRegisterOp, UserBurnSupportOp, + BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, UserBurnSupportOp, +}; +use crate::chainstate::burn::{ + BlockSnapshot, ConsensusHash, ConsensusHashExtensions, OpsHash, SortitionHash, }; -use crate::chainstate::burn::{BlockSnapshot, ConsensusHash, OpsHash, SortitionHash}; +use crate::chainstate::stacks::address::StacksAddressExtensions; +use crate::chainstate::stacks::index::TrieHashExtension; use crate::chainstate::stacks::StacksPublicKey; use crate::util_lib::db::Error as db_error; -use stacks_common::address::AddressHashMode; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::hex_bytes; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Hash160; -use stacks_common::util::log; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::uint::BitArray; -use stacks_common::util::uint::Uint256; -use stacks_common::util::uint::Uint512; -use stacks_common::util::vrf::VRFPrivateKey; -use stacks_common::util::vrf::VRFPublicKey; - -use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, VRFSeed, -}; #[test] fn test_process_block_ops() { diff --git a/stackslib/src/burnchains/tests/db.rs b/stackslib/src/burnchains/tests/db.rs index b6829929d4..77e2420ea8 100644 --- a/stackslib/src/burnchains/tests/db.rs +++ b/stackslib/src/burnchains/tests/db.rs @@ -14,32 +14,29 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::chainstate::stacks::address::StacksAddressExtensions; use std::cmp; use std::convert::TryInto; +use stacks_common::address::AddressHashMode; +use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction as BtcTx; +use stacks_common::deps_common::bitcoin::network::serialize::deserialize; +use stacks_common::types::chainstate::StacksAddress; +use stacks_common::util::hash::*; + +use super::*; use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::bitcoin::address::*; use crate::burnchains::bitcoin::blocks::*; use crate::burnchains::bitcoin::*; -use crate::burnchains::PoxConstants; -use crate::burnchains::BLOCKSTACK_MAGIC_MAINNET; +use crate::burnchains::{PoxConstants, BLOCKSTACK_MAGIC_MAINNET}; use crate::chainstate::burn::operations::leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS; use crate::chainstate::burn::*; use crate::chainstate::coordinator::tests::next_txid; -use crate::chainstate::stacks::address::PoxAddress; +use crate::chainstate::stacks::address::{PoxAddress, StacksAddressExtensions}; use crate::chainstate::stacks::index::ClarityMarfTrieId; use crate::chainstate::stacks::*; -use crate::core::StacksEpochId; -use crate::core::BITCOIN_REGTEST_FIRST_BLOCK_HASH; +use crate::core::{StacksEpochId, BITCOIN_REGTEST_FIRST_BLOCK_HASH}; use crate::util_lib::db::Error as DBError; -use stacks_common::address::AddressHashMode; -use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction as BtcTx; -use stacks_common::deps_common::bitcoin::network::serialize::deserialize; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::util::hash::*; - -use super::*; impl BurnchainHeaderReader for Vec { fn read_burnchain_headers( diff --git a/stackslib/src/burnchains/tests/mod.rs b/stackslib/src/burnchains/tests/mod.rs index a2e15aab33..b635b97107 100644 --- a/stackslib/src/burnchains/tests/mod.rs +++ b/stackslib/src/burnchains/tests/mod.rs @@ -20,31 +20,27 @@ pub mod db; use std::collections::HashMap; +use stacks_common::address::*; +use stacks_common::types::chainstate::{BlockHeaderHash, SortitionId, VRFSeed}; +use stacks_common::util::get_epoch_time_secs; +use stacks_common::util::hash::*; +use stacks_common::util::secp256k1::*; +use stacks_common::util::vrf::*; + +use super::*; use crate::burnchains::bitcoin::indexer::BitcoinIndexer; use crate::burnchains::db::*; -use crate::burnchains::Burnchain; -use crate::burnchains::*; +use crate::burnchains::{Burnchain, *}; use crate::chainstate::burn::db::sortdb::*; -use crate::chainstate::burn::operations::BlockstackOperationType; -use crate::chainstate::burn::operations::*; +use crate::chainstate::burn::operations::{BlockstackOperationType, *}; use crate::chainstate::burn::*; use crate::chainstate::coordinator::comm::*; use crate::chainstate::coordinator::*; use crate::chainstate::stacks::*; use crate::core::STACKS_EPOCH_2_1_MARKER; use crate::cost_estimates::{CostEstimator, FeeEstimator}; -use crate::util_lib::db::*; -use stacks_common::address::*; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::*; -use stacks_common::util::secp256k1::*; -use stacks_common::util::vrf::*; - -use stacks_common::types::chainstate::{BlockHeaderHash, SortitionId, VRFSeed}; - use crate::stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; - -use super::*; +use crate::util_lib::db::*; // all SPV headers will have this timestamp, so that multiple burnchain nodes will always have the // same SPV header timestamps regardless of when they are instantiated. diff --git a/stackslib/src/chainstate/burn/db/mod.rs b/stackslib/src/chainstate/burn/db/mod.rs index c36807243a..78bacdedf8 100644 --- a/stackslib/src/chainstate/burn/db/mod.rs +++ b/stackslib/src/chainstate/burn/db/mod.rs @@ -14,13 +14,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::error; -use std::fmt; +use std::{error, fmt}; -use rusqlite::Connection; -use rusqlite::Error as sqlite_error; -use rusqlite::Row; +use rusqlite::{Connection, Error as sqlite_error, Row}; use serde_json::Error as serde_error; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, TrieHash, VRFSeed, +}; +use stacks_common::util::hash::{hex_bytes, Hash160, Sha512Trunc256Sum}; +use stacks_common::util::secp256k1::MessageSignature; +use stacks_common::util::vrf::*; use crate::burnchains::bitcoin::address::BitcoinAddress; use crate::burnchains::{Address, Txid}; @@ -28,15 +31,7 @@ use crate::chainstate::burn::{ConsensusHash, OpsHash, SortitionHash}; use crate::chainstate::stacks::address::PoxAddress; use crate::chainstate::stacks::StacksPublicKey; use crate::util_lib::db; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::FromColumn; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::util::hash::{hex_bytes, Hash160, Sha512Trunc256Sum}; -use stacks_common::util::secp256k1::MessageSignature; -use stacks_common::util::vrf::*; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, VRFSeed}; +use crate::util_lib::db::{Error as db_error, FromColumn}; pub mod processing; pub mod sortdb; diff --git a/stackslib/src/chainstate/burn/db/processing.rs b/stackslib/src/chainstate/burn/db/processing.rs index 544396ab0a..bf1e83efd9 100644 --- a/stackslib/src/chainstate/burn/db/processing.rs +++ b/stackslib/src/chainstate/burn/db/processing.rs @@ -17,27 +17,23 @@ along with Blockstack. If not, see . */ +use stacks_common::address::AddressHashMode; +use stacks_common::types::chainstate::{BurnchainHeaderHash, PoxId, SortitionId, TrieHash}; + use crate::burnchains::{ Burnchain, BurnchainBlockHeader, BurnchainStateTransition, Error as BurnchainError, }; -use crate::chainstate::burn::db::sortdb::SortitionDB; -use crate::chainstate::burn::db::sortdb::{InitialMiningBonus, SortitionHandleTx}; -use crate::chainstate::burn::operations::{ - leader_block_commit::{MissedBlockCommit, RewardSetInfo}, - BlockstackOperationType, Error as OpError, -}; +use crate::chainstate::burn::db::sortdb::{InitialMiningBonus, SortitionDB, SortitionHandleTx}; +use crate::chainstate::burn::operations::leader_block_commit::{MissedBlockCommit, RewardSetInfo}; +use crate::chainstate::burn::operations::{BlockstackOperationType, Error as OpError}; use crate::chainstate::burn::BlockSnapshot; use crate::chainstate::coordinator::RewardCycleInfo; use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::index::{ - marf::MARF, storage::TrieFileStorage, Error as MARFError, MARFValue, MarfTrieId, -}; +use crate::chainstate::stacks::index::marf::MARF; +use crate::chainstate::stacks::index::storage::TrieFileStorage; +use crate::chainstate::stacks::index::{Error as MARFError, MARFValue, MarfTrieId}; use crate::core::INITIAL_MINING_BONUS_WINDOW; use crate::util_lib::db::Error as DBError; -use stacks_common::address::AddressHashMode; - -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{BurnchainHeaderHash, PoxId, SortitionId}; impl<'a> SortitionHandleTx<'a> { /// Run a blockstack operation's "check()" method and return the result. @@ -367,22 +363,23 @@ impl<'a> SortitionHandleTx<'a> { #[cfg(test)] mod tests { - use crate::burnchains::bitcoin::{address::BitcoinAddress, BitcoinNetworkType}; + use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, VRFSeed}; + use stacks_common::util::hash::hex_bytes; + use stacks_common::util::vrf::VRFPublicKey; + + use super::*; + use crate::burnchains::bitcoin::address::BitcoinAddress; + use crate::burnchains::bitcoin::BitcoinNetworkType; use crate::burnchains::*; - use crate::chainstate::burn::db::sortdb::{tests::test_append_snapshot, SortitionDB}; - use crate::chainstate::burn::operations::{ - leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS, LeaderBlockCommitOp, LeaderKeyRegisterOp, - }; + use crate::chainstate::burn::db::sortdb::tests::test_append_snapshot; + use crate::chainstate::burn::db::sortdb::SortitionDB; + use crate::chainstate::burn::operations::leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS; + use crate::chainstate::burn::operations::{LeaderBlockCommitOp, LeaderKeyRegisterOp}; use crate::chainstate::burn::*; use crate::chainstate::stacks::address::StacksAddressExtensions; use crate::chainstate::stacks::index::TrieHashExtension; use crate::chainstate::stacks::StacksPublicKey; use crate::core::MICROSTACKS_PER_STACKS; - use stacks_common::util::{hash::hex_bytes, vrf::VRFPublicKey}; - - use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, VRFSeed}; - - use super::*; #[test] fn test_initial_block_reward() { diff --git a/stackslib/src/chainstate/burn/db/sortdb.rs b/stackslib/src/chainstate/burn/db/sortdb.rs index ec1df4ad55..4c63a28968 100644 --- a/stackslib/src/chainstate/burn/db/sortdb.rs +++ b/stackslib/src/chainstate/burn/db/sortdb.rs @@ -14,88 +14,76 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::cmp::Ord; -use std::cmp::Ordering; +use std::cmp::{Ord, Ordering}; use std::collections::{HashMap, HashSet}; use std::convert::{From, TryFrom, TryInto}; use std::io::{ErrorKind, Write}; -use std::ops::Deref; -use std::ops::DerefMut; -use std::{cmp, fmt, fs, str::FromStr}; +use std::ops::{Deref, DerefMut}; +use std::str::FromStr; +use std::{cmp, fmt, fs}; +use clarity::vm::ast::ASTRules; use clarity::vm::costs::ExecutionCost; +use clarity::vm::representations::{ClarityName, ContractName}; +use clarity::vm::types::Value; use rand; use rand::RngCore; use rusqlite::types::ToSql; -use rusqlite::Row; -use rusqlite::Transaction; -use rusqlite::TransactionBehavior; -use rusqlite::{Connection, OpenFlags, OptionalExtension, NO_PARAMS}; +use rusqlite::{ + Connection, OpenFlags, OptionalExtension, Row, Transaction, TransactionBehavior, NO_PARAMS, +}; use sha2::{Digest, Sha512_256}; +use stacks_common::address::AddressHashMode; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksAddress, StacksBlockId, + TrieHash, VRFSeed, +}; +use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, Sha512Trunc256Sum}; +use stacks_common::util::secp256k1::MessageSignature; +use stacks_common::util::vrf::*; +use stacks_common::util::{get_epoch_time_secs, log}; use crate::burnchains::affirmation::{AffirmationMap, AffirmationMapEntry}; use crate::burnchains::bitcoin::BitcoinNetworkType; use crate::burnchains::db::{BurnchainDB, BurnchainHeaderReader}; -use crate::burnchains::{Address, PublicKey, Txid}; use crate::burnchains::{ - Burnchain, BurnchainBlockHeader, BurnchainRecipient, BurnchainStateTransition, + Address, Burnchain, BurnchainBlockHeader, BurnchainRecipient, BurnchainStateTransition, BurnchainStateTransitionOps, BurnchainTransaction, BurnchainView, Error as BurnchainError, - PoxConstants, + PoxConstants, PublicKey, Txid, +}; +use crate::chainstate::burn::operations::leader_block_commit::{ + MissedBlockCommit, RewardSetInfo, OUTPUTS_PER_COMMIT, }; -use crate::chainstate::burn::operations::DelegateStxOp; use crate::chainstate::burn::operations::{ - leader_block_commit::{MissedBlockCommit, RewardSetInfo, OUTPUTS_PER_COMMIT}, - BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, PreStxOp, StackStxOp, - TransferStxOp, UserBurnSupportOp, + BlockstackOperationType, DelegateStxOp, LeaderBlockCommitOp, LeaderKeyRegisterOp, PreStxOp, + StackStxOp, TransferStxOp, UserBurnSupportOp, +}; +use crate::chainstate::burn::{ + BlockSnapshot, ConsensusHash, ConsensusHashExtensions, Opcodes, OpsHash, SortitionHash, }; -use crate::chainstate::burn::Opcodes; -use crate::chainstate::burn::{BlockSnapshot, ConsensusHash, OpsHash, SortitionHash}; use crate::chainstate::coordinator::{ Error as CoordinatorError, PoxAnchorBlockStatus, RewardCycleInfo, }; -use crate::chainstate::stacks::address::PoxAddress; +use crate::chainstate::stacks::address::{PoxAddress, StacksAddressExtensions}; use crate::chainstate::stacks::boot::PoxStartCycleInfo; use crate::chainstate::stacks::db::{StacksChainState, StacksHeaderInfo}; -use crate::chainstate::stacks::index::marf::MARFOpenOpts; -use crate::chainstate::stacks::index::marf::MarfConnection; -use crate::chainstate::stacks::index::marf::MARF; +use crate::chainstate::stacks::index::marf::{MARFOpenOpts, MarfConnection, MARF}; use crate::chainstate::stacks::index::storage::TrieFileStorage; -use crate::chainstate::stacks::index::{Error as MARFError, MarfTrieId}; -use crate::chainstate::stacks::StacksPublicKey; -use crate::chainstate::stacks::*; +use crate::chainstate::stacks::index::{ + ClarityMarfTrieId, Error as MARFError, MARFValue, MarfTrieId, +}; +use crate::chainstate::stacks::{StacksPublicKey, *}; use crate::chainstate::ChainstateDB; -use crate::core::AST_RULES_PRECHECK_SIZE; -use crate::core::FIRST_BURNCHAIN_CONSENSUS_HASH; -use crate::core::FIRST_STACKS_BLOCK_HASH; -use crate::core::{StacksEpoch, StacksEpochExtension, StacksEpochId, STACKS_EPOCH_MAX}; +use crate::core::{ + StacksEpoch, StacksEpochExtension, StacksEpochId, AST_RULES_PRECHECK_SIZE, + FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, STACKS_EPOCH_MAX, +}; use crate::net::neighbors::MAX_NEIGHBOR_BLOCK_DELAY; use crate::net::{Error as NetError, Error}; -use crate::util_lib::db::tx_begin_immediate; -use crate::util_lib::db::tx_busy_handler; -use crate::util_lib::db::DBTx; -use crate::util_lib::db::Error as db_error; use crate::util_lib::db::{ db_mkdirs, opt_u64_to_sql, query_count, query_row, query_row_columns, query_row_panic, - query_rows, sql_pragma, u64_to_sql, DBConn, FromColumn, FromRow, IndexDBConn, IndexDBTx, -}; -use clarity::vm::ast::ASTRules; -use clarity::vm::representations::{ClarityName, ContractName}; -use clarity::vm::types::Value; - -use stacks_common::address::AddressHashMode; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, Sha512Trunc256Sum}; -use stacks_common::util::log; -use stacks_common::util::secp256k1::MessageSignature; -use stacks_common::util::vrf::*; - -use crate::chainstate::burn::ConsensusHashExtensions; -use crate::chainstate::stacks::address::StacksAddressExtensions; -use crate::chainstate::stacks::index::{ClarityMarfTrieId, MARFValue}; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksBlockId, VRFSeed, + query_rows, sql_pragma, tx_begin_immediate, tx_busy_handler, u64_to_sql, DBConn, DBTx, + Error as db_error, FromColumn, FromRow, IndexDBConn, IndexDBTx, }; const BLOCK_HEIGHT_MAX: u64 = ((1 as u64) << 63) - 1; @@ -5816,35 +5804,31 @@ impl ChainstateDB for SortitionDB { #[cfg(test)] pub mod tests { - use crate::chainstate::stacks::index::TrieHashExtension; - use crate::core::StacksEpochExtension; use std::sync::mpsc::sync_channel; use std::thread; + use stacks_common::address::AddressHashMode; + use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, VRFSeed}; + use stacks_common::util::get_epoch_time_secs; + use stacks_common::util::hash::{hex_bytes, Hash160}; + use stacks_common::util::vrf::*; + + use super::*; + use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::bitcoin::address::BitcoinAddress; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; use crate::burnchains::bitcoin::BitcoinNetworkType; + use crate::burnchains::tests::affirmation::{make_reward_cycle, make_simple_key_register}; use crate::burnchains::*; + use crate::chainstate::burn::operations::leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS; use crate::chainstate::burn::operations::{ - leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS, BlockstackOperationType, - LeaderBlockCommitOp, LeaderKeyRegisterOp, UserBurnSupportOp, + BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, UserBurnSupportOp, }; use crate::chainstate::burn::ConsensusHash; + use crate::chainstate::stacks::index::TrieHashExtension; use crate::chainstate::stacks::StacksPublicKey; - use crate::core::*; + use crate::core::{StacksEpochExtension, *}; use crate::util_lib::db::Error as db_error; - use stacks_common::address::AddressHashMode; - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::hash::{hex_bytes, Hash160}; - use stacks_common::util::vrf::*; - - use stacks_common::types::chainstate::StacksAddress; - use stacks_common::types::chainstate::{BlockHeaderHash, VRFSeed}; - - use crate::burnchains::affirmation::AffirmationMap; - use crate::burnchains::tests::affirmation::{make_reward_cycle, make_simple_key_register}; - - use super::*; #[test] fn test_instantiate() { diff --git a/stackslib/src/chainstate/burn/distribution.rs b/stackslib/src/chainstate/burn/distribution.rs index 223b88374e..8e76950d3a 100644 --- a/stackslib/src/chainstate/burn/distribution.rs +++ b/stackslib/src/chainstate/burn/distribution.rs @@ -18,25 +18,22 @@ use std::cmp; use std::collections::{BTreeMap, HashMap}; use std::convert::TryInto; -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::PublicKey; -use crate::burnchains::Txid; -use crate::burnchains::{BurnchainRecipient, BurnchainSigner, BurnchainTransaction}; +use stacks_common::address::AddressHashMode; +use stacks_common::util::hash::Hash160; +use stacks_common::util::log; +use stacks_common::util::uint::{BitArray, Uint256, Uint512}; +use stacks_common::util::vrf::VRFPublicKey; + +use crate::burnchains::{ + Address, Burnchain, BurnchainRecipient, BurnchainSigner, BurnchainTransaction, PublicKey, Txid, +}; +use crate::chainstate::burn::operations::leader_block_commit::MissedBlockCommit; use crate::chainstate::burn::operations::{ - leader_block_commit::MissedBlockCommit, BlockstackOperationType, LeaderBlockCommitOp, - LeaderKeyRegisterOp, UserBurnSupportOp, + BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, UserBurnSupportOp, }; use crate::chainstate::stacks::StacksPublicKey; use crate::core::MINING_COMMITMENT_WINDOW; use crate::monitoring; -use stacks_common::address::AddressHashMode; -use stacks_common::util::hash::Hash160; -use stacks_common::util::log; -use stacks_common::util::uint::BitArray; -use stacks_common::util::uint::Uint256; -use stacks_common::util::uint::Uint512; -use stacks_common::util::vrf::VRFPublicKey; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct BurnSamplePoint { @@ -405,16 +402,26 @@ impl BurnSamplePoint { #[cfg(test)] mod tests { + use std::marker::PhantomData; + + use stacks_common::address::AddressHashMode; + use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksAddress, VRFSeed, + }; + use stacks_common::util::hash::{hex_bytes, Hash160}; + use stacks_common::util::log; + use stacks_common::util::uint::{BitArray, Uint256, Uint512}; + use stacks_common::util::vrf::*; + + use super::BurnSamplePoint; use crate::burnchains::bitcoin::address::BitcoinAddress; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; use crate::burnchains::bitcoin::BitcoinNetworkType; - use crate::burnchains::Address; - use crate::burnchains::Burnchain; - use crate::burnchains::BurnchainSigner; - use crate::burnchains::PublicKey; - use crate::burnchains::Txid; + use crate::burnchains::{Address, Burnchain, BurnchainSigner, PublicKey, Txid}; + use crate::chainstate::burn::operations::leader_block_commit::{ + MissedBlockCommit, BURN_BLOCK_MINED_AT_MODULUS, + }; use crate::chainstate::burn::operations::{ - leader_block_commit::{MissedBlockCommit, BURN_BLOCK_MINED_AT_MODULUS}, BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, UserBurnSupportOp, }; use crate::chainstate::burn::ConsensusHash; @@ -422,21 +429,6 @@ mod tests { use crate::chainstate::stacks::index::TrieHashExtension; use crate::chainstate::stacks::StacksPublicKey; use crate::core::MINING_COMMITMENT_WINDOW; - use stacks_common::address::AddressHashMode; - use stacks_common::types::chainstate::StacksAddress; - use stacks_common::util::hash::hex_bytes; - use stacks_common::util::hash::Hash160; - use stacks_common::util::log; - use stacks_common::util::uint::BitArray; - use stacks_common::util::uint::Uint256; - use stacks_common::util::uint::Uint512; - use stacks_common::util::vrf::*; - use std::marker::PhantomData; - - use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash}; - use stacks_common::types::chainstate::{SortitionId, VRFSeed}; - - use super::BurnSamplePoint; struct BurnDistFixture { consumed_leader_keys: Vec, diff --git a/stackslib/src/chainstate/burn/mod.rs b/stackslib/src/chainstate/burn/mod.rs index cad79db79c..0ab14b982b 100644 --- a/stackslib/src/chainstate/burn/mod.rs +++ b/stackslib/src/chainstate/burn/mod.rs @@ -19,33 +19,24 @@ use std::fmt; use std::io::Write; use rand::seq::index::sample; -use rand::Rng; -use rand::SeedableRng; +use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha20Rng; use ripemd::Ripemd160; -use rusqlite::Connection; -use rusqlite::Transaction; +use rusqlite::{Connection, Transaction}; use sha2::Sha256; - -use crate::burnchains::Address; -use crate::burnchains::PublicKey; -use crate::burnchains::Txid; -use crate::chainstate::burn::db::sortdb::SortitionHandleTx; -use crate::core::SYSTEM_FORK_SET_VERSION; -use crate::util_lib::db::Error as db_error; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::util::hash::Hash32; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::hash::{to_hex, Hash160}; +pub use stacks_common::types::chainstate::ConsensusHash; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, TrieHash, VRFSeed, +}; +use stacks_common::util::hash::{to_hex, Hash160, Hash32, Sha512Trunc256Sum}; use stacks_common::util::log; use stacks_common::util::uint::Uint256; use stacks_common::util::vrf::VRFProof; -use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, VRFSeed, -}; - -pub use stacks_common::types::chainstate::ConsensusHash; +use crate::burnchains::{Address, PublicKey, Txid}; +use crate::chainstate::burn::db::sortdb::SortitionHandleTx; +use crate::core::SYSTEM_FORK_SET_VERSION; +use crate::util_lib::db::Error as db_error; /// This module contains the code for processing the burn chain state database pub mod db; @@ -387,19 +378,17 @@ impl ConsensusHashExtensions for ConsensusHash { #[cfg(test)] mod tests { + use rusqlite::Connection; + use stacks_common::types::chainstate::BurnchainHeaderHash; + use stacks_common::util::hash::{hex_bytes, Hash160}; + use stacks_common::util::{get_epoch_time_secs, log}; + + use super::*; use crate::burnchains::bitcoin::address::BitcoinAddress; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; use crate::chainstate::burn::db::sortdb::*; use crate::chainstate::stacks::index::TrieHashExtension; use crate::util_lib::db::Error as db_error; - use rusqlite::Connection; - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::hash::{hex_bytes, Hash160}; - use stacks_common::util::log; - - use stacks_common::types::chainstate::BurnchainHeaderHash; - - use super::*; #[test] fn get_prev_consensus_hashes() { diff --git a/stackslib/src/chainstate/burn/operations/delegate_stx.rs b/stackslib/src/chainstate/burn/operations/delegate_stx.rs index 7915c5c11b..9f6a47a8fa 100644 --- a/stackslib/src/chainstate/burn/operations/delegate_stx.rs +++ b/stackslib/src/chainstate/burn/operations/delegate_stx.rs @@ -1,15 +1,15 @@ -use crate::burnchains::BurnchainTransaction; -use crate::burnchains::{BurnchainBlockHeader, Txid}; -use crate::chainstate::burn::operations::Error as op_error; +use std::io::{Read, Write}; + +use stacks_common::codec::{write_next, Error as codec_error, StacksMessageCodec}; +use stacks_common::types::chainstate::{BurnchainHeaderHash, StacksAddress}; + +use crate::burnchains::{BurnchainBlockHeader, BurnchainTransaction, Txid}; use crate::chainstate::burn::operations::{ parse_u128_from_be, parse_u32_from_be, parse_u64_from_be, BlockstackOperationType, - DelegateStxOp, PreStxOp, + DelegateStxOp, Error as op_error, PreStxOp, }; use crate::chainstate::burn::Opcodes; use crate::chainstate::stacks::address::PoxAddress; -use stacks_common::codec::{write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::{BurnchainHeaderHash, StacksAddress}; -use std::io::{Read, Write}; struct ParsedData { delegated_ustx: u128, @@ -260,24 +260,21 @@ impl StacksMessageCodec for DelegateStxOp { } mod tests { + use stacks_common::address::AddressHashMode; + use stacks_common::types::chainstate::{BurnchainHeaderHash, StacksAddress}; + use stacks_common::util::hash::*; + use crate::burnchains::bitcoin::address::{ BitcoinAddress, LegacyBitcoinAddress, LegacyBitcoinAddressType, }; - use crate::burnchains::bitcoin::BitcoinTxInputStructured; use crate::burnchains::bitcoin::{ - BitcoinInputType, BitcoinNetworkType, BitcoinTxInput, BitcoinTxOutput, + BitcoinInputType, BitcoinNetworkType, BitcoinTransaction, BitcoinTxInput, + BitcoinTxInputStructured, BitcoinTxOutput, }; - use crate::burnchains::BurnchainTransaction; - use crate::burnchains::{bitcoin::BitcoinTransaction, Txid}; - use crate::chainstate::burn::operations::DelegateStxOp; - use crate::chainstate::burn::operations::Error as op_error; + use crate::burnchains::{BurnchainTransaction, Txid}; + use crate::chainstate::burn::operations::{DelegateStxOp, Error as op_error}; use crate::chainstate::burn::Opcodes; - use crate::chainstate::stacks::address::PoxAddress; - use crate::chainstate::stacks::address::StacksAddressExtensions; - use stacks_common::address::AddressHashMode; - use stacks_common::types::chainstate::BurnchainHeaderHash; - use stacks_common::types::chainstate::StacksAddress; - use stacks_common::util::hash::*; + use crate::chainstate::stacks::address::{PoxAddress, StacksAddressExtensions}; // Parse a DelegateStx op in which the height is set to None. #[test] diff --git a/stackslib/src/chainstate/burn/operations/leader_block_commit.rs b/stackslib/src/chainstate/burn/operations/leader_block_commit.rs index b7f32fd007..df84034b52 100644 --- a/stackslib/src/chainstate/burn/operations/leader_block_commit.rs +++ b/stackslib/src/chainstate/burn/operations/leader_block_commit.rs @@ -16,43 +16,35 @@ use std::io::{Read, Write}; -use crate::burnchains::bitcoin::BitcoinNetworkType; -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainBlockHeader; -use crate::burnchains::PoxConstants; -use crate::burnchains::Txid; -use crate::burnchains::{BurnchainRecipient, BurnchainSigner}; -use crate::burnchains::{BurnchainTransaction, PublicKey}; -use crate::chainstate::burn::db::sortdb::SortitionHandle; -use crate::chainstate::burn::db::sortdb::{SortitionDB, SortitionHandleTx}; -use crate::chainstate::burn::operations::Error as op_error; -use crate::chainstate::burn::operations::{ - parse_u16_from_be, parse_u32_from_be, BlockstackOperationType, LeaderBlockCommitOp, - LeaderKeyRegisterOp, UserBurnSupportOp, -}; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::burn::Opcodes; -use crate::chainstate::burn::SortitionId; -use crate::chainstate::stacks::address::PoxAddress; -use crate::chainstate::stacks::index::storage::TrieFileStorage; -use crate::chainstate::stacks::{StacksPrivateKey, StacksPublicKey}; -use crate::core::STACKS_EPOCH_2_2_MARKER; -use crate::core::STACKS_EPOCH_2_3_MARKER; -use crate::core::STACKS_EPOCH_2_4_MARKER; -use crate::core::{StacksEpoch, StacksEpochId}; -use crate::core::{STACKS_EPOCH_2_05_MARKER, STACKS_EPOCH_2_1_MARKER}; -use crate::net::Error as net_error; use stacks_common::address::AddressHashMode; use stacks_common::codec::{write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::TrieHash; use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, StacksAddress, VRFSeed, + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, TrieHash, VRFSeed, }; use stacks_common::util::hash::to_hex; use stacks_common::util::log; use stacks_common::util::vrf::{VRFPrivateKey, VRFPublicKey, VRF}; +use crate::burnchains::bitcoin::BitcoinNetworkType; +use crate::burnchains::{ + Address, Burnchain, BurnchainBlockHeader, BurnchainRecipient, BurnchainSigner, + BurnchainTransaction, PoxConstants, PublicKey, Txid, +}; +use crate::chainstate::burn::db::sortdb::{SortitionDB, SortitionHandle, SortitionHandleTx}; +use crate::chainstate::burn::operations::{ + parse_u16_from_be, parse_u32_from_be, BlockstackOperationType, Error as op_error, + LeaderBlockCommitOp, LeaderKeyRegisterOp, UserBurnSupportOp, +}; +use crate::chainstate::burn::{ConsensusHash, Opcodes, SortitionId}; +use crate::chainstate::stacks::address::PoxAddress; +use crate::chainstate::stacks::index::storage::TrieFileStorage; +use crate::chainstate::stacks::{StacksPrivateKey, StacksPublicKey}; +use crate::core::{ + StacksEpoch, StacksEpochId, STACKS_EPOCH_2_05_MARKER, STACKS_EPOCH_2_1_MARKER, + STACKS_EPOCH_2_2_MARKER, STACKS_EPOCH_2_3_MARKER, STACKS_EPOCH_2_4_MARKER, +}; +use crate::net::Error as net_error; + // return type from parse_data below struct ParsedData { block_header_hash: BlockHeaderHash, @@ -1029,6 +1021,17 @@ impl LeaderBlockCommitOp { #[cfg(test)] mod tests { + use clarity::vm::costs::ExecutionCost; + use rand::{thread_rng, RngCore}; + use stacks_common::address::AddressHashMode; + use stacks_common::deps_common::bitcoin::blockdata::transaction::{Transaction, TxOut}; + use stacks_common::deps_common::bitcoin::network::serialize::{deserialize, serialize_hex}; + use stacks_common::types::chainstate::{BlockHeaderHash, SortitionId, StacksAddress, VRFSeed}; + use stacks_common::util::get_epoch_time_secs; + use stacks_common::util::hash::*; + use stacks_common::util::vrf::VRFPublicKey; + + use super::*; use crate::burnchains::bitcoin::address::*; use crate::burnchains::bitcoin::blocks::BitcoinBlockParser; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; @@ -1038,33 +1041,14 @@ mod tests { use crate::chainstate::burn::db::sortdb::*; use crate::chainstate::burn::db::*; use crate::chainstate::burn::operations::*; - use crate::chainstate::burn::ConsensusHash; - use crate::chainstate::burn::*; + use crate::chainstate::burn::{ConsensusHash, *}; use crate::chainstate::stacks::address::StacksAddressExtensions; use crate::chainstate::stacks::index::TrieHashExtension; use crate::chainstate::stacks::StacksPublicKey; use crate::core::{ - StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, - PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, STACKS_EPOCH_MAX, + StacksEpoch, StacksEpochExtension, StacksEpochId, PEER_VERSION_EPOCH_1_0, + PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, STACKS_EPOCH_MAX, }; - use stacks_common::address::AddressHashMode; - use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; - use stacks_common::deps_common::bitcoin::blockdata::transaction::TxOut; - use stacks_common::deps_common::bitcoin::network::serialize::{deserialize, serialize_hex}; - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::hash::*; - use stacks_common::util::vrf::VRFPublicKey; - - use stacks_common::types::chainstate::StacksAddress; - use stacks_common::types::chainstate::{BlockHeaderHash, SortitionId, VRFSeed}; - - use super::*; - - use clarity::vm::costs::ExecutionCost; - use rand::thread_rng; - use rand::RngCore; - - use crate::core::StacksEpochExtension; struct OpFixture { txstr: String, diff --git a/stackslib/src/chainstate/burn/operations/leader_key_register.rs b/stackslib/src/chainstate/burn/operations/leader_key_register.rs index 7f86391f28..1a0add9a08 100644 --- a/stackslib/src/chainstate/burn/operations/leader_key_register.rs +++ b/stackslib/src/chainstate/burn/operations/leader_key_register.rs @@ -16,34 +16,27 @@ use std::io::{Read, Write}; -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainBlockHeader; -use crate::burnchains::BurnchainTransaction; -use crate::burnchains::PublicKey; -use crate::burnchains::Txid; -use crate::chainstate::burn::db::sortdb::SortitionHandleTx; -use crate::chainstate::burn::operations::Error as op_error; -use crate::chainstate::burn::operations::{ - BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, UserBurnSupportOp, -}; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::burn::Opcodes; -use crate::chainstate::stacks::StacksPrivateKey; -use crate::chainstate::stacks::StacksPublicKey; -use crate::net::Error as net_error; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::DBTx; use stacks_common::address::AddressHashMode; use stacks_common::codec::{write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::TrieHash; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, TrieHash, +}; use stacks_common::util::hash::DoubleSha256; use stacks_common::util::log; use stacks_common::util::vrf::{VRFPrivateKey, VRFPublicKey, VRF}; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BurnchainHeaderHash; +use crate::burnchains::{ + Address, Burnchain, BurnchainBlockHeader, BurnchainTransaction, PublicKey, Txid, +}; +use crate::chainstate::burn::db::sortdb::SortitionHandleTx; +use crate::chainstate::burn::operations::{ + BlockstackOperationType, Error as op_error, LeaderBlockCommitOp, LeaderKeyRegisterOp, + UserBurnSupportOp, +}; +use crate::chainstate::burn::{ConsensusHash, Opcodes}; +use crate::chainstate::stacks::{StacksPrivateKey, StacksPublicKey}; +use crate::net::Error as net_error; +use crate::util_lib::db::{DBConn, DBTx}; pub struct ParsedData { pub consensus_hash: ConsensusHash, @@ -233,6 +226,13 @@ impl LeaderKeyRegisterOp { #[cfg(test)] pub mod tests { + use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; + use stacks_common::deps_common::bitcoin::network::serialize::deserialize; + use stacks_common::types::chainstate::SortitionId; + use stacks_common::util::hash::{hex_bytes, to_hex}; + use stacks_common::util::{get_epoch_time_secs, log}; + + use super::*; use crate::burnchains::bitcoin::address::BitcoinAddress; use crate::burnchains::bitcoin::blocks::BitcoinBlockParser; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; @@ -246,15 +246,6 @@ pub mod tests { use crate::chainstate::stacks::address::StacksAddressExtensions; use crate::chainstate::stacks::index::TrieHashExtension; use crate::core::StacksEpochId; - use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; - use stacks_common::deps_common::bitcoin::network::serialize::deserialize; - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::hash::{hex_bytes, to_hex}; - use stacks_common::util::log; - - use stacks_common::types::chainstate::SortitionId; - - use super::*; pub struct OpFixture { pub txstr: String, diff --git a/stackslib/src/chainstate/burn/operations/mod.rs b/stackslib/src/chainstate/burn/operations/mod.rs index 27fa0a43f9..0e930b6b0b 100644 --- a/stackslib/src/chainstate/burn/operations/mod.rs +++ b/stackslib/src/chainstate/burn/operations/mod.rs @@ -14,40 +14,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::convert::From; -use std::convert::TryInto; -use std::error; -use std::fmt; -use std::fs; -use std::io; - -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainBlockHeader; -use crate::burnchains::Error as BurnchainError; -use crate::burnchains::Txid; -use crate::burnchains::{Address, PublicKey}; -use crate::burnchains::{BurnchainRecipient, BurnchainSigner, BurnchainTransaction}; +use std::convert::{From, TryInto}; +use std::{error, fmt, fs, io}; + +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, TrieHash, VRFSeed, +}; +use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, Sha512Trunc256Sum}; +use stacks_common::util::secp256k1::MessageSignature; +use stacks_common::util::vrf::VRFPublicKey; + +use crate::burnchains::{ + Address, Burnchain, BurnchainBlockHeader, BurnchainRecipient, BurnchainSigner, + BurnchainTransaction, Error as BurnchainError, PublicKey, Txid, +}; use crate::chainstate::burn::db::sortdb::SortitionHandleTx; use crate::chainstate::burn::operations::leader_block_commit::{ MissedBlockCommit, BURN_BLOCK_MINED_AT_MODULUS, }; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::VRFSeed; - -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::burn::Opcodes; +use crate::chainstate::burn::{ConsensusHash, Opcodes}; use crate::chainstate::stacks::address::PoxAddress; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::DBTx; -use crate::util_lib::db::Error as db_error; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::hash::{hex_bytes, to_hex, Hash160}; -use stacks_common::util::secp256k1::MessageSignature; -use stacks_common::util::vrf::VRFPublicKey; - -use stacks_common::types::chainstate::BurnchainHeaderHash; +use crate::util_lib::db::{DBConn, DBTx, Error as db_error}; pub mod delegate_stx; pub mod leader_block_commit; @@ -541,11 +528,6 @@ pub fn parse_u16_from_be(bytes: &[u8]) -> Option { } mod test { - use crate::burnchains::Txid; - use crate::chainstate::burn::operations::{ - BlockstackOperationType, DelegateStxOp, PreStxOp, StackStxOp, TransferStxOp, - }; - use crate::chainstate::stacks::address::PoxAddress; use stacks_common::address::C32_ADDRESS_VERSION_MAINNET_SINGLESIG; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, StacksAddress, VRFSeed, @@ -553,6 +535,12 @@ mod test { use stacks_common::types::Address; use stacks_common::util::hash::Hash160; + use crate::burnchains::Txid; + use crate::chainstate::burn::operations::{ + BlockstackOperationType, DelegateStxOp, PreStxOp, StackStxOp, TransferStxOp, + }; + use crate::chainstate::stacks::address::PoxAddress; + #[test] fn test_serialization_transfer_stx_op() { let sender_addr = "ST2QKZ4FKHAH1NQKYKYAYZPY440FEPK7GZ1R5HBP2"; diff --git a/stackslib/src/chainstate/burn/operations/stack_stx.rs b/stackslib/src/chainstate/burn/operations/stack_stx.rs index 33afe58c5f..786c3ad158 100644 --- a/stackslib/src/chainstate/burn/operations/stack_stx.rs +++ b/stackslib/src/chainstate/burn/operations/stack_stx.rs @@ -16,34 +16,28 @@ use std::io::{Read, Write}; -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainBlockHeader; -use crate::burnchains::PoxConstants; -use crate::burnchains::Txid; -use crate::burnchains::{BurnchainTransaction, PublicKey}; +use stacks_common::address::AddressHashMode; +use stacks_common::codec::{write_next, Error as codec_error, StacksMessageCodec}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, TrieHash, VRFSeed, +}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::log; +use stacks_common::util::vrf::{VRFPrivateKey, VRFPublicKey, VRF}; + +use crate::burnchains::{ + Address, Burnchain, BurnchainBlockHeader, BurnchainTransaction, PoxConstants, PublicKey, Txid, +}; use crate::chainstate::burn::db::sortdb::{SortitionDB, SortitionHandleTx}; -use crate::chainstate::burn::operations::Error as op_error; use crate::chainstate::burn::operations::{ - parse_u128_from_be, BlockstackOperationType, PreStxOp, StackStxOp, + parse_u128_from_be, BlockstackOperationType, Error as op_error, PreStxOp, StackStxOp, }; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::burn::Opcodes; +use crate::chainstate::burn::{ConsensusHash, Opcodes}; use crate::chainstate::stacks::address::PoxAddress; use crate::chainstate::stacks::index::storage::TrieFileStorage; use crate::chainstate::stacks::{StacksPrivateKey, StacksPublicKey}; -use crate::core::StacksEpochId; -use crate::core::POX_MAX_NUM_CYCLES; +use crate::core::{StacksEpochId, POX_MAX_NUM_CYCLES}; use crate::net::Error as net_error; -use stacks_common::address::AddressHashMode; -use stacks_common::codec::{write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; -use stacks_common::util::vrf::{VRFPrivateKey, VRFPublicKey, VRF}; - -use stacks_common::types::chainstate::VRFSeed; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksAddress}; // return type from parse_data below struct ParsedData { @@ -366,6 +360,15 @@ impl StackStxOp { #[cfg(test)] mod tests { + use stacks_common::address::AddressHashMode; + use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; + use stacks_common::deps_common::bitcoin::network::serialize::{deserialize, serialize_hex}; + use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, VRFSeed}; + use stacks_common::util::get_epoch_time_secs; + use stacks_common::util::hash::*; + use stacks_common::util::vrf::VRFPublicKey; + + use super::*; use crate::burnchains::bitcoin::address::*; use crate::burnchains::bitcoin::blocks::BitcoinBlockParser; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; @@ -374,23 +377,10 @@ mod tests { use crate::chainstate::burn::db::sortdb::*; use crate::chainstate::burn::db::*; use crate::chainstate::burn::operations::*; - use crate::chainstate::burn::ConsensusHash; - use crate::chainstate::burn::*; - use crate::chainstate::stacks::address::PoxAddress; - use crate::chainstate::stacks::address::StacksAddressExtensions; + use crate::chainstate::burn::{ConsensusHash, *}; + use crate::chainstate::stacks::address::{PoxAddress, StacksAddressExtensions}; use crate::chainstate::stacks::StacksPublicKey; use crate::core::StacksEpochId; - use stacks_common::address::AddressHashMode; - use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; - use stacks_common::deps_common::bitcoin::network::serialize::{deserialize, serialize_hex}; - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::hash::*; - use stacks_common::util::vrf::VRFPublicKey; - - use stacks_common::types::chainstate::StacksAddress; - use stacks_common::types::chainstate::{BlockHeaderHash, VRFSeed}; - - use super::*; struct OpFixture { txstr: String, diff --git a/stackslib/src/chainstate/burn/operations/transfer_stx.rs b/stackslib/src/chainstate/burn/operations/transfer_stx.rs index 43eda1c1fa..9d1d562d9c 100644 --- a/stackslib/src/chainstate/burn/operations/transfer_stx.rs +++ b/stackslib/src/chainstate/burn/operations/transfer_stx.rs @@ -16,32 +16,28 @@ use std::io::{Read, Write}; -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainBlockHeader; -use crate::burnchains::BurnchainRecipient; -use crate::burnchains::Txid; -use crate::burnchains::{BurnchainTransaction, PublicKey}; +use stacks_common::address::AddressHashMode; +use stacks_common::codec::{write_next, Error as codec_error, StacksMessageCodec}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, TrieHash, VRFSeed, +}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::log; +use stacks_common::util::vrf::{VRFPrivateKey, VRFPublicKey, VRF}; + +use crate::burnchains::{ + Address, Burnchain, BurnchainBlockHeader, BurnchainRecipient, BurnchainTransaction, PublicKey, + Txid, +}; use crate::chainstate::burn::db::sortdb::{SortitionDB, SortitionHandleTx}; -use crate::chainstate::burn::operations::Error as op_error; use crate::chainstate::burn::operations::{ - parse_u128_from_be, BlockstackOperationType, TransferStxOp, + parse_u128_from_be, BlockstackOperationType, Error as op_error, TransferStxOp, }; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::burn::Opcodes; +use crate::chainstate::burn::{ConsensusHash, Opcodes}; use crate::chainstate::stacks::index::storage::TrieFileStorage; use crate::chainstate::stacks::{StacksPrivateKey, StacksPublicKey}; use crate::core::POX_MAX_NUM_CYCLES; use crate::net::Error as net_error; -use stacks_common::address::AddressHashMode; -use stacks_common::codec::{write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; -use stacks_common::util::vrf::{VRFPrivateKey, VRFPublicKey, VRF}; - -use stacks_common::types::chainstate::VRFSeed; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksAddress}; // return type from parse_data below struct ParsedData { @@ -245,6 +241,15 @@ impl TransferStxOp { #[cfg(test)] mod tests { + use stacks_common::address::AddressHashMode; + use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; + use stacks_common::deps_common::bitcoin::network::serialize::{deserialize, serialize_hex}; + use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, VRFSeed}; + use stacks_common::util::get_epoch_time_secs; + use stacks_common::util::hash::*; + use stacks_common::util::vrf::VRFPublicKey; + + use super::*; use crate::burnchains::bitcoin::address::*; use crate::burnchains::bitcoin::blocks::BitcoinBlockParser; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; @@ -253,21 +258,9 @@ mod tests { use crate::chainstate::burn::db::sortdb::*; use crate::chainstate::burn::db::*; use crate::chainstate::burn::operations::*; - use crate::chainstate::burn::ConsensusHash; - use crate::chainstate::burn::*; + use crate::chainstate::burn::{ConsensusHash, *}; use crate::chainstate::stacks::address::StacksAddressExtensions; use crate::chainstate::stacks::StacksPublicKey; - use stacks_common::address::AddressHashMode; - use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; - use stacks_common::deps_common::bitcoin::network::serialize::{deserialize, serialize_hex}; - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::hash::*; - use stacks_common::util::vrf::VRFPublicKey; - - use stacks_common::types::chainstate::StacksAddress; - use stacks_common::types::chainstate::{BlockHeaderHash, VRFSeed}; - - use super::*; #[test] fn test_parse_transfer_stx() { diff --git a/stackslib/src/chainstate/burn/operations/user_burn_support.rs b/stackslib/src/chainstate/burn/operations/user_burn_support.rs index d522a4657b..cd17b39a27 100644 --- a/stackslib/src/chainstate/burn/operations/user_burn_support.rs +++ b/stackslib/src/chainstate/burn/operations/user_burn_support.rs @@ -17,31 +17,23 @@ use std::io::{Read, Write}; use std::marker::PhantomData; -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainBlockHeader; -use crate::burnchains::BurnchainTransaction; -use crate::burnchains::PublicKey; -use crate::burnchains::Txid; -use crate::chainstate::burn::db::sortdb::SortitionHandleTx; -use crate::chainstate::burn::operations::Error as op_error; -use crate::chainstate::burn::operations::{ - parse_u16_from_be, parse_u32_from_be, BlockstackOperationType, LeaderBlockCommitOp, - LeaderKeyRegisterOp, UserBurnSupportOp, -}; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::burn::Opcodes; -use crate::net::Error as net_error; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::DBTx; use stacks_common::codec::{write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::TrieHash; +use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, TrieHash}; use stacks_common::util::hash::Hash160; use stacks_common::util::log; use stacks_common::util::vrf::{VRFPublicKey, VRF}; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BurnchainHeaderHash; +use crate::burnchains::{ + Address, Burnchain, BurnchainBlockHeader, BurnchainTransaction, PublicKey, Txid, +}; +use crate::chainstate::burn::db::sortdb::SortitionHandleTx; +use crate::chainstate::burn::operations::{ + parse_u16_from_be, parse_u32_from_be, BlockstackOperationType, Error as op_error, + LeaderBlockCommitOp, LeaderKeyRegisterOp, UserBurnSupportOp, +}; +use crate::chainstate::burn::{ConsensusHash, Opcodes}; +use crate::net::Error as net_error; +use crate::util_lib::db::{DBConn, DBTx}; // return type for parse_data (below) struct ParsedData { @@ -301,6 +293,13 @@ impl UserBurnSupportOp { #[cfg(test)] mod tests { + use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; + use stacks_common::deps_common::bitcoin::network::serialize::deserialize; + use stacks_common::types::chainstate::{SortitionId, StacksAddress}; + use stacks_common::util::hash::{hex_bytes, to_hex, Hash160}; + use stacks_common::util::{get_epoch_time_secs, log}; + + use super::*; use crate::burnchains::bitcoin::address::BitcoinAddress; use crate::burnchains::bitcoin::blocks::BitcoinBlockParser; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; @@ -314,16 +313,6 @@ mod tests { use crate::chainstate::stacks::address::StacksAddressExtensions; use crate::chainstate::stacks::index::TrieHashExtension; use crate::core::StacksEpochId; - use stacks_common::deps_common::bitcoin::blockdata::transaction::Transaction; - use stacks_common::deps_common::bitcoin::network::serialize::deserialize; - use stacks_common::types::chainstate::StacksAddress; - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::hash::{hex_bytes, to_hex, Hash160}; - use stacks_common::util::log; - - use stacks_common::types::chainstate::SortitionId; - - use super::*; struct OpFixture { txstr: String, diff --git a/stackslib/src/chainstate/burn/sortition.rs b/stackslib/src/chainstate/burn/sortition.rs index c2d21a7a4c..d1cb3a2259 100644 --- a/stackslib/src/chainstate/burn/sortition.rs +++ b/stackslib/src/chainstate/burn/sortition.rs @@ -17,36 +17,29 @@ use std::collections::BTreeMap; use rusqlite::Connection; +use stacks_common::types::chainstate::{ + BlockHeaderHash, PoxId, SortitionId, StacksBlockId, TrieHash, VRFSeed, +}; +use stacks_common::util::hash::Hash160; +use stacks_common::util::log; +use stacks_common::util::uint::{BitArray, Uint256, Uint512}; -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainBlock; -use crate::burnchains::BurnchainBlockHeader; -use crate::burnchains::PublicKey; -use crate::burnchains::Txid; +use crate::burnchains::{ + Address, Burnchain, BurnchainBlock, BurnchainBlockHeader, PublicKey, Txid, +}; use crate::chainstate::burn::db::sortdb::SortitionHandleTx; use crate::chainstate::burn::distribution::BurnSamplePoint; use crate::chainstate::burn::operations::{ BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, UserBurnSupportOp, }; -use crate::chainstate::burn::BlockSnapshot; -use crate::chainstate::burn::{BurnchainHeaderHash, ConsensusHash, OpsHash, SortitionHash}; +use crate::chainstate::burn::{ + BlockSnapshot, BurnchainHeaderHash, ConsensusHash, ConsensusHashExtensions, OpsHash, + SortitionHash, +}; use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::index::MarfTrieId; +use crate::chainstate::stacks::index::{ClarityMarfTrieId, MarfTrieId, TrieHashExtension}; use crate::core::*; use crate::util_lib::db::Error as db_error; -use stacks_common::util::hash::Hash160; -use stacks_common::util::log; -use stacks_common::util::uint::BitArray; -use stacks_common::util::uint::Uint256; -use stacks_common::util::uint::Uint512; - -use crate::chainstate::burn::ConsensusHashExtensions; -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::chainstate::stacks::index::TrieHashExtension; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{BlockHeaderHash, PoxId, SortitionId, VRFSeed}; impl BlockSnapshot { /// Creates an "empty" (i.e. zeroed out) BlockSnapshot, to make a basis for creating @@ -443,22 +436,18 @@ impl BlockSnapshot { #[cfg(test)] mod test { - use crate::burnchains::tests::*; - use crate::burnchains::*; - use crate::chainstate::burn::db::sortdb::*; - use crate::chainstate::burn::operations::*; - use crate::chainstate::stacks::*; use stacks_common::address::*; + use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, VRFSeed}; use stacks_common::util::get_epoch_time_secs; use stacks_common::util::hash::hex_bytes; - use stacks_common::util::vrf::VRFPrivateKey; - use stacks_common::util::vrf::VRFPublicKey; - - use stacks_common::types::chainstate::BlockHeaderHash; - use stacks_common::types::chainstate::BurnchainHeaderHash; - use stacks_common::types::chainstate::VRFSeed; + use stacks_common::util::vrf::{VRFPrivateKey, VRFPublicKey}; use super::*; + use crate::burnchains::tests::*; + use crate::burnchains::*; + use crate::chainstate::burn::db::sortdb::*; + use crate::chainstate::burn::operations::*; + use crate::chainstate::stacks::*; fn test_make_snapshot( sort_tx: &mut SortitionHandleTx, diff --git a/stackslib/src/chainstate/coordinator/comm.rs b/stackslib/src/chainstate/coordinator/comm.rs index e73c2105e3..d89afef1e3 100644 --- a/stackslib/src/chainstate/coordinator/comm.rs +++ b/stackslib/src/chainstate/coordinator/comm.rs @@ -14,10 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::sync::{ - atomic::{AtomicU64, Ordering}, - Arc, Condvar, LockResult, Mutex, MutexGuard, RwLock, TryLockResult, -}; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::{Arc, Condvar, LockResult, Mutex, MutexGuard, RwLock, TryLockResult}; use std::time::{Duration, Instant}; use std::{process, thread}; diff --git a/stackslib/src/chainstate/coordinator/mod.rs b/stackslib/src/chainstate/coordinator/mod.rs index 821a79b0a6..d758a16829 100644 --- a/stackslib/src/chainstate/coordinator/mod.rs +++ b/stackslib/src/chainstate/coordinator/mod.rs @@ -14,76 +14,70 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::cmp; use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; use std::convert::{TryFrom, TryInto}; -use std::fs; use std::path::PathBuf; use std::sync::mpsc::SyncSender; -use std::sync::Arc; -use std::sync::Mutex; +use std::sync::{Arc, Mutex}; use std::time::Duration; +use std::{cmp, fs}; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::database::BurnStateDB; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; +use clarity::vm::Value; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksBlockId, +}; +use stacks_common::util::get_epoch_time_secs; + +pub use self::comm::CoordinatorCommunication; +use super::stacks::boot::RewardSet; +use crate::burnchains::affirmation::{AffirmationMap, AffirmationMapEntry}; +use crate::burnchains::bitcoin::indexer::BitcoinIndexer; +use crate::burnchains::db::{ + BlockCommitMetadata, BurnchainBlockData, BurnchainDB, BurnchainDBTransaction, + BurnchainHeaderReader, +}; use crate::burnchains::{ - affirmation::{AffirmationMap, AffirmationMapEntry}, - bitcoin::indexer::BitcoinIndexer, - db::{ - BlockCommitMetadata, BurnchainBlockData, BurnchainDB, BurnchainDBTransaction, - BurnchainHeaderReader, - }, Address, Burnchain, BurnchainBlockHeader, Error as BurnchainError, PoxConstants, Txid, }; -use crate::chainstate::burn::{ - db::sortdb::{SortitionDB, SortitionDBConn, SortitionDBTx, SortitionHandleTx}, - operations::leader_block_commit::{RewardSetInfo, BURN_BLOCK_MINED_AT_MODULUS}, - operations::BlockstackOperationType, - operations::LeaderBlockCommitOp, - BlockSnapshot, ConsensusHash, +use crate::chainstate::burn::db::sortdb::{ + SortitionDB, SortitionDBConn, SortitionDBTx, SortitionHandleTx, +}; +use crate::chainstate::burn::operations::leader_block_commit::{ + RewardSetInfo, BURN_BLOCK_MINED_AT_MODULUS, }; +use crate::chainstate::burn::operations::{BlockstackOperationType, LeaderBlockCommitOp}; +use crate::chainstate::burn::{BlockSnapshot, ConsensusHash}; use crate::chainstate::coordinator::comm::{ ArcCounterCoordinatorNotices, CoordinatorEvents, CoordinatorNotices, CoordinatorReceivers, }; use crate::chainstate::stacks::address::PoxAddress; use crate::chainstate::stacks::boot::POX_3_NAME; +use crate::chainstate::stacks::db::accounts::MinerReward; +use crate::chainstate::stacks::db::{ + ChainStateBootData, ClarityTx, MinerRewardInfo, StacksChainState, StacksEpochReceipt, + StacksHeaderInfo, +}; +use crate::chainstate::stacks::events::{ + StacksTransactionEvent, StacksTransactionReceipt, TransactionOrigin, +}; +use crate::chainstate::stacks::index::marf::MARFOpenOpts; use crate::chainstate::stacks::index::MarfTrieId; +use crate::chainstate::stacks::miner::{signal_mining_blocked, signal_mining_ready, MinerStatus}; use crate::chainstate::stacks::{ - db::{ - accounts::MinerReward, ChainStateBootData, ClarityTx, MinerRewardInfo, StacksChainState, - StacksEpochReceipt, StacksHeaderInfo, - }, - events::{StacksTransactionEvent, StacksTransactionReceipt, TransactionOrigin}, - miner::{signal_mining_blocked, signal_mining_ready, MinerStatus}, Error as ChainstateError, StacksBlock, StacksBlockHeader, TransactionPayload, }; -use crate::core::{StacksEpoch, StacksEpochId}; +use crate::core::{ + StacksEpoch, StacksEpochId, FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, +}; +use crate::cost_estimates::{CostEstimator, FeeEstimator, PessimisticEstimator}; use crate::monitoring::{ increment_contract_calls_processed, increment_stx_blocks_processed_counter, }; use crate::net::atlas::{AtlasConfig, AtlasDB, AttachmentInstance}; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::DBTx; -use crate::util_lib::db::Error as DBError; -use clarity::vm::{ - costs::ExecutionCost, - types::{PrincipalData, QualifiedContractIdentifier}, - Value, -}; - -use crate::cost_estimates::{CostEstimator, FeeEstimator, PessimisticEstimator}; -use clarity::vm::database::BurnStateDB; -use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksBlockId, -}; - -use crate::chainstate::stacks::index::marf::MARFOpenOpts; - -pub use self::comm::CoordinatorCommunication; - -use super::stacks::boot::RewardSet; -use stacks_common::util::get_epoch_time_secs; - -use crate::core::FIRST_BURNCHAIN_CONSENSUS_HASH; -use crate::core::FIRST_STACKS_BLOCK_HASH; +use crate::util_lib::db::{DBConn, DBTx, Error as DBError}; pub mod comm; #[cfg(test)] diff --git a/stackslib/src/chainstate/coordinator/tests.rs b/stackslib/src/chainstate/coordinator/tests.rs index cd3ba0714a..42fbffa50f 100644 --- a/stackslib/src/chainstate/coordinator/tests.rs +++ b/stackslib/src/chainstate/coordinator/tests.rs @@ -15,23 +15,38 @@ // along with this program. If not, see . use std::cmp; -use std::collections::BTreeMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::sync::{ - atomic::{AtomicBool, AtomicU64, Ordering}, - mpsc::sync_channel, - Arc, RwLock, -}; +use std::collections::{BTreeMap, HashSet, VecDeque}; +use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::sync::mpsc::sync_channel; +use std::sync::{Arc, RwLock}; +use clarity::vm::clarity::TransactionConnection; +use clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; +use clarity::vm::database::BurnStateDB; +use clarity::vm::errors::Error as InterpreterError; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; +use clarity::vm::{ClarityVersion, Value}; +use rand::RngCore; use rusqlite::Connection; +use stacks_common::address::AddressHashMode; +use stacks_common::consts::CHAIN_ID_TESTNET; +use stacks_common::deps_common::bitcoin::blockdata::block::{BlockHeader, LoneBlockHeader}; +use stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; +use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksAddress, StacksBlockId, + TrieHash, VRFSeed, +}; +use stacks_common::util::hash::{to_hex, Hash160}; +use stacks_common::util::vrf::*; +use stacks_common::{address, types, util}; use crate::burnchains::affirmation::*; use crate::burnchains::bitcoin::address::BitcoinAddress; use crate::burnchains::bitcoin::indexer::BitcoinIndexer; +use crate::burnchains::db::*; use crate::burnchains::tests::db::*; -use crate::burnchains::{db::*, *}; -use crate::chainstate; +use crate::burnchains::*; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::burn::distribution::BurnSamplePoint; use crate::chainstate::burn::operations::leader_block_commit::*; @@ -39,48 +54,18 @@ use crate::chainstate::burn::operations::*; use crate::chainstate::burn::*; use crate::chainstate::coordinator::{Error as CoordError, *}; use crate::chainstate::stacks::address::PoxAddress; -use crate::chainstate::stacks::boot::POX_1_NAME; -use crate::chainstate::stacks::boot::POX_2_NAME; -use crate::chainstate::stacks::boot::{PoxStartCycleInfo, POX_3_NAME}; -use crate::chainstate::stacks::db::{ - accounts::MinerReward, ClarityTx, StacksChainState, StacksHeaderInfo, +use crate::chainstate::stacks::boot::{ + PoxStartCycleInfo, COSTS_2_NAME, POX_1_NAME, POX_2_NAME, POX_3_NAME, }; +use crate::chainstate::stacks::db::accounts::MinerReward; +use crate::chainstate::stacks::db::{ClarityTx, StacksChainState, StacksHeaderInfo}; use crate::chainstate::stacks::*; use crate::clarity_vm::clarity::ClarityConnection; -use crate::core; use crate::core::*; use crate::monitoring::increment_stx_blocks_processed_counter; -use crate::util_lib::boot::boot_code_addr; +use crate::util_lib::boot::{boot_code_addr, boot_code_id}; use crate::util_lib::strings::StacksString; -use clarity::vm::errors::Error as InterpreterError; -use clarity::vm::{ - costs::{ExecutionCost, LimitedCostTracker}, - types::PrincipalData, - types::QualifiedContractIdentifier, - Value, -}; -use stacks_common::address; -use stacks_common::consts::CHAIN_ID_TESTNET; -use stacks_common::util::hash::{to_hex, Hash160}; -use stacks_common::util::vrf::*; - -use crate::chainstate::stacks::boot::COSTS_2_NAME; -use crate::util_lib::boot::boot_code_id; -use clarity::vm::clarity::TransactionConnection; -use clarity::vm::database::BurnStateDB; -use clarity::vm::ClarityVersion; -use rand::RngCore; -use stacks_common::address::AddressHashMode; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, PoxId, SortitionId, StacksAddress, VRFSeed, -}; -use stacks_common::{types, util}; - -use stacks_common::deps_common::bitcoin::blockdata::block::{BlockHeader, LoneBlockHeader}; -use stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; -use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash; +use crate::{chainstate, core}; lazy_static! { pub static ref BURN_BLOCK_HEADERS: Arc = Arc::new(AtomicU64::new(1)); diff --git a/stackslib/src/chainstate/mod.rs b/stackslib/src/chainstate/mod.rs index 8566160f80..349a34ee3b 100644 --- a/stackslib/src/chainstate/mod.rs +++ b/stackslib/src/chainstate/mod.rs @@ -15,7 +15,6 @@ // along with this program. If not, see . use crate::util_lib::db; - use crate::util_lib::db::Error as db_error; pub trait ChainstateDB { diff --git a/stackslib/src/chainstate/stacks/address.rs b/stackslib/src/chainstate/stacks/address.rs index 565f152676..d87d164da5 100644 --- a/stackslib/src/chainstate/stacks/address.rs +++ b/stackslib/src/chainstate/stacks/address.rs @@ -19,6 +19,16 @@ use std::io::prelude::*; use std::io::{Read, Write}; use std::{fmt, io}; +use clarity::vm::types::{PrincipalData, SequenceData, StandardPrincipalData, TupleData, Value}; +use stacks_common::address::c32::{c32_address, c32_address_decode}; +use stacks_common::address::{b58, public_keys_to_address_hash, AddressHashMode}; +use stacks_common::codec::{read_next, write_next, Error as codec_error, StacksMessageCodec}; +use stacks_common::deps_common::bitcoin::blockdata::opcodes::All as BtcOp; +use stacks_common::deps_common::bitcoin::blockdata::script::Builder as BtcScriptBuilder; +use stacks_common::deps_common::bitcoin::blockdata::transaction::TxOut; +use stacks_common::types::chainstate::{StacksAddress, STACKS_ADDRESS_ENCODED_SIZE}; +use stacks_common::util::hash::{to_hex, Hash160, HASH160_ENCODED_SIZE}; + use crate::burnchains::bitcoin::address::{ legacy_address_type_to_version_byte, legacy_version_byte_to_address_type, to_b58_version_byte, to_c32_version_byte, BitcoinAddress, LegacyBitcoinAddress, LegacyBitcoinAddressType, @@ -26,30 +36,12 @@ use crate::burnchains::bitcoin::address::{ }; use crate::burnchains::bitcoin::BitcoinTxOutput; use crate::burnchains::{Address, PublicKey}; -use crate::chainstate::stacks::StacksPublicKey; use crate::chainstate::stacks::{ - C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, + StacksPublicKey, C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; use crate::net::Error as net_error; -use clarity::vm::types::{PrincipalData, SequenceData, StandardPrincipalData}; -use clarity::vm::types::{TupleData, Value}; -use stacks_common::address::b58; -use stacks_common::address::c32::c32_address; -use stacks_common::address::c32::c32_address_decode; -use stacks_common::address::public_keys_to_address_hash; -use stacks_common::address::AddressHashMode; -use stacks_common::deps_common::bitcoin::blockdata::opcodes::All as BtcOp; -use stacks_common::deps_common::bitcoin::blockdata::script::Builder as BtcScriptBuilder; -use stacks_common::deps_common::bitcoin::blockdata::transaction::TxOut; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::HASH160_ENCODED_SIZE; - use crate::util_lib::boot::boot_code_addr; -use stacks_common::codec::{read_next, write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::STACKS_ADDRESS_ENCODED_SIZE; pub trait StacksAddressExtensions { fn to_b58(self) -> String; @@ -526,15 +518,16 @@ impl StacksAddressExtensions for StacksAddress { #[cfg(test)] mod test { + use clarity::vm::types::BuffData; + use stacks_common::util::hash::*; + use stacks_common::util::secp256k1::Secp256k1PublicKey as PubKey; + use super::*; use crate::burnchains::bitcoin::BitcoinNetworkType; use crate::chainstate::stacks::*; use crate::net::codec::test::check_codec_and_corruption; use crate::net::codec::*; use crate::net::*; - use clarity::vm::types::BuffData; - use stacks_common::util::hash::*; - use stacks_common::util::secp256k1::Secp256k1PublicKey as PubKey; #[test] fn tx_stacks_address_codec() { diff --git a/stackslib/src/chainstate/stacks/auth.rs b/stackslib/src/chainstate/stacks/auth.rs index a489c80d02..d2981683c0 100644 --- a/stackslib/src/chainstate/stacks/auth.rs +++ b/stackslib/src/chainstate/stacks/auth.rs @@ -18,42 +18,26 @@ use std::io; use std::io::prelude::*; use std::io::{Read, Write}; -use crate::burnchains::PrivateKey; -use crate::burnchains::PublicKey; -use crate::burnchains::Txid; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::MultisigHashMode; -use crate::chainstate::stacks::MultisigSpendingCondition; -use crate::chainstate::stacks::SinglesigHashMode; -use crate::chainstate::stacks::SinglesigSpendingCondition; -use crate::chainstate::stacks::StacksPrivateKey; -use crate::chainstate::stacks::StacksPublicKey; -use crate::chainstate::stacks::TransactionAuth; -use crate::chainstate::stacks::TransactionAuthField; -use crate::chainstate::stacks::TransactionAuthFieldID; -use crate::chainstate::stacks::TransactionAuthFlags; -use crate::chainstate::stacks::TransactionPublicKeyEncoding; -use crate::chainstate::stacks::TransactionSpendingCondition; +use stacks_common::address::{public_keys_to_address_hash, AddressHashMode}; +use stacks_common::codec::{ + read_next, write_next, Error as codec_error, StacksMessageCodec, MAX_MESSAGE_LEN, +}; +use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{to_hex, Hash160, Sha512Trunc256Sum}; +use stacks_common::util::retry::{BoundReader, RetryReader}; +use stacks_common::util::secp256k1::{MessageSignature, MESSAGE_SIGNATURE_ENCODED_SIZE}; + +use crate::burnchains::{PrivateKey, PublicKey, Txid}; use crate::chainstate::stacks::{ + Error, MultisigHashMode, MultisigSpendingCondition, SinglesigHashMode, + SinglesigSpendingCondition, StacksPrivateKey, StacksPublicKey, TransactionAuth, + TransactionAuthField, TransactionAuthFieldID, TransactionAuthFlags, + TransactionPublicKeyEncoding, TransactionSpendingCondition, C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; -use crate::net::Error as net_error; -use crate::net::STACKS_PUBLIC_KEY_ENCODED_SIZE; -use stacks_common::address::public_keys_to_address_hash; -use stacks_common::address::AddressHashMode; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::retry::BoundReader; -use stacks_common::util::retry::RetryReader; -use stacks_common::util::secp256k1::MessageSignature; -use stacks_common::util::secp256k1::MESSAGE_SIGNATURE_ENCODED_SIZE; - -use stacks_common::codec::{read_next, write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::StacksAddress; +use crate::net::{Error as net_error, STACKS_PUBLIC_KEY_ENCODED_SIZE}; impl StacksMessageCodec for TransactionAuthField { fn consensus_serialize(&self, fd: &mut W) -> Result<(), codec_error> { @@ -1096,14 +1080,12 @@ impl TransactionAuth { #[cfg(test)] mod test { - use crate::chainstate::stacks::StacksPublicKey as PubKey; - use crate::chainstate::stacks::*; + use super::*; + use crate::chainstate::stacks::{StacksPublicKey as PubKey, *}; use crate::net::codec::test::check_codec_and_corruption; use crate::net::codec::*; use crate::net::*; - use super::*; - #[test] fn tx_stacks_spending_condition_p2pkh() { // p2pkh diff --git a/stackslib/src/chainstate/stacks/block.rs b/stackslib/src/chainstate/stacks/block.rs index fe715e6f2f..88a05fde6e 100644 --- a/stackslib/src/chainstate/stacks/block.rs +++ b/stackslib/src/chainstate/stacks/block.rs @@ -19,33 +19,25 @@ use std::io; use std::io::prelude::*; use std::io::{Read, Write}; -use sha2::Digest; -use sha2::Sha512_256; - -use crate::burnchains::PrivateKey; -use crate::burnchains::PublicKey; -use crate::chainstate::burn::operations::*; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::burn::*; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::*; -use crate::core::*; -use crate::net::Error as net_error; -use stacks_common::codec::MAX_MESSAGE_LEN; +use sha2::{Digest, Sha512_256}; +use stacks_common::codec::{ + read_next, write_next, Error as codec_error, StacksMessageCodec, MAX_MESSAGE_LEN, +}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksBlockId, StacksWorkScore, TrieHash, VRFSeed, +}; use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::MerkleTree; -use stacks_common::util::hash::Sha512Trunc256Sum; +use stacks_common::util::hash::{MerkleTree, Sha512Trunc256Sum}; use stacks_common::util::retry::BoundReader; use stacks_common::util::secp256k1::MessageSignature; use stacks_common::util::vrf::*; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblockHeader; -use stacks_common::codec::{read_next, write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{BlockHeaderHash, StacksWorkScore, VRFSeed}; +use crate::burnchains::{PrivateKey, PublicKey}; +use crate::chainstate::burn::operations::*; +use crate::chainstate::burn::{ConsensusHash, *}; +use crate::chainstate::stacks::{Error, StacksBlockHeader, StacksMicroblockHeader, *}; +use crate::core::*; +use crate::net::Error as net_error; impl StacksMessageCodec for StacksBlockHeader { fn consensus_serialize(&self, fd: &mut W) -> Result<(), codec_error> { @@ -920,28 +912,25 @@ impl StacksMicroblock { #[cfg(test)] mod test { + use std::error::Error; + + use stacks_common::address::*; + use stacks_common::types::chainstate::StacksAddress; + use stacks_common::util::hash::*; + + use super::*; use crate::burnchains::bitcoin::address::BitcoinAddress; use crate::burnchains::bitcoin::blocks::BitcoinBlockParser; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; use crate::burnchains::bitcoin::BitcoinNetworkType; - use crate::burnchains::BurnchainBlockHeader; - use crate::burnchains::BurnchainSigner; - use crate::burnchains::Txid; + use crate::burnchains::{BurnchainBlockHeader, BurnchainSigner, Txid}; use crate::chainstate::burn::operations::leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS; use crate::chainstate::stacks::address::StacksAddressExtensions; - use crate::chainstate::stacks::test::make_codec_test_block; - use crate::chainstate::stacks::test::*; + use crate::chainstate::stacks::test::{make_codec_test_block, *}; use crate::chainstate::stacks::*; use crate::net::codec::test::*; use crate::net::codec::*; use crate::net::*; - use stacks_common::address::*; - use stacks_common::util::hash::*; - use std::error::Error; - - use stacks_common::types::chainstate::StacksAddress; - - use super::*; #[test] fn codec_stacks_block_ecvrf_proof() { diff --git a/stackslib/src/chainstate/stacks/boot/contract_tests.rs b/stackslib/src/chainstate/stacks/boot/contract_tests.rs index 0a9766c020..0c36912ec6 100644 --- a/stackslib/src/chainstate/stacks/boot/contract_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/contract_tests.rs @@ -1,29 +1,10 @@ use std::collections::{HashMap, VecDeque}; -use std::convert::TryFrom; -use std::convert::TryInto; +use std::convert::{TryFrom, TryInto}; -use crate::burnchains::Burnchain; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::stacks::address::PoxAddress; -use crate::chainstate::stacks::boot::{ - BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET, - POX_2_TESTNET_CODE, -}; -use crate::chainstate::stacks::db::{MinerPaymentSchedule, StacksHeaderInfo}; -use crate::chainstate::stacks::index::MarfTrieId; -use crate::chainstate::stacks::index::{ClarityMarfTrieId, TrieMerkleProof}; -use crate::chainstate::stacks::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; -use crate::chainstate::stacks::*; -use crate::clarity_vm::database::marf::MarfedKV; -use crate::core::{ - BITCOIN_REGTEST_FIRST_BLOCK_HASH, BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT, - BITCOIN_REGTEST_FIRST_BLOCK_TIMESTAMP, FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, - POX_REWARD_CYCLE_LENGTH, -}; -use crate::util_lib::db::{DBConn, FromRow}; use clarity::vm::analysis::arithmetic_checker::ArithmeticOnlyChecker; use clarity::vm::analysis::mem_type_check; use clarity::vm::ast::ASTRules; +use clarity::vm::clarity::TransactionConnection; use clarity::vm::contexts::OwnedEnvironment; use clarity::vm::contracts::Contract; use clarity::vm::costs::CostOverflowingMath; @@ -40,27 +21,33 @@ use clarity::vm::types::{ OptionalData, PrincipalData, QualifiedContractIdentifier, ResponseData, StandardPrincipalData, TupleData, TupleTypeSignature, TypeSignature, Value, NONE, }; +use clarity::vm::version::ClarityVersion; use stacks_common::address::AddressHashMode; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::{Sha256Sum, Sha512Trunc256Sum}; - -use crate::clarity_vm::clarity::Error as ClarityError; -use crate::core::PEER_VERSION_EPOCH_1_0; -use crate::core::POX_TESTNET_CYCLE_LENGTH; -use crate::util_lib::boot::boot_code_addr; -use crate::util_lib::boot::boot_code_id; -use crate::{ - burnchains::PoxConstants, - clarity_vm::{clarity::ClarityBlockConnection, database::marf::WritableMarfStore}, - core::StacksEpoch, - core::StacksEpochId, -}; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksAddress, StacksBlockId, VRFSeed, }; +use stacks_common::util::hash::{to_hex, Sha256Sum, Sha512Trunc256Sum}; -use clarity::vm::clarity::TransactionConnection; -use clarity::vm::version::ClarityVersion; +use crate::burnchains::{Burnchain, PoxConstants}; +use crate::chainstate::burn::ConsensusHash; +use crate::chainstate::stacks::address::PoxAddress; +use crate::chainstate::stacks::boot::{ + BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET, + POX_2_TESTNET_CODE, +}; +use crate::chainstate::stacks::db::{MinerPaymentSchedule, StacksHeaderInfo}; +use crate::chainstate::stacks::index::{ClarityMarfTrieId, MarfTrieId, TrieMerkleProof}; +use crate::chainstate::stacks::{C32_ADDRESS_VERSION_TESTNET_SINGLESIG, *}; +use crate::clarity_vm::clarity::{ClarityBlockConnection, Error as ClarityError}; +use crate::clarity_vm::database::marf::{MarfedKV, WritableMarfStore}; +use crate::core::{ + StacksEpoch, StacksEpochId, BITCOIN_REGTEST_FIRST_BLOCK_HASH, + BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT, BITCOIN_REGTEST_FIRST_BLOCK_TIMESTAMP, + FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, PEER_VERSION_EPOCH_1_0, + POX_REWARD_CYCLE_LENGTH, POX_TESTNET_CYCLE_LENGTH, +}; +use crate::util_lib::boot::{boot_code_addr, boot_code_id}; +use crate::util_lib::db::{DBConn, FromRow}; const USTX_PER_HOLDER: u128 = 1_000_000; diff --git a/stackslib/src/chainstate/stacks/boot/docs.rs b/stackslib/src/chainstate/stacks/boot/docs.rs index 7ba1c1135e..802146ffeb 100644 --- a/stackslib/src/chainstate/stacks/boot/docs.rs +++ b/stackslib/src/chainstate/stacks/boot/docs.rs @@ -1,9 +1,10 @@ use std::collections::{HashMap, HashSet}; use std::iter::FromIterator; -use super::STACKS_BOOT_CODE_MAINNET; use clarity::vm::docs::contracts::{produce_docs_refs, ContractSupportDocs}; +use super::STACKS_BOOT_CODE_MAINNET; + fn make_contract_support_docs() -> HashMap<&'static str, ContractSupportDocs> { let pox_descriptions = vec![ ("disallow-contract-caller", "Revokes authorization from a contract to invoke stacking methods through contract-calls"), diff --git a/stackslib/src/chainstate/stacks/boot/mod.rs b/stackslib/src/chainstate/stacks/boot/mod.rs index 41436cfb84..2dbeecd563 100644 --- a/stackslib/src/chainstate/stacks/boot/mod.rs +++ b/stackslib/src/chainstate/stacks/boot/mod.rs @@ -16,59 +16,44 @@ use std::boxed::Box; use std::cmp; -use std::convert::TryFrom; -use std::convert::TryInto; +use std::convert::{TryFrom, TryInto}; -use crate::burnchains::bitcoin::address::BitcoinAddress; -use crate::burnchains::Burnchain; -use crate::burnchains::{Address, PoxConstants}; -use crate::chainstate::burn::db::sortdb::SortitionDB; -use crate::chainstate::stacks::address::PoxAddress; -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::index::marf::MarfConnection; -use crate::chainstate::stacks::Error; -use crate::clarity_vm::clarity::ClarityConnection; -use crate::clarity_vm::clarity::ClarityTransactionConnection; -use crate::core::StacksEpochId; -use crate::core::{POX_MAXIMAL_SCALING, POX_THRESHOLD_STEPS_USTX}; -use crate::util_lib::strings::VecDisplay; use clarity::vm::analysis::CheckErrors; use clarity::vm::ast::ASTRules; -use clarity::vm::clarity::TransactionConnection; +use clarity::vm::clarity::{Error as ClarityError, TransactionConnection}; use clarity::vm::contexts::ContractContext; -use clarity::vm::costs::{ - cost_functions::ClarityCostFunction, ClarityCostFunctionReference, CostStateSummary, -}; -use clarity::vm::database::ClarityDatabase; -use clarity::vm::database::{NULL_BURN_STATE_DB, NULL_HEADER_DB}; -use clarity::vm::errors::Error as VmError; -use clarity::vm::errors::InterpreterError; +use clarity::vm::costs::cost_functions::ClarityCostFunction; +use clarity::vm::costs::{ClarityCostFunctionReference, CostStateSummary, LimitedCostTracker}; +use clarity::vm::database::{ClarityDatabase, NULL_BURN_STATE_DB, NULL_HEADER_DB}; +use clarity::vm::errors::{Error as VmError, InterpreterError}; use clarity::vm::events::StacksTransactionEvent; -use clarity::vm::representations::ClarityName; -use clarity::vm::representations::ContractName; +use clarity::vm::representations::{ClarityName, ContractName}; use clarity::vm::types::{ PrincipalData, QualifiedContractIdentifier, SequenceData, StandardPrincipalData, TupleData, TypeSignature, Value, }; -use clarity::vm::Environment; +use clarity::vm::{ClarityVersion, Environment, SymbolicExpression}; use stacks_common::address::AddressHashMode; use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Hash160; +use stacks_common::types; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, StacksBlockId}; +use stacks_common::util::hash::{to_hex, Hash160}; -use crate::chainstate::stacks::address::StacksAddressExtensions; +use crate::burnchains::bitcoin::address::BitcoinAddress; +use crate::burnchains::{Address, Burnchain, PoxConstants}; +use crate::chainstate::burn::db::sortdb::SortitionDB; +use crate::chainstate::stacks::address::{PoxAddress, StacksAddressExtensions}; +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::index::marf::MarfConnection; +use crate::chainstate::stacks::Error; +use crate::clarity_vm::clarity::{ClarityConnection, ClarityTransactionConnection}; use crate::clarity_vm::database::HeadersDBConn; +use crate::core::{ + StacksEpochId, BITCOIN_REGTEST_FIRST_BLOCK_HASH, CHAIN_ID_MAINNET, POX_MAXIMAL_SCALING, + POX_THRESHOLD_STEPS_USTX, +}; use crate::util_lib::boot; -use clarity::vm::clarity::Error as ClarityError; -use clarity::vm::ClarityVersion; -use clarity::vm::{costs::LimitedCostTracker, SymbolicExpression}; -use stacks_common::types; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; - -use crate::core::BITCOIN_REGTEST_FIRST_BLOCK_HASH; -use crate::core::CHAIN_ID_MAINNET; +use crate::util_lib::strings::VecDisplay; const BOOT_CODE_POX_BODY: &'static str = std::include_str!("pox.clar"); const BOOT_CODE_POX_TESTNET_CONSTS: &'static str = std::include_str!("pox-testnet.clar"); @@ -1027,8 +1012,13 @@ pub mod test { use std::convert::From; use std::fs; - use crate::burnchains::Address; - use crate::burnchains::PublicKey; + use clarity::vm::contracts::Contract; + use clarity::vm::types::*; + use stacks_common::util::hash::to_hex; + use stacks_common::util::*; + + use super::*; + use crate::burnchains::{Address, PublicKey}; use crate::chainstate::burn::db::sortdb::*; use crate::chainstate::burn::db::*; use crate::chainstate::burn::operations::BlockstackOperationType; @@ -1037,21 +1027,13 @@ pub mod test { use crate::chainstate::stacks::db::*; use crate::chainstate::stacks::miner::*; use crate::chainstate::stacks::tests::*; - use crate::chainstate::stacks::Error as chainstate_error; - use crate::chainstate::stacks::*; - use crate::core::StacksEpochId; - use crate::core::*; + use crate::chainstate::stacks::{ + Error as chainstate_error, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, *, + }; + use crate::core::{StacksEpochId, *}; use crate::net::test::*; - use clarity::vm::contracts::Contract; - use clarity::vm::types::*; - use stacks_common::util::hash::to_hex; - use stacks_common::util::*; - - use crate::chainstate::stacks::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; use crate::util_lib::boot::{boot_code_id, boot_code_test_addr}; - use super::*; - pub const TESTNET_STACKING_THRESHOLD_25: u128 = 8000; /// Extract a PoX address from its tuple representation. diff --git a/stackslib/src/chainstate/stacks/boot/pox_2_tests.rs b/stackslib/src/chainstate/stacks/boot/pox_2_tests.rs index 34146c6c82..54bdb226e2 100644 --- a/stackslib/src/chainstate/stacks/boot/pox_2_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/pox_2_tests.rs @@ -1,27 +1,10 @@ use std::collections::{HashMap, HashSet, VecDeque}; -use std::convert::TryFrom; -use std::convert::TryInto; +use std::convert::{TryFrom, TryInto}; -use crate::chainstate::burn::BlockSnapshot; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::stacks::address::{PoxAddress, PoxAddressType20, PoxAddressType32}; -use crate::chainstate::stacks::boot::{ - BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET, POX_2_NAME, - POX_3_NAME, -}; -use crate::chainstate::stacks::db::{ - MinerPaymentSchedule, StacksChainState, StacksHeaderInfo, MINER_REWARD_MATURITY, -}; -use crate::chainstate::stacks::index::marf::MarfConnection; -use crate::chainstate::stacks::index::MarfTrieId; -use crate::chainstate::stacks::*; -use crate::clarity_vm::database::marf::MarfedKV; -use crate::clarity_vm::database::HeadersDBConn; -use crate::core::*; -use crate::util_lib::db::{DBConn, FromRow}; +use clarity::vm::clarity::ClarityConnection; use clarity::vm::contexts::OwnedEnvironment; use clarity::vm::contracts::Contract; -use clarity::vm::costs::CostOverflowingMath; +use clarity::vm::costs::{CostOverflowingMath, LimitedCostTracker}; use clarity::vm::database::*; use clarity::vm::errors::{ CheckErrors, Error, IncomparableError, InterpreterError, InterpreterResult, RuntimeErrorType, @@ -37,32 +20,38 @@ use clarity::vm::types::{ Value, NONE, }; use stacks_common::address::AddressHashMode; -use stacks_common::types::Address; -use stacks_common::util::hash::hex_bytes; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::{Sha256Sum, Sha512Trunc256Sum}; - -use crate::net::test::TestPeer; -use crate::util_lib::boot::boot_code_id; -use crate::{ - burnchains::Burnchain, - chainstate::{ - burn::db::sortdb::SortitionDB, - stacks::{events::TransactionOrigin, tests::make_coinbase}, - }, - clarity_vm::{clarity::ClarityBlockConnection, database::marf::WritableMarfStore}, - net::test::TestEventObserver, -}; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, VRFSeed, }; +use stacks_common::types::Address; +use stacks_common::util::hash::{hex_bytes, to_hex, Sha256Sum, Sha512Trunc256Sum}; -use super::{test::*, RawRewardSetEntry}; -use crate::clarity_vm::clarity::Error as ClarityError; - +use super::test::*; +use super::RawRewardSetEntry; +use crate::burnchains::Burnchain; +use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::burn::operations::*; -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::LimitedCostTracker; +use crate::chainstate::burn::{BlockSnapshot, ConsensusHash}; +use crate::chainstate::stacks::address::{PoxAddress, PoxAddressType20, PoxAddressType32}; +use crate::chainstate::stacks::boot::{ + BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET, POX_2_NAME, + POX_3_NAME, +}; +use crate::chainstate::stacks::db::{ + MinerPaymentSchedule, StacksChainState, StacksHeaderInfo, MINER_REWARD_MATURITY, +}; +use crate::chainstate::stacks::events::TransactionOrigin; +use crate::chainstate::stacks::index::marf::MarfConnection; +use crate::chainstate::stacks::index::MarfTrieId; +use crate::chainstate::stacks::tests::make_coinbase; +use crate::chainstate::stacks::*; +use crate::clarity_vm::clarity::{ClarityBlockConnection, Error as ClarityError}; +use crate::clarity_vm::database::marf::{MarfedKV, WritableMarfStore}; +use crate::clarity_vm::database::HeadersDBConn; +use crate::core::*; +use crate::net::test::{TestEventObserver, TestPeer}; +use crate::util_lib::boot::boot_code_id; +use crate::util_lib::db::{DBConn, FromRow}; const USTX_PER_HOLDER: u128 = 1_000_000; diff --git a/stackslib/src/chainstate/stacks/boot/pox_3_tests.rs b/stackslib/src/chainstate/stacks/boot/pox_3_tests.rs index 46618e3a9b..4baf4b74e4 100644 --- a/stackslib/src/chainstate/stacks/boot/pox_3_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/pox_3_tests.rs @@ -1,33 +1,10 @@ use std::collections::{HashMap, HashSet, VecDeque}; -use std::convert::TryFrom; -use std::convert::TryInto; +use std::convert::{TryFrom, TryInto}; -use crate::burnchains::PoxConstants; -use crate::chainstate::burn::BlockSnapshot; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::stacks::address::{PoxAddress, PoxAddressType20, PoxAddressType32}; -use crate::chainstate::stacks::boot::pox_2_tests::{ - check_pox_print_event, check_stacking_state_invariants, generate_pox_clarity_value, - get_partial_stacked, get_reward_cycle_total, get_reward_set_entries_at, get_stacking_state_pox, - get_stacking_state_pox_2, get_stx_account_at, PoxPrintFields, StackingStateCheckData, -}; -use crate::chainstate::stacks::boot::{ - BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET, POX_2_NAME, - POX_3_NAME, -}; -use crate::chainstate::stacks::db::{ - MinerPaymentSchedule, StacksChainState, StacksHeaderInfo, MINER_REWARD_MATURITY, -}; -use crate::chainstate::stacks::index::marf::MarfConnection; -use crate::chainstate::stacks::index::MarfTrieId; -use crate::chainstate::stacks::*; -use crate::clarity_vm::database::marf::MarfedKV; -use crate::clarity_vm::database::HeadersDBConn; -use crate::core::*; -use crate::util_lib::db::{DBConn, FromRow}; +use clarity::vm::clarity::ClarityConnection; use clarity::vm::contexts::OwnedEnvironment; use clarity::vm::contracts::Contract; -use clarity::vm::costs::CostOverflowingMath; +use clarity::vm::costs::{CostOverflowingMath, LimitedCostTracker}; use clarity::vm::database::*; use clarity::vm::errors::{ CheckErrors, Error, IncomparableError, InterpreterError, InterpreterResult, RuntimeErrorType, @@ -43,32 +20,43 @@ use clarity::vm::types::{ Value, NONE, }; use stacks_common::address::AddressHashMode; -use stacks_common::types::Address; -use stacks_common::util::hash::hex_bytes; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::{Sha256Sum, Sha512Trunc256Sum}; - -use crate::net::test::TestPeer; -use crate::util_lib::boot::boot_code_id; -use crate::{ - burnchains::Burnchain, - chainstate::{ - burn::db::sortdb::SortitionDB, - stacks::{events::TransactionOrigin, tests::make_coinbase}, - }, - clarity_vm::{clarity::ClarityBlockConnection, database::marf::WritableMarfStore}, - net::test::TestEventObserver, -}; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, VRFSeed, }; +use stacks_common::types::Address; +use stacks_common::util::hash::{hex_bytes, to_hex, Sha256Sum, Sha512Trunc256Sum}; -use super::{test::*, RawRewardSetEntry}; -use crate::clarity_vm::clarity::Error as ClarityError; - +use super::test::*; +use super::RawRewardSetEntry; +use crate::burnchains::{Burnchain, PoxConstants}; +use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::burn::operations::*; -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::LimitedCostTracker; +use crate::chainstate::burn::{BlockSnapshot, ConsensusHash}; +use crate::chainstate::stacks::address::{PoxAddress, PoxAddressType20, PoxAddressType32}; +use crate::chainstate::stacks::boot::pox_2_tests::{ + check_pox_print_event, check_stacking_state_invariants, generate_pox_clarity_value, + get_partial_stacked, get_reward_cycle_total, get_reward_set_entries_at, get_stacking_state_pox, + get_stacking_state_pox_2, get_stx_account_at, PoxPrintFields, StackingStateCheckData, +}; +use crate::chainstate::stacks::boot::{ + BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET, POX_2_NAME, + POX_3_NAME, +}; +use crate::chainstate::stacks::db::{ + MinerPaymentSchedule, StacksChainState, StacksHeaderInfo, MINER_REWARD_MATURITY, +}; +use crate::chainstate::stacks::events::TransactionOrigin; +use crate::chainstate::stacks::index::marf::MarfConnection; +use crate::chainstate::stacks::index::MarfTrieId; +use crate::chainstate::stacks::tests::make_coinbase; +use crate::chainstate::stacks::*; +use crate::clarity_vm::clarity::{ClarityBlockConnection, Error as ClarityError}; +use crate::clarity_vm::database::marf::{MarfedKV, WritableMarfStore}; +use crate::clarity_vm::database::HeadersDBConn; +use crate::core::*; +use crate::net::test::{TestEventObserver, TestPeer}; +use crate::util_lib::boot::boot_code_id; +use crate::util_lib::db::{DBConn, FromRow}; const USTX_PER_HOLDER: u128 = 1_000_000; diff --git a/stackslib/src/chainstate/stacks/db/accounts.rs b/stackslib/src/chainstate/stacks/db/accounts.rs index 81aa5b18ef..4e499c4a09 100644 --- a/stackslib/src/chainstate/stacks/db/accounts.rs +++ b/stackslib/src/chainstate/stacks/db/accounts.rs @@ -16,25 +16,21 @@ use std::collections::HashMap; +use clarity::vm::database::clarity_store::*; +use clarity::vm::database::*; +use clarity::vm::types::*; use rusqlite::types::ToSql; use rusqlite::Row; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; use crate::burnchains::Address; use crate::chainstate::stacks::db::blocks::*; use crate::chainstate::stacks::db::*; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::*; +use crate::chainstate::stacks::{Error, *}; use crate::clarity::vm::types::StacksAddressExtensions; use crate::clarity_vm::clarity::{ClarityConnection, ClarityTransactionConnection}; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::*; -use clarity::vm::database::clarity_store::*; -use clarity::vm::database::*; -use clarity::vm::types::*; - -use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; - use crate::core::StacksEpochId; +use crate::util_lib::db::{Error as db_error, *}; /// A record of a coin reward for a miner. There will be at most two of these for a miner: one for /// the coinbase + block-txs + confirmed-mblock-txs, and one for the produced-mblock-txs. The @@ -1067,20 +1063,18 @@ impl StacksChainState { #[cfg(test)] mod test { - use crate::burnchains::*; - use crate::chainstate::burn::*; - use crate::chainstate::stacks::db::test::*; - use crate::chainstate::stacks::index::*; - use crate::chainstate::stacks::Error; - use crate::chainstate::stacks::*; - use crate::core::StacksEpochId; use clarity::vm::costs::ExecutionCost; - use stacks_common::util::hash::*; - use clarity::vm::types::StacksAddressExtensions; use stacks_common::types::chainstate::BurnchainHeaderHash; + use stacks_common::util::hash::*; use super::*; + use crate::burnchains::*; + use crate::chainstate::burn::*; + use crate::chainstate::stacks::db::test::*; + use crate::chainstate::stacks::index::*; + use crate::chainstate::stacks::{Error, *}; + use crate::core::StacksEpochId; fn make_dummy_miner_payment_schedule( addr: &StacksAddress, diff --git a/stackslib/src/chainstate/stacks/db/blocks.rs b/stackslib/src/chainstate/stacks/db/blocks.rs index bb2c0f6519..25dcdc9f33 100644 --- a/stackslib/src/chainstate/stacks/db/blocks.rs +++ b/stackslib/src/chainstate/stacks/db/blocks.rs @@ -14,87 +14,66 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::cmp; use std::collections::{HashMap, HashSet}; use std::convert::From; -use std::fmt; -use std::fs; -use std::io; use std::io::prelude::*; use std::io::{Read, Seek, SeekFrom, Write}; use std::path::{Path, PathBuf}; +use std::{cmp, fmt, fs, io}; -use clarity::vm::ast::ASTRules; -use rand::thread_rng; -use rand::Rng; -use rand::RngCore; -use rusqlite::Connection; -use rusqlite::DatabaseName; -use rusqlite::{Error as sqlite_error, OptionalExtension}; +pub use clarity::vm::analysis::errors::{CheckError, CheckErrors}; +use clarity::vm::analysis::run_analysis; +use clarity::vm::clarity::TransactionConnection; +use clarity::vm::contexts::AssetMap; +use clarity::vm::contracts::Contract; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::database::{BurnStateDB, ClarityDatabase, NULL_BURN_STATE_DB}; +use clarity::vm::types::{ + AssetIdentifier, BuffData, PrincipalData, QualifiedContractIdentifier, SequenceData, + StacksAddressExtensions as ClarityStacksAddressExtensions, StandardPrincipalData, TupleData, + TypeSignature, Value, +}; +use rand::{thread_rng, Rng, RngCore}; +use rusqlite::{Connection, DatabaseName, Error as sqlite_error, OptionalExtension}; use serde::Serialize; +use stacks_common::codec::{read_next, write_next, MAX_MESSAGE_LEN}; +use stacks_common::types::chainstate::{ + BurnchainHeaderHash, SortitionId, StacksAddress, StacksBlockId, +}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::retry::BoundReader; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs}; use crate::burnchains::affirmation::AffirmationMap; -use crate::burnchains::db::BurnchainDB; -use crate::burnchains::db::BurnchainHeaderReader; +use crate::burnchains::db::{BurnchainDB, BurnchainHeaderReader}; use crate::chainstate::burn::db::sortdb::*; use crate::chainstate::burn::operations::*; use crate::chainstate::burn::BlockSnapshot; -use crate::chainstate::stacks::address::PoxAddress; +use crate::chainstate::coordinator::BlockEventDispatcher; +use crate::chainstate::stacks::address::{PoxAddress, StacksAddressExtensions}; use crate::chainstate::stacks::db::accounts::MinerReward; use crate::chainstate::stacks::db::transactions::TransactionNonceMismatch; -use crate::chainstate::stacks::db::ExtendedStacksHeader; use crate::chainstate::stacks::db::*; use crate::chainstate::stacks::index::MarfTrieId; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::*; use crate::chainstate::stacks::{ - C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, - C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, + Error, StacksBlockHeader, StacksMicroblockHeader, C32_ADDRESS_VERSION_MAINNET_MULTISIG, + C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_MULTISIG, + C32_ADDRESS_VERSION_TESTNET_SINGLESIG, *, }; use crate::clarity_vm::clarity::{ClarityBlockConnection, ClarityConnection, ClarityInstance}; use crate::clarity_vm::database::SortitionDBRef; -use crate::core::mempool::MemPoolDB; -use crate::core::mempool::MAXIMUM_MEMPOOL_TX_CHAINING; +use crate::core::mempool::{MemPoolDB, MAXIMUM_MEMPOOL_TX_CHAINING}; use crate::core::*; use crate::cost_estimates::EstimatorError; +use crate::monitoring::{set_last_block_transaction_count, set_last_execution_cost_observed}; use crate::net::relay::Relayer; -use crate::net::BlocksInvData; -use crate::net::Error as net_error; -use crate::util_lib::db::u64_to_sql; -use crate::util_lib::db::Error as db_error; +use crate::net::{BlocksInvData, Error as net_error}; +use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::{ query_count, query_int, query_row, query_row_columns, query_row_panic, query_rows, - tx_busy_handler, DBConn, FromColumn, FromRow, + tx_busy_handler, u64_to_sql, DBConn, Error as db_error, FromColumn, FromRow, }; use crate::util_lib::strings::StacksString; -pub use clarity::vm::analysis::errors::{CheckError, CheckErrors}; -use clarity::vm::analysis::run_analysis; -use clarity::vm::clarity::TransactionConnection; -use clarity::vm::contexts::AssetMap; -use clarity::vm::contracts::Contract; -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::database::{BurnStateDB, ClarityDatabase, NULL_BURN_STATE_DB}; -use clarity::vm::types::{ - AssetIdentifier, BuffData, PrincipalData, QualifiedContractIdentifier, SequenceData, - StacksAddressExtensions as ClarityStacksAddressExtensions, StandardPrincipalData, TupleData, - TypeSignature, Value, -}; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::codec::{read_next, write_next}; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::to_hex; -use stacks_common::util::retry::BoundReader; - -use crate::chainstate::coordinator::BlockEventDispatcher; -use crate::chainstate::stacks::address::StacksAddressExtensions; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblockHeader; -use crate::monitoring::{set_last_block_transaction_count, set_last_execution_cost_observed}; -use crate::util_lib::boot::boot_code_id; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::SortitionId; -use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; #[derive(Debug, Clone, PartialEq)] pub struct StagingMicroblock { @@ -6723,9 +6702,15 @@ impl StacksChainState { pub mod test { use std::fs; - use rand::thread_rng; - use rand::Rng; + use clarity::vm::ast::ASTRules; + use clarity::vm::types::StacksAddressExtensions; + use rand::{thread_rng, Rng}; + use serde_json; + use stacks_common::types::chainstate::{BlockHeaderHash, StacksWorkScore}; + use stacks_common::util::hash::*; + use stacks_common::util::retry::*; + use super::*; use crate::burnchains::*; use crate::chainstate::burn::db::sortdb::*; use crate::chainstate::burn::*; @@ -6735,25 +6720,12 @@ pub mod test { use crate::chainstate::stacks::miner::*; use crate::chainstate::stacks::test::*; use crate::chainstate::stacks::tests::*; - use crate::chainstate::stacks::Error as chainstate_error; - use crate::chainstate::stacks::*; + use crate::chainstate::stacks::{Error as chainstate_error, *}; use crate::core::mempool::*; - use crate::net::test::*; - use crate::util_lib::db::Error as db_error; - use crate::util_lib::db::*; - use stacks_common::util::hash::*; - use stacks_common::util::retry::*; - use crate::cost_estimates::metrics::UnitMetric; use crate::cost_estimates::UnitEstimator; - use stacks_common::types::chainstate::{BlockHeaderHash, StacksWorkScore}; - - use super::*; - - use clarity::vm::ast::ASTRules; - use clarity::vm::types::StacksAddressExtensions; - - use serde_json; + use crate::net::test::*; + use crate::util_lib::db::{Error as db_error, *}; pub fn make_empty_coinbase_block(mblock_key: &StacksPrivateKey) -> StacksBlock { let privk = StacksPrivateKey::from_hex( diff --git a/stackslib/src/chainstate/stacks/db/contracts.rs b/stackslib/src/chainstate/stacks/db/contracts.rs index 6b46fa4479..3fd13b3783 100644 --- a/stackslib/src/chainstate/stacks/db/contracts.rs +++ b/stackslib/src/chainstate/stacks/db/contracts.rs @@ -15,43 +15,28 @@ // along with this program. If not, see . use std::collections::{HashMap, HashSet}; -use std::fmt; -use std::fs; -use std::io; use std::io::prelude::*; - -use crate::chainstate::stacks::db::*; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::*; - use std::path::{Path, PathBuf}; - -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::{query_count, query_rows, DBConn}; - -use crate::util_lib::strings::StacksString; - -use stacks_common::util::hash::to_hex; - -use crate::chainstate::burn::db::sortdb::*; - -use crate::net::Error as net_error; - -use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}; - -use clarity::vm::contexts::{AssetMap, OwnedEnvironment}; - -use clarity::vm::analysis::run_analysis; -use clarity::vm::types::{AssetIdentifier, Value}; +use std::{fmt, fs, io}; pub use clarity::vm::analysis::errors::CheckErrors; -use clarity::vm::errors::Error as clarity_vm_error; - -use clarity::vm::database::ClarityDatabase; - +use clarity::vm::analysis::run_analysis; +use clarity::vm::contexts::{AssetMap, OwnedEnvironment}; use clarity::vm::contracts::Contract; +use clarity::vm::database::ClarityDatabase; +use clarity::vm::errors::Error as clarity_vm_error; +use clarity::vm::types::{ + AssetIdentifier, PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, Value, +}; +use stacks_common::util::hash::to_hex; +use crate::chainstate::burn::db::sortdb::*; +use crate::chainstate::stacks::db::*; +use crate::chainstate::stacks::{Error, *}; use crate::clarity_vm::clarity::ClarityConnection; +use crate::net::Error as net_error; +use crate::util_lib::db::{query_count, query_rows, DBConn, Error as db_error}; +use crate::util_lib::strings::StacksString; impl StacksChainState { pub fn get_contract( diff --git a/stackslib/src/chainstate/stacks/db/headers.rs b/stackslib/src/chainstate/stacks/db/headers.rs index 4ab791a1d9..0b5c06c156 100644 --- a/stackslib/src/chainstate/stacks/db/headers.rs +++ b/stackslib/src/chainstate/stacks/db/headers.rs @@ -15,28 +15,23 @@ // along with this program. If not, see . use std::collections::HashMap; -use std::fmt; -use std::fs; -use std::io; use std::io::prelude::*; use std::path::{Path, PathBuf}; +use std::{fmt, fs, io}; -use rusqlite::{types::ToSql, OptionalExtension, Row}; +use clarity::vm::costs::ExecutionCost; +use rusqlite::types::ToSql; +use rusqlite::{OptionalExtension, Row}; +use stacks_common::types::chainstate::{StacksBlockId, StacksWorkScore}; use crate::chainstate::burn::ConsensusHash; use crate::chainstate::stacks::db::*; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::*; -use crate::core::FIRST_BURNCHAIN_CONSENSUS_HASH; -use crate::core::FIRST_STACKS_BLOCK_HASH; -use crate::util_lib::db::Error as db_error; +use crate::chainstate::stacks::{Error, *}; +use crate::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH}; use crate::util_lib::db::{ query_count, query_row, query_row_columns, query_row_panic, query_rows, u64_to_sql, DBConn, - FromColumn, FromRow, + Error as db_error, FromColumn, FromRow, }; -use clarity::vm::costs::ExecutionCost; - -use stacks_common::types::chainstate::{StacksBlockId, StacksWorkScore}; impl FromRow for StacksBlockHeader { fn from_row<'a>(row: &'a Row) -> Result { diff --git a/stackslib/src/chainstate/stacks/db/mod.rs b/stackslib/src/chainstate/stacks/db/mod.rs index 80bac05476..5e1996f3bb 100644 --- a/stackslib/src/chainstate/stacks/db/mod.rs +++ b/stackslib/src/chainstate/stacks/db/mod.rs @@ -14,30 +14,41 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::collections::{btree_map::Entry, BTreeMap, HashSet}; -use std::fmt; -use std::fs; -use std::io; +use std::collections::btree_map::Entry; +use std::collections::{BTreeMap, HashSet}; use std::io::prelude::*; use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; +use std::{fmt, fs, io}; +use clarity::vm::analysis::analysis_db::AnalysisDatabase; +use clarity::vm::analysis::run_analysis; use clarity::vm::ast::ASTRules; +use clarity::vm::clarity::TransactionConnection; +use clarity::vm::contexts::OwnedEnvironment; +use clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; +use clarity::vm::database::{ + BurnStateDB, ClarityDatabase, HeadersDB, STXBalance, SqliteConnection, NULL_BURN_STATE_DB, +}; +use clarity::vm::events::*; +use clarity::vm::representations::{ClarityName, ContractName}; +use clarity::vm::types::TupleData; +use clarity::vm::Value; use rusqlite::types::ToSql; -use rusqlite::Connection; -use rusqlite::OpenFlags; -use rusqlite::OptionalExtension; -use rusqlite::Row; -use rusqlite::Transaction; -use rusqlite::NO_PARAMS; +use rusqlite::{Connection, OpenFlags, OptionalExtension, Row, Transaction, NO_PARAMS}; +use serde::de::Error as de_Error; +use serde::Deserialize; +use stacks_common::codec::{read_next, write_next, StacksMessageCodec}; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId, TrieHash}; +use stacks_common::util; +use stacks_common::util::hash::{hex_bytes, to_hex}; use crate::burnchains::bitcoin::address::{BitcoinAddress, LegacyBitcoinAddress}; use crate::burnchains::{Address, Burnchain, BurnchainParameters, PoxConstants}; -use crate::chainstate::burn::db::sortdb::BlockHeaderCache; -use crate::chainstate::burn::db::sortdb::*; -use crate::chainstate::burn::db::sortdb::{SortitionDB, SortitionDBConn}; +use crate::chainstate::burn::db::sortdb::{BlockHeaderCache, SortitionDB, SortitionDBConn, *}; use crate::chainstate::burn::operations::{DelegateStxOp, StackStxOp, TransferStxOp}; -use crate::chainstate::burn::ConsensusHash; +use crate::chainstate::burn::{ConsensusHash, ConsensusHashExtensions}; +use crate::chainstate::stacks::address::StacksAddressExtensions; use crate::chainstate::stacks::boot::*; use crate::chainstate::stacks::db::accounts::*; use crate::chainstate::stacks::db::blocks::*; @@ -48,58 +59,27 @@ use crate::chainstate::stacks::index::marf::{ BLOCK_HEIGHT_TO_HASH_MAPPING_KEY, MARF, }; use crate::chainstate::stacks::index::storage::TrieFileStorage; -use crate::chainstate::stacks::index::MarfTrieId; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::*; +use crate::chainstate::stacks::index::{ClarityMarfTrieId, MARFValue, MarfTrieId}; use crate::chainstate::stacks::{ - C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, - C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, + Error, StacksBlockHeader, StacksMicroblockHeader, C32_ADDRESS_VERSION_MAINNET_MULTISIG, + C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_MULTISIG, + C32_ADDRESS_VERSION_TESTNET_SINGLESIG, *, }; use crate::clarity_vm::clarity::{ ClarityBlockConnection, ClarityConnection, ClarityInstance, ClarityReadOnlyConnection, - Error as clarity_error, + Error as clarity_error, PreCommitClarityBlock, }; +use crate::clarity_vm::database::marf::MarfedKV; +use crate::clarity_vm::database::HeadersDBConn; use crate::core::*; use crate::monitoring; use crate::net::atlas::BNS_CHARS_REGEX; use crate::net::Error as net_error; -use crate::util_lib::db::Error as db_error; +use crate::util_lib::boot::{boot_code_acc, boot_code_addr, boot_code_id, boot_code_tx_auth}; use crate::util_lib::db::{ - query_count, query_row, tx_begin_immediate, tx_busy_handler, DBConn, DBTx, FromColumn, FromRow, - IndexDBConn, IndexDBTx, + query_count, query_row, tx_begin_immediate, tx_busy_handler, DBConn, DBTx, Error as db_error, + FromColumn, FromRow, IndexDBConn, IndexDBTx, }; -use clarity::vm::analysis::analysis_db::AnalysisDatabase; -use clarity::vm::analysis::run_analysis; -use clarity::vm::clarity::TransactionConnection; -use clarity::vm::contexts::OwnedEnvironment; -use clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; -use clarity::vm::database::{ - BurnStateDB, ClarityDatabase, HeadersDB, STXBalance, SqliteConnection, NULL_BURN_STATE_DB, -}; - -use crate::clarity_vm::clarity::PreCommitClarityBlock; -use clarity::vm::events::*; -use clarity::vm::representations::ClarityName; -use clarity::vm::representations::ContractName; -use clarity::vm::types::TupleData; -use stacks_common::util; -use stacks_common::util::hash::{hex_bytes, to_hex}; - -use crate::chainstate::burn::ConsensusHashExtensions; -use crate::chainstate::stacks::address::StacksAddressExtensions; -use crate::chainstate::stacks::index::{ClarityMarfTrieId, MARFValue}; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblockHeader; -use crate::clarity_vm::database::marf::MarfedKV; -use crate::clarity_vm::database::HeadersDBConn; -use crate::util_lib::boot::{boot_code_acc, boot_code_addr, boot_code_id, boot_code_tx_auth}; -use clarity::vm::Value; -use stacks_common::types::chainstate::{StacksAddress, StacksBlockId, TrieHash}; - -use stacks_common::codec::{read_next, write_next, StacksMessageCodec}; - -use serde::de::Error as de_Error; -use serde::Deserialize; pub mod accounts; pub mod blocks; @@ -2526,14 +2506,13 @@ impl StacksChainState { pub mod test { use std::{env, fs}; - use crate::chainstate::stacks::db::*; - use crate::chainstate::stacks::*; use clarity::vm::test_util::TEST_BURN_STATE_DB; use stx_genesis::GenesisData; - use crate::util_lib::boot::boot_code_test_addr; - use super::*; + use crate::chainstate::stacks::db::*; + use crate::chainstate::stacks::*; + use crate::util_lib::boot::boot_code_test_addr; pub fn instantiate_chainstate( mainnet: bool, diff --git a/stackslib/src/chainstate/stacks/db/transactions.rs b/stackslib/src/chainstate/stacks/db/transactions.rs index 5dfa3e1793..ac11e74897 100644 --- a/stackslib/src/chainstate/stacks/db/transactions.rs +++ b/stackslib/src/chainstate/stacks/db/transactions.rs @@ -15,50 +15,40 @@ // along with this program. If not, see . use std::collections::{HashMap, HashSet}; -use std::fmt; -use std::fs; -use std::io; use std::io::prelude::*; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; +use std::{fmt, fs, io}; -use crate::chainstate::burn::db::sortdb::*; -use crate::chainstate::stacks::db::*; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::*; -use crate::clarity_vm::clarity::{ - ClarityBlockConnection, ClarityConnection, ClarityInstance, ClarityTransactionConnection, - Error as clarity_error, -}; -use crate::net::Error as net_error; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::{query_count, query_rows, DBConn}; -use clarity::vm::ast::ASTRules; -use stacks_common::util::hash::to_hex; - -use crate::chainstate::stacks::StacksMicroblockHeader; -use crate::util_lib::strings::{StacksString, VecDisplay}; use clarity::vm::analysis::run_analysis; use clarity::vm::analysis::types::ContractAnalysis; +use clarity::vm::ast::errors::ParseErrors; +use clarity::vm::ast::ASTRules; use clarity::vm::clarity::TransactionConnection; use clarity::vm::contexts::{AssetMap, AssetMapEntry, Environment}; use clarity::vm::contracts::Contract; -use clarity::vm::costs::cost_functions; use clarity::vm::costs::cost_functions::ClarityCostFunction; -use clarity::vm::costs::runtime_cost; -use clarity::vm::costs::CostTracker; -use clarity::vm::costs::ExecutionCost; +use clarity::vm::costs::{cost_functions, runtime_cost, CostTracker, ExecutionCost}; use clarity::vm::database::ClarityDatabase; use clarity::vm::errors::Error as InterpreterError; -use clarity::vm::representations::ClarityName; -use clarity::vm::representations::ContractName; -use clarity::vm::types::StacksAddressExtensions as ClarityStacksAddressExt; +use clarity::vm::representations::{ClarityName, ContractName}; use clarity::vm::types::{ AssetIdentifier, BuffData, PrincipalData, QualifiedContractIdentifier, SequenceData, - StandardPrincipalData, TupleData, TypeSignature, Value, + StacksAddressExtensions as ClarityStacksAddressExt, StandardPrincipalData, TupleData, + TypeSignature, Value, }; +use stacks_common::util::hash::to_hex; -use clarity::vm::ast::errors::ParseErrors; +use crate::chainstate::burn::db::sortdb::*; +use crate::chainstate::stacks::db::*; +use crate::chainstate::stacks::{Error, StacksMicroblockHeader, *}; +use crate::clarity_vm::clarity::{ + ClarityBlockConnection, ClarityConnection, ClarityInstance, ClarityTransactionConnection, + Error as clarity_error, +}; +use crate::net::Error as net_error; +use crate::util_lib::db::{query_count, query_rows, DBConn, Error as db_error}; +use crate::util_lib::strings::{StacksString, VecDisplay}; impl StacksTransactionReceipt { pub fn from_stx_transfer( @@ -1458,28 +1448,24 @@ impl StacksChainState { #[cfg(test)] pub mod test { + use clarity::vm::clarity::TransactionConnection; + use clarity::vm::contracts::Contract; + use clarity::vm::representations::{ClarityName, ContractName}; + use clarity::vm::test_util::{UnitTestBurnStateDB, TEST_BURN_STATE_DB}; use clarity::vm::tests::TEST_HEADER_DB; + use clarity::vm::types::*; use rand::Rng; + use stacks_common::types::chainstate::SortitionId; + use stacks_common::util::hash::*; + use super::*; use crate::burnchains::Address; use crate::chainstate::stacks::boot::*; use crate::chainstate::stacks::db::test::*; use crate::chainstate::stacks::index::storage::*; use crate::chainstate::stacks::index::*; - use crate::chainstate::stacks::Error; - use crate::chainstate::stacks::*; + use crate::chainstate::stacks::{Error, *}; use crate::chainstate::*; - use clarity::vm::clarity::TransactionConnection; - use clarity::vm::contracts::Contract; - use clarity::vm::representations::ClarityName; - use clarity::vm::representations::ContractName; - use clarity::vm::test_util::UnitTestBurnStateDB; - use clarity::vm::test_util::TEST_BURN_STATE_DB; - use clarity::vm::types::*; - use stacks_common::types::chainstate::SortitionId; - use stacks_common::util::hash::*; - - use super::*; pub const TestBurnStateDB_20: UnitTestBurnStateDB = UnitTestBurnStateDB { epoch_id: StacksEpochId::Epoch20, diff --git a/stackslib/src/chainstate/stacks/db/unconfirmed.rs b/stackslib/src/chainstate/stacks/db/unconfirmed.rs index 9033feb573..c3d11c9627 100644 --- a/stackslib/src/chainstate/stacks/db/unconfirmed.rs +++ b/stackslib/src/chainstate/stacks/db/unconfirmed.rs @@ -20,27 +20,22 @@ use std::collections::{HashMap, HashSet}; use std::fs; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::database::{BurnStateDB, HeadersDB, NULL_BURN_STATE_DB, NULL_HEADER_DB}; +use stacks_common::types::chainstate::{BurnchainHeaderHash, StacksBlockId}; + +use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::accounts::*; use crate::chainstate::stacks::db::blocks::*; use crate::chainstate::stacks::db::*; use crate::chainstate::stacks::events::*; use crate::chainstate::stacks::index::marf::MARFOpenOpts; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::*; +use crate::chainstate::stacks::{Error, *}; use crate::clarity_vm::clarity::{ClarityInstance, Error as clarity_error}; +use crate::clarity_vm::database::marf::MarfedKV; use crate::core::*; use crate::net::Error as net_error; use crate::util_lib::db::Error as db_error; -use clarity::vm::costs::ExecutionCost; -use clarity::vm::database::BurnStateDB; -use clarity::vm::database::HeadersDB; -use clarity::vm::database::NULL_BURN_STATE_DB; -use clarity::vm::database::NULL_HEADER_DB; - -use crate::chainstate::burn::db::sortdb::SortitionDB; -use crate::clarity_vm::database::marf::MarfedKV; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; pub type UnconfirmedTxMap = HashMap; @@ -646,6 +641,9 @@ impl StacksChainState { mod test { use std::fs; + use clarity::vm::types::StacksAddressExtensions; + + use super::*; use crate::burnchains::PublicKey; use crate::chainstate::burn::db::sortdb::*; use crate::chainstate::burn::db::*; @@ -656,15 +654,11 @@ mod test { use crate::chainstate::stacks::index::*; use crate::chainstate::stacks::miner::*; use crate::chainstate::stacks::tests::make_coinbase; - use crate::chainstate::stacks::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; - use crate::chainstate::stacks::*; + use crate::chainstate::stacks::{C32_ADDRESS_VERSION_TESTNET_SINGLESIG, *}; use crate::core::mempool::*; use crate::core::*; use crate::net::relay::*; use crate::net::test::*; - use clarity::vm::types::StacksAddressExtensions; - - use super::*; #[test] fn test_unconfirmed_refresh_one_microblock_stx_transfer() { diff --git a/stackslib/src/chainstate/stacks/events.rs b/stackslib/src/chainstate/stacks/events.rs index 7afbdad990..6ea4f694ad 100644 --- a/stackslib/src/chainstate/stacks/events.rs +++ b/stackslib/src/chainstate/stacks/events.rs @@ -1,8 +1,6 @@ -use crate::burnchains::Txid; -use crate::chainstate::stacks::StacksMicroblockHeader; -use crate::chainstate::stacks::StacksTransaction; use clarity::vm::analysis::ContractAnalysis; use clarity::vm::costs::ExecutionCost; +pub use clarity::vm::events::StacksTransactionEvent; use clarity::vm::types::{ AssetIdentifier, PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, Value, }; @@ -10,8 +8,9 @@ use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; use stacks_common::util::hash::to_hex; +use crate::burnchains::Txid; use crate::chainstate::burn::operations::BlockstackOperationType; -pub use clarity::vm::events::StacksTransactionEvent; +use crate::chainstate::stacks::{StacksMicroblockHeader, StacksTransaction}; #[derive(Debug, Clone, PartialEq)] pub enum TransactionOrigin { diff --git a/stackslib/src/chainstate/stacks/index/bits.rs b/stackslib/src/chainstate/stacks/index/bits.rs index c4ece80ce6..88869d4172 100644 --- a/stackslib/src/chainstate/stacks/index/bits.rs +++ b/stackslib/src/chainstate/stacks/index/bits.rs @@ -14,30 +14,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::error; /// This file contains low-level methods for reading and manipulating Trie node data. use std::fmt; -use std::io; use std::io::{ErrorKind, Read, Seek, SeekFrom, Write}; +use std::{error, io}; -use sha2::Digest; -use sha2::Sha512_256 as TrieHasher; - -use crate::chainstate::stacks::index::node::{ - clear_backptr, ConsensusSerializable, TrieNode16, TrieNode256, TrieNode4, TrieNode48, - TrieNodeID, TrieNodeType, TriePtr, TRIEPTR_SIZE, +use sha2::{Digest, Sha512_256 as TrieHasher}; +use stacks_common::types::chainstate::{ + TrieHash, BLOCK_HEADER_HASH_ENCODED_SIZE, TRIEHASH_ENCODED_SIZE, }; -use crate::chainstate::stacks::index::node::{TrieNode, TRIEPATH_MAX_LEN}; -use crate::chainstate::stacks::index::storage::{TrieFileStorage, TrieStorageConnection}; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::TrieLeaf; -use crate::chainstate::stacks::index::{BlockMap, MarfTrieId}; use stacks_common::util::hash::to_hex; use stacks_common::util::log; use stacks_common::util::macros::is_trace; -use stacks_common::types::chainstate::BLOCK_HEADER_HASH_ENCODED_SIZE; -use stacks_common::types::chainstate::{TrieHash, TRIEHASH_ENCODED_SIZE}; +use crate::chainstate::stacks::index::node::{ + clear_backptr, ConsensusSerializable, TrieNode, TrieNode16, TrieNode256, TrieNode4, TrieNode48, + TrieNodeID, TrieNodeType, TriePtr, TRIEPATH_MAX_LEN, TRIEPTR_SIZE, +}; +use crate::chainstate::stacks::index::storage::{TrieFileStorage, TrieStorageConnection}; +use crate::chainstate::stacks::index::{BlockMap, Error, MarfTrieId, TrieLeaf}; /// Get the size of a Trie path (note that a Trie path is 32 bytes long, and can definitely _not_ /// be over 255 bytes). diff --git a/stackslib/src/chainstate/stacks/index/cache.rs b/stackslib/src/chainstate/stacks/index/cache.rs index cc0d4dbf75..3763f15c6b 100644 --- a/stackslib/src/chainstate/stacks/index/cache.rs +++ b/stackslib/src/chainstate/stacks/index/cache.rs @@ -17,25 +17,23 @@ use std::char::from_digit; use std::collections::{HashMap, HashSet, VecDeque}; use std::convert::{TryFrom, TryInto}; -use std::env; -use std::fmt; -use std::fs; use std::hash::{Hash, Hasher}; -use std::io; use std::io::{BufWriter, Cursor, Read, Seek, SeekFrom, Write}; use std::iter::FromIterator; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; -use std::os; use std::path::{Path, PathBuf}; use std::time::SystemTime; -use std::{cmp, error}; +use std::{cmp, env, error, fmt, fs, io, os}; +use rusqlite::types::{FromSql, ToSql}; use rusqlite::{ - types::{FromSql, ToSql}, Connection, Error as SqliteError, ErrorCode as SqliteErrorCode, OpenFlags, OptionalExtension, Transaction, NO_PARAMS, }; +use stacks_common::types::chainstate::{ + BlockHeaderHash, TrieHash, BLOCK_HEADER_HASH_ENCODED_SIZE, TRIEHASH_ENCODED_SIZE, +}; use crate::chainstate::stacks::index::bits::{ get_node_byte_len, get_node_hash, read_block_identifier, read_hash_bytes, read_node_hash_bytes, @@ -45,19 +43,11 @@ use crate::chainstate::stacks::index::node::{ clear_backptr, is_backptr, set_backptr, TrieNode, TrieNode16, TrieNode256, TrieNode4, TrieNode48, TrieNodeID, TrieNodeType, TriePath, TriePtr, }; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::TrieLeaf; -use crate::chainstate::stacks::index::{trie_sql, ClarityMarfTrieId, MarfTrieId}; -use crate::util_lib::db::sql_pragma; -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::tx_begin_immediate; -use crate::util_lib::db::tx_busy_handler; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::SQLITE_MMAP_SIZE; - -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BLOCK_HEADER_HASH_ENCODED_SIZE; -use stacks_common::types::chainstate::{TrieHash, TRIEHASH_ENCODED_SIZE}; +use crate::chainstate::stacks::index::{trie_sql, ClarityMarfTrieId, Error, MarfTrieId, TrieLeaf}; +use crate::util_lib::db::{ + sql_pragma, sqlite_open, tx_begin_immediate, tx_busy_handler, Error as db_error, + SQLITE_MMAP_SIZE, +}; /// Fully-qualified address of a Trie node. Includes both the block's blob rowid and the pointer within the /// block's blob as to where it is stored. @@ -342,22 +332,18 @@ impl TrieCache { pub mod test { use std::collections::VecDeque; use std::fs; + use std::time::SystemTime; + + use rand::{thread_rng, Rng}; + use sha2::Digest; + use stacks_common::util::hash::Sha512Trunc256Sum; + use super::*; use crate::chainstate::stacks::index::marf::*; use crate::chainstate::stacks::index::node::*; use crate::chainstate::stacks::index::storage::*; use crate::chainstate::stacks::index::*; - use super::*; - - use rand::thread_rng; - use rand::Rng; - - use sha2::Digest; - use stacks_common::util::hash::Sha512Trunc256Sum; - - use std::time::SystemTime; - /// Deterministic random keys to insert pub fn make_test_insert_data( num_inserts_per_block: u64, diff --git a/stackslib/src/chainstate/stacks/index/file.rs b/stackslib/src/chainstate/stacks/index/file.rs index df84a9dadb..99df760167 100644 --- a/stackslib/src/chainstate/stacks/index/file.rs +++ b/stackslib/src/chainstate/stacks/index/file.rs @@ -17,26 +17,24 @@ use std::char::from_digit; use std::collections::{HashMap, HashSet, VecDeque}; use std::convert::{TryFrom, TryInto}; -use std::env; -use std::fmt; -use std::fs; use std::fs::OpenOptions; use std::hash::{Hash, Hasher}; -use std::io; use std::io::{BufWriter, Cursor, Read, Seek, SeekFrom, Write}; use std::iter::FromIterator; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; -use std::os; use std::path::{Path, PathBuf}; use std::time::SystemTime; -use std::{cmp, error}; +use std::{cmp, env, error, fmt, fs, io, os}; +use rusqlite::types::{FromSql, ToSql}; use rusqlite::{ - types::{FromSql, ToSql}, Connection, Error as SqliteError, ErrorCode as SqliteErrorCode, OpenFlags, OptionalExtension, Transaction, NO_PARAMS, }; +use stacks_common::types::chainstate::{ + BlockHeaderHash, TrieHash, BLOCK_HEADER_HASH_ENCODED_SIZE, TRIEHASH_ENCODED_SIZE, +}; use crate::chainstate::stacks::index::bits::{ get_node_byte_len, get_node_hash, read_block_identifier, read_hash_bytes, read_node_hash_bytes, @@ -47,23 +45,12 @@ use crate::chainstate::stacks::index::node::{ clear_backptr, is_backptr, set_backptr, TrieNode, TrieNode16, TrieNode256, TrieNode4, TrieNode48, TrieNodeID, TrieNodeType, TriePath, TriePtr, }; -use crate::chainstate::stacks::index::storage::NodeHashReader; -use crate::chainstate::stacks::index::storage::TrieStorageConnection; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::TrieLeaf; -use crate::chainstate::stacks::index::{trie_sql, ClarityMarfTrieId, MarfTrieId}; - -use crate::util_lib::db::sql_pragma; -use crate::util_lib::db::sql_vacuum; -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::tx_begin_immediate; -use crate::util_lib::db::tx_busy_handler; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::SQLITE_MMAP_SIZE; - -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BLOCK_HEADER_HASH_ENCODED_SIZE; -use stacks_common::types::chainstate::{TrieHash, TRIEHASH_ENCODED_SIZE}; +use crate::chainstate::stacks::index::storage::{NodeHashReader, TrieStorageConnection}; +use crate::chainstate::stacks::index::{trie_sql, ClarityMarfTrieId, Error, MarfTrieId, TrieLeaf}; +use crate::util_lib::db::{ + sql_pragma, sql_vacuum, sqlite_open, tx_begin_immediate, tx_busy_handler, Error as db_error, + SQLITE_MMAP_SIZE, +}; /// Mapping between block IDs and trie offsets pub type TrieIdOffsets = HashMap; diff --git a/stackslib/src/chainstate/stacks/index/marf.rs b/stackslib/src/chainstate/stacks/index/marf.rs index 976dd69c2e..6cec632373 100644 --- a/stackslib/src/chainstate/stacks/index/marf.rs +++ b/stackslib/src/chainstate/stacks/index/marf.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::error; -use std::fmt; -use std::fs; -use std::io; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use std::ops::DerefMut; use std::path::PathBuf; +use std::{error, fmt, fs, io}; use rusqlite::{Connection, Transaction}; use sha2::Digest; +use stacks_common::types::chainstate::{BlockHeaderHash, TrieHash, TRIEHASH_ENCODED_SIZE}; +use stacks_common::util::hash::Sha512Trunc256Sum; +use stacks_common::util::log; use crate::chainstate::stacks::index::bits::{get_leaf_hash, get_node_hash, read_root_hash}; use crate::chainstate::stacks::index::node::{ @@ -34,18 +34,10 @@ use crate::chainstate::stacks::index::storage::{ TrieFileStorage, TrieHashCalculationMode, TrieStorageConnection, TrieStorageTransaction, }; use crate::chainstate::stacks::index::trie::Trie; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::MARFValue; -use crate::chainstate::stacks::index::MarfTrieId; +use crate::chainstate::stacks::index::{ + ClarityMarfTrieId, Error, MARFValue, MarfTrieId, TrieHashExtension, TrieLeaf, TrieMerkleProof, +}; use crate::util_lib::db::Error as db_error; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::log; - -use crate::chainstate::stacks::index::TrieHashExtension; -use crate::chainstate::stacks::index::{ClarityMarfTrieId, TrieLeaf, TrieMerkleProof}; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::TRIEHASH_ENCODED_SIZE; pub const BLOCK_HASH_TO_HEIGHT_MAPPING_KEY: &str = "__MARF_BLOCK_HASH_TO_HEIGHT"; pub const BLOCK_HEIGHT_TO_HASH_MAPPING_KEY: &str = "__MARF_BLOCK_HEIGHT_TO_HASH"; diff --git a/stackslib/src/chainstate/stacks/index/mod.rs b/stackslib/src/chainstate/stacks/index/mod.rs index 734f2bc875..a712ee01a8 100644 --- a/stackslib/src/chainstate/stacks/index/mod.rs +++ b/stackslib/src/chainstate/stacks/index/mod.rs @@ -14,25 +14,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::error; -use std::fmt; use std::hash::Hash; -use std::io; use std::io::{Seek, SeekFrom}; -use std::ptr; +use std::{error, fmt, io, ptr}; -use sha2::Digest; -use sha2::Sha512_256 as TrieHasher; - -use crate::util_lib::db::Error as db_error; +use sha2::{Digest, Sha512_256 as TrieHasher}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksBlockId, TrieHash, + TRIEHASH_ENCODED_SIZE, +}; use stacks_common::util::hash::to_hex; use stacks_common::util::log; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::SortitionId; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::{TrieHash, TRIEHASH_ENCODED_SIZE}; +use crate::util_lib::db::Error as db_error; pub mod bits; pub mod cache; diff --git a/stackslib/src/chainstate/stacks/index/node.rs b/stackslib/src/chainstate/stacks/index/node.rs index 712bee82f3..ece5943949 100644 --- a/stackslib/src/chainstate/stacks/index/node.rs +++ b/stackslib/src/chainstate/stacks/index/node.rs @@ -16,31 +16,26 @@ use std::char::from_digit; use std::collections::{HashMap, HashSet, VecDeque}; -use std::error; -use std::fmt; -use std::io; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +use std::{error, fmt, io}; use sha2::Digest; - -use crate::chainstate::stacks::index::bits::{ - get_path_byte_len, get_ptrs_byte_len, path_from_bytes, ptrs_from_bytes, write_path_to_bytes, +use stacks_common::codec::{read_next, Error as codec_error, StacksMessageCodec}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, TrieHash, BLOCK_HEADER_HASH_ENCODED_SIZE, TRIEHASH_ENCODED_SIZE, }; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::{BlockMap, MarfTrieId, TrieHasher}; use stacks_common::util::hash::to_hex; use stacks_common::util::slice_partialeq; -use crate::chainstate::stacks::index::TrieHashExtension; +use crate::chainstate::stacks::index::bits::{ + get_path_byte_len, get_ptrs_byte_len, path_from_bytes, ptrs_from_bytes, write_path_to_bytes, +}; use crate::chainstate::stacks::index::{ - ClarityMarfTrieId, MARFValue, TrieLeaf, MARF_VALUE_ENCODED_SIZE, + BlockMap, ClarityMarfTrieId, Error, MARFValue, MarfTrieId, TrieHashExtension, TrieHasher, + TrieLeaf, MARF_VALUE_ENCODED_SIZE, }; -use stacks_common::codec::{read_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BLOCK_HEADER_HASH_ENCODED_SIZE; -use stacks_common::types::chainstate::{TrieHash, TRIEHASH_ENCODED_SIZE}; #[derive(Debug, Clone, PartialEq)] pub enum CursorError { diff --git a/stackslib/src/chainstate/stacks/index/proofs.rs b/stackslib/src/chainstate/stacks/index/proofs.rs index ee5f8fc1fd..9348a8b4f9 100644 --- a/stackslib/src/chainstate/stacks/index/proofs.rs +++ b/stackslib/src/chainstate/stacks/index/proofs.rs @@ -16,17 +16,19 @@ use std::char::from_digit; use std::collections::{HashMap, HashSet, VecDeque}; -use std::error; -use std::fmt; -use std::fs; -use std::io; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; +use std::{error, fmt, fs, io}; -use sha2::Digest; -use sha2::Sha512_256 as TrieHasher; +use sha2::{Digest, Sha512_256 as TrieHasher}; +use stacks_common::codec::{read_next, Error as codec_error, StacksMessageCodec}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, TrieHash, BLOCK_HEADER_HASH_ENCODED_SIZE, TRIEHASH_ENCODED_SIZE, +}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::slice_partialeq; use crate::chainstate::stacks::index::bits::{ get_leaf_hash, get_node_hash, read_root_hash, write_path_to_bytes, @@ -39,21 +41,10 @@ use crate::chainstate::stacks::index::node::{ }; use crate::chainstate::stacks::index::storage::{TrieFileStorage, TrieStorageConnection}; use crate::chainstate::stacks::index::trie::Trie; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::{BlockMap, MarfTrieId}; -use stacks_common::util::hash::to_hex; -use stacks_common::util::slice_partialeq; - -use crate::chainstate::stacks::index::TrieHashExtension; use crate::chainstate::stacks::index::{ - ClarityMarfTrieId, MARFValue, ProofTrieNode, ProofTriePtr, TrieLeaf, TrieMerkleProof, - TrieMerkleProofType, + BlockMap, ClarityMarfTrieId, Error, MARFValue, MarfTrieId, ProofTrieNode, ProofTriePtr, + TrieHashExtension, TrieLeaf, TrieMerkleProof, TrieMerkleProofType, }; -use stacks_common::codec::{read_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BLOCK_HEADER_HASH_ENCODED_SIZE; - -use stacks_common::types::chainstate::{TrieHash, TRIEHASH_ENCODED_SIZE}; impl ConsensusSerializable<()> for ProofTrieNode { fn write_consensus_bytes( diff --git a/stackslib/src/chainstate/stacks/index/storage.rs b/stackslib/src/chainstate/stacks/index/storage.rs index 40ebed90ac..c39976419e 100644 --- a/stackslib/src/chainstate/stacks/index/storage.rs +++ b/stackslib/src/chainstate/stacks/index/storage.rs @@ -17,34 +17,33 @@ use std::char::from_digit; use std::collections::{HashMap, HashSet, VecDeque}; use std::convert::{TryFrom, TryInto}; -use std::env; -use std::fmt; -use std::fs; use std::hash::{Hash, Hasher}; -use std::io; use std::io::{BufWriter, Cursor, Read, Seek, SeekFrom, Write}; use std::iter::FromIterator; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; -use std::os; use std::path::{Path, PathBuf}; use std::time::SystemTime; -use std::{cmp, error}; +use std::{cmp, env, error, fmt, fs, io, os}; +use rusqlite::types::{FromSql, ToSql}; use rusqlite::{ - types::{FromSql, ToSql}, Connection, Error as SqliteError, ErrorCode as SqliteErrorCode, OpenFlags, OptionalExtension, Transaction, NO_PARAMS, }; use sha2::Digest; +use stacks_common::types::chainstate::{ + BlockHeaderHash, TrieHash, BLOCK_HEADER_HASH_ENCODED_SIZE, TRIEHASH_ENCODED_SIZE, +}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::log; use crate::chainstate::stacks::index::bits::{ get_node_byte_len, get_node_hash, read_block_identifier, read_hash_bytes, read_node_hash_bytes, read_nodetype, read_root_hash, write_nodetype_bytes, }; use crate::chainstate::stacks::index::cache::*; -use crate::chainstate::stacks::index::file::TrieFile; -use crate::chainstate::stacks::index::file::TrieFileNodeHashReader; +use crate::chainstate::stacks::index::file::{TrieFile, TrieFileNodeHashReader}; use crate::chainstate::stacks::index::marf::MARFOpenOpts; use crate::chainstate::stacks::index::node::{ clear_backptr, is_backptr, set_backptr, TrieNode, TrieNode16, TrieNode256, TrieNode4, @@ -52,25 +51,14 @@ use crate::chainstate::stacks::index::node::{ }; use crate::chainstate::stacks::index::profile::TrieBenchmark; use crate::chainstate::stacks::index::trie::Trie; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::TrieHasher; -use crate::chainstate::stacks::index::{trie_sql, BlockMap, MarfTrieId}; -use crate::util_lib::db::sql_pragma; -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::tx_begin_immediate; -use crate::util_lib::db::tx_busy_handler; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::SQLITE_MARF_PAGE_SIZE; -use crate::util_lib::db::SQLITE_MMAP_SIZE; - -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; - -use crate::chainstate::stacks::index::TrieHashExtension; -use crate::chainstate::stacks::index::{ClarityMarfTrieId, TrieLeaf}; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BLOCK_HEADER_HASH_ENCODED_SIZE; -use stacks_common::types::chainstate::{TrieHash, TRIEHASH_ENCODED_SIZE}; +use crate::chainstate::stacks::index::{ + trie_sql, BlockMap, ClarityMarfTrieId, Error, MarfTrieId, TrieHashExtension, TrieHasher, + TrieLeaf, +}; +use crate::util_lib::db::{ + sql_pragma, sqlite_open, tx_begin_immediate, tx_busy_handler, Error as db_error, + SQLITE_MARF_PAGE_SIZE, SQLITE_MMAP_SIZE, +}; /// A trait for reading the hash of a node into a given Write impl, given the pointer to a node in /// a trie. diff --git a/stackslib/src/chainstate/stacks/index/test/cache.rs b/stackslib/src/chainstate/stacks/index/test/cache.rs index 224de0ea93..5a0bc41d00 100644 --- a/stackslib/src/chainstate/stacks/index/test/cache.rs +++ b/stackslib/src/chainstate/stacks/index/test/cache.rs @@ -14,23 +14,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::chainstate::stacks::index::marf::*; -use crate::chainstate::stacks::index::node::*; -use crate::chainstate::stacks::index::storage::*; -use crate::chainstate::stacks::index::*; -use std::cmp; use std::collections::VecDeque; -use std::fs; - -use super::*; - -use rand::thread_rng; -use rand::Rng; +use std::time::SystemTime; +use std::{cmp, fs}; +use rand::{thread_rng, Rng}; use sha2::Digest; use stacks_common::util::hash::Sha512Trunc256Sum; -use std::time::SystemTime; +use super::*; +use crate::chainstate::stacks::index::marf::*; +use crate::chainstate::stacks::index::node::*; +use crate::chainstate::stacks::index::storage::*; +use crate::chainstate::stacks::index::*; /// Deterministic random keys to insert pub fn make_test_insert_data( diff --git a/stackslib/src/chainstate/stacks/index/test/file.rs b/stackslib/src/chainstate/stacks/index/test/file.rs index 7f76c63a44..499198aca5 100644 --- a/stackslib/src/chainstate/stacks/index/test/file.rs +++ b/stackslib/src/chainstate/stacks/index/test/file.rs @@ -14,6 +14,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::fs; + +use rusqlite::{Connection, OpenFlags}; + +use super::*; use crate::chainstate::stacks::index::cache::test::make_test_insert_data; use crate::chainstate::stacks::index::cache::*; use crate::chainstate::stacks::index::file::*; @@ -21,11 +26,6 @@ use crate::chainstate::stacks::index::marf::*; use crate::chainstate::stacks::index::storage::*; use crate::chainstate::stacks::index::*; use crate::util_lib::db::*; -use rusqlite::Connection; -use rusqlite::OpenFlags; -use std::fs; - -use super::*; fn db_path(test_name: &str) -> String { let path = format!("/tmp/{}.sqlite", test_name); diff --git a/stackslib/src/chainstate/stacks/index/test/marf.rs b/stackslib/src/chainstate/stacks/index/test/marf.rs index cc12623673..b66fc4dd8a 100644 --- a/stackslib/src/chainstate/stacks/index/test/marf.rs +++ b/stackslib/src/chainstate/stacks/index/test/marf.rs @@ -20,6 +20,11 @@ use std::fs; use std::io::Cursor; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::util::get_epoch_time_ms; +use stacks_common::util::hash::to_hex; + +use super::*; use crate::chainstate::stacks::index::bits::*; use crate::chainstate::stacks::index::marf::*; use crate::chainstate::stacks::index::node::*; @@ -27,17 +32,9 @@ use crate::chainstate::stacks::index::proofs::*; use crate::chainstate::stacks::index::storage::*; use crate::chainstate::stacks::index::test::*; use crate::chainstate::stacks::index::trie::*; -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::MARFValue; -use crate::chainstate::stacks::index::TrieHashExtension; -use crate::chainstate::stacks::index::TrieLeaf; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::hash::to_hex; - -use stacks_common::types::chainstate::StacksBlockId; - -use super::*; +use crate::chainstate::stacks::index::{ + ClarityMarfTrieId, Error, MARFValue, TrieHashExtension, TrieLeaf, +}; #[test] fn marf_insert_different_leaf_same_block_100() { diff --git a/stackslib/src/chainstate/stacks/index/test/mod.rs b/stackslib/src/chainstate/stacks/index/test/mod.rs index 609380ae17..2c3b04698c 100644 --- a/stackslib/src/chainstate/stacks/index/test/mod.rs +++ b/stackslib/src/chainstate/stacks/index/test/mod.rs @@ -17,29 +17,24 @@ #![allow(unused_variables)] #![allow(unused_assignments)] -use std::fs; - use std::collections::HashMap; +use std::fs; use std::io::{Cursor, Seek, SeekFrom}; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::util::get_epoch_time_ms; +use stacks_common::util::hash::to_hex; + use crate::chainstate::stacks::index::bits::*; use crate::chainstate::stacks::index::marf::*; use crate::chainstate::stacks::index::node::*; use crate::chainstate::stacks::index::proofs::*; use crate::chainstate::stacks::index::storage::*; use crate::chainstate::stacks::index::trie::*; -use crate::chainstate::stacks::index::MARFValue; -use crate::chainstate::stacks::index::MarfTrieId; -use crate::chainstate::stacks::index::TrieHashExtension; -use crate::chainstate::stacks::index::TrieLeaf; -use crate::chainstate::stacks::index::TrieMerkleProof; - -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::hash::to_hex; - -use crate::chainstate::stacks::BlockHeaderHash; -use crate::chainstate::stacks::TrieHash; -use stacks_common::types::chainstate::StacksBlockId; +use crate::chainstate::stacks::index::{ + MARFValue, MarfTrieId, TrieHashExtension, TrieLeaf, TrieMerkleProof, +}; +use crate::chainstate::stacks::{BlockHeaderHash, TrieHash}; pub mod cache; pub mod file; diff --git a/stackslib/src/chainstate/stacks/index/test/node.rs b/stackslib/src/chainstate/stacks/index/test/node.rs index 240db172b1..a98491595d 100644 --- a/stackslib/src/chainstate/stacks/index/test/node.rs +++ b/stackslib/src/chainstate/stacks/index/test/node.rs @@ -19,6 +19,7 @@ use std::io::Cursor; +use super::*; use crate::chainstate::stacks::index::bits::*; use crate::chainstate::stacks::index::marf::*; use crate::chainstate::stacks::index::node::*; @@ -28,8 +29,6 @@ use crate::chainstate::stacks::index::test::*; use crate::chainstate::stacks::index::trie::*; use crate::chainstate::stacks::index::*; -use super::*; - #[test] fn trieptr_to_bytes() { let mut t = TriePtr::new(0x11, 0x22, 0x33445566); diff --git a/stackslib/src/chainstate/stacks/index/test/proofs.rs b/stackslib/src/chainstate/stacks/index/test/proofs.rs index 0693c42018..9642bfcdc5 100644 --- a/stackslib/src/chainstate/stacks/index/test/proofs.rs +++ b/stackslib/src/chainstate/stacks/index/test/proofs.rs @@ -14,12 +14,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use super::*; use crate::chainstate::stacks::index::marf::*; use crate::chainstate::stacks::index::test::*; use crate::chainstate::stacks::index::*; -use super::*; - #[test] fn verifier_catches_stale_proof() { use std::env; diff --git a/stackslib/src/chainstate/stacks/index/test/storage.rs b/stackslib/src/chainstate/stacks/index/test/storage.rs index dfcc538431..a996bc7186 100644 --- a/stackslib/src/chainstate/stacks/index/test/storage.rs +++ b/stackslib/src/chainstate/stacks/index/test/storage.rs @@ -17,15 +17,13 @@ use std::collections::VecDeque; use std::fs; +use rand::{thread_rng, Rng}; + +use super::*; use crate::chainstate::stacks::index::marf::*; use crate::chainstate::stacks::index::node::*; use crate::chainstate::stacks::index::*; -use rand::thread_rng; -use rand::Rng; - -use super::*; - fn ptrs_cmp(p1: &[TriePtr], p2: &[TriePtr]) -> bool { if p1.len() != p2.len() { return false; diff --git a/stackslib/src/chainstate/stacks/index/test/trie.rs b/stackslib/src/chainstate/stacks/index/test/trie.rs index 9d9efaa710..ca2c0ced65 100644 --- a/stackslib/src/chainstate/stacks/index/test/trie.rs +++ b/stackslib/src/chainstate/stacks/index/test/trie.rs @@ -19,6 +19,7 @@ use std::io::Cursor; +use super::*; use crate::chainstate::stacks::index::bits::*; use crate::chainstate::stacks::index::marf::*; use crate::chainstate::stacks::index::node::*; @@ -26,10 +27,7 @@ use crate::chainstate::stacks::index::proofs::*; use crate::chainstate::stacks::index::storage::*; use crate::chainstate::stacks::index::test::*; use crate::chainstate::stacks::index::trie::*; -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::chainstate::stacks::index::*; - -use super::*; +use crate::chainstate::stacks::index::{ClarityMarfTrieId, *}; fn walk_to_insertion_point( f: &mut TrieStorageConnection, diff --git a/stackslib/src/chainstate/stacks/index/trie.rs b/stackslib/src/chainstate/stacks/index/trie.rs index fcd5d9c10c..6c7cc7a08a 100644 --- a/stackslib/src/chainstate/stacks/index/trie.rs +++ b/stackslib/src/chainstate/stacks/index/trie.rs @@ -14,14 +14,19 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::error; /// This module defines the methods for reading and inserting into a Trie use std::fmt; -use std::io; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use std::marker::PhantomData; +use std::{error, io}; use sha2::Digest; +use stacks_common::types::chainstate::{ + BlockHeaderHash, TrieHash, BLOCK_HEADER_HASH_ENCODED_SIZE, TRIEHASH_ENCODED_SIZE, +}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::log; +use stacks_common::util::macros::is_trace; use crate::chainstate::stacks::index::bits::{ get_leaf_hash, get_node_hash, get_nodetype_hash_bytes, @@ -34,18 +39,9 @@ use crate::chainstate::stacks::index::node::{ use crate::chainstate::stacks::index::storage::{ TrieFileStorage, TrieHashCalculationMode, TrieStorageConnection, }; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::{MarfTrieId, TrieHasher}; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; -use stacks_common::util::macros::is_trace; - -use crate::chainstate::stacks::index::TrieHashExtension; -use crate::chainstate::stacks::index::TrieLeaf; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::BLOCK_HEADER_HASH_ENCODED_SIZE; -use stacks_common::types::chainstate::TRIEHASH_ENCODED_SIZE; +use crate::chainstate::stacks::index::{ + Error, MarfTrieId, TrieHashExtension, TrieHasher, TrieLeaf, +}; /// We don't actually instantiate a Trie, but we still need to pass a type parameter for the /// storage implementation. diff --git a/stackslib/src/chainstate/stacks/index/trie_sql.rs b/stackslib/src/chainstate/stacks/index/trie_sql.rs index 21a4d3e271..787a3b125a 100644 --- a/stackslib/src/chainstate/stacks/index/trie_sql.rs +++ b/stackslib/src/chainstate/stacks/index/trie_sql.rs @@ -20,50 +20,37 @@ use std::char::from_digit; use std::collections::{HashMap, HashSet, VecDeque}; use std::convert::{TryFrom, TryInto}; -use std::error; -use std::fmt; -use std::fs; -use std::io; use std::io::{BufWriter, Cursor, Read, Seek, SeekFrom, Write}; use std::iter::FromIterator; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; -use std::os; use std::path::{Path, PathBuf}; +use std::{error, fmt, fs, io, os}; use regex::Regex; -use rusqlite::{ - blob::Blob, - types::{FromSql, ToSql}, - Connection, Error as SqliteError, OptionalExtension, Transaction, NO_PARAMS, +use rusqlite::blob::Blob; +use rusqlite::types::{FromSql, ToSql}; +use rusqlite::{Connection, Error as SqliteError, OptionalExtension, Transaction, NO_PARAMS}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, TrieHash, BLOCK_HEADER_HASH_ENCODED_SIZE, TRIEHASH_ENCODED_SIZE, }; +use stacks_common::util::log; use crate::chainstate::stacks::index::bits::{ get_node_byte_len, get_node_hash, read_block_identifier, read_hash_bytes, read_node_hash_bytes as bits_read_node_hash_bytes, read_nodetype, read_nodetype_nohash, write_nodetype_bytes, }; - use crate::chainstate::stacks::index::file::TrieFile; use crate::chainstate::stacks::index::node::{ clear_backptr, is_backptr, set_backptr, TrieNode, TrieNode16, TrieNode256, TrieNode4, TrieNode48, TrieNodeID, TrieNodeType, TriePath, TriePtr, }; use crate::chainstate::stacks::index::storage::{TrieFileStorage, TrieStorageConnection}; -use crate::chainstate::stacks::index::Error; -use crate::chainstate::stacks::index::{trie_sql, BlockMap, MarfTrieId}; -use crate::util_lib::db::query_count; -use crate::util_lib::db::query_row; -use crate::util_lib::db::query_rows; -use crate::util_lib::db::sql_pragma; -use crate::util_lib::db::tx_begin_immediate; -use crate::util_lib::db::u64_to_sql; -use stacks_common::util::log; - -use crate::chainstate::stacks::index::TrieLeaf; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BLOCK_HEADER_HASH_ENCODED_SIZE; -use stacks_common::types::chainstate::{TrieHash, TRIEHASH_ENCODED_SIZE}; +use crate::chainstate::stacks::index::{trie_sql, BlockMap, Error, MarfTrieId, TrieLeaf}; +use crate::util_lib::db::{ + query_count, query_row, query_rows, sql_pragma, tx_begin_immediate, u64_to_sql, +}; static SQL_MARF_DATA_TABLE: &str = " CREATE TABLE IF NOT EXISTS marf_data ( diff --git a/stackslib/src/chainstate/stacks/miner.rs b/stackslib/src/chainstate/stacks/miner.rs index 1969559db5..de58760ce6 100644 --- a/stackslib/src/chainstate/stacks/miner.rs +++ b/stackslib/src/chainstate/stacks/miner.rs @@ -14,68 +14,56 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::cmp; -use std::collections::HashMap; -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::convert::From; -use std::fs; -use std::mem; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; -use std::sync::Arc; -use std::sync::Mutex; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Mutex}; use std::thread::ThreadId; +use std::{cmp, fs, mem}; -use crate::burnchains::PrivateKey; -use crate::burnchains::PublicKey; +use clarity::vm::analysis::{CheckError, CheckErrors}; +use clarity::vm::ast::errors::ParseErrors; +use clarity::vm::ast::ASTRules; +use clarity::vm::clarity::TransactionConnection; +use clarity::vm::database::BurnStateDB; +use clarity::vm::errors::Error as InterpreterError; +use clarity::vm::types::TypeSignature; +use serde::Deserialize; +use stacks_common::codec::{read_next, write_next, StacksMessageCodec}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, StacksWorkScore, TrieHash, +}; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::get_epoch_time_ms; +use stacks_common::util::hash::{MerkleTree, Sha512Trunc256Sum}; +use stacks_common::util::secp256k1::{MessageSignature, Secp256k1PrivateKey}; +use stacks_common::util::vrf::*; + +use crate::burnchains::{PrivateKey, PublicKey}; use crate::chainstate::burn::db::sortdb::{SortitionDB, SortitionDBConn, SortitionHandleTx}; use crate::chainstate::burn::operations::*; use crate::chainstate::burn::*; +use crate::chainstate::stacks::address::StacksAddressExtensions; +use crate::chainstate::stacks::db::blocks::{MemPoolRejection, SetupBlockResult}; use crate::chainstate::stacks::db::transactions::{ handle_clarity_runtime_error, ClarityRuntimeTxError, }; use crate::chainstate::stacks::db::unconfirmed::UnconfirmedState; use crate::chainstate::stacks::db::{ - blocks::MemPoolRejection, ChainstateTx, ClarityTx, MinerRewardInfo, StacksChainState, - MINER_REWARD_MATURITY, + ChainstateTx, ClarityTx, MinerRewardInfo, StacksChainState, MINER_REWARD_MATURITY, }; use crate::chainstate::stacks::events::{StacksTransactionEvent, StacksTransactionReceipt}; -use crate::chainstate::stacks::Error; -use crate::chainstate::stacks::*; +use crate::chainstate::stacks::{Error, StacksBlockHeader, StacksMicroblockHeader, *}; use crate::clarity_vm::clarity::{ClarityConnection, ClarityInstance}; use crate::core::mempool::*; use crate::core::*; use crate::cost_estimates::metrics::CostMetric; use crate::cost_estimates::CostEstimator; -use crate::net::relay::Relayer; -use crate::net::Error as net_error; -use clarity::vm::database::BurnStateDB; -use serde::Deserialize; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::hash::MerkleTree; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::secp256k1::{MessageSignature, Secp256k1PrivateKey}; -use stacks_common::util::vrf::*; - -use crate::chainstate::stacks::address::StacksAddressExtensions; -use crate::chainstate::stacks::db::blocks::SetupBlockResult; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblockHeader; use crate::monitoring::{ set_last_mined_block_transaction_count, set_last_mined_execution_cost_observed, }; -use clarity::vm::analysis::{CheckError, CheckErrors}; -use clarity::vm::ast::errors::ParseErrors; -use clarity::vm::ast::ASTRules; -use clarity::vm::clarity::TransactionConnection; -use clarity::vm::errors::Error as InterpreterError; -use clarity::vm::types::TypeSignature; -use stacks_common::codec::{read_next, write_next, StacksMessageCodec}; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, StacksWorkScore}; +use crate::net::relay::Relayer; +use crate::net::Error as net_error; /// System status for mining. /// The miner can be Ready, in which case a miner is allowed to run diff --git a/stackslib/src/chainstate/stacks/mod.rs b/stackslib/src/chainstate/stacks/mod.rs index d7890b725e..f7f1243d9c 100644 --- a/stackslib/src/chainstate/stacks/mod.rs +++ b/stackslib/src/chainstate/stacks/mod.rs @@ -14,55 +14,46 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::convert::From; -use std::convert::TryFrom; -use std::error; -use std::fmt; -use std::io; +use std::convert::{From, TryFrom}; use std::io::prelude::*; use std::io::{Read, Write}; -use std::ops::Deref; -use std::ops::DerefMut; +use std::ops::{Deref, DerefMut}; +use std::{error, fmt, io}; -use rusqlite::Error as RusqliteError; -use sha2::{Digest, Sha512_256}; - -use crate::burnchains::Txid; -use crate::chainstate::burn::operations::LeaderBlockCommitOp; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::stacks::db::accounts::MinerReward; -use crate::chainstate::stacks::db::blocks::MemPoolRejection; -use crate::chainstate::stacks::db::MinerRewardInfo; -use crate::chainstate::stacks::db::StacksHeaderInfo; -use crate::chainstate::stacks::index::Error as marf_error; -use crate::clarity_vm::clarity::Error as clarity_error; -use crate::net::Error as net_error; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::strings::StacksString; use clarity::vm::contexts::GlobalContext; -use clarity::vm::costs::CostErrors; -use clarity::vm::costs::ExecutionCost; +use clarity::vm::costs::{CostErrors, ExecutionCost}; use clarity::vm::errors::Error as clarity_interpreter_error; use clarity::vm::representations::{ClarityName, ContractName}; use clarity::vm::types::{ PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, Value, }; use clarity::vm::ClarityVersion; +use rusqlite::Error as RusqliteError; +use sha2::{Digest, Sha512_256}; use stacks_common::address::AddressHashMode; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::hash::HASH160_ENCODED_SIZE; +use stacks_common::codec::{ + read_next, write_next, Error as codec_error, StacksMessageCodec, MAX_MESSAGE_LEN, +}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, StacksWorkScore, TrieHash, + TRIEHASH_ENCODED_SIZE, +}; +use stacks_common::util::hash::{Hash160, Sha512Trunc256Sum, HASH160_ENCODED_SIZE}; use stacks_common::util::secp256k1; use stacks_common::util::secp256k1::MessageSignature; use stacks_common::util::vrf::VRFProof; -use stacks_common::codec::{read_next, write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksWorkScore, -}; -use stacks_common::types::chainstate::{StacksBlockId, TrieHash, TRIEHASH_ENCODED_SIZE}; +use crate::burnchains::Txid; +use crate::chainstate::burn::operations::LeaderBlockCommitOp; +use crate::chainstate::burn::ConsensusHash; +use crate::chainstate::stacks::db::accounts::MinerReward; +use crate::chainstate::stacks::db::blocks::MemPoolRejection; +use crate::chainstate::stacks::db::{MinerRewardInfo, StacksHeaderInfo}; +use crate::chainstate::stacks::index::Error as marf_error; +use crate::clarity_vm::clarity::Error as clarity_error; +use crate::net::Error as net_error; +use crate::util_lib::db::{DBConn, Error as db_error}; +use crate::util_lib::strings::StacksString; pub mod address; pub mod auth; @@ -77,12 +68,11 @@ pub mod transaction; #[cfg(test)] pub mod tests; -pub use stacks_common::types::chainstate::{StacksPrivateKey, StacksPublicKey}; - pub use stacks_common::address::{ C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_MULTISIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; +pub use stacks_common::types::chainstate::{StacksPrivateKey, StacksPublicKey}; pub const STACKS_BLOCK_VERSION: u8 = 6; pub const STACKS_BLOCK_VERSION_AST_PRECHECK_SIZE: u8 = 1; @@ -907,18 +897,17 @@ pub const MAX_MICROBLOCK_SIZE: u32 = 65536; #[cfg(test)] pub mod test { - use crate::chainstate::stacks::StacksPublicKey as PubKey; - use crate::chainstate::stacks::*; - use crate::core::*; - use crate::net::codec::test::check_codec_and_corruption; - use crate::net::codec::*; - use crate::net::*; use clarity::vm::representations::{ClarityName, ContractName}; use clarity::vm::ClarityVersion; use stacks_common::util::hash::*; use stacks_common::util::log; use super::*; + use crate::chainstate::stacks::{StacksPublicKey as PubKey, *}; + use crate::core::*; + use crate::net::codec::test::check_codec_and_corruption; + use crate::net::codec::*; + use crate::net::*; /// Make a representative of each kind of transaction we support pub fn codec_all_transactions( diff --git a/stackslib/src/chainstate/stacks/tests/accounting.rs b/stackslib/src/chainstate/stacks/tests/accounting.rs index 86873174c9..1bd328d810 100644 --- a/stackslib/src/chainstate/stacks/tests/accounting.rs +++ b/stackslib/src/chainstate/stacks/tests/accounting.rs @@ -18,16 +18,20 @@ /// various conditions, such as ensuring that the right principals get paid and ensuring that fees /// are appropriately distributed. use std::cell::RefCell; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::fs; -use std::io; +use std::collections::{HashMap, HashSet, VecDeque}; use std::path::{Path, PathBuf}; +use std::{fs, io}; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::types::*; use rand::seq::SliceRandom; -use rand::thread_rng; -use rand::Rng; +use rand::{thread_rng, Rng}; +use stacks_common::address::*; +use stacks_common::types::chainstate::SortitionId; +use stacks_common::util::hash::MerkleTree; +use stacks_common::util::sleep_ms; +use stacks_common::util::vrf::VRFProof; use crate::burnchains::tests::*; use crate::burnchains::*; @@ -40,30 +44,17 @@ use crate::chainstate::coordinator::Error as CoordinatorError; use crate::chainstate::stacks::db::blocks::test::store_staging_block; use crate::chainstate::stacks::db::test::*; use crate::chainstate::stacks::db::*; -use crate::chainstate::stacks::Error as ChainstateError; -use crate::chainstate::stacks::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; -use crate::chainstate::stacks::*; -use crate::net::test::*; -use crate::util_lib::db::Error as db_error; -use clarity::vm::types::*; -use stacks_common::address::*; -use stacks_common::util::sleep_ms; -use stacks_common::util::vrf::VRFProof; - -use crate::cost_estimates::metrics::UnitMetric; -use crate::cost_estimates::UnitEstimator; -use crate::util_lib::boot::boot_code_addr; -use stacks_common::types::chainstate::SortitionId; - -use clarity::vm::costs::LimitedCostTracker; - use crate::chainstate::stacks::miner::*; use crate::chainstate::stacks::tests::*; +use crate::chainstate::stacks::{ + Error as ChainstateError, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, *, +}; use crate::core::*; - -use stacks_common::util::hash::MerkleTree; - -use clarity::vm::clarity::ClarityConnection; +use crate::cost_estimates::metrics::UnitMetric; +use crate::cost_estimates::UnitEstimator; +use crate::net::test::*; +use crate::util_lib::boot::boot_code_addr; +use crate::util_lib::db::Error as db_error; // test that the bad (pre 2.1) microblock fee payment still works. we have to support it for // eternity :( diff --git a/stackslib/src/chainstate/stacks/tests/block_construction.rs b/stackslib/src/chainstate/stacks/tests/block_construction.rs index 459f91b807..24de63a676 100644 --- a/stackslib/src/chainstate/stacks/tests/block_construction.rs +++ b/stackslib/src/chainstate/stacks/tests/block_construction.rs @@ -21,17 +21,23 @@ /// concerned with building out and testing block histories from manually-constructed blocks, /// ignoring mempool-level concerns entirely. use std::cell::RefCell; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::fs; -use std::io; +use std::collections::{HashMap, HashSet, VecDeque}; use std::path::{Path, PathBuf}; +use std::{fs, io}; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; use clarity::vm::database::ClarityDatabase; +use clarity::vm::test_util::TEST_BURN_STATE_DB; +use clarity::vm::types::*; use rand::seq::SliceRandom; -use rand::thread_rng; -use rand::Rng; +use rand::{thread_rng, Rng}; +use stacks_common::address::*; +use stacks_common::types::chainstate::SortitionId; +use stacks_common::util::hash::MerkleTree; +use stacks_common::util::secp256k1::Secp256k1PrivateKey; +use stacks_common::util::vrf::VRFProof; +use stacks_common::util::{get_epoch_time_ms, sleep_ms}; use crate::burnchains::tests::*; use crate::burnchains::*; @@ -45,37 +51,20 @@ use crate::chainstate::stacks::db::blocks::test::store_staging_block; use crate::chainstate::stacks::db::test::*; use crate::chainstate::stacks::db::*; use crate::chainstate::stacks::events::StacksTransactionReceipt; -use crate::chainstate::stacks::test::codec_all_transactions; -use crate::chainstate::stacks::Error as ChainstateError; -use crate::chainstate::stacks::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; -use crate::chainstate::stacks::*; -use crate::core::FIRST_BURNCHAIN_CONSENSUS_HASH; -use crate::net::test::*; -use crate::util_lib::db::Error as db_error; -use clarity::vm::types::*; -use stacks_common::address::*; -use stacks_common::util::sleep_ms; -use stacks_common::util::vrf::VRFProof; - -use crate::cost_estimates::metrics::UnitMetric; -use crate::cost_estimates::UnitEstimator; -use crate::util_lib::boot::boot_code_addr; -use stacks_common::types::chainstate::SortitionId; - -use clarity::vm::costs::LimitedCostTracker; - use crate::chainstate::stacks::miner::*; +use crate::chainstate::stacks::test::codec_all_transactions; use crate::chainstate::stacks::tests::*; +use crate::chainstate::stacks::{ + Error as ChainstateError, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, *, +}; use crate::core::mempool::MemPoolWalkSettings; use crate::core::tests::make_block; -use crate::core::*; - -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::hash::MerkleTree; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; - -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::test_util::TEST_BURN_STATE_DB; +use crate::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, *}; +use crate::cost_estimates::metrics::UnitMetric; +use crate::cost_estimates::UnitEstimator; +use crate::net::test::*; +use crate::util_lib::boot::boot_code_addr; +use crate::util_lib::db::Error as db_error; #[test] fn test_build_anchored_blocks_empty() { diff --git a/stackslib/src/chainstate/stacks/tests/chain_histories.rs b/stackslib/src/chainstate/stacks/tests/chain_histories.rs index 43a7d50493..1ed4bbc425 100644 --- a/stackslib/src/chainstate/stacks/tests/chain_histories.rs +++ b/stackslib/src/chainstate/stacks/tests/chain_histories.rs @@ -21,16 +21,21 @@ /// module focuses on building and testing chain histories; unlike `block_construction`, this module does not /// test anything about block construction from mempool state. use std::cell::RefCell; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::fs; -use std::io; +use std::collections::{HashMap, HashSet, VecDeque}; use std::path::{Path, PathBuf}; +use std::{fs, io}; +use clarity::vm::ast::ASTRules; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::types::*; use rand::seq::SliceRandom; -use rand::thread_rng; -use rand::Rng; +use rand::{thread_rng, Rng}; +use stacks_common::address::*; +use stacks_common::types::chainstate::SortitionId; +use stacks_common::util::hash::MerkleTree; +use stacks_common::util::sleep_ms; +use stacks_common::util::vrf::VRFProof; use crate::burnchains::db::BurnchainDB; use crate::burnchains::tests::*; @@ -44,31 +49,17 @@ use crate::chainstate::coordinator::Error as CoordinatorError; use crate::chainstate::stacks::db::blocks::test::store_staging_block; use crate::chainstate::stacks::db::test::*; use crate::chainstate::stacks::db::*; -use crate::chainstate::stacks::Error as ChainstateError; -use crate::chainstate::stacks::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; -use crate::chainstate::stacks::*; -use crate::net::test::*; -use crate::util_lib::db::Error as db_error; -use clarity::vm::types::*; -use stacks_common::address::*; -use stacks_common::util::sleep_ms; -use stacks_common::util::vrf::VRFProof; - -use crate::cost_estimates::metrics::UnitMetric; -use crate::cost_estimates::UnitEstimator; -use crate::util_lib::boot::boot_code_addr; -use stacks_common::types::chainstate::SortitionId; - -use clarity::vm::ast::ASTRules; -use clarity::vm::costs::LimitedCostTracker; - use crate::chainstate::stacks::miner::*; use crate::chainstate::stacks::tests::*; +use crate::chainstate::stacks::{ + Error as ChainstateError, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, *, +}; use crate::core::*; - -use stacks_common::util::hash::MerkleTree; - -use clarity::vm::clarity::ClarityConnection; +use crate::cost_estimates::metrics::UnitMetric; +use crate::cost_estimates::UnitEstimator; +use crate::net::test::*; +use crate::util_lib::boot::boot_code_addr; +use crate::util_lib::db::Error as db_error; fn connect_burnchain_db(burnchain: &Burnchain) -> BurnchainDB { let burnchain_db = diff --git a/stackslib/src/chainstate/stacks/tests/mod.rs b/stackslib/src/chainstate/stacks/tests/mod.rs index 16a1a8ef33..0be3d75f6b 100644 --- a/stackslib/src/chainstate/stacks/tests/mod.rs +++ b/stackslib/src/chainstate/stacks/tests/mod.rs @@ -15,16 +15,20 @@ // along with this program. If not, see . use std::cell::RefCell; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::fs; -use std::io; +use std::collections::{HashMap, HashSet, VecDeque}; use std::path::{Path, PathBuf}; +use std::{fs, io}; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::types::*; use rand::seq::SliceRandom; -use rand::thread_rng; -use rand::Rng; +use rand::{thread_rng, Rng}; +use stacks_common::address::*; +use stacks_common::consts::FIRST_BURNCHAIN_CONSENSUS_HASH; +use stacks_common::types::chainstate::SortitionId; +use stacks_common::util::sleep_ms; +use stacks_common::util::vrf::{VRFProof, VRFPublicKey}; use crate::burnchains::tests::*; use crate::burnchains::*; @@ -37,29 +41,15 @@ use crate::chainstate::coordinator::Error as CoordinatorError; use crate::chainstate::stacks::db::blocks::test::store_staging_block; use crate::chainstate::stacks::db::test::*; use crate::chainstate::stacks::db::*; -use crate::chainstate::stacks::Error as ChainstateError; -use crate::chainstate::stacks::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; -use crate::chainstate::stacks::*; -use crate::net::test::*; -use crate::util_lib::db::Error as db_error; -use clarity::vm::types::*; -use stacks_common::address::*; -use stacks_common::util::sleep_ms; -use stacks_common::util::vrf::VRFProof; - +use crate::chainstate::stacks::miner::*; +use crate::chainstate::stacks::{ + Error as ChainstateError, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, *, +}; use crate::cost_estimates::metrics::UnitMetric; use crate::cost_estimates::UnitEstimator; +use crate::net::test::*; use crate::util_lib::boot::boot_code_addr; -use stacks_common::types::chainstate::SortitionId; - -use clarity::vm::costs::LimitedCostTracker; - -use crate::chainstate::stacks::miner::*; - -use stacks_common::consts::FIRST_BURNCHAIN_CONSENSUS_HASH; -use stacks_common::util::vrf::VRFPublicKey; - -use clarity::vm::clarity::ClarityConnection; +use crate::util_lib::db::Error as db_error; pub mod accounting; pub mod block_construction; diff --git a/stackslib/src/chainstate/stacks/transaction.rs b/stackslib/src/chainstate/stacks/transaction.rs index 2c673e27fe..de65a62a16 100644 --- a/stackslib/src/chainstate/stacks/transaction.rs +++ b/stackslib/src/chainstate/stacks/transaction.rs @@ -19,24 +19,21 @@ use std::io; use std::io::prelude::*; use std::io::{Read, Write}; -use crate::burnchains::Txid; -use crate::chainstate::stacks::*; -use crate::core::*; -use crate::net::Error as net_error; use clarity::vm::representations::{ClarityName, ContractName}; use clarity::vm::types::serialization::SerializationError as clarity_serialization_error; use clarity::vm::types::{QualifiedContractIdentifier, StandardPrincipalData}; -use clarity::vm::{SymbolicExpression, SymbolicExpressionType, Value}; +use clarity::vm::{ClarityVersion, SymbolicExpression, SymbolicExpressionType, Value}; +use stacks_common::codec::{read_next, write_next, Error as codec_error, StacksMessageCodec}; +use stacks_common::types::chainstate::StacksAddress; use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha512Trunc256Sum; +use stacks_common::util::hash::{to_hex, Sha512Trunc256Sum}; use stacks_common::util::retry::BoundReader; use stacks_common::util::secp256k1::MessageSignature; -use crate::chainstate::stacks::StacksMicroblockHeader; -use clarity::vm::ClarityVersion; -use stacks_common::codec::{read_next, write_next, Error as codec_error, StacksMessageCodec}; -use stacks_common::types::chainstate::StacksAddress; +use crate::burnchains::Txid; +use crate::chainstate::stacks::{StacksMicroblockHeader, *}; +use crate::core::*; +use crate::net::Error as net_error; impl StacksMessageCodec for TransactionContractCall { fn consensus_serialize(&self, fd: &mut W) -> Result<(), codec_error> { @@ -1071,23 +1068,21 @@ impl StacksTransactionSigner { mod test { use std::error::Error; - use crate::chainstate::stacks::test::codec_all_transactions; - use crate::chainstate::stacks::StacksPublicKey as PubKey; - use crate::chainstate::stacks::*; - use crate::chainstate::stacks::{ - C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, - }; - use crate::net::codec::test::check_codec_and_corruption; - use crate::net::codec::*; - use crate::net::*; use clarity::vm::representations::{ClarityName, ContractName}; use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; use stacks_common::util::hash::*; use stacks_common::util::log; - use stacks_common::util::retry::BoundReader; - use stacks_common::util::retry::LogReader; + use stacks_common::util::retry::{BoundReader, LogReader}; use super::*; + use crate::chainstate::stacks::test::codec_all_transactions; + use crate::chainstate::stacks::{ + StacksPublicKey as PubKey, C32_ADDRESS_VERSION_MAINNET_MULTISIG, + C32_ADDRESS_VERSION_MAINNET_SINGLESIG, *, + }; + use crate::net::codec::test::check_codec_and_corruption; + use crate::net::codec::*; + use crate::net::*; fn corrupt_auth_field( corrupt_auth_fields: &TransactionAuth, diff --git a/stackslib/src/clarity_cli.rs b/stackslib/src/clarity_cli.rs index 43677baf15..9c384a2316 100644 --- a/stackslib/src/clarity_cli.rs +++ b/stackslib/src/clarity_cli.rs @@ -14,93 +14,59 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::convert::TryInto; -use std::env; +use std::convert::{TryFrom, TryInto}; use std::ffi::OsStr; -use std::fs; -use std::io; use std::io::{Read, Write}; use std::iter::Iterator; use std::path::PathBuf; -use std::process; +use std::str::FromStr; +use std::{env, fs, io, process}; use clarity::vm::coverage::CoverageReporter; use rand::Rng; use rusqlite::types::ToSql; -use rusqlite::Row; -use rusqlite::Transaction; -use rusqlite::{Connection, OpenFlags, NO_PARAMS}; - -use crate::chainstate::stacks::index::{storage::TrieFileStorage, MarfTrieId}; -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::FromColumn; +use rusqlite::{Connection, OpenFlags, Row, Transaction, NO_PARAMS}; +use serde::Serialize; +use serde_json::json; use stacks_common::address::c32::c32_address; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::hash::{bytes_to_hex, Hash160, Sha512Trunc256Sum}; - -use crate::clarity::{ - vm::analysis, - vm::analysis::contract_interface_builder::build_contract_interface, - vm::analysis::{errors::CheckError, errors::CheckResult, AnalysisDatabase, ContractAnalysis}, - vm::ast, - vm::ast::build_ast_with_rules, - vm::ast::ASTRules, - vm::contexts::GlobalContext, - vm::contexts::{AssetMap, OwnedEnvironment}, - vm::costs::ExecutionCost, - vm::costs::LimitedCostTracker, - vm::database::{ - BurnStateDB, ClarityDatabase, HeadersDB, STXBalance, SqliteConnection, NULL_BURN_STATE_DB, - }, - vm::errors::{Error, InterpreterResult, RuntimeErrorType}, - vm::eval_all, - vm::types::{OptionalData, PrincipalData, QualifiedContractIdentifier}, - vm::ClarityVersion, - vm::ContractContext, - vm::ContractName, - vm::{SymbolicExpression, SymbolicExpressionType, Value}, +use stacks_common::codec::StacksMessageCodec; +use stacks_common::consts::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, StacksAddress, StacksBlockId, VRFSeed, *, }; -use stacks_common::util::log; - -use crate::burnchains::PoxConstants; -use crate::burnchains::Txid; -use stacks_common::types::chainstate::*; +use stacks_common::util::hash::{bytes_to_hex, Hash160, Sha512Trunc256Sum}; +use stacks_common::util::{get_epoch_time_ms, log}; +use crate::burnchains::{Address, PoxConstants, Txid}; use crate::chainstate::stacks::boot::{ BOOT_CODE_BNS, BOOT_CODE_COSTS, BOOT_CODE_COSTS_2, BOOT_CODE_COSTS_2_TESTNET, BOOT_CODE_COSTS_3, BOOT_CODE_COST_VOTING_MAINNET, BOOT_CODE_COST_VOTING_TESTNET, BOOT_CODE_GENESIS, BOOT_CODE_LOCKUP, BOOT_CODE_POX_MAINNET, BOOT_CODE_POX_TESTNET, POX_2_MAINNET_CODE, POX_2_TESTNET_CODE, }; - +use crate::chainstate::stacks::index::storage::TrieFileStorage; +use crate::chainstate::stacks::index::{ClarityMarfTrieId, MarfTrieId}; +use crate::clarity::vm::analysis::contract_interface_builder::build_contract_interface; +use crate::clarity::vm::analysis::errors::{CheckError, CheckResult}; +use crate::clarity::vm::analysis::{AnalysisDatabase, ContractAnalysis}; +use crate::clarity::vm::ast::{build_ast_with_rules, ASTRules}; +use crate::clarity::vm::contexts::{AssetMap, GlobalContext, OwnedEnvironment}; +use crate::clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; +use crate::clarity::vm::database::{ + BurnStateDB, ClarityDatabase, HeadersDB, STXBalance, SqliteConnection, NULL_BURN_STATE_DB, +}; +use crate::clarity::vm::errors::{Error, InterpreterResult, RuntimeErrorType}; +use crate::clarity::vm::types::{OptionalData, PrincipalData, QualifiedContractIdentifier}; +use crate::clarity::vm::{ + analysis, ast, eval_all, ClarityVersion, ContractContext, ContractName, SymbolicExpression, + SymbolicExpressionType, Value, +}; +use crate::clarity_vm::database::marf::{MarfedKV, WritableMarfStore}; +use crate::clarity_vm::database::MemoryBackingStore; +use crate::core::{StacksEpochId, BLOCK_LIMIT_MAINNET_205, HELIUM_BLOCK_LIMIT_20}; use crate::util_lib::boot::{boot_code_addr, boot_code_id}; - -use crate::burnchains::Address; -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::core::BLOCK_LIMIT_MAINNET_205; -use crate::core::HELIUM_BLOCK_LIMIT_20; - +use crate::util_lib::db::{sqlite_open, FromColumn}; use crate::util_lib::strings::StacksString; -use serde::Serialize; -use serde_json::json; - -use stacks_common::codec::StacksMessageCodec; - -use std::convert::TryFrom; - -use crate::clarity_vm::database::marf::MarfedKV; -use crate::clarity_vm::database::marf::WritableMarfStore; -use crate::clarity_vm::database::MemoryBackingStore; -use crate::core::StacksEpochId; -use stacks_common::consts::CHAIN_ID_MAINNET; -use stacks_common::consts::CHAIN_ID_TESTNET; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::VRFSeed; -use std::str::FromStr; lazy_static! { pub static ref STACKS_BOOT_CODE_MAINNET_2_1: [(&'static str, &'static str); 9] = [ diff --git a/stackslib/src/clarity_cli_main.rs b/stackslib/src/clarity_cli_main.rs index f983263cfc..839006a47f 100644 --- a/stackslib/src/clarity_cli_main.rs +++ b/stackslib/src/clarity_cli_main.rs @@ -23,10 +23,10 @@ extern crate blockstack_lib; extern crate serde_json; +use std::{env, process}; + use blockstack_lib::clarity_cli as clarity; use stacks_common::util::log; -use std::env; -use std::process; fn main() { let argv: Vec = env::args().collect(); diff --git a/stackslib/src/clarity_vm/clarity.rs b/stackslib/src/clarity_vm/clarity.rs index f1cd911327..fce78929f9 100644 --- a/stackslib/src/clarity_vm/clarity.rs +++ b/stackslib/src/clarity_vm/clarity.rs @@ -15,50 +15,14 @@ // along with this program. If not, see . use std::convert::TryFrom; -use std::error; -use std::fmt; -use std::thread; - -use crate::chainstate::stacks::boot::BOOT_CODE_COSTS_2_TESTNET; -use crate::chainstate::stacks::boot::POX_2_MAINNET_CODE; -use crate::chainstate::stacks::boot::POX_2_TESTNET_CODE; -use crate::chainstate::stacks::boot::POX_3_MAINNET_CODE; -use crate::chainstate::stacks::boot::POX_3_TESTNET_CODE; -use crate::chainstate::stacks::boot::{ - BOOT_CODE_COSTS, BOOT_CODE_COSTS_2, BOOT_CODE_COSTS_3, - BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET, COSTS_2_NAME, - COSTS_3_NAME, POX_2_NAME, POX_3_NAME, -}; -use crate::chainstate::stacks::db::StacksAccount; -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::events::{StacksTransactionEvent, StacksTransactionReceipt}; -use crate::chainstate::stacks::index::marf::MARF; -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::chainstate::stacks::index::MarfTrieId; -use crate::chainstate::stacks::Error as ChainstateError; -use crate::chainstate::stacks::StacksMicroblockHeader; -use crate::chainstate::stacks::TransactionAuth; -use crate::chainstate::stacks::TransactionPayload; -use crate::chainstate::stacks::TransactionPublicKeyEncoding; -use crate::chainstate::stacks::TransactionSmartContract; -use crate::chainstate::stacks::TransactionSpendingCondition; -use crate::chainstate::stacks::TransactionVersion; -use crate::chainstate::stacks::{SinglesigHashMode, SinglesigSpendingCondition, StacksTransaction}; -use crate::core::StacksEpoch; -use crate::core::{FIRST_STACKS_BLOCK_ID, GENESIS_EPOCH}; -use crate::util_lib::boot::{boot_code_acc, boot_code_addr, boot_code_id, boot_code_tx_auth}; -use crate::util_lib::strings::StacksString; -use crate::{ - burnchains::Burnchain, - burnchains::PoxConstants, - clarity_vm::database::marf::{MarfedKV, WritableMarfStore}, -}; -use crate::{clarity_vm::database::marf::ReadOnlyMarfStore, core::StacksEpochId}; -use clarity::vm::analysis; -use clarity::vm::analysis::AnalysisDatabase; -use clarity::vm::analysis::{errors::CheckError, errors::CheckErrors, ContractAnalysis}; -use clarity::vm::ast; -use clarity::vm::ast::{errors::ParseError, errors::ParseErrors, ASTRules, ContractAST}; +use std::{error, fmt, thread}; + +use clarity::vm::analysis::errors::{CheckError, CheckErrors}; +use clarity::vm::analysis::{AnalysisDatabase, ContractAnalysis}; +use clarity::vm::ast::errors::{ParseError, ParseErrors}; +use clarity::vm::ast::{ASTRules, ContractAST}; +use clarity::vm::clarity::TransactionConnection; +pub use clarity::vm::clarity::{ClarityConnection, Error}; use clarity::vm::contexts::{AssetMap, Environment, OwnedEnvironment}; use clarity::vm::costs::{CostTracker, ExecutionCost, LimitedCostTracker}; use clarity::vm::database::{ @@ -71,22 +35,36 @@ use clarity::vm::types::{ AssetIdentifier, BuffData, OptionalData, PrincipalData, QualifiedContractIdentifier, TupleData, TypeSignature, Value, }; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::SortitionId; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::TrieHash; - -use crate::util_lib::db::Error as DatabaseError; -pub use clarity::vm::clarity::ClarityConnection; -pub use clarity::vm::clarity::Error; -use clarity::vm::clarity::TransactionConnection; - +use clarity::vm::{analysis, ast, ClarityVersion, ContractName}; use stacks_common::consts::CHAIN_ID_TESTNET; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksBlockId, TrieHash, +}; use stacks_common::util::secp256k1::MessageSignature; +use crate::burnchains::{Burnchain, PoxConstants}; +use crate::chainstate::stacks::boot::{ + BOOT_CODE_COSTS, BOOT_CODE_COSTS_2, BOOT_CODE_COSTS_2_TESTNET, BOOT_CODE_COSTS_3, + BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET, COSTS_2_NAME, + COSTS_3_NAME, POX_2_MAINNET_CODE, POX_2_NAME, POX_2_TESTNET_CODE, POX_3_MAINNET_CODE, + POX_3_NAME, POX_3_TESTNET_CODE, +}; +use crate::chainstate::stacks::db::{StacksAccount, StacksChainState}; +use crate::chainstate::stacks::events::{StacksTransactionEvent, StacksTransactionReceipt}; +use crate::chainstate::stacks::index::marf::MARF; +use crate::chainstate::stacks::index::{ClarityMarfTrieId, MarfTrieId}; +use crate::chainstate::stacks::{ + Error as ChainstateError, SinglesigHashMode, SinglesigSpendingCondition, + StacksMicroblockHeader, StacksTransaction, TransactionAuth, TransactionPayload, + TransactionPublicKeyEncoding, TransactionSmartContract, TransactionSpendingCondition, + TransactionVersion, +}; +use crate::clarity_vm::database::marf::{MarfedKV, ReadOnlyMarfStore, WritableMarfStore}; +use crate::core::{StacksEpoch, StacksEpochId, FIRST_STACKS_BLOCK_ID, GENESIS_EPOCH}; +use crate::util_lib::boot::{boot_code_acc, boot_code_addr, boot_code_id, boot_code_tx_auth}; +use crate::util_lib::db::Error as DatabaseError; +use crate::util_lib::strings::StacksString; + /// /// A high-level interface for interacting with the Clarity VM. /// @@ -1590,22 +1568,18 @@ impl<'a, 'b> ClarityTransactionConnection<'a, 'b> { mod tests { use std::fs; - use rusqlite::NO_PARAMS; - use clarity::vm::analysis::errors::CheckErrors; use clarity::vm::database::{ClarityBackingStore, STXBalance}; - use clarity::vm::types::{StandardPrincipalData, Value}; - - use crate::core::{PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05}; use clarity::vm::test_util::{TEST_BURN_STATE_DB, TEST_HEADER_DB}; - - use crate::chainstate::stacks::index::ClarityMarfTrieId; - use crate::clarity_vm::database::marf::MarfedKV; - + use clarity::vm::types::{StandardPrincipalData, Value}; + use rusqlite::NO_PARAMS; + use stacks_common::consts::CHAIN_ID_TESTNET; use stacks_common::types::chainstate::ConsensusHash; use super::*; - use stacks_common::consts::CHAIN_ID_TESTNET; + use crate::chainstate::stacks::index::ClarityMarfTrieId; + use crate::clarity_vm::database::marf::MarfedKV; + use crate::core::{PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05}; #[test] pub fn bad_syntax_test() { @@ -2262,11 +2236,12 @@ mod tests { #[test] pub fn test_post_condition_failure_contract_publish() { + use stacks_common::util::hash::Hash160; + use stacks_common::util::secp256k1::MessageSignature; + use crate::chainstate::stacks::db::*; use crate::chainstate::stacks::*; use crate::util_lib::strings::StacksString; - use stacks_common::util::hash::Hash160; - use stacks_common::util::secp256k1::MessageSignature; let marf = MarfedKV::temporary(); let mut clarity_instance = ClarityInstance::new(false, CHAIN_ID_TESTNET, marf); diff --git a/stackslib/src/clarity_vm/database/marf.rs b/stackslib/src/clarity_vm/database/marf.rs index fae04b3494..c4c869d119 100644 --- a/stackslib/src/clarity_vm/database/marf.rs +++ b/stackslib/src/clarity_vm/database/marf.rs @@ -1,29 +1,26 @@ use std::path::PathBuf; use std::str::FromStr; -use rusqlite::Connection; - -use crate::chainstate::stacks::index::marf::{MARFOpenOpts, MarfConnection, MarfTransaction, MARF}; -use crate::chainstate::stacks::index::{Error, MarfTrieId}; -use crate::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH}; -use crate::util_lib::db::IndexDBConn; use clarity::vm::analysis::AnalysisDatabase; use clarity::vm::database::{ - BurnStateDB, ClarityBackingStore, ClarityDatabase, HeadersDB, SqliteConnection, + BurnStateDB, ClarityBackingStore, ClarityDatabase, HeadersDB, SpecialCaseHandler, + SqliteConnection, }; use clarity::vm::errors::{ IncomparableError, InterpreterError, InterpreterResult, RuntimeErrorType, }; use clarity::vm::types::QualifiedContractIdentifier; +use rusqlite::Connection; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId, TrieHash}; -use crate::chainstate::stacks::index::{ClarityMarfTrieId, MARFValue, TrieMerkleProof}; -use clarity::vm::database::SpecialCaseHandler; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::{StacksBlockId, TrieHash}; - +use crate::chainstate::stacks::index::marf::{MARFOpenOpts, MarfConnection, MarfTransaction, MARF}; +use crate::chainstate::stacks::index::{ + ClarityMarfTrieId, Error, MARFValue, MarfTrieId, TrieMerkleProof, +}; use crate::clarity_vm::special::handle_contract_call_special_cases; -use crate::util_lib::db::Error as DatabaseError; -use stacks_common::codec::StacksMessageCodec; +use crate::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH}; +use crate::util_lib::db::{Error as DatabaseError, IndexDBConn}; /// The MarfedKV struct is used to wrap a MARF data structure and side-storage /// for use as a K/V store for ClarityDB or the AnalysisDB. @@ -111,9 +108,10 @@ impl MarfedKV { // used by benchmarks pub fn temporary() -> MarfedKV { + use std::env; + use rand::Rng; use stacks_common::util::hash::to_hex; - use std::env; let mut path = PathBuf::from_str("/tmp/stacks-node-tests/unit-tests-marf").unwrap(); let random_bytes = rand::thread_rng().gen::<[u8; 32]>(); diff --git a/stackslib/src/clarity_vm/database/mod.rs b/stackslib/src/clarity_vm/database/mod.rs index 01351f5c7c..4e19f5ef2e 100644 --- a/stackslib/src/clarity_vm/database/mod.rs +++ b/stackslib/src/clarity_vm/database/mod.rs @@ -1,5 +1,19 @@ -use clarity::vm::types::PrincipalData; +use std::ops::{Deref, DerefMut}; + +use clarity::vm::analysis::AnalysisDatabase; +use clarity::vm::database::{ + BurnStateDB, ClarityBackingStore, ClarityDatabase, HeadersDB, SpecialCaseHandler, + SqliteConnection, NULL_BURN_STATE_DB, NULL_HEADER_DB, +}; +use clarity::vm::errors::{InterpreterResult, RuntimeErrorType}; +use clarity::vm::types::{PrincipalData, TupleData}; use rusqlite::{Connection, OptionalExtension, Row, ToSql}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, SortitionId, StacksAddress, StacksBlockId, + VRFSeed, +}; +use stacks_common::types::Address; +use stacks_common::util::vrf::VRFProof; use crate::chainstate::burn::db::sortdb::{ get_ancestor_sort_id, get_ancestor_sort_id_tx, SortitionDB, SortitionDBConn, SortitionHandle, @@ -7,35 +21,15 @@ use crate::chainstate::burn::db::sortdb::{ }; use crate::chainstate::stacks::boot::PoxStartCycleInfo; use crate::chainstate::stacks::db::accounts::MinerReward; -use crate::chainstate::stacks::db::{MinerPaymentSchedule, StacksChainState, StacksHeaderInfo}; -use crate::chainstate::stacks::index::MarfTrieId; -use crate::util_lib::db::FromColumn; -use crate::util_lib::db::{DBConn, FromRow}; -use clarity::vm::analysis::AnalysisDatabase; -use clarity::vm::database::{ - BurnStateDB, ClarityBackingStore, ClarityDatabase, HeadersDB, SqliteConnection, - NULL_BURN_STATE_DB, NULL_HEADER_DB, +use crate::chainstate::stacks::db::{ + ChainstateTx, MinerPaymentSchedule, StacksChainState, StacksHeaderInfo, }; -use clarity::vm::errors::{InterpreterResult, RuntimeErrorType}; - -use crate::chainstate::stacks::db::ChainstateTx; use crate::chainstate::stacks::index::marf::{MarfConnection, MARF}; -use crate::chainstate::stacks::index::{ClarityMarfTrieId, TrieMerkleProof}; +use crate::chainstate::stacks::index::{ClarityMarfTrieId, MarfTrieId, TrieMerkleProof}; use crate::chainstate::stacks::Error as ChainstateError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, SortitionId}; -use stacks_common::types::chainstate::{StacksAddress, VRFSeed}; -use stacks_common::util::vrf::VRFProof; - -use crate::core::StacksEpoch; -use crate::core::StacksEpochId; -use std::ops::{Deref, DerefMut}; - use crate::clarity_vm::special::handle_contract_call_special_cases; -use clarity::vm::database::SpecialCaseHandler; -use clarity::vm::types::TupleData; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::Address; +use crate::core::{StacksEpoch, StacksEpochId}; +use crate::util_lib::db::{DBConn, FromColumn, FromRow}; pub mod marf; diff --git a/stackslib/src/clarity_vm/tests/analysis_costs.rs b/stackslib/src/clarity_vm/tests/analysis_costs.rs index 1c98089b85..87e1759290 100644 --- a/stackslib/src/clarity_vm/tests/analysis_costs.rs +++ b/stackslib/src/clarity_vm/tests/analysis_costs.rs @@ -14,14 +14,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::chainstate::stacks::index::storage::TrieFileStorage; -use crate::clarity_vm::clarity::ClarityInstance; -use crate::clarity_vm::tests::costs::get_simple_test; -use crate::clarity_vm::tests::simple_tests::with_marfed_environment; use clarity::vm::ast::ASTRules; use clarity::vm::clarity::TransactionConnection; -use clarity::vm::contexts::Environment; -use clarity::vm::contexts::{AssetMap, AssetMapEntry, GlobalContext, OwnedEnvironment}; +use clarity::vm::contexts::{ + AssetMap, AssetMapEntry, Environment, GlobalContext, OwnedEnvironment, +}; use clarity::vm::contracts::Contract; use clarity::vm::costs::ExecutionCost; use clarity::vm::database::{ClarityDatabase, NULL_BURN_STATE_DB, NULL_HEADER_DB}; @@ -29,20 +26,23 @@ use clarity::vm::errors::{CheckErrors, Error, RuntimeErrorType}; use clarity::vm::functions::NativeFunctions; use clarity::vm::representations::SymbolicExpression; use clarity::vm::test_util::{TEST_BURN_STATE_DB, TEST_HEADER_DB}; -use clarity::vm::tests::{execute, symbols_from_values, UnitTestBurnStateDB}; +use clarity::vm::tests::{ + execute, symbols_from_values, test_only_mainnet_to_chain_id, UnitTestBurnStateDB, +}; use clarity::vm::types::{ AssetIdentifier, PrincipalData, QualifiedContractIdentifier, ResponseData, Value, }; -use clarity::vm::{execute as vm_execute, ContractName}; +use clarity::vm::{execute as vm_execute, ClarityVersion, ContractName}; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; +use stacks_common::types::StacksEpochId; use stacks_common::util::hash::hex_bytes; +use crate::chainstate::stacks::index::storage::TrieFileStorage; use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::clarity_vm::clarity::ClarityConnection; +use crate::clarity_vm::clarity::{ClarityConnection, ClarityInstance}; use crate::clarity_vm::database::marf::MarfedKV; -use clarity::vm::tests::test_only_mainnet_to_chain_id; -use clarity::vm::ClarityVersion; -use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; -use stacks_common::types::StacksEpochId; +use crate::clarity_vm::tests::costs::get_simple_test; +use crate::clarity_vm::tests::simple_tests::with_marfed_environment; fn setup_tracked_cost_test( use_mainnet: bool, diff --git a/stackslib/src/clarity_vm/tests/ast.rs b/stackslib/src/clarity_vm/tests/ast.rs index bc1cff12a5..2074fa7636 100644 --- a/stackslib/src/clarity_vm/tests/ast.rs +++ b/stackslib/src/clarity_vm/tests/ast.rs @@ -1,19 +1,19 @@ -use crate::clarity_vm::{clarity::ClarityInstance, database::marf::MarfedKV}; use clarity::vm::ast::build_ast; use clarity::vm::test_util::{TEST_BURN_STATE_DB, TEST_HEADER_DB}; -use clarity::vm::types::QualifiedContractIdentifier; -use stacks_common::types::chainstate::StacksBlockId; - -use crate::chainstate::stacks::index::ClarityMarfTrieId; use clarity::vm::tests::test_clarity_versions; +use clarity::vm::types::QualifiedContractIdentifier; use clarity::vm::version::ClarityVersion; -use stacks_common::consts::CHAIN_ID_TESTNET; -use stacks_common::types::StacksEpochId; - #[cfg(test)] use rstest::rstest; #[cfg(test)] use rstest_reuse::{self, *}; +use stacks_common::consts::CHAIN_ID_TESTNET; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::StacksEpochId; + +use crate::chainstate::stacks::index::ClarityMarfTrieId; +use crate::clarity_vm::clarity::ClarityInstance; +use crate::clarity_vm::database::marf::MarfedKV; fn dependency_edge_counting_runtime( iters: usize, diff --git a/stackslib/src/clarity_vm/tests/contracts.rs b/stackslib/src/clarity_vm/tests/contracts.rs index e62c4a6863..b9916dac11 100644 --- a/stackslib/src/clarity_vm/tests/contracts.rs +++ b/stackslib/src/clarity_vm/tests/contracts.rs @@ -14,51 +14,40 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; - -#[cfg(any(test, feature = "testing"))] -use rstest::rstest; -#[cfg(any(test, feature = "testing"))] -use rstest_reuse::{self, *}; - -use crate::chainstate::burn::BlockSnapshot; -use crate::clarity_vm::clarity::ClarityBlockConnection; -use clarity::vm::ast; use clarity::vm::ast::errors::ParseErrors; use clarity::vm::ast::ASTRules; use clarity::vm::clarity::Error as ClarityError; use clarity::vm::contexts::{Environment, GlobalContext, OwnedEnvironment}; use clarity::vm::contracts::Contract; use clarity::vm::costs::ExecutionCost; -use clarity::vm::database::ClarityDatabase; +use clarity::vm::database::{ClarityDatabase, MemoryBackingStore}; use clarity::vm::errors::{CheckErrors, Error, RuntimeErrorType}; -use clarity::vm::execute as vm_execute; use clarity::vm::representations::SymbolicExpression; use clarity::vm::tests::{ execute, is_committed, is_err_code_i128 as is_err_code, symbols_from_values, BurnStateDB, TEST_BURN_STATE_DB, TEST_HEADER_DB, }; +use clarity::vm::types::SequenceData::Buffer; use clarity::vm::types::{ - OptionalData, PrincipalData, QualifiedContractIdentifier, ResponseData, StandardPrincipalData, - TypeSignature, Value, + BuffData, OptionalData, PrincipalData, QualifiedContractIdentifier, ResponseData, + StandardPrincipalData, TypeSignature, Value, +}; +use clarity::vm::Value::Sequence; +use clarity::vm::{ast, execute as vm_execute, ClarityVersion}; +#[cfg(any(test, feature = "testing"))] +use rstest::rstest; +#[cfg(any(test, feature = "testing"))] +use rstest_reuse::{self, *}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, SortitionId, StacksAddress, StacksBlockId, }; -use clarity::vm::ClarityVersion; -use stacks_common::types::chainstate::{ConsensusHash, SortitionId}; use stacks_common::types::StacksEpoch; use stacks_common::util::hash::hex_bytes; -use clarity::vm::types::BuffData; -use clarity::vm::types::SequenceData::Buffer; -use clarity::vm::Value::Sequence; - -use clarity::vm::database::MemoryBackingStore; - +use crate::chainstate::burn::BlockSnapshot; use crate::chainstate::stacks::boot::contract_tests::{test_sim_height_to_hash, ClarityTestSim}; -use crate::clarity::vm::clarity::ClarityConnection; -use crate::clarity::vm::clarity::TransactionConnection; +use crate::clarity::vm::clarity::{ClarityConnection, TransactionConnection}; +use crate::clarity_vm::clarity::ClarityBlockConnection; #[test] // Here, we set up a basic test to see if we can recover a path from the ClarityTestSim. diff --git a/stackslib/src/clarity_vm/tests/costs.rs b/stackslib/src/clarity_vm/tests/costs.rs index 1c387e01b2..e07e06451f 100644 --- a/stackslib/src/clarity_vm/tests/costs.rs +++ b/stackslib/src/clarity_vm/tests/costs.rs @@ -14,20 +14,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::chainstate::stacks::index::storage::TrieFileStorage; -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::clarity_vm::clarity::ClarityInstance; -use crate::core::FIRST_BURNCHAIN_CONSENSUS_HASH; -use crate::core::FIRST_STACKS_BLOCK_HASH; -use crate::util_lib::boot::boot_code_id; +use std::collections::HashMap; + use clarity::vm::ast::ASTRules; use clarity::vm::clarity::TransactionConnection; -use clarity::vm::contexts::Environment; -use clarity::vm::contexts::{AssetMap, AssetMapEntry, GlobalContext, OwnedEnvironment}; +use clarity::vm::contexts::{ + AssetMap, AssetMapEntry, Environment, GlobalContext, OwnedEnvironment, +}; use clarity::vm::contracts::Contract; use clarity::vm::costs::cost_functions::ClarityCostFunction; use clarity::vm::costs::{ClarityCostFunctionReference, ExecutionCost, LimitedCostTracker}; -use clarity::vm::database::ClarityDatabase; +use clarity::vm::database::{ClarityDatabase, MemoryBackingStore}; use clarity::vm::errors::{CheckErrors, Error, RuntimeErrorType}; use clarity::vm::events::StacksTransactionEvent; use clarity::vm::functions::NativeFunctions; @@ -36,21 +33,21 @@ use clarity::vm::test_util::{ execute, execute_on_network, symbols_from_values, TEST_BURN_STATE_DB, TEST_BURN_STATE_DB_21, TEST_HEADER_DB, }; +use clarity::vm::tests::test_only_mainnet_to_chain_id; use clarity::vm::types::{ AssetIdentifier, OptionalData, PrincipalData, QualifiedContractIdentifier, ResponseData, Value, }; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; +use clarity::vm::{ClarityVersion, ContractName}; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; use stacks_common::types::StacksEpochId; use stacks_common::util::hash::hex_bytes; -use std::collections::HashMap; - +use crate::chainstate::stacks::index::storage::TrieFileStorage; +use crate::chainstate::stacks::index::ClarityMarfTrieId; +use crate::clarity_vm::clarity::ClarityInstance; use crate::clarity_vm::database::marf::MarfedKV; -use clarity::vm::database::MemoryBackingStore; -use clarity::vm::tests::test_only_mainnet_to_chain_id; +use crate::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH}; +use crate::util_lib::boot::boot_code_id; lazy_static! { static ref COST_VOTING_MAINNET_CONTRACT: QualifiedContractIdentifier = diff --git a/stackslib/src/clarity_vm/tests/epoch_switch.rs b/stackslib/src/clarity_vm/tests/epoch_switch.rs index e443040ffd..c6c630333f 100644 --- a/stackslib/src/clarity_vm/tests/epoch_switch.rs +++ b/stackslib/src/clarity_vm/tests/epoch_switch.rs @@ -14,36 +14,32 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use rusqlite::{Connection, OptionalExtension}; - -use crate::chainstate::burn::db::sortdb::{ - SortitionDB, SortitionDBConn, SortitionHandleConn, SortitionHandleTx, -}; -use crate::chainstate::stacks::db::{MinerPaymentSchedule, StacksHeaderInfo}; -use crate::chainstate::stacks::index::MarfTrieId; -use crate::util_lib::db::{DBConn, FromRow}; use clarity::vm::analysis::AnalysisDatabase; +use clarity::vm::costs::ExecutionCost; use clarity::vm::database::{ BurnStateDB, ClarityBackingStore, ClarityDatabase, HeadersDB, SqliteConnection, NULL_BURN_STATE_DB, NULL_HEADER_DB, }; use clarity::vm::errors::{InterpreterResult, RuntimeErrorType}; use clarity::vm::test_util::{TEST_BURN_STATE_DB, TEST_HEADER_DB}; +use rand::{thread_rng, RngCore}; +use rusqlite::{Connection, OptionalExtension}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksAddress, StacksBlockId, VRFSeed, +}; +use stacks_common::util::hash::to_hex; use crate::burnchains::PoxConstants; -use crate::chainstate::stacks::index::{ClarityMarfTrieId, TrieMerkleProof}; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, SortitionId}; -use stacks_common::types::chainstate::{StacksAddress, VRFSeed}; - -use crate::core::{StacksEpoch, StacksEpochId, STACKS_EPOCH_MAX}; -use crate::core::{PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05}; - -use rand::thread_rng; -use rand::RngCore; - -use clarity::vm::costs::ExecutionCost; -use stacks_common::util::hash::to_hex; +use crate::chainstate::burn::db::sortdb::{ + SortitionDB, SortitionDBConn, SortitionHandleConn, SortitionHandleTx, +}; +use crate::chainstate::stacks::db::{MinerPaymentSchedule, StacksHeaderInfo}; +use crate::chainstate::stacks::index::{ClarityMarfTrieId, MarfTrieId, TrieMerkleProof}; +use crate::core::{ + StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, + PEER_VERSION_EPOCH_2_05, STACKS_EPOCH_MAX, +}; +use crate::util_lib::db::{DBConn, FromRow}; fn test_burnstatedb_epoch( burnstatedb: &dyn BurnStateDB, diff --git a/stackslib/src/clarity_vm/tests/events.rs b/stackslib/src/clarity_vm/tests/events.rs index d5343eb0ac..ef3c1f59e2 100644 --- a/stackslib/src/clarity_vm/tests/events.rs +++ b/stackslib/src/clarity_vm/tests/events.rs @@ -14,28 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::chainstate::stacks::StacksBlockHeader; -use crate::clarity_vm::clarity::ClarityInstance; -use crate::clarity_vm::database::marf::MarfedKV; - -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH}; +use clarity::vm::ast::ASTRules; use clarity::vm::contexts::OwnedEnvironment; use clarity::vm::costs::ExecutionCost; +use clarity::vm::database::MemoryBackingStore; use clarity::vm::events::*; -use clarity::vm::tests::execute; -use clarity::vm::tests::{TEST_BURN_STATE_DB, TEST_HEADER_DB}; +use clarity::vm::tests::{ + execute, test_only_mainnet_to_chain_id, TEST_BURN_STATE_DB, TEST_HEADER_DB, +}; use clarity::vm::types::{AssetIdentifier, BuffData, QualifiedContractIdentifier, Value}; - +use clarity::vm::{ClarityVersion, ContractContext}; use stacks_common::types::chainstate::StacksBlockId; use stacks_common::types::StacksEpochId; -use clarity::vm::ast::ASTRules; -use clarity::vm::database::MemoryBackingStore; - -use clarity::vm::tests::test_only_mainnet_to_chain_id; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractContext; +use crate::chainstate::stacks::index::ClarityMarfTrieId; +use crate::chainstate::stacks::StacksBlockHeader; +use crate::clarity_vm::clarity::ClarityInstance; +use crate::clarity_vm::database::marf::MarfedKV; +use crate::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH}; fn helper_execute(contract: &str, method: &str) -> (Value, Vec) { helper_execute_epoch(contract, method, None, StacksEpochId::Epoch21, false) diff --git a/stackslib/src/clarity_vm/tests/forking.rs b/stackslib/src/clarity_vm/tests/forking.rs index 7545d99984..b56472a566 100644 --- a/stackslib/src/clarity_vm/tests/forking.rs +++ b/stackslib/src/clarity_vm/tests/forking.rs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::chainstate::stacks::index::storage::TrieFileStorage; -use crate::chainstate::stacks::index::ClarityMarfTrieId; use clarity::vm::analysis::errors::CheckErrors; use clarity::vm::ast::ASTRules; use clarity::vm::contexts::OwnedEnvironment; @@ -25,16 +23,16 @@ use clarity::vm::representations::SymbolicExpression; use clarity::vm::test_util::{ execute, is_committed, is_err_code, symbols_from_values, TEST_BURN_STATE_DB, TEST_HEADER_DB, }; -use clarity::vm::types::Value; -use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; +use clarity::vm::tests::test_clarity_versions; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, Value}; use clarity::vm::version::ClarityVersion; use clarity::vm::ContractContext; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; use stacks_common::types::StacksEpochId; +use crate::chainstate::stacks::index::storage::TrieFileStorage; +use crate::chainstate::stacks::index::ClarityMarfTrieId; use crate::clarity_vm::database::marf::MarfedKV; -use clarity::vm::tests::test_clarity_versions; const p1_str: &str = "'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR"; diff --git a/stackslib/src/clarity_vm/tests/large_contract.rs b/stackslib/src/clarity_vm/tests/large_contract.rs index e31d8db516..9a626e8b04 100644 --- a/stackslib/src/clarity_vm/tests/large_contract.rs +++ b/stackslib/src/clarity_vm/tests/large_contract.rs @@ -14,46 +14,38 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::chainstate::stacks::index::ClarityMarfTrieId; -use crate::clarity_vm::clarity::{ClarityInstance, Error as ClarityError}; -#[cfg(test)] -use rstest::rstest; -#[cfg(test)] -use rstest_reuse::{self, *}; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; - use clarity::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; use clarity::vm::ast::{self, ASTRules}; +use clarity::vm::clarity::{ClarityConnection, TransactionConnection}; use clarity::vm::contexts::{Environment, GlobalContext, OwnedEnvironment}; use clarity::vm::contracts::Contract; use clarity::vm::costs::ExecutionCost; use clarity::vm::database::ClarityDatabase; -use clarity::vm::errors::Error as InterpreterError; -use clarity::vm::errors::{CheckErrors, Error, RuntimeErrorType}; +use clarity::vm::errors::{CheckErrors, Error as InterpreterError, Error, RuntimeErrorType}; use clarity::vm::representations::SymbolicExpression; use clarity::vm::test_util::*; +use clarity::vm::tests::test_clarity_versions; use clarity::vm::types::{ OptionalData, PrincipalData, QualifiedContractIdentifier, ResponseData, StandardPrincipalData, TypeSignature, Value, }; -use clarity::vm::ContractContext; -use clarity::vm::MAX_CALL_STACK_DEPTH; -use stacks_common::util::hash::hex_bytes; - -use crate::clarity_vm::database::marf::MarfedKV; -use crate::clarity_vm::database::MemoryBackingStore; -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::clarity::TransactionConnection; - use clarity::vm::version::ClarityVersion; - +use clarity::vm::{ContractContext, MAX_CALL_STACK_DEPTH}; +#[cfg(test)] +use rstest::rstest; +#[cfg(test)] +use rstest_reuse::{self, *}; use stacks_common::consts::{CHAIN_ID_MAINNET, CHAIN_ID_TESTNET}; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; use stacks_common::types::StacksEpochId; +use stacks_common::util::hash::hex_bytes; use crate::chainstate::stacks::boot::{BOOT_CODE_COSTS, BOOT_CODE_COSTS_2, BOOT_CODE_COSTS_3}; +use crate::chainstate::stacks::index::ClarityMarfTrieId; +use crate::clarity_vm::clarity::{ClarityInstance, Error as ClarityError}; +use crate::clarity_vm::database::marf::MarfedKV; +use crate::clarity_vm::database::MemoryBackingStore; use crate::util_lib::boot::boot_code_id; -use clarity::vm::tests::test_clarity_versions; fn test_block_headers(n: u8) -> StacksBlockId { StacksBlockId([n as u8; 32]) diff --git a/stackslib/src/clarity_vm/tests/simple_tests.rs b/stackslib/src/clarity_vm/tests/simple_tests.rs index 0365f69655..0367bd8448 100644 --- a/stackslib/src/clarity_vm/tests/simple_tests.rs +++ b/stackslib/src/clarity_vm/tests/simple_tests.rs @@ -3,8 +3,7 @@ use clarity::vm::errors::{Error, RuntimeErrorType}; use clarity::vm::test_util::{TEST_BURN_STATE_DB, TEST_HEADER_DB}; use clarity::vm::types::QualifiedContractIdentifier; use stacks_common::consts::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH}; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; use stacks_common::types::StacksEpochId; use crate::chainstate::stacks::index::ClarityMarfTrieId; diff --git a/stackslib/src/core/mempool.rs b/stackslib/src/core/mempool.rs index 16ad765814..b853401fd9 100644 --- a/stackslib/src/core/mempool.rs +++ b/stackslib/src/core/mempool.rs @@ -16,81 +16,56 @@ use std::cmp::{self, Ordering}; use std::collections::{HashMap, HashSet, VecDeque}; -use std::fs; use std::hash::Hasher; -use std::io; use std::io::{Read, Write}; -use std::ops::Deref; -use std::ops::DerefMut; +use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; +use std::time::Instant; +use std::{fs, io}; +use clarity::vm::types::PrincipalData; use rand::distributions::Uniform; use rand::prelude::Distribution; use rusqlite::types::ToSql; -use rusqlite::Connection; -use rusqlite::Error as SqliteError; -use rusqlite::OpenFlags; -use rusqlite::OptionalExtension; -use rusqlite::Row; -use rusqlite::Rows; -use rusqlite::Transaction; -use rusqlite::NO_PARAMS; - +use rusqlite::{ + Connection, Error as SqliteError, OpenFlags, OptionalExtension, Row, Rows, Transaction, + NO_PARAMS, +}; use siphasher::sip::SipHasher; // this is SipHash-2-4 +use stacks_common::codec::{ + read_next, write_next, Error as codec_error, StacksMessageCodec, MAX_MESSAGE_LEN, +}; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, StacksBlockId}; +use stacks_common::util::hash::{to_hex, Sha512Trunc256Sum}; +use stacks_common::util::retry::{BoundReader, RetryReader}; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs}; use crate::burnchains::Txid; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::burn::ConsensusHash; +use crate::chainstate::stacks::db::blocks::MemPoolRejection; +use crate::chainstate::stacks::db::{ClarityTx, StacksChainState}; +use crate::chainstate::stacks::events::StacksTransactionReceipt; +use crate::chainstate::stacks::index::Error as MarfError; +use crate::chainstate::stacks::miner::TransactionEvent; use crate::chainstate::stacks::{ - db::blocks::MemPoolRejection, db::ClarityTx, db::StacksChainState, index::Error as MarfError, - Error as ChainstateError, StacksTransaction, + Error as ChainstateError, StacksBlock, StacksMicroblock, StacksTransaction, TransactionPayload, }; -use crate::chainstate::stacks::{StacksMicroblock, TransactionPayload}; -use crate::core::ExecutionCost; -use crate::core::StacksEpochId; -use crate::core::FIRST_BURNCHAIN_CONSENSUS_HASH; -use crate::core::FIRST_STACKS_BLOCK_HASH; +use crate::clarity_vm::clarity::ClarityConnection; +use crate::core::{ + ExecutionCost, StacksEpochId, FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, +}; +use crate::cost_estimates::metrics::{CostMetric, UnitMetric}; +use crate::cost_estimates::{CostEstimator, EstimatorError, UnitEstimator}; use crate::monitoring::increment_stx_mempool_gc; use crate::net::Error as net_error; -use crate::util_lib::db::query_int; -use crate::util_lib::db::query_row_columns; -use crate::util_lib::db::query_rows; -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::tx_begin_immediate; -use crate::util_lib::db::tx_busy_handler; -use crate::util_lib::db::u64_to_sql; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::FromColumn; -use crate::util_lib::db::{query_row, Error}; -use crate::util_lib::db::{sql_pragma, DBConn, DBTx, FromRow}; -use clarity::vm::types::PrincipalData; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha512Trunc256Sum; -use std::time::Instant; - use crate::util_lib::bloom::{BloomCounter, BloomFilter, BloomNodeHasher}; - -use crate::clarity_vm::clarity::ClarityConnection; - -use crate::chainstate::stacks::events::StacksTransactionReceipt; -use crate::chainstate::stacks::miner::TransactionEvent; -use crate::chainstate::stacks::StacksBlock; -use crate::cost_estimates; -use crate::cost_estimates::metrics::CostMetric; -use crate::cost_estimates::metrics::UnitMetric; -use crate::cost_estimates::CostEstimator; -use crate::cost_estimates::EstimatorError; -use crate::cost_estimates::UnitEstimator; -use crate::monitoring; -use crate::util_lib::db::table_exists; -use stacks_common::codec::Error as codec_error; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, StacksBlockId}; - -use stacks_common::codec::{read_next, write_next, MAX_MESSAGE_LEN}; -use stacks_common::util::retry::{BoundReader, RetryReader}; +use crate::util_lib::db::{ + query_int, query_row, query_row_columns, query_rows, sql_pragma, sqlite_open, table_exists, + tx_begin_immediate, tx_busy_handler, u64_to_sql, DBConn, DBTx, Error as db_error, Error, + FromColumn, FromRow, +}; +use crate::{cost_estimates, monitoring}; // maximum number of confirmations a transaction can have before it's garbage-collected pub const MEMPOOL_MAX_TRANSACTION_AGE: u64 = 256; diff --git a/stackslib/src/core/mod.rs b/stackslib/src/core/mod.rs index 17cda22173..b09ee9f2cd 100644 --- a/stackslib/src/core/mod.rs +++ b/stackslib/src/core/mod.rs @@ -14,27 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::burnchains::Burnchain; -use crate::burnchains::Error as burnchain_error; -use crate::chainstate::burn::ConsensusHash; -use clarity::vm::costs::ExecutionCost; -use stacks_common::util::log; use std::collections::HashSet; use std::convert::TryFrom; -pub use self::mempool::MemPoolDB; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash}; +use clarity::vm::costs::ExecutionCost; +use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksBlockId}; use stacks_common::types::StacksEpoch as GenericStacksEpoch; pub use stacks_common::types::StacksEpochId; +use stacks_common::util::log; + +pub use self::mempool::MemPoolDB; +use crate::burnchains::{Burnchain, Error as burnchain_error}; +use crate::chainstate::burn::ConsensusHash; pub mod mempool; #[cfg(test)] pub mod tests; -use std::cmp::Ord; -use std::cmp::Ordering; -use std::cmp::PartialOrd; +use std::cmp::{Ord, Ordering, PartialOrd}; pub type StacksEpoch = GenericStacksEpoch; diff --git a/stackslib/src/core/tests/mod.rs b/stackslib/src/core/tests/mod.rs index b064a43e5f..8902ff4cb8 100644 --- a/stackslib/src/core/tests/mod.rs +++ b/stackslib/src/core/tests/mod.rs @@ -14,77 +14,59 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::cmp; -use std::collections::HashMap; -use std::collections::HashSet; -use std::io; +use std::collections::{HashMap, HashSet}; +use std::{cmp, io}; -use crate::burnchains::Address; -use crate::burnchains::Txid; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::database::HeadersDB; +use clarity::vm::errors::{Error as ClarityError, RuntimeErrorType}; +use clarity::vm::test_util::TEST_BURN_STATE_DB; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; +use rand::prelude::*; +use rand::thread_rng; +use stacks_common::address::AddressHashMode; +use stacks_common::codec::{read_next, Error as codec_error, StacksMessageCodec}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, StacksWorkScore, TrieHash, + VRFSeed, +}; +use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, *}; +use stacks_common::util::secp256k1::{MessageSignature, *}; +use stacks_common::util::vrf::VRFProof; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs, log, sleep_ms}; + +use super::MemPoolDB; +use crate::burnchains::{Address, Txid}; use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::stacks::db::test::chainstate_path; -use crate::chainstate::stacks::db::test::instantiate_chainstate; -use crate::chainstate::stacks::db::test::instantiate_chainstate_with_balances; +use crate::chainstate::stacks::db::blocks::MemPoolRejection; +use crate::chainstate::stacks::db::test::{ + chainstate_path, instantiate_chainstate, instantiate_chainstate_with_balances, +}; +use crate::chainstate::stacks::db::{StacksChainState, StacksHeaderInfo}; use crate::chainstate::stacks::events::StacksTransactionReceipt; +use crate::chainstate::stacks::index::{MarfTrieId, TrieHashExtension}; use crate::chainstate::stacks::miner::TransactionResult; use crate::chainstate::stacks::test::codec_all_transactions; use crate::chainstate::stacks::{ - db::blocks::MemPoolRejection, db::StacksChainState, index::MarfTrieId, CoinbasePayload, - Error as ChainstateError, SinglesigHashMode, SinglesigSpendingCondition, StacksPrivateKey, - StacksPublicKey, StacksTransaction, StacksTransactionSigner, TokenTransferMemo, - TransactionAnchorMode, TransactionAuth, TransactionContractCall, TransactionPayload, - TransactionPostConditionMode, TransactionPublicKeyEncoding, TransactionSmartContract, - TransactionSpendingCondition, TransactionVersion, + CoinbasePayload, Error as ChainstateError, SinglesigHashMode, SinglesigSpendingCondition, + StacksBlockHeader, StacksMicroblockHeader, StacksPrivateKey, StacksPublicKey, + StacksTransaction, StacksTransactionSigner, TokenTransferMemo, TransactionAnchorMode, + TransactionAuth, TransactionContractCall, TransactionPayload, TransactionPostConditionMode, + TransactionPublicKeyEncoding, TransactionSmartContract, TransactionSpendingCondition, + TransactionVersion, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, + C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; -use crate::chainstate::stacks::{ - C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, +use crate::core::mempool::{ + db_get_all_nonces, MemPoolSyncData, MemPoolWalkSettings, TxTag, BLOOM_COUNTER_DEPTH, + BLOOM_COUNTER_ERROR_RATE, MAX_BLOOM_COUNTER_TXS, }; -use crate::core::mempool::db_get_all_nonces; -use crate::core::mempool::decode_tx_stream; -use crate::core::mempool::MemPoolSyncData; -use crate::core::mempool::MemPoolWalkSettings; -use crate::core::mempool::TxTag; -use crate::core::mempool::{BLOOM_COUNTER_DEPTH, BLOOM_COUNTER_ERROR_RATE, MAX_BLOOM_COUNTER_TXS}; -use crate::core::FIRST_BURNCHAIN_CONSENSUS_HASH; -use crate::core::FIRST_STACKS_BLOCK_HASH; +use crate::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH}; use crate::net::Error as NetError; use crate::util_lib::bloom::test::setup_bloom_counter; use crate::util_lib::bloom::*; use crate::util_lib::db::{tx_begin_immediate, DBConn, FromRow}; use crate::util_lib::strings::StacksString; -use clarity::vm::{ - database::HeadersDB, - errors::Error as ClarityError, - errors::RuntimeErrorType, - test_util::TEST_BURN_STATE_DB, - types::{PrincipalData, QualifiedContractIdentifier}, - ClarityName, ContractName, Value, -}; -use stacks_common::address::AddressHashMode; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::util::hash::Hash160; -use stacks_common::util::secp256k1::MessageSignature; -use stacks_common::util::sleep_ms; -use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs}; -use stacks_common::util::{hash::hex_bytes, hash::to_hex, hash::*, log, secp256k1::*}; - -use crate::chainstate::stacks::db::StacksHeaderInfo; -use crate::chainstate::stacks::index::TrieHashExtension; -use crate::chainstate::stacks::{StacksBlockHeader, StacksMicroblockHeader}; -use clarity::vm::costs::ExecutionCost; -use clarity::vm::types::StacksAddressExtensions; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash}; -use stacks_common::types::chainstate::{StacksAddress, StacksBlockId, StacksWorkScore, VRFSeed}; -use stacks_common::util::vrf::VRFProof; - -use super::MemPoolDB; - -use rand::prelude::*; -use rand::thread_rng; - -use stacks_common::codec::read_next; -use stacks_common::codec::Error as codec_error; const FOO_CONTRACT: &'static str = "(define-public (foo) (ok 1)) (define-public (bar (x uint)) (ok x))"; diff --git a/stackslib/src/cost_estimates/fee_medians.rs b/stackslib/src/cost_estimates/fee_medians.rs index ac7e032204..7e1a2459b4 100644 --- a/stackslib/src/cost_estimates/fee_medians.rs +++ b/stackslib/src/cost_estimates/fee_medians.rs @@ -1,33 +1,27 @@ use std::cmp; use std::cmp::Ordering; use std::convert::TryFrom; -use std::{iter::FromIterator, path::Path}; +use std::iter::FromIterator; +use std::path::Path; -use rusqlite::AndThenRows; -use rusqlite::Transaction as SqlTransaction; +use clarity::vm::costs::ExecutionCost; +use rusqlite::types::{FromSql, FromSqlError}; use rusqlite::{ - types::{FromSql, FromSqlError}, - Connection, Error as SqliteError, OptionalExtension, ToSql, + AndThenRows, Connection, Error as SqliteError, OptionalExtension, ToSql, + Transaction as SqlTransaction, }; use serde_json::Value as JsonValue; +use super::metrics::{CostMetric, PROPORTION_RESOLUTION}; +use super::{EstimatorError, FeeEstimator, FeeRateEstimate}; +use crate::chainstate::stacks::db::StacksEpochReceipt; +use crate::chainstate::stacks::events::TransactionOrigin; use crate::chainstate::stacks::TransactionPayload; +use crate::cost_estimates::StacksTransactionReceipt; use crate::util_lib::db::{ sql_pragma, sqlite_open, table_exists, tx_begin_immediate_sqlite, u64_to_sql, }; -use clarity::vm::costs::ExecutionCost; - -use crate::chainstate::stacks::db::StacksEpochReceipt; -use crate::chainstate::stacks::events::TransactionOrigin; - -use super::metrics::CostMetric; -use super::FeeRateEstimate; -use super::{EstimatorError, FeeEstimator}; - -use super::metrics::PROPORTION_RESOLUTION; -use crate::cost_estimates::StacksTransactionReceipt; - const CREATE_TABLE: &'static str = " CREATE TABLE median_fee_estimator ( measure_key INTEGER PRIMARY KEY AUTOINCREMENT, diff --git a/stackslib/src/cost_estimates/fee_rate_fuzzer.rs b/stackslib/src/cost_estimates/fee_rate_fuzzer.rs index c2534aa2f7..852c524547 100644 --- a/stackslib/src/cost_estimates/fee_rate_fuzzer.rs +++ b/stackslib/src/cost_estimates/fee_rate_fuzzer.rs @@ -1,13 +1,10 @@ use clarity::vm::costs::ExecutionCost; - -use super::FeeRateEstimate; -use super::{EstimatorError, FeeEstimator}; -use crate::chainstate::stacks::db::StacksEpochReceipt; use rand::distributions::{Distribution, Uniform}; use rand::rngs::StdRng; -use rand::thread_rng; -use rand::RngCore; -use rand::SeedableRng; +use rand::{thread_rng, RngCore, SeedableRng}; + +use super::{EstimatorError, FeeEstimator, FeeRateEstimate}; +use crate::chainstate::stacks::db::StacksEpochReceipt; /// The FeeRateFuzzer wraps an underlying FeeEstimator. It passes `notify_block` calls to the /// underlying estimator. On `get_rate_estimates` calls, it adds a random fuzz to the result coming diff --git a/stackslib/src/cost_estimates/fee_scalar.rs b/stackslib/src/cost_estimates/fee_scalar.rs index ca252940cb..14c4471458 100644 --- a/stackslib/src/cost_estimates/fee_scalar.rs +++ b/stackslib/src/cost_estimates/fee_scalar.rs @@ -1,30 +1,23 @@ use std::cmp; use std::convert::TryFrom; -use std::{iter::FromIterator, path::Path}; +use std::iter::FromIterator; +use std::path::Path; -use rusqlite::Transaction as SqlTransaction; +use clarity::vm::costs::ExecutionCost; +use rusqlite::types::{FromSql, FromSqlError}; use rusqlite::{ - types::{FromSql, FromSqlError}, - Connection, Error as SqliteError, OptionalExtension, ToSql, + Connection, Error as SqliteError, OptionalExtension, ToSql, Transaction as SqlTransaction, }; use serde_json::Value as JsonValue; -use crate::chainstate::stacks::TransactionPayload; -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::tx_begin_immediate_sqlite; -use crate::util_lib::db::u64_to_sql; - -use clarity::vm::costs::ExecutionCost; - +use super::metrics::CostMetric; +use super::{EstimatorError, FeeEstimator, FeeRateEstimate}; use crate::chainstate::stacks::db::StacksEpochReceipt; use crate::chainstate::stacks::events::TransactionOrigin; - -use crate::util_lib::db::sql_pragma; -use crate::util_lib::db::table_exists; - -use super::metrics::CostMetric; -use super::FeeRateEstimate; -use super::{EstimatorError, FeeEstimator}; +use crate::chainstate::stacks::TransactionPayload; +use crate::util_lib::db::{ + sql_pragma, sqlite_open, table_exists, tx_begin_immediate_sqlite, u64_to_sql, +}; const SINGLETON_ROW_ID: i64 = 1; const CREATE_TABLE: &'static str = " diff --git a/stackslib/src/cost_estimates/mod.rs b/stackslib/src/cost_estimates/mod.rs index 475bbab0d0..f50e2db412 100644 --- a/stackslib/src/cost_estimates/mod.rs +++ b/stackslib/src/cost_estimates/mod.rs @@ -1,17 +1,18 @@ use std::cmp; use std::collections::HashMap; +use std::error::Error; +use std::fmt::Display; use std::iter::FromIterator; use std::ops::{Add, Div, Mul, Rem, Sub}; use std::path::Path; -use std::{error::Error, fmt::Display}; -use crate::chainstate::stacks::events::{StacksTransactionReceipt, TransactionOrigin}; -use crate::chainstate::stacks::{StacksBlock, TransactionPayload}; use clarity::vm::costs::ExecutionCost; use rusqlite::Error as SqliteError; use crate::burnchains::Txid; use crate::chainstate::stacks::db::StacksEpochReceipt; +use crate::chainstate::stacks::events::{StacksTransactionReceipt, TransactionOrigin}; +use crate::chainstate::stacks::{StacksBlock, TransactionPayload}; pub mod fee_medians; pub mod fee_rate_fuzzer; @@ -22,11 +23,10 @@ pub mod pessimistic; #[cfg(test)] pub mod tests; -use crate::chainstate::stacks::StacksTransaction; -use crate::core::StacksEpochId; - use self::metrics::CostMetric; pub use self::pessimistic::PessimisticEstimator; +use crate::chainstate::stacks::StacksTransaction; +use crate::core::StacksEpochId; /// This trait is for implementation of *fee rate* estimation: estimators should /// track the actual paid fee rate for transactions in blocks, and use that to diff --git a/stackslib/src/cost_estimates/pessimistic.rs b/stackslib/src/cost_estimates/pessimistic.rs index fffe05d7a0..bd76d9f4a9 100644 --- a/stackslib/src/cost_estimates/pessimistic.rs +++ b/stackslib/src/cost_estimates/pessimistic.rs @@ -1,25 +1,22 @@ use std::cmp; use std::convert::TryFrom; -use std::{iter::FromIterator, path::Path}; +use std::iter::FromIterator; +use std::path::Path; -use super::metrics::PROPORTION_RESOLUTION; +use clarity::vm::costs::ExecutionCost; +use rusqlite::types::{FromSql, FromSqlError}; use rusqlite::{ - types::{FromSql, FromSqlError}, Connection, Error as SqliteError, OptionalExtension, ToSql, Transaction as SqliteTransaction, }; use serde_json::Value as JsonValue; -use crate::chainstate::stacks::TransactionPayload; -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::u64_to_sql; -use clarity::vm::costs::ExecutionCost; - -use crate::util_lib::db::sql_pragma; -use crate::util_lib::db::table_exists; -use crate::util_lib::db::tx_begin_immediate_sqlite; - +use super::metrics::PROPORTION_RESOLUTION; use super::{CostEstimator, EstimatorError}; +use crate::chainstate::stacks::TransactionPayload; use crate::core::StacksEpochId; +use crate::util_lib::db::{ + sql_pragma, sqlite_open, table_exists, tx_begin_immediate_sqlite, u64_to_sql, +}; /// This struct pessimistically estimates the `ExecutionCost` of transaction payloads. /// diff --git a/stackslib/src/cost_estimates/tests/common.rs b/stackslib/src/cost_estimates/tests/common.rs index 882de6fb66..b290c6d000 100644 --- a/stackslib/src/cost_estimates/tests/common.rs +++ b/stackslib/src/cost_estimates/tests/common.rs @@ -1,12 +1,13 @@ -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::stacks::db::{StacksEpochReceipt, StacksHeaderInfo}; -use crate::chainstate::stacks::events::StacksTransactionReceipt; use clarity::vm::costs::ExecutionCost; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksWorkScore}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksWorkScore, TrieHash, +}; use stacks_common::util::hash::{to_hex, Hash160, Sha512Trunc256Sum}; use stacks_common::util::vrf::VRFProof; +use crate::chainstate::burn::ConsensusHash; +use crate::chainstate::stacks::db::{StacksEpochReceipt, StacksHeaderInfo}; +use crate::chainstate::stacks::events::StacksTransactionReceipt; use crate::chainstate::stacks::{ CoinbasePayload, StacksBlockHeader, StacksTransaction, TokenTransferMemo, TransactionAuth, TransactionContractCall, TransactionPayload, TransactionSpendingCondition, TransactionVersion, diff --git a/stackslib/src/cost_estimates/tests/cost_estimators.rs b/stackslib/src/cost_estimates/tests/cost_estimators.rs index 4016507a5b..eccaaba708 100644 --- a/stackslib/src/cost_estimates/tests/cost_estimators.rs +++ b/stackslib/src/cost_estimates/tests/cost_estimators.rs @@ -1,37 +1,32 @@ -use std::{env, path::PathBuf}; -use time::Instant; +use std::env; +use std::path::PathBuf; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::types::{PrincipalData, StandardPrincipalData}; +use clarity::vm::Value; use rand::seq::SliceRandom; use rand::Rng; - -use crate::cost_estimates::metrics::CostMetric; -use crate::cost_estimates::{EstimatorError, FeeEstimator}; -use clarity::vm::costs::ExecutionCost; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksWorkScore, TrieHash, +}; +use stacks_common::util::hash::{to_hex, Hash160, Sha512Trunc256Sum}; +use stacks_common::util::vrf::VRFProof; +use time::Instant; use crate::chainstate::burn::ConsensusHash; use crate::chainstate::stacks::db::{StacksEpochReceipt, StacksHeaderInfo}; use crate::chainstate::stacks::events::StacksTransactionReceipt; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksWorkScore}; - -use stacks_common::util::hash::{to_hex, Hash160, Sha512Trunc256Sum}; -use stacks_common::util::vrf::VRFProof; - -use crate::chainstate::stacks::StacksBlockHeader; use crate::chainstate::stacks::{ - CoinbasePayload, StacksTransaction, TokenTransferMemo, TransactionAuth, + CoinbasePayload, StacksBlockHeader, StacksTransaction, TokenTransferMemo, TransactionAuth, TransactionContractCall, TransactionPayload, TransactionSpendingCondition, TransactionVersion, }; -use crate::core::StacksEpochId; -use crate::core::BLOCK_LIMIT_MAINNET_20; +use crate::core::{StacksEpochId, BLOCK_LIMIT_MAINNET_20}; use crate::cost_estimates::fee_scalar::ScalarFeeRateEstimator; +use crate::cost_estimates::metrics::CostMetric; use crate::cost_estimates::tests::common::*; -use crate::cost_estimates::CostEstimator; -use crate::cost_estimates::FeeRateEstimate; -use crate::cost_estimates::PessimisticEstimator; -use clarity::vm::types::{PrincipalData, StandardPrincipalData}; -use clarity::vm::Value; +use crate::cost_estimates::{ + CostEstimator, EstimatorError, FeeEstimator, FeeRateEstimate, PessimisticEstimator, +}; fn instantiate_test_db() -> PessimisticEstimator { let mut path = env::temp_dir(); diff --git a/stackslib/src/cost_estimates/tests/fee_medians.rs b/stackslib/src/cost_estimates/tests/fee_medians.rs index 429311a470..0b85650f84 100644 --- a/stackslib/src/cost_estimates/tests/fee_medians.rs +++ b/stackslib/src/cost_estimates/tests/fee_medians.rs @@ -1,32 +1,29 @@ use std::env; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::types::{PrincipalData, StandardPrincipalData}; +use clarity::vm::Value; use rand::seq::SliceRandom; use rand::Rng; - -use crate::cost_estimates::metrics::CostMetric; -use crate::cost_estimates::{EstimatorError, FeeEstimator}; -use clarity::vm::costs::ExecutionCost; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksWorkScore, +}; +use stacks_common::util::hash::{to_hex, Hash160, Sha512Trunc256Sum}; use crate::chainstate::burn::ConsensusHash; use crate::chainstate::stacks::db::{StacksEpochReceipt, StacksHeaderInfo}; use crate::chainstate::stacks::events::StacksTransactionReceipt; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksWorkScore}; -use stacks_common::util::hash::{to_hex, Hash160, Sha512Trunc256Sum}; - use crate::chainstate::stacks::{ CoinbasePayload, StacksBlockHeader, StacksTransaction, TokenTransferMemo, TransactionAuth, TransactionContractCall, TransactionPayload, TransactionSpendingCondition, TransactionVersion, }; use crate::core::StacksEpochId; -use crate::cost_estimates::fee_medians::fee_rate_estimate_from_sorted_weighted_fees; -use crate::cost_estimates::fee_medians::FeeRateAndWeight; -use crate::cost_estimates::fee_medians::WeightedMedianFeeRateEstimator; -use crate::cost_estimates::metrics::ProportionalDotProduct; +use crate::cost_estimates::fee_medians::{ + fee_rate_estimate_from_sorted_weighted_fees, FeeRateAndWeight, WeightedMedianFeeRateEstimator, +}; +use crate::cost_estimates::metrics::{CostMetric, ProportionalDotProduct}; use crate::cost_estimates::tests::common::*; -use crate::cost_estimates::FeeRateEstimate; -use clarity::vm::types::{PrincipalData, StandardPrincipalData}; -use clarity::vm::Value; -use stacks_common::types::chainstate::StacksAddress; +use crate::cost_estimates::{EstimatorError, FeeEstimator, FeeRateEstimate}; /// Returns true iff `b` is within `0.1%` of `a`. fn is_close_f64(a: f64, b: f64) -> bool { diff --git a/stackslib/src/cost_estimates/tests/fee_rate_fuzzer.rs b/stackslib/src/cost_estimates/tests/fee_rate_fuzzer.rs index 4319f3332b..1a1d953b25 100644 --- a/stackslib/src/cost_estimates/tests/fee_rate_fuzzer.rs +++ b/stackslib/src/cost_estimates/tests/fee_rate_fuzzer.rs @@ -1,24 +1,19 @@ -use crate::cost_estimates::{EstimatorError, FeeEstimator}; use clarity::vm::costs::ExecutionCost; +use rand::rngs::StdRng; +use rand::{thread_rng, RngCore, SeedableRng}; +use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash}; use crate::chainstate::burn::ConsensusHash; use crate::chainstate::stacks::db::{StacksEpochReceipt, StacksHeaderInfo}; use crate::chainstate::stacks::events::StacksTransactionReceipt; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash}; - use crate::chainstate::stacks::{ CoinbasePayload, StacksTransaction, TokenTransferMemo, TransactionAuth, TransactionContractCall, TransactionPayload, TransactionSpendingCondition, TransactionVersion, }; use crate::core::StacksEpochId; use crate::cost_estimates::fee_rate_fuzzer::FeeRateFuzzer; -use crate::cost_estimates::FeeRateEstimate; -use rand::rngs::StdRng; -use rand::thread_rng; -use rand::RngCore; -use rand::SeedableRng; - use crate::cost_estimates::tests::common::make_block_receipt; +use crate::cost_estimates::{EstimatorError, FeeEstimator, FeeRateEstimate}; struct ConstantFeeEstimator {} diff --git a/stackslib/src/cost_estimates/tests/fee_scalar.rs b/stackslib/src/cost_estimates/tests/fee_scalar.rs index ab4251884c..68339e59b7 100644 --- a/stackslib/src/cost_estimates/tests/fee_scalar.rs +++ b/stackslib/src/cost_estimates/tests/fee_scalar.rs @@ -1,34 +1,30 @@ -use std::{env, path::PathBuf}; -use time::Instant; +use std::env; +use std::path::PathBuf; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::types::{PrincipalData, StandardPrincipalData}; +use clarity::vm::Value; use rand::seq::SliceRandom; use rand::Rng; - -use crate::cost_estimates::metrics::CostMetric; -use crate::cost_estimates::{EstimatorError, FeeEstimator}; -use clarity::vm::costs::ExecutionCost; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksWorkScore, TrieHash, +}; +use stacks_common::util::hash::{to_hex, Hash160, Sha512Trunc256Sum}; +use stacks_common::util::vrf::VRFProof; +use time::Instant; use crate::chainstate::burn::ConsensusHash; use crate::chainstate::stacks::db::{StacksEpochReceipt, StacksHeaderInfo}; use crate::chainstate::stacks::events::StacksTransactionReceipt; -use crate::chainstate::stacks::StacksBlockHeader; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksWorkScore}; -use stacks_common::util::hash::{to_hex, Hash160, Sha512Trunc256Sum}; -use stacks_common::util::vrf::VRFProof; - use crate::chainstate::stacks::{ - CoinbasePayload, StacksTransaction, TokenTransferMemo, TransactionAuth, + CoinbasePayload, StacksBlockHeader, StacksTransaction, TokenTransferMemo, TransactionAuth, TransactionContractCall, TransactionPayload, TransactionSpendingCondition, TransactionVersion, }; use crate::core::StacksEpochId; use crate::cost_estimates::fee_scalar::ScalarFeeRateEstimator; -use crate::cost_estimates::FeeRateEstimate; -use clarity::vm::types::{PrincipalData, StandardPrincipalData}; -use clarity::vm::Value; -use stacks_common::types::chainstate::StacksAddress; - +use crate::cost_estimates::metrics::CostMetric; use crate::cost_estimates::tests::common::make_block_receipt; +use crate::cost_estimates::{EstimatorError, FeeEstimator, FeeRateEstimate}; fn instantiate_test_db(m: CM) -> ScalarFeeRateEstimator { let mut path = env::temp_dir(); diff --git a/stackslib/src/cost_estimates/tests/metrics.rs b/stackslib/src/cost_estimates/tests/metrics.rs index 3cb0d0f763..c4e3d58f14 100644 --- a/stackslib/src/cost_estimates/tests/metrics.rs +++ b/stackslib/src/cost_estimates/tests/metrics.rs @@ -1,7 +1,8 @@ +use clarity::vm::costs::ExecutionCost; + use crate::chainstate::stacks::MAX_BLOCK_LEN; use crate::core::BLOCK_LIMIT_MAINNET_20; use crate::cost_estimates::metrics::{CostMetric, ProportionalDotProduct}; -use clarity::vm::costs::ExecutionCost; #[test] // Test that when dimensions of the execution cost are near "zero", diff --git a/stackslib/src/main.rs b/stackslib/src/main.rs index d660f74be3..c70e5c2e7a 100644 --- a/stackslib/src/main.rs +++ b/stackslib/src/main.rs @@ -32,77 +32,58 @@ extern crate serde_json; #[macro_use(o, slog_log, slog_trace, slog_debug, slog_info, slog_warn, slog_error)] extern crate slog; -use std::io; +use std::collections::{HashMap, HashSet}; +use std::convert::TryFrom; +use std::fs::{File, OpenOptions}; use std::io::prelude::*; -use std::process; -use std::thread; -use std::{collections::HashMap, env}; -use std::{convert::TryFrom, fs}; +use std::io::BufReader; +use std::{env, fs, io, process, thread}; -use blockstack_lib::burnchains::BLOCKSTACK_MAGIC_MAINNET; -use blockstack_lib::clarity_cli; -use blockstack_lib::cost_estimates::UnitEstimator; -use rusqlite::types::ToSql; -use rusqlite::Connection; -use rusqlite::OpenFlags; - -use blockstack_lib::burnchains::bitcoin::indexer::BitcoinIndexer; -use blockstack_lib::burnchains::bitcoin::indexer::{BitcoinIndexerConfig, BitcoinIndexerRuntime}; -use blockstack_lib::burnchains::bitcoin::spv; -use blockstack_lib::burnchains::bitcoin::BitcoinNetworkType; -use blockstack_lib::burnchains::db::BurnchainDB; -use blockstack_lib::burnchains::Address; -use blockstack_lib::burnchains::Burnchain; -use blockstack_lib::burnchains::Txid; +use blockstack_lib::burnchains::bitcoin::indexer::{ + BitcoinIndexer, BitcoinIndexerConfig, BitcoinIndexerRuntime, +}; +use blockstack_lib::burnchains::bitcoin::{spv, BitcoinNetworkType}; +use blockstack_lib::burnchains::db::{BurnchainBlockData, BurnchainDB}; +use blockstack_lib::burnchains::{ + Address, Burnchain, PoxConstants, Txid, BLOCKSTACK_MAGIC_MAINNET, +}; +use blockstack_lib::chainstate::burn::db::sortdb::SortitionDB; use blockstack_lib::chainstate::burn::ConsensusHash; -use blockstack_lib::chainstate::stacks::db::blocks::DummyEventDispatcher; -use blockstack_lib::chainstate::stacks::db::blocks::StagingBlock; -use blockstack_lib::chainstate::stacks::db::ChainStateBootData; -use blockstack_lib::chainstate::stacks::index::marf::MARFOpenOpts; -use blockstack_lib::chainstate::stacks::index::marf::MarfConnection; -use blockstack_lib::chainstate::stacks::index::marf::MARF; +use blockstack_lib::chainstate::stacks::db::blocks::{DummyEventDispatcher, StagingBlock}; +use blockstack_lib::chainstate::stacks::db::{ + ChainStateBootData, StacksChainState, StacksHeaderInfo, +}; +use blockstack_lib::chainstate::stacks::index::marf::{MARFOpenOpts, MarfConnection, MARF}; use blockstack_lib::chainstate::stacks::index::ClarityMarfTrieId; use blockstack_lib::chainstate::stacks::miner::*; -use blockstack_lib::chainstate::stacks::StacksBlockHeader; -use blockstack_lib::chainstate::stacks::*; +use blockstack_lib::chainstate::stacks::{StacksBlockHeader, *}; use blockstack_lib::clarity::vm::costs::ExecutionCost; use blockstack_lib::clarity::vm::types::StacksAddressExtensions; use blockstack_lib::clarity::vm::ClarityVersion; +use blockstack_lib::clarity_cli; use blockstack_lib::clarity_cli::vm_execute; -use blockstack_lib::core::*; +use blockstack_lib::core::{MemPoolDB, *}; use blockstack_lib::cost_estimates::metrics::UnitMetric; +use blockstack_lib::cost_estimates::UnitEstimator; +use blockstack_lib::net::db::LocalPeer; +use blockstack_lib::net::p2p::PeerNetwork; use blockstack_lib::net::relay::Relayer; -use blockstack_lib::net::{db::LocalPeer, p2p::PeerNetwork}; +use blockstack_lib::util_lib::db::sqlite_open; use blockstack_lib::util_lib::strings::UrlString; -use blockstack_lib::{ - burnchains::{db::BurnchainBlockData, PoxConstants}, - chainstate::{ - burn::db::sortdb::SortitionDB, - stacks::db::{StacksChainState, StacksHeaderInfo}, - }, - core::MemPoolDB, - util_lib::db::sqlite_open, -}; +use libstackerdb::StackerDBChunkData; +use rusqlite::types::ToSql; +use rusqlite::{Connection, OpenFlags}; use serde_json::Value; use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::StacksAddress; use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, PoxId, StacksBlockId, + BlockHeaderHash, BurnchainHeaderHash, PoxId, StacksAddress, StacksBlockId, }; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::hash::{hex_bytes, to_hex}; -use stacks_common::util::log; -use stacks_common::util::retry::LogReader; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::secp256k1::Secp256k1PublicKey; -use stacks_common::util::sleep_ms; -use stacks_common::util::{hash::Hash160, vrf::VRFProof}; -use std::collections::HashSet; -use std::fs::{File, OpenOptions}; -use std::io::BufReader; - -use libstackerdb::StackerDBChunkData; use stacks_common::types::net::PeerAddress; +use stacks_common::util::hash::{hex_bytes, to_hex, Hash160}; +use stacks_common::util::retry::LogReader; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; +use stacks_common::util::vrf::VRFProof; +use stacks_common::util::{get_epoch_time_ms, log, sleep_ms}; fn main() { let mut argv: Vec = env::args().collect(); diff --git a/stackslib/src/monitoring/mod.rs b/stackslib/src/monitoring/mod.rs index 460b3d29fa..b1fa025fde 100644 --- a/stackslib/src/monitoring/mod.rs +++ b/stackslib/src/monitoring/mod.rs @@ -14,26 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::{fmt, fs, path::PathBuf}; - -use rusqlite::{OpenFlags, OptionalExtension}; - -use crate::burnchains::BurnchainSigner; -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::Error as DatabaseError; -use crate::{ - burnchains::Txid, - core::MemPoolDB, - net::{httpcore::StacksHttpRequest, Error as net_error}, - util_lib::db::{tx_busy_handler, DBConn}, -}; -use clarity::vm::costs::ExecutionCost; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::uint::{Uint256, Uint512}; use std::convert::TryInto; use std::error::Error; +use std::path::PathBuf; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Mutex; +use std::{fmt, fs}; + +use clarity::vm::costs::ExecutionCost; +use rusqlite::{OpenFlags, OptionalExtension}; +use stacks_common::util::get_epoch_time_secs; +use stacks_common::util::uint::{Uint256, Uint512}; + +use crate::burnchains::{BurnchainSigner, Txid}; +use crate::core::MemPoolDB; +use crate::net::httpcore::{StacksHttpRequest, StacksHttpResponse}; +use crate::net::Error as net_error; +use crate::util_lib::db::{sqlite_open, tx_busy_handler, DBConn, Error as DatabaseError}; #[cfg(feature = "monitoring_prom")] mod prometheus; diff --git a/stackslib/src/net/api/callreadonly.rs b/stackslib/src/net/api/callreadonly.rs index 6d385d9218..7ab2a728c3 100644 --- a/stackslib/src/net/api/callreadonly.rs +++ b/stackslib/src/net/api/callreadonly.rs @@ -14,65 +14,48 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, - StacksHttp, StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, +use clarity::vm::analysis::CheckErrors; +use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; +use clarity::vm::database::{ClarityDatabase, STXBalance, StoreType}; +use clarity::vm::errors::Error::Unchecked; +use clarity::vm::errors::{Error as ClarityRuntimeError, InterpreterError}; +use clarity::vm::representations::{ + CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, STANDARD_PRINCIPAL_REGEX_STRING, }; - -use crate::net::http::{ - parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, - HttpRequestContents, HttpRequestPayload, HttpRequestPreamble, HttpResponse, - HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::types::{ + PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, + BOUND_VALUE_SERIALIZATION_HEX, }; +use clarity::vm::{ClarityName, ClarityVersion, ContractName, SymbolicExpression, Value}; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use stacks_common::util::hash::{to_hex, Sha256Sum}; use crate::burnchains::Burnchain; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::Error as ChainError; use crate::core::mempool::MemPoolDB; -use crate::net::TipRequest; +use crate::net::http::{ + parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, + HttpRequestContents, HttpRequestPayload, HttpRequestPreamble, HttpResponse, + HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::Error as DBError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha256Sum; - -use clarity::vm::analysis::CheckErrors; -use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::ExecutionCost; -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::database::ClarityDatabase; -use clarity::vm::database::STXBalance; -use clarity::vm::database::StoreType; -use clarity::vm::errors::Error as ClarityRuntimeError; -use clarity::vm::errors::Error::Unchecked; -use clarity::vm::errors::InterpreterError; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::types::BOUND_VALUE_SERIALIZATION_HEX; -use clarity::vm::ClarityName; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; -use clarity::vm::SymbolicExpression; -use clarity::vm::Value; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - #[derive(Clone, Serialize, Deserialize)] pub struct CallReadOnlyRequestBody { pub sender: String, diff --git a/stackslib/src/net/api/getaccount.rs b/stackslib/src/net/api/getaccount.rs index 654babbf06..684096cd1f 100644 --- a/stackslib/src/net/api/getaccount.rs +++ b/stackslib/src/net/api/getaccount.rs @@ -14,22 +14,18 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, - StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, - HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, -}; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::database::{ClarityDatabase, STXBalance}; +use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; +use clarity::vm::types::{PrincipalData, StandardPrincipalData}; +use clarity::vm::ClarityVersion; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::{to_hex, Sha256Sum}; use crate::burnchains::Burnchain; use crate::chainstate::burn::db::sortdb::SortitionDB; @@ -37,24 +33,19 @@ use crate::chainstate::stacks::boot::{POX_1_NAME, POX_2_NAME, POX_3_NAME}; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::Error as ChainError; use crate::core::mempool::MemPoolDB; -use crate::net::TipRequest; +use crate::net::http::{ + parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, + HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::Error as DBError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha256Sum; - -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::database::ClarityDatabase; -use clarity::vm::database::STXBalance; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::ClarityVersion; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct AccountEntryResponse { pub balance: String, diff --git a/stackslib/src/net/api/getattachment.rs b/stackslib/src/net/api/getattachment.rs index fb9e5cecdd..30c5f3db5c 100644 --- a/stackslib/src/net/api/getattachment.rs +++ b/stackslib/src/net/api/getattachment.rs @@ -14,29 +14,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::collections::HashSet; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse}, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; +use regex::{Captures, Regex}; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::Hash160; +use url::form_urlencoded; +use crate::net::atlas::{ + AttachmentPage, GetAttachmentResponse, MAX_ATTACHMENT_INV_PAGES_PER_REQUEST, +}; use crate::net::http::{ parse_json, Error, HttpBadRequest, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, }; - -use crate::net::atlas::{AttachmentPage, MAX_ATTACHMENT_INV_PAGES_PER_REQUEST}; - -use crate::net::atlas::GetAttachmentResponse; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::Hash160; - -use url::form_urlencoded; +use crate::net::httpcore::{ + HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState}; #[derive(Clone)] pub struct RPCGetAttachmentRequestHandler { diff --git a/stackslib/src/net/api/getattachmentsinv.rs b/stackslib/src/net/api/getattachmentsinv.rs index 50cdf80f9c..9ab19c6176 100644 --- a/stackslib/src/net/api/getattachmentsinv.rs +++ b/stackslib/src/net/api/getattachmentsinv.rs @@ -14,31 +14,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::collections::HashSet; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse}, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{ConsensusHash, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use url::form_urlencoded; +use crate::net::atlas::{ + AttachmentPage, GetAttachmentsInvResponse, MAX_ATTACHMENT_INV_PAGES_PER_REQUEST, +}; use crate::net::http::{ parse_json, Error, HttpBadRequest, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, }; - -use crate::net::atlas::{AttachmentPage, MAX_ATTACHMENT_INV_PAGES_PER_REQUEST}; - -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; - -use crate::net::atlas::GetAttachmentsInvResponse; - -use url::form_urlencoded; +use crate::net::httpcore::{ + HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState}; #[derive(Clone)] pub struct RPCGetAttachmentsInvRequestHandler { diff --git a/stackslib/src/net/api/getblock.rs b/stackslib/src/net/api/getblock.rs index ea280197e1..924c165de7 100644 --- a/stackslib/src/net/api/getblock.rs +++ b/stackslib/src/net/api/getblock.rs @@ -14,41 +14,31 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; -use std::fs; use std::fs::OpenOptions; -use std::io; use std::io::{Read, Seek, SeekFrom, Write}; +use std::{fs, io}; +use regex::{Captures, Regex}; +use serde::de::Error as de_Error; +use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::to_hex; +use {serde, serde_json}; + +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{Error as ChainError, StacksBlock}; use crate::net::http::{ parse_bytes, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, HttpVersion, }; use crate::net::httpcore::{ - HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, + StacksHttpResponse, }; -use crate::net::StacksNodeState; -use crate::net::MAX_HEADERS; -use crate::net::{httpcore::StacksHttp, Error as NetError, TipRequest}; - -use crate::chainstate::stacks::Error as ChainError; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksBlock; - -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - -use serde; -use serde::de::Error as de_Error; -use serde_json; +use crate::net::{Error as NetError, StacksNodeState, TipRequest, MAX_HEADERS}; +use crate::util_lib::db::{DBConn, Error as DBError}; #[derive(Clone)] pub struct RPCBlocksRequestHandler { diff --git a/stackslib/src/net/api/getconstantval.rs b/stackslib/src/net/api/getconstantval.rs index fc36e3664d..a7845c7fec 100644 --- a/stackslib/src/net/api/getconstantval.rs +++ b/stackslib/src/net/api/getconstantval.rs @@ -14,56 +14,41 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, - StacksHttp, StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, - HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::database::{ClarityDatabase, STXBalance, StoreType}; +use clarity::vm::representations::{ + CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, STANDARD_PRINCIPAL_REGEX_STRING, }; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}; +use clarity::vm::{ClarityName, ClarityVersion, ContractName}; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use stacks_common::util::hash::{to_hex, Sha256Sum}; use crate::burnchains::Burnchain; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::Error as ChainError; use crate::core::mempool::MemPoolDB; -use crate::net::TipRequest; +use crate::net::http::{ + parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, + HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::Error as DBError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha256Sum; - -use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::database::ClarityDatabase; -use clarity::vm::database::STXBalance; -use clarity::vm::database::StoreType; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::ClarityName; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ConstantValResponse { pub data: String, diff --git a/stackslib/src/net/api/getcontractabi.rs b/stackslib/src/net/api/getcontractabi.rs index 841ca2ebc6..38d614b1f4 100644 --- a/stackslib/src/net/api/getcontractabi.rs +++ b/stackslib/src/net/api/getcontractabi.rs @@ -14,59 +14,43 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, - StacksHttp, StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, - HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::analysis::contract_interface_builder::ContractInterface; +use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::database::clarity_store::{make_contract_hash_key, ContractCommitment}; +use clarity::vm::database::{ClarityDatabase, STXBalance, StoreType}; +use clarity::vm::representations::{ + CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, STANDARD_PRINCIPAL_REGEX_STRING, }; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}; +use clarity::vm::{ClarityName, ClarityVersion, ContractName}; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use stacks_common::util::hash::{to_hex, Sha256Sum}; use crate::burnchains::Burnchain; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::Error as ChainError; use crate::core::mempool::MemPoolDB; -use crate::net::TipRequest; +use crate::net::http::{ + parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, + HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::Error as DBError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha256Sum; - -use clarity::vm::analysis::contract_interface_builder::ContractInterface; -use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::database::clarity_store::make_contract_hash_key; -use clarity::vm::database::clarity_store::ContractCommitment; -use clarity::vm::database::ClarityDatabase; -use clarity::vm::database::STXBalance; -use clarity::vm::database::StoreType; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::ClarityName; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - #[derive(Clone)] pub struct RPCGetContractAbiRequestHandler { pub contract_identifier: Option, diff --git a/stackslib/src/net/api/getcontractsrc.rs b/stackslib/src/net/api/getcontractsrc.rs index 42bcf0ef5b..f670d1020c 100644 --- a/stackslib/src/net/api/getcontractsrc.rs +++ b/stackslib/src/net/api/getcontractsrc.rs @@ -14,57 +14,41 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, - StacksHttp, StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, - HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::database::clarity_store::{make_contract_hash_key, ContractCommitment}; +use clarity::vm::database::{ClarityDatabase, STXBalance, StoreType}; +use clarity::vm::representations::{ + CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, STANDARD_PRINCIPAL_REGEX_STRING, }; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}; +use clarity::vm::{ClarityName, ClarityVersion, ContractName}; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use stacks_common::util::hash::{to_hex, Sha256Sum}; use crate::burnchains::Burnchain; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::Error as ChainError; use crate::core::mempool::MemPoolDB; -use crate::net::TipRequest; +use crate::net::http::{ + parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, + HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::Error as DBError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha256Sum; - -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::database::clarity_store::make_contract_hash_key; -use clarity::vm::database::clarity_store::ContractCommitment; -use clarity::vm::database::ClarityDatabase; -use clarity::vm::database::STXBalance; -use clarity::vm::database::StoreType; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::ClarityName; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ContractSrcResponse { pub source: String, diff --git a/stackslib/src/net/api/getdatavar.rs b/stackslib/src/net/api/getdatavar.rs index 1ea7065266..0594dc8639 100644 --- a/stackslib/src/net/api/getdatavar.rs +++ b/stackslib/src/net/api/getdatavar.rs @@ -14,56 +14,41 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, - StacksHttp, StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, - HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::database::{ClarityDatabase, STXBalance, StoreType}; +use clarity::vm::representations::{ + CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, STANDARD_PRINCIPAL_REGEX_STRING, }; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}; +use clarity::vm::{ClarityName, ClarityVersion, ContractName}; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use stacks_common::util::hash::{to_hex, Sha256Sum}; use crate::burnchains::Burnchain; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::Error as ChainError; use crate::core::mempool::MemPoolDB; -use crate::net::TipRequest; +use crate::net::http::{ + parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, + HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::Error as DBError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha256Sum; - -use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::database::ClarityDatabase; -use clarity::vm::database::STXBalance; -use clarity::vm::database::StoreType; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::ClarityName; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct DataVarResponse { pub data: String, diff --git a/stackslib/src/net/api/getheaders.rs b/stackslib/src/net/api/getheaders.rs index 7918baadf5..b2a3e4dc96 100644 --- a/stackslib/src/net/api/getheaders.rs +++ b/stackslib/src/net/api/getheaders.rs @@ -14,39 +14,28 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; +use regex::{Captures, Regex}; +use serde::de::Error as de_Error; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::to_hex; +use {serde, serde_json}; + +use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; +use crate::chainstate::stacks::Error as ChainError; use crate::net::http::{ parse_json, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, }; use crate::net::httpcore::{ - HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, + request, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, + StacksHttpResponse, }; -use crate::net::StacksNodeState; -use crate::net::MAX_HEADERS; -use crate::net::{ - httpcore::{request, StacksHttp}, - Error as NetError, TipRequest, -}; - -use crate::chainstate::stacks::Error as ChainError; - -use crate::chainstate::stacks::db::ExtendedStacksHeader; -use crate::chainstate::stacks::db::StacksChainState; - -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - -use serde; -use serde::de::Error as de_Error; -use serde_json; +use crate::net::{Error as NetError, StacksNodeState, TipRequest, MAX_HEADERS}; +use crate::util_lib::db::{DBConn, Error as DBError}; #[derive(Clone)] pub struct RPCHeadersRequestHandler { diff --git a/stackslib/src/net/api/getinfo.rs b/stackslib/src/net/api/getinfo.rs index 86b0bdd13f..f83173a44d 100644 --- a/stackslib/src/net/api/getinfo.rs +++ b/stackslib/src/net/api/getinfo.rs @@ -14,35 +14,30 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse}, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, - HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey, }; +use stacks_common::types::net::PeerHost; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{Hash160, Sha256Sum}; use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::Txid; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::StacksChainState; use crate::core::mempool::MemPoolDB; - -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::types::net::PeerHost; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha256Sum; - +use crate::net::http::{ + parse_json, Error, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, + HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, +}; +use crate::net::httpcore::{ + HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState}; use crate::version_string; /// The request to GET /v2/info diff --git a/stackslib/src/net/api/getistraitimplemented.rs b/stackslib/src/net/api/getistraitimplemented.rs index 09c772d1a0..8aa0a8fbef 100644 --- a/stackslib/src/net/api/getistraitimplemented.rs +++ b/stackslib/src/net/api/getistraitimplemented.rs @@ -14,57 +14,43 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, - StacksHttp, StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, +use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::database::{ClarityDatabase, STXBalance, StoreType}; +use clarity::vm::representations::{ + CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, STANDARD_PRINCIPAL_REGEX_STRING, }; - -use crate::net::http::{ - parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, - HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::types::{ + PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, TraitIdentifier, }; +use clarity::vm::{ClarityName, ClarityVersion, ContractName}; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use stacks_common::util::hash::{to_hex, Sha256Sum}; use crate::burnchains::Burnchain; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::Error as ChainError; use crate::core::mempool::MemPoolDB; -use crate::net::TipRequest; +use crate::net::http::{ + parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, + HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::Error as DBError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha256Sum; - -use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::database::ClarityDatabase; -use clarity::vm::database::STXBalance; -use clarity::vm::database::StoreType; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::types::TraitIdentifier; -use clarity::vm::ClarityName; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct GetIsTraitImplementedResponse { pub is_implemented: bool, diff --git a/stackslib/src/net/api/getmapentry.rs b/stackslib/src/net/api/getmapentry.rs index 4e8df13fb2..9a5cc24e82 100644 --- a/stackslib/src/net/api/getmapentry.rs +++ b/stackslib/src/net/api/getmapentry.rs @@ -14,59 +14,45 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, - StacksHttp, StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, +use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::database::{ClarityDatabase, STXBalance, StoreType}; +use clarity::vm::representations::{ + CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, STANDARD_PRINCIPAL_REGEX_STRING, }; - -use crate::net::http::{ - parse_json, Error, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, - HttpRequestPayload, HttpRequestPreamble, HttpResponse, HttpResponseContents, - HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::types::{ + PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, + BOUND_VALUE_SERIALIZATION_HEX, }; +use clarity::vm::{ClarityName, ClarityVersion, ContractName, Value}; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use stacks_common::util::hash::{to_hex, Sha256Sum}; use crate::burnchains::Burnchain; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::Error as ChainError; use crate::core::mempool::MemPoolDB; -use crate::net::TipRequest; +use crate::net::http::{ + parse_json, Error, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, + HttpRequestPayload, HttpRequestPreamble, HttpResponse, HttpResponseContents, + HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::Error as DBError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Sha256Sum; - -use clarity::vm::ast::parser::v1::CLARITY_NAME_REGEX; -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::database::ClarityDatabase; -use clarity::vm::database::STXBalance; -use clarity::vm::database::StoreType; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::types::BOUND_VALUE_SERIALIZATION_HEX; -use clarity::vm::ClarityName; -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct MapEntryResponse { pub data: String, diff --git a/stackslib/src/net/api/getmicroblocks_confirmed.rs b/stackslib/src/net/api/getmicroblocks_confirmed.rs index f2817e4c9e..3c07a07a48 100644 --- a/stackslib/src/net/api/getmicroblocks_confirmed.rs +++ b/stackslib/src/net/api/getmicroblocks_confirmed.rs @@ -14,47 +14,32 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; -use std::fs; use std::fs::OpenOptions; -use std::io; use std::io::{Read, Seek, SeekFrom, Write}; +use std::{fs, io}; +use regex::{Captures, Regex}; +use serde::de::Error as de_Error; +use stacks_common::codec::{read_next, StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::to_hex; +use {serde, serde_json}; + +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{Error as ChainError, StacksBlockHeader, StacksMicroblock}; +use crate::net::api::getmicroblocks_indexed::StacksIndexedMicroblockStream; use crate::net::http::{ parse_bytes, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, }; use crate::net::httpcore::{ - request, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, + request, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, StacksHttpResponse, }; -use crate::net::StacksNodeState; -use crate::net::MAX_HEADERS; -use crate::net::{httpcore::StacksHttp, Error as NetError, TipRequest}; - -use crate::chainstate::stacks::Error as ChainError; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; - -use stacks_common::codec::read_next; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - -use serde; -use serde::de::Error as de_Error; -use serde_json; - -use crate::net::api::getmicroblocks_indexed::StacksIndexedMicroblockStream; +use crate::net::{Error as NetError, StacksNodeState, TipRequest, MAX_HEADERS}; +use crate::util_lib::db::{DBConn, Error as DBError}; #[derive(Clone)] pub struct RPCMicroblocksConfirmedRequestHandler { diff --git a/stackslib/src/net/api/getmicroblocks_indexed.rs b/stackslib/src/net/api/getmicroblocks_indexed.rs index d2a89c2ca3..8f5eb7bc59 100644 --- a/stackslib/src/net/api/getmicroblocks_indexed.rs +++ b/stackslib/src/net/api/getmicroblocks_indexed.rs @@ -14,47 +14,31 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; -use std::fs; use std::fs::OpenOptions; -use std::io; use std::io::{Read, Seek, SeekFrom, Write}; +use std::{fs, io}; + +use regex::{Captures, Regex}; +use serde::de::Error as de_Error; +use stacks_common::codec::{read_next, StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::to_hex; +use {serde, serde_json}; +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{Error as ChainError, StacksBlockHeader, StacksMicroblock}; use crate::net::http::{ parse_bytes, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, HttpVersion, }; use crate::net::httpcore::{ - HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, -}; -use crate::net::StacksNodeState; -use crate::net::MAX_HEADERS; -use crate::net::{ - httpcore::{request, StacksHttp}, - Error as NetError, TipRequest, + request, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, + StacksHttpResponse, }; - -use crate::chainstate::stacks::Error as ChainError; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; - -use stacks_common::codec::read_next; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - -use serde; -use serde::de::Error as de_Error; -use serde_json; +use crate::net::{Error as NetError, StacksNodeState, TipRequest, MAX_HEADERS}; +use crate::util_lib::db::{DBConn, Error as DBError}; #[derive(Clone)] pub struct RPCMicroblocksIndexedRequestHandler { diff --git a/stackslib/src/net/api/getmicroblocks_unconfirmed.rs b/stackslib/src/net/api/getmicroblocks_unconfirmed.rs index 6a81e4ce1f..f18d1855d4 100644 --- a/stackslib/src/net/api/getmicroblocks_unconfirmed.rs +++ b/stackslib/src/net/api/getmicroblocks_unconfirmed.rs @@ -14,48 +14,34 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; -use std::fs; use std::fs::OpenOptions; -use std::io; use std::io::{Read, Seek, SeekFrom, Write}; +use std::{fs, io}; +use regex::{Captures, Regex}; +use serde::de::Error as de_Error; +use stacks_common::codec::{read_next, Error as CodecError, StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::to_hex; +use stacks_common::util::retry::BoundReader; +use {serde, serde_json}; + +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{Error as ChainError, StacksBlockHeader, StacksMicroblock}; use crate::net::http::{ parse_bytes, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, }; use crate::net::httpcore::{ - request, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, + request, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, StacksHttpResponse, }; -use crate::net::StacksNodeState; -use crate::net::MAX_HEADERS; -use crate::net::MAX_MICROBLOCKS_UNCONFIRMED; -use crate::net::{httpcore::StacksHttp, Error as NetError, TipRequest}; - -use crate::chainstate::stacks::Error as ChainError; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; - -use stacks_common::codec::read_next; -use stacks_common::codec::Error as CodecError; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; -use stacks_common::util::retry::BoundReader; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - -use serde; -use serde::de::Error as de_Error; -use serde_json; +use crate::net::{ + Error as NetError, StacksNodeState, TipRequest, MAX_HEADERS, MAX_MICROBLOCKS_UNCONFIRMED, +}; +use crate::util_lib::db::{DBConn, Error as DBError}; #[derive(Clone)] pub struct RPCMicroblocksUnconfirmedRequestHandler { diff --git a/stackslib/src/net/api/getneighbors.rs b/stackslib/src/net/api/getneighbors.rs index 8e89cafa63..3b14d8397f 100644 --- a/stackslib/src/net/api/getneighbors.rs +++ b/stackslib/src/net/api/getneighbors.rs @@ -14,30 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::net::{ - db::PeerDB, - httpcore::{ - HttpPreambleExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, - StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, NeighborKey, PeerAddress, StacksNodeState, -}; use std::io::{Read, Write}; +use clarity::vm::types::QualifiedContractIdentifier; use regex::{Captures, Regex}; +use stacks_common::types::net::{PeerAddress, PeerHost}; +use stacks_common::util::hash::Hash160; +use crate::net::db::PeerDB; use crate::net::http::{ parse_json, Error, HttpContentType, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpVersion, }; - -use crate::net::MAX_NEIGHBORS_DATA_LEN; - -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::Hash160; - -use clarity::vm::types::QualifiedContractIdentifier; +use crate::net::httpcore::{ + HttpPreambleExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, NeighborKey, StacksNodeState, MAX_NEIGHBORS_DATA_LEN}; #[derive(Clone)] pub struct RPCNeighborsRequestHandler {} diff --git a/stackslib/src/net/api/getpoxinfo.rs b/stackslib/src/net/api/getpoxinfo.rs index ca34ad6360..70d02fe198 100644 --- a/stackslib/src/net/api/getpoxinfo.rs +++ b/stackslib/src/net/api/getpoxinfo.rs @@ -14,22 +14,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, - StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, TipRequest, -}; - -use crate::net::http::{ - parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, - HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, -}; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::costs::LimitedCostTracker; +use clarity::vm::types::{PrincipalData, StandardPrincipalData}; +use clarity::vm::ClarityVersion; +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::Sha256Sum; use crate::burnchains::Burnchain; use crate::chainstate::burn::db::sortdb::SortitionDB; @@ -37,20 +31,19 @@ use crate::chainstate::stacks::boot::{POX_1_NAME, POX_2_NAME, POX_3_NAME}; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::Error as ChainError; use crate::core::mempool::MemPoolDB; +use crate::net::http::{ + parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, + HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::Error as DBError; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::Sha256Sum; - -use clarity::vm::costs::LimitedCostTracker; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::ClarityVersion; - -use clarity::vm::clarity::ClarityConnection; - #[derive(Clone)] pub struct RPCPoxInfoRequestHandler {} impl RPCPoxInfoRequestHandler { diff --git a/stackslib/src/net/api/getstackerdbchunk.rs b/stackslib/src/net/api/getstackerdbchunk.rs index 27ed845a1a..72bd80685a 100644 --- a/stackslib/src/net/api/getstackerdbchunk.rs +++ b/stackslib/src/net/api/getstackerdbchunk.rs @@ -14,58 +14,39 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; -use std::fs; use std::fs::OpenOptions; -use std::io; use std::io::{Read, Seek, SeekFrom, Write}; +use std::{fs, io}; + +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::representations::{ + CLARITY_NAME_REGEX, CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, + STANDARD_PRINCIPAL_REGEX_STRING, +}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}; +use clarity::vm::{ClarityName, ContractName}; +use libstackerdb::{SlotMetadata, STACKERDB_MAX_CHUNK_SIZE}; +use regex::{Captures, Regex}; +use serde::de::Error as de_Error; +use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::to_hex; +use {serde, serde_json}; +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{Error as ChainError, StacksBlock}; use crate::net::http::{ parse_bytes, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, }; use crate::net::httpcore::{ - HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, -}; -use crate::net::StacksNodeState; -use crate::net::MAX_HEADERS; -use crate::net::{ - httpcore::{request, HttpPreambleExtensions, StacksHttp}, - Error as NetError, TipRequest, + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, }; - -use crate::chainstate::stacks::Error as ChainError; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksBlock; - -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::representations::CLARITY_NAME_REGEX; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - -use libstackerdb::SlotMetadata; -use libstackerdb::STACKERDB_MAX_CHUNK_SIZE; - -use serde; -use serde::de::Error as de_Error; -use serde_json; +use crate::net::{Error as NetError, StacksNodeState, TipRequest, MAX_HEADERS}; +use crate::util_lib::db::{DBConn, Error as DBError}; #[derive(Clone)] pub struct RPCGetStackerDBChunkRequestHandler { diff --git a/stackslib/src/net/api/getstackerdbmetadata.rs b/stackslib/src/net/api/getstackerdbmetadata.rs index 905f6e04ae..9d0fd7c049 100644 --- a/stackslib/src/net/api/getstackerdbmetadata.rs +++ b/stackslib/src/net/api/getstackerdbmetadata.rs @@ -14,56 +14,38 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; -use std::fs; use std::fs::OpenOptions; -use std::io; use std::io::{Read, Seek, SeekFrom, Write}; +use std::{fs, io}; +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::representations::{ + CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, STANDARD_PRINCIPAL_REGEX_STRING, +}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}; +use clarity::vm::{ClarityName, ContractName}; +use libstackerdb::SlotMetadata; +use regex::{Captures, Regex}; +use serde::de::Error as de_Error; +use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::to_hex; +use {serde, serde_json}; + +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{Error as ChainError, StacksBlock}; use crate::net::http::{ parse_json, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, }; use crate::net::httpcore::{ - HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, -}; -use crate::net::StacksNodeState; -use crate::net::MAX_HEADERS; -use crate::net::{ - httpcore::{request, HttpPreambleExtensions, StacksHttp}, - Error as NetError, TipRequest, + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, }; - -use crate::chainstate::stacks::Error as ChainError; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksBlock; - -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - -use libstackerdb::SlotMetadata; - -use serde; -use serde::de::Error as de_Error; -use serde_json; +use crate::net::{Error as NetError, StacksNodeState, TipRequest, MAX_HEADERS}; +use crate::util_lib::db::{DBConn, Error as DBError}; #[derive(Clone)] pub struct RPCGetStackerDBMetadataRequestHandler { diff --git a/stackslib/src/net/api/getstxtransfercost.rs b/stackslib/src/net/api/getstxtransfercost.rs index dda7e25f24..961cfe4f1b 100644 --- a/stackslib/src/net/api/getstxtransfercost.rs +++ b/stackslib/src/net/api/getstxtransfercost.rs @@ -14,19 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse}, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, - HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, +use regex::{Captures, Regex}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey, }; +use stacks_common::types::net::PeerHost; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{Hash160, Sha256Sum}; use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::Txid; @@ -34,16 +30,15 @@ use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::blocks::MINIMUM_TX_FEE_RATE_PER_BYTE; use crate::chainstate::stacks::db::StacksChainState; use crate::core::mempool::MemPoolDB; - -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::types::net::PeerHost; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha256Sum; - +use crate::net::http::{ + parse_json, Error, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, + HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, +}; +use crate::net::httpcore::{ + HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState}; use crate::version_string; #[derive(Clone)] diff --git a/stackslib/src/net/api/gettransaction_unconfirmed.rs b/stackslib/src/net/api/gettransaction_unconfirmed.rs index 7345abcffe..2ed8ba346e 100644 --- a/stackslib/src/net/api/gettransaction_unconfirmed.rs +++ b/stackslib/src/net/api/gettransaction_unconfirmed.rs @@ -14,38 +14,31 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - request, HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, - HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use regex::{Captures, Regex}; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::{ + BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey, }; +use stacks_common::types::net::PeerHost; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{to_hex, Hash160, Sha256Sum}; use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::Txid; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::StacksChainState; use crate::core::mempool::MemPoolDB; - -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::types::net::PeerHost; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha256Sum; +use crate::net::http::{ + parse_json, Error, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, + HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum UnconfirmedTransactionStatus { diff --git a/stackslib/src/net/api/mod.rs b/stackslib/src/net/api/mod.rs index cf6a841c74..3eaa6148d2 100644 --- a/stackslib/src/net/api/mod.rs +++ b/stackslib/src/net/api/mod.rs @@ -16,34 +16,22 @@ use std::convert::From; -use crate::net::Error as NetError; +use clarity::vm::costs::ExecutionCost; +use stacks_common::codec::read_next; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; +use crate::burnchains::Txid; +use crate::chainstate::stacks::{StacksMicroblock, StacksTransaction}; use crate::core::mempool; - -use stacks_common::types::chainstate::StacksBlockId; - +use crate::cost_estimates::FeeRateEstimate; +use crate::net::atlas::GetAttachmentResponse; use crate::net::http::{ Error, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, }; - use crate::net::httpcore::{StacksHttp, StacksHttpRequest, StacksHttpResponse}; - -use crate::chainstate::stacks::StacksMicroblock; -use crate::chainstate::stacks::StacksTransaction; - -use crate::burnchains::Txid; - -use stacks_common::codec::read_next; - -use crate::net::atlas::GetAttachmentResponse; - -use crate::cost_estimates::FeeRateEstimate; - -use clarity::vm::costs::ExecutionCost; - +use crate::net::Error as NetError; use crate::stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::BlockHeaderHash; pub mod callreadonly; pub mod getaccount; diff --git a/stackslib/src/net/api/postblock.rs b/stackslib/src/net/api/postblock.rs index 04692d6e6a..3380102101 100644 --- a/stackslib/src/net/api/postblock.rs +++ b/stackslib/src/net/api/postblock.rs @@ -14,57 +14,43 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, - StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, - HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, - HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::costs::ExecutionCost; +use regex::{Captures, Regex}; +use stacks_common::codec::{Error as CodecError, StacksMessageCodec, MAX_PAYLOAD_LEN}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey, }; +use stacks_common::types::net::PeerHost; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{hex_bytes, Hash160, Sha256Sum}; +use stacks_common::util::retry::BoundReader; use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::Txid; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::blocks::MINIMUM_TX_FEE_RATE_PER_BYTE; use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksBlock; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksTransaction; -use crate::chainstate::stacks::TransactionPayload; +use crate::chainstate::stacks::{ + StacksBlock, StacksBlockHeader, StacksTransaction, TransactionPayload, +}; use crate::core::mempool::MemPoolDB; -use crate::net::relay::Relayer; -use crate::net::Attachment; -use crate::net::BlocksData; -use crate::net::BlocksDatum; -use crate::net::StacksMessageType; - -use stacks_common::codec::Error as CodecError; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_PAYLOAD_LEN; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::types::net::PeerHost; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::hex_bytes; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha256Sum; -use stacks_common::util::retry::BoundReader; - use crate::cost_estimates::FeeRateEstimate; - -use clarity::vm::costs::ExecutionCost; +use crate::net::http::{ + parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, + HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, + HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::relay::Relayer; +use crate::net::{ + Attachment, BlocksData, BlocksDatum, Error as NetError, StacksMessageType, StacksNodeState, +}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StacksBlockAcceptedData { diff --git a/stackslib/src/net/api/postfeerate.rs b/stackslib/src/net/api/postfeerate.rs index ed713bb4c3..42fbfbc347 100644 --- a/stackslib/src/net/api/postfeerate.rs +++ b/stackslib/src/net/api/postfeerate.rs @@ -14,20 +14,18 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse}, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, - HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, - HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::costs::ExecutionCost; +use regex::{Captures, Regex}; +use stacks_common::codec::{StacksMessageCodec, MAX_PAYLOAD_LEN}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey, }; +use stacks_common::types::net::PeerHost; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{hex_bytes, Hash160, Sha256Sum}; +use stacks_common::util::retry::BoundReader; use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::Txid; @@ -36,23 +34,17 @@ use crate::chainstate::stacks::db::blocks::MINIMUM_TX_FEE_RATE_PER_BYTE; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::TransactionPayload; use crate::core::mempool::MemPoolDB; - -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_PAYLOAD_LEN; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::types::net::PeerHost; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::hex_bytes; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha256Sum; -use stacks_common::util::retry::BoundReader; - use crate::cost_estimates::FeeRateEstimate; - -use clarity::vm::costs::ExecutionCost; +use crate::net::http::{ + parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, + HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, + HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as NetError, StacksNodeState}; #[derive(Serialize, Deserialize)] pub struct FeeRateEstimateRequestBody { diff --git a/stackslib/src/net/api/postmempoolquery.rs b/stackslib/src/net/api/postmempoolquery.rs index 4a18f73157..0ad3168661 100644 --- a/stackslib/src/net/api/postmempoolquery.rs +++ b/stackslib/src/net/api/postmempoolquery.rs @@ -14,52 +14,35 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; -use std::fs; use std::fs::OpenOptions; -use std::io; use std::io::{Read, Seek, SeekFrom, Write}; +use std::{fs, io}; +use rand::{thread_rng, Rng}; +use regex::{Captures, Regex}; +use serde::de::Error as de_Error; +use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::net::PeerHost; +use stacks_common::util::hash::to_hex; +use url::form_urlencoded; +use {serde, serde_json}; + +use crate::burnchains::Txid; +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{Error as ChainError, StacksTransaction}; +use crate::core::mempool::{decode_tx_stream, MemPoolDB, MemPoolSyncData}; use crate::net::http::{ parse_bytes, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, }; use crate::net::httpcore::{ - HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, + StacksHttpResponse, }; -use crate::net::StacksNodeState; -use crate::net::MAX_HEADERS; -use crate::net::{httpcore::StacksHttp, Error as NetError, TipRequest}; - -use crate::burnchains::Txid; - -use crate::chainstate::stacks::Error as ChainError; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksTransaction; - -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::to_hex; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - -use crate::core::mempool::decode_tx_stream; -use crate::core::mempool::MemPoolDB; -use crate::core::mempool::MemPoolSyncData; - -use serde; -use serde::de::Error as de_Error; -use serde_json; - -use url::form_urlencoded; - -use rand::thread_rng; -use rand::Rng; +use crate::net::{Error as NetError, StacksNodeState, TipRequest, MAX_HEADERS}; +use crate::util_lib::db::{DBConn, Error as DBError}; #[derive(Clone)] pub struct RPCMempoolQueryRequestHandler { diff --git a/stackslib/src/net/api/postmicroblock.rs b/stackslib/src/net/api/postmicroblock.rs index 7b677ec213..0ff17d724e 100644 --- a/stackslib/src/net/api/postmicroblock.rs +++ b/stackslib/src/net/api/postmicroblock.rs @@ -14,58 +14,43 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, - StacksHttpRequest, StacksHttpResponse, - }, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, - HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, - HttpResponsePayload, HttpResponsePreamble, HttpServerError, +use clarity::vm::costs::ExecutionCost; +use regex::{Captures, Regex}; +use stacks_common::codec::{Error as CodecError, StacksMessageCodec, MAX_PAYLOAD_LEN}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey, }; +use stacks_common::types::net::PeerHost; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{hex_bytes, Hash160, Sha256Sum}; +use stacks_common::util::retry::BoundReader; use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::Txid; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::blocks::MINIMUM_TX_FEE_RATE_PER_BYTE; use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::Error as ChainError; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; -use crate::chainstate::stacks::StacksTransaction; -use crate::chainstate::stacks::TransactionPayload; +use crate::chainstate::stacks::{ + Error as ChainError, StacksBlockHeader, StacksMicroblock, StacksTransaction, TransactionPayload, +}; use crate::core::mempool::MemPoolDB; -use crate::net::relay::Relayer; -use crate::net::Attachment; -use crate::net::MicroblocksData; -use crate::net::StacksMessageType; -use crate::net::TipRequest; - -use stacks_common::codec::Error as CodecError; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_PAYLOAD_LEN; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::types::net::PeerHost; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::hex_bytes; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha256Sum; -use stacks_common::util::retry::BoundReader; - use crate::cost_estimates::FeeRateEstimate; - -use clarity::vm::costs::ExecutionCost; +use crate::net::http::{ + parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, + HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, + HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, + StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::relay::Relayer; +use crate::net::{ + Attachment, Error as NetError, MicroblocksData, StacksMessageType, StacksNodeState, TipRequest, +}; #[derive(Clone)] pub struct RPCPostMicroblockRequestHandler { diff --git a/stackslib/src/net/api/poststackerdbchunk.rs b/stackslib/src/net/api/poststackerdbchunk.rs index e7bf6ce80b..8af2fb0e33 100644 --- a/stackslib/src/net/api/poststackerdbchunk.rs +++ b/stackslib/src/net/api/poststackerdbchunk.rs @@ -14,60 +14,42 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; -use std::fs; use std::fs::OpenOptions; -use std::io; use std::io::{Read, Seek, SeekFrom, Write}; +use std::{fs, io}; -use crate::net::http::{ - parse_json, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, - HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, - HttpResponsePayload, HttpResponsePreamble, HttpServerError, -}; -use crate::net::httpcore::{ - HttpRequestContentsExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, +use clarity::vm::clarity::ClarityConnection; +use clarity::vm::representations::{ + CLARITY_NAME_REGEX, CONTRACT_NAME_REGEX_STRING, PRINCIPAL_DATA_REGEX_STRING, + STANDARD_PRINCIPAL_REGEX_STRING, }; -use crate::net::StacksNodeState; -use crate::net::{ - httpcore::{request, HttpPreambleExtensions, StacksHttp}, - Error as NetError, TipRequest, +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}; +use clarity::vm::{ClarityName, ContractName}; +use libstackerdb::{ + SlotMetadata, StackerDBChunkAckData, StackerDBChunkData, STACKERDB_MAX_CHUNK_SIZE, }; - -use crate::chainstate::stacks::Error as ChainError; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksBlock; - -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; +use regex::{Captures, Regex}; +use serde::de::Error as de_Error; +use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN}; use stacks_common::types::chainstate::StacksBlockId; use stacks_common::types::net::PeerHost; use stacks_common::util::hash::to_hex; use stacks_common::util::secp256k1::MessageSignature; +use {serde, serde_json}; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as DBError; - -use clarity::vm::clarity::ClarityConnection; -use clarity::vm::representations::CLARITY_NAME_REGEX; -use clarity::vm::representations::CONTRACT_NAME_REGEX_STRING; -use clarity::vm::representations::PRINCIPAL_DATA_REGEX_STRING; -use clarity::vm::representations::STANDARD_PRINCIPAL_REGEX_STRING; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - -use libstackerdb::SlotMetadata; -use libstackerdb::StackerDBChunkAckData; -use libstackerdb::StackerDBChunkData; -use libstackerdb::STACKERDB_MAX_CHUNK_SIZE; - -use serde; -use serde::de::Error as de_Error; -use serde_json; +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{Error as ChainError, StacksBlock}; +use crate::net::http::{ + parse_json, Error, HttpBadRequest, HttpChunkGenerator, HttpContentType, HttpNotFound, + HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, + HttpResponsePayload, HttpResponsePreamble, HttpServerError, +}; +use crate::net::httpcore::{ + request, HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::{Error as NetError, StacksNodeState, TipRequest}; +use crate::util_lib::db::{DBConn, Error as DBError}; #[derive(Clone)] pub struct RPCPostStackerDBChunkRequestHandler { diff --git a/stackslib/src/net/api/posttransaction.rs b/stackslib/src/net/api/posttransaction.rs index 189cd143da..655a3a221a 100644 --- a/stackslib/src/net/api/posttransaction.rs +++ b/stackslib/src/net/api/posttransaction.rs @@ -14,51 +14,38 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use regex::{Captures, Regex}; use std::io::{Read, Write}; -use crate::net::{ - httpcore::{HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse}, - p2p::PeerNetwork, - Error as NetError, StacksNodeState, -}; - -use crate::net::http::{ - parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, - HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, - HttpResponsePayload, HttpResponsePreamble, HttpServerError, HttpVersion, +use clarity::vm::costs::ExecutionCost; +use regex::{Captures, Regex}; +use stacks_common::codec::{Error as CodecError, StacksMessageCodec, MAX_PAYLOAD_LEN}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey, }; +use stacks_common::types::net::PeerHost; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, Sha256Sum}; +use stacks_common::util::retry::BoundReader; use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::Txid; use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::stacks::db::blocks::MINIMUM_TX_FEE_RATE_PER_BYTE; use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::StacksTransaction; -use crate::chainstate::stacks::TransactionPayload; +use crate::chainstate::stacks::{StacksTransaction, TransactionPayload}; use crate::core::mempool::MemPoolDB; -use crate::net::relay::Relayer; -use crate::net::Attachment; -use crate::net::StacksMessageType; - -use stacks_common::codec::Error as CodecError; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_PAYLOAD_LEN; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::types::net::PeerHost; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::hex_bytes; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha256Sum; -use stacks_common::util::retry::BoundReader; - use crate::cost_estimates::FeeRateEstimate; - -use clarity::vm::costs::ExecutionCost; +use crate::net::http::{ + parse_json, Error, HttpBadRequest, HttpContentType, HttpNotFound, HttpRequest, + HttpRequestContents, HttpRequestPreamble, HttpResponse, HttpResponseContents, + HttpResponsePayload, HttpResponsePreamble, HttpServerError, HttpVersion, +}; +use crate::net::httpcore::{ + HttpPreambleExtensions, RPCRequestHandler, StacksHttpRequest, StacksHttpResponse, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::relay::Relayer; +use crate::net::{Attachment, Error as NetError, StacksMessageType, StacksNodeState}; #[derive(Serialize, Deserialize)] pub struct PostTransactionRequestBody { diff --git a/stackslib/src/net/api/tests/callreadonly.rs b/stackslib/src/net/api/tests/callreadonly.rs index 59cf9c9db7..577d2e0b12 100644 --- a/stackslib/src/net/api/tests/callreadonly.rs +++ b/stackslib/src/net/api/tests/callreadonly.rs @@ -14,36 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::test_rpc; use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getaccount.rs b/stackslib/src/net/api/tests/getaccount.rs index 34e6d81835..996edfd3e2 100644 --- a/stackslib/src/net/api/tests/getaccount.rs +++ b/stackslib/src/net/api/tests/getaccount.rs @@ -14,34 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - +use super::test_rpc; use crate::net::api::*; -use crate::net::httpcore::RPCRequestHandler; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getattachment.rs b/stackslib/src/net/api/tests/getattachment.rs index 80159ca5f0..aa409aea42 100644 --- a/stackslib/src/net/api/tests/getattachment.rs +++ b/stackslib/src/net/api/tests/getattachment.rs @@ -14,35 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; use stacks_common::util::hash::Hash160; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - +use super::test_rpc; use crate::net::api::*; -use crate::net::httpcore::RPCRequestHandler; -use crate::net::Attachment; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{Attachment, ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getattachmentsinv.rs b/stackslib/src/net/api/tests/getattachmentsinv.rs index 2b0e12df15..c7dd8e0328 100644 --- a/stackslib/src/net/api/tests/getattachmentsinv.rs +++ b/stackslib/src/net/api/tests/getattachmentsinv.rs @@ -14,39 +14,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - use std::collections::HashSet; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; - +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; +use serde_json; use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - +use super::{test_rpc, TestRPC}; use crate::net::api::*; use crate::net::connection::ConnectionOptions; -use crate::net::httpcore::RPCRequestHandler; -use crate::net::Attachment; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use super::test_rpc; -use super::TestRPC; - -use serde_json; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{Attachment, ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getblock.rs b/stackslib/src/net/api/tests/getblock.rs index 5ffa67afc0..f987f5e79b 100644 --- a/stackslib/src/net/api/tests/getblock.rs +++ b/stackslib/src/net/api/tests/getblock.rs @@ -14,49 +14,34 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; + +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPrivateKey; +use stacks_common::types::chainstate::{ + ConsensusHash, StacksAddress, StacksBlockId, StacksPrivateKey, +}; use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use crate::util_lib::db::DBConn; - -use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; -use crate::chainstate::stacks::Error as chainstate_error; -use crate::chainstate::stacks::StacksBlock; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; - +use super::TestRPC; use crate::chainstate::stacks::db::blocks::test::*; use crate::chainstate::stacks::db::test::instantiate_chainstate; - -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - +use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; +use crate::chainstate::stacks::{ + Error as chainstate_error, StacksBlock, StacksBlockHeader, StacksMicroblock, +}; use crate::net::api::getblock::StacksBlockStream; +use crate::net::api::*; +use crate::net::connection::ConnectionOptions; use crate::net::http::HttpChunkGenerator; - use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, }; - -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - -use crate::net::api::*; -use crate::net::httpcore::RPCRequestHandler; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::{ProtocolFamily, TipRequest}; +use crate::util_lib::db::DBConn; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getconstantval.rs b/stackslib/src/net/api/tests/getconstantval.rs index 58b191b219..4e03679f1f 100644 --- a/stackslib/src/net/api/tests/getconstantval.rs +++ b/stackslib/src/net/api/tests/getconstantval.rs @@ -14,33 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - +use super::test_rpc; use crate::net::api::*; -use crate::net::httpcore::RPCRequestHandler; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getcontractabi.rs b/stackslib/src/net/api/tests/getcontractabi.rs index 3c44a6fe6f..a1b3738a92 100644 --- a/stackslib/src/net/api/tests/getcontractabi.rs +++ b/stackslib/src/net/api/tests/getcontractabi.rs @@ -14,33 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - +use super::test_rpc; use crate::net::api::*; -use crate::net::httpcore::RPCRequestHandler; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getcontractsrc.rs b/stackslib/src/net/api/tests/getcontractsrc.rs index c038d148c1..cb376b66d2 100644 --- a/stackslib/src/net/api/tests/getcontractsrc.rs +++ b/stackslib/src/net/api/tests/getcontractsrc.rs @@ -14,33 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - +use super::test_rpc; use crate::net::api::*; -use crate::net::httpcore::RPCRequestHandler; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getdatavar.rs b/stackslib/src/net/api/tests/getdatavar.rs index f0a9d2ff0f..f4ce526fc9 100644 --- a/stackslib/src/net/api/tests/getdatavar.rs +++ b/stackslib/src/net/api/tests/getdatavar.rs @@ -14,33 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - +use super::test_rpc; use crate::net::api::*; -use crate::net::httpcore::RPCRequestHandler; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getheaders.rs b/stackslib/src/net/api/tests/getheaders.rs index d3b80c7a03..800d43220a 100644 --- a/stackslib/src/net/api/tests/getheaders.rs +++ b/stackslib/src/net/api/tests/getheaders.rs @@ -14,48 +14,34 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPrivateKey; +use stacks_common::types::chainstate::{ + ConsensusHash, StacksAddress, StacksBlockId, StacksPrivateKey, +}; use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use crate::util_lib::db::DBConn; - -use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; -use crate::chainstate::stacks::Error as chainstate_error; -use crate::chainstate::stacks::StacksBlock; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; - +use super::TestRPC; use crate::chainstate::stacks::db::blocks::test::*; use crate::chainstate::stacks::db::test::instantiate_chainstate; -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; +use crate::chainstate::stacks::{ + Error as chainstate_error, StacksBlock, StacksBlockHeader, StacksMicroblock, +}; use crate::net::api::getheaders::StacksHeaderStream; +use crate::net::api::*; +use crate::net::connection::ConnectionOptions; use crate::net::http::HttpChunkGenerator; - use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, }; - -use crate::net::httpcore::RPCRequestHandler; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - -use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::{ProtocolFamily, TipRequest}; +use crate::util_lib::db::DBConn; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getinfo.rs b/stackslib/src/net/api/tests/getinfo.rs index 8e79c98b69..da1ca4ba19 100644 --- a/stackslib/src/net/api/tests/getinfo.rs +++ b/stackslib/src/net/api/tests/getinfo.rs @@ -14,36 +14,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; +use serde_json; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::test_rpc; use crate::net::api::getinfo::RPCPeerInfoData; -use crate::net::httpcore::RPCRequestHandler; -use serde_json; - +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getistraitimplemented.rs b/stackslib/src/net/api/tests/getistraitimplemented.rs index 8760fe8ecf..99c1f4be4f 100644 --- a/stackslib/src/net/api/tests/getistraitimplemented.rs +++ b/stackslib/src/net/api/tests/getistraitimplemented.rs @@ -14,36 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::test_rpc; use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getmapentry.rs b/stackslib/src/net/api/tests/getmapentry.rs index 00b2152567..d8e25cfe5f 100644 --- a/stackslib/src/net/api/tests/getmapentry.rs +++ b/stackslib/src/net/api/tests/getmapentry.rs @@ -14,37 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::test_rpc; use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getmicroblocks_confirmed.rs b/stackslib/src/net/api/tests/getmicroblocks_confirmed.rs index d78de0c0ec..298cb496ce 100644 --- a/stackslib/src/net/api/tests/getmicroblocks_confirmed.rs +++ b/stackslib/src/net/api/tests/getmicroblocks_confirmed.rs @@ -14,57 +14,36 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPrivateKey; - -use crate::util_lib::db::DBConn; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; -use crate::chainstate::stacks::Error as chainstate_error; -use crate::chainstate::stacks::StacksBlock; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::{ + ConsensusHash, StacksAddress, StacksBlockId, StacksPrivateKey, +}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use super::TestRPC; use crate::chainstate::stacks::db::blocks::test::*; use crate::chainstate::stacks::db::test::instantiate_chainstate; +use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; use crate::chainstate::stacks::test::make_codec_test_block; - +use crate::chainstate::stacks::{ + Error as chainstate_error, StacksBlock, StacksBlockHeader, StacksMicroblock, +}; +use crate::core::BLOCK_LIMIT_MAINNET_21; use crate::net::api::getmicroblocks_indexed::StacksIndexedMicroblockStream; - +use crate::net::api::*; +use crate::net::connection::ConnectionOptions; use crate::net::http::HttpChunkGenerator; - -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, }; - -use stacks_common::types::net::PeerHost; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - -use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::{ProtocolFamily, TipRequest}; +use crate::util_lib::db::DBConn; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getmicroblocks_indexed.rs b/stackslib/src/net/api/tests/getmicroblocks_indexed.rs index 1a192afb53..52d49c8f2e 100644 --- a/stackslib/src/net/api/tests/getmicroblocks_indexed.rs +++ b/stackslib/src/net/api/tests/getmicroblocks_indexed.rs @@ -14,55 +14,35 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPrivateKey; - -use crate::util_lib::db::DBConn; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; -use crate::chainstate::stacks::Error as chainstate_error; -use crate::chainstate::stacks::StacksBlock; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::{ + ConsensusHash, StacksAddress, StacksBlockId, StacksPrivateKey, +}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use super::TestRPC; use crate::chainstate::stacks::db::blocks::test::*; use crate::chainstate::stacks::db::test::instantiate_chainstate; +use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; use crate::chainstate::stacks::test::make_codec_test_block; - +use crate::chainstate::stacks::{ + Error as chainstate_error, StacksBlock, StacksBlockHeader, StacksMicroblock, +}; +use crate::core::BLOCK_LIMIT_MAINNET_21; use crate::net::api::getmicroblocks_indexed::StacksIndexedMicroblockStream; - -use crate::net::http::HttpChunkGenerator; - -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest}; - -use stacks_common::types::net::PeerHost; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::http::HttpChunkGenerator; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; +use crate::util_lib::db::DBConn; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getmicroblocks_unconfirmed.rs b/stackslib/src/net/api/tests/getmicroblocks_unconfirmed.rs index b559597145..cc244956f6 100644 --- a/stackslib/src/net/api/tests/getmicroblocks_unconfirmed.rs +++ b/stackslib/src/net/api/tests/getmicroblocks_unconfirmed.rs @@ -14,54 +14,34 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPrivateKey; - -use crate::util_lib::db::DBConn; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; -use crate::chainstate::stacks::Error as chainstate_error; -use crate::chainstate::stacks::StacksBlock; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::{ + ConsensusHash, StacksAddress, StacksBlockId, StacksPrivateKey, +}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use super::TestRPC; use crate::chainstate::stacks::db::blocks::test::*; use crate::chainstate::stacks::db::test::instantiate_chainstate; - +use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; +use crate::chainstate::stacks::{ + Error as chainstate_error, StacksBlock, StacksBlockHeader, StacksMicroblock, +}; +use crate::core::BLOCK_LIMIT_MAINNET_21; use crate::net::api::getmicroblocks_unconfirmed::StacksUnconfirmedMicroblockStream; - -use crate::net::http::HttpChunkGenerator; - -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest}; - -use stacks_common::types::net::PeerHost; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::Address; - -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::http::HttpChunkGenerator; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; +use crate::util_lib::db::DBConn; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getneighbors.rs b/stackslib/src/net/api/tests/getneighbors.rs index 6c7da7ff1b..43acd650cc 100644 --- a/stackslib/src/net/api/tests/getneighbors.rs +++ b/stackslib/src/net/api/tests/getneighbors.rs @@ -14,36 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::test_rpc; use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getpoxinfo.rs b/stackslib/src/net/api/tests/getpoxinfo.rs index 33b949e016..88ec1bda37 100644 --- a/stackslib/src/net/api/tests/getpoxinfo.rs +++ b/stackslib/src/net/api/tests/getpoxinfo.rs @@ -14,36 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::test_rpc; use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getstackerdbchunk.rs b/stackslib/src/net/api/tests/getstackerdbchunk.rs index 4017e895d4..11284c5bb6 100644 --- a/stackslib/src/net/api/tests/getstackerdbchunk.rs +++ b/stackslib/src/net/api/tests/getstackerdbchunk.rs @@ -14,38 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; +use libstackerdb::SlotMetadata; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::test_rpc; use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use libstackerdb::SlotMetadata; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getstackerdbmetadata.rs b/stackslib/src/net/api/tests/getstackerdbmetadata.rs index 89cc1c9cd1..c2e72c3092 100644 --- a/stackslib/src/net/api/tests/getstackerdbmetadata.rs +++ b/stackslib/src/net/api/tests/getstackerdbmetadata.rs @@ -14,38 +14,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; use stacks_common::util::hash::Sha512Trunc256Sum; use stacks_common::util::secp256k1::MessageSignature; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::test_rpc; use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/getstxtransfercost.rs b/stackslib/src/net/api/tests/getstxtransfercost.rs index 38bb0877f6..6c4cccc369 100644 --- a/stackslib/src/net/api/tests/getstxtransfercost.rs +++ b/stackslib/src/net/api/tests/getstxtransfercost.rs @@ -14,38 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, -}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - use super::test_rpc; - use crate::chainstate::stacks::db::blocks::MINIMUM_TX_FEE_RATE_PER_BYTE; - +use crate::core::BLOCK_LIMIT_MAINNET_21; +use crate::net::api::*; use crate::net::connection::ConnectionOptions; +use crate::net::httpcore::{ + HttpPreambleExtensions, HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, + StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/gettransaction_unconfirmed.rs b/stackslib/src/net/api/tests/gettransaction_unconfirmed.rs index 5d8eeaa0d2..5e249d62c6 100644 --- a/stackslib/src/net/api/tests/gettransaction_unconfirmed.rs +++ b/stackslib/src/net/api/tests/gettransaction_unconfirmed.rs @@ -14,36 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::TestRPC; use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - -use crate::net::connection::ConnectionOptions; - use crate::net::api::gettransaction_unconfirmed::UnconfirmedTransactionStatus; - -use super::TestRPC; +use crate::net::api::*; +use crate::net::connection::ConnectionOptions; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/mod.rs b/stackslib/src/net/api/tests/mod.rs index b0ebde67f0..adcd681ae5 100644 --- a/stackslib/src/net/api/tests/mod.rs +++ b/stackslib/src/net/api/tests/mod.rs @@ -16,65 +16,35 @@ use std::net::SocketAddr; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use libstackerdb::SlotMetadata; +use stacks_common::address::{AddressHashMode, C32_ADDRESS_VERSION_TESTNET_SINGLESIG}; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::{ + BlockHeaderHash, ConsensusHash, StacksAddress, StacksBlockId, StacksPrivateKey, StacksPublicKey, +}; +use stacks_common::util::hash::{Hash160, Sha512Trunc256Sum}; +use stacks_common::util::pipe::Pipe; + use crate::burnchains::bitcoin::indexer::BitcoinIndexer; use crate::burnchains::Txid; - use crate::chainstate::burn::db::sortdb::SortitionDB; - use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::miner::BlockBuilderSettings; -use crate::chainstate::stacks::miner::StacksMicroblockBuilder; -use crate::chainstate::stacks::CoinbasePayload; -use crate::chainstate::stacks::StacksBlock; -use crate::chainstate::stacks::StacksBlockBuilder; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::StacksMicroblock; -use crate::chainstate::stacks::StacksTransaction; -use crate::chainstate::stacks::StacksTransactionSigner; -use crate::chainstate::stacks::TokenTransferMemo; -use crate::chainstate::stacks::TransactionAnchorMode; -use crate::chainstate::stacks::TransactionAuth; -use crate::chainstate::stacks::TransactionPayload; -use crate::chainstate::stacks::TransactionPostConditionMode; -use crate::chainstate::stacks::TransactionVersion; - +use crate::chainstate::stacks::miner::{BlockBuilderSettings, StacksMicroblockBuilder}; +use crate::chainstate::stacks::{ + CoinbasePayload, StacksBlock, StacksBlockBuilder, StacksBlockHeader, StacksMicroblock, + StacksTransaction, StacksTransactionSigner, TokenTransferMemo, TransactionAnchorMode, + TransactionAuth, TransactionPayload, TransactionPostConditionMode, TransactionVersion, +}; use crate::core::MemPoolDB; - +use crate::net::httpcore::{StacksHttpRequest, StacksHttpResponse}; use crate::net::relay::Relayer; use crate::net::rpc::ConversationHttp; -use crate::net::Attachment; -use crate::net::AttachmentInstance; -use crate::net::RPCHandlerArgs; -use crate::net::StackerDBConfig; -use crate::net::StacksHttpRequest; -use crate::net::StacksHttpResponse; -use crate::net::StacksNodeState; -use crate::net::UrlString; - -use crate::net::test::TestPeer; -use crate::net::test::TestPeerConfig; - -use stacks_common::address::AddressHashMode; -use stacks_common::address::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; - -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPrivateKey; -use stacks_common::types::chainstate::StacksPublicKey; - -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::pipe::Pipe; - -use stacks_common::codec::StacksMessageCodec; - -use clarity::vm::costs::ExecutionCost; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; - -use libstackerdb::SlotMetadata; +use crate::net::test::{TestPeer, TestPeerConfig}; +use crate::net::{ + Attachment, AttachmentInstance, RPCHandlerArgs, StackerDBConfig, StacksNodeState, UrlString, +}; mod callreadonly; mod getaccount; diff --git a/stackslib/src/net/api/tests/postblock.rs b/stackslib/src/net/api/tests/postblock.rs index 816c6909de..c3d1f29359 100644 --- a/stackslib/src/net/api/tests/postblock.rs +++ b/stackslib/src/net/api/tests/postblock.rs @@ -14,38 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest}; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; +use stacks_common::types::chainstate::{ConsensusHash, StacksAddress}; use stacks_common::types::net::PeerHost; - -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::core::BLOCK_LIMIT_MAINNET_21; - +use super::TestRPC; use crate::chainstate::stacks::test::make_codec_test_block; use crate::chainstate::stacks::StacksBlockHeader; -use crate::net::httpcore::RPCRequestHandler; - +use crate::core::BLOCK_LIMIT_MAINNET_21; +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/postfeerate.rs b/stackslib/src/net/api/tests/postfeerate.rs index 64b5d87f39..b34109b5e5 100644 --- a/stackslib/src/net/api/tests/postfeerate.rs +++ b/stackslib/src/net/api/tests/postfeerate.rs @@ -14,36 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest}; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; use stacks_common::types::chainstate::StacksAddress; use stacks_common::types::net::PeerHost; use stacks_common::types::Address; use stacks_common::util::hash::to_hex; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::core::BLOCK_LIMIT_MAINNET_21; - +use super::test_rpc; use crate::chainstate::stacks::TransactionPayload; -use crate::net::httpcore::RPCRequestHandler; - +use crate::core::BLOCK_LIMIT_MAINNET_21; +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::test_rpc; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/postmempoolquery.rs b/stackslib/src/net/api/tests/postmempoolquery.rs index 6445f85c28..034eed9f49 100644 --- a/stackslib/src/net/api/tests/postmempoolquery.rs +++ b/stackslib/src/net/api/tests/postmempoolquery.rs @@ -16,68 +16,38 @@ use std::collections::HashSet; use std::io; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use stacks_common::codec::read_next; -use stacks_common::codec::Error as CodecError; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksPrivateKey; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::Hash160; - -use crate::util_lib::db::DBConn; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; +use stacks_common::codec::{read_next, Error as CodecError, StacksMessageCodec}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, ConsensusHash, StacksAddress, StacksPrivateKey, +}; +use stacks_common::types::net::PeerHost; +use stacks_common::types::Address; +use stacks_common::util::hash::{to_hex, Hash160}; +use super::TestRPC; use crate::burnchains::Txid; use crate::chainstate::stacks::db::blocks::test::*; -use crate::chainstate::stacks::db::test::chainstate_path; -use crate::chainstate::stacks::db::test::instantiate_chainstate; +use crate::chainstate::stacks::db::test::{chainstate_path, instantiate_chainstate}; use crate::chainstate::stacks::db::{ExtendedStacksHeader, StacksChainState}; -use crate::chainstate::stacks::Error as chainstate_error; use crate::chainstate::stacks::{ - StacksTransaction, TokenTransferMemo, TransactionAnchorMode, TransactionAuth, - TransactionPayload, TransactionPostConditionMode, TransactionVersion, + Error as chainstate_error, StacksTransaction, TokenTransferMemo, TransactionAnchorMode, + TransactionAuth, TransactionPayload, TransactionPostConditionMode, TransactionVersion, }; - +use crate::core::mempool::{decode_tx_stream, MemPoolSyncData, TxTag, MAX_BLOOM_COUNTER_TXS}; +use crate::core::{MemPoolDB, BLOCK_LIMIT_MAINNET_21}; use crate::net::api::postmempoolquery::StacksMemPoolStream; - -use crate::net::http::HttpChunkGenerator; - -use crate::core::mempool::decode_tx_stream; -use crate::core::mempool::MemPoolSyncData; -use crate::core::mempool::TxTag; -use crate::core::mempool::MAX_BLOOM_COUNTER_TXS; -use crate::core::MemPoolDB; -use crate::net::Error as NetError; - -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest}; - -use stacks_common::types::net::PeerHost; - -use stacks_common::types::Address; - -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::core::BLOCK_LIMIT_MAINNET_21; -use crate::net::httpcore::RPCRequestHandler; - use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::http::HttpChunkGenerator; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, +}; +use crate::net::{Error as NetError, ProtocolFamily, TipRequest}; +use crate::util_lib::db::DBConn; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/postmicroblock.rs b/stackslib/src/net/api/tests/postmicroblock.rs index 8caf6ea9de..9688b4a3fc 100644 --- a/stackslib/src/net/api/tests/postmicroblock.rs +++ b/stackslib/src/net/api/tests/postmicroblock.rs @@ -14,37 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::core::BLOCK_LIMIT_MAINNET_21; - +use super::TestRPC; use crate::chainstate::stacks::test::make_codec_test_microblock; use crate::chainstate::stacks::StacksMicroblock; -use crate::net::httpcore::RPCRequestHandler; - +use crate::core::BLOCK_LIMIT_MAINNET_21; +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/poststackerdbchunk.rs b/stackslib/src/net/api/tests/poststackerdbchunk.rs index b32d0e8440..4ab5cac6eb 100644 --- a/stackslib/src/net/api/tests/poststackerdbchunk.rs +++ b/stackslib/src/net/api/tests/poststackerdbchunk.rs @@ -14,40 +14,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest}; - -use stacks_common::types::net::PeerHost; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; +use libstackerdb::{SlotMetadata, StackerDBChunkData}; use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::net::PeerHost; use stacks_common::types::Address; use stacks_common::util::hash::Sha512Trunc256Sum; use stacks_common::util::secp256k1::MessageSignature; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - +use super::TestRPC; use crate::core::BLOCK_LIMIT_MAINNET_21; - -use libstackerdb::SlotMetadata; -use libstackerdb::StackerDBChunkData; - -use crate::net::httpcore::RPCRequestHandler; - +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, +}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/api/tests/posttransaction.rs b/stackslib/src/net/api/tests/posttransaction.rs index 6cf6d4d1b5..fd1c1e7e37 100644 --- a/stackslib/src/net/api/tests/posttransaction.rs +++ b/stackslib/src/net/api/tests/posttransaction.rs @@ -14,46 +14,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::SocketAddr; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest}; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::{ClarityName, ContractName, Value}; +use stacks_common::address::{AddressHashMode, C32_ADDRESS_VERSION_TESTNET_SINGLESIG}; +use stacks_common::types::chainstate::{StacksAddress, StacksPrivateKey, StacksPublicKey}; use stacks_common::types::net::PeerHost; - -use stacks_common::address::AddressHashMode; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksPrivateKey; -use stacks_common::types::chainstate::StacksPublicKey; use stacks_common::types::Address; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::Value; - -use crate::net::api::*; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; - -use crate::core::BLOCK_LIMIT_MAINNET_21; - +use super::TestRPC; use crate::chainstate::stacks::{ StacksTransaction, StacksTransactionSigner, TransactionAuth, TransactionPayload, TransactionVersion, }; - -use stacks_common::address::C32_ADDRESS_VERSION_TESTNET_SINGLESIG; - -use crate::net::httpcore::RPCRequestHandler; -use crate::net::Attachment; - +use crate::core::BLOCK_LIMIT_MAINNET_21; +use crate::net::api::*; use crate::net::connection::ConnectionOptions; - -use super::TestRPC; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, RPCRequestHandler, StacksHttp, StacksHttpRequest, +}; +use crate::net::{Attachment, ProtocolFamily, TipRequest}; #[test] fn test_try_parse_request() { diff --git a/stackslib/src/net/asn.rs b/stackslib/src/net/asn.rs index 3bcd91def9..f38c6c54d4 100644 --- a/stackslib/src/net/asn.rs +++ b/stackslib/src/net/asn.rs @@ -15,16 +15,14 @@ // along with this program. If not, see . use std::fs::File; -use std::io::BufRead; -use std::io::BufReader; - -use crate::net::Error as net_error; - -use regex::Captures; -use regex::Regex; +use std::io::{BufRead, BufReader}; +use regex::{Captures, Regex}; +use stacks_common::types::net::PeerAddress; use stacks_common::util::log; +use crate::net::Error as net_error; + // IPv4 prefix to ASN/org map entry #[derive(Debug, Clone, PartialEq)] pub struct ASEntry4 { @@ -226,11 +224,13 @@ impl ASEntry4 { #[cfg(test)] mod test { - use super::*; - use stacks_common::util::log; use std::io; use std::io::BufRead; + use stacks_common::util::log; + + use super::*; + struct asn_fixture { text: String, result: Result, net_error>, diff --git a/stackslib/src/net/atlas/db.rs b/stackslib/src/net/atlas/db.rs index 2712b854d6..10f48a6114 100644 --- a/stackslib/src/net/atlas/db.rs +++ b/stackslib/src/net/atlas/db.rs @@ -33,43 +33,27 @@ //! to its download queue. //! -use rusqlite::types::FromSql; -use rusqlite::types::FromSqlError; -use rusqlite::types::ToSql; -use rusqlite::types::ToSqlOutput; -use rusqlite::types::ValueRef; -use rusqlite::OptionalExtension; -use rusqlite::Row; -use rusqlite::Transaction; -use rusqlite::{Connection, OpenFlags, NO_PARAMS}; - use std::collections::HashSet; -use std::convert::From; -use std::convert::TryFrom; +use std::convert::{From, TryFrom}; use std::fs; -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::tx_begin_immediate; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::{ - query_count, query_int, query_row, query_rows, u64_to_sql, FromColumn, FromRow, -}; - +use clarity::vm::types::QualifiedContractIdentifier; +use rusqlite::types::{FromSql, FromSqlError, ToSql, ToSqlOutput, ValueRef}; +use rusqlite::{Connection, OpenFlags, OptionalExtension, Row, Transaction, NO_PARAMS}; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::StacksBlockId; use stacks_common::util; use stacks_common::util::hash::{bin_bytes, hex_bytes, to_bin, to_hex, Hash160}; use stacks_common::util::log; use stacks_common::util::macros::is_big_endian; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use clarity::vm::types::QualifiedContractIdentifier; - -use crate::burnchains::Txid; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; use super::{AtlasConfig, Attachment, AttachmentInstance}; +use crate::burnchains::Txid; +use crate::util_lib::db::{ + query_count, query_int, query_row, query_rows, sqlite_open, tx_begin_immediate, u64_to_sql, + DBConn, Error as db_error, FromColumn, FromRow, +}; pub const ATLASDB_VERSION: &'static str = "2"; diff --git a/stackslib/src/net/atlas/download.rs b/stackslib/src/net/atlas/download.rs index 15fd1d46d3..489050bcbd 100644 --- a/stackslib/src/net/atlas/download.rs +++ b/stackslib/src/net/atlas/download.rs @@ -17,42 +17,29 @@ use std::cmp::Ordering; use std::collections::hash_map::Entry; use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; -use std::fmt; use std::hash::{Hash, Hasher}; use std::net::{IpAddr, SocketAddr}; +use std::{cmp, fmt}; +use clarity::vm::types::QualifiedContractIdentifier; +use rand::{thread_rng, Rng}; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; +use stacks_common::util::hash::{Hash160, MerkleHashFunc}; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs}; + +use super::{AtlasDB, Attachment, AttachmentInstance, MAX_ATTACHMENT_INV_PAGES_PER_REQUEST}; use crate::chainstate::burn::ConsensusHash; -use crate::net::atlas::MAX_RETRY_DELAY; -use crate::net::atlas::{GetAttachmentResponse, GetAttachmentsInvResponse}; +use crate::net::atlas::{GetAttachmentResponse, GetAttachmentsInvResponse, MAX_RETRY_DELAY}; use crate::net::connection::ConnectionOptions; use crate::net::dns::*; +use crate::net::http::HttpRequestContents; +use crate::net::httpcore::{StacksHttpRequest, StacksHttpResponse}; use crate::net::p2p::PeerNetwork; use crate::net::server::HttpPeer; -use crate::net::Error as net_error; -use crate::net::NeighborKey; -use crate::net::Requestable; +use crate::net::{Error as net_error, NeighborKey, PeerHost, Requestable}; use crate::util_lib::db::Error as DBError; use crate::util_lib::strings; use crate::util_lib::strings::UrlString; -use clarity::vm::types::QualifiedContractIdentifier; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::util::hash::{hex_bytes, Hash160, MerkleHashFunc}; -use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs}; - -use stacks_common::types::chainstate::BlockHeaderHash; - -use super::{AtlasDB, Attachment, AttachmentInstance, MAX_ATTACHMENT_INV_PAGES_PER_REQUEST}; - -use rand::thread_rng; -use rand::Rng; -use std::cmp; - -use crate::net::httpcore::{StacksHttpRequest, StacksHttpResponse}; - -use crate::net::http::HttpRequestContents; - -use serde::ser::Serialize; -use stacks_common::types::net::PeerHost; #[derive(Debug)] pub struct AttachmentsDownloader { diff --git a/stackslib/src/net/atlas/mod.rs b/stackslib/src/net/atlas/mod.rs index 1392f5b0ac..441802bff2 100644 --- a/stackslib/src/net/atlas/mod.rs +++ b/stackslib/src/net/atlas/mod.rs @@ -18,24 +18,20 @@ use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::hash::{Hash, Hasher}; -use regex::Regex; - -use crate::burnchains::Txid; -use crate::chainstate::burn::db::sortdb::SortitionDB; -use crate::chainstate::burn::ConsensusHash; -use crate::util_lib::boot::boot_code_id; use clarity::vm::types::{QualifiedContractIdentifier, SequenceData, TupleData, Value}; +use regex::Regex; +use serde::de::{Deserialize, Error as de_Error}; +use serde::ser::Serialize; use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, MerkleHashFunc}; -use stacks_common::types::chainstate::BlockHeaderHash; - pub use self::db::AtlasDB; pub use self::download::AttachmentsDownloader; - -use serde::de::{Deserialize, Error as de_Error}; -use serde::ser::Serialize; +use crate::burnchains::Txid; +use crate::chainstate::burn::db::sortdb::SortitionDB; +use crate::chainstate::burn::ConsensusHash; +use crate::util_lib::boot::boot_code_id; /// Implements AtlasDB and associated API. Stores information about attachments and attachment /// instances. diff --git a/stackslib/src/net/atlas/tests.rs b/stackslib/src/net/atlas/tests.rs index 97307cf0a2..567d49fe61 100644 --- a/stackslib/src/net/atlas/tests.rs +++ b/stackslib/src/net/atlas/tests.rs @@ -16,33 +16,30 @@ use std::collections::{BinaryHeap, HashMap, HashSet}; use std::convert::TryFrom; -use std::thread; -use std::time; +use std::{thread, time}; +use clarity::vm::types::QualifiedContractIdentifier; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; +use stacks_common::types::net::{PeerAddress, PeerHost}; +use stacks_common::util::hash::Hash160; + +use super::download::{ + AttachmentRequest, AttachmentsBatch, AttachmentsBatchStateContext, AttachmentsInventoryRequest, + BatchedRequestsResult, ReliabilityReport, +}; +use super::{ + AtlasConfig, AtlasDB, Attachment, AttachmentInstance, AttachmentPage, GetAttachmentsInvResponse, +}; use crate::burnchains::Txid; use crate::chainstate::burn::ConsensusHash; use crate::chainstate::stacks::db::StacksChainState; use crate::net::connection::ConnectionOptions; +use crate::net::http::{HttpResponsePayload, HttpResponsePreamble, HttpVersion}; +use crate::net::httpcore::StacksHttpResponse; use crate::net::Requestable; use crate::util_lib::boot::boot_code_id; use crate::util_lib::db::u64_to_sql; use crate::util_lib::strings::UrlString; -use clarity::vm::types::QualifiedContractIdentifier; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerHost; -use stacks_common::util::hash::Hash160; - -use crate::net::http::{HttpResponsePayload, HttpResponsePreamble, HttpVersion}; -use crate::net::httpcore::StacksHttpResponse; - -use crate::net::atlas::GetAttachmentsInvResponse; - -use super::download::{ - AttachmentRequest, AttachmentsBatch, AttachmentsBatchStateContext, AttachmentsInventoryRequest, - BatchedRequestsResult, ReliabilityReport, -}; -use super::{AtlasConfig, AtlasDB, Attachment, AttachmentInstance, AttachmentPage}; fn new_attachment_from(content: &str) -> Attachment { Attachment { diff --git a/stackslib/src/net/chat.rs b/stackslib/src/net/chat.rs index a754300ca6..664ab52c30 100644 --- a/stackslib/src/net/chat.rs +++ b/stackslib/src/net/chat.rs @@ -14,64 +14,42 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::cmp; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; +use std::collections::{HashMap, HashSet, VecDeque}; use std::convert::TryFrom; -use std::io::Read; -use std::io::Write; -use std::mem; +use std::io::{Read, Write}; use std::net::SocketAddr; +use std::{cmp, mem}; +use clarity::vm::types::QualifiedContractIdentifier; use rand; -use rand::thread_rng; -use rand::Rng; +use rand::{thread_rng, Rng}; +use stacks_common::types::chainstate::PoxId; +use stacks_common::types::net::PeerAddress; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::to_hex; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; +use stacks_common::util::{get_epoch_time_secs, log}; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainView; -use crate::burnchains::PublicKey; +use crate::burnchains::{Burnchain, BurnchainView, PublicKey}; use crate::chainstate::burn::db::sortdb; use crate::chainstate::burn::db::sortdb::{BlockHeaderCache, SortitionDB}; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::StacksPublicKey; -use crate::core::PEER_VERSION_EPOCH_2_2; -use crate::core::PEER_VERSION_EPOCH_2_3; +use crate::core::{StacksEpoch, PEER_VERSION_EPOCH_2_2, PEER_VERSION_EPOCH_2_3}; use crate::monitoring; use crate::net::asn::ASEntry4; use crate::net::codec::*; -use crate::net::connection::ConnectionOptions; -use crate::net::connection::ConnectionP2P; -use crate::net::connection::ReplyHandleP2P; -use crate::net::db::PeerDB; -use crate::net::db::*; +use crate::net::connection::{ConnectionOptions, ConnectionP2P, ReplyHandleP2P}; +use crate::net::db::{PeerDB, *}; use crate::net::neighbors::MAX_NEIGHBOR_BLOCK_DELAY; use crate::net::p2p::PeerNetwork; use crate::net::relay::*; use crate::net::stackerdb::StackerDBs; -use crate::net::Error as net_error; -use crate::net::GetBlocksInv; -use crate::net::GetPoxInv; -use crate::net::Neighbor; -use crate::net::NeighborKey; -use crate::net::StacksMessage; -use crate::net::StacksP2P; -use crate::net::GETPOXINV_MAX_BITLEN; -use crate::net::*; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; -use stacks_common::types::net::PeerAddress; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use crate::core::StacksEpoch; -use stacks_common::types::chainstate::PoxId; -use stacks_common::types::StacksPublicKeyBuffer; - -use clarity::vm::types::QualifiedContractIdentifier; +use crate::net::{ + Error as net_error, GetBlocksInv, GetPoxInv, Neighbor, NeighborKey, StacksMessage, StacksP2P, + GETPOXINV_MAX_BITLEN, *, +}; +use crate::util_lib::db::{DBConn, Error as db_error}; // did we or did we not successfully send a message? #[derive(Debug, Clone)] @@ -2713,11 +2691,17 @@ impl ConversationP2P { mod test { use std::fs; use std::io::prelude::*; - use std::io::Read; - use std::io::Write; - use std::net::SocketAddr; - use std::net::SocketAddrV4; + use std::io::{Read, Write}; + use std::net::{SocketAddr, SocketAddrV4}; + use clarity::vm::costs::ExecutionCost; + use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, SortitionId}; + use stacks_common::util::pipe::*; + use stacks_common::util::secp256k1::*; + use stacks_common::util::sleep_ms; + use stacks_common::util::uint::*; + + use super::*; use crate::burnchains::bitcoin::keys::BitcoinPublicKey; use crate::burnchains::burnchain::*; use crate::burnchains::*; @@ -2733,15 +2717,6 @@ mod test { use crate::net::test::*; use crate::net::*; use crate::util_lib::test::*; - use clarity::vm::costs::ExecutionCost; - use stacks_common::util::pipe::*; - use stacks_common::util::secp256k1::*; - use stacks_common::util::sleep_ms; - use stacks_common::util::uint::*; - - use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, SortitionId}; - - use super::*; const DEFAULT_SERVICES: u16 = (ServiceFlags::RELAY as u16) | (ServiceFlags::RPC as u16); const STACKERDB_SERVICES: u16 = (ServiceFlags::RELAY as u16) diff --git a/stackslib/src/net/codec.rs b/stackslib/src/net/codec.rs index 61ecbe4eae..a9de074061 100644 --- a/stackslib/src/net/codec.rs +++ b/stackslib/src/net/codec.rs @@ -16,50 +16,37 @@ use std::collections::HashSet; use std::convert::TryFrom; -use std::io; use std::io::prelude::*; use std::io::Read; -use std::mem; +use std::{io, mem}; +use clarity::vm::types::{QualifiedContractIdentifier, StandardPrincipalData}; +use clarity::vm::ContractName; use rand; use rand::Rng; -use sha2::Digest; -use sha2::Sha512_256; - -use crate::burnchains::BurnchainView; -use crate::burnchains::PrivateKey; -use crate::burnchains::PublicKey; -use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::stacks::StacksBlock; -use crate::chainstate::stacks::StacksMicroblock; -use crate::chainstate::stacks::StacksPublicKey; -use crate::chainstate::stacks::StacksTransaction; -use crate::chainstate::stacks::MAX_BLOCK_LEN; -use crate::core::PEER_VERSION_TESTNET; -use crate::net::db::LocalPeer; -use crate::net::Error as net_error; -use crate::net::*; -use stacks_common::codec::{read_next_at_most, read_next_exact, MAX_MESSAGE_LEN}; -use stacks_common::util::hash::to_hex; -use stacks_common::util::hash::DoubleSha256; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::MerkleHashFunc; -use stacks_common::util::log; -use stacks_common::util::retry::BoundReader; -use stacks_common::util::secp256k1::MessageSignature; -use stacks_common::util::secp256k1::MESSAGE_SIGNATURE_ENCODED_SIZE; -use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; - +use sha2::{Digest, Sha512_256}; use stacks_common::codec::{ - read_next, write_next, Error as codec_error, StacksMessageCodec, MAX_RELAYERS_LEN, - PREAMBLE_ENCODED_SIZE, + read_next, read_next_at_most, read_next_exact, write_next, Error as codec_error, + StacksMessageCodec, MAX_MESSAGE_LEN, MAX_RELAYERS_LEN, PREAMBLE_ENCODED_SIZE, }; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BurnchainHeaderHash; +use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash}; +use stacks_common::types::net::PeerAddress; use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{to_hex, DoubleSha256, Hash160, MerkleHashFunc}; +use stacks_common::util::log; +use stacks_common::util::retry::BoundReader; +use stacks_common::util::secp256k1::{ + MessageSignature, Secp256k1PrivateKey, Secp256k1PublicKey, MESSAGE_SIGNATURE_ENCODED_SIZE, +}; -use clarity::vm::types::{QualifiedContractIdentifier, StandardPrincipalData}; -use clarity::vm::ContractName; +use crate::burnchains::{BurnchainView, PrivateKey, PublicKey}; +use crate::chainstate::burn::ConsensusHash; +use crate::chainstate::stacks::{ + StacksBlock, StacksMicroblock, StacksPublicKey, StacksTransaction, MAX_BLOCK_LEN, +}; +use crate::core::PEER_VERSION_TESTNET; +use crate::net::db::LocalPeer; +use crate::net::{Error as net_error, *}; impl Preamble { /// Make an empty preamble with the given version and fork-set identifier, and payload length. diff --git a/stackslib/src/net/connection.rs b/stackslib/src/net/connection.rs index 91c70c20f7..522a0f6343 100644 --- a/stackslib/src/net/connection.rs +++ b/stackslib/src/net/connection.rs @@ -16,34 +16,29 @@ use std::collections::VecDeque; use std::convert::TryFrom; -use std::io; use std::io::{Read, Write}; -use std::net; -use std::ops::Deref; -use std::ops::DerefMut; +use std::ops::{Deref, DerefMut}; +use std::sync::mpsc::{ + sync_channel, Receiver, RecvError, RecvTimeoutError, SyncSender, TryRecvError, TrySendError, +}; use std::time::Duration; +use std::{io, net}; -use std::sync::mpsc::sync_channel; -use std::sync::mpsc::Receiver; -use std::sync::mpsc::RecvError; -use std::sync::mpsc::RecvTimeoutError; -use std::sync::mpsc::SyncSender; -use std::sync::mpsc::TryRecvError; -use std::sync::mpsc::TrySendError; - +use clarity::vm::costs::ExecutionCost; +use clarity::vm::types::BOUND_VALUE_SERIALIZATION_HEX; use mio; use mio::net as mio_net; +use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::types::net::PeerAddress; +use stacks_common::util::hash::to_hex; +use stacks_common::util::pipe::*; +use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::{get_epoch_time_secs, log, sleep_ms}; +use crate::chainstate::burn::ConsensusHash; use crate::core::mempool::MAX_BLOOM_COUNTER_TXS; +use crate::monitoring::{update_inbound_bandwidth, update_outbound_bandwidth}; use crate::net::codec::*; -use crate::net::Error as net_error; -use crate::net::MessageSequence; -use crate::net::ProtocolFamily; -use crate::net::StacksHttp; -use crate::net::StacksP2P; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; - use crate::net::download::BLOCK_DOWNLOAD_INTERVAL; use crate::net::inv::{INV_REWARD_CYCLES, INV_SYNC_INTERVAL}; use crate::net::neighbors::{ @@ -51,18 +46,9 @@ use crate::net::neighbors::{ WALK_MAX_DURATION, WALK_MIN_DURATION, WALK_RESET_INTERVAL, WALK_RESET_PROB, WALK_RETRY_COUNT, WALK_STATE_TIMEOUT, }; - -use clarity::vm::{costs::ExecutionCost, types::BOUND_VALUE_SERIALIZATION_HEX}; - -use stacks_common::types::net::PeerAddress; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; -use stacks_common::util::pipe::*; -use stacks_common::util::secp256k1::Secp256k1PublicKey; -use stacks_common::util::sleep_ms; - -use crate::monitoring::{update_inbound_bandwidth, update_outbound_bandwidth}; +use crate::net::{ + Error as net_error, MessageSequence, Preamble, ProtocolFamily, RelayData, StacksHttp, StacksP2P, +}; /// Receiver notification handle. /// When a message with the expected `seq` value arrives, send it to an expected receiver (possibly @@ -1423,25 +1409,22 @@ pub type ReplyHandleHttp = NetworkReplyHandle; #[cfg(test)] mod test { - use super::*; - use crate::net::*; + use std::io::prelude::*; + use std::io::{Read, Write}; + use std::sync::{Arc, Mutex}; + use std::{io, thread}; + use rand; use rand::RngCore; use stacks_common::util::pipe::*; use stacks_common::util::secp256k1::*; use stacks_common::util::*; - use std::io; - use std::io::prelude::*; - use std::io::{Read, Write}; - use std::sync::{Arc, Mutex}; - use std::thread; - - use crate::net::test::make_tcp_sockets; - use crate::net::test::NetCursor; + use super::*; use crate::chainstate::stacks::test::make_codec_test_block; use crate::net::http::*; - + use crate::net::test::{make_tcp_sockets, NetCursor}; + use crate::net::*; use crate::util_lib::test::*; fn test_connection_relay_producer_consumer( diff --git a/stackslib/src/net/db.rs b/stackslib/src/net/db.rs index a11627a638..25c4ed7e62 100644 --- a/stackslib/src/net/db.rs +++ b/stackslib/src/net/db.rs @@ -14,65 +14,37 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::fmt; - use std::collections::HashSet; +use std::convert::{From, TryFrom}; +use std::{fmt, fs}; +use clarity::vm::types::{ + QualifiedContractIdentifier, StacksAddressExtensions, StandardPrincipalData, +}; +use rand::seq::SliceRandom; +use rand::{thread_rng, Rng, RngCore}; use rusqlite::types::ToSql; -use rusqlite::OptionalExtension; -use rusqlite::Row; -use rusqlite::Transaction; -use rusqlite::{Connection, OpenFlags, NO_PARAMS}; - -use std::convert::From; -use std::convert::TryFrom; -use std::fs; - -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::types::StandardPrincipalData; - -use crate::util_lib::db::sqlite_open; -use crate::util_lib::db::tx_begin_immediate; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::{query_count, query_row, query_rows, u64_to_sql, FromColumn, FromRow}; - +use rusqlite::{Connection, OpenFlags, OptionalExtension, Row, Transaction, NO_PARAMS}; +use stacks_common::types::net::{PeerAddress, PeerHost}; use stacks_common::util; -use stacks_common::util::get_epoch_time_secs; use stacks_common::util::hash::{ bin_bytes, hex_bytes, to_bin, to_hex, Hash160, Sha256Sum, Sha512Trunc256Sum, }; -use stacks_common::util::log; use stacks_common::util::macros::is_big_endian; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use crate::util_lib::db::tx_busy_handler; - -use crate::chainstate::stacks::StacksPrivateKey; -use crate::chainstate::stacks::StacksPublicKey; - -use rand::seq::SliceRandom; -use rand::thread_rng; -use rand::Rng; -use rand::RngCore; - -use crate::net::asn::ASEntry4; -use crate::net::Neighbor; -use crate::net::NeighborAddress; -use crate::net::NeighborKey; -use crate::net::ServiceFlags; - -use crate::burnchains::PrivateKey; -use crate::burnchains::PublicKey; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; +use stacks_common::util::{get_epoch_time_secs, log}; +use crate::burnchains::{PrivateKey, PublicKey}; +use crate::chainstate::stacks::{StacksPrivateKey, StacksPublicKey}; use crate::core::NETWORK_P2P_PORT; - +use crate::net::asn::ASEntry4; +use crate::net::{Neighbor, NeighborAddress, NeighborKey, ServiceFlags}; +use crate::util_lib::db::{ + query_count, query_row, query_rows, sqlite_open, tx_begin_immediate, tx_busy_handler, + u64_to_sql, DBConn, Error as db_error, FromColumn, FromRow, +}; use crate::util_lib::strings::UrlString; -use stacks_common::types::net::PeerAddress; - pub const PEERDB_VERSION: &'static str = "2"; const NUM_SLOTS: usize = 8; @@ -1826,17 +1798,13 @@ impl PeerDB { #[cfg(test)] mod test { - use super::*; - use crate::net::Neighbor; - use crate::net::NeighborKey; - use stacks_common::types::net::PeerAddress; - + use clarity::vm::types::{StacksAddressExtensions, StandardPrincipalData}; use stacks_common::types::chainstate::StacksAddress; - + use stacks_common::types::net::{PeerAddress, PeerHost}; use stacks_common::util::hash::Hash160; - use clarity::vm::types::StacksAddressExtensions; - use clarity::vm::types::StandardPrincipalData; + use super::*; + use crate::net::{Neighbor, NeighborKey}; /// Test storage, retrieval, and mutation of LocalPeer, including its stacker DB contract IDs #[test] diff --git a/stackslib/src/net/dns.rs b/stackslib/src/net/dns.rs index ac99ee5d41..aedb73bd62 100644 --- a/stackslib/src/net/dns.rs +++ b/stackslib/src/net/dns.rs @@ -14,39 +14,21 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::sync::mpsc::sync_channel; -use std::sync::mpsc::Receiver; -use std::sync::mpsc::RecvError; -use std::sync::mpsc::RecvTimeoutError; -use std::sync::mpsc::SyncSender; -use std::sync::mpsc::TryRecvError; -use std::sync::mpsc::TrySendError; - +use std::collections::{HashMap, HashSet, VecDeque}; use std::hash::{Hash, Hasher}; -use std::net::ToSocketAddrs; +use std::net::{SocketAddr, ToSocketAddrs}; +use std::sync::mpsc::{ + sync_channel, Receiver, RecvError, RecvTimeoutError, SyncSender, TryRecvError, TrySendError, +}; -use crate::net::asn::ASEntry4; -use crate::net::Error as net_error; -use crate::net::Neighbor; -use crate::net::NeighborKey; +use stacks_common::types::net::PeerAddress; +use stacks_common::util::hash::to_hex; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs, log, sleep_ms}; +use crate::net::asn::ASEntry4; use crate::net::codec::*; -use crate::net::*; - +use crate::net::{Error as net_error, Neighbor, NeighborKey, *}; use crate::util_lib::db::Error as db_error; -use stacks_common::util::sleep_ms; - -use std::net::SocketAddr; - -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; - -use stacks_common::types::net::PeerAddress; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; /// In Rust, there's no easy way to do non-blocking DNS lookups (I blame getaddrinfo), so do it in /// a separate thread, and implement a way for the block downloader to periodically poll for @@ -375,11 +357,13 @@ impl DNSClient { #[cfg(test)] mod test { - use crate::net::test::*; - use stacks_common::util::*; use std::collections::HashMap; use std::error::Error; + use stacks_common::util::*; + + use crate::net::test::*; + #[test] fn dns_start_stop() { let (client, thread_handle) = dns_thread_start(100); diff --git a/stackslib/src/net/download.rs b/stackslib/src/net/download.rs index 7f6f7fba1b..5957b9818a 100644 --- a/stackslib/src/net/download.rs +++ b/stackslib/src/net/download.rs @@ -14,45 +14,36 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; +use std::collections::{HashMap, HashSet, VecDeque}; use std::convert::TryFrom; use std::hash::{Hash, Hasher}; -use std::io::Read; -use std::io::Write; -use std::net::IpAddr; -use std::net::SocketAddr; -use std::sync::mpsc::sync_channel; -use std::sync::mpsc::Receiver; -use std::sync::mpsc::RecvError; -use std::sync::mpsc::RecvTimeoutError; -use std::sync::mpsc::SyncSender; -use std::sync::mpsc::TryRecvError; -use std::sync::mpsc::TrySendError; +use std::io::{Read, Write}; +use std::net::{IpAddr, SocketAddr}; +use std::sync::mpsc::{ + sync_channel, Receiver, RecvError, RecvTimeoutError, SyncSender, TryRecvError, TrySendError, +}; use rand::seq::SliceRandom; -use rand::thread_rng; -use rand::RngCore; +use rand::{thread_rng, RngCore}; +use stacks_common::types::chainstate::{BlockHeaderHash, PoxId, SortitionId, StacksBlockId}; +use stacks_common::types::net::{PeerAddress, PeerHost}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs, log}; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainView; +use crate::burnchains::{Burnchain, BurnchainView}; use crate::chainstate::burn::db::sortdb::{BlockHeaderCache, SortitionDB, SortitionDBConn}; use crate::chainstate::burn::BlockSnapshot; use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::Error as chainstate_error; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::core::mempool::MemPoolDB; -use crate::core::EMPTY_MICROBLOCK_PARENT_HASH; -use crate::core::FIRST_BURNCHAIN_CONSENSUS_HASH; -use crate::core::FIRST_STACKS_BLOCK_HASH; +use crate::chainstate::stacks::{Error as chainstate_error, StacksBlockHeader}; +use crate::core::{ + EMPTY_MICROBLOCK_PARENT_HASH, FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, +}; use crate::net::asn::ASEntry4; use crate::net::atlas::AttachmentsDownloader; use crate::net::codec::*; -use crate::net::connection::ConnectionOptions; -use crate::net::connection::ReplyHandleHttp; -use crate::net::db::PeerDB; -use crate::net::db::*; +use crate::net::connection::{ConnectionOptions, ReplyHandleHttp}; +use crate::net::db::{PeerDB, *}; use crate::net::dns::*; use crate::net::http::HttpRequestContents; use crate::net::httpcore::{StacksHttpRequest, StacksHttpResponse}; @@ -61,25 +52,10 @@ use crate::net::neighbors::MAX_NEIGHBOR_BLOCK_DELAY; use crate::net::p2p::PeerNetwork; use crate::net::rpc::*; use crate::net::server::HttpPeer; -use crate::net::Error as net_error; -use crate::net::GetBlocksInv; -use crate::net::Neighbor; -use crate::net::NeighborKey; -use crate::net::StacksMessage; -use crate::net::StacksP2P; -use crate::net::*; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::net::PeerAddress; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use stacks_common::types::chainstate::{BlockHeaderHash, PoxId, SortitionId}; +use crate::net::{ + Error as net_error, GetBlocksInv, Neighbor, NeighborKey, StacksMessage, StacksP2P, *, +}; +use crate::util_lib::db::{DBConn, Error as db_error}; #[cfg(not(test))] pub const BLOCK_DOWNLOAD_INTERVAL: u64 = 180; @@ -2532,8 +2508,16 @@ pub mod test { use std::collections::HashMap; use std::convert::TryFrom; + use clarity::vm::clarity::ClarityConnection; + use clarity::vm::costs::ExecutionCost; + use clarity::vm::execute; + use clarity::vm::representations::*; use rand::Rng; + use stacks_common::util::hash::*; + use stacks_common::util::sleep_ms; + use stacks_common::util::vrf::VRFProof; + use super::*; use crate::burnchains::tests::TestMiner; use crate::chainstate::burn::db::sortdb::*; use crate::chainstate::burn::operations::*; @@ -2549,15 +2533,6 @@ pub mod test { use crate::stacks_common::types::PublicKey; use crate::util_lib::strings::*; use crate::util_lib::test::*; - use clarity::vm::clarity::ClarityConnection; - use clarity::vm::costs::ExecutionCost; - use clarity::vm::execute; - use clarity::vm::representations::*; - use stacks_common::util::hash::*; - use stacks_common::util::sleep_ms; - use stacks_common::util::vrf::VRFProof; - - use super::*; fn get_peer_availability( peer: &mut TestPeer, diff --git a/stackslib/src/net/http/common.rs b/stackslib/src/net/http/common.rs index 0fee2c37bb..476c7c03da 100644 --- a/stackslib/src/net/http/common.rs +++ b/stackslib/src/net/http/common.rs @@ -14,16 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::fmt; -use std::io; use std::io::Read; use std::net::SocketAddr; use std::str::FromStr; +use std::{fmt, io}; -use stacks_common::codec::read_next; -use stacks_common::codec::Error as CodecError; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; +use stacks_common::codec::{read_next, Error as CodecError, StacksMessageCodec, MAX_MESSAGE_LEN}; use stacks_common::types::net::PeerHost; use stacks_common::util::chunked_encoding::*; use stacks_common::util::retry::BoundReader; diff --git a/stackslib/src/net/http/error.rs b/stackslib/src/net/http/error.rs index afe6dce62e..c84c04d585 100644 --- a/stackslib/src/net/http/error.rs +++ b/stackslib/src/net/http/error.rs @@ -17,13 +17,12 @@ use std::io; use std::io::Read; -use crate::net::http::response::HttpResponse; -use crate::net::http::{Error, HttpContentType, HttpResponsePayload, HttpResponsePreamble}; - +use serde_json; use stacks_common::codec::MAX_MESSAGE_LEN; use stacks_common::util::retry::BoundReader; -use serde_json; +use crate::net::http::response::HttpResponse; +use crate::net::http::{Error, HttpContentType, HttpResponsePayload, HttpResponsePreamble}; /// Default implementation of `try_parse_response()` for an HTTP error message that implements /// `HttpReqeust`. diff --git a/stackslib/src/net/http/mod.rs b/stackslib/src/net/http/mod.rs index 7d032ddd90..cc6355ca31 100644 --- a/stackslib/src/net/http/mod.rs +++ b/stackslib/src/net/http/mod.rs @@ -23,16 +23,14 @@ pub mod stream; #[cfg(test)] mod tests; -use regex::{Captures, Regex}; use std::collections::BTreeMap; -use std::fmt; -use std::io; use std::io::Write; use std::str::FromStr; +use std::{fmt, io}; -use stacks_common::codec::Error as CodecError; - +use regex::{Captures, Regex}; use serde_json; +use stacks_common::codec::Error as CodecError; pub use crate::net::http::common::{ parse_bytes, parse_bytestream, parse_json, HttpReservedHeader, HttpVersion, diff --git a/stackslib/src/net/http/request.rs b/stackslib/src/net/http/request.rs index f9a0dd0d92..b0e2eab059 100644 --- a/stackslib/src/net/http/request.rs +++ b/stackslib/src/net/http/request.rs @@ -18,27 +18,22 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use std::io::{Read, Write}; use std::string::ToString; -use crate::net::http::common::HttpReservedHeader; -use crate::net::http::common::HTTP_PREAMBLE_MAX_ENCODED_SIZE; -use crate::net::http::common::HTTP_PREAMBLE_MAX_NUM_HEADERS; -use crate::net::http::{ - default_accept_header, write_headers, Error, HttpContentType, HttpResponseContents, - HttpResponsePreamble, HttpVersion, -}; - -use stacks_common::codec::{write_next, Error as CodecError, StacksMessageCodec}; -use stacks_common::types::net::PeerHost; - -use stacks_common::deps_common::httparse; - use percent_encoding::percent_decode_str; +use rand::{thread_rng, Rng}; use regex::{Captures, Regex}; +use serde_json; +use stacks_common::codec::{write_next, Error as CodecError, StacksMessageCodec}; +use stacks_common::deps_common::httparse; +use stacks_common::types::net::PeerHost; use url::form_urlencoded; -use rand::thread_rng; -use rand::Rng; - -use serde_json; +use crate::net::http::common::{ + HttpReservedHeader, HTTP_PREAMBLE_MAX_ENCODED_SIZE, HTTP_PREAMBLE_MAX_NUM_HEADERS, +}; +use crate::net::http::{ + default_accept_header, write_headers, Error, HttpContentType, HttpResponseContents, + HttpResponsePreamble, HttpVersion, +}; /// HTTP request preamble. This captures "control plane" data for an HTTP request, and contains /// everything of use to us from the HTTP requests's headers. diff --git a/stackslib/src/net/http/response.rs b/stackslib/src/net/http/response.rs index d8cf2a3d74..57a1afb2ce 100644 --- a/stackslib/src/net/http/response.rs +++ b/stackslib/src/net/http/response.rs @@ -20,23 +20,21 @@ use std::io::{Read, Write}; use std::ops::Deref; use std::time::SystemTime; -use crate::net::http::{ - common::{HttpReservedHeader, HTTP_PREAMBLE_MAX_ENCODED_SIZE, HTTP_PREAMBLE_MAX_NUM_HEADERS}, - request::{HttpRequestContents, HttpRequestPreamble}, - stream::HttpChunkGenerator, - write_headers, Error, HttpContentType, HttpVersion, -}; - use stacks_common::codec::{Error as CodecError, StacksMessageCodec}; - use stacks_common::deps_common::httparse; -use stacks_common::util::chunked_encoding::HttpChunkedTransferWriter; -use stacks_common::util::chunked_encoding::HttpChunkedTransferWriterState; +use stacks_common::util::chunked_encoding::{ + HttpChunkedTransferWriter, HttpChunkedTransferWriterState, +}; use stacks_common::util::hash::to_hex; use stacks_common::util::pipe::PipeWrite; +use {serde, serde_json}; -use serde; -use serde_json; +use crate::net::http::common::{ + HttpReservedHeader, HTTP_PREAMBLE_MAX_ENCODED_SIZE, HTTP_PREAMBLE_MAX_NUM_HEADERS, +}; +use crate::net::http::request::{HttpRequestContents, HttpRequestPreamble}; +use crate::net::http::stream::HttpChunkGenerator; +use crate::net::http::{write_headers, Error, HttpContentType, HttpVersion}; /// HTTP response preamble. This captures all HTTP header information, but in a way that /// certain fields that nodes rely on are guaranteed to have correct, sensible values. diff --git a/stackslib/src/net/http/stream.rs b/stackslib/src/net/http/stream.rs index c698b27384..08fe5a26c7 100644 --- a/stackslib/src/net/http/stream.rs +++ b/stackslib/src/net/http/stream.rs @@ -17,26 +17,20 @@ use std::io; use std::io::{Read, Write}; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::StacksBlockId; - -use crate::burnchains::Txid; -use crate::chainstate::stacks::{StacksBlock, StacksBlockHeader, StacksMicroblock}; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::Error as ChainstateError; - -use crate::util_lib::db::Error as DBError; - -use crate::core::mempool::{MemPoolDB, MemPoolSyncData}; - +use rand::{thread_rng, Rng}; +use stacks_common::types::chainstate::{BlockHeaderHash, StacksBlockId}; use stacks_common::util::chunked_encoding::{ HttpChunkedTransferWriter, HttpChunkedTransferWriterState, }; use stacks_common::util::pipe::PipeWrite; -use rand::thread_rng; -use rand::Rng; +use crate::burnchains::Txid; +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{ + Error as ChainstateError, StacksBlock, StacksBlockHeader, StacksMicroblock, +}; +use crate::core::mempool::{MemPoolDB, MemPoolSyncData}; +use crate::util_lib::db::Error as DBError; pub trait HttpChunkGenerator: Send { fn generate_next_chunk(&mut self) -> Result, String>; diff --git a/stackslib/src/net/http/tests.rs b/stackslib/src/net/http/tests.rs index f7c6f204f1..4a6ff91d81 100644 --- a/stackslib/src/net/http/tests.rs +++ b/stackslib/src/net/http/tests.rs @@ -14,18 +14,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::net::{PeerAddress, PeerHost}; + +use crate::net::http::common::{HTTP_PREAMBLE_MAX_ENCODED_SIZE, HTTP_PREAMBLE_MAX_NUM_HEADERS}; use crate::net::http::{ HttpContentType, HttpRequestPreamble, HttpReservedHeader, HttpResponsePreamble, HttpVersion, }; -use crate::net::http::common::HTTP_PREAMBLE_MAX_ENCODED_SIZE; -use crate::net::http::common::HTTP_PREAMBLE_MAX_NUM_HEADERS; - -use stacks_common::types::net::PeerAddress; -use stacks_common::types::net::PeerHost; - -use stacks_common::codec::StacksMessageCodec; - #[test] fn test_parse_reserved_header() { let tests = vec![ diff --git a/stackslib/src/net/httpcore.rs b/stackslib/src/net/httpcore.rs index dbdeefce1b..ae4db0c07f 100644 --- a/stackslib/src/net/httpcore.rs +++ b/stackslib/src/net/httpcore.rs @@ -14,59 +14,43 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::burnchains::Txid; -use crate::chainstate::burn::db::sortdb::SortitionDB; -use crate::chainstate::burn::BlockSnapshot; -use crate::chainstate::stacks::db::blocks::StagingBlock; -use crate::chainstate::stacks::db::StacksChainState; -use crate::core::MemPoolDB; -use crate::core::StacksEpoch; -use crate::net::connection::ConnectionOptions; -use crate::net::http::{ - common::HTTP_PREAMBLE_MAX_ENCODED_SIZE, http_reason, Error as HttpError, HttpBadRequest, - HttpContentType, HttpErrorResponse, HttpNotFound, HttpRequest, HttpRequestContents, - HttpRequestPreamble, HttpResponse, HttpResponseContents, HttpResponsePayload, - HttpResponsePreamble, HttpServerError, HttpVersion, -}; -use crate::net::p2p::PeerNetwork; -use crate::net::server::HttpPeer; -use crate::net::Error as NetError; -use crate::net::MessageSequence; -use crate::net::ProtocolFamily; -use crate::net::StacksNodeState; -use crate::net::UrlString; /// This module binds the http library to Stacks as a `ProtocolFamily` implementation use std::collections::{BTreeMap, HashMap}; -use std::fmt; -use std::io; use std::io::{Read, Write}; -use std::mem; use std::net::SocketAddr; +use std::{fmt, io, mem}; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::types::{QualifiedContractIdentifier, BOUND_VALUE_SERIALIZATION_HEX}; +use clarity::vm::{ClarityName, ContractName}; +use percent_encoding::percent_decode_str; use regex::{Captures, Regex}; - -use url::Url; - -use stacks_common::codec::read_next; -use stacks_common::codec::Error as CodecError; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::MAX_MESSAGE_LEN; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPublicKey; +use stacks_common::codec::{read_next, Error as CodecError, StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::types::chainstate::{ + ConsensusHash, StacksAddress, StacksBlockId, StacksPublicKey, +}; use stacks_common::types::net::PeerHost; use stacks_common::types::Address; use stacks_common::util::chunked_encoding::*; use stacks_common::util::retry::{BoundReader, RetryReader}; +use url::Url; -use clarity::vm::costs::ExecutionCost; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::BOUND_VALUE_SERIALIZATION_HEX; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; - -use percent_encoding::percent_decode_str; +use crate::burnchains::Txid; +use crate::chainstate::burn::db::sortdb::SortitionDB; +use crate::chainstate::burn::BlockSnapshot; +use crate::chainstate::stacks::db::blocks::StagingBlock; +use crate::chainstate::stacks::db::StacksChainState; +use crate::core::{MemPoolDB, StacksEpoch}; +use crate::net::connection::ConnectionOptions; +use crate::net::http::common::HTTP_PREAMBLE_MAX_ENCODED_SIZE; +use crate::net::http::{ + http_reason, Error as HttpError, HttpBadRequest, HttpContentType, HttpErrorResponse, + HttpNotFound, HttpRequest, HttpRequestContents, HttpRequestPreamble, HttpResponse, + HttpResponseContents, HttpResponsePayload, HttpResponsePreamble, HttpServerError, HttpVersion, +}; +use crate::net::p2p::PeerNetwork; +use crate::net::server::HttpPeer; +use crate::net::{Error as NetError, MessageSequence, ProtocolFamily, StacksNodeState, UrlString}; const CHUNK_BUF_LEN: usize = 32768; diff --git a/stackslib/src/net/inv.rs b/stackslib/src/net/inv.rs index ceb08d1dd0..6a3bee20c0 100644 --- a/stackslib/src/net/inv.rs +++ b/stackslib/src/net/inv.rs @@ -15,54 +15,37 @@ // along with this program. If not, see . use std::cmp; -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::collections::HashSet; +use std::collections::{BTreeMap, HashMap, HashSet}; use std::convert::TryFrom; -use std::io::Read; -use std::io::Write; +use std::io::{Read, Write}; use std::net::SocketAddr; use rand; use rand::seq::SliceRandom; -use rand::thread_rng; -use rand::Rng; +use rand::{thread_rng, Rng}; +use stacks_common::types::chainstate::{BlockHeaderHash, PoxId, SortitionId}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs, log}; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainView; +use crate::burnchains::{Burnchain, BurnchainView}; use crate::chainstate::burn::db::sortdb::{ BlockHeaderCache, SortitionDB, SortitionDBConn, SortitionHandleConn, }; -use crate::chainstate::burn::BlockSnapshot; +use crate::chainstate::burn::{BlockSnapshot, ConsensusHashExtensions}; use crate::chainstate::stacks::db::StacksChainState; use crate::net::asn::ASEntry4; use crate::net::chat::ConversationP2P; use crate::net::codec::*; -use crate::net::connection::ConnectionOptions; -use crate::net::connection::ConnectionP2P; -use crate::net::connection::ReplyHandleP2P; -use crate::net::db::PeerDB; -use crate::net::db::*; +use crate::net::connection::{ConnectionOptions, ConnectionP2P, ReplyHandleP2P}; +use crate::net::db::{PeerDB, *}; use crate::net::neighbors::MAX_NEIGHBOR_BLOCK_DELAY; use crate::net::p2p::PeerNetwork; -use crate::net::Error as net_error; -use crate::net::GetBlocksInv; -use crate::net::Neighbor; -use crate::net::NeighborKey; -use crate::net::StacksMessage; -use crate::net::StacksP2P; -use crate::net::*; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use crate::chainstate::burn::ConsensusHashExtensions; -use stacks_common::types::chainstate::{BlockHeaderHash, PoxId, SortitionId}; +use crate::net::{ + Error as net_error, GetBlocksInv, Neighbor, NeighborKey, PeerAddress, StacksMessage, StacksP2P, + *, +}; +use crate::util_lib::db::{DBConn, Error as db_error}; /// This module is responsible for synchronizing block inventories with other peers #[cfg(not(test))] @@ -2647,20 +2630,18 @@ impl PeerNetwork { mod test { use std::collections::HashMap; - use crate::burnchains::PoxConstants; - use crate::chainstate::stacks::*; - use crate::net::test::*; - use crate::net::*; - use crate::util_lib::test::*; + use stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; use super::*; - use crate::burnchains::bitcoin::indexer::BitcoinIndexer; use crate::burnchains::db::BurnchainHeaderReader; use crate::burnchains::tests::BURNCHAIN_TEST_BLOCK_TIME; - use crate::burnchains::BurnchainBlockHeader; + use crate::burnchains::{BurnchainBlockHeader, PoxConstants}; use crate::chainstate::coordinator::tests::get_burnchain; - use stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; + use crate::chainstate::stacks::*; + use crate::net::test::*; + use crate::net::*; + use crate::util_lib::test::*; #[test] fn peerblocksinv_has_ith_block() { diff --git a/stackslib/src/net/mod.rs b/stackslib/src/net/mod.rs index 564e346c4f..188a4bca31 100644 --- a/stackslib/src/net/mod.rs +++ b/stackslib/src/net/mod.rs @@ -17,100 +17,80 @@ use std::borrow::Borrow; use std::cmp::PartialEq; use std::collections::{HashMap, HashSet}; -use std::convert::From; -use std::convert::TryFrom; -use std::error; -use std::fmt; -use std::hash::Hash; -use std::hash::Hasher; -use std::io; +use std::convert::{From, TryFrom}; +use std::hash::{Hash, Hasher}; use std::io::prelude::*; use std::io::{Read, Write}; -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::Ipv6Addr; -use std::net::SocketAddr; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; use std::ops::Deref; use std::str::FromStr; +use std::{error, fmt, io}; -use rand::thread_rng; -use rand::RngCore; +use clarity::vm::analysis::contract_interface_builder::ContractInterface; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::types::{ + PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, TraitIdentifier, +}; +use clarity::vm::{ClarityName, ContractName, Value}; +use libstackerdb::{ + Error as libstackerdb_error, SlotMetadata, StackerDBChunkAckData, StackerDBChunkData, +}; +use rand::{thread_rng, RngCore}; use regex::Regex; -use rusqlite; use rusqlite::types::ToSqlOutput; use rusqlite::ToSql; use serde::de::Error as de_Error; use serde::ser::Error as ser_Error; use serde::{Deserialize, Serialize}; -use serde_json; -use url; +use stacks_common::codec::{ + read_next, write_next, Error as codec_error, StacksMessageCodec, + BURNCHAIN_HEADER_HASH_ENCODED_SIZE, +}; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, PoxId, StacksAddress, StacksBlockId, +}; +use stacks_common::types::net::{Error as AddrError, PeerAddress, PeerHost}; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::hash::{ + hex_bytes, to_hex, Hash160, Sha256Sum, DOUBLE_SHA256_ENCODED_SIZE, HASH160_ENCODED_SIZE, +}; +use stacks_common::util::secp256k1::{ + MessageSignature, Secp256k1PublicKey, MESSAGE_SIGNATURE_ENCODED_SIZE, +}; +use stacks_common::util::{get_epoch_time_secs, log}; +use {rusqlite, serde_json, url}; use crate::burnchains::affirmation::AffirmationMap; -use crate::burnchains::Burnchain; -use crate::burnchains::Error as burnchain_error; -use crate::burnchains::Txid; +use crate::burnchains::{Error as burnchain_error, Txid}; +use crate::chainstate::burn::db::sortdb::SortitionDB; use crate::chainstate::burn::ConsensusHash; use crate::chainstate::coordinator::Error as coordinator_error; use crate::chainstate::stacks::db::blocks::MemPoolRejection; +use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::index::Error as marf_error; -use crate::chainstate::stacks::Error as chainstate_error; use crate::chainstate::stacks::{ - Error as chain_error, StacksBlock, StacksMicroblock, StacksPublicKey, StacksTransaction, - TransactionPayload, + Error as chainstate_error, Error as chain_error, StacksBlock, StacksBlockHeader, + StacksMicroblock, StacksPublicKey, StacksTransaction, TransactionPayload, }; use crate::clarity_vm::clarity::Error as clarity_error; -use crate::core::POX_REWARD_CYCLE_LENGTH; +use crate::core::mempool::*; +use crate::core::{StacksEpoch, POX_REWARD_CYCLE_LENGTH}; +use crate::cost_estimates::metrics::CostMetric; +use crate::cost_estimates::{CostEstimator, FeeEstimator, FeeRateEstimate}; use crate::net::atlas::{Attachment, AttachmentInstance}; -use crate::net::httpcore::TipRequest; +use crate::net::dns::*; +use crate::net::http::error::{HttpNotFound, HttpServerError}; +use crate::net::http::{ + Error as HttpErr, HttpRequestContents, HttpRequestPreamble, HttpResponsePreamble, +}; +use crate::net::httpcore::{ + HttpRequestContentsExtensions, StacksHttp, StacksHttpRequest, StacksHttpResponse, TipRequest, +}; +use crate::net::p2p::PeerNetwork; use crate::util_lib::bloom::{BloomFilter, BloomNodeHasher}; use crate::util_lib::boot::boot_code_tx_auth; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; +use crate::util_lib::db::{DBConn, Error as db_error}; use crate::util_lib::strings::UrlString; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; -use clarity::vm::types::TraitIdentifier; -use clarity::vm::{ - analysis::contract_interface_builder::ContractInterface, types::PrincipalData, ClarityName, - ContractName, Value, -}; -use stacks_common::codec::Error as codec_error; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::BURNCHAIN_HEADER_HASH_ENCODED_SIZE; -use stacks_common::codec::{read_next, write_next}; -use stacks_common::types::net::{Error as AddrError, PeerAddress, PeerHost}; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::DOUBLE_SHA256_ENCODED_SIZE; -use stacks_common::util::hash::HASH160_ENCODED_SIZE; -use stacks_common::util::hash::{hex_bytes, to_hex}; -use stacks_common::util::log; -use stacks_common::util::secp256k1::MessageSignature; -use stacks_common::util::secp256k1::Secp256k1PublicKey; -use stacks_common::util::secp256k1::MESSAGE_SIGNATURE_ENCODED_SIZE; - -use crate::chainstate::stacks::StacksBlockHeader; - -use crate::cost_estimates::FeeRateEstimate; -use clarity::vm::costs::ExecutionCost; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::PoxId; -use stacks_common::types::chainstate::{BurnchainHeaderHash, StacksAddress, StacksBlockId}; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::hash::Sha256Sum; - -use crate::net::dns::*; -use crate::net::http::{HttpContentType, HttpNotFound, HttpServerError}; -pub use crate::net::httpcore::StacksHttp; - -use crate::cost_estimates::{metrics::CostMetric, CostEstimator, FeeEstimator}; - -use crate::core::mempool::{MemPoolDB, MemPoolEventDispatcher}; -use crate::core::StacksEpoch; - -use libstackerdb::{ - Error as libstackerdb_error, SlotMetadata, StackerDBChunkAckData, StackerDBChunkData, -}; /// Implements RPC API pub mod api; @@ -153,20 +133,8 @@ pub mod rpc; pub mod server; pub mod stackerdb; -use crate::net::stackerdb::StackerDBConfig; -use crate::net::stackerdb::StackerDBSync; -use crate::net::stackerdb::StackerDBSyncResult; -use crate::net::stackerdb::StackerDBs; - pub use crate::net::neighbors::{NeighborComms, PeerNetworkComms}; - -use crate::chainstate::burn::db::sortdb::SortitionDB; -use crate::chainstate::stacks::db::StacksChainState; -use crate::net::p2p::PeerNetwork; - -use crate::net::httpcore::{HttpRequestContentsExtensions, StacksHttpRequest, StacksHttpResponse}; - -use crate::net::http::{Error as HttpErr, HttpRequestContents, HttpRequestPreamble}; +use crate::net::stackerdb::{StackerDBConfig, StackerDBSync, StackerDBSyncResult, StackerDBs}; #[cfg(test)] pub mod tests; @@ -1565,30 +1533,40 @@ pub trait Requestable: std::fmt::Display { #[cfg(test)] pub mod test { - use std::fs; - use std::io; - use std::io::Cursor; - use std::io::ErrorKind; - use std::io::Read; - use std::io::Write; + use std::collections::HashMap; + use std::io::{Cursor, ErrorKind, Read, Write}; use std::net::*; - use std::ops::Deref; - use std::ops::DerefMut; + use std::ops::{Deref, DerefMut}; use std::sync::mpsc::sync_channel; - use std::thread; - use std::{collections::HashMap, sync::Mutex}; + use std::sync::Mutex; + use std::{fs, io, thread}; use clarity::vm::ast::ASTRules; - use mio; - use rand; + use clarity::vm::costs::ExecutionCost; + use clarity::vm::database::STXBalance; + use clarity::vm::types::*; + use clarity::vm::ClarityVersion; use rand::RngCore; + use stacks_common::address::*; + use stacks_common::codec::StacksMessageCodec; + use stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; + use stacks_common::types::chainstate::TrieHash; + use stacks_common::types::StacksEpochId; + use stacks_common::util::get_epoch_time_secs; + use stacks_common::util::hash::*; + use stacks_common::util::secp256k1::*; + use stacks_common::util::uint::*; + use stacks_common::util::vrf::*; + use {mio, rand}; + use super::*; use crate::burnchains::bitcoin::address::*; use crate::burnchains::bitcoin::indexer::BitcoinIndexer; use crate::burnchains::bitcoin::keys::*; + use crate::burnchains::bitcoin::spv::BITCOIN_GENESIS_BLOCK_HASH_REGTEST; use crate::burnchains::bitcoin::*; use crate::burnchains::burnchain::*; - use crate::burnchains::db::BurnchainDB; + use crate::burnchains::db::{BurnchainDB, BurnchainHeaderReader}; use crate::burnchains::tests::*; use crate::burnchains::*; use crate::chainstate::burn::db::sortdb; @@ -1598,15 +1576,17 @@ pub mod test { use crate::chainstate::coordinator::tests::*; use crate::chainstate::coordinator::*; use crate::chainstate::stacks::address::PoxAddress; + use crate::chainstate::stacks::boot::test::get_parent_tip; use crate::chainstate::stacks::boot::*; - use crate::chainstate::stacks::db::StacksChainState; - use crate::chainstate::stacks::db::*; + use crate::chainstate::stacks::db::accounts::MinerReward; + use crate::chainstate::stacks::db::{StacksChainState, *}; + use crate::chainstate::stacks::events::StacksTransactionReceipt; use crate::chainstate::stacks::miner::*; use crate::chainstate::stacks::tests::chain_histories::mine_smart_contract_block_contract_call_microblock; use crate::chainstate::stacks::tests::*; - use crate::chainstate::stacks::*; + use crate::chainstate::stacks::{StacksMicroblockHeader, *}; use crate::chainstate::*; - use crate::core::NETWORK_P2P_PORT; + use crate::core::{StacksEpochExtension, NETWORK_P2P_PORT}; use crate::net::asn::*; use crate::net::atlas::*; use crate::net::chat::*; @@ -1618,35 +1598,8 @@ pub mod test { use crate::net::poll::*; use crate::net::relay::*; use crate::net::Error as net_error; - use crate::net::RPCHandlerArgs; - use crate::util_lib::strings::*; - use clarity::vm::costs::ExecutionCost; - use clarity::vm::database::STXBalance; - use clarity::vm::types::*; - use clarity::vm::ClarityVersion; - use stacks_common::address::*; - use stacks_common::address::*; - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::hash::*; - use stacks_common::util::secp256k1::*; - use stacks_common::util::uint::*; - use stacks_common::util::vrf::*; - - use stacks_common::deps_common::bitcoin::network::serialize::BitcoinHash; - - use super::*; - use crate::chainstate::stacks::boot::test::get_parent_tip; - use crate::chainstate::stacks::StacksMicroblockHeader; - use crate::chainstate::stacks::{db::accounts::MinerReward, events::StacksTransactionReceipt}; - use crate::core::StacksEpochExtension; use crate::util_lib::boot::boot_code_test_addr; - use stacks_common::codec::StacksMessageCodec; - use stacks_common::types::chainstate::TrieHash; - use stacks_common::types::StacksEpochId; - - use crate::burnchains::bitcoin::spv::BITCOIN_GENESIS_BLOCK_HASH_REGTEST; - - use crate::burnchains::db::BurnchainHeaderReader; + use crate::util_lib::strings::*; impl StacksMessageCodec for BlockstackOperationType { fn consensus_serialize(&self, fd: &mut W) -> Result<(), codec_error> { diff --git a/stackslib/src/net/neighbors/comms.rs b/stackslib/src/net/neighbors/comms.rs index 92b2a75edb..75ea4c2ab6 100644 --- a/stackslib/src/net/neighbors/comms.rs +++ b/stackslib/src/net/neighbors/comms.rs @@ -14,35 +14,28 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::core::PEER_VERSION_TESTNET; +use std::collections::{HashMap, HashSet}; +use std::{cmp, mem}; +use stacks_common::types::chainstate::StacksPublicKey; +use stacks_common::util::hash::Hash160; +use stacks_common::util::log; +use stacks_common::util::secp256k1::Secp256k1PublicKey; + +use crate::burnchains::{Address, PublicKey}; +use crate::core::PEER_VERSION_TESTNET; +use crate::net::connection::{ConnectionOptions, ReplyHandleP2P}; +use crate::net::db::{LocalPeer, PeerDB}; +use crate::net::neighbors::{ + NeighborWalk, NeighborWalkDB, NeighborWalkResult, MAX_NEIGHBOR_BLOCK_DELAY, + NEIGHBOR_MINIMUM_CONTACT_INTERVAL, +}; +use crate::net::p2p::PeerNetwork; use crate::net::{ - connection::{ConnectionOptions, ReplyHandleP2P}, - db::{LocalPeer, PeerDB}, - neighbors::{ - NeighborWalk, NeighborWalkDB, NeighborWalkResult, MAX_NEIGHBOR_BLOCK_DELAY, - NEIGHBOR_MINIMUM_CONTACT_INTERVAL, - }, - p2p::PeerNetwork, Error as net_error, HandshakeData, Neighbor, NeighborAddress, NeighborKey, PeerAddress, StacksMessage, StacksMessageType, NUM_NEIGHBORS, }; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use std::cmp; -use std::mem; - -use std::collections::HashMap; -use std::collections::HashSet; - -use crate::burnchains::Address; -use crate::burnchains::PublicKey; - -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::util::hash::Hash160; -use stacks_common::util::log; - /// A trait for representing session state for a set of connected neighbors, for the purposes of executing some P2P /// algorithm. pub trait NeighborComms { diff --git a/stackslib/src/net/neighbors/db.rs b/stackslib/src/net/neighbors/db.rs index d3afce27a1..fd85f0ce1f 100644 --- a/stackslib/src/net/neighbors/db.rs +++ b/stackslib/src/net/neighbors/db.rs @@ -14,35 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::net::db::PeerDB; +use std::collections::{HashMap, HashSet}; +use std::{cmp, mem}; + +use rand::prelude::*; +use rand::thread_rng; +use stacks_common::util::hash::Hash160; +use stacks_common::util::{get_epoch_time_secs, log}; +use crate::burnchains::{Address, Burnchain, BurnchainView}; +use crate::net::db::PeerDB; +use crate::net::neighbors::{NeighborWalkResult, NEIGHBOR_MINIMUM_CONTACT_INTERVAL, NUM_NEIGHBORS}; +use crate::net::p2p::PeerNetwork; use crate::net::{ Error as net_error, HandshakeAcceptData, HandshakeData, Neighbor, NeighborAddress, NeighborKey, Preamble, StackerDBHandshakeData, StacksMessage, }; - -use crate::net::neighbors::{NeighborWalkResult, NEIGHBOR_MINIMUM_CONTACT_INTERVAL, NUM_NEIGHBORS}; - -use crate::net::p2p::PeerNetwork; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::DBTx; - -use std::cmp; -use std::mem; - -use std::collections::HashMap; -use std::collections::HashSet; - -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainView; - -use rand::prelude::*; -use rand::thread_rng; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::Hash160; -use stacks_common::util::log; +use crate::util_lib::db::{DBConn, DBTx}; /// Capture replacement state #[derive(Debug, Clone, PartialEq)] diff --git a/stackslib/src/net/neighbors/mod.rs b/stackslib/src/net/neighbors/mod.rs index fb276df643..031e9f91a5 100644 --- a/stackslib/src/net/neighbors/mod.rs +++ b/stackslib/src/net/neighbors/mod.rs @@ -14,43 +14,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::net::db::PeerDB; -use crate::net::Error as net_error; -use crate::net::Neighbor; -use crate::net::NeighborKey; - -use crate::net::codec::*; -use crate::net::*; - -use crate::net::connection::ConnectionOptions; -use crate::net::connection::ReplyHandleP2P; - -use crate::net::db::LocalPeer; - -use crate::net::p2p::PeerNetwork; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::DBTx; -use crate::util_lib::db::Error as db_error; - -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use std::cmp; -use std::mem; +use std::collections::{HashMap, HashSet}; use std::net::SocketAddr; - -use std::collections::HashMap; -use std::collections::HashSet; - -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainView; -use crate::burnchains::PublicKey; +use std::{cmp, mem}; use rand::prelude::*; use rand::thread_rng; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::log; +use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::{get_epoch_time_secs, log}; + +use crate::burnchains::{Address, Burnchain, BurnchainView, PublicKey}; +use crate::net::codec::*; +use crate::net::connection::{ConnectionOptions, ReplyHandleP2P}; +use crate::net::db::{LocalPeer, PeerDB}; +use crate::net::p2p::PeerNetwork; +use crate::net::{Error as net_error, Neighbor, NeighborKey, PeerAddress, *}; +use crate::util_lib::db::{DBConn, DBTx, Error as db_error}; pub mod comms; pub mod db; diff --git a/stackslib/src/net/neighbors/neighbor.rs b/stackslib/src/net/neighbors/neighbor.rs index 733e0edd8c..a1d513daa2 100644 --- a/stackslib/src/net/neighbors/neighbor.rs +++ b/stackslib/src/net/neighbors/neighbor.rs @@ -14,25 +14,20 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::net::{db::PeerDB, Error as net_error, Neighbor, NeighborAddress, NeighborKey}; - -use crate::util_lib::db::{DBConn, DBTx}; - -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::util::hash::Hash160; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - use std::cmp; -use crate::burnchains::Address; -use crate::burnchains::PublicKey; - +use clarity::vm::types::QualifiedContractIdentifier; use rand::prelude::*; use rand::thread_rng; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::log; +use stacks_common::types::chainstate::StacksPublicKey; +use stacks_common::util::hash::Hash160; +use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::{get_epoch_time_secs, log}; -use clarity::vm::types::QualifiedContractIdentifier; +use crate::burnchains::{Address, PublicKey}; +use crate::net::db::PeerDB; +use crate::net::{Error as net_error, Neighbor, NeighborAddress, NeighborKey}; +use crate::util_lib::db::{DBConn, DBTx}; /// Walk-specific helper functions for neighbors impl Neighbor { diff --git a/stackslib/src/net/neighbors/walk.rs b/stackslib/src/net/neighbors/walk.rs index ea31f4b835..5cbda3c774 100644 --- a/stackslib/src/net/neighbors/walk.rs +++ b/stackslib/src/net/neighbors/walk.rs @@ -14,46 +14,30 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::net::db::PeerDB; +use std::collections::{HashMap, HashSet}; +use std::{cmp, mem}; +use rand::prelude::*; +use rand::thread_rng; +use stacks_common::types::chainstate::StacksPublicKey; +use stacks_common::util::hash::Hash160; +use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::{get_epoch_time_secs, log}; + +use crate::burnchains::{Address, Burnchain, BurnchainView, PublicKey}; +use crate::net::connection::{ConnectionOptions, ReplyHandleP2P}; +use crate::net::db::{LocalPeer, PeerDB}; +use crate::net::neighbors::{ + NeighborComms, NeighborCommsRequest, NeighborReplacements, NeighborWalkDB, ToNeighborKey, + MAX_NEIGHBOR_BLOCK_DELAY, NEIGHBOR_MINIMUM_CONTACT_INTERVAL, +}; +use crate::net::p2p::PeerNetwork; use crate::net::{ - neighbors::{ - NeighborComms, NeighborReplacements, NeighborWalkDB, ToNeighborKey, - MAX_NEIGHBOR_BLOCK_DELAY, NEIGHBOR_MINIMUM_CONTACT_INTERVAL, - }, Error as net_error, HandshakeAcceptData, HandshakeData, MessageSequence, Neighbor, NeighborAddress, NeighborKey, PeerAddress, Preamble, StackerDBHandshakeData, StacksMessage, StacksMessageType, NUM_NEIGHBORS, }; -use crate::net::neighbors::NeighborCommsRequest; - -use crate::net::connection::ConnectionOptions; -use crate::net::connection::ReplyHandleP2P; - -use crate::net::db::LocalPeer; -use crate::net::p2p::PeerNetwork; - -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use std::cmp; -use std::mem; - -use std::collections::HashMap; -use std::collections::HashSet; - -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainView; -use crate::burnchains::PublicKey; - -use rand::prelude::*; -use rand::thread_rng; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::Hash160; -use stacks_common::util::log; - /// This struct records information from an inbound peer that has authenticated to this node. As /// new remote nodes connect, this node will remember this state for them so that the neighbor walk /// logic can try to ask them for neighbors. This enables a public peer to ask a NAT'ed peer for diff --git a/stackslib/src/net/p2p.rs b/stackslib/src/net/p2p.rs index e0d9528695..0de77c4ff2 100644 --- a/stackslib/src/net/p2p.rs +++ b/stackslib/src/net/p2p.rs @@ -14,37 +14,29 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::cmp; use std::cmp::Ordering; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::mem; -use std::net::IpAddr; -use std::net::Ipv4Addr; -use std::net::Ipv6Addr; -use std::net::SocketAddr; -use std::sync::mpsc::sync_channel; -use std::sync::mpsc::Receiver; -use std::sync::mpsc::RecvError; -use std::sync::mpsc::SendError; -use std::sync::mpsc::SyncSender; -use std::sync::mpsc::TryRecvError; -use std::sync::mpsc::TrySendError; - -use mio; +use std::collections::{HashMap, HashSet, VecDeque}; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; +use std::sync::mpsc::{ + sync_channel, Receiver, RecvError, SendError, SyncSender, TryRecvError, TrySendError, +}; +use std::{cmp, mem}; + +use clarity::vm::ast::ASTRules; +use clarity::vm::database::BurnStateDB; +use clarity::vm::types::QualifiedContractIdentifier; use mio::net as mio_net; use rand::prelude::*; use rand::thread_rng; +use stacks_common::types::chainstate::{PoxId, SortitionId}; +use stacks_common::types::net::{PeerAddress, PeerHost}; +use stacks_common::util::hash::to_hex; +use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs, log}; +use {mio, url}; -use url; - -use crate::burnchains::db::BurnchainDB; -use crate::burnchains::db::BurnchainHeaderReader; -use crate::burnchains::Address; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainView; -use crate::burnchains::PublicKey; +use crate::burnchains::db::{BurnchainDB, BurnchainHeaderReader}; +use crate::burnchains::{Address, Burnchain, BurnchainView, PublicKey}; use crate::chainstate::burn::db::sortdb::{BlockHeaderCache, SortitionDB}; use crate::chainstate::burn::BlockSnapshot; use crate::chainstate::coordinator::{ @@ -52,55 +44,25 @@ use crate::chainstate::coordinator::{ static_get_stacks_tip_affirmation_map, }; use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::{MAX_BLOCK_LEN, MAX_TRANSACTION_LEN}; -use crate::core::mempool::{MemPoolDB, MemPoolEventDispatcher}; +use crate::chainstate::stacks::{StacksBlockHeader, MAX_BLOCK_LEN, MAX_TRANSACTION_LEN}; use crate::monitoring::{update_inbound_neighbors, update_outbound_neighbors}; use crate::net::asn::ASEntry4; -use crate::net::atlas::AtlasDB; -use crate::net::atlas::{AttachmentInstance, AttachmentsDownloader}; -use crate::net::chat::ConversationP2P; -use crate::net::chat::NeighborStats; -use crate::net::connection::ConnectionOptions; -use crate::net::connection::NetworkReplyHandle; -use crate::net::connection::ReplyHandleP2P; -use crate::net::db::LocalPeer; -use crate::net::db::PeerDB; +use crate::net::atlas::{AtlasDB, AttachmentInstance, AttachmentsDownloader}; +use crate::net::chat::{ConversationP2P, NeighborStats}; +use crate::net::connection::{ConnectionOptions, NetworkReplyHandle, ReplyHandleP2P}; +use crate::net::db::{LocalPeer, PeerDB}; use crate::net::download::BlockDownloader; +use crate::net::http::HttpRequestContents; +use crate::net::httpcore::StacksHttpRequest; use crate::net::inv::*; use crate::net::neighbors::*; -use crate::net::poll::NetworkPollState; -use crate::net::poll::NetworkState; +use crate::net::poll::{NetworkPollState, NetworkState}; use crate::net::prune::*; -use crate::net::relay::RelayerStats; -use crate::net::relay::*; +use crate::net::relay::{RelayerStats, *, *}; use crate::net::server::*; use crate::net::stackerdb::{StackerDBConfig, StackerDBSync, StackerDBTx, StackerDBs}; -use crate::net::Error as net_error; -use crate::net::Neighbor; -use crate::net::NeighborKey; -use crate::net::RPCHandlerArgs; -use crate::net::*; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::DBTx; -use crate::util_lib::db::Error as db_error; -use clarity::vm::database::BurnStateDB; -use stacks_common::types::net::PeerAddress; -use stacks_common::types::net::PeerHost; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::to_hex; -use stacks_common::util::log; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use crate::chainstate::stacks::StacksBlockHeader; -use stacks_common::types::chainstate::{PoxId, SortitionId}; - -use clarity::vm::ast::ASTRules; -use clarity::vm::types::QualifiedContractIdentifier; - -use crate::net::httpcore::StacksHttpRequest; - -use crate::net::http::HttpRequestContents; +use crate::net::{Error as net_error, Neighbor, NeighborKey, RPCHandlerArgs, *}; +use crate::util_lib::db::{DBConn, DBTx, Error as db_error}; /// inter-thread request to send a p2p message from another thread in this program. #[derive(Debug)] @@ -5778,12 +5740,18 @@ impl PeerNetwork { #[cfg(test)] mod test { - use std::thread; - use std::time; + use std::{thread, time}; + use clarity::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; + use clarity::vm::types::StacksAddressExtensions; + use clarity::vm::MAX_CALL_STACK_DEPTH; use rand; use rand::RngCore; + use stacks_common::types::chainstate::BurnchainHeaderHash; + use stacks_common::util::secp256k1::Secp256k1PrivateKey; + use stacks_common::util::{log, sleep_ms}; + use super::*; use crate::burnchains::burnchain::*; use crate::burnchains::*; use crate::chainstate::stacks::test::*; @@ -5796,16 +5764,6 @@ mod test { use crate::net::test::*; use crate::net::*; use crate::util_lib::test::*; - use clarity::vm::types::StacksAddressExtensions; - use stacks_common::types::chainstate::BurnchainHeaderHash; - use stacks_common::util::log; - use stacks_common::util::secp256k1::Secp256k1PrivateKey; - use stacks_common::util::sleep_ms; - - use clarity::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; - use clarity::vm::MAX_CALL_STACK_DEPTH; - - use super::*; fn make_random_peer_address() -> PeerAddress { let mut rng = rand::thread_rng(); diff --git a/stackslib/src/net/poll.rs b/stackslib/src/net/poll.rs index 00ee4095de..5941741bc1 100644 --- a/stackslib/src/net/poll.rs +++ b/stackslib/src/net/poll.rs @@ -14,38 +14,20 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::net::Error as net_error; -use crate::net::Neighbor; -use crate::net::NeighborKey; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; - -use std::collections::HashMap; -use std::collections::HashSet; -use std::io; -use std::io::Error as io_error; -use std::io::ErrorKind; -use std::io::Read; -use std::io::Write; -use std::net; -use std::net::SocketAddr; -use std::time; +use std::collections::{HashMap, HashSet}; +use std::io::{Error as io_error, ErrorKind, Read, Write}; +use std::net::{Shutdown, SocketAddr}; use std::time::Duration; +use std::{io, net, time}; -use stacks_common::util::log; -use stacks_common::util::sleep_ms; - -use mio; -use mio::net as mio_net; -use mio::PollOpt; -use mio::Ready; -use mio::Token; - -use std::net::Shutdown; - -use rand; +use mio::{net as mio_net, PollOpt, Ready, Token}; use rand::RngCore; +use stacks_common::types::net::PeerAddress; +use stacks_common::util::{log, sleep_ms}; +use {mio, rand}; + +use crate::net::{Error as net_error, Neighbor, NeighborKey}; +use crate::util_lib::db::{DBConn, Error as db_error}; const SERVER: Token = mio::Token(0); @@ -497,14 +479,12 @@ impl NetworkState { #[cfg(test)] mod test { - use super::*; + use std::collections::HashSet; + use mio; - use mio::net as mio_net; - use mio::PollOpt; - use mio::Ready; - use mio::Token; + use mio::{net as mio_net, PollOpt, Ready, Token}; - use std::collections::HashSet; + use super::*; #[test] fn test_bind() { diff --git a/stackslib/src/net/prune.rs b/stackslib/src/net/prune.rs index 214bfe2582..b2b7ff6c32 100644 --- a/stackslib/src/net/prune.rs +++ b/stackslib/src/net/prune.rs @@ -14,40 +14,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::net::p2p::*; -/// This module contains the logic for pruning client and neighbor connections -use crate::net::*; - -use crate::net::Error as net_error; - -use crate::net::connection::ConnectionOptions; - -use crate::net::chat::NeighborStats; - -use crate::net::poll::NetworkPollState; -use crate::net::poll::NetworkState; - -use crate::net::db::LocalPeer; -use crate::net::db::PeerDB; - -use crate::net::neighbors::*; - -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; - -use std::net::Shutdown; -use std::net::SocketAddr; - use std::cmp::Ordering; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; - -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::log; +use std::collections::{HashMap, HashSet, VecDeque}; +use std::net::{Shutdown, SocketAddr}; use rand::prelude::*; use rand::thread_rng; +use stacks_common::types::net::PeerAddress; +use stacks_common::util::{get_epoch_time_secs, log}; + +use crate::net::chat::NeighborStats; +use crate::net::connection::ConnectionOptions; +use crate::net::db::{LocalPeer, PeerDB}; +use crate::net::neighbors::*; +use crate::net::p2p::*; +use crate::net::poll::{NetworkPollState, NetworkState}; +use crate::net::Error as net_error; +/// This module contains the logic for pruning client and neighbor connections +use crate::net::*; +use crate::util_lib::db::{DBConn, Error as db_error}; impl PeerNetwork { /// Find out which organizations have which of our outbound neighbors. diff --git a/stackslib/src/net/relay.rs b/stackslib/src/net/relay.rs index 194ffa9c75..eda4a543b9 100644 --- a/stackslib/src/net/relay.rs +++ b/stackslib/src/net/relay.rs @@ -14,58 +14,46 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::cmp; -use std::collections::BTreeMap; -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::mem; +use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; +use std::{cmp, mem}; +use clarity::vm::ast::errors::{ParseError, ParseErrors}; +use clarity::vm::ast::{ast_check_size, ASTRules}; +use clarity::vm::costs::ExecutionCost; +use clarity::vm::errors::RuntimeErrorType; +use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; +use clarity::vm::ClarityVersion; use rand::prelude::*; -use rand::thread_rng; -use rand::Rng; +use rand::{thread_rng, Rng}; +use stacks_common::codec::MAX_PAYLOAD_LEN; +use stacks_common::types::chainstate::{BurnchainHeaderHash, PoxId, SortitionId, StacksBlockId}; +use stacks_common::types::StacksEpochId; +use stacks_common::util::get_epoch_time_secs; +use stacks_common::util::hash::Sha512Trunc256Sum; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainView; +use crate::burnchains::{Burnchain, BurnchainView}; use crate::chainstate::burn::db::sortdb::{SortitionDB, SortitionDBConn, SortitionHandleConn}; -use crate::chainstate::burn::BlockSnapshot; -use crate::chainstate::burn::ConsensusHash; +use crate::chainstate::burn::{BlockSnapshot, ConsensusHash}; use crate::chainstate::coordinator::comm::CoordinatorChannels; +use crate::chainstate::coordinator::BlockEventDispatcher; +use crate::chainstate::stacks::db::unconfirmed::ProcessedUnconfirmedState; use crate::chainstate::stacks::db::{StacksChainState, StacksEpochReceipt, StacksHeaderInfo}; use crate::chainstate::stacks::events::StacksTransactionReceipt; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::chainstate::stacks::TransactionPayload; +use crate::chainstate::stacks::{StacksBlockHeader, TransactionPayload}; use crate::clarity_vm::clarity::Error as clarity_error; -use crate::core::mempool::MemPoolDB; -use crate::core::mempool::*; +use crate::core::mempool::{MemPoolDB, *}; +use crate::monitoring::update_stacks_tip_height; use crate::net::chat::*; use crate::net::connection::*; use crate::net::db::*; +use crate::net::httpcore::*; use crate::net::p2p::*; use crate::net::poll::*; use crate::net::rpc::*; use crate::net::stackerdb::{ StackerDBConfig, StackerDBEventDispatcher, StackerDBSyncResult, StackerDBs, }; -use crate::net::Error as net_error; -use crate::net::*; -use clarity::vm::ast::errors::{ParseError, ParseErrors}; -use clarity::vm::ast::{ast_check_size, ASTRules}; -use clarity::vm::costs::ExecutionCost; -use clarity::vm::errors::RuntimeErrorType; -use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; -use clarity::vm::ClarityVersion; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::Sha512Trunc256Sum; - -use crate::chainstate::coordinator::BlockEventDispatcher; -use crate::chainstate::stacks::db::unconfirmed::ProcessedUnconfirmedState; -use crate::monitoring::update_stacks_tip_height; -use stacks_common::codec::MAX_PAYLOAD_LEN; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::{PoxId, SortitionId}; -use stacks_common::types::StacksEpochId; +use crate::net::{Error as net_error, *}; pub type BlocksAvailableMap = HashMap; @@ -2457,55 +2445,45 @@ pub mod test { use std::cell::RefCell; use std::collections::HashMap; + use clarity::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; + use clarity::vm::ast::ASTRules; + use clarity::vm::costs::LimitedCostTracker; + use clarity::vm::database::ClarityDatabase; + use clarity::vm::types::QualifiedContractIdentifier; + use clarity::vm::{ClarityVersion, MAX_CALL_STACK_DEPTH}; + use stacks_common::address::AddressHashMode; + use stacks_common::types::chainstate::{ + BlockHeaderHash, StacksBlockId, StacksWorkScore, TrieHash, + }; + use stacks_common::types::Address; + use stacks_common::util::hash::MerkleTree; + use stacks_common::util::sleep_ms; + use stacks_common::util::vrf::VRFProof; + + use super::*; use crate::burnchains::tests::TestMiner; - use crate::chainstate::stacks::db::blocks::MINIMUM_TX_FEE; - use crate::chainstate::stacks::db::blocks::MINIMUM_TX_FEE_RATE_PER_BYTE; - use crate::chainstate::stacks::Error as ChainstateError; - use crate::chainstate::stacks::*; + use crate::chainstate::stacks::db::blocks::{MINIMUM_TX_FEE, MINIMUM_TX_FEE_RATE_PER_BYTE}; + use crate::chainstate::stacks::miner::{BlockBuilderSettings, StacksMicroblockBuilder}; + use crate::chainstate::stacks::test::codec_all_transactions; + use crate::chainstate::stacks::tests::{ + make_coinbase, make_coinbase_with_nonce, make_smart_contract_with_version, + make_user_stacks_transfer, + }; + use crate::chainstate::stacks::{Error as ChainstateError, *}; + use crate::clarity_vm::clarity::ClarityConnection; + use crate::core::*; + use crate::net::api::getinfo::RPCPeerInfoData; use crate::net::asn::*; use crate::net::chat::*; use crate::net::codec::*; use crate::net::download::test::run_get_blocks_and_microblocks; use crate::net::download::*; use crate::net::http::{HttpRequestContents, HttpRequestPreamble}; + use crate::net::httpcore::StacksHttpMessage; use crate::net::inv::*; use crate::net::test::*; use crate::net::*; use crate::util_lib::test::*; - use clarity::vm::costs::LimitedCostTracker; - use clarity::vm::database::ClarityDatabase; - use stacks_common::util::sleep_ms; - use stacks_common::util::vrf::VRFProof; - - use super::*; - use crate::clarity_vm::clarity::ClarityConnection; - use crate::core::*; - use clarity::vm::types::QualifiedContractIdentifier; - use clarity::vm::ClarityVersion; - use stacks_common::types::chainstate::BlockHeaderHash; - - use clarity::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; - use clarity::vm::ast::ASTRules; - use clarity::vm::MAX_CALL_STACK_DEPTH; - - use crate::chainstate::stacks::miner::BlockBuilderSettings; - use crate::chainstate::stacks::miner::StacksMicroblockBuilder; - use crate::chainstate::stacks::test::codec_all_transactions; - use crate::chainstate::stacks::tests::make_coinbase; - use crate::chainstate::stacks::tests::make_coinbase_with_nonce; - use crate::chainstate::stacks::tests::make_smart_contract_with_version; - use crate::chainstate::stacks::tests::make_user_stacks_transfer; - use crate::core::*; - use stacks_common::address::AddressHashMode; - use stacks_common::types::chainstate::StacksBlockId; - use stacks_common::types::chainstate::StacksWorkScore; - use stacks_common::types::chainstate::TrieHash; - use stacks_common::types::Address; - use stacks_common::util::hash::MerkleTree; - - use crate::net::api::getinfo::RPCPeerInfoData; - - use crate::net::httpcore::StacksHttpMessage; #[test] fn test_relayer_stats_add_relyed_messages() { diff --git a/stackslib/src/net/rpc.rs b/stackslib/src/net/rpc.rs index e64a60cc84..f66e26a71a 100644 --- a/stackslib/src/net/rpc.rs +++ b/stackslib/src/net/rpc.rs @@ -14,128 +14,72 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::collections::HashMap; -use std::collections::HashSet; -use std::collections::VecDeque; -use std::io; +use std::collections::{HashMap, HashSet, VecDeque}; +use std::convert::TryFrom; use std::io::prelude::*; use std::io::{Read, Seek, SeekFrom, Write}; use std::net::SocketAddr; use std::time::Instant; -use std::{convert::TryFrom, fmt}; - +use std::{fmt, io}; + +use clarity::vm::analysis::errors::CheckErrors; +use clarity::vm::ast::ASTRules; +use clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; +use clarity::vm::database::clarity_store::{make_contract_hash_key, ContractCommitment}; +use clarity::vm::database::{ + BurnStateDB, ClarityDatabase, ClaritySerializable, STXBalance, StoreType, +}; +use clarity::vm::errors::Error::Unchecked; +use clarity::vm::errors::{Error as ClarityRuntimeError, InterpreterError}; +use clarity::vm::types::{ + PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, TraitIdentifier, +}; +use clarity::vm::{ClarityName, ClarityVersion, ContractName, SymbolicExpression, Value}; +use libstackerdb::{StackerDBChunkAckData, StackerDBChunkData}; use rand::prelude::*; use rand::thread_rng; use rusqlite::{DatabaseName, NO_PARAMS}; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, +}; +use stacks_common::types::net::{PeerAddress, PeerHost}; +use stacks_common::types::StacksPublicKeyBuffer; +use stacks_common::util::chunked_encoding::*; +use stacks_common::util::get_epoch_time_secs; +use stacks_common::util::hash::{hex_bytes, to_hex, Hash160, Sha256Sum}; +use stacks_common::util::secp256k1::MessageSignature; +use stacks_common::{types, util}; use crate::burnchains::affirmation::AffirmationMap; -use crate::burnchains::Burnchain; -use crate::burnchains::BurnchainView; -use crate::burnchains::*; +use crate::burnchains::{Burnchain, BurnchainView, *}; use crate::chainstate::burn::db::sortdb::SortitionDB; +use crate::chainstate::burn::operations::leader_block_commit::OUTPUTS_PER_COMMIT; use crate::chainstate::burn::ConsensusHash; -use crate::chainstate::stacks::db::blocks::CheckError; -use crate::chainstate::stacks::db::{blocks::MINIMUM_TX_FEE_RATE_PER_BYTE, StacksChainState}; -use crate::chainstate::stacks::Error as chain_error; -use crate::chainstate::stacks::*; -use crate::clarity_vm::clarity::ClarityConnection; +use crate::chainstate::stacks::boot::{POX_1_NAME, POX_2_NAME, POX_3_NAME}; +use crate::chainstate::stacks::db::blocks::{CheckError, MINIMUM_TX_FEE_RATE_PER_BYTE}; +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::{Error as chain_error, StacksBlockHeader, *}; +use crate::clarity_vm::clarity::{ClarityConnection, Error as clarity_error}; +use crate::clarity_vm::database::marf::MarfedKV; use crate::core::mempool::*; use crate::cost_estimates::metrics::CostMetric; -use crate::cost_estimates::CostEstimator; -use crate::cost_estimates::FeeEstimator; -use crate::monitoring; +use crate::cost_estimates::{CostEstimator, FeeEstimator}; use crate::net::atlas::{AtlasDB, Attachment, MAX_ATTACHMENT_INV_PAGES_PER_REQUEST}; -use crate::net::connection::ConnectionHttp; -use crate::net::connection::ConnectionOptions; -use crate::net::connection::ReplyHandleHttp; +use crate::net::connection::{ConnectionHttp, ConnectionOptions, ReplyHandleHttp}; use crate::net::db::PeerDB; - use crate::net::http::{HttpRequestContents, HttpResponseContents}; -use crate::net::PeerHostExtensions; -use crate::net::StacksNodeState; - use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpMessage, - StacksHttpRequest, StacksHttpResponse, TipRequest, HTTP_REQUEST_ID_RESERVED, -}; - -use crate::core::mempool::MemPoolSyncData; -use crate::net::api::{ - callreadonly::CallReadOnlyRequestBody, callreadonly::CallReadOnlyResponse, - getaccount::AccountEntryResponse, getconstantval::ConstantValResponse, - getcontractsrc::ContractSrcResponse, getdatavar::DataVarResponse, getinfo::RPCAffirmationData, - getinfo::RPCLastPoxAnchorData, getinfo::RPCPeerInfoData, - getistraitimplemented::GetIsTraitImplementedResponse, getmapentry::MapEntryResponse, - getpoxinfo::RPCPoxContractVersion, getpoxinfo::RPCPoxInfoData, - gettransaction_unconfirmed::UnconfirmedTransactionResponse, - gettransaction_unconfirmed::UnconfirmedTransactionStatus, postfeerate::RPCFeeEstimate, - postfeerate::RPCFeeEstimateResponse, + StacksHttp, StacksHttpMessage, StacksHttpRequest, StacksHttpResponse, HTTP_REQUEST_ID_RESERVED, }; -use crate::net::atlas::{AttachmentPage, GetAttachmentResponse, GetAttachmentsInvResponse}; -use crate::net::p2p::PeerMap; -use crate::net::p2p::PeerNetwork; +use crate::net::p2p::{PeerMap, PeerNetwork}; use crate::net::relay::Relayer; -use crate::net::stackerdb::StackerDBTx; -use crate::net::stackerdb::StackerDBs; -use crate::net::BlocksData; -use crate::net::BlocksDatum; -use crate::net::Error as net_error; -use crate::net::MicroblocksData; -use crate::net::NeighborAddress; -use crate::net::NeighborsData; -use crate::net::ProtocolFamily; -use crate::net::StackerDBPushChunkData; -use crate::net::StacksMessageType; -use crate::net::UrlString; -use crate::net::MAX_HEADERS; -use crate::net::MAX_NEIGHBORS_DATA_LEN; -use crate::util_lib::db::DBConn; -use crate::util_lib::db::Error as db_error; -use clarity::vm::database::clarity_store::make_contract_hash_key; -use clarity::vm::types::TraitIdentifier; -use clarity::vm::ClarityVersion; -use clarity::vm::{ - analysis::errors::CheckErrors, - ast::ASTRules, - costs::{ExecutionCost, LimitedCostTracker}, - database::{ - clarity_store::ContractCommitment, BurnStateDB, ClarityDatabase, ClaritySerializable, - STXBalance, StoreType, - }, - errors::Error as ClarityRuntimeError, - errors::Error::Unchecked, - errors::InterpreterError, - types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}, - ClarityName, ContractName, SymbolicExpression, Value, -}; -use libstackerdb::{StackerDBChunkAckData, StackerDBChunkData}; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::{hex_bytes, to_hex}; - -use crate::chainstate::stacks::boot::{POX_1_NAME, POX_2_NAME, POX_3_NAME}; -use crate::chainstate::stacks::StacksBlockHeader; -use crate::clarity_vm::database::marf::MarfedKV; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::{BurnchainHeaderHash, StacksAddress, StacksBlockId}; -use stacks_common::types::net::{PeerAddress, PeerHost}; -use stacks_common::types::StacksPublicKeyBuffer; -use stacks_common::util::chunked_encoding::*; -use stacks_common::util::secp256k1::MessageSignature; - -use crate::clarity_vm::clarity::Error as clarity_error; - -use crate::{ - chainstate::burn::operations::leader_block_commit::OUTPUTS_PER_COMMIT, version_string, -}; -use stacks_common::types; -use stacks_common::util; -use stacks_common::util::hash::Sha256Sum; - +use crate::net::stackerdb::{StackerDBTx, StackerDBs}; +use crate::net::{Error as net_error, StacksMessageType, StacksNodeState}; use crate::util_lib::boot::boot_code_id; - -use crate::net::api::{getpoxinfo::RPCPoxCurrentCycleInfo, getpoxinfo::RPCPoxNextCycleInfo}; +use crate::util_lib::db::{DBConn, Error as db_error}; +use crate::util_lib::strings::UrlString; +use crate::{monitoring, version_string}; pub const STREAM_CHUNK_SIZE: u64 = 4096; diff --git a/stackslib/src/net/server.rs b/stackslib/src/net/server.rs index 58e55760aa..e93819e34e 100644 --- a/stackslib/src/net/server.rs +++ b/stackslib/src/net/server.rs @@ -14,40 +14,28 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::io::Error as io_error; -use std::io::ErrorKind; -use std::io::{Read, Write}; - -use std::collections::HashMap; -use std::collections::VecDeque; - -use std::net::SocketAddr; - -use std::sync::mpsc::sync_channel; -use std::sync::mpsc::Receiver; -use std::sync::mpsc::RecvError; -use std::sync::mpsc::SendError; -use std::sync::mpsc::SyncSender; -use std::sync::mpsc::TryRecvError; - -use crate::net::connection::ConnectionOptions; -use crate::net::httpcore::{StacksHttpRequest, StacksHttpResponse}; -use crate::net::p2p::PeerNetwork; -use crate::net::poll::{NetworkPollState, NetworkState}; -use crate::net::rpc::ConversationHttp; -use crate::net::Error as net_error; -use crate::net::{NeighborKey, PeerHostExtensions, StacksMessageType, StacksNodeState, UrlString}; - -use crate::net::http::HttpBadRequest; - -use crate::chainstate::stacks::db::StacksChainState; -use crate::core::mempool::MemPoolDB; +use std::collections::{HashMap, VecDeque}; +use std::io::{Error as io_error, ErrorKind, Read, Write}; +use std::sync::mpsc::{sync_channel, Receiver, RecvError, SendError, SyncSender, TryRecvError}; use mio::net as mio_net; - use stacks_common::types::net::{PeerAddress, PeerHost}; use stacks_common::util::get_epoch_time_secs; +use crate::burnchains::{Burnchain, BurnchainView}; +use crate::chainstate::burn::db::sortdb::SortitionDB; +use crate::chainstate::stacks::db::StacksChainState; +use crate::core::mempool::*; +use crate::net::atlas::AtlasDB; +use crate::net::connection::*; +use crate::net::db::*; +use crate::net::http::*; +use crate::net::httpcore::*; +use crate::net::p2p::{PeerMap, PeerNetwork}; +use crate::net::poll::*; +use crate::net::rpc::*; +use crate::net::{Error as net_error, *}; + #[derive(Debug)] pub struct HttpPeer { /// ongoing http conversations (either they reached out to us, or we to them) @@ -678,50 +666,32 @@ impl HttpPeer { #[cfg(test)] mod test { - use super::*; - use crate::net::codec::*; - use crate::net::httpcore::*; - use crate::net::rpc::*; - use crate::net::test::*; - use crate::net::*; use std::cell::RefCell; - - use crate::burnchains::Burnchain; - use crate::burnchains::BurnchainView; - use stacks_common::types::chainstate::BurnchainHeaderHash; - - use crate::burnchains::*; - use crate::chainstate::stacks::db::blocks::test::*; - use crate::chainstate::stacks::db::StacksChainState; - use crate::chainstate::stacks::test::*; - use crate::chainstate::stacks::Error as chain_error; - use crate::chainstate::stacks::*; - use crate::chainstate::stacks::*; - use stacks_common::types::chainstate::BlockHeaderHash; - - use std::sync::mpsc::sync_channel; - use std::sync::mpsc::Receiver; - use std::sync::mpsc::RecvError; - use std::sync::mpsc::SendError; - use std::sync::mpsc::SyncSender; - use std::sync::mpsc::TryRecvError; - + use std::net::{SocketAddr, TcpStream}; + use std::sync::mpsc::{sync_channel, Receiver, RecvError, SendError, SyncSender, TryRecvError}; use std::thread; - use std::net::SocketAddr; - use std::net::TcpStream; - - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::pipe::*; - use stacks_common::util::sleep_ms; - - use crate::chainstate::burn::ConsensusHash; - use crate::chainstate::stacks::StacksBlockHeader; use clarity::vm::contracts::Contract; - use clarity::vm::representations::ClarityName; - use clarity::vm::representations::ContractName; + use clarity::vm::representations::{ClarityName, ContractName}; use clarity::vm::types::*; use stacks_common::codec::MAX_MESSAGE_LEN; + use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash}; + use stacks_common::util::pipe::*; + use stacks_common::util::{get_epoch_time_secs, sleep_ms}; + + use super::*; + use crate::burnchains::{Burnchain, BurnchainView, *}; + use crate::chainstate::burn::ConsensusHash; + use crate::chainstate::stacks::db::blocks::test::*; + use crate::chainstate::stacks::db::StacksChainState; + use crate::chainstate::stacks::test::*; + use crate::chainstate::stacks::{Error as chain_error, StacksBlockHeader, *, *}; + use crate::net::codec::*; + use crate::net::http::*; + use crate::net::httpcore::*; + use crate::net::rpc::*; + use crate::net::test::*; + use crate::net::*; fn test_http_server( test_name: &str, diff --git a/stackslib/src/net/stackerdb/config.rs b/stackslib/src/net/stackerdb/config.rs index 07329ae01b..376f57b141 100644 --- a/stackslib/src/net/stackerdb/config.rs +++ b/stackslib/src/net/stackerdb/config.rs @@ -37,34 +37,29 @@ use std::collections::{HashMap, HashSet}; use std::mem; -use crate::net::stackerdb::{ - StackerDBConfig, StackerDBs, STACKERDB_INV_MAX, STACKERDB_MAX_CHUNK_SIZE, -}; - -use crate::net::Error as net_error; -use crate::net::NeighborAddress; - -use crate::chainstate::burn::db::sortdb::SortitionDB; -use crate::chainstate::stacks::db::StacksChainState; -use crate::chainstate::stacks::Error as chainstate_error; - -use crate::clarity_vm::clarity::{ClarityReadOnlyConnection, Error as clarity_error}; use clarity::vm::analysis::ContractAnalysis; use clarity::vm::clarity::ClarityConnection; use clarity::vm::database::BurnStateDB; -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::types::StandardPrincipalData; use clarity::vm::types::{ - BufferLength, FixedFunction, FunctionType, ListTypeData, PrincipalData, SequenceSubtype, - TupleTypeSignature, TypeSignature, + BufferLength, FixedFunction, FunctionType, ListTypeData, PrincipalData, + QualifiedContractIdentifier, SequenceSubtype, StandardPrincipalData, TupleTypeSignature, + TypeSignature, }; use clarity::vm::ClarityName; - use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; use stacks_common::types::net::PeerAddress; use stacks_common::types::StacksEpochId; use stacks_common::util::hash::Hash160; +use crate::chainstate::burn::db::sortdb::SortitionDB; +use crate::chainstate::stacks::db::StacksChainState; +use crate::chainstate::stacks::Error as chainstate_error; +use crate::clarity_vm::clarity::{ClarityReadOnlyConnection, Error as clarity_error}; +use crate::net::stackerdb::{ + StackerDBConfig, StackerDBs, STACKERDB_INV_MAX, STACKERDB_MAX_CHUNK_SIZE, +}; +use crate::net::{Error as net_error, NeighborAddress}; + const MAX_HINT_REPLICAS: u32 = 128; lazy_static! { diff --git a/stackslib/src/net/stackerdb/db.rs b/stackslib/src/net/stackerdb/db.rs index 4b4232f676..6034f3d059 100644 --- a/stackslib/src/net/stackerdb/db.rs +++ b/stackslib/src/net/stackerdb/db.rs @@ -14,38 +14,28 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::collections::HashMap; -use std::collections::HashSet; - -use std::fs; -use std::io; +use std::collections::{HashMap, HashSet}; use std::path::Path; +use std::{fs, io}; -use libstackerdb::SlotMetadata; -use libstackerdb::STACKERDB_MAX_CHUNK_SIZE; +use clarity::vm::types::QualifiedContractIdentifier; +use clarity::vm::ContractName; +use libstackerdb::{SlotMetadata, STACKERDB_MAX_CHUNK_SIZE}; +use rusqlite::types::ToSql; +use rusqlite::{Connection, OpenFlags, OptionalExtension, Row, Transaction, NO_PARAMS}; +use stacks_common::types::chainstate::{ConsensusHash, StacksAddress}; +use stacks_common::util::get_epoch_time_secs; +use stacks_common::util::hash::Sha512Trunc256Sum; +use stacks_common::util::secp256k1::MessageSignature; use crate::chainstate::stacks::address::PoxAddress; use crate::net::stackerdb::{StackerDBConfig, StackerDBTx, StackerDBs, STACKERDB_INV_MAX}; -use crate::net::Error as net_error; -use crate::net::{StackerDBChunkData, StackerDBHandshakeData}; - -use rusqlite::{ - types::ToSql, Connection, OpenFlags, OptionalExtension, Row, Transaction, NO_PARAMS, -}; - +use crate::net::{Error as net_error, StackerDBChunkData, StackerDBHandshakeData}; use crate::util_lib::db::{ opt_u64_to_sql, query_row, query_row_panic, query_rows, sql_pragma, sqlite_open, tx_begin_immediate, tx_busy_handler, u64_to_sql, DBConn, Error as db_error, FromColumn, FromRow, }; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::secp256k1::MessageSignature; - -use clarity::vm::types::QualifiedContractIdentifier; -use clarity::vm::ContractName; const STACKER_DB_SCHEMA: &'static [&'static str] = &[ r#" diff --git a/stackslib/src/net/stackerdb/mod.rs b/stackslib/src/net/stackerdb/mod.rs index 3862544676..8520cec1f0 100644 --- a/stackslib/src/net/stackerdb/mod.rs +++ b/stackslib/src/net/stackerdb/mod.rs @@ -118,36 +118,23 @@ pub mod config; pub mod db; pub mod sync; -use crate::net::Error as net_error; -use crate::net::NackData; -use crate::net::NackErrorCodes; -use crate::net::Neighbor; -use crate::net::NeighborAddress; -use crate::net::NeighborKey; -use crate::net::Preamble; -use crate::net::StackerDBChunkData; -use crate::net::StackerDBChunkInvData; -use crate::net::StackerDBGetChunkData; -use crate::net::StackerDBPushChunkData; -use crate::net::StacksMessage; -use crate::net::StacksMessageType; +use std::collections::{HashMap, HashSet}; -use crate::util_lib::db::{DBConn, DBTx}; -use stacks_common::types::chainstate::ConsensusHash; +use clarity::vm::types::QualifiedContractIdentifier; +use libstackerdb::{SlotMetadata, STACKERDB_MAX_CHUNK_SIZE}; +use stacks_common::types::chainstate::{ConsensusHash, StacksAddress}; +use stacks_common::util::get_epoch_time_secs; use stacks_common::util::hash::Sha512Trunc256Sum; use stacks_common::util::secp256k1::MessageSignature; -use std::collections::{HashMap, HashSet}; use crate::net::neighbors::NeighborComms; - use crate::net::p2p::PeerNetwork; - -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::util::get_epoch_time_secs; - -use libstackerdb::{SlotMetadata, STACKERDB_MAX_CHUNK_SIZE}; - -use clarity::vm::types::QualifiedContractIdentifier; +use crate::net::{ + Error as net_error, NackData, NackErrorCodes, Neighbor, NeighborAddress, NeighborKey, Preamble, + StackerDBChunkData, StackerDBChunkInvData, StackerDBGetChunkData, StackerDBPushChunkData, + StacksMessage, StacksMessageType, +}; +use crate::util_lib::db::{DBConn, DBTx}; /// maximum chunk inventory size pub const STACKERDB_INV_MAX: u32 = 4096; diff --git a/stackslib/src/net/stackerdb/sync.rs b/stackslib/src/net/stackerdb/sync.rs index 3c22df43db..a5d875d86e 100644 --- a/stackslib/src/net/stackerdb/sync.rs +++ b/stackslib/src/net/stackerdb/sync.rs @@ -17,35 +17,27 @@ use std::collections::{HashMap, HashSet}; use std::mem; -use crate::net::stackerdb::{ - StackerDBConfig, StackerDBSync, StackerDBSyncResult, StackerDBSyncState, StackerDBs, -}; - -use crate::net::db::PeerDB; - -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; +use clarity::vm::types::QualifiedContractIdentifier; +use rand::prelude::SliceRandom; +use rand::{thread_rng, Rng, RngCore}; +use stacks_common::types::chainstate::{ConsensusHash, StacksAddress}; use stacks_common::util::get_epoch_time_secs; use stacks_common::util::hash::Hash160; use crate::net::chat::ConversationP2P; use crate::net::connection::ReplyHandleP2P; +use crate::net::db::PeerDB; +use crate::net::neighbors::NeighborComms; use crate::net::p2p::PeerNetwork; -use crate::net::Error as net_error; +use crate::net::stackerdb::{ + StackerDBConfig, StackerDBSync, StackerDBSyncResult, StackerDBSyncState, StackerDBs, +}; use crate::net::{ - NackData, Neighbor, NeighborAddress, NeighborKey, StackerDBChunkData, StackerDBChunkInvData, - StackerDBGetChunkData, StackerDBGetChunkInvData, StackerDBPushChunkData, StacksMessageType, + Error as net_error, NackData, Neighbor, NeighborAddress, NeighborKey, StackerDBChunkData, + StackerDBChunkInvData, StackerDBGetChunkData, StackerDBGetChunkInvData, StackerDBPushChunkData, + StacksMessageType, }; -use crate::net::neighbors::NeighborComms; - -use clarity::vm::types::QualifiedContractIdentifier; - -use rand::prelude::SliceRandom; -use rand::thread_rng; -use rand::Rng; -use rand::RngCore; - const MAX_CHUNKS_IN_FLIGHT: usize = 6; const MAX_DB_NEIGHBORS: usize = 32; diff --git a/stackslib/src/net/stackerdb/tests/config.rs b/stackslib/src/net/stackerdb/tests/config.rs index 07a5cd7218..dec38e4691 100644 --- a/stackslib/src/net/stackerdb/tests/config.rs +++ b/stackslib/src/net/stackerdb/tests/config.rs @@ -14,37 +14,26 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::burnchains::Burnchain; -use crate::core::StacksEpochExtension; -use crate::core::BITCOIN_REGTEST_FIRST_BLOCK_HASH; +use clarity::vm::types::QualifiedContractIdentifier; +use clarity::vm::{ClarityVersion, ContractName}; +use stacks_common::address::AddressHashMode; +use stacks_common::types::chainstate::{ + BurnchainHeaderHash, StacksAddress, StacksPrivateKey, StacksPublicKey, +}; +use stacks_common::types::StacksEpoch; +use stacks_common::util::hash::Hash160; +use crate::burnchains::Burnchain; use crate::chainstate::stacks::boot::test::{ instantiate_pox_peer, instantiate_pox_peer_with_epoch, }; -use crate::chainstate::stacks::StacksTransaction; -use crate::chainstate::stacks::StacksTransactionSigner; -use crate::chainstate::stacks::TransactionAuth; -use crate::chainstate::stacks::TransactionPayload; -use crate::chainstate::stacks::TransactionVersion; - +use crate::chainstate::stacks::{ + StacksTransaction, StacksTransactionSigner, TransactionAuth, TransactionPayload, + TransactionVersion, +}; +use crate::core::{StacksEpochExtension, BITCOIN_REGTEST_FIRST_BLOCK_HASH}; use crate::net::test::TestEventObserver; -use crate::net::Error as net_error; -use crate::net::NeighborAddress; -use crate::net::StackerDBConfig; - -use clarity::vm::ClarityVersion; -use clarity::vm::ContractName; - -use stacks_common::address::AddressHashMode; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksPrivateKey; -use stacks_common::types::chainstate::StacksPublicKey; -use stacks_common::types::net::PeerAddress; -use stacks_common::types::StacksEpoch; -use stacks_common::util::hash::Hash160; - -use clarity::vm::types::QualifiedContractIdentifier; +use crate::net::{Error as net_error, NeighborAddress, PeerAddress, StackerDBConfig}; fn make_smart_contract( name: &str, diff --git a/stackslib/src/net/stackerdb/tests/db.rs b/stackslib/src/net/stackerdb/tests/db.rs index 273274e83b..7371b6b9c5 100644 --- a/stackslib/src/net/stackerdb/tests/db.rs +++ b/stackslib/src/net/stackerdb/tests/db.rs @@ -17,26 +17,21 @@ use std::fs; use std::path::Path; -use crate::net::stackerdb::{db::SlotValidation, StackerDBConfig, StackerDBs}; -use libstackerdb::SlotMetadata; - -use crate::net::Error as net_error; -use crate::net::StackerDBChunkData; - +use clarity::vm::types::QualifiedContractIdentifier; use clarity::vm::ContractName; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; - -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::secp256k1::MessageSignature; - +use libstackerdb::SlotMetadata; use stacks_common::address::{ AddressHashMode, C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, }; -use stacks_common::types::chainstate::{StacksPrivateKey, StacksPublicKey}; +use stacks_common::types::chainstate::{ + ConsensusHash, StacksAddress, StacksPrivateKey, StacksPublicKey, +}; +use stacks_common::util::hash::{Hash160, Sha512Trunc256Sum}; +use stacks_common::util::secp256k1::MessageSignature; -use clarity::vm::types::QualifiedContractIdentifier; +use crate::net::stackerdb::db::SlotValidation; +use crate::net::stackerdb::{StackerDBConfig, StackerDBs}; +use crate::net::{Error as net_error, StackerDBChunkData}; fn setup_test_path(path: &str) { let dirname = Path::new(path).parent().unwrap().to_str().unwrap(); diff --git a/stackslib/src/net/stackerdb/tests/sync.rs b/stackslib/src/net/stackerdb/tests/sync.rs index 87fd47f19e..92187820c0 100644 --- a/stackslib/src/net/stackerdb/tests/sync.rs +++ b/stackslib/src/net/stackerdb/tests/sync.rs @@ -16,39 +16,28 @@ use std::fs; -use crate::net::stackerdb::{db::SlotValidation, StackerDBConfig, StackerDBs}; -use libstackerdb::SlotMetadata; - -use crate::net::Error as net_error; -use crate::net::StackerDBChunkData; - +use clarity::vm::types::QualifiedContractIdentifier; use clarity::vm::ContractName; -use stacks_common::types::chainstate::ConsensusHash; -use stacks_common::types::chainstate::StacksAddress; - -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha512Trunc256Sum; -use stacks_common::util::secp256k1::{MessageSignature, Secp256k1PrivateKey}; - +use libstackerdb::SlotMetadata; +use rand::prelude::*; +use rand::seq::SliceRandom; +use rand::{thread_rng, Rng, RngCore}; use stacks_common::address::{ AddressHashMode, C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, }; -use stacks_common::types::chainstate::{StacksPrivateKey, StacksPublicKey}; - -use rand::prelude::*; -use rand::seq::SliceRandom; -use rand::thread_rng; -use rand::Rng; -use rand::RngCore; +use stacks_common::types::chainstate::{ + ConsensusHash, StacksAddress, StacksPrivateKey, StacksPublicKey, +}; +use stacks_common::util::hash::{Hash160, Sha512Trunc256Sum}; +use stacks_common::util::secp256k1::{MessageSignature, Secp256k1PrivateKey}; use crate::net::relay::Relayer; -use crate::net::test::TestPeer; -use crate::net::test::TestPeerConfig; - +use crate::net::stackerdb::db::SlotValidation; +use crate::net::stackerdb::{StackerDBConfig, StackerDBs}; +use crate::net::test::{TestPeer, TestPeerConfig}; +use crate::net::{Error as net_error, StackerDBChunkData}; use crate::util_lib::test::with_timeout; -use clarity::vm::types::QualifiedContractIdentifier; - const BASE_PORT: u16 = 33000; // Minimum chunk size for FROST is 97 + T * 33, where T = 3000 diff --git a/stackslib/src/net/tests/httpcore.rs b/stackslib/src/net/tests/httpcore.rs index 1b152f42f4..8cd42f45b7 100644 --- a/stackslib/src/net/tests/httpcore.rs +++ b/stackslib/src/net/tests/httpcore.rs @@ -18,6 +18,14 @@ use std::io::Write; use std::net::{SocketAddr, ToSocketAddrs}; use std::str; +use stacks_common::codec::StacksMessageCodec; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId, StacksPrivateKey}; +use stacks_common::types::net::{PeerAddress, PeerHost}; +use stacks_common::util::chunked_encoding::{ + HttpChunkedTransferWriter, HttpChunkedTransferWriterState, +}; +use stacks_common::util::hash::{hex_bytes, to_hex, Hash160}; + use crate::burnchains::Txid; use crate::chainstate::stacks::db::blocks::test::make_sample_microblock_stream; use crate::chainstate::stacks::test::make_codec_test_block; @@ -25,8 +33,7 @@ use crate::chainstate::stacks::{ StacksTransaction, TokenTransferMemo, TransactionAuth, TransactionPayload, TransactionPostConditionMode, TransactionVersion, }; -use crate::net::api::getneighbors::RPCNeighbor; -use crate::net::api::getneighbors::RPCNeighborsInfo; +use crate::net::api::getneighbors::{RPCNeighbor, RPCNeighborsInfo}; use crate::net::connection::ConnectionOptions; use crate::net::http::{ http_error_from_code_and_text, http_reason, HttpContentType, HttpErrorResponse, @@ -34,21 +41,11 @@ use crate::net::http::{ HttpVersion, HTTP_PREAMBLE_MAX_NUM_HEADERS, }; use crate::net::httpcore::{ - HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttpRequest, StacksHttpResponse, + HttpPreambleExtensions, HttpRequestContentsExtensions, StacksHttp, StacksHttpMessage, + StacksHttpPreamble, StacksHttpRequest, StacksHttpResponse, }; -use crate::net::httpcore::{StacksHttp, StacksHttpMessage, StacksHttpPreamble}; use crate::net::rpc::ConversationHttp; -use crate::net::ProtocolFamily; -use crate::net::TipRequest; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; -use stacks_common::types::chainstate::StacksPrivateKey; -use stacks_common::types::net::{PeerAddress, PeerHost}; -use stacks_common::util::chunked_encoding::HttpChunkedTransferWriter; -use stacks_common::util::chunked_encoding::HttpChunkedTransferWriterState; -use stacks_common::util::hash::hex_bytes; -use stacks_common::util::hash::{to_hex, Hash160}; +use crate::net::{ProtocolFamily, TipRequest}; #[test] fn test_parse_stacks_http_preamble_request_err() { diff --git a/stackslib/src/net/tests/neighbors.rs b/stackslib/src/net/tests/neighbors.rs index 149988ff5c..333543e7ca 100644 --- a/stackslib/src/net/tests/neighbors.rs +++ b/stackslib/src/net/tests/neighbors.rs @@ -14,26 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::core::PEER_VERSION_TESTNET; +use clarity::vm::types::{StacksAddressExtensions, StandardPrincipalData}; +use rand::prelude::*; +use rand::thread_rng; +use stacks_common::util::hash::*; +use stacks_common::util::sleep_ms; use crate::core::{ - StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, STACKS_EPOCH_MAX, + StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, + PEER_VERSION_TESTNET, STACKS_EPOCH_MAX, }; use crate::net::asn::*; use crate::net::chat::*; use crate::net::db::*; use crate::net::neighbors::*; use crate::net::test::*; -use crate::net::Error as net_error; -use crate::net::*; +use crate::net::{Error as net_error, *}; use crate::util_lib::test::*; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::types::StandardPrincipalData; -use stacks_common::util::hash::*; -use stacks_common::util::sleep_ms; - -use rand::prelude::*; -use rand::thread_rng; const TEST_IN_OUT_DEGREES: u64 = 0x1; diff --git a/stackslib/src/util_lib/bloom.rs b/stackslib/src/util_lib/bloom.rs index e3633288f0..d34fca233a 100644 --- a/stackslib/src/util_lib/bloom.rs +++ b/stackslib/src/util_lib/bloom.rs @@ -19,28 +19,15 @@ use std::collections::HashMap; use std::hash::Hasher; use std::io::{Read, Seek, SeekFrom, Write}; -use stacks_common::util::hash::Sha512Trunc256Sum; - -use siphasher::sip::SipHasher; // this is SipHash-2-4 - -use stacks_common::codec::Error as codec_error; -use stacks_common::codec::StacksMessageCodec; -use stacks_common::codec::{read_next, write_next}; - -use crate::util_lib::db::query_expect_row; -use crate::util_lib::db::Error as db_error; -use crate::util_lib::db::{DBConn, DBTx}; - -use stacks_common::util::hash::to_hex; - -use rusqlite::blob::Blob; -use rusqlite::Error as sqlite_error; -use rusqlite::Row; -use rusqlite::ToSql; -use rusqlite::NO_PARAMS; - use rand::prelude::*; use rand::thread_rng; +use rusqlite::blob::Blob; +use rusqlite::{Error as sqlite_error, Row, ToSql, NO_PARAMS}; +use siphasher::sip::SipHasher; // this is SipHash-2-4 +use stacks_common::codec::{read_next, write_next, Error as codec_error, StacksMessageCodec}; +use stacks_common::util::hash::{to_hex, Sha512Trunc256Sum}; + +use crate::util_lib::db::{query_expect_row, DBConn, DBTx, Error as db_error}; /// A field of bits of known length! #[derive(Debug, Clone, PartialEq)] @@ -605,15 +592,13 @@ impl BloomHash for BloomNodeHasher { #[cfg(test)] pub mod test { - use super::*; - use std::fs; use rand::prelude::*; use rand::thread_rng; - use rusqlite::OpenFlags; + use super::*; use crate::util_lib::db::{sql_pragma, tx_begin_immediate, tx_busy_handler, DBConn, DBTx}; pub fn setup_bloom_counter(db_name: &str) -> DBConn { diff --git a/stackslib/src/util_lib/boot.rs b/stackslib/src/util_lib/boot.rs index b580166890..af3f443278 100644 --- a/stackslib/src/util_lib/boot.rs +++ b/stackslib/src/util_lib/boot.rs @@ -1,16 +1,17 @@ use std::convert::TryFrom; -use crate::chainstate::stacks::db::StacksAccount; -use crate::chainstate::stacks::{ - SinglesigHashMode, SinglesigSpendingCondition, TransactionAuth, TransactionPublicKeyEncoding, - TransactionSpendingCondition, -}; use clarity::vm::database::STXBalance; use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; use clarity::vm::ContractName; use stacks_common::types::chainstate::StacksAddress; use stacks_common::util::secp256k1::MessageSignature; +use crate::chainstate::stacks::db::StacksAccount; +use crate::chainstate::stacks::{ + SinglesigHashMode, SinglesigSpendingCondition, TransactionAuth, TransactionPublicKeyEncoding, + TransactionSpendingCondition, +}; + pub fn boot_code_id(name: &str, mainnet: bool) -> QualifiedContractIdentifier { let addr = boot_code_addr(mainnet); QualifiedContractIdentifier::new( diff --git a/stackslib/src/util_lib/db.rs b/stackslib/src/util_lib/db.rs index 8409b154c1..5d5f6226da 100644 --- a/stackslib/src/util_lib/db.rs +++ b/stackslib/src/util_lib/db.rs @@ -15,48 +15,28 @@ // along with this program. If not, see . use std::convert::TryInto; -use std::error; -use std::fmt; -use std::fs; -use std::io; use std::io::Error as IOError; -use std::ops::Deref; -use std::ops::DerefMut; -use std::path::Path; -use std::path::PathBuf; +use std::ops::{Deref, DerefMut}; +use std::path::{Path, PathBuf}; use std::time::Duration; +use std::{error, fmt, fs, io}; -use rand::thread_rng; -use rand::Rng; -use rand::RngCore; +use clarity::vm::types::QualifiedContractIdentifier; +use rand::{thread_rng, Rng, RngCore}; use rusqlite::types::{FromSql, ToSql}; -use rusqlite::Connection; -use rusqlite::Error as sqlite_error; -use rusqlite::OpenFlags; -use rusqlite::OptionalExtension; -use rusqlite::Row; -use rusqlite::Transaction; -use rusqlite::TransactionBehavior; -use rusqlite::NO_PARAMS; +use rusqlite::{ + Connection, Error as sqlite_error, OpenFlags, OptionalExtension, Row, Transaction, + TransactionBehavior, NO_PARAMS, +}; use serde_json::Error as serde_error; - -use clarity::vm::types::QualifiedContractIdentifier; -use stacks_common::types::chainstate::SortitionId; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::chainstate::{SortitionId, StacksAddress, StacksBlockId, TrieHash}; use stacks_common::types::Address; use stacks_common::util::hash::to_hex; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; use stacks_common::util::sleep_ms; -use crate::chainstate::stacks::index::marf::MarfConnection; -use crate::chainstate::stacks::index::marf::MarfTransaction; -use crate::chainstate::stacks::index::marf::MARF; -use crate::chainstate::stacks::index::Error as MARFError; -use crate::chainstate::stacks::index::MARFValue; -use crate::chainstate::stacks::index::MarfTrieId; -use stacks_common::types::chainstate::TrieHash; +use crate::chainstate::stacks::index::marf::{MarfConnection, MarfTransaction, MARF}; +use crate::chainstate::stacks::index::{Error as MARFError, MARFValue, MarfTrieId}; pub type DBConn = rusqlite::Connection; pub type DBTx<'a> = rusqlite::Transaction<'a>; diff --git a/stackslib/src/util_lib/mod.rs b/stackslib/src/util_lib/mod.rs index 8d41c60276..85b09a3af6 100644 --- a/stackslib/src/util_lib/mod.rs +++ b/stackslib/src/util_lib/mod.rs @@ -6,13 +6,12 @@ pub mod strings; #[cfg(test)] pub mod test { - use super::*; - use stacks_common::util::get_epoch_time_secs; - use stacks_common::util::sleep_ms; - use std::panic; - use std::process; use std::sync::mpsc::sync_channel; - use std::thread; + use std::{panic, process, thread}; + + use stacks_common::util::{get_epoch_time_secs, sleep_ms}; + + use super::*; pub fn with_timeout(timeout_secs: u64, test_func: F) where diff --git a/stackslib/src/util_lib/strings.rs b/stackslib/src/util_lib/strings.rs index 47291e192d..cb43956274 100644 --- a/stackslib/src/util_lib/strings.rs +++ b/stackslib/src/util_lib/strings.rs @@ -16,17 +16,10 @@ use std::borrow::Borrow; use std::convert::TryFrom; -use std::fmt; -use std::io; use std::io::prelude::*; use std::io::{Read, Write}; -use std::ops::Deref; -use std::ops::DerefMut; - -use regex::Regex; -use url; - -use stacks_common::codec::Error as codec_error; +use std::ops::{Deref, DerefMut}; +use std::{fmt, io}; use clarity::vm::errors::RuntimeErrorType; use clarity::vm::representations::{ @@ -36,10 +29,13 @@ use clarity::vm::representations::{ use clarity::vm::types::{ PrincipalData, QualifiedContractIdentifier, StandardPrincipalData, Value, }; -use stacks_common::codec::MAX_MESSAGE_LEN; +use regex::Regex; +use stacks_common::codec::{ + read_next, read_next_at_most, write_next, Error as codec_error, StacksMessageCodec, + MAX_MESSAGE_LEN, +}; use stacks_common::util::retry::BoundReader; - -use stacks_common::codec::{read_next, read_next_at_most, write_next, StacksMessageCodec}; +use url; lazy_static! { static ref URL_STRING_REGEX: Regex = @@ -326,12 +322,11 @@ impl UrlString { mod test { use std::error::Error; + use super::*; use crate::net::codec::test::check_codec_and_corruption; use crate::net::codec::*; use crate::net::*; - use super::*; - #[test] fn tx_stacks_strings_codec() { let s = "hello-world"; diff --git a/stx-genesis/build.rs b/stx-genesis/build.rs index bc80838566..710585c248 100644 --- a/stx-genesis/build.rs +++ b/stx-genesis/build.rs @@ -1,11 +1,8 @@ use std::fmt::Write as FmtWrite; -use std::fs; +use std::fs::File; +use std::io::{BufRead, BufReader, Read, Write}; use std::path::Path; -use std::{ - env, - fs::File, - io::{BufRead, BufReader, Read, Write}, -}; +use std::{env, fs}; use libflate::deflate; use sha2::{Digest, Sha256}; diff --git a/stx-genesis/src/lib.rs b/stx-genesis/src/lib.rs index dc287a36fc..9d25704b7b 100644 --- a/stx-genesis/src/lib.rs +++ b/stx-genesis/src/lib.rs @@ -1,5 +1,5 @@ -use std::io::{self, BufReader}; -use std::io::{prelude::*, Cursor, Lines}; +use std::io::prelude::*; +use std::io::{self, BufReader, Cursor, Lines}; use libflate::deflate::{self, Decoder}; diff --git a/testnet/stacks-node/Cargo.toml b/testnet/stacks-node/Cargo.toml index 1eb350861c..82ed994ee4 100644 --- a/testnet/stacks-node/Cargo.toml +++ b/testnet/stacks-node/Cargo.toml @@ -38,10 +38,10 @@ clarity = { path = "../../clarity", features = ["default", "testing"]} stacks-common = { path = "../../stacks-common", features = ["default", "testing"] } stacks = { package = "stackslib", path = "../../stackslib", features = ["default", "testing"] } stacks-signer = { path = "../../stacks-signer" } -p256k1 = "5.4.1" +p256k1 = "5.5" tracing = "0.1.37" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } -wsts = { git = "https://github.com/Trust-Machines/wsts", tag = "4.0.0rc2" } +wsts = "4.0.0" [dev-dependencies.rusqlite] version = "=0.24.2" diff --git a/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs b/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs index 2076c0904f..8f2ba1df5d 100644 --- a/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs +++ b/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs @@ -1,24 +1,19 @@ +use std::cmp; +use std::io::Cursor; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::Arc; +use std::time::Instant; + use async_h1::client; use async_std::io::ReadExt; use async_std::net::TcpStream; use base64::encode; use http_types::{Method, Request, Url}; -use std::io::Cursor; -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, -}; -use std::time::Instant; - use serde::Serialize; use serde_json::value::RawValue; - -use std::cmp; - -use super::super::operations::BurnchainOpSigner; -use super::super::Config; -use super::{BurnchainController, BurnchainTip, Error as BurnchainControllerError}; - +use stacks::burnchains::bitcoin::address::{ + BitcoinAddress, LegacyBitcoinAddress, LegacyBitcoinAddressType, SegwitBitcoinAddress, +}; use stacks::burnchains::bitcoin::indexer::{ BitcoinIndexer, BitcoinIndexerConfig, BitcoinIndexerRuntime, }; @@ -26,26 +21,22 @@ use stacks::burnchains::bitcoin::spv::SpvClient; use stacks::burnchains::bitcoin::BitcoinNetworkType; use stacks::burnchains::db::BurnchainDB; use stacks::burnchains::indexer::BurnchainIndexer; -use stacks::burnchains::BurnchainStateTransitionOps; -use stacks::burnchains::Error as burnchain_error; -use stacks::burnchains::PoxConstants; -use stacks::burnchains::PublicKey; use stacks::burnchains::{ - bitcoin::address::{ - BitcoinAddress, LegacyBitcoinAddress, LegacyBitcoinAddressType, SegwitBitcoinAddress, - }, - Txid, + Burnchain, BurnchainParameters, BurnchainStateTransitionOps, Error as burnchain_error, + PoxConstants, PublicKey, Txid, }; -use stacks::burnchains::{Burnchain, BurnchainParameters}; use stacks::chainstate::burn::db::sortdb::SortitionDB; use stacks::chainstate::burn::operations::{ BlockstackOperationType, DelegateStxOp, LeaderBlockCommitOp, LeaderKeyRegisterOp, PreStxOp, TransferStxOp, UserBurnSupportOp, }; +#[cfg(test)] +use stacks::chainstate::burn::Opcodes; use stacks::chainstate::coordinator::comm::CoordinatorChannels; #[cfg(test)] use stacks::chainstate::stacks::address::PoxAddress; use stacks::core::{StacksEpoch, StacksEpochId}; +use stacks::monitoring::{increment_btc_blocks_received_counter, increment_btc_ops_sent_counter}; use stacks_common::codec::StacksMessageCodec; use stacks_common::deps_common::bitcoin::blockdata::opcodes; use stacks_common::deps_common::bitcoin::blockdata::script::{Builder, Script}; @@ -53,21 +44,18 @@ use stacks_common::deps_common::bitcoin::blockdata::transaction::{ OutPoint, Transaction, TxIn, TxOut, }; use stacks_common::deps_common::bitcoin::network::encodable::ConsensusEncodable; -use stacks_common::util::hash::{hex_bytes, Hash160}; -use stacks_common::util::secp256k1::Secp256k1PublicKey; -use stacks_common::util::sleep_ms; - #[cfg(test)] use stacks_common::deps_common::bitcoin::network::serialize::deserialize as btc_deserialize; - use stacks_common::deps_common::bitcoin::network::serialize::RawEncoder; use stacks_common::deps_common::bitcoin::util::hash::Sha256dHash; - -use stacks::monitoring::{increment_btc_blocks_received_counter, increment_btc_ops_sent_counter}; - -#[cfg(test)] -use stacks::chainstate::burn::Opcodes; use stacks_common::types::chainstate::BurnchainHeaderHash; +use stacks_common::util::hash::{hex_bytes, Hash160}; +use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::sleep_ms; + +use super::super::operations::BurnchainOpSigner; +use super::super::Config; +use super::{BurnchainController, BurnchainTip, Error as BurnchainControllerError}; /// The number of bitcoin blocks that can have /// passed since the UTXO cache was last refreshed before diff --git a/testnet/stacks-node/src/burnchains/mocknet_controller.rs b/testnet/stacks-node/src/burnchains/mocknet_controller.rs index 7ae121ac3e..0c1ae9c84e 100644 --- a/testnet/stacks-node/src/burnchains/mocknet_controller.rs +++ b/testnet/stacks-node/src/burnchains/mocknet_controller.rs @@ -1,15 +1,16 @@ use std::collections::VecDeque; use std::time::Instant; +use clarity::vm::costs::ExecutionCost; use stacks::burnchains::bitcoin::BitcoinBlock; use stacks::burnchains::{ Burnchain, BurnchainBlock, BurnchainBlockHeader, BurnchainStateTransitionOps, Txid, }; use stacks::chainstate::burn::db::sortdb::{SortitionDB, SortitionHandleTx}; -use stacks::chainstate::burn::operations::DelegateStxOp; +use stacks::chainstate::burn::operations::leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS; use stacks::chainstate::burn::operations::{ - leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS, BlockstackOperationType, LeaderBlockCommitOp, - LeaderKeyRegisterOp, PreStxOp, StackStxOp, TransferStxOp, UserBurnSupportOp, + BlockstackOperationType, DelegateStxOp, LeaderBlockCommitOp, LeaderKeyRegisterOp, PreStxOp, + StackStxOp, TransferStxOp, UserBurnSupportOp, }; use stacks::chainstate::burn::BlockSnapshot; use stacks::core::{ @@ -23,7 +24,6 @@ use stacks_common::util::hash::Sha256Sum; use super::super::operations::BurnchainOpSigner; use super::super::Config; use super::{BurnchainController, BurnchainTip, Error as BurnchainControllerError}; -use clarity::vm::costs::ExecutionCost; /// MocknetController is simulating a simplistic burnchain. pub struct MocknetController { diff --git a/testnet/stacks-node/src/burnchains/mod.rs b/testnet/stacks-node/src/burnchains/mod.rs index f0badf7899..5506cf6231 100644 --- a/testnet/stacks-node/src/burnchains/mod.rs +++ b/testnet/stacks-node/src/burnchains/mod.rs @@ -1,24 +1,19 @@ pub mod bitcoin_regtest_controller; pub mod mocknet_controller; -pub use self::bitcoin_regtest_controller::BitcoinRegtestController; -pub use self::mocknet_controller::MocknetController; - -use super::operations::BurnchainOpSigner; - use std::fmt; use std::time::Instant; use stacks::burnchains; -use stacks::burnchains::BurnchainStateTransitionOps; -use stacks::burnchains::Txid; +use stacks::burnchains::{BurnchainStateTransitionOps, Txid}; use stacks::chainstate::burn::db::sortdb::SortitionDB; use stacks::chainstate::burn::operations::BlockstackOperationType; use stacks::chainstate::burn::BlockSnapshot; - use stacks::core::{StacksEpoch, StacksEpochId}; -pub use self::bitcoin_regtest_controller::make_bitcoin_indexer; +pub use self::bitcoin_regtest_controller::{make_bitcoin_indexer, BitcoinRegtestController}; +pub use self::mocknet_controller::MocknetController; +use super::operations::BurnchainOpSigner; #[derive(Debug)] pub enum Error { diff --git a/testnet/stacks-node/src/config.rs b/testnet/stacks-node/src/config.rs index fb90b7cdd1..b3c1a1a9d4 100644 --- a/testnet/stacks-node/src/config.rs +++ b/testnet/stacks-node/src/config.rs @@ -2,44 +2,34 @@ use std::convert::TryInto; use std::fs; use std::net::{SocketAddr, ToSocketAddrs}; use std::path::PathBuf; -use std::sync::Arc; -use std::sync::Mutex; - -use rand::RngCore; +use std::sync::{Arc, Mutex}; use clarity::vm::costs::ExecutionCost; use clarity::vm::types::{AssetIdentifier, PrincipalData, QualifiedContractIdentifier}; +use rand::RngCore; use stacks::burnchains::bitcoin::BitcoinNetworkType; -use stacks::burnchains::Burnchain; -use stacks::burnchains::{MagicBytes, BLOCKSTACK_MAGIC_MAINNET}; +use stacks::burnchains::{Burnchain, MagicBytes, BLOCKSTACK_MAGIC_MAINNET}; use stacks::chainstate::stacks::index::marf::MARFOpenOpts; use stacks::chainstate::stacks::index::storage::TrieHashCalculationMode; -use stacks::chainstate::stacks::miner::BlockBuilderSettings; -use stacks::chainstate::stacks::miner::MinerStatus; +use stacks::chainstate::stacks::miner::{BlockBuilderSettings, MinerStatus}; use stacks::chainstate::stacks::MAX_BLOCK_LEN; use stacks::core::mempool::MemPoolWalkSettings; -use stacks::core::StacksEpoch; -use stacks::core::StacksEpochExtension; -use stacks::core::StacksEpochId; use stacks::core::{ - CHAIN_ID_MAINNET, CHAIN_ID_TESTNET, PEER_VERSION_MAINNET, PEER_VERSION_TESTNET, + StacksEpoch, StacksEpochExtension, StacksEpochId, CHAIN_ID_MAINNET, CHAIN_ID_TESTNET, + PEER_VERSION_MAINNET, PEER_VERSION_TESTNET, }; use stacks::cost_estimates::fee_medians::WeightedMedianFeeRateEstimator; use stacks::cost_estimates::fee_rate_fuzzer::FeeRateFuzzer; use stacks::cost_estimates::fee_scalar::ScalarFeeRateEstimator; -use stacks::cost_estimates::metrics::CostMetric; -use stacks::cost_estimates::metrics::ProportionalDotProduct; -use stacks::cost_estimates::CostEstimator; -use stacks::cost_estimates::FeeEstimator; -use stacks::cost_estimates::PessimisticEstimator; +use stacks::cost_estimates::metrics::{CostMetric, ProportionalDotProduct}; +use stacks::cost_estimates::{CostEstimator, FeeEstimator, PessimisticEstimator}; use stacks::net::atlas::AtlasConfig; use stacks::net::connection::ConnectionOptions; use stacks::net::{Neighbor, NeighborKey}; use stacks_common::types::net::PeerAddress; use stacks_common::util::get_epoch_time_ms; use stacks_common::util::hash::hex_bytes; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; const DEFAULT_SATS_PER_VB: u64 = 50; const DEFAULT_MAX_RBF_RATE: u64 = 150; // 1.5x diff --git a/testnet/stacks-node/src/event_dispatcher.rs b/testnet/stacks-node/src/event_dispatcher.rs index 8849e82573..235627b063 100644 --- a/testnet/stacks-node/src/event_dispatcher.rs +++ b/testnet/stacks-node/src/event_dispatcher.rs @@ -5,43 +5,37 @@ use std::time::Duration; use async_h1::client; use async_std::net::TcpStream; -use http_types::{Method, Request, Url}; -use serde_json::json; - use clarity::vm::analysis::contract_interface_builder::build_contract_interface; use clarity::vm::costs::ExecutionCost; use clarity::vm::events::{FTEventType, NFTEventType, STXEventType}; use clarity::vm::types::{AssetIdentifier, QualifiedContractIdentifier, Value}; +use http_types::{Method, Request, Url}; +pub use libsigner::StackerDBChunksEvent; +use serde_json::json; use stacks::burnchains::{PoxConstants, Txid}; +use stacks::chainstate::burn::operations::BlockstackOperationType; +use stacks::chainstate::burn::ConsensusHash; use stacks::chainstate::coordinator::BlockEventDispatcher; use stacks::chainstate::stacks::address::PoxAddress; -use stacks::chainstate::stacks::db::StacksHeaderInfo; +use stacks::chainstate::stacks::db::accounts::MinerReward; +use stacks::chainstate::stacks::db::unconfirmed::ProcessedUnconfirmedState; +use stacks::chainstate::stacks::db::{MinerRewardInfo, StacksHeaderInfo}; use stacks::chainstate::stacks::events::{ StacksTransactionEvent, StacksTransactionReceipt, TransactionOrigin, }; +use stacks::chainstate::stacks::miner::TransactionEvent; use stacks::chainstate::stacks::{ - db::accounts::MinerReward, db::MinerRewardInfo, StacksTransaction, + StacksBlock, StacksMicroblock, StacksTransaction, TransactionPayload, }; -use stacks::chainstate::stacks::{StacksBlock, StacksMicroblock}; -use stacks::core::mempool::MemPoolDropReason; -use stacks::core::mempool::MemPoolEventDispatcher; +use stacks::core::mempool::{MemPoolDropReason, MemPoolEventDispatcher}; +use stacks::libstackerdb::StackerDBChunkData; use stacks::net::atlas::{Attachment, AttachmentInstance}; +use stacks::net::stackerdb::StackerDBEventDispatcher; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksBlockId}; use stacks_common::util::hash::bytes_to_hex; use super::config::{EventKeyType, EventObserverConfig}; -use stacks::chainstate::burn::operations::BlockstackOperationType; -use stacks::chainstate::burn::ConsensusHash; -use stacks::chainstate::stacks::db::unconfirmed::ProcessedUnconfirmedState; -use stacks::chainstate::stacks::miner::TransactionEvent; -use stacks::chainstate::stacks::TransactionPayload; - -use stacks::net::stackerdb::StackerDBEventDispatcher; - -use stacks::libstackerdb::StackerDBChunkData; - -pub use libsigner::StackerDBChunksEvent; #[derive(Debug, Clone)] struct EventObserver { @@ -1066,13 +1060,14 @@ impl EventDispatcher { #[cfg(test)] mod test { - use crate::event_dispatcher::EventObserver; use clarity::vm::costs::ExecutionCost; use stacks::burnchains::{PoxConstants, Txid}; use stacks::chainstate::stacks::db::StacksHeaderInfo; use stacks::chainstate::stacks::StacksBlock; use stacks_common::types::chainstate::{BurnchainHeaderHash, StacksBlockId}; + use crate::event_dispatcher::EventObserver; + #[test] fn build_block_processed_event() { let observer = EventObserver { diff --git a/testnet/stacks-node/src/keychain.rs b/testnet/stacks-node/src/keychain.rs index b3249f52b4..7ea3b90556 100644 --- a/testnet/stacks-node/src/keychain.rs +++ b/testnet/stacks-node/src/keychain.rs @@ -2,18 +2,16 @@ use stacks::burnchains::BurnchainSigner; use stacks::chainstate::stacks::{ StacksPrivateKey, StacksPublicKey, StacksTransactionSigner, TransactionAuth, }; -use stacks_common::address::AddressHashMode; +use stacks_common::address::{ + AddressHashMode, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, +}; use stacks_common::types::chainstate::StacksAddress; use stacks_common::util::hash::{Hash160, Sha256Sum}; +use stacks_common::util::secp256k1::Secp256k1PublicKey; use stacks_common::util::vrf::{VRFPrivateKey, VRFProof, VRFPublicKey, VRF}; use super::operations::BurnchainOpSigner; -use stacks_common::address::{ - C32_ADDRESS_VERSION_MAINNET_SINGLESIG, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, -}; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - /// A wrapper around a node's seed, coupled with operations for using it #[derive(Clone)] pub struct Keychain { @@ -198,23 +196,17 @@ mod tests { use stacks::burnchains::PrivateKey; use stacks::chainstate::stacks::{ - StacksPrivateKey, StacksPublicKey, StacksTransactionSigner, TransactionAuth, + StacksPrivateKey, StacksPublicKey, StacksTransaction, StacksTransactionSigner, + TokenTransferMemo, TransactionAuth, TransactionPayload, TransactionPostConditionMode, + TransactionVersion, }; use stacks_common::address::AddressHashMode; use stacks_common::types::chainstate::StacksAddress; use stacks_common::util::hash::{Hash160, Sha256Sum}; use stacks_common::util::vrf::{VRFPrivateKey, VRFProof, VRFPublicKey, VRF}; - use crate::operations::BurnchainOpSigner; - use super::Keychain; - - use stacks::chainstate::stacks::StacksTransaction; - use stacks::chainstate::stacks::TokenTransferMemo; - use stacks::chainstate::stacks::TransactionPayload; - use stacks::chainstate::stacks::TransactionPostConditionMode; - use stacks::chainstate::stacks::TransactionVersion; - + use crate::operations::BurnchainOpSigner; use crate::stacks_common::types::Address; /// Legacy implementation; kept around for testing diff --git a/testnet/stacks-node/src/main.rs b/testnet/stacks-node/src/main.rs index 987b5e1f03..33f1214dc9 100644 --- a/testnet/stacks-node/src/main.rs +++ b/testnet/stacks-node/src/main.rs @@ -35,6 +35,12 @@ pub mod run_loop; pub mod syncctl; pub mod tenure; +use std::convert::TryInto; +use std::{env, panic, process}; + +use backtrace::Backtrace; +use pico_args::Arguments; + pub use self::burnchains::{ BitcoinRegtestController, BurnchainController, BurnchainTip, MocknetController, }; @@ -45,15 +51,6 @@ pub use self::node::{ChainTip, Node}; pub use self::run_loop::{helium, neon}; pub use self::tenure::Tenure; -use pico_args::Arguments; -use std::env; - -use std::convert::TryInto; -use std::panic; -use std::process; - -use backtrace::Backtrace; - fn main() { panic::set_hook(Box::new(|panic_info| { error!("Process abort due to thread panic: {}", panic_info); @@ -66,8 +63,7 @@ fn main() { let pid = process::id(); eprintln!("Dumping core for pid {}", std::process::id()); - use libc::kill; - use libc::SIGQUIT; + use libc::{kill, SIGQUIT}; // *should* trigger a core dump, if you run `ulimit -c unlimited` first! unsafe { kill(pid.try_into().unwrap(), SIGQUIT) }; diff --git a/testnet/stacks-node/src/monitoring/prometheus.rs b/testnet/stacks-node/src/monitoring/prometheus.rs index 9342a8f8d4..65c427d2bc 100644 --- a/testnet/stacks-node/src/monitoring/prometheus.rs +++ b/testnet/stacks-node/src/monitoring/prometheus.rs @@ -1,9 +1,8 @@ use async_std::net::{TcpListener, TcpStream}; use async_std::prelude::*; use async_std::task; -use stacks::prometheus::{gather, Encoder, TextEncoder}; - use http_types::{Body, Response, StatusCode}; +use stacks::prometheus::{gather, Encoder, TextEncoder}; pub fn start_serving_prometheus_metrics(bind_address: String) { let addr = bind_address.clone(); diff --git a/testnet/stacks-node/src/neon_node.rs b/testnet/stacks-node/src/neon_node.rs index 82d7f4bbf1..517f080cb6 100644 --- a/testnet/stacks-node/src/neon_node.rs +++ b/testnet/stacks-node/src/neon_node.rs @@ -138,93 +138,81 @@ /// /// This file may be refactored in the future into a full-fledged module. use std::cmp; -use std::collections::HashMap; -use std::collections::VecDeque; +use std::collections::{HashMap, VecDeque}; use std::convert::{TryFrom, TryInto}; -use std::mem; +use std::default::Default; use std::net::SocketAddr; +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::{Receiver, SyncSender, TrySendError}; -use std::sync::{atomic::AtomicBool, atomic::Ordering, Arc, Mutex}; +use std::sync::{Arc, Mutex}; +use std::thread::JoinHandle; use std::time::Duration; -use std::{thread, thread::JoinHandle}; +use std::{mem, thread}; +use clarity::vm::ast::ASTRules; use clarity::vm::costs::ExecutionCost; -use stacks::burnchains::{ - db::BurnchainHeaderReader, Burnchain, BurnchainParameters, BurnchainSigner, Txid, -}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; +use stacks::burnchains::db::BurnchainHeaderReader; +use stacks::burnchains::{Burnchain, BurnchainParameters, BurnchainSigner, Txid}; use stacks::chainstate::burn::db::sortdb::SortitionDB; +use stacks::chainstate::burn::operations::leader_block_commit::{ + RewardSetInfo, BURN_BLOCK_MINED_AT_MODULUS, +}; use stacks::chainstate::burn::operations::{ - leader_block_commit::{RewardSetInfo, BURN_BLOCK_MINED_AT_MODULUS}, BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, }; -use stacks::chainstate::burn::BlockSnapshot; -use stacks::chainstate::burn::ConsensusHash; +use stacks::chainstate::burn::{BlockSnapshot, ConsensusHash}; use stacks::chainstate::coordinator::comm::CoordinatorChannels; use stacks::chainstate::coordinator::{get_next_recipients, OnChainRewardSetProvider}; use stacks::chainstate::stacks::address::PoxAddress; use stacks::chainstate::stacks::db::unconfirmed::UnconfirmedTxMap; -use stacks::chainstate::stacks::db::StacksHeaderInfo; -use stacks::chainstate::stacks::db::{StacksChainState, MINER_REWARD_MATURITY}; -use stacks::chainstate::stacks::Error as ChainstateError; -use stacks::chainstate::stacks::StacksPublicKey; -use stacks::chainstate::stacks::{ - miner::get_mining_spend_amount, miner::signal_mining_blocked, miner::signal_mining_ready, - miner::BlockBuilderSettings, miner::MinerStatus, miner::StacksMicroblockBuilder, - StacksBlockBuilder, StacksBlockHeader, +use stacks::chainstate::stacks::db::{StacksChainState, StacksHeaderInfo, MINER_REWARD_MATURITY}; +use stacks::chainstate::stacks::miner::{ + get_mining_spend_amount, signal_mining_blocked, signal_mining_ready, BlockBuilderSettings, + MinerStatus, StacksMicroblockBuilder, }; use stacks::chainstate::stacks::{ - CoinbasePayload, StacksBlock, StacksMicroblock, StacksTransaction, StacksTransactionSigner, + CoinbasePayload, Error as ChainstateError, StacksBlock, StacksBlockBuilder, StacksBlockHeader, + StacksMicroblock, StacksPublicKey, StacksTransaction, StacksTransactionSigner, TransactionAnchorMode, TransactionPayload, TransactionVersion, }; use stacks::core::mempool::MemPoolDB; -use stacks::core::FIRST_BURNCHAIN_CONSENSUS_HASH; -use stacks::core::STACKS_EPOCH_2_4_MARKER; -use stacks::cost_estimates::metrics::CostMetric; -use stacks::cost_estimates::metrics::UnitMetric; -use stacks::cost_estimates::UnitEstimator; -use stacks::cost_estimates::{CostEstimator, FeeEstimator}; +use stacks::core::{FIRST_BURNCHAIN_CONSENSUS_HASH, STACKS_EPOCH_2_4_MARKER}; +use stacks::cost_estimates::metrics::{CostMetric, UnitMetric}; +use stacks::cost_estimates::{CostEstimator, FeeEstimator, UnitEstimator}; +use stacks::monitoring; use stacks::monitoring::{increment_stx_blocks_mined_counter, update_active_miners_count_gauge}; +use stacks::net::atlas::{AtlasConfig, AtlasDB}; +use stacks::net::db::{LocalPeer, PeerDB}; +use stacks::net::dns::{DNSClient, DNSResolver}; +use stacks::net::p2p::PeerNetwork; +use stacks::net::relay::Relayer; +use stacks::net::stackerdb::{StackerDBConfig, StackerDBSync, StackerDBs}; use stacks::net::{ - atlas::{AtlasConfig, AtlasDB}, - db::{LocalPeer, PeerDB}, - dns::DNSClient, - dns::DNSResolver, - p2p::PeerNetwork, - relay::Relayer, - stackerdb::{StackerDBConfig, StackerDBSync, StackerDBs}, Error as NetError, NetworkResult, PeerNetworkComms, RPCHandlerArgs, ServiceFlags, }; use stacks::util_lib::strings::{UrlString, VecDisplay}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::{ - BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksAddress, VRFSeed, + BlockHeaderHash, BurnchainHeaderHash, SortitionId, StacksAddress, StacksBlockId, + StacksPrivateKey, VRFSeed, }; use stacks_common::types::net::PeerAddress; use stacks_common::types::StacksEpochId; -use stacks_common::util::get_epoch_time_ms; -use stacks_common::util::get_epoch_time_secs; use stacks_common::util::hash::{to_hex, Hash160, Sha256Sum}; use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::vrf::VRFPublicKey; +use stacks_common::util::vrf::{VRFProof, VRFPublicKey}; +use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs}; -use crate::burnchains::bitcoin_regtest_controller::OngoingBlockCommit; -use crate::burnchains::bitcoin_regtest_controller::{addr2str, BitcoinRegtestController}; +use super::{BurnchainController, Config, EventDispatcher, Keychain}; +use crate::burnchains::bitcoin_regtest_controller::{ + addr2str, BitcoinRegtestController, OngoingBlockCommit, +}; use crate::burnchains::make_bitcoin_indexer; -use crate::run_loop::neon::Counters; -use crate::run_loop::neon::RunLoop; +use crate::run_loop::neon::{Counters, RunLoop}; use crate::run_loop::RegisteredKey; -use crate::ChainTip; - -use super::{BurnchainController, Config, EventDispatcher, Keychain}; use crate::syncctl::PoxSyncWatchdogComms; -use stacks::monitoring; - -use stacks_common::types::chainstate::{StacksBlockId, StacksPrivateKey}; -use stacks_common::util::vrf::VRFProof; - -use clarity::vm::ast::ASTRules; -use clarity::vm::types::PrincipalData; -use clarity::vm::types::QualifiedContractIdentifier; +use crate::ChainTip; pub const RELAYER_MAX_BUFFER: usize = 100; const VRF_MOCK_MINER_KEY: u64 = 1; diff --git a/testnet/stacks-node/src/node.rs b/testnet/stacks-node/src/node.rs index 69d8a51097..b63b4ddbc1 100644 --- a/testnet/stacks-node/src/node.rs +++ b/testnet/stacks-node/src/node.rs @@ -1,11 +1,26 @@ +use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::net::SocketAddr; -use std::{collections::HashMap, collections::HashSet, env}; -use std::{thread, thread::JoinHandle, time}; +use std::thread::JoinHandle; +use std::{env, thread, time}; +use clarity::vm::database::BurnStateDB; +use rand::RngCore; +use stacks::burnchains::bitcoin::BitcoinNetworkType; +use stacks::burnchains::db::BurnchainDB; +use stacks::burnchains::{PoxConstants, Txid}; +use stacks::chainstate::burn::db::sortdb::SortitionDB; +use stacks::chainstate::burn::operations::leader_block_commit::{ + RewardSetInfo, BURN_BLOCK_MINED_AT_MODULUS, +}; +use stacks::chainstate::burn::operations::{ + BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, +}; use stacks::chainstate::burn::ConsensusHash; +use stacks::chainstate::stacks::address::PoxAddress; use stacks::chainstate::stacks::db::{ - ChainStateBootData, ClarityTx, StacksChainState, StacksHeaderInfo, + ChainStateBootData, ChainstateAccountBalance, ChainstateAccountLockup, ChainstateBNSName, + ChainstateBNSNamespace, ClarityTx, StacksChainState, StacksEpochReceipt, StacksHeaderInfo, }; use stacks::chainstate::stacks::events::{ StacksTransactionEvent, StacksTransactionReceipt, TransactionOrigin, @@ -14,54 +29,28 @@ use stacks::chainstate::stacks::{ CoinbasePayload, StacksBlock, StacksMicroblock, StacksTransaction, StacksTransactionSigner, TransactionAnchorMode, TransactionPayload, TransactionVersion, }; -use stacks::chainstate::{burn::db::sortdb::SortitionDB, stacks::db::StacksEpochReceipt}; use stacks::core::mempool::MemPoolDB; use stacks::core::STACKS_EPOCH_2_1_MARKER; use stacks::cost_estimates::metrics::UnitMetric; use stacks::cost_estimates::UnitEstimator; -use stacks::net::atlas::AttachmentInstance; -use stacks::net::{ - atlas::{AtlasConfig, AtlasDB}, - db::PeerDB, - p2p::PeerNetwork, - stackerdb::StackerDBs, - Error as NetError, RPCHandlerArgs, -}; +use stacks::net::atlas::{AtlasConfig, AtlasDB, AttachmentInstance}; +use stacks::net::db::PeerDB; +use stacks::net::p2p::PeerNetwork; +use stacks::net::stackerdb::StackerDBs; +use stacks::net::{Error as NetError, RPCHandlerArgs}; use stacks::util_lib::strings::UrlString; -use stacks::{ - burnchains::db::BurnchainDB, - burnchains::PoxConstants, - chainstate::burn::operations::{ - leader_block_commit::{RewardSetInfo, BURN_BLOCK_MINED_AT_MODULUS}, - BlockstackOperationType, LeaderBlockCommitOp, LeaderKeyRegisterOp, - }, -}; -use stacks::{ - burnchains::Txid, - chainstate::stacks::db::{ - ChainstateAccountBalance, ChainstateAccountLockup, ChainstateBNSName, - ChainstateBNSNamespace, - }, -}; -use stacks_common::types::chainstate::TrieHash; -use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, VRFSeed}; +use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, TrieHash, VRFSeed}; use stacks_common::types::net::PeerAddress; use stacks_common::util::get_epoch_time_secs; use stacks_common::util::hash::Sha256Sum; use stacks_common::util::secp256k1::Secp256k1PrivateKey; use stacks_common::util::vrf::VRFPublicKey; -use crate::run_loop; -use crate::{genesis_data::USE_TEST_GENESIS_CHAINSTATE, run_loop::RegisteredKey}; - -use crate::burnchains::make_bitcoin_indexer; - use super::{BurnchainController, BurnchainTip, Config, EventDispatcher, Keychain, Tenure}; -use clarity::vm::database::BurnStateDB; -use stacks::burnchains::bitcoin::BitcoinNetworkType; - -use rand::RngCore; -use stacks::chainstate::stacks::address::PoxAddress; +use crate::burnchains::make_bitcoin_indexer; +use crate::genesis_data::USE_TEST_GENESIS_CHAINSTATE; +use crate::run_loop; +use crate::run_loop::RegisteredKey; #[derive(Debug, Clone)] pub struct ChainTip { diff --git a/testnet/stacks-node/src/run_loop/helium.rs b/testnet/stacks-node/src/run_loop/helium.rs index 436ff1bca5..c7212d4132 100644 --- a/testnet/stacks-node/src/run_loop/helium.rs +++ b/testnet/stacks-node/src/run_loop/helium.rs @@ -1,11 +1,11 @@ +use stacks::chainstate::stacks::db::ClarityTx; +use stacks_common::types::chainstate::BurnchainHeaderHash; + use super::RunLoopCallbacks; use crate::burnchains::Error as BurnchainControllerError; use crate::{ BitcoinRegtestController, BurnchainController, ChainTip, Config, MocknetController, Node, }; -use stacks::chainstate::stacks::db::ClarityTx; - -use stacks_common::types::chainstate::BurnchainHeaderHash; /// RunLoop is coordinating a simulated burnchain and some simulated nodes /// taking turns in producing blocks. diff --git a/testnet/stacks-node/src/run_loop/mod.rs b/testnet/stacks-node/src/run_loop/mod.rs index 0f8c8ffb58..bc76a128ca 100644 --- a/testnet/stacks-node/src/run_loop/mod.rs +++ b/testnet/stacks-node/src/run_loop/mod.rs @@ -1,25 +1,20 @@ pub mod helium; pub mod neon; -use crate::{BurnchainController, BurnchainTip, ChainTip, Tenure}; - +use clarity::vm::costs::ExecutionCost; +use clarity::vm::database::BurnStateDB; +use stacks::burnchains::{PoxConstants, Txid}; use stacks::chainstate::stacks::db::StacksChainState; +use stacks::chainstate::stacks::events::StacksTransactionReceipt; use stacks::chainstate::stacks::{ - TransactionAuth, TransactionPayload, TransactionSpendingCondition, + StacksBlock, TransactionAuth, TransactionPayload, TransactionSpendingCondition, }; +use stacks_common::types::chainstate::StacksBlockId; use stacks_common::util::vrf::VRFPublicKey; -use clarity::vm::database::BurnStateDB; - use crate::stacks::chainstate::coordinator::BlockEventDispatcher; use crate::stacks::chainstate::stacks::index::ClarityMarfTrieId; -use crate::EventDispatcher; -use clarity::vm::costs::ExecutionCost; -use stacks::burnchains::PoxConstants; -use stacks::burnchains::Txid; -use stacks::chainstate::stacks::events::StacksTransactionReceipt; -use stacks::chainstate::stacks::StacksBlock; -use stacks_common::types::chainstate::StacksBlockId; +use crate::{BurnchainController, BurnchainTip, ChainTip, EventDispatcher, Tenure}; macro_rules! info_blue { ($($arg:tt)*) => ({ diff --git a/testnet/stacks-node/src/run_loop/neon.rs b/testnet/stacks-node/src/run_loop/neon.rs index b3bfe0785f..3688acb153 100644 --- a/testnet/stacks-node/src/run_loop/neon.rs +++ b/testnet/stacks-node/src/run_loop/neon.rs @@ -1,19 +1,12 @@ -use std::cmp; -use std::sync::atomic::{AtomicBool, Ordering}; - #[cfg(test)] use std::sync::atomic::AtomicU64; - +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::sync_channel; - -use std::sync::Arc; -use std::sync::Mutex; -use std::thread; +use std::sync::{Arc, Mutex}; use std::thread::JoinHandle; +use std::{cmp, thread}; -use stacks_common::deps_common::ctrlc as termination; -use stacks_common::deps_common::ctrlc::SignalId; - +use libc; use stacks::burnchains::bitcoin::address::{BitcoinAddress, LegacyBitcoinAddressType}; use stacks::burnchains::Burnchain; use stacks::chainstate::burn::db::sortdb::SortitionDB; @@ -25,31 +18,29 @@ use stacks::chainstate::coordinator::{ ChainsCoordinatorConfig, CoordinatorCommunication, Error as coord_error, }; use stacks::chainstate::stacks::db::{ChainStateBootData, StacksChainState}; +use stacks::chainstate::stacks::miner::{signal_mining_blocked, signal_mining_ready, MinerStatus}; use stacks::core::StacksEpochId; use stacks::net::atlas::{AtlasConfig, AtlasDB, Attachment}; use stacks::util_lib::db::Error as db_error; +use stacks_common::deps_common::ctrlc as termination; +use stacks_common::deps_common::ctrlc::SignalId; +use stacks_common::types::PublicKey; +use stacks_common::util::hash::Hash160; +use stacks_common::util::{get_epoch_time_secs, sleep_ms}; use stx_genesis::GenesisData; use super::RunLoopCallbacks; use crate::burnchains::make_bitcoin_indexer; use crate::monitoring::start_serving_monitoring_metrics; -use crate::neon_node::Globals; -use crate::neon_node::StacksNode; -use crate::neon_node::BLOCK_PROCESSOR_STACK_SIZE; -use crate::neon_node::RELAYER_MAX_BUFFER; -use crate::node::use_test_genesis_chainstate; +use crate::neon_node::{Globals, StacksNode, BLOCK_PROCESSOR_STACK_SIZE, RELAYER_MAX_BUFFER}; +use crate::node::{ + get_account_balances, get_account_lockups, get_names, get_namespaces, + use_test_genesis_chainstate, +}; use crate::syncctl::{PoxSyncWatchdog, PoxSyncWatchdogComms}; use crate::{ - node::{get_account_balances, get_account_lockups, get_names, get_namespaces}, run_loop, BitcoinRegtestController, BurnchainController, Config, EventDispatcher, Keychain, }; -use stacks::chainstate::stacks::miner::{signal_mining_blocked, signal_mining_ready, MinerStatus}; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::sleep_ms; - -use libc; -use stacks_common::types::PublicKey; -use stacks_common::util::hash::Hash160; pub const STDERR: i32 = 2; #[cfg(test)] diff --git a/testnet/stacks-node/src/stacks_events.rs b/testnet/stacks-node/src/stacks_events.rs index 882891398f..f63b17a6ab 100644 --- a/testnet/stacks-node/src/stacks_events.rs +++ b/testnet/stacks-node/src/stacks_events.rs @@ -1,11 +1,11 @@ +use std::io::prelude::*; +use std::io::BufReader; +use std::net::{TcpListener, TcpStream}; + use chrono::{SecondsFormat, Utc}; use lazy_static::lazy_static; use regex::Regex; use serde_json::{json, Value}; -use std::io::prelude::*; -use std::io::BufReader; -use std::net::TcpListener; -use std::net::TcpStream; const DEFAULT_ADDR: &str = "127.0.0.1:3700"; diff --git a/testnet/stacks-node/src/syncctl.rs b/testnet/stacks-node/src/syncctl.rs index 87b082f2af..85a3404c42 100644 --- a/testnet/stacks-node/src/syncctl.rs +++ b/testnet/stacks-node/src/syncctl.rs @@ -1,18 +1,14 @@ use std::collections::VecDeque; +use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::sync::Arc; use stacks::burnchains::{Burnchain, Error as burnchain_error}; use stacks::chainstate::stacks::db::StacksChainState; -use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::sleep_ms; +use stacks_common::util::{get_epoch_time_secs, sleep_ms}; use crate::burnchains::BurnchainTip; use crate::Config; -use std::sync::{ - atomic::{AtomicBool, AtomicU64, Ordering}, - Arc, -}; - // amount of time to wait for an inv or download sync to complete. // These _really should_ complete before the PoX sync watchdog permits processing the next reward // cycle, so this number is intentionally high (like, there's something really wrong with your diff --git a/testnet/stacks-node/src/tenure.rs b/testnet/stacks-node/src/tenure.rs index 011e1fbcd3..882a65d06b 100644 --- a/testnet/stacks-node/src/tenure.rs +++ b/testnet/stacks-node/src/tenure.rs @@ -1,7 +1,3 @@ -/// Only used by the Helium (Mocknet) node -use super::node::ChainTip; -use super::{BurnchainTip, Config}; - use std::thread; use std::time::{Duration, Instant}; @@ -11,15 +7,20 @@ use stacks::burnchains::PoxConstants; use stacks::chainstate::burn::db::sortdb::SortitionDB; use stacks::chainstate::burn::db::sortdb::SortitionDBConn; use stacks::chainstate::stacks::db::StacksChainState; +use stacks::chainstate::stacks::miner::BlockBuilderSettings; use stacks::chainstate::stacks::{ - miner::BlockBuilderSettings, StacksBlock, StacksBlockBuilder, StacksMicroblock, - StacksPrivateKey, StacksPublicKey, StacksTransaction, + StacksBlock, StacksBlockBuilder, StacksMicroblock, StacksPrivateKey, StacksPublicKey, + StacksTransaction, }; use stacks::core::mempool::MemPoolDB; use stacks_common::types::chainstate::VRFSeed; use stacks_common::util::hash::Hash160; use stacks_common::util::vrf::VRFProof; +/// Only used by the Helium (Mocknet) node +use super::node::ChainTip; +use super::{BurnchainTip, Config}; + pub struct TenureArtifacts { pub anchored_block: StacksBlock, pub microblocks: Vec, diff --git a/testnet/stacks-node/src/tests/bitcoin_regtest.rs b/testnet/stacks-node/src/tests/bitcoin_regtest.rs index ff9cc45767..fdb09dd22c 100644 --- a/testnet/stacks-node/src/tests/bitcoin_regtest.rs +++ b/testnet/stacks-node/src/tests/bitcoin_regtest.rs @@ -1,10 +1,8 @@ +use std::env; +use std::io::{BufRead, BufReader}; use std::process::{Child, Command, Stdio}; -use crate::config::InitialBalance; -use crate::helium::RunLoop; -use crate::tests::to_addr; -use crate::Config; - +use clarity::vm::costs::ExecutionCost; use stacks::chainstate::burn::operations::BlockstackOperationType::{ LeaderBlockCommit, LeaderKeyRegister, }; @@ -13,9 +11,10 @@ use stacks::core::StacksEpochId; use stacks_common::util::hash::hex_bytes; use super::PUBLISH_CONTRACT; -use clarity::vm::costs::ExecutionCost; -use std::env; -use std::io::{BufRead, BufReader}; +use crate::config::InitialBalance; +use crate::helium::RunLoop; +use crate::tests::to_addr; +use crate::Config; pub enum BitcoinCoreError { SpawnFailed(String), diff --git a/testnet/stacks-node/src/tests/epoch_205.rs b/testnet/stacks-node/src/tests/epoch_205.rs index 50601eb3da..60577cb690 100644 --- a/testnet/stacks-node/src/tests/epoch_205.rs +++ b/testnet/stacks-node/src/tests/epoch_205.rs @@ -1,54 +1,40 @@ use std::collections::HashMap; -use std::env; +use std::convert::TryFrom; use std::sync::atomic::Ordering; -use std::thread; +use std::{env, thread}; +use clarity::vm::costs::ExecutionCost; use clarity::vm::types::PrincipalData; use clarity::vm::ContractName; -use stacks::burnchains::Burnchain; -use stacks::burnchains::Txid; -use stacks::chainstate::burn::operations::BlockstackOperationType; +use stacks::burnchains::{Burnchain, Txid}; +use stacks::chainstate::burn::operations::leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS; +use stacks::chainstate::burn::operations::{BlockstackOperationType, LeaderBlockCommitOp}; +use stacks::chainstate::stacks::address::PoxAddress; use stacks::chainstate::stacks::db::StacksChainState; -use stacks::chainstate::stacks::StacksBlockHeader; -use stacks::chainstate::stacks::StacksPrivateKey; -use stacks::chainstate::stacks::StacksTransaction; -use stacks::chainstate::stacks::TransactionPayload; -use stacks::core::StacksEpoch; -use stacks::core::StacksEpochId; +use stacks::chainstate::stacks::{ + StacksBlockHeader, StacksPrivateKey, StacksTransaction, TransactionPayload, +}; +use stacks::core; use stacks::core::{ - PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, + StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, + PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, }; use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::StacksAddress; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, VRFSeed, +}; use stacks_common::util::hash::hex_bytes; use stacks_common::util::sleep_ms; -use std::convert::TryFrom; -use crate::config::EventKeyType; -use crate::config::EventObserverConfig; -use crate::config::InitialBalance; -use crate::neon; +use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; use crate::tests::bitcoin_regtest::BitcoinCoreController; -use crate::tests::make_contract_call; -use crate::tests::make_contract_call_mblock_only; -use crate::tests::make_contract_publish; -use crate::tests::make_contract_publish_microblock_only; use crate::tests::neon_integrations::*; -use crate::tests::run_until_burnchain_height; -use crate::tests::select_transactions_where; -use crate::tests::to_addr; -use crate::BitcoinRegtestController; -use crate::BurnchainController; -use crate::Keychain; -use stacks::core; - -use clarity::vm::costs::ExecutionCost; -use stacks::chainstate::burn::operations::leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS; -use stacks::chainstate::burn::operations::LeaderBlockCommitOp; -use stacks::chainstate::stacks::address::PoxAddress; -use stacks_common::types::chainstate::VRFSeed; +use crate::tests::{ + make_contract_call, make_contract_call_mblock_only, make_contract_publish, + make_contract_publish_microblock_only, run_until_burnchain_height, select_transactions_where, + to_addr, +}; +use crate::{neon, BitcoinRegtestController, BurnchainController, Keychain}; #[test] #[ignore] diff --git a/testnet/stacks-node/src/tests/epoch_21.rs b/testnet/stacks-node/src/tests/epoch_21.rs index 12f00bf066..fb73916964 100644 --- a/testnet/stacks-node/src/tests/epoch_21.rs +++ b/testnet/stacks-node/src/tests/epoch_21.rs @@ -1,75 +1,50 @@ -use std::collections::HashMap; -use std::collections::HashSet; -use std::env; -use std::thread; - -use stacks::burnchains::Burnchain; -use stacks::chainstate::stacks::db::StacksChainState; -use stacks::chainstate::stacks::StacksBlockHeader; -use stacks_common::types::chainstate::StacksAddress; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; - -use crate::config::Config; -use crate::config::EventKeyType; -use crate::config::EventObserverConfig; -use crate::config::InitialBalance; -use crate::neon; -use crate::neon::RunLoopCounter; -use crate::tests::bitcoin_regtest::BitcoinCoreController; -use crate::tests::neon_integrations::*; -use crate::tests::*; -use crate::BitcoinRegtestController; -use crate::BurnchainController; -use stacks::core; - -use stacks::chainstate::burn::db::sortdb::SortitionDB; -use stacks::chainstate::burn::operations::leader_block_commit::BURN_BLOCK_MINED_AT_MODULUS; -use stacks::chainstate::burn::operations::leader_block_commit::OUTPUTS_PER_COMMIT; -use stacks::chainstate::burn::operations::BlockstackOperationType; -use stacks::chainstate::burn::operations::LeaderBlockCommitOp; -use stacks::chainstate::burn::operations::PreStxOp; -use stacks::chainstate::burn::operations::TransferStxOp; - -use stacks::chainstate::stacks::address::PoxAddress; +use std::collections::{HashMap, HashSet}; +use std::{env, thread}; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; +use clarity::vm::ClarityVersion; use stacks::burnchains::bitcoin::address::{ BitcoinAddress, LegacyBitcoinAddressType, SegwitBitcoinAddress, }; use stacks::burnchains::bitcoin::BitcoinNetworkType; -use stacks::burnchains::PoxConstants; -use stacks::burnchains::Txid; - -use crate::stacks_common::address::AddressHashMode; -use crate::stacks_common::types::Address; -use crate::stacks_common::util::hash::{bytes_to_hex, hex_bytes}; - -use stacks_common::types::chainstate::BlockHeaderHash; -use stacks_common::types::chainstate::BurnchainHeaderHash; -use stacks_common::types::chainstate::VRFSeed; -use stacks_common::types::PrivateKey; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::Sha256Sum; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - +use stacks::burnchains::{Burnchain, PoxConstants, Txid}; +use stacks::chainstate::burn::db::sortdb::SortitionDB; +use stacks::chainstate::burn::operations::leader_block_commit::{ + BURN_BLOCK_MINED_AT_MODULUS, OUTPUTS_PER_COMMIT, +}; +use stacks::chainstate::burn::operations::{ + BlockstackOperationType, LeaderBlockCommitOp, PreStxOp, TransferStxOp, +}; use stacks::chainstate::coordinator::comm::CoordinatorChannels; -use stacks::chainstate::stacks::miner::set_mining_spend_amount; -use stacks::chainstate::stacks::miner::signal_mining_blocked; -use stacks::chainstate::stacks::miner::signal_mining_ready; - +use stacks::chainstate::stacks::address::PoxAddress; +use stacks::chainstate::stacks::db::StacksChainState; +use stacks::chainstate::stacks::miner::{ + set_mining_spend_amount, signal_mining_blocked, signal_mining_ready, +}; +use stacks::chainstate::stacks::StacksBlockHeader; use stacks::clarity_cli::vm_execute as execute; - -use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; -use clarity::vm::ClarityVersion; +use stacks::core; use stacks::core::BURNCHAIN_TX_SEARCH_WINDOW; +use stacks::util_lib::boot::boot_code_id; +use stacks_common::types::chainstate::{ + BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, VRFSeed, +}; +use stacks_common::types::PrivateKey; +use stacks_common::util::hash::{Hash160, Sha256Sum}; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; +use stacks_common::util::sleep_ms; use crate::burnchains::bitcoin_regtest_controller::UTXO; +use crate::config::{Config, EventKeyType, EventObserverConfig, InitialBalance}; +use crate::neon::RunLoopCounter; use crate::operations::BurnchainOpSigner; -use crate::Keychain; - -use stacks_common::util::sleep_ms; - -use stacks::util_lib::boot::boot_code_id; -use stacks_common::types::chainstate::StacksBlockId; +use crate::stacks_common::address::AddressHashMode; +use crate::stacks_common::types::Address; +use crate::stacks_common::util::hash::{bytes_to_hex, hex_bytes}; +use crate::tests::bitcoin_regtest::BitcoinCoreController; +use crate::tests::neon_integrations::*; +use crate::tests::*; +use crate::{neon, BitcoinRegtestController, BurnchainController, Keychain}; const MINER_BURN_PUBLIC_KEY: &'static str = "03dc62fe0b8964d01fc9ca9a5eec0e22e557a12cc656919e648f04e0b26fea5faa"; diff --git a/testnet/stacks-node/src/tests/epoch_22.rs b/testnet/stacks-node/src/tests/epoch_22.rs index a0bab09e58..4e817452b9 100644 --- a/testnet/stacks-node/src/tests/epoch_22.rs +++ b/testnet/stacks-node/src/tests/epoch_22.rs @@ -1,46 +1,32 @@ use std::collections::HashMap; -use std::env; -use std::thread; +use std::{env, thread}; -use stacks::burnchains::Burnchain; +use clarity::vm::types::PrincipalData; +use clarity::vm::ClarityVersion; +use stacks::burnchains::{Burnchain, PoxConstants}; use stacks::chainstate::stacks::address::PoxAddress; use stacks::chainstate::stacks::db::StacksChainState; -use stacks::chainstate::stacks::miner::signal_mining_blocked; -use stacks::chainstate::stacks::miner::signal_mining_ready; +use stacks::chainstate::stacks::miner::{signal_mining_blocked, signal_mining_ready}; +use stacks::clarity_cli::vm_execute as execute; +use stacks::core; use stacks::core::STACKS_EPOCH_MAX; -use stacks_common::types::chainstate::StacksAddress; +use stacks::util_lib::boot::boot_code_id; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; use stacks_common::types::PrivateKey; +use stacks_common::util::hash::Hash160; +use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::sleep_ms; -use crate::config::EventKeyType; -use crate::config::EventObserverConfig; -use crate::config::InitialBalance; -use crate::neon; +use super::neon_integrations::get_account; +use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; use crate::neon_node::StacksNode; +use crate::stacks_common::types::Address; +use crate::stacks_common::util::hash::bytes_to_hex; use crate::tests::bitcoin_regtest::BitcoinCoreController; use crate::tests::epoch_21::wait_pox_stragglers; use crate::tests::neon_integrations::*; use crate::tests::*; -use crate::BitcoinRegtestController; -use crate::BurnchainController; -use stacks::core; - -use super::neon_integrations::get_account; -use crate::stacks_common::types::Address; -use crate::stacks_common::util::hash::bytes_to_hex; -use stacks::burnchains::PoxConstants; - -use stacks_common::util::hash::Hash160; -use stacks_common::util::secp256k1::Secp256k1PublicKey; - -use stacks::clarity_cli::vm_execute as execute; - -use clarity::vm::types::PrincipalData; -use clarity::vm::ClarityVersion; - -use stacks_common::util::sleep_ms; - -use stacks::util_lib::boot::boot_code_id; -use stacks_common::types::chainstate::StacksBlockId; +use crate::{neon, BitcoinRegtestController, BurnchainController}; #[test] #[ignore] diff --git a/testnet/stacks-node/src/tests/epoch_23.rs b/testnet/stacks-node/src/tests/epoch_23.rs index 2b4d817e10..73a731a5bc 100644 --- a/testnet/stacks-node/src/tests/epoch_23.rs +++ b/testnet/stacks-node/src/tests/epoch_23.rs @@ -14,28 +14,19 @@ // along with this program. If not, see . use std::collections::HashMap; -use std::env; -use std::thread; +use std::{env, thread}; -use clarity::vm::types::QualifiedContractIdentifier; -use stacks::burnchains::Burnchain; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; +use stacks::burnchains::{Burnchain, PoxConstants}; +use stacks::core; use stacks::core::STACKS_EPOCH_MAX; use stacks_common::util::sleep_ms; -use crate::config::EventKeyType; -use crate::config::EventObserverConfig; -use crate::config::InitialBalance; -use crate::neon; +use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; use crate::tests::bitcoin_regtest::BitcoinCoreController; use crate::tests::neon_integrations::*; use crate::tests::*; -use crate::BitcoinRegtestController; -use crate::BurnchainController; -use stacks::core; - -use stacks::burnchains::PoxConstants; - -use clarity::vm::types::PrincipalData; +use crate::{neon, BitcoinRegtestController, BurnchainController}; #[test] #[ignore] diff --git a/testnet/stacks-node/src/tests/epoch_24.rs b/testnet/stacks-node/src/tests/epoch_24.rs index a3dd6f95e2..97f9744223 100644 --- a/testnet/stacks-node/src/tests/epoch_24.rs +++ b/testnet/stacks-node/src/tests/epoch_24.rs @@ -13,12 +13,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; -use crate::tests::neon_integrations::{ - get_account, get_chain_info, get_pox_info, neon_integration_test_conf, next_block_and_wait, - submit_tx, test_observer, wait_for_runloop, -}; -use crate::tests::{make_contract_call, to_addr}; +use std::collections::HashMap; +use std::{env, thread}; + use clarity::boot_util::boot_code_id; use clarity::vm::types::PrincipalData; use clarity::vm::{ClarityVersion, Value}; @@ -28,23 +25,26 @@ use stacks::chainstate::stacks::address::PoxAddress; use stacks::chainstate::stacks::boot::RawRewardSetEntry; use stacks::chainstate::stacks::db::StacksChainState; use stacks::chainstate::stacks::{Error, StacksTransaction, TransactionPayload}; -use stacks_common::types::chainstate::{StacksAddress, StacksBlockId, StacksPrivateKey}; -use stacks_common::util::hash::{bytes_to_hex, hex_bytes, Hash160}; -use stacks_common::util::secp256k1::Secp256k1PublicKey; -use std::collections::HashMap; -use std::{env, thread}; - -use crate::tests::bitcoin_regtest::BitcoinCoreController; -use crate::{neon, BitcoinRegtestController, BurnchainController}; use stacks::clarity_cli::vm_execute as execute; use stacks::core; - use stacks_common::address::{AddressHashMode, C32_ADDRESS_VERSION_TESTNET_SINGLESIG}; use stacks_common::codec::StacksMessageCodec; use stacks_common::consts::STACKS_EPOCH_MAX; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId, StacksPrivateKey}; use stacks_common::types::Address; +use stacks_common::util::hash::{bytes_to_hex, hex_bytes, Hash160}; +use stacks_common::util::secp256k1::Secp256k1PublicKey; use stacks_common::util::sleep_ms; +use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; +use crate::tests::bitcoin_regtest::BitcoinCoreController; +use crate::tests::neon_integrations::{ + get_account, get_chain_info, get_pox_info, neon_integration_test_conf, next_block_and_wait, + submit_tx, test_observer, wait_for_runloop, +}; +use crate::tests::{make_contract_call, to_addr}; +use crate::{neon, BitcoinRegtestController, BurnchainController}; + #[cfg(test)] pub fn get_reward_set_entries_at_block( state: &mut StacksChainState, diff --git a/testnet/stacks-node/src/tests/integrations.rs b/testnet/stacks-node/src/tests/integrations.rs index dfa15ed945..c2057d6430 100644 --- a/testnet/stacks-node/src/tests/integrations.rs +++ b/testnet/stacks-node/src/tests/integrations.rs @@ -2,51 +2,44 @@ use std::collections::HashMap; use std::fmt::Write; use std::sync::Mutex; -use reqwest; - -use crate::config::InitialBalance; -use crate::helium::RunLoop; -use crate::tests::make_sponsored_stacks_transfer_on_testnet; +use clarity::vm::analysis::contract_interface_builder::{ + build_contract_interface, ContractInterface, +}; +use clarity::vm::analysis::mem_type_check; use clarity::vm::costs::ExecutionCost; -use clarity::vm::types::StacksAddressExtensions; -use clarity::vm::ClarityVersion; -use clarity::vm::{ - analysis::{ - contract_interface_builder::{build_contract_interface, ContractInterface}, - mem_type_check, - }, - types::{QualifiedContractIdentifier, ResponseData, TupleData}, - Value, +use clarity::vm::types::{ + QualifiedContractIdentifier, ResponseData, StacksAddressExtensions, TupleData, }; +use clarity::vm::{ClarityVersion, Value}; +use reqwest; use stacks::burnchains::Address; -use stacks::chainstate::stacks::db::blocks::MINIMUM_TX_FEE_RATE_PER_BYTE; +use stacks::chainstate::stacks::db::blocks::{MemPoolRejection, MINIMUM_TX_FEE_RATE_PER_BYTE}; +use stacks::chainstate::stacks::db::StacksChainState; use stacks::chainstate::stacks::{ - db::blocks::MemPoolRejection, db::StacksChainState, StacksBlockHeader, StacksPrivateKey, - StacksTransaction, + StacksBlockHeader, StacksPrivateKey, StacksTransaction, TokenTransferMemo, + TransactionContractCall, TransactionPayload, }; -use stacks::chainstate::stacks::{TokenTransferMemo, TransactionContractCall, TransactionPayload}; use stacks::clarity_vm::clarity::ClarityConnection; use stacks::core::mempool::MAXIMUM_MEMPOOL_TX_CHAINING; -use stacks::core::StacksEpoch; -use stacks::core::StacksEpochId; -use stacks::core::PEER_VERSION_EPOCH_2_0; -use stacks::core::PEER_VERSION_EPOCH_2_05; -use stacks::core::PEER_VERSION_EPOCH_2_1; -use stacks::net::api::{ - callreadonly::CallReadOnlyRequestBody, getaccount::AccountEntryResponse, - getcontractsrc::ContractSrcResponse, getistraitimplemented::GetIsTraitImplementedResponse, +use stacks::core::{ + StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, + PEER_VERSION_EPOCH_2_1, }; +use stacks::net::api::callreadonly::CallReadOnlyRequestBody; +use stacks::net::api::getaccount::AccountEntryResponse; +use stacks::net::api::getcontractsrc::ContractSrcResponse; +use stacks::net::api::getistraitimplemented::GetIsTraitImplementedResponse; use stacks_common::codec::StacksMessageCodec; -use stacks_common::types::chainstate::{StacksAddress, VRFSeed}; -use stacks_common::util::hash::Sha256Sum; -use stacks_common::util::hash::{hex_bytes, to_hex}; - -use stacks_common::types::chainstate::StacksBlockId; +use stacks_common::types::chainstate::{StacksAddress, StacksBlockId, VRFSeed}; +use stacks_common::util::hash::{hex_bytes, to_hex, Sha256Sum}; use super::{ make_contract_call, make_contract_publish, make_stacks_transfer, to_addr, ADDR_4, SK_1, SK_2, SK_3, }; +use crate::config::InitialBalance; +use crate::helium::RunLoop; +use crate::tests::make_sponsored_stacks_transfer_on_testnet; const OTHER_CONTRACT: &'static str = " (define-data-var x uint u0) diff --git a/testnet/stacks-node/src/tests/mempool.rs b/testnet/stacks-node/src/tests/mempool.rs index 1b65aa37e4..d55c024aa0 100644 --- a/testnet/stacks-node/src/tests/mempool.rs +++ b/testnet/stacks-node/src/tests/mempool.rs @@ -1,38 +1,35 @@ -use std::convert::From; -use std::convert::TryFrom; +use std::convert::{From, TryFrom}; use std::sync::Mutex; +use clarity::vm::costs::ExecutionCost; use clarity::vm::database::NULL_BURN_STATE_DB; -use clarity::vm::{ - representations::ContractName, types::PrincipalData, types::QualifiedContractIdentifier, - types::StandardPrincipalData, Value, -}; -use stacks::chainstate::stacks::TransactionAnchorMode; +use clarity::vm::representations::ContractName; +use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, StandardPrincipalData}; +use clarity::vm::Value; +use stacks::chainstate::stacks::db::blocks::MemPoolRejection; use stacks::chainstate::stacks::{ - db::blocks::MemPoolRejection, Error as ChainstateError, StacksBlockHeader, - StacksMicroblockHeader, StacksPrivateKey, StacksPublicKey, StacksTransaction, - StacksTransactionSigner, TokenTransferMemo, TransactionAuth, TransactionPayload, - TransactionSpendingCondition, TransactionVersion, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, + Error as ChainstateError, StacksBlockHeader, StacksMicroblockHeader, StacksPrivateKey, + StacksPublicKey, StacksTransaction, StacksTransactionSigner, TokenTransferMemo, + TransactionAnchorMode, TransactionAuth, TransactionPayload, TransactionSpendingCondition, + TransactionVersion, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, }; use stacks::core::mempool::MemPoolDB; -use stacks::core::CHAIN_ID_TESTNET; +use stacks::core::{StacksEpochId, CHAIN_ID_TESTNET}; use stacks::cost_estimates::metrics::UnitMetric; use stacks::cost_estimates::UnitEstimator; use stacks::net::Error as NetError; use stacks_common::address::AddressHashMode; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress}; -use stacks_common::util::{hash::*, secp256k1::*}; - -use crate::helium::RunLoop; -use crate::Keychain; -use clarity::vm::costs::ExecutionCost; -use stacks::core::StacksEpochId; +use stacks_common::util::hash::*; +use stacks_common::util::secp256k1::*; use super::{ make_coinbase, make_contract_call, make_contract_publish, make_poison, make_stacks_transfer, serialize_sign_standard_single_sig_tx_anchor_mode_version, to_addr, SK_1, SK_2, }; +use crate::helium::RunLoop; +use crate::Keychain; const FOO_CONTRACT: &'static str = "(define-public (foo) (ok 1)) (define-public (bar (x uint)) (ok x))"; diff --git a/testnet/stacks-node/src/tests/mod.rs b/testnet/stacks-node/src/tests/mod.rs index b87ed2c739..03f61b5e4c 100644 --- a/testnet/stacks-node/src/tests/mod.rs +++ b/testnet/stacks-node/src/tests/mod.rs @@ -2,41 +2,36 @@ use std::convert::TryInto; use std::sync::atomic::AtomicU64; use std::sync::Arc; -use rand::RngCore; - use clarity::vm::costs::ExecutionCost; use clarity::vm::database::BurnStateDB; use clarity::vm::events::STXEventType; use clarity::vm::types::PrincipalData; use clarity::vm::{ClarityName, ContractName, Value}; +use rand::RngCore; use stacks::chainstate::burn::ConsensusHash; +use stacks::chainstate::stacks::db::StacksChainState; use stacks::chainstate::stacks::events::StacksTransactionEvent; +use stacks::chainstate::stacks::miner::{BlockBuilderSettings, StacksMicroblockBuilder}; use stacks::chainstate::stacks::{ - db::StacksChainState, miner::BlockBuilderSettings, miner::StacksMicroblockBuilder, CoinbasePayload, StacksBlock, StacksMicroblock, StacksMicroblockHeader, StacksPrivateKey, StacksPublicKey, StacksTransaction, StacksTransactionSigner, TokenTransferMemo, TransactionAnchorMode, TransactionAuth, TransactionContractCall, TransactionPayload, TransactionPostConditionMode, TransactionSmartContract, TransactionSpendingCondition, TransactionVersion, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; -use stacks::core::CHAIN_ID_TESTNET; +use stacks::core::{StacksEpoch, StacksEpochExtension, StacksEpochId, CHAIN_ID_TESTNET}; use stacks::util_lib::strings::StacksString; +use stacks_common::address::AddressHashMode; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::StacksAddress; use stacks_common::util::get_epoch_time_secs; -use stacks_common::util::hash::hex_bytes; -use stacks_common::{address::AddressHashMode, util::hash::to_hex}; - -use crate::helium::RunLoop; -use crate::tests::neon_integrations::get_chain_info; -use crate::tests::neon_integrations::next_block_and_wait; -use crate::BitcoinRegtestController; -use stacks::core::StacksEpoch; -use stacks::core::StacksEpochExtension; -use stacks::core::StacksEpochId; +use stacks_common::util::hash::{hex_bytes, to_hex}; use super::burnchains::bitcoin_regtest_controller::ParsedUTXO; use super::Config; +use crate::helium::RunLoop; +use crate::tests::neon_integrations::{get_chain_info, next_block_and_wait}; +use crate::BitcoinRegtestController; mod atlas; mod bitcoin_regtest; diff --git a/testnet/stacks-node/src/tests/neon_integrations.rs b/testnet/stacks-node/src/tests/neon_integrations.rs index 049b92e92a..e9664e46dc 100644 --- a/testnet/stacks-node/src/tests/neon_integrations.rs +++ b/testnet/stacks-node/src/tests/neon_integrations.rs @@ -1,30 +1,37 @@ -use std::cmp; -use std::fs; +use std::collections::{HashMap, HashSet}; +use std::convert::TryFrom; use std::path::Path; -use std::sync::mpsc; -use std::sync::Arc; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::{mpsc, Arc}; use std::time::{Duration, Instant}; -use std::{ - collections::HashMap, - collections::HashSet, - sync::atomic::{AtomicU64, Ordering}, -}; -use std::{env, thread}; - -use rusqlite::types::ToSql; +use std::{cmp, env, fs, thread}; +use clarity::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; +use clarity::vm::ast::ASTRules; use clarity::vm::costs::ExecutionCost; use clarity::vm::types::PrincipalData; -use clarity::vm::ClarityVersion; -use clarity::vm::Value; +use clarity::vm::{ClarityName, ClarityVersion, ContractName, Value, MAX_CALL_STACK_DEPTH}; +use rand::Rng; +use rusqlite::types::ToSql; use stacks::burnchains::bitcoin::address::{BitcoinAddress, LegacyBitcoinAddressType}; use stacks::burnchains::bitcoin::BitcoinNetworkType; -use stacks::burnchains::Txid; -use stacks::burnchains::{Address, Burnchain, PoxConstants}; +use stacks::burnchains::db::BurnchainDB; +use stacks::burnchains::{Address, Burnchain, PoxConstants, Txid}; +use stacks::chainstate::burn::db::sortdb::SortitionDB; use stacks::chainstate::burn::operations::{ BlockstackOperationType, DelegateStxOp, PreStxOp, TransferStxOp, }; +use stacks::chainstate::burn::ConsensusHash; use stacks::chainstate::coordinator::comm::CoordinatorChannels; +use stacks::chainstate::stacks::db::StacksChainState; +use stacks::chainstate::stacks::miner::{ + signal_mining_blocked, signal_mining_ready, TransactionErrorEvent, TransactionEvent, + TransactionSuccessEvent, +}; +use stacks::chainstate::stacks::{ + StacksBlock, StacksBlockHeader, StacksMicroblock, StacksMicroblockHeader, StacksPrivateKey, + StacksPublicKey, StacksTransaction, TransactionContractCall, TransactionPayload, +}; use stacks::clarity_cli::vm_execute as execute; use stacks::core; use stacks::core::{ @@ -32,75 +39,43 @@ use stacks::core::{ BLOCK_LIMIT_MAINNET_21, CHAIN_ID_TESTNET, HELIUM_BLOCK_LIMIT_20, PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, }; -use stacks::net::api::{ - getaccount::AccountEntryResponse, getcontractsrc::ContractSrcResponse, - getinfo::RPCPeerInfoData, getpoxinfo::RPCPoxInfoData, - gettransaction_unconfirmed::UnconfirmedTransactionResponse, postblock::StacksBlockAcceptedData, - postfeerate::RPCFeeEstimateResponse, posttransaction::PostTransactionRequestBody, +use stacks::net::api::getaccount::AccountEntryResponse; +use stacks::net::api::getcontractsrc::ContractSrcResponse; +use stacks::net::api::getinfo::RPCPeerInfoData; +use stacks::net::api::getpoxinfo::RPCPoxInfoData; +use stacks::net::api::gettransaction_unconfirmed::UnconfirmedTransactionResponse; +use stacks::net::api::postblock::StacksBlockAcceptedData; +use stacks::net::api::postfeerate::RPCFeeEstimateResponse; +use stacks::net::api::posttransaction::PostTransactionRequestBody; +use stacks::net::atlas::{ + AtlasConfig, AtlasDB, GetAttachmentResponse, GetAttachmentsInvResponse, + MAX_ATTACHMENT_INV_PAGES_PER_REQUEST, }; -use stacks::net::atlas::GetAttachmentResponse; -use stacks::net::atlas::GetAttachmentsInvResponse; -use stacks::net::atlas::{AtlasConfig, AtlasDB, MAX_ATTACHMENT_INV_PAGES_PER_REQUEST}; use stacks::util_lib::boot::boot_code_id; -use stacks::{ - burnchains::db::BurnchainDB, - chainstate::{burn::ConsensusHash, stacks::StacksMicroblock}, -}; -use stacks::{ - chainstate::stacks::{ - db::StacksChainState, StacksBlock, StacksBlockHeader, StacksMicroblockHeader, - StacksPrivateKey, StacksPublicKey, StacksTransaction, TransactionContractCall, - TransactionPayload, - }, - util_lib::db::query_row_columns, - util_lib::db::query_rows, - util_lib::db::u64_to_sql, -}; +use stacks::util_lib::db::{query_row_columns, query_rows, u64_to_sql}; use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, }; -use stacks_common::util::hash::Hash160; -use stacks_common::util::hash::{bytes_to_hex, hex_bytes, to_hex}; -use stacks_common::util::secp256k1::Secp256k1PrivateKey; -use stacks_common::util::secp256k1::Secp256k1PublicKey; +use stacks_common::util::hash::{bytes_to_hex, hex_bytes, to_hex, Hash160}; +use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs, sleep_ms}; -use crate::{ - burnchains::bitcoin_regtest_controller::BitcoinRPCRequest, - burnchains::bitcoin_regtest_controller::UTXO, config::EventKeyType, - config::EventObserverConfig, config::InitialBalance, neon, operations::BurnchainOpSigner, - syncctl::PoxSyncWatchdogComms, BitcoinRegtestController, BurnchainController, Config, - ConfigFile, Keychain, -}; - -use crate::util::hash::{MerkleTree, Sha512Trunc256Sum}; -use crate::util::secp256k1::MessageSignature; - -use rand::Rng; - use super::bitcoin_regtest::BitcoinCoreController; use super::{ make_contract_call, make_contract_publish, make_contract_publish_microblock_only, make_microblock, make_stacks_transfer, make_stacks_transfer_mblock_only, to_addr, ADDR_4, SK_1, SK_2, }; - -use crate::config::FeeEstimatorName; -use crate::tests::SK_3; -use clarity::vm::ast::stack_depth_checker::AST_CALL_STACK_DEPTH_BUFFER; -use clarity::vm::ast::ASTRules; -use clarity::vm::ClarityName; -use clarity::vm::ContractName; -use clarity::vm::MAX_CALL_STACK_DEPTH; -use stacks::chainstate::burn::db::sortdb::SortitionDB; -use stacks::chainstate::stacks::miner::{ - signal_mining_blocked, signal_mining_ready, TransactionErrorEvent, TransactionEvent, - TransactionSuccessEvent, -}; -use std::convert::TryFrom; - +use crate::burnchains::bitcoin_regtest_controller::{BitcoinRPCRequest, UTXO}; +use crate::config::{EventKeyType, EventObserverConfig, FeeEstimatorName, InitialBalance}; +use crate::operations::BurnchainOpSigner; use crate::stacks_common::types::PrivateKey; +use crate::syncctl::PoxSyncWatchdogComms; +use crate::tests::SK_3; +use crate::util::hash::{MerkleTree, Sha512Trunc256Sum}; +use crate::util::secp256k1::MessageSignature; +use crate::{neon, BitcoinRegtestController, BurnchainController, Config, ConfigFile, Keychain}; fn inner_neon_integration_test_conf(seed: Option>) -> (Config, StacksAddress) { let mut conf = super::new_test_conf(); @@ -202,9 +177,8 @@ pub mod test_observer { use std::sync::Mutex; use std::thread; - use tokio; - use warp; use warp::Filter; + use {tokio, warp}; use crate::event_dispatcher::{MinedBlockEvent, MinedMicroblockEvent, StackerDBChunksEvent}; diff --git a/testnet/stacks-node/src/tests/signer.rs b/testnet/stacks-node/src/tests/signer.rs index c99cbe0129..788474085b 100644 --- a/testnet/stacks-node/src/tests/signer.rs +++ b/testnet/stacks-node/src/tests/signer.rs @@ -2,33 +2,26 @@ use std::sync::mpsc::{channel, Receiver, Sender}; use std::time::Duration; use std::{env, thread}; -use crate::{ - config::{Config as NeonConfig, EventKeyType, EventObserverConfig, InitialBalance}, - neon, - tests::{ - bitcoin_regtest::BitcoinCoreController, - make_contract_publish, - neon_integrations::{ - neon_integration_test_conf, next_block_and_wait, submit_tx, wait_for_runloop, - }, - to_addr, - }, - BitcoinRegtestController, BurnchainController, -}; use clarity::vm::types::QualifiedContractIdentifier; use libsigner::{RunningSigner, Signer, StackerDBEventReceiver}; use stacks::chainstate::stacks::StacksPrivateKey; use stacks_common::types::chainstate::StacksAddress; -use stacks_signer::{ - config::Config as SignerConfig, - runloop::RunLoopCommand, - utils::{build_signer_config_tomls, build_stackerdb_contract}, -}; -use tracing_subscriber::{fmt, prelude::*, EnvFilter}; -use wsts::{ - state_machine::{coordinator::Coordinator as FrostCoordinator, OperationResult}, - v2, +use stacks_signer::config::Config as SignerConfig; +use stacks_signer::runloop::RunLoopCommand; +use stacks_signer::utils::{build_signer_config_tomls, build_stackerdb_contract}; +use tracing_subscriber::prelude::*; +use tracing_subscriber::{fmt, EnvFilter}; +use wsts::state_machine::coordinator::frost::Coordinator as FrostCoordinator; +use wsts::state_machine::OperationResult; +use wsts::v2; + +use crate::config::{Config as NeonConfig, EventKeyType, EventObserverConfig, InitialBalance}; +use crate::tests::bitcoin_regtest::BitcoinCoreController; +use crate::tests::neon_integrations::{ + neon_integration_test_conf, next_block_and_wait, submit_tx, wait_for_runloop, }; +use crate::tests::{make_contract_publish, to_addr}; +use crate::{neon, BitcoinRegtestController, BurnchainController}; // Helper struct for holding the btc and stx neon nodes #[allow(dead_code)] @@ -171,7 +164,7 @@ fn test_stackerdb_dkg() { .collect::>(); let signer_stacks_addresses = signer_stacks_private_keys .iter() - .map(|key| to_addr(key).into()) + .map(to_addr) .collect::>(); // Setup the neon node diff --git a/testnet/stacks-node/src/tests/stackerdb.rs b/testnet/stacks-node/src/tests/stackerdb.rs index 13371fd9dd..a38f98b767 100644 --- a/testnet/stacks-node/src/tests/stackerdb.rs +++ b/testnet/stacks-node/src/tests/stackerdb.rs @@ -14,39 +14,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::env; -use std::thread; - -use super::bitcoin_regtest::BitcoinCoreController; -use crate::{ - burnchains::BurnchainController, - config::EventKeyType, - config::EventObserverConfig, - config::InitialBalance, - neon, - tests::{ - make_contract_publish, - neon_integrations::{ - neon_integration_test_conf, next_block_and_wait, submit_tx, test_observer, - wait_for_runloop, - }, - to_addr, - }, - BitcoinRegtestController, -}; - -use stacks::chainstate::stacks::StacksPrivateKey; +use std::{env, thread}; use clarity::vm::types::QualifiedContractIdentifier; - +use stacks::chainstate::stacks::StacksPrivateKey; use stacks::libstackerdb::{StackerDBChunkAckData, StackerDBChunkData}; - use stacks_common::types::chainstate::StacksAddress; use stacks_common::util::hash::Sha512Trunc256Sum; +use {reqwest, serde_json}; -use serde_json; - -use reqwest; +use super::bitcoin_regtest::BitcoinCoreController; +use crate::burnchains::BurnchainController; +use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; +use crate::tests::neon_integrations::{ + neon_integration_test_conf, next_block_and_wait, submit_tx, test_observer, wait_for_runloop, +}; +use crate::tests::{make_contract_publish, to_addr}; +use crate::{neon, BitcoinRegtestController}; fn post_stackerdb_chunk( http_origin: &str,