From 8b79e8d265993e0f9b9bcd46323d5c791f60e0ce Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Tue, 19 Mar 2024 22:36:20 +0100 Subject: [PATCH 01/13] feat: update pox-4 txs --- Cargo.lock | 477 +++++++++++++++--- components/stacks-network/Cargo.toml | 8 +- .../stacks-network/src/chains_coordinator.rs | 326 +++++++++--- components/stacks-network/src/orchestrator.rs | 3 +- 4 files changed, 668 insertions(+), 146 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c30c3c62..4da39b206 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,7 +42,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cipher", "cpufeatures", ] @@ -67,7 +67,7 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "once_cell", "version_check", "zerocopy", @@ -109,7 +109,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -255,7 +255,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi 0.1.19", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -284,7 +284,7 @@ checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" dependencies = [ "addr2line 0.19.0", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object 0.30.3", @@ -363,6 +363,28 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.64.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 1.0.107", + "which", +] + [[package]] name = "bip39" version = "1.0.1" @@ -572,7 +594,7 @@ dependencies = [ "tokio", "tokio-util", "url", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -652,6 +674,21 @@ dependencies = [ "jobserver", ] +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -730,6 +767,17 @@ dependencies = [ "inout", ] +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading 0.8.3", +] + [[package]] name = "clap" version = "4.4.8" @@ -779,6 +827,19 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +[[package]] +name = "clar2wasm" +version = "0.1.0" +source = "git+https://github.com/stacks-network/clarity-wasm.git?branch=chore/update-clarity#d08b7628206b36f6d7a5e7a92a786ac007c8e7e6" +dependencies = [ + "clap", + "clarity", + "lazy_static", + "regex", + "walrus", + "wat", +] + [[package]] name = "clar2wasm" version = "0.1.0" @@ -825,7 +886,7 @@ dependencies = [ "libsecp256k1 0.7.1", "log", "mac_address", - "mio", + "mio 0.8.11", "nix 0.24.2", "num_cpus", "pbkdf2", @@ -850,7 +911,7 @@ dependencies = [ "tokio-util", "toml 0.5.11", "tower-lsp", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -944,7 +1005,7 @@ dependencies = [ "serde_derive", "serde_json", "serde_stacker", - "sha2-asm", + "sha2-asm 0.5.5", "slog", "stacks-common", "wasmtime", @@ -1012,7 +1073,7 @@ dependencies = [ "atty", "bytes", "chrono", - "clar2wasm", + "clar2wasm 0.1.0 (git+https://github.com/stacks-network/clarity-wasm.git)", "clarity", "debug_types", "futures", @@ -1071,7 +1132,7 @@ checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" dependencies = [ "error-code", "str-buf", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1098,7 +1159,7 @@ checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" dependencies = [ "atty", "lazy_static", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1117,7 +1178,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen", ] @@ -1160,7 +1221,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -1287,7 +1348,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -1305,7 +1366,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crossbeam-epoch", "crossbeam-utils", ] @@ -1317,7 +1378,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" dependencies = [ "autocfg", - "cfg-if", + "cfg-if 1.0.0", "crossbeam-utils", "memoffset 0.9.0", "scopeguard", @@ -1338,11 +1399,11 @@ dependencies = [ "bitflags 2.4.0", "crossterm_winapi", "libc", - "mio", + "mio 0.8.11", "parking_lot", "signal-hook", "signal-hook-mio", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1351,7 +1412,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1457,7 +1518,7 @@ version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "curve25519-dalek-derive", "digest 0.10.7", @@ -1529,7 +1590,7 @@ version = "5.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "hashbrown 0.12.3", "lock_api", "once_cell", @@ -1644,7 +1705,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "dirs-sys-next", ] @@ -1663,7 +1724,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "dirs-sys-next", ] @@ -1675,7 +1736,7 @@ checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ "libc", "redox_users", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1686,7 +1747,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", "redox_users", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1739,7 +1800,7 @@ version = "0.8.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -1835,7 +1896,7 @@ version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ef1a30ae415c3a691a4f41afddc2dbcd6d70baf338368d85ebc1e8ed92cedb9" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "rustix 0.36.16", "windows-sys 0.45.0", ] @@ -1887,6 +1948,22 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags 1.3.2", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + [[package]] name = "funty" version = "2.0.0" @@ -2052,7 +2129,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] @@ -2063,7 +2140,7 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", @@ -2436,7 +2513,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2547,6 +2624,15 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + [[package]] name = "ipnet" version = "2.7.1" @@ -2665,12 +2751,28 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "lazy_static" 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 = "leb128" version = "0.2.5" @@ -2689,8 +2791,18 @@ version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" dependencies = [ - "cfg-if", - "winapi", + "cfg-if 1.0.0", + "winapi 0.3.9", +] + +[[package]] +name = "libloading" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +dependencies = [ + "cfg-if 1.0.0", + "windows-targets 0.48.5", ] [[package]] @@ -2816,6 +2928,20 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "libstackerdb" +version = "0.0.1" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#1173e5a52db07a72e6881dcb466a4218e7b9fa24" +dependencies = [ + "clarity", + "secp256k1 0.24.3", + "serde", + "serde_derive", + "serde_stacker", + "sha2 0.10.6", + "stacks-common", +] + [[package]] name = "link-cplusplus" version = "1.0.8" @@ -2859,7 +2985,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "serde", ] @@ -2869,7 +2995,7 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "generator", "scoped-tls", "serde", @@ -2907,7 +3033,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b238e3235c8382b7653c6408ed1b08dd379bdb9fdf990fb0bbae3db2cc0ae963" dependencies = [ "nix 0.23.2", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2990,6 +3116,12 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniscript" version = "11.0.0" @@ -3010,6 +3142,25 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +dependencies = [ + "cfg-if 0.1.10", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow", + "net2", + "slab", + "winapi 0.2.8", +] + [[package]] name = "mio" version = "0.8.11" @@ -3022,6 +3173,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "miow" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", +] + [[package]] name = "multer" version = "2.1.0" @@ -3078,11 +3241,22 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02662cd2e62b131937bdef85d0918b05bc3c204daf4c64af62845403eccb60f3" dependencies = [ - "cfg-if", - "libloading", + "cfg-if 1.0.0", + "libloading 0.6.7", "smallvec 1.10.0", ] +[[package]] +name = "net2" +version = "0.2.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b13b648036a2339d06de780866fbdfda0dde886de7b3af2ddeba8b14f4ee34ac" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "winapi 0.3.9", +] + [[package]] name = "nibble_vec" version = "0.1.0" @@ -3100,7 +3274,7 @@ checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ "bitflags 1.3.2", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "memoffset 0.6.5", ] @@ -3112,7 +3286,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" dependencies = [ "bitflags 1.3.2", - "cfg-if", + "cfg-if 1.0.0", "libc", "memoffset 0.6.5", ] @@ -3124,7 +3298,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ "bitflags 1.3.2", - "cfg-if", + "cfg-if 1.0.0", "libc", "static_assertions", ] @@ -3135,6 +3309,16 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[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" @@ -3142,7 +3326,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" dependencies = [ "overload", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -3279,6 +3463,29 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "p256k1" +version = "5.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e81c2cb5a1936d3f26278f9d698932239d03ddf0d5818392d91cd5f98ffc79" +dependencies = [ + "bindgen", + "bitvec", + "bs58 0.4.0", + "cc", + "hex 0.4.3", + "itertools 0.10.5", + "num-traits", + "primitive-types", + "proc-macro2", + "quote", + "rand_core 0.6.4", + "rustfmt-wrapper", + "serde", + "sha2 0.10.6", + "syn 2.0.50", +] + [[package]] name = "p256k1" version = "7.0.0" @@ -3343,7 +3550,7 @@ version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall 0.2.16", "smallvec 1.10.0", @@ -3402,6 +3609,12 @@ dependencies = [ "syn 2.0.50", ] +[[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" @@ -3484,7 +3697,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52cff9d1d4dee5fe6d03729099f4a310a41179e0a10dbf542039873f2e826fb" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "opaque-debug 0.3.0", "universal-hash", @@ -3598,7 +3811,7 @@ version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fnv", "lazy_static", "memchr", @@ -3921,7 +4134,7 @@ dependencies = [ "spin 0.5.2", "untrusted 0.7.1", "web-sys", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -4166,7 +4379,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db7826789c0e25614b03e5a54a0717a86f9ff6e6e5247f92b369472869320039" dependencies = [ "bitflags 1.3.2", - "cfg-if", + "cfg-if 1.0.0", "clipboard-win", "dirs-next", "fd-lock", @@ -4180,7 +4393,7 @@ dependencies = [ "unicode-segmentation", "unicode-width", "utf8parse", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -4478,7 +4691,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ "block-buffer 0.9.0", - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest 0.9.0", "opaque-debug 0.3.0", @@ -4490,9 +4703,10 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest 0.10.7", + "sha2-asm 0.6.3", ] [[package]] @@ -4504,6 +4718,15 @@ dependencies = [ "cc", ] +[[package]] +name = "sha2-asm" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27ba7066011e3fb30d808b51affff34f0a66d3a03a58edd787c6e420e40e44e" +dependencies = [ + "cc", +] + [[package]] name = "sha3" version = "0.8.2" @@ -4536,6 +4759,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook" version = "0.3.17" @@ -4553,7 +4782,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" dependencies = [ "libc", - "mio", + "mio 0.8.11", "signal-hook", ] @@ -4581,6 +4810,12 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + [[package]] name = "slab" version = "0.4.7" @@ -4682,7 +4917,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -4755,10 +4990,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" dependencies = [ "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "psm", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -4789,7 +5024,7 @@ dependencies = [ "slog-json", "slog-term", "time", - "winapi", + "winapi 0.3.9", "wsts", ] @@ -4840,6 +5075,7 @@ dependencies = [ "serde_json", "serde_yaml", "stacks-rpc-client 2.3.1", + "stackslib", "tokio", "tracing", "tracing-appender", @@ -4879,6 +5115,49 @@ dependencies = [ "tiny-hderive", ] +[[package]] +name = "stackslib" +version = "0.0.1" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#1173e5a52db07a72e6881dcb466a4218e7b9fa24" +dependencies = [ + "chrono", + "clar2wasm 0.1.0 (git+https://github.com/stacks-network/clarity-wasm.git?branch=chore/update-clarity)", + "clarity", + "curve25519-dalek 2.0.0", + "ed25519-dalek", + "hashbrown 0.14.3", + "integer-sqrt", + "lazy_static", + "libc", + "libstackerdb", + "mio 0.6.23", + "nix 0.23.2", + "p256k1 5.5.0", + "percent-encoding", + "pox-locking", + "rand 0.8.5", + "rand_chacha 0.3.1", + "rand_core 0.6.4", + "regex", + "ripemd", + "rusqlite", + "secp256k1 0.24.3", + "serde", + "serde_derive", + "serde_json", + "sha2 0.10.6", + "sha3 0.10.6", + "siphasher", + "slog", + "slog-term", + "stacks-common", + "tikv-jemallocator", + "time", + "url", + "winapi 0.3.9", + "wsts", +] + [[package]] name = "state" version = "0.5.3" @@ -5029,7 +5308,7 @@ version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fastrand", "redox_syscall 0.3.5", "rustix 0.38.25", @@ -5044,7 +5323,7 @@ checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" dependencies = [ "dirs-next", "rustversion", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -5082,7 +5361,7 @@ version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "once_cell", ] @@ -5095,6 +5374,26 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.5.4+5.3.0-patched" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9402443cb8fd499b6f327e40565234ff34dbda27460c5b47db0db77443dd85d1" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965fe0c26be5c56c94e38ba547249074803efd52adfb66de62107d95aab3eaca" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.3.34" @@ -5165,7 +5464,7 @@ dependencies = [ "backtrace", "bytes", "libc", - "mio", + "mio 0.8.11", "num_cpus", "parking_lot", "pin-project-lite", @@ -5361,7 +5660,7 @@ version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -5643,7 +5942,7 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -5668,7 +5967,7 @@ version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -5756,7 +6055,7 @@ dependencies = [ "async-trait", "bincode", "bumpalo", - "cfg-if", + "cfg-if 1.0.0", "fxprof-processed-profile", "indexmap 2.2.3", "libc", @@ -5789,7 +6088,7 @@ version = "15.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "beada8bb15df52503de0a4c58de4357bfd2f96d9a44a6e547bad11efdd988b47" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -5840,7 +6139,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe2e7532f1d6adbcc57e69bb6a7c503f0859076d07a9b4b6aabe8021ff8a05fd" dependencies = [ "anyhow", - "cfg-if", + "cfg-if 1.0.0", "cranelift-codegen", "cranelift-control", "cranelift-entity", @@ -5902,7 +6201,7 @@ checksum = "404741f4c6d7f4e043be2e8b466406a2aee289ccdba22bf9eba6399921121b97" dependencies = [ "anyhow", "cc", - "cfg-if", + "cfg-if 1.0.0", "rustix 0.38.25", "wasmtime-asm-macros", "wasmtime-versioned-export-macros", @@ -5918,7 +6217,7 @@ dependencies = [ "addr2line 0.21.0", "anyhow", "bincode", - "cfg-if", + "cfg-if 1.0.0", "cpp_demangle", "gimli 0.28.1", "ittapi", @@ -5954,7 +6253,7 @@ version = "15.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3090a69ba1476979e090aa7ed4bc759178bafdb65b22f98b9ba24fc6e7e578d5" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "windows-sys 0.48.0", ] @@ -5967,7 +6266,7 @@ checksum = "b993ac8380385ed67bf71b51b9553edcf1ab0801b78a805a067de581b9a3e88a" dependencies = [ "anyhow", "cc", - "cfg-if", + "cfg-if 1.0.0", "indexmap 2.2.3", "libc", "log", @@ -6067,6 +6366,24 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix 0.38.25", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -6077,6 +6394,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -6089,7 +6412,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -6254,7 +6577,7 @@ version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "windows-sys 0.48.0", ] @@ -6275,6 +6598,16 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "wsts" version = "8.1.0" @@ -6286,7 +6619,7 @@ dependencies = [ "hashbrown 0.14.3", "hex 0.4.3", "num-traits", - "p256k1", + "p256k1 7.0.0", "polynomial", "primitive-types", "rand_core 0.6.4", diff --git a/components/stacks-network/Cargo.toml b/components/stacks-network/Cargo.toml index e259df543..15bc4fb55 100644 --- a/components/stacks-network/Cargo.toml +++ b/components/stacks-network/Cargo.toml @@ -31,18 +31,20 @@ chrono = "0.4.31" futures = "0.3.12" base58 = "0.2.0" tokio = { version = "1.35.1", features = ["full"] } +dirs = { version = "4.0.0" } +clap = { version = "4.4.8", features = ["derive"] } +serde_yaml = "0.8.23" +stackslib = { git = "https://github.com/stacks-network/stacks-core.git", branch="feat/clarity-wasm-next", package = "stackslib" } chainhook-sdk = { default-features = true, git = "https://github.com/hirosystems/chainhook.git", branch="chore/update-clarinet-and-clarity" } # chainhook-sdk = { version = "=0.11", default-features = true } + stacks-rpc-client = { path = "../stacks-rpc-client" } clarinet-files = { path = "../clarinet-files", features = ["cli"] } clarinet-deployments = { path = "../clarinet-deployments", features = ["cli"] } clarinet-utils = { path = "../clarinet-utils" } hiro-system-kit = { path = "../hiro-system-kit", features = ["log"] } clarity-repl = { path = "../clarity-repl", features = ["cli"] } -dirs = { version = "4.0.0" } -clap = { version = "4.4.8", features = ["derive"] } -serde_yaml = "0.8.23" [lib] name = "stacks_network" diff --git a/components/stacks-network/src/chains_coordinator.rs b/components/stacks-network/src/chains_coordinator.rs index 718c9baee..e538e6ee1 100644 --- a/components/stacks-network/src/chains_coordinator.rs +++ b/components/stacks-network/src/chains_coordinator.rs @@ -31,12 +31,23 @@ use clarity_repl::clarity::util::hash::{hex_bytes, Hash160}; use clarity_repl::clarity::vm::types::{BuffData, SequenceData, TupleData}; use clarity_repl::clarity::vm::ClarityName; use clarity_repl::clarity::vm::Value as ClarityValue; +use clarity_repl::clarity::PublicKey; use clarity_repl::codec; use hiro_system_kit; use hiro_system_kit::slog; use hiro_system_kit::yellow; use stacks_rpc_client::PoxInfo; use stacks_rpc_client::StacksRpc; +use stackslib::chainstate::stacks::address::PoxAddress; +use stackslib::core::CHAIN_ID_TESTNET; +use stackslib::types::chainstate::StacksPrivateKey; +use stackslib::types::chainstate::StacksPublicKey; +use stackslib::types::PrivateKey; +use stackslib::util::hash::Sha256Sum; +use stackslib::util::secp256k1::MessageSignature; +use stackslib::util_lib::signed_structured_data::pox4::make_pox_4_signed_data_domain; +use stackslib::util_lib::signed_structured_data::pox4::Pox4SignatureTopic; +use stackslib::util_lib::signed_structured_data::structured_data_message_hash; use std::convert::TryFrom; use std::str; use std::sync::atomic::{AtomicBool, Ordering}; @@ -648,8 +659,8 @@ pub async fn publish_stacking_orders( fee_rate: u64, bitcoin_block_height: u32, ) -> Option { - let stacks_node_rpc_url = format!("http://{}", &services_map_hosts.stacks_node_host); - let pox_info: PoxInfo = match reqwest::get(format!("{}/v2/pox", stacks_node_rpc_url)).await { + let node_rpc_url = format!("http://{}", &services_map_hosts.stacks_node_host); + let pox_info: PoxInfo = match reqwest::get(format!("{}/v2/pox", node_rpc_url)).await { Ok(result) => match result.json().await { Ok(pox_info) => Some(pox_info), Err(e) => { @@ -682,53 +693,52 @@ pub async fn publish_stacking_orders( return None; } + let pox_contract_id = pox_info.contract_id; + let pox_version = pox_contract_id + .rsplit('-') + .next() + .and_then(|version| version.parse::().ok()) + .unwrap(); + + let signer_key = StacksPrivateKey::from_hex( + "1b9397438f32b0d8ad27340e76e35354087b30bec8d335506f5395f7abd139e101", + ) + .unwrap(); + let mut transactions = 0; for (i, pox_stacking_order) in devnet_config.pox_stacking_orders.iter().enumerate() { if !should_publish_stacking_orders(¤t_cycle, pox_stacking_order) { continue; } - let PoxStackingOrder { - duration, - start_at_cycle, - .. - } = pox_stacking_order; - // if the is not the first cycle of this stacker, then stacking order will be extended - let extend_stacking = current_cycle != start_at_cycle - 1; + let extend_stacking = current_cycle != pox_stacking_order.start_at_cycle - 1; if extend_stacking && !pox_stacking_order.auto_extend.unwrap_or_default() { continue; } - let account = accounts + let account = match accounts .iter() - .find(|e| e.label == pox_stacking_order.wallet); - - let account = match account { - Some(account) => account.clone(), + .find(|e| e.label == pox_stacking_order.wallet) + .cloned() + { + Some(account) => account, _ => continue, }; transactions += 1; let stx_amount = pox_info.next_cycle.min_threshold_ustx * pox_stacking_order.slots; - let addr_bytes = pox_stacking_order - .btc_address - .from_base58() - .expect("Unable to get bytes from btc address"); - let node_url = stacks_node_rpc_url.clone(); - let pox_contract_id = pox_info.contract_id.clone(); - let pox_version = pox_contract_id - .rsplit('-') - .next() - .and_then(|version| version.parse::().ok()) - .unwrap(); - - let duration = *duration; + + let node_rpc_url_moved = node_rpc_url.clone(); + let pox_contract_id_moved = pox_contract_id.clone(); + let btc_address_moved = pox_stacking_order.btc_address.clone(); + let duration = pox_stacking_order.duration; + let stacking_result = hiro_system_kit::thread_named("Stacking orders handler").spawn(move || { let default_fee = fee_rate * 1000; - let stacks_rpc = StacksRpc::new(&node_url); + let stacks_rpc = StacksRpc::new(&node_rpc_url_moved); let nonce = stacks_rpc.get_nonce(&account.stx_address)?; let (_, _, account_secret_key) = clarinet_files::compute_addresses( @@ -737,51 +747,21 @@ pub async fn publish_stacking_orders( &StacksNetwork::Devnet.get_networks(), ); - let pox_addr_arg = ClarityValue::Tuple( - TupleData::from_data(vec![ - ( - ClarityName::try_from("version".to_owned()).unwrap(), - ClarityValue::buff_from_byte(AddressHashMode::SerializeP2PKH as u8), - ), - ( - ClarityName::try_from("hashbytes".to_owned()).unwrap(), - ClarityValue::Sequence(SequenceData::Buffer(BuffData { - data: Hash160::from_bytes(&addr_bytes[1..21]) - .unwrap() - .as_bytes() - .to_vec(), - })), - ), - ]) - .unwrap(), + let (method, arguments) = get_stacking_tx_method_and_args( + pox_version, + bitcoin_block_height, + current_cycle.into(), + &signer_key, + extend_stacking, + &btc_address_moved, + stx_amount, + duration, + i.try_into().unwrap(), ); - let (method, mut arguments) = match extend_stacking { - false => ( - "stack-stx", - vec![ - ClarityValue::UInt(stx_amount.into()), - pox_addr_arg, - ClarityValue::UInt((bitcoin_block_height - 1).into()), - ClarityValue::UInt(duration.into()), - ], - ), - true => ( - "stack-extend", - vec![ClarityValue::UInt(duration.into()), pox_addr_arg], - ), - }; - - if pox_version >= 4 { - let mut signer_key = vec![0; 33]; - signer_key[0] = i as u8; - signer_key[1] = nonce as u8; - arguments.push(ClarityValue::buff_from(signer_key).unwrap()); - }; - let tx = codec::build_contrat_call_transaction( - pox_contract_id, - method.into(), + pox_contract_id_moved, + method, arguments, nonce, default_fee, @@ -931,3 +911,209 @@ async fn handle_bitcoin_mining( } } } + +fn get_stacking_tx_method_and_args( + pox_version: u32, + bitcoin_block_height: u32, + cycle: u128, + signer_key: &StacksPrivateKey, + extend_stacking: bool, + btc_address: &str, + stx_amount: u64, + duration: u32, + auth_id: u128, +) -> (String, Vec) { + let addr_bytes = btc_address + .from_base58() + .expect("Unable to get bytes from btc address"); + let pox_addr_tuple = ClarityValue::Tuple( + TupleData::from_data(vec![ + ( + ClarityName::try_from("version".to_owned()).unwrap(), + ClarityValue::buff_from_byte(AddressHashMode::SerializeP2PKH as u8), + ), + ( + ClarityName::try_from("hashbytes".to_owned()).unwrap(), + ClarityValue::Sequence(SequenceData::Buffer(BuffData { + data: Hash160::from_bytes(&addr_bytes[1..21]) + .unwrap() + .as_bytes() + .to_vec(), + })), + ), + ]) + .unwrap(), + ); + let pox_addr = PoxAddress::try_from_pox_tuple(false, &pox_addr_tuple).unwrap(); + + let burn_block_height: u128 = (bitcoin_block_height - 1).into(); + let (method, topic, mut arguments) = match extend_stacking { + false => ( + "stack-stx", + Pox4SignatureTopic::StackStx, + vec![ + ClarityValue::UInt(stx_amount.into()), + pox_addr_tuple, + ClarityValue::UInt(burn_block_height), + ClarityValue::UInt(duration.into()), + ], + ), + true => ( + "stack-extend", + Pox4SignatureTopic::StackExtend, + vec![ClarityValue::UInt(duration.into()), pox_addr_tuple], + ), + }; + + // extra arguments for pox-4 + // (signer-sig (optional (buff 65))) + // (signer-key (buff 33)) + // (max-amount uint) + // (auth-id uint) + if pox_version >= 4 { + let signer_sig = make_signer_key_signature( + &pox_addr, + signer_key, + cycle, + &topic, + duration.into(), + stx_amount.into(), + auth_id, + ); + let pub_key = StacksPublicKey::from_private(signer_key); + arguments.push(ClarityValue::some(ClarityValue::buff_from(signer_sig).unwrap()).unwrap()); + arguments.push(ClarityValue::buff_from(pub_key.to_bytes()).unwrap()); + arguments.push(ClarityValue::UInt(stx_amount.into())); + arguments.push(ClarityValue::UInt(auth_id)); + }; + + (method.to_string(), arguments) +} + +// The current version of stackslib we are using (from feat/clarity-wasm-next) does not have the latest version of make_pox_4_signer_key_signature +// This is a temporary fix until feat/clarity-wasm-next catches up with the branch next + +fn make_pox_4_signer_key_message_hash( + pox_addr: &PoxAddress, + reward_cycle: u128, + topic: &Pox4SignatureTopic, + chain_id: u32, + period: u128, + max_amount: u128, + auth_id: u128, +) -> Sha256Sum { + let domain_tuple = make_pox_4_signed_data_domain(chain_id); + let data_tuple = ClarityValue::Tuple( + TupleData::from_data(vec![ + ( + "pox-addr".into(), + pox_addr.clone().as_clarity_tuple().unwrap().into(), + ), + ("reward-cycle".into(), ClarityValue::UInt(reward_cycle)), + ("period".into(), ClarityValue::UInt(period)), + ( + "topic".into(), + ClarityValue::string_ascii_from_bytes(topic.get_name_str().into()).unwrap(), + ), + ("auth-id".into(), ClarityValue::UInt(auth_id)), + ("max-amount".into(), ClarityValue::UInt(max_amount)), + ]) + .unwrap(), + ); + structured_data_message_hash(data_tuple, domain_tuple) +} + +fn make_pox_4_signer_key_signature( + pox_addr: &PoxAddress, + signer_key: &StacksPrivateKey, + reward_cycle: u128, + topic: &Pox4SignatureTopic, + chain_id: u32, + period: u128, + max_amount: u128, + auth_id: u128, +) -> Result { + let msg_hash = make_pox_4_signer_key_message_hash( + pox_addr, + reward_cycle, + topic, + chain_id, + period, + max_amount, + auth_id, + ); + signer_key.sign(msg_hash.as_bytes()) +} + +fn make_signer_key_signature( + pox_addr: &PoxAddress, + signer_key: &StacksPrivateKey, + reward_cycle: u128, + topic: &Pox4SignatureTopic, + period: u128, + max_amount: u128, + auth_id: u128, +) -> Vec { + let signature = make_pox_4_signer_key_signature( + pox_addr, + signer_key, + reward_cycle, + topic, + CHAIN_ID_TESTNET, + period, + max_amount, + auth_id, + ) + .unwrap(); + + signature.to_rsv() +} + +#[cfg(test)] +mod key_tests { + use super::*; + use clarinet_files::DEFAULT_DERIVATION_PATH; + use stackslib::{net::stackerdb::db, util::hash::bytes_to_hex}; + #[test] + fn test_make_signer_key_signature() { + let label = "wallet_1".to_string(); + let mnemonic = "sell invite acquire kitten bamboo drastic jelly vivid peace spawn twice guilt pave pen trash pretty park cube fragile unaware remain midnight betray rebuild".to_string(); + + let account = AccountConfig { + label, + mnemonic, + derivation: DEFAULT_DERIVATION_PATH.into(), + balance: 100000, + stx_address: "ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5".into(), + btc_address: "mr1iPkD9N3RJZZxXRk7xF9d36gffa6exNC".into(), + is_mainnet: false, + }; + + let addr_bytes = account + .btc_address + .from_base58() + .expect("Unable to get bytes from btc address"); + + let pox_addr_tuple = ClarityValue::Tuple( + TupleData::from_data(vec![ + ( + ClarityName::try_from("version".to_owned()).unwrap(), + ClarityValue::buff_from_byte(AddressHashMode::SerializeP2PKH as u8), + ), + ( + ClarityName::try_from("hashbytes".to_owned()).unwrap(), + ClarityValue::Sequence(SequenceData::Buffer(BuffData { + data: Hash160::from_bytes(&addr_bytes[1..21]) + .unwrap() + .as_bytes() + .to_vec(), + })), + ), + ]) + .unwrap(), + ); + + let pox_addr = PoxAddress::try_from_pox_tuple(false, &pox_addr_tuple).unwrap(); + dbg!(pox_addr); + } +} diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index bdafd37ca..c487119d9 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -1181,7 +1181,8 @@ start_height = {epoch_3_0} entrypoint: Some(vec![ "stacks-node".into(), "start".into(), - "--config=/src/stacks-node/Stacks.toml".into(), + "--config".into(), + "/src/stacks-node/Stacks.toml".into(), ]), env: Some(env), host_config: Some(HostConfig { From bdb28e727ae396c51f5e49c1a8332072954cc27d Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Wed, 20 Mar 2024 02:05:14 +0100 Subject: [PATCH 02/13] feat: initialize signer --- .../clarinet-files/src/network_manifest.rs | 12 + .../src/jupyter/core.rs | 11 +- .../stacks-network/src/chains_coordinator.rs | 2 +- components/stacks-network/src/orchestrator.rs | 231 ++++++++++++++++-- components/stacks-network/src/ui/ui.rs | 4 +- 5 files changed, 234 insertions(+), 26 deletions(-) diff --git a/components/clarinet-files/src/network_manifest.rs b/components/clarinet-files/src/network_manifest.rs index 5109e2850..f3d0a1864 100644 --- a/components/clarinet-files/src/network_manifest.rs +++ b/components/clarinet-files/src/network_manifest.rs @@ -116,6 +116,7 @@ pub struct DevnetConfigFile { pub bitcoin_node_image_url: Option, pub bitcoin_explorer_image_url: Option, pub stacks_node_image_url: Option, + pub stacks_signer_image_url: Option, pub stacks_api_image_url: Option, pub stacks_explorer_image_url: Option, pub postgres_image_url: Option, @@ -275,6 +276,7 @@ pub struct DevnetConfig { pub execute_script: Vec, pub bitcoin_node_image_url: String, pub stacks_node_image_url: String, + pub stacks_signer_image_url: String, pub stacks_api_image_url: String, pub stacks_explorer_image_url: String, pub postgres_image_url: String, @@ -893,6 +895,16 @@ impl NetworkManifest { } }, ), + stacks_signer_image_url: devnet_config + .stacks_signer_image_url + .take() + .unwrap_or_else(|| { + if devnet_config.use_nakamoto.unwrap_or(false) { + DEFAULT_STACKS_NODE_IMAGE_NAKA.to_string() + } else { + DEFAULT_STACKS_NODE_IMAGE.to_string() + } + }), stacks_api_image_url: devnet_config.stacks_api_image_url.take().unwrap_or_else( || { if devnet_config.use_nakamoto.unwrap_or(false) { diff --git a/components/clarity-jupyter-kernel/src/jupyter/core.rs b/components/clarity-jupyter-kernel/src/jupyter/core.rs index f85952cfa..4b7f9d7a1 100644 --- a/components/clarity-jupyter-kernel/src/jupyter/core.rs +++ b/components/clarity-jupyter-kernel/src/jupyter/core.rs @@ -155,13 +155,10 @@ impl Server { .send(&mut *self.iopub.lock().unwrap())?; let mut has_error = false; for code in split_code_and_command(src) { - match self.session.formatted_interpretation( - code.to_string(), - None, - false, - None, - None, - ) { + match self + .session + .formatted_interpretation(code.to_string(), None, false, None) + { Ok((result, _)) => { let res = result.join("\n"); let mut data: HashMap = HashMap::new(); diff --git a/components/stacks-network/src/chains_coordinator.rs b/components/stacks-network/src/chains_coordinator.rs index e538e6ee1..6afe04957 100644 --- a/components/stacks-network/src/chains_coordinator.rs +++ b/components/stacks-network/src/chains_coordinator.rs @@ -453,7 +453,7 @@ pub async fn start_chains_coordinator( if tx.tx_description.contains("::commit-block") { let _ = devnet_event_tx.send(DevnetEvent::ServiceStatus( ServiceStatusData { - order: 5, + order: 6, status: Status::Green, name: "subnet-node".into(), comment: "⚡️".to_string(), diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index c487119d9..af3001407 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -34,6 +34,7 @@ pub struct DevnetOrchestrator { pub termination_success_tx: Option>, pub can_exit: bool, stacks_node_container_id: Option, + stacks_signer_container_id: Option, stacks_api_container_id: Option, stacks_explorer_container_id: Option, bitcoin_node_container_id: Option, @@ -152,6 +153,7 @@ impl DevnetOrchestrator { can_exit: true, termination_success_tx: None, stacks_node_container_id: None, + stacks_signer_container_id: None, stacks_api_container_id: None, stacks_explorer_container_id: None, bitcoin_node_container_id: None, @@ -329,6 +331,13 @@ impl DevnetOrchestrator { let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { order: 2, status: Status::Red, + name: "stacks-signer".into(), + comment: "initializing".into(), + })); + + let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { + order: 3, + status: Status::Red, name: "stacks-api".into(), comment: if disable_stacks_api { "disabled".into() @@ -338,7 +347,7 @@ impl DevnetOrchestrator { })); let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 3, + order: 4, status: Status::Red, name: "stacks-explorer".into(), comment: if disable_stacks_explorer { @@ -349,7 +358,7 @@ impl DevnetOrchestrator { })); let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 4, + order: 5, status: Status::Red, name: "bitcoin-explorer".into(), comment: if disable_bitcoin_explorer { @@ -361,14 +370,14 @@ impl DevnetOrchestrator { if enable_subnet_node { let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 5, + order: 6, status: Status::Red, name: "subnet-node".into(), comment: "initializing".into(), })); let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 6, + order: 7, status: Status::Red, name: "subnet-api".into(), comment: if disable_subnet_api { @@ -421,7 +430,7 @@ impl DevnetOrchestrator { if !disable_stacks_api { // Start postgres let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 2, + order: 3, status: Status::Yellow, name: "stacks-api".into(), comment: "preparing postgres container".into(), @@ -444,7 +453,7 @@ impl DevnetOrchestrator { } }; let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 2, + order: 3, status: Status::Yellow, name: "stacks-api".into(), comment: "preparing container".into(), @@ -460,7 +469,7 @@ impl DevnetOrchestrator { } }; let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 2, + order: 3, status: Status::Green, name: "stacks-api".into(), comment: format!("http://localhost:{}/doc", stacks_api_port), @@ -487,7 +496,7 @@ impl DevnetOrchestrator { } }; let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 5, + order: 6, status: Status::Yellow, name: "subnet-node".into(), comment: "booting".into(), @@ -512,7 +521,7 @@ impl DevnetOrchestrator { } }; let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 6, + order: 7, status: Status::Green, name: "subnet-api".into(), comment: format!("http://localhost:{}/doc", subnet_api_port), @@ -528,7 +537,7 @@ impl DevnetOrchestrator { } } - // Start stacks-blockchain + // Start stacks-node let _ = event_tx.send(DevnetEvent::info("Starting stacks-node".to_string())); let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { order: 1, @@ -559,10 +568,47 @@ impl DevnetOrchestrator { } }; + // Start stacks-signer + let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer".to_string())); + let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { + order: 2, + status: Status::Yellow, + name: "stacks-signer".into(), + comment: "updating image".into(), + })); + match self.prepare_stacks_signer_container(boot_index, ctx).await { + Ok(_) => {} + Err(message) => { + let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); + self.kill(ctx, Some(&message)).await; + return Err(message); + } + }; + let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { + order: 2, + status: Status::Yellow, + name: "stacks-signer".into(), + comment: "booting".into(), + })); + match self.boot_stacks_signer_container().await { + Ok(_) => {} + Err(message) => { + let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); + self.kill(ctx, Some(&message)).await; + return Err(message); + } + }; + let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { + order: 2, + status: Status::Green, + name: "stacks-signer".into(), + comment: "Waiting for messages".into(), + })); + // Start stacks-explorer if !disable_stacks_explorer { let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 3, + order: 4, status: Status::Yellow, name: "stacks-explorer".into(), comment: "preparing container".into(), @@ -585,7 +631,7 @@ impl DevnetOrchestrator { } }; let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 3, + order: 4, status: Status::Green, name: "stacks-explorer".into(), comment: format!("http://localhost:{}", stacks_explorer_port), @@ -595,7 +641,7 @@ impl DevnetOrchestrator { // Start bitcoin-explorer if !disable_bitcoin_explorer { let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 4, + order: 5, status: Status::Yellow, name: "bitcoin-explorer".into(), comment: "preparing container".into(), @@ -618,7 +664,7 @@ impl DevnetOrchestrator { } }; let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 4, + order: 5, status: Status::Green, name: "bitcoin-explorer".into(), comment: format!("http://localhost:{}", bitcoin_explorer_port), @@ -1264,6 +1310,153 @@ start_height = {epoch_3_0} Ok(()) } + pub fn prepare_stacks_signer_config(&self, boot_index: u32) -> Result, String> { + let (_, devnet_config) = match &self.network_config { + Some(ref network_config) => match network_config.devnet { + Some(ref devnet_config) => (network_config, devnet_config), + _ => return Err("unable to get devnet configuration".into()), + }, + _ => return Err("unable to get Docker client".into()), + }; + + let signer_private_key = + "1b9397438f32b0d8ad27340e76e35354087b30bec8d335506f5395f7abd139e101"; + let signer_conf = format!( + r#" +stacks_private_key = "{signer_private_key}" +node_host = "0.0.0.0:{stacks_node_rpc_port}" # eg "127.0.0.1:20443" +# must be added as event_observer in node config: +endpoint = "0.0.0.0:30000" # e.g 127.0.0.1:30000 +network = "testnet" +auth_password = "12345" +db_path = "/devnet/nakamoto-neon/stacks-signer-0.sqlite" +"#, + signer_private_key = signer_private_key, + // signer_private_key = devnet_config.signer_private_key, + stacks_node_rpc_port = devnet_config.stacks_node_rpc_port + ); + let mut signer_conf_path = PathBuf::from(&devnet_config.working_dir); + signer_conf_path.push("conf/Signer.toml"); + let mut file = File::create(signer_conf_path) + .map_err(|e| format!("unable to create Signer.toml: {:?}", e))?; + file.write_all(signer_conf.as_bytes()) + .map_err(|e| format!("unable to write Signer.toml: {:?}", e))?; + + let mut stacks_signer_data_path = PathBuf::from(&devnet_config.working_dir); + stacks_signer_data_path.push("data"); + stacks_signer_data_path.push(format!("{}", boot_index)); + stacks_signer_data_path.push("signer"); + fs::create_dir_all(stacks_signer_data_path) + .map_err(|e| format!("unable to create stacks directory: {:?}", e))?; + + let mut labels = HashMap::new(); + labels.insert("project".to_string(), self.network_name.to_string()); + labels.insert("reset".to_string(), "true".to_string()); + + let mut binds = vec![format!( + "{}/conf:/src/stacks-signer/", + devnet_config.working_dir + )]; + + if devnet_config.bind_containers_volumes { + binds.push(format!( + "{}/data/{}/stacks:/devnet/", + devnet_config.working_dir, boot_index + )) + } + + let config = Config { + labels: Some(labels), + image: Some(devnet_config.stacks_signer_image_url.clone()), + // domainname: Some(self.network_name.to_string()), + tty: None, + exposed_ports: None, + entrypoint: Some(vec![ + "stacks-signer".into(), + "run".into(), + "--config".into(), + "/src/stacks-signer/Signer.toml".into(), + ]), + env: None, + host_config: Some(HostConfig { + auto_remove: Some(true), + binds: Some(binds), + network_mode: Some(self.network_name.clone()), + port_bindings: None, + extra_hosts: Some(vec!["host.docker.internal:host-gateway".into()]), + ..Default::default() + }), + ..Default::default() + }; + + Ok(config) + } + + pub async fn prepare_stacks_signer_container( + &mut self, + boot_index: u32, + ctx: &Context, + ) -> Result<(), String> { + let (docker, devnet_config) = match (&self.docker_client, &self.network_config) { + (Some(ref docker), Some(ref network_config)) => match network_config.devnet { + Some(ref devnet_config) => (docker, devnet_config), + _ => return Err("unable to get devnet configuration".into()), + }, + _ => return Err("unable to get Docker client".into()), + }; + + let _info = docker + .create_image( + Some(CreateImageOptions { + from_image: devnet_config.stacks_signer_image_url.clone(), + platform: devnet_config.docker_platform.clone(), + ..Default::default() + }), + None, + None, + ) + .try_collect::>() + .await + .map_err(|e| format!("unable to create image: {}", e))?; + + let config = self.prepare_stacks_signer_config(boot_index)?; + + let options = CreateContainerOptions { + name: format!("stacks-signer.{}", self.network_name), + platform: Some(devnet_config.docker_platform.to_string()), + }; + + let container = docker + .create_container::(Some(options), config) + .await + .map_err(|e| format!("unable to create container: {}", e))? + .id; + + ctx.try_log(|logger| slog::info!(logger, "Created container stacks-signer: {}", container)); + self.stacks_signer_container_id = Some(container.clone()); + + Ok(()) + } + + pub async fn boot_stacks_signer_container(&mut self) -> Result<(), String> { + let container = match &self.stacks_signer_container_id { + Some(container) => container.clone(), + _ => return Err("unable to boot container".to_string()), + }; + + let docker = match &self.docker_client { + Some(ref docker) => docker, + _ => return Err("unable to get Docker client".into()), + }; + + docker + .start_container::(&container, None) + .await + .map_err(|e| formatted_docker_error("unable to start stacks-signer container", e))?; + + Ok(()) + } + pub fn prepare_subnet_node_config(&self, boot_index: u32) -> Result, String> { let devnet_config = match &self.network_config { Some(network_config) => match &network_config.devnet { @@ -2138,19 +2331,21 @@ events_keys = ["*"] pub async fn stop_containers(&self) -> Result<(), String> { let containers_ids = match ( &self.stacks_node_container_id, + &self.stacks_signer_container_id, &self.stacks_api_container_id, &self.stacks_explorer_container_id, &self.bitcoin_node_container_id, &self.bitcoin_explorer_container_id, &self.postgres_container_id, ) { - (Some(c1), Some(c2), Some(c3), Some(c4), Some(c5), Some(c6)) => { - (c1, c2, c3, c4, c5, c6) + (Some(c1), Some(c2), Some(c3), Some(c4), Some(c5), Some(c6), Some(c7)) => { + (c1, c2, c3, c4, c5, c6, c7) } _ => return Err("unable to boot container".to_string()), }; let ( stacks_node_c_id, + stacks_signer_c_id, stacks_api_c_id, stacks_explorer_c_id, bitcoin_node_c_id, @@ -2169,6 +2364,10 @@ events_keys = ["*"] .kill_container(stacks_node_c_id, Some(options.clone())) .await; + let _ = docker + .kill_container(stacks_signer_c_id, Some(options.clone())) + .await; + let _ = docker .kill_container(stacks_api_c_id, Some(options.clone())) .await; diff --git a/components/stacks-network/src/ui/ui.rs b/components/stacks-network/src/ui/ui.rs index ccbe1fb53..b8a6e5b1d 100644 --- a/components/stacks-network/src/ui/ui.rs +++ b/components/stacks-network/src/ui/ui.rs @@ -25,8 +25,8 @@ pub fn draw(f: &mut Frame, app: &mut App) { .split(page_components[1]); let service_len = match app.subnet_enabled { - false => 7, - true => 9, + false => 8, + true => 10, }; let top_right_components = Layout::default() From 9d57c4e1eaffbf3b9cf42ca78dc0327523f8c8e1 Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Wed, 20 Mar 2024 15:59:24 +0100 Subject: [PATCH 03/13] chore: udpate dependencies --- Cargo.lock | 305 ++++++++---------- components/stacks-network/Cargo.toml | 2 +- components/stacks-network/src/orchestrator.rs | 104 ++---- 3 files changed, 171 insertions(+), 240 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4da39b206..493288005 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -363,28 +363,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bindgen" -version = "0.64.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" -dependencies = [ - "bitflags 1.3.2", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 1.0.107", - "which", -] - [[package]] name = "bip39" version = "1.0.1" @@ -570,9 +548,9 @@ dependencies = [ [[package]] name = "bollard" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f03db470b3c0213c47e978da93200259a1eb4dae2e5512cba9955e2b540a6fc6" +checksum = "83545367eb6428eb35c29cdec3a1f350fa8d6d9085d59a7d7bcb637f2e38db5a" dependencies = [ "base64 0.21.7", "bollard-stubs", @@ -580,9 +558,12 @@ dependencies = [ "futures-core", "futures-util", "hex 0.4.3", - "http", - "hyper", - "hyperlocal", + "http 1.1.0", + "http-body-util", + "hyper 1.2.0", + "hyper-named-pipe", + "hyper-util", + "hyperlocal-next", "log", "pin-project-lite", "serde", @@ -593,15 +574,16 @@ dependencies = [ "thiserror", "tokio", "tokio-util", + "tower-service", "url", "winapi 0.3.9", ] [[package]] name = "bollard-stubs" -version = "1.43.0-rc.2" +version = "1.44.0-rc.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b58071e8fd9ec1e930efd28e3a90c1251015872a2ce49f81f36421b86466932e" +checksum = "709d9aa1c37abb89d40f19f5d0ad6f0d88cb1581264e571c9350fc5bb89cf1c5" dependencies = [ "serde", "serde_repr", @@ -674,15 +656,6 @@ dependencies = [ "jobserver", ] -[[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" @@ -711,7 +684,7 @@ dependencies = [ "fxhash", "hex 0.4.3", "hiro-system-kit 0.3.1", - "hyper", + "hyper 0.14.27", "lazy_static", "miniscript", "prometheus", @@ -767,17 +740,6 @@ dependencies = [ "inout", ] -[[package]] -name = "clang-sys" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" -dependencies = [ - "glob", - "libc", - "libloading 0.8.3", -] - [[package]] name = "clap" version = "4.4.8" @@ -1259,7 +1221,7 @@ dependencies = [ "hashbrown 0.14.3", "log", "regalloc2", - "smallvec 1.10.0", + "smallvec 1.13.1", "target-lexicon", ] @@ -1305,7 +1267,7 @@ checksum = "e57374fd11d72cf9ffb85ff64506ed831440818318f58d09f45b4185e5e9c376" dependencies = [ "cranelift-codegen", "log", - "smallvec 1.10.0", + "smallvec 1.13.1", "target-lexicon", ] @@ -1337,7 +1299,7 @@ dependencies = [ "cranelift-frontend", "itertools 0.10.5", "log", - "smallvec 1.10.0", + "smallvec 1.13.1", "wasmparser 0.116.1", "wasmtime-types", ] @@ -2215,7 +2177,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.8", "indexmap 2.2.3", "slab", "tokio", @@ -2428,6 +2390,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.5" @@ -2435,7 +2408,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", - "http", + "http 0.2.8", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -2462,8 +2458,8 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", + "http 0.2.8", + "http-body 0.4.5", "httparse", "httpdate", "itoa", @@ -2475,6 +2471,40 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "itoa", + "pin-project-lite", + "smallvec 1.13.1", + "tokio", + "want", +] + +[[package]] +name = "hyper-named-pipe" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b7d8abf35697b81a825e386fc151e0d503e8cb5fcb93cc8669c376dfd6f278" +dependencies = [ + "hex 0.4.3", + "hyper 1.2.0", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", + "winapi 0.3.9", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -2482,24 +2512,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.8", + "hyper 0.14.27", "rustls", "tokio", "tokio-rustls", ] [[package]] -name = "hyperlocal" -version = "0.8.0" +name = "hyper-util" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fafdf7b2b2de7c9784f76e02c0935e65a8117ec3b768644379983ab333ac98c" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" dependencies = [ + "bytes", + "futures-channel", "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.2.0", + "pin-project-lite", + "socket2 0.5.5", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "hyperlocal-next" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acf569d43fa9848e510358c07b80f4adf34084ddc28c6a4a651ee8474c070dcc" +dependencies = [ "hex 0.4.3", - "hyper", - "pin-project", + "http-body-util", + "hyper 1.2.0", + "hyper-util", + "pin-project-lite", "tokio", + "tower-service", ] [[package]] @@ -2767,12 +2819,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 = "leb128" version = "0.2.5" @@ -2795,16 +2841,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "libloading" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" -dependencies = [ - "cfg-if 1.0.0", - "windows-targets 0.48.5", -] - [[package]] name = "libsecp256k1" version = "0.3.5" @@ -2931,7 +2967,7 @@ dependencies = [ [[package]] name = "libstackerdb" version = "0.0.1" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#1173e5a52db07a72e6881dcb466a4218e7b9fa24" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#5eb967cf4f58efcffe385c7a6fd2ed82e5f5da58" dependencies = [ "clarity", "secp256k1 0.24.3", @@ -3116,12 +3152,6 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniscript" version = "11.0.0" @@ -3194,7 +3224,7 @@ dependencies = [ "bytes", "encoding_rs", "futures-util", - "http", + "http 0.2.8", "httparse", "log", "memchr", @@ -3216,7 +3246,7 @@ dependencies = [ "neon-macros", "neon-runtime", "semver 0.9.0", - "smallvec 1.10.0", + "smallvec 1.13.1", ] [[package]] @@ -3242,8 +3272,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02662cd2e62b131937bdef85d0918b05bc3c204daf4c64af62845403eccb60f3" dependencies = [ "cfg-if 1.0.0", - "libloading 0.6.7", - "smallvec 1.10.0", + "libloading", + "smallvec 1.13.1", ] [[package]] @@ -3263,7 +3293,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" dependencies = [ - "smallvec 1.10.0", + "smallvec 1.13.1", ] [[package]] @@ -3309,16 +3339,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" -[[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" @@ -3463,29 +3483,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "p256k1" -version = "5.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e81c2cb5a1936d3f26278f9d698932239d03ddf0d5818392d91cd5f98ffc79" -dependencies = [ - "bindgen", - "bitvec", - "bs58 0.4.0", - "cc", - "hex 0.4.3", - "itertools 0.10.5", - "num-traits", - "primitive-types", - "proc-macro2", - "quote", - "rand_core 0.6.4", - "rustfmt-wrapper", - "serde", - "sha2 0.10.6", - "syn 2.0.50", -] - [[package]] name = "p256k1" version = "7.0.0" @@ -3553,7 +3550,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall 0.2.16", - "smallvec 1.10.0", + "smallvec 1.13.1", "windows-sys 0.45.0", ] @@ -3609,12 +3606,6 @@ dependencies = [ "syn 2.0.50", ] -[[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" @@ -4035,7 +4026,7 @@ dependencies = [ "log", "rustc-hash", "slice-group-by", - "smallvec 1.10.0", + "smallvec 1.13.1", ] [[package]] @@ -4094,9 +4085,9 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", - "hyper", + "http 0.2.8", + "http-body 0.4.5", + "hyper 0.14.27", "hyper-rustls", "ipnet", "js-sys", @@ -4235,8 +4226,8 @@ dependencies = [ "cookie", "either", "futures", - "http", - "hyper", + "http 0.2.8", + "hyper 0.14.27", "indexmap 1.9.2", "log", "memchr", @@ -4245,7 +4236,7 @@ dependencies = [ "pin-project-lite", "ref-cast", "serde", - "smallvec 1.10.0", + "smallvec 1.13.1", "stable-pattern", "state", "time", @@ -4265,7 +4256,7 @@ dependencies = [ "hashlink", "libsqlite3-sys", "serde_json", - "smallvec 1.10.0", + "smallvec 1.13.1", ] [[package]] @@ -4389,7 +4380,7 @@ dependencies = [ "nix 0.23.2", "radix_trie", "scopeguard", - "smallvec 1.10.0", + "smallvec 1.13.1", "unicode-segmentation", "unicode-width", "utf8parse", @@ -4759,12 +4750,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - [[package]] name = "signal-hook" version = "0.3.17" @@ -4906,9 +4891,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "socket2" @@ -5118,7 +5103,7 @@ dependencies = [ [[package]] name = "stackslib" version = "0.0.1" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#1173e5a52db07a72e6881dcb466a4218e7b9fa24" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#5eb967cf4f58efcffe385c7a6fd2ed82e5f5da58" dependencies = [ "chrono", "clar2wasm 0.1.0 (git+https://github.com/stacks-network/clarity-wasm.git?branch=chore/update-clarity)", @@ -5132,7 +5117,6 @@ dependencies = [ "libstackerdb", "mio 0.6.23", "nix 0.23.2", - "p256k1 5.5.0", "percent-encoding", "pox-locking", "rand 0.8.5", @@ -5604,8 +5588,10 @@ dependencies = [ "futures-util", "pin-project", "pin-project-lite", + "tokio", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -5661,6 +5647,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if 1.0.0", + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -5720,7 +5707,7 @@ dependencies = [ "once_cell", "regex", "sharded-slab", - "smallvec 1.10.0", + "smallvec 1.13.1", "thread_local", "tracing", "tracing-core", @@ -6366,18 +6353,6 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix 0.38.25", -] - [[package]] name = "winapi" version = "0.2.8" @@ -6619,7 +6594,7 @@ dependencies = [ "hashbrown 0.14.3", "hex 0.4.3", "num-traits", - "p256k1 7.0.0", + "p256k1", "polynomial", "primitive-types", "rand_core 0.6.4", diff --git a/components/stacks-network/Cargo.toml b/components/stacks-network/Cargo.toml index 15bc4fb55..26af681f5 100644 --- a/components/stacks-network/Cargo.toml +++ b/components/stacks-network/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] atty = "0.2.14" ansi_term = "0.12.1" -bollard = "0.15.0" +bollard = "0.16.0" bytes = "1.4.0" bitcoin = "0.29.2" bitcoincore-rpc = "0.16.0" diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index af3001407..98f695afc 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -1036,6 +1036,17 @@ amount = {} )); } + stacks_conf.push_str(&format!( + r#" +[[events_observer]] +endpoint = "stacks-signer.{}:30002" +retry_count = 255 +include_data_events = false +events_keys = ["stackerdb", "block_proposal", "burn_blocks"] +"#, + self.network_name + )); + stacks_conf.push_str(&format!( r#" # Add orchestrator (docker-host) as an event observer @@ -1324,15 +1335,16 @@ start_height = {epoch_3_0} let signer_conf = format!( r#" stacks_private_key = "{signer_private_key}" -node_host = "0.0.0.0:{stacks_node_rpc_port}" # eg "127.0.0.1:20443" +node_host = "stacks-node.{network_name}:{stacks_node_rpc_port}" # eg "127.0.0.1:20443" # must be added as event_observer in node config: -endpoint = "0.0.0.0:30000" # e.g 127.0.0.1:30000 +endpoint = "0.0.0.0:30002" # e.g 127.0.0.1:30000 network = "testnet" auth_password = "12345" -db_path = "/devnet/nakamoto-neon/stacks-signer-0.sqlite" +db_path = "stacks-signer-0.sqlite" "#, signer_private_key = signer_private_key, // signer_private_key = devnet_config.signer_private_key, + network_name = self.network_name, stacks_node_rpc_port = devnet_config.stacks_node_rpc_port ); let mut signer_conf_path = PathBuf::from(&devnet_config.working_dir); @@ -2498,78 +2510,22 @@ events_keys = ["*"] let options = Some(KillContainerOptions { signal: "SIGKILL" }); // Terminate containers - if let Some(ref bitcoin_explorer_container_id) = self.bitcoin_explorer_container_id { - let _ = docker - .kill_container(bitcoin_explorer_container_id, options.clone()) - .await; - ctx.try_log(|logger| slog::info!(logger, "Terminating bitcoin-explorer")); - let _ = docker - .remove_container(bitcoin_explorer_container_id, None) - .await; - } - - if let Some(ref stacks_explorer_container_id) = self.stacks_explorer_container_id { - let _ = docker - .kill_container(stacks_explorer_container_id, options.clone()) - .await; - ctx.try_log(|logger| slog::info!(logger, "Terminating stacks-explorer")); - let _ = docker - .remove_container(stacks_explorer_container_id, None) - .await; - } - - if let Some(ref bitcoin_node_container_id) = self.bitcoin_node_container_id { - let _ = docker - .kill_container(bitcoin_node_container_id, options.clone()) - .await; - ctx.try_log(|logger| slog::info!(logger, "Terminating bitcoin-node")); - let _ = docker - .remove_container(bitcoin_node_container_id, None) - .await; - } - - if let Some(ref stacks_api_container_id) = self.stacks_api_container_id { - let _ = docker - .kill_container(stacks_api_container_id, options.clone()) - .await; - ctx.try_log(|logger| slog::info!(logger, "Terminating stacks-api")); - let _ = docker.remove_container(stacks_api_container_id, None).await; - } - - if let Some(ref postgres_container_id) = self.postgres_container_id { - let _ = docker - .kill_container(postgres_container_id, options.clone()) - .await; - ctx.try_log(|logger| slog::info!(logger, "Terminating postgres")); - let _ = docker.remove_container(postgres_container_id, None).await; - } - - if let Some(ref stacks_node_container_id) = self.stacks_node_container_id { - let _ = docker - .kill_container(stacks_node_container_id, options.clone()) - .await; - ctx.try_log(|logger| slog::info!(logger, "Terminating stacks-node")); - let _ = docker - .remove_container(stacks_node_container_id, None) - .await; - } - - if let Some(ref subnet_node_container_id) = self.subnet_node_container_id { - let _ = docker - .kill_container(subnet_node_container_id, options.clone()) - .await; - ctx.try_log(|logger| slog::info!(logger, "Terminating subnet-node")); - let _ = docker - .remove_container(subnet_node_container_id, None) - .await; - } + let container_ids = vec![ + self.bitcoin_explorer_container_id.clone(), + self.stacks_explorer_container_id.clone(), + self.bitcoin_node_container_id.clone(), + self.stacks_api_container_id.clone(), + self.postgres_container_id.clone(), + self.stacks_node_container_id.clone(), + self.stacks_signer_container_id.clone(), + self.subnet_node_container_id.clone(), + self.subnet_api_container_id.clone(), + ]; - if let Some(ref subnet_api_container_id) = self.subnet_api_container_id { - let _ = docker - .kill_container(subnet_api_container_id, options) - .await; - ctx.try_log(|logger| slog::info!(logger, "Terminating subnet-api")); - let _ = docker.remove_container(subnet_api_container_id, None).await; + for container_id in container_ids.into_iter().flatten() { + let _ = docker.kill_container(&container_id, options.clone()).await; + ctx.try_log(|logger| slog::info!(logger, "Terminating container: {}", &container_id)); + let _ = docker.remove_container(&container_id, None).await; } // Delete network From 0f3f04d5e083e99ba3a510656b72c9724d94a29c Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Wed, 20 Mar 2024 22:46:11 +0100 Subject: [PATCH 04/13] feat: improved config and set 2 signers --- .../stacks-network/src/chains_coordinator.rs | 16 +- components/stacks-network/src/orchestrator.rs | 138 +++++++++++++----- 2 files changed, 116 insertions(+), 38 deletions(-) diff --git a/components/stacks-network/src/chains_coordinator.rs b/components/stacks-network/src/chains_coordinator.rs index 6afe04957..a4d099f9d 100644 --- a/components/stacks-network/src/chains_coordinator.rs +++ b/components/stacks-network/src/chains_coordinator.rs @@ -700,10 +700,16 @@ pub async fn publish_stacking_orders( .and_then(|version| version.parse::().ok()) .unwrap(); - let signer_key = StacksPrivateKey::from_hex( - "1b9397438f32b0d8ad27340e76e35354087b30bec8d335506f5395f7abd139e101", - ) - .unwrap(); + let signer_private_keys = [ + StacksPrivateKey::from_hex( + "7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801", + ) + .unwrap(), + StacksPrivateKey::from_hex( + "530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101", + ) + .unwrap(), + ]; let mut transactions = 0; for (i, pox_stacking_order) in devnet_config.pox_stacking_orders.iter().enumerate() { @@ -751,7 +757,7 @@ pub async fn publish_stacking_orders( pox_version, bitcoin_block_height, current_cycle.into(), - &signer_key, + &signer_private_keys[i], extend_stacking, &btc_address_moved, stx_amount, diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index 98f695afc..bd8cc525f 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -34,7 +34,8 @@ pub struct DevnetOrchestrator { pub termination_success_tx: Option>, pub can_exit: bool, stacks_node_container_id: Option, - stacks_signer_container_id: Option, + stacks_signer_1_container_id: Option, + stacks_signer_2_container_id: Option, stacks_api_container_id: Option, stacks_explorer_container_id: Option, bitcoin_node_container_id: Option, @@ -153,7 +154,8 @@ impl DevnetOrchestrator { can_exit: true, termination_success_tx: None, stacks_node_container_id: None, - stacks_signer_container_id: None, + stacks_signer_1_container_id: None, + stacks_signer_2_container_id: None, stacks_api_container_id: None, stacks_explorer_container_id: None, bitcoin_node_container_id: None, @@ -331,7 +333,7 @@ impl DevnetOrchestrator { let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { order: 2, status: Status::Red, - name: "stacks-signer".into(), + name: "stacks-signer-1".into(), comment: "initializing".into(), })); @@ -568,15 +570,18 @@ impl DevnetOrchestrator { } }; - // Start stacks-signer - let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer".to_string())); + // Start stacks-signer-1 + let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer-1".to_string())); let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { order: 2, status: Status::Yellow, - name: "stacks-signer".into(), + name: "stacks-signer-1".into(), comment: "updating image".into(), })); - match self.prepare_stacks_signer_container(boot_index, ctx).await { + match self + .prepare_stacks_signer_container(boot_index, ctx, 1) + .await + { Ok(_) => {} Err(message) => { let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); @@ -587,10 +592,10 @@ impl DevnetOrchestrator { let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { order: 2, status: Status::Yellow, - name: "stacks-signer".into(), + name: "stacks-signer-1".into(), comment: "booting".into(), })); - match self.boot_stacks_signer_container().await { + match self.boot_stacks_signer_container(1).await { Ok(_) => {} Err(message) => { let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); @@ -601,10 +606,32 @@ impl DevnetOrchestrator { let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { order: 2, status: Status::Green, - name: "stacks-signer".into(), + name: "stacks-signer-1".into(), comment: "Waiting for messages".into(), })); + // Start stacks-signer-2 + let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer-2".to_string())); + match self + .prepare_stacks_signer_container(boot_index, ctx, 2) + .await + { + Ok(_) => {} + Err(message) => { + let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); + self.kill(ctx, Some(&message)).await; + return Err(message); + } + }; + match self.boot_stacks_signer_container(2).await { + Ok(_) => {} + Err(message) => { + let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); + self.kill(ctx, Some(&message)).await; + return Err(message); + } + }; + // Start stacks-explorer if !disable_stacks_explorer { let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { @@ -1005,6 +1032,7 @@ disable_block_download = true disable_inbound_handshakes = true disable_inbound_walks = true public_ip_address = "1.1.1.1:1234" +block_proposal_token = "12345" [miner] min_tx_fee = 1 @@ -1039,7 +1067,18 @@ amount = {} stacks_conf.push_str(&format!( r#" [[events_observer]] -endpoint = "stacks-signer.{}:30002" +endpoint = "stacks-signer-1.{}:30000" +retry_count = 255 +include_data_events = false +events_keys = ["stackerdb", "block_proposal", "burn_blocks"] +"#, + self.network_name + )); + + stacks_conf.push_str(&format!( + r#" +[[events_observer]] +endpoint = "stacks-signer-2.{}:30000" retry_count = 255 include_data_events = false events_keys = ["stackerdb", "block_proposal", "burn_blocks"] @@ -1321,7 +1360,11 @@ start_height = {epoch_3_0} Ok(()) } - pub fn prepare_stacks_signer_config(&self, boot_index: u32) -> Result, String> { + pub fn prepare_stacks_signer_config( + &self, + boot_index: u32, + signer_id: u32, + ) -> Result, String> { let (_, devnet_config) = match &self.network_config { Some(ref network_config) => match network_config.devnet { Some(ref devnet_config) => (network_config, devnet_config), @@ -1330,25 +1373,28 @@ start_height = {epoch_3_0} _ => return Err("unable to get Docker client".into()), }; - let signer_private_key = - "1b9397438f32b0d8ad27340e76e35354087b30bec8d335506f5395f7abd139e101"; + let signer_private_keys = [ + "7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801", + "530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101", + ]; + let signer_conf = format!( r#" stacks_private_key = "{signer_private_key}" node_host = "stacks-node.{network_name}:{stacks_node_rpc_port}" # eg "127.0.0.1:20443" # must be added as event_observer in node config: -endpoint = "0.0.0.0:30002" # e.g 127.0.0.1:30000 +endpoint = "0.0.0.0:30000" # e.g 127.0.0.1:30000 network = "testnet" auth_password = "12345" -db_path = "stacks-signer-0.sqlite" +db_path = "stacks-signer-{signer_id}.sqlite" "#, - signer_private_key = signer_private_key, + signer_private_key = signer_private_keys[(signer_id - 1) as usize], // signer_private_key = devnet_config.signer_private_key, network_name = self.network_name, stacks_node_rpc_port = devnet_config.stacks_node_rpc_port ); let mut signer_conf_path = PathBuf::from(&devnet_config.working_dir); - signer_conf_path.push("conf/Signer.toml"); + signer_conf_path.push(format!("conf/Signer-{signer_id}.toml")); let mut file = File::create(signer_conf_path) .map_err(|e| format!("unable to create Signer.toml: {:?}", e))?; file.write_all(signer_conf.as_bytes()) @@ -1387,7 +1433,7 @@ db_path = "stacks-signer-0.sqlite" "stacks-signer".into(), "run".into(), "--config".into(), - "/src/stacks-signer/Signer.toml".into(), + format!("/src/stacks-signer/Signer-{signer_id}.toml"), ]), env: None, host_config: Some(HostConfig { @@ -1408,6 +1454,7 @@ db_path = "stacks-signer-0.sqlite" &mut self, boot_index: u32, ctx: &Context, + signer_id: u32, ) -> Result<(), String> { let (docker, devnet_config) = match (&self.docker_client, &self.network_config) { (Some(ref docker), Some(ref network_config)) => match network_config.devnet { @@ -1431,10 +1478,10 @@ db_path = "stacks-signer-0.sqlite" .await .map_err(|e| format!("unable to create image: {}", e))?; - let config = self.prepare_stacks_signer_config(boot_index)?; + let config = self.prepare_stacks_signer_config(boot_index, signer_id)?; let options = CreateContainerOptions { - name: format!("stacks-signer.{}", self.network_name), + name: format!("stacks-signer-{signer_id}.{}", self.network_name), platform: Some(devnet_config.docker_platform.to_string()), }; @@ -1444,16 +1491,34 @@ db_path = "stacks-signer-0.sqlite" .map_err(|e| format!("unable to create container: {}", e))? .id; - ctx.try_log(|logger| slog::info!(logger, "Created container stacks-signer: {}", container)); - self.stacks_signer_container_id = Some(container.clone()); + ctx.try_log(|logger| { + slog::info!( + logger, + "Created container stacks-signer-{signer_id}: {}", + container + ) + }); + if signer_id == 1 { + self.stacks_signer_1_container_id = Some(container.clone()); + } else { + self.stacks_signer_2_container_id = Some(container.clone()); + } + // self.stacks_signer_container_id = Some(container.clone()); Ok(()) } - pub async fn boot_stacks_signer_container(&mut self) -> Result<(), String> { - let container = match &self.stacks_signer_container_id { - Some(container) => container.clone(), - _ => return Err("unable to boot container".to_string()), + pub async fn boot_stacks_signer_container(&mut self, signer_id: u32) -> Result<(), String> { + let container = match signer_id { + 1 => match &self.stacks_signer_1_container_id { + Some(container) => container.clone(), + _ => return Err("unable to boot container".to_string()), + }, + 2 => match &self.stacks_signer_2_container_id { + Some(container) => container.clone(), + _ => return Err("unable to boot container".to_string()), + }, + _ => return Err("invalid signer_id".to_string()), }; let docker = match &self.docker_client { @@ -2343,21 +2408,23 @@ events_keys = ["*"] pub async fn stop_containers(&self) -> Result<(), String> { let containers_ids = match ( &self.stacks_node_container_id, - &self.stacks_signer_container_id, + &self.stacks_signer_1_container_id, + &self.stacks_signer_2_container_id, &self.stacks_api_container_id, &self.stacks_explorer_container_id, &self.bitcoin_node_container_id, &self.bitcoin_explorer_container_id, &self.postgres_container_id, ) { - (Some(c1), Some(c2), Some(c3), Some(c4), Some(c5), Some(c6), Some(c7)) => { - (c1, c2, c3, c4, c5, c6, c7) + (Some(c1), Some(c2), Some(c3), Some(c4), Some(c5), Some(c6), Some(c7), Some(c8)) => { + (c1, c2, c3, c4, c5, c6, c7, c8) } _ => return Err("unable to boot container".to_string()), }; let ( stacks_node_c_id, - stacks_signer_c_id, + stacks_signer_1_c_id, + stacks_signer_2_c_id, stacks_api_c_id, stacks_explorer_c_id, bitcoin_node_c_id, @@ -2377,7 +2444,11 @@ events_keys = ["*"] .await; let _ = docker - .kill_container(stacks_signer_c_id, Some(options.clone())) + .kill_container(stacks_signer_1_c_id, Some(options.clone())) + .await; + + let _ = docker + .kill_container(stacks_signer_2_c_id, Some(options.clone())) .await; let _ = docker @@ -2517,7 +2588,8 @@ events_keys = ["*"] self.stacks_api_container_id.clone(), self.postgres_container_id.clone(), self.stacks_node_container_id.clone(), - self.stacks_signer_container_id.clone(), + self.stacks_signer_1_container_id.clone(), + self.stacks_signer_2_container_id.clone(), self.subnet_node_container_id.clone(), self.subnet_api_container_id.clone(), ]; From f69f0312a14a47c0dd2d7432980cfdc7d56dcf5e Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Thu, 21 Mar 2024 19:23:13 +0100 Subject: [PATCH 05/13] feat: make service order in devnet ui dynamic --- .../stacks-network/src/chains_coordinator.rs | 61 +-- components/stacks-network/src/event.rs | 36 ++ components/stacks-network/src/lib.rs | 1 + components/stacks-network/src/orchestrator.rs | 404 ++++++++++-------- components/stacks-network/src/ui/app.rs | 9 +- components/stacks-network/src/ui/mod.rs | 5 +- components/stacks-network/src/ui/ui.rs | 9 +- 7 files changed, 316 insertions(+), 209 deletions(-) diff --git a/components/stacks-network/src/chains_coordinator.rs b/components/stacks-network/src/chains_coordinator.rs index a4d099f9d..97eba6c2a 100644 --- a/components/stacks-network/src/chains_coordinator.rs +++ b/components/stacks-network/src/chains_coordinator.rs @@ -1,7 +1,7 @@ use super::ChainsCoordinatorCommand; +use crate::event::send_status_update; use crate::event::DevnetEvent; -use crate::event::ServiceStatusData; use crate::event::Status; use crate::orchestrator::ServicesMapHosts; @@ -249,6 +249,12 @@ pub async fn start_chains_coordinator( let chains_coordinator_commands_oper = sel.recv(&chains_coordinator_commands_rx); let observer_event_oper = sel.recv(&observer_event_rx); + let DevnetConfig { + use_nakamoto, + enable_subnet_node, + .. + } = config.devnet_config; + loop { let oper = sel.select(); let command = match oper.index() { @@ -294,12 +300,12 @@ pub async fn start_chains_coordinator( ObserverEvent::BitcoinChainEvent((chain_update, _)) => { // Contextual shortcut: Devnet is an environment under control, // with 1 miner. As such we will ignore Reorgs handling. - let (log, status) = match &chain_update { + let (log, comment) = match &chain_update { BitcoinChainEvent::ChainUpdatedWithBlocks(event) => { let tip = event.new_blocks.last().unwrap(); let bitcoin_block_height = tip.block_identifier.index; let log = format!("Bitcoin block #{} received", bitcoin_block_height); - let status = + let comment = format!("mining blocks (chaintip = #{})", bitcoin_block_height); // Stacking orders can't be published until devnet is ready @@ -321,7 +327,7 @@ pub async fn start_chains_coordinator( } } - (log, status) + (log, comment) } BitcoinChainEvent::ChainUpdatedWithReorg(events) => { let tip = events.blocks_to_apply.last().unwrap(); @@ -337,12 +343,14 @@ pub async fn start_chains_coordinator( let _ = devnet_event_tx.send(DevnetEvent::debug(log)); - let _ = devnet_event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 0, - status: Status::Green, - name: "bitcoin-node".into(), - comment: status, - })); + send_status_update( + &devnet_event_tx, + use_nakamoto, + enable_subnet_node, + "bitcoin-node", + Status::Green, + &comment, + ); let _ = devnet_event_tx.send(DevnetEvent::BitcoinChainEvent(chain_update.clone())); } ObserverEvent::StacksChainEvent((chain_event, _)) => { @@ -383,15 +391,20 @@ pub async fn start_chains_coordinator( // Partially update the UI. With current approach a full update // would requires either cloning the block, or passing ownership. - let _ = devnet_event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 1, - status: Status::Green, - name: "stacks-node 2.1".to_string(), - comment: format!( + send_status_update( + &devnet_event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-node", + Status::Green, + &format!( "mining blocks (chaintip = #{})", known_tip.block.block_identifier.index ), - })); + ); + + // devnet_event_tx.send(DevnetEvent::send_status_update(status_update_data)); + let message = if known_tip.block.block_identifier.index == 0 { format!( "Genesis Stacks block anchored in Bitcoin block #{} includes {} transactions", @@ -451,14 +464,14 @@ pub async fn start_chains_coordinator( if config.devnet_config.enable_subnet_node && !subnet_initialized { for tx in transactions.iter() { if tx.tx_description.contains("::commit-block") { - let _ = devnet_event_tx.send(DevnetEvent::ServiceStatus( - ServiceStatusData { - order: 6, - status: Status::Green, - name: "subnet-node".into(), - comment: "⚡️".to_string(), - }, - )); + send_status_update( + &devnet_event_tx, + use_nakamoto, + enable_subnet_node, + "subnet-node", + Status::Green, + "⚡️", + ); subnet_initialized = true; break; } diff --git a/components/stacks-network/src/event.rs b/components/stacks-network/src/event.rs index 512e8db5e..e1d6ed2c3 100644 --- a/components/stacks-network/src/event.rs +++ b/components/stacks-network/src/event.rs @@ -70,6 +70,42 @@ impl DevnetEvent { } } +pub fn send_status_update( + event_tx: &Sender, + with_nakamoto: bool, + with_subnets: bool, + name: &str, + status: Status, + comment: &str, +) { + let signer_order_start = if with_nakamoto { 2 } else { 0 }; + let subnet_order_start = if with_subnets { + 5 + signer_order_start + } else { + signer_order_start + }; + + let order = match name { + "bitcoin-node" => 0, + "stacks-node" => 1, + "stacks-signer-1" => signer_order_start, + "stacks-signer-2" => signer_order_start + 1, + "stacks-api" => signer_order_start + 2, + "subnet-node" => subnet_order_start, + "subnet-api" => subnet_order_start + 1, + "stacks-explorer" => subnet_order_start + 2, + "bitcoin-explorer" => subnet_order_start + 3, + _ => return, + }; + + let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { + order, + status, + name: name.into(), + comment: comment.into(), + })); +} + #[derive(Clone, Debug)] pub enum Status { Red, diff --git a/components/stacks-network/src/lib.rs b/components/stacks-network/src/lib.rs index 6682df491..6bfa0a69d 100644 --- a/components/stacks-network/src/lib.rs +++ b/components/stacks-network/src/lib.rs @@ -186,6 +186,7 @@ async fn do_run_devnet( ), &devnet_path, devnet_config.enable_subnet_node, + devnet_config.use_nakamoto, !devnet_config.bitcoin_controller_automining_disabled, &ctx, )?; diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index bd8cc525f..33e8ea0e6 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -23,7 +23,7 @@ use std::path::PathBuf; use std::sync::mpsc::{Receiver, Sender}; use std::time::Duration; -use crate::event::{DevnetEvent, ServiceStatusData, Status}; +use crate::event::{send_status_update, DevnetEvent, Status}; #[derive(Debug)] pub struct DevnetOrchestrator { @@ -306,6 +306,7 @@ impl DevnetOrchestrator { let disable_bitcoin_explorer = devnet_config.disable_bitcoin_explorer; let enable_subnet_node = devnet_config.enable_subnet_node; let disable_subnet_api = devnet_config.disable_subnet_api; + let use_nakamoto = devnet_config.use_nakamoto; let _ = fs::create_dir(&devnet_config.working_dir); let _ = fs::create_dir(format!("{}/conf", devnet_config.working_dir)); @@ -316,78 +317,85 @@ impl DevnetOrchestrator { let stacks_api_port = devnet_config.stacks_api_port; let subnet_api_port = devnet_config.subnet_api_port; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 0, - status: Status::Red, - name: "bitcoin-node".into(), - comment: "initializing".into(), - })); - - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 1, - status: Status::Red, - name: "stacks-node".into(), - comment: "initializing".into(), - })); - - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 2, - status: Status::Red, - name: "stacks-signer-1".into(), - comment: "initializing".into(), - })); - - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 3, - status: Status::Red, - name: "stacks-api".into(), - comment: if disable_stacks_api { - "disabled".into() - } else { - "initializing".into() - }, - })); - - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 4, - status: Status::Red, - name: "stacks-explorer".into(), - comment: if disable_stacks_explorer { - "disabled".into() - } else { - "initializing".into() - }, - })); - - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 5, - status: Status::Red, - name: "bitcoin-explorer".into(), - comment: if disable_bitcoin_explorer { - "disabled".into() - } else { - "initializing".into() - }, - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "bitcoin-node", + Status::Red, + "initializing", + ); + + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-node", + Status::Red, + "initializing", + ); + + if use_nakamoto { + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-1", + Status::Red, + "initializing", + ); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-2", + Status::Red, + "initializing", + ); + } + + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-api", + Status::Red, + "initializing", + ); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-explorer", + Status::Red, + "initializing", + ); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "bitcoin-explorer", + Status::Red, + "initializing", + ); if enable_subnet_node { - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 6, - status: Status::Red, - name: "subnet-node".into(), - comment: "initializing".into(), - })); - - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 7, - status: Status::Red, - name: "subnet-api".into(), - comment: if disable_subnet_api { - "disabled".into() - } else { - "initializing".into() - }, - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "subnet-node", + Status::Red, + "initializing", + ); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "subnet-api", + Status::Red, + "initializing", + ); } let _ = event_tx.send(DevnetEvent::info(format!( @@ -397,12 +405,14 @@ impl DevnetOrchestrator { // Start bitcoind let _ = event_tx.send(DevnetEvent::info("Starting bitcoin-node".to_string())); - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 0, - status: Status::Yellow, - name: "bitcoin-node".into(), - comment: "preparing container".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "bitcoin-node", + Status::Yellow, + "preparing container", + ); match self.prepare_bitcoin_node_container(ctx).await { Ok(_) => {} Err(message) => { @@ -411,12 +421,14 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 0, - status: Status::Yellow, - name: "bitcoin-node".into(), - comment: "booting".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "bitcoin-node", + Status::Yellow, + "booting", + ); match self.boot_bitcoin_node_container().await { Ok(_) => { self.initialize_bitcoin_node(&event_tx).await?; @@ -431,12 +443,14 @@ impl DevnetOrchestrator { // Start stacks-api if !disable_stacks_api { // Start postgres - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 3, - status: Status::Yellow, - name: "stacks-api".into(), - comment: "preparing postgres container".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-api", + Status::Yellow, + "preparing postgres container", + ); let _ = event_tx.send(DevnetEvent::info("Starting postgres".to_string())); match self.prepare_postgres_container(ctx).await { Ok(_) => {} @@ -454,12 +468,14 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 3, - status: Status::Yellow, - name: "stacks-api".into(), - comment: "preparing container".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-api", + Status::Yellow, + "preparing container", + ); let _ = event_tx.send(DevnetEvent::info("Starting stacks-api".to_string())); match self.prepare_stacks_api_container(ctx).await { @@ -470,12 +486,15 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 3, - status: Status::Green, - name: "stacks-api".into(), - comment: format!("http://localhost:{}/doc", stacks_api_port), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-api", + Status::Green, + &format!("http://localhost:{}/doc", stacks_api_port), + ); + match self.boot_stacks_api_container(ctx).await { Ok(_) => {} Err(message) => { @@ -497,12 +516,14 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 6, - status: Status::Yellow, - name: "subnet-node".into(), - comment: "booting".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "subnet-node", + Status::Yellow, + "booting", + ); match self.boot_subnet_node_container().await { Ok(_) => {} Err(message) => { @@ -522,12 +543,14 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 7, - status: Status::Green, - name: "subnet-api".into(), - comment: format!("http://localhost:{}/doc", subnet_api_port), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "subnet-api", + Status::Green, + &format!("http://localhost:{}/doc", subnet_api_port), + ); match self.boot_subnet_api_container().await { Ok(_) => {} Err(message) => { @@ -541,12 +564,14 @@ impl DevnetOrchestrator { // Start stacks-node let _ = event_tx.send(DevnetEvent::info("Starting stacks-node".to_string())); - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 1, - status: Status::Yellow, - name: "stacks-node".into(), - comment: "updating image".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-node", + Status::Yellow, + "updating image", + ); match self.prepare_stacks_node_container(boot_index, ctx).await { Ok(_) => {} Err(message) => { @@ -555,12 +580,14 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 1, - status: Status::Yellow, - name: "stacks-node".into(), - comment: "booting".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-node", + Status::Yellow, + "booting", + ); match self.boot_stacks_node_container().await { Ok(_) => {} Err(message) => { @@ -572,12 +599,14 @@ impl DevnetOrchestrator { // Start stacks-signer-1 let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer-1".to_string())); - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 2, - status: Status::Yellow, - name: "stacks-signer-1".into(), - comment: "updating image".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-1", + Status::Yellow, + "updating image", + ); match self .prepare_stacks_signer_container(boot_index, ctx, 1) .await @@ -589,12 +618,14 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 2, - status: Status::Yellow, - name: "stacks-signer-1".into(), - comment: "booting".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-1", + Status::Yellow, + "booting", + ); match self.boot_stacks_signer_container(1).await { Ok(_) => {} Err(message) => { @@ -603,12 +634,14 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 2, - status: Status::Green, - name: "stacks-signer-1".into(), - comment: "Waiting for messages".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-1", + Status::Green, + "Waiting for messages", + ); // Start stacks-signer-2 let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer-2".to_string())); @@ -634,12 +667,14 @@ impl DevnetOrchestrator { // Start stacks-explorer if !disable_stacks_explorer { - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 4, - status: Status::Yellow, - name: "stacks-explorer".into(), - comment: "preparing container".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-explorer", + Status::Yellow, + "preparing container", + ); match self.prepare_stacks_explorer_container(ctx).await { Ok(_) => {} Err(message) => { @@ -657,22 +692,26 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 4, - status: Status::Green, - name: "stacks-explorer".into(), - comment: format!("http://localhost:{}", stacks_explorer_port), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-explorer", + Status::Green, + &format!("http://localhost:{}", stacks_explorer_port), + ); } // Start bitcoin-explorer if !disable_bitcoin_explorer { - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 5, - status: Status::Yellow, - name: "bitcoin-explorer".into(), - comment: "preparing container".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "bitcoin-explorer", + Status::Yellow, + "preparing container", + ); match self.prepare_bitcoin_explorer_container(ctx).await { Ok(_) => {} Err(message) => { @@ -690,12 +729,14 @@ impl DevnetOrchestrator { return Err(message); } }; - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 5, - status: Status::Green, - name: "bitcoin-explorer".into(), - comment: format!("http://localhost:{}", bitcoin_explorer_port), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "bitcoin-explorer", + Status::Green, + &format!("http://localhost:{}", bitcoin_explorer_port), + ); } loop { @@ -706,18 +747,23 @@ impl DevnetOrchestrator { break; } Ok(false) => { - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 0, - status: Status::Yellow, - name: "bitcoin-node".into(), - comment: "restarting".into(), - })); - let _ = event_tx.send(DevnetEvent::ServiceStatus(ServiceStatusData { - order: 1, - status: Status::Yellow, - name: "stacks-node".into(), - comment: "restarting".into(), - })); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "bitcoin-node", + Status::Yellow, + "restarting", + ); + + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-node", + Status::Yellow, + "restarting", + ); let _ = event_tx.send(DevnetEvent::debug("Killing containers".into())); let _ = self.stop_containers().await; diff --git a/components/stacks-network/src/ui/app.rs b/components/stacks-network/src/ui/app.rs index 403f7cc19..e55a57ed7 100644 --- a/components/stacks-network/src/ui/app.rs +++ b/components/stacks-network/src/ui/app.rs @@ -17,6 +17,7 @@ pub enum BlockData { pub struct App<'a> { pub title: &'a str, pub subnet_enabled: bool, + pub nakamoto_enabled: bool, pub devnet_path: &'a str, pub should_quit: bool, pub blocks: Vec, @@ -28,7 +29,12 @@ pub struct App<'a> { } impl<'a> App<'a> { - pub fn new(title: &'a str, devnet_path: &'a str, subnet_enabled: bool) -> App<'a> { + pub fn new( + title: &'a str, + devnet_path: &'a str, + subnet_enabled: bool, + nakamoto_enabled: bool, + ) -> App<'a> { App { title, devnet_path, @@ -40,6 +46,7 @@ impl<'a> App<'a> { logs: StatefulList::with_items(vec![]), services: StatefulList::with_items(vec![]), subnet_enabled, + nakamoto_enabled, } } diff --git a/components/stacks-network/src/ui/mod.rs b/components/stacks-network/src/ui/mod.rs index 74987a3fd..26bdd2750 100644 --- a/components/stacks-network/src/ui/mod.rs +++ b/components/stacks-network/src/ui/mod.rs @@ -32,6 +32,7 @@ pub fn start_ui( orchestrator_terminated_rx: Receiver, devnet_path: &str, subnet_enabled: bool, + nakamoto_enabled: bool, automining_enabled: bool, ctx: &Context, ) -> Result<(), String> { @@ -42,6 +43,7 @@ pub fn start_ui( orchestrator_terminated_rx, devnet_path, subnet_enabled, + nakamoto_enabled, automining_enabled, ctx, ); @@ -58,6 +60,7 @@ pub fn do_start_ui( orchestrator_terminated_rx: Receiver, devnet_path: &str, subnet_enabled: bool, + nakamoto_enabled: bool, automining_enabled: bool, ctx: &Context, ) -> Result<(), String> { @@ -95,7 +98,7 @@ pub fn do_start_ui( } }); - let mut app = App::new("Clarinet", devnet_path, subnet_enabled); + let mut app = App::new("Clarinet", devnet_path, subnet_enabled, nakamoto_enabled); terminal .clear() diff --git a/components/stacks-network/src/ui/ui.rs b/components/stacks-network/src/ui/ui.rs index b8a6e5b1d..b6f251121 100644 --- a/components/stacks-network/src/ui/ui.rs +++ b/components/stacks-network/src/ui/ui.rs @@ -24,10 +24,11 @@ pub fn draw(f: &mut Frame, app: &mut App) { .constraints([Constraint::Min(0), Constraint::Length(78)].as_ref()) .split(page_components[1]); - let service_len = match app.subnet_enabled { - false => 8, - true => 10, - }; + let nb_of_services = 5; + let nb_of_signers = if app.nakamoto_enabled { 2 } else { 0 }; + let nb_of_subnet_services = if app.subnet_enabled { 2 } else { 0 }; + + let service_len = nb_of_services + nb_of_signers + nb_of_subnet_services + 2; let top_right_components = Layout::default() .direction(Direction::Vertical) From a473664dd278429b69ac24c6aea56f37b43399f7 Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:59:54 +0100 Subject: [PATCH 06/13] refactor: minor changes --- components/stacks-network/src/event.rs | 22 +++++++--------- components/stacks-network/src/orchestrator.rs | 25 ++++++++++--------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/components/stacks-network/src/event.rs b/components/stacks-network/src/event.rs index e1d6ed2c3..e341d48d7 100644 --- a/components/stacks-network/src/event.rs +++ b/components/stacks-network/src/event.rs @@ -78,23 +78,19 @@ pub fn send_status_update( status: Status, comment: &str, ) { - let signer_order_start = if with_nakamoto { 2 } else { 0 }; - let subnet_order_start = if with_subnets { - 5 + signer_order_start - } else { - signer_order_start - }; + let signers_services = if with_nakamoto { 2 } else { 0 }; + let subnet_services = if with_subnets { 2 } else { 0 }; let order = match name { "bitcoin-node" => 0, "stacks-node" => 1, - "stacks-signer-1" => signer_order_start, - "stacks-signer-2" => signer_order_start + 1, - "stacks-api" => signer_order_start + 2, - "subnet-node" => subnet_order_start, - "subnet-api" => subnet_order_start + 1, - "stacks-explorer" => subnet_order_start + 2, - "bitcoin-explorer" => subnet_order_start + 3, + "stacks-signer-1" => 2, + "stacks-signer-2" => 3, + "stacks-api" => signers_services + 2, + "subnet-node" => signers_services + 3, + "subnet-api" => signers_services + 4, + "stacks-explorer" => signers_services + subnet_services + 3, + "bitcoin-explorer" => signers_services + subnet_services + 4, _ => return, }; diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index 33e8ea0e6..3422eb426 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -1109,28 +1109,29 @@ amount = {} account.stx_address, account.balance )); } - - stacks_conf.push_str(&format!( - r#" + if devnet_config.use_nakamoto { + stacks_conf.push_str(&format!( + r#" [[events_observer]] -endpoint = "stacks-signer-1.{}:30000" +endpoint = "stacks-signer-1.{}:30001" retry_count = 255 include_data_events = false events_keys = ["stackerdb", "block_proposal", "burn_blocks"] "#, - self.network_name - )); + self.network_name + )); - stacks_conf.push_str(&format!( - r#" + stacks_conf.push_str(&format!( + r#" [[events_observer]] -endpoint = "stacks-signer-2.{}:30000" +endpoint = "stacks-signer-2.{}:30002" retry_count = 255 include_data_events = false events_keys = ["stackerdb", "block_proposal", "burn_blocks"] "#, - self.network_name - )); + self.network_name + )); + } stacks_conf.push_str(&format!( r#" @@ -1429,7 +1430,7 @@ start_height = {epoch_3_0} stacks_private_key = "{signer_private_key}" node_host = "stacks-node.{network_name}:{stacks_node_rpc_port}" # eg "127.0.0.1:20443" # must be added as event_observer in node config: -endpoint = "0.0.0.0:30000" # e.g 127.0.0.1:30000 +endpoint = "0.0.0.0:3000{signer_id}" network = "testnet" auth_password = "12345" db_path = "stacks-signer-{signer_id}.sqlite" From c97cf8ba070e1fdde23baf245dc470e68f43f8c9 Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:21:28 +0100 Subject: [PATCH 07/13] refactor: minor changes --- .../clarinet-cli/src/generate/project.rs | 9 ++-- .../clarinet-files/src/network_manifest.rs | 5 +- .../stacks-network/src/chains_coordinator.rs | 53 +------------------ components/stacks-network/src/orchestrator.rs | 39 +++++++++++--- 4 files changed, 41 insertions(+), 65 deletions(-) diff --git a/components/clarinet-cli/src/generate/project.rs b/components/clarinet-cli/src/generate/project.rs index aa5954eb0..cd130d8de 100644 --- a/components/clarinet-cli/src/generate/project.rs +++ b/components/clarinet-cli/src/generate/project.rs @@ -1,10 +1,10 @@ use clarinet_files::{ DEFAULT_BITCOIN_EXPLORER_IMAGE, DEFAULT_BITCOIN_NODE_IMAGE, DEFAULT_DERIVATION_PATH, DEFAULT_EPOCH_2_0, DEFAULT_EPOCH_2_05, DEFAULT_EPOCH_2_1, DEFAULT_EPOCH_2_2, DEFAULT_EPOCH_2_3, - DEFAULT_EPOCH_2_4, DEFAULT_EPOCH_2_5, DEFAULT_EPOCH_3_0, DEFAULT_FAUCET_MNEMONIC, - DEFAULT_POSTGRES_IMAGE, DEFAULT_STACKS_API_IMAGE, DEFAULT_STACKS_EXPLORER_IMAGE, - DEFAULT_STACKS_MINER_MNEMONIC, DEFAULT_STACKS_NODE_IMAGE, DEFAULT_SUBNET_API_IMAGE, - DEFAULT_SUBNET_CONTRACT_ID, DEFAULT_SUBNET_MNEMONIC, DEFAULT_SUBNET_NODE_IMAGE, + DEFAULT_EPOCH_2_4, DEFAULT_EPOCH_2_5, DEFAULT_FAUCET_MNEMONIC, DEFAULT_POSTGRES_IMAGE, + DEFAULT_STACKS_API_IMAGE, DEFAULT_STACKS_EXPLORER_IMAGE, DEFAULT_STACKS_MINER_MNEMONIC, + DEFAULT_STACKS_NODE_IMAGE, DEFAULT_SUBNET_API_IMAGE, DEFAULT_SUBNET_CONTRACT_ID, + DEFAULT_SUBNET_MNEMONIC, DEFAULT_SUBNET_NODE_IMAGE, }; use super::changes::{Changes, DirectoryCreation, FileCreation}; @@ -410,7 +410,6 @@ disable_stacks_api = false # epoch_2_3 = {DEFAULT_EPOCH_2_3} # epoch_2_4 = {DEFAULT_EPOCH_2_4} # epoch_2_5 = {DEFAULT_EPOCH_2_5} -# epoch_3_0 = {DEFAULT_EPOCH_3_0} # Send some stacking orders diff --git a/components/clarinet-files/src/network_manifest.rs b/components/clarinet-files/src/network_manifest.rs index f3d0a1864..59fb7aaa7 100644 --- a/components/clarinet-files/src/network_manifest.rs +++ b/components/clarinet-files/src/network_manifest.rs @@ -46,8 +46,9 @@ pub const DEFAULT_EPOCH_2_1: u64 = 101; pub const DEFAULT_EPOCH_2_2: u64 = 102; pub const DEFAULT_EPOCH_2_3: u64 = 103; pub const DEFAULT_EPOCH_2_4: u64 = 104; -pub const DEFAULT_EPOCH_2_5: u64 = 105; -pub const DEFAULT_EPOCH_3_0: u64 = 121; +pub const DEFAULT_EPOCH_2_5: u64 = 108; +// Epoch 3.0 isn't stable for now, let's focus on running 2.5 +pub const DEFAULT_EPOCH_3_0: u64 = 100001; // Currently, the pox-4 contract has these values hardcoded: // https://github.com/stacks-network/stacks-core/blob/e09ab931e2f15ff70f3bb5c2f4d7afb[…]42bd7bec6/stackslib/src/chainstate/stacks/boot/pox-testnet.clar diff --git a/components/stacks-network/src/chains_coordinator.rs b/components/stacks-network/src/chains_coordinator.rs index 97eba6c2a..811be40ad 100644 --- a/components/stacks-network/src/chains_coordinator.rs +++ b/components/stacks-network/src/chains_coordinator.rs @@ -713,7 +713,7 @@ pub async fn publish_stacking_orders( .and_then(|version| version.parse::().ok()) .unwrap(); - let signer_private_keys = [ + let default_signing_keys = [ StacksPrivateKey::from_hex( "7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801", ) @@ -770,7 +770,7 @@ pub async fn publish_stacking_orders( pox_version, bitcoin_block_height, current_cycle.into(), - &signer_private_keys[i], + &default_signing_keys[i % 2], extend_stacking, &btc_address_moved, stx_amount, @@ -1087,52 +1087,3 @@ fn make_signer_key_signature( signature.to_rsv() } - -#[cfg(test)] -mod key_tests { - use super::*; - use clarinet_files::DEFAULT_DERIVATION_PATH; - use stackslib::{net::stackerdb::db, util::hash::bytes_to_hex}; - #[test] - fn test_make_signer_key_signature() { - let label = "wallet_1".to_string(); - let mnemonic = "sell invite acquire kitten bamboo drastic jelly vivid peace spawn twice guilt pave pen trash pretty park cube fragile unaware remain midnight betray rebuild".to_string(); - - let account = AccountConfig { - label, - mnemonic, - derivation: DEFAULT_DERIVATION_PATH.into(), - balance: 100000, - stx_address: "ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5".into(), - btc_address: "mr1iPkD9N3RJZZxXRk7xF9d36gffa6exNC".into(), - is_mainnet: false, - }; - - let addr_bytes = account - .btc_address - .from_base58() - .expect("Unable to get bytes from btc address"); - - let pox_addr_tuple = ClarityValue::Tuple( - TupleData::from_data(vec![ - ( - ClarityName::try_from("version".to_owned()).unwrap(), - ClarityValue::buff_from_byte(AddressHashMode::SerializeP2PKH as u8), - ), - ( - ClarityName::try_from("hashbytes".to_owned()).unwrap(), - ClarityValue::Sequence(SequenceData::Buffer(BuffData { - data: Hash160::from_bytes(&addr_bytes[1..21]) - .unwrap() - .as_bytes() - .to_vec(), - })), - ), - ]) - .unwrap(), - ); - - let pox_addr = PoxAddress::try_from_pox_tuple(false, &pox_addr_tuple).unwrap(); - dbg!(pox_addr); - } -} diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index 3422eb426..6ef22ea88 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -640,11 +640,19 @@ impl DevnetOrchestrator { enable_subnet_node, "stacks-signer-1", Status::Green, - "Waiting for messages", + "running", ); // Start stacks-signer-2 let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer-2".to_string())); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-2", + Status::Yellow, + "updating image", + ); match self .prepare_stacks_signer_container(boot_index, ctx, 2) .await @@ -656,6 +664,14 @@ impl DevnetOrchestrator { return Err(message); } }; + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-2", + Status::Yellow, + "booting", + ); match self.boot_stacks_signer_container(2).await { Ok(_) => {} Err(message) => { @@ -664,6 +680,14 @@ impl DevnetOrchestrator { return Err(message); } }; + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-2", + Status::Green, + "running", + ); // Start stacks-explorer if !disable_stacks_explorer { @@ -1412,15 +1436,16 @@ start_height = {epoch_3_0} boot_index: u32, signer_id: u32, ) -> Result, String> { - let (_, devnet_config) = match &self.network_config { + let devnet_config = match &self.network_config { Some(ref network_config) => match network_config.devnet { - Some(ref devnet_config) => (network_config, devnet_config), - _ => return Err("unable to get devnet configuration".into()), + Some(ref devnet_config) => devnet_config, + _ => return Err("unable to initialize bitcoin node".to_string()), }, - _ => return Err("unable to get Docker client".into()), + _ => return Err("unable to initialize bitcoin node".to_string()), }; - let signer_private_keys = [ + // the default wallet_1 and wallet_2 are the default signers + let default_signing_keys = [ "7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801", "530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101", ]; @@ -1435,7 +1460,7 @@ network = "testnet" auth_password = "12345" db_path = "stacks-signer-{signer_id}.sqlite" "#, - signer_private_key = signer_private_keys[(signer_id - 1) as usize], + signer_private_key = default_signing_keys[(signer_id - 1) as usize], // signer_private_key = devnet_config.signer_private_key, network_name = self.network_name, stacks_node_rpc_port = devnet_config.stacks_node_rpc_port From ea4af824b9bc233d0d998f911bca38942a017de5 Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:51:47 +0100 Subject: [PATCH 08/13] chore: upgrade dependencies --- Cargo.lock | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 493288005..b0a8acd05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -789,19 +789,6 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" -[[package]] -name = "clar2wasm" -version = "0.1.0" -source = "git+https://github.com/stacks-network/clarity-wasm.git?branch=chore/update-clarity#d08b7628206b36f6d7a5e7a92a786ac007c8e7e6" -dependencies = [ - "clap", - "clarity", - "lazy_static", - "regex", - "walrus", - "wat", -] - [[package]] name = "clar2wasm" version = "0.1.0" @@ -953,7 +940,7 @@ dependencies = [ [[package]] name = "clarity" version = "2.3.0" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#5eb967cf4f58efcffe385c7a6fd2ed82e5f5da58" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#35cce11f4a7e49f29dd1cf06680abfbd31099669" dependencies = [ "getrandom 0.2.8", "hashbrown 0.14.3", @@ -1035,7 +1022,7 @@ dependencies = [ "atty", "bytes", "chrono", - "clar2wasm 0.1.0 (git+https://github.com/stacks-network/clarity-wasm.git)", + "clar2wasm", "clarity", "debug_types", "futures", @@ -1066,7 +1053,7 @@ dependencies = [ [[package]] name = "clarity-repl" version = "2.3.1" -source = "git+https://github.com/hirosystems/clarinet.git#0288a26106b1339b0d556b3cb0b0093595936a01" +source = "git+https://github.com/hirosystems/clarinet.git#05c6a57097359e321d597813898234d040b021b2" dependencies = [ "ansi_term", "atty", @@ -2293,7 +2280,7 @@ dependencies = [ [[package]] name = "hiro-system-kit" version = "0.1.0" -source = "git+https://github.com/hirosystems/clarinet.git#0288a26106b1339b0d556b3cb0b0093595936a01" +source = "git+https://github.com/hirosystems/clarinet.git#05c6a57097359e321d597813898234d040b021b2" dependencies = [ "ansi_term", "atty", @@ -2967,7 +2954,7 @@ dependencies = [ [[package]] name = "libstackerdb" version = "0.0.1" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#5eb967cf4f58efcffe385c7a6fd2ed82e5f5da58" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#35cce11f4a7e49f29dd1cf06680abfbd31099669" dependencies = [ "clarity", "secp256k1 0.24.3", @@ -3703,7 +3690,7 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "pox-locking" version = "2.4.0" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#5eb967cf4f58efcffe385c7a6fd2ed82e5f5da58" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#35cce11f4a7e49f29dd1cf06680abfbd31099669" dependencies = [ "clarity", "slog", @@ -4984,7 +4971,7 @@ dependencies = [ [[package]] name = "stacks-common" version = "0.0.2" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#5eb967cf4f58efcffe385c7a6fd2ed82e5f5da58" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#35cce11f4a7e49f29dd1cf06680abfbd31099669" dependencies = [ "chrono", "curve25519-dalek 2.0.0", @@ -5086,7 +5073,7 @@ dependencies = [ [[package]] name = "stacks-rpc-client" version = "2.3.1" -source = "git+https://github.com/hirosystems/clarinet.git#0288a26106b1339b0d556b3cb0b0093595936a01" +source = "git+https://github.com/hirosystems/clarinet.git#05c6a57097359e321d597813898234d040b021b2" dependencies = [ "clarity-repl 2.3.1 (git+https://github.com/hirosystems/clarinet.git)", "hmac 0.12.1", @@ -5103,10 +5090,10 @@ dependencies = [ [[package]] name = "stackslib" version = "0.0.1" -source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#5eb967cf4f58efcffe385c7a6fd2ed82e5f5da58" +source = "git+https://github.com/stacks-network/stacks-core.git?branch=feat/clarity-wasm-next#35cce11f4a7e49f29dd1cf06680abfbd31099669" dependencies = [ "chrono", - "clar2wasm 0.1.0 (git+https://github.com/stacks-network/clarity-wasm.git?branch=chore/update-clarity)", + "clar2wasm", "clarity", "curve25519-dalek 2.0.0", "ed25519-dalek", From 412775adcd9e3d8d7db19bd4bef0782f655ac334 Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:55:13 +0100 Subject: [PATCH 09/13] refactor: update default nakamoto devnet images --- components/clarinet-files/src/network_manifest.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/clarinet-files/src/network_manifest.rs b/components/clarinet-files/src/network_manifest.rs index 59fb7aaa7..4e586ccc5 100644 --- a/components/clarinet-files/src/network_manifest.rs +++ b/components/clarinet-files/src/network_manifest.rs @@ -17,9 +17,10 @@ pub const DEFAULT_DERIVATION_PATH: &str = "m/44'/5757'/0'/0/0"; pub const DEFAULT_STACKS_NODE_IMAGE: &str = "quay.io/hirosystems/stacks-node:devnet-2.4.0.0.0"; pub const DEFAULT_STACKS_API_IMAGE: &str = "hirosystems/stacks-blockchain-api:latest"; // Nakamoto images overrides -pub const DEFAULT_STACKS_NODE_IMAGE_NAKA: &str = "blockstack/stacks-blockchain:devnet-next-stable"; +pub const DEFAULT_STACKS_NODE_IMAGE_NAKA: &str = + "quay.io/hirosystems/stacks-node:devnet-with-signer-beta4"; pub const DEFAULT_STACKS_API_IMAGE_NAKA: &str = - "hirosystems/stacks-blockchain-api:7.9.0-nakamoto.1"; + "hirosystems/stacks-blockchain-api:7.10.0-nakamoto.1"; pub const DEFAULT_BITCOIN_NODE_IMAGE: &str = "quay.io/hirosystems/bitcoind:26.0"; pub const DEFAULT_BITCOIN_EXPLORER_IMAGE: &str = "quay.io/hirosystems/bitcoin-explorer:devnet"; From 379e6f0e543798f59bb57257965d58b64e7052e7 Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:56:23 +0100 Subject: [PATCH 10/13] refactor: update default nakamoto devnet images --- components/clarinet-files/src/network_manifest.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/clarinet-files/src/network_manifest.rs b/components/clarinet-files/src/network_manifest.rs index 4e586ccc5..1c2170ba7 100644 --- a/components/clarinet-files/src/network_manifest.rs +++ b/components/clarinet-files/src/network_manifest.rs @@ -19,8 +19,7 @@ pub const DEFAULT_STACKS_API_IMAGE: &str = "hirosystems/stacks-blockchain-api:la // Nakamoto images overrides pub const DEFAULT_STACKS_NODE_IMAGE_NAKA: &str = "quay.io/hirosystems/stacks-node:devnet-with-signer-beta4"; -pub const DEFAULT_STACKS_API_IMAGE_NAKA: &str = - "hirosystems/stacks-blockchain-api:7.10.0-nakamoto.1"; +pub const DEFAULT_STACKS_API_IMAGE_NAKA: &str = "hirosystems/stacks-blockchain-api:7.10.0-beta.1"; pub const DEFAULT_BITCOIN_NODE_IMAGE: &str = "quay.io/hirosystems/bitcoind:26.0"; pub const DEFAULT_BITCOIN_EXPLORER_IMAGE: &str = "quay.io/hirosystems/bitcoin-explorer:devnet"; From 56997a180b28bb7e1d79b2e2e03036ebe5403e35 Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:02:10 +0100 Subject: [PATCH 11/13] fix: disable signers in non-nakamoto mode --- components/stacks-network/src/orchestrator.rs | 182 +++++++++--------- 1 file changed, 92 insertions(+), 90 deletions(-) diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index 6ef22ea88..4082d0b35 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -597,97 +597,99 @@ impl DevnetOrchestrator { } }; - // Start stacks-signer-1 - let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer-1".to_string())); - send_status_update( - &event_tx, - use_nakamoto, - enable_subnet_node, - "stacks-signer-1", - Status::Yellow, - "updating image", - ); - match self - .prepare_stacks_signer_container(boot_index, ctx, 1) - .await - { - Ok(_) => {} - Err(message) => { - let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); - self.kill(ctx, Some(&message)).await; - return Err(message); - } - }; - send_status_update( - &event_tx, - use_nakamoto, - enable_subnet_node, - "stacks-signer-1", - Status::Yellow, - "booting", - ); - match self.boot_stacks_signer_container(1).await { - Ok(_) => {} - Err(message) => { - let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); - self.kill(ctx, Some(&message)).await; - return Err(message); - } - }; - send_status_update( - &event_tx, - use_nakamoto, - enable_subnet_node, - "stacks-signer-1", - Status::Green, - "running", - ); + if use_nakamoto { + // Start stacks-signer-1 + let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer-1".to_string())); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-1", + Status::Yellow, + "updating image", + ); + match self + .prepare_stacks_signer_container(boot_index, ctx, 1) + .await + { + Ok(_) => {} + Err(message) => { + let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); + self.kill(ctx, Some(&message)).await; + return Err(message); + } + }; + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-1", + Status::Yellow, + "booting", + ); + match self.boot_stacks_signer_container(1).await { + Ok(_) => {} + Err(message) => { + let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); + self.kill(ctx, Some(&message)).await; + return Err(message); + } + }; + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-1", + Status::Green, + "running", + ); - // Start stacks-signer-2 - let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer-2".to_string())); - send_status_update( - &event_tx, - use_nakamoto, - enable_subnet_node, - "stacks-signer-2", - Status::Yellow, - "updating image", - ); - match self - .prepare_stacks_signer_container(boot_index, ctx, 2) - .await - { - Ok(_) => {} - Err(message) => { - let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); - self.kill(ctx, Some(&message)).await; - return Err(message); - } - }; - send_status_update( - &event_tx, - use_nakamoto, - enable_subnet_node, - "stacks-signer-2", - Status::Yellow, - "booting", - ); - match self.boot_stacks_signer_container(2).await { - Ok(_) => {} - Err(message) => { - let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); - self.kill(ctx, Some(&message)).await; - return Err(message); - } - }; - send_status_update( - &event_tx, - use_nakamoto, - enable_subnet_node, - "stacks-signer-2", - Status::Green, - "running", - ); + // Start stacks-signer-2 + let _ = event_tx.send(DevnetEvent::info("Starting stacks-signer-2".to_string())); + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-2", + Status::Yellow, + "updating image", + ); + match self + .prepare_stacks_signer_container(boot_index, ctx, 2) + .await + { + Ok(_) => {} + Err(message) => { + let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); + self.kill(ctx, Some(&message)).await; + return Err(message); + } + }; + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-2", + Status::Yellow, + "booting", + ); + match self.boot_stacks_signer_container(2).await { + Ok(_) => {} + Err(message) => { + let _ = event_tx.send(DevnetEvent::FatalError(message.clone())); + self.kill(ctx, Some(&message)).await; + return Err(message); + } + }; + send_status_update( + &event_tx, + use_nakamoto, + enable_subnet_node, + "stacks-signer-2", + Status::Green, + "running", + ); + } // Start stacks-explorer if !disable_stacks_explorer { From d101c6b81ee4fed44ce7cc552a25ce558be7852d Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:22:17 +0100 Subject: [PATCH 12/13] fix: stack-extend txs in devnet --- .../stacks-network/src/chains_coordinator.rs | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/components/stacks-network/src/chains_coordinator.rs b/components/stacks-network/src/chains_coordinator.rs index 811be40ad..b26c1a8f3 100644 --- a/components/stacks-network/src/chains_coordinator.rs +++ b/components/stacks-network/src/chains_coordinator.rs @@ -966,37 +966,44 @@ fn get_stacking_tx_method_and_args( let pox_addr = PoxAddress::try_from_pox_tuple(false, &pox_addr_tuple).unwrap(); let burn_block_height: u128 = (bitcoin_block_height - 1).into(); - let (method, topic, mut arguments) = match extend_stacking { - false => ( - "stack-stx", - Pox4SignatureTopic::StackStx, - vec![ - ClarityValue::UInt(stx_amount.into()), - pox_addr_tuple, - ClarityValue::UInt(burn_block_height), - ClarityValue::UInt(duration.into()), - ], - ), - true => ( - "stack-extend", - Pox4SignatureTopic::StackExtend, - vec![ClarityValue::UInt(duration.into()), pox_addr_tuple], - ), + + let mut arguments = if extend_stacking { + vec![ClarityValue::UInt(duration.into()), pox_addr_tuple] + } else { + vec![ + ClarityValue::UInt(stx_amount.into()), + pox_addr_tuple, + ClarityValue::UInt(burn_block_height), + ClarityValue::UInt(duration.into()), + ] + }; + + let method = if extend_stacking { + "stack-extend" + } else { + "stack-stx" }; - // extra arguments for pox-4 - // (signer-sig (optional (buff 65))) - // (signer-key (buff 33)) - // (max-amount uint) - // (auth-id uint) if pox_version >= 4 { + // extra arguments for pox-4 ( for both stack-stx and stack-extend) + // (signer-sig (optional (buff 65))) + // (signer-key (buff 33)) + // (max-amount uint) + // (auth-id uint) + let signature_amount = if extend_stacking { 0 } else { stx_amount }; + let topic = if extend_stacking { + Pox4SignatureTopic::StackExtend + } else { + Pox4SignatureTopic::StackStx + }; + let signer_sig = make_signer_key_signature( &pox_addr, signer_key, cycle, &topic, duration.into(), - stx_amount.into(), + signature_amount.into(), auth_id, ); let pub_key = StacksPublicKey::from_private(signer_key); From ff289e8c91bd56e4745e55bb1dfb258ac9bc0250 Mon Sep 17 00:00:00 2001 From: Hugo Caillard <911307+hugocaillard@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:25:00 +0100 Subject: [PATCH 13/13] refactor: minor change --- components/stacks-network/src/chains_coordinator.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/stacks-network/src/chains_coordinator.rs b/components/stacks-network/src/chains_coordinator.rs index b26c1a8f3..5ba244c48 100644 --- a/components/stacks-network/src/chains_coordinator.rs +++ b/components/stacks-network/src/chains_coordinator.rs @@ -967,6 +967,12 @@ fn get_stacking_tx_method_and_args( let burn_block_height: u128 = (bitcoin_block_height - 1).into(); + let method = if extend_stacking { + "stack-extend" + } else { + "stack-stx" + }; + let mut arguments = if extend_stacking { vec![ClarityValue::UInt(duration.into()), pox_addr_tuple] } else { @@ -978,12 +984,6 @@ fn get_stacking_tx_method_and_args( ] }; - let method = if extend_stacking { - "stack-extend" - } else { - "stack-stx" - }; - if pox_version >= 4 { // extra arguments for pox-4 ( for both stack-stx and stack-extend) // (signer-sig (optional (buff 65)))