diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 7afa11b8..ae65eb05 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -23,7 +23,7 @@ env: CARGO_TERM_COLOR: always # Build smaller artifacts to avoid running out of space in CI # TODO: Try to remove once https://github.com/paritytech/substrate/issues/11538 is resolved - RUSTFLAGS: -C strip=symbols -C opt-level=s --cfg tokio_unstable + RUSTFLAGS: -C strip=symbols -C opt-level=s # Remove unnecessary WASM build artefacts WASM_BUILD_CLEAN_TARGET: 1 diff --git a/.github/workflows/rustdoc.yml b/.github/workflows/rustdoc.yml index f1e0c32a..329d2c6f 100644 --- a/.github/workflows/rustdoc.yml +++ b/.github/workflows/rustdoc.yml @@ -9,7 +9,6 @@ env: CARGO_INCREMENTAL: 0 CARGO_NET_RETRY: 10 RUSTUP_MAX_RETRIES: 10 - RUSTFLAGS: --cfg tokio_unstable jobs: rustdoc: diff --git a/Cargo.lock b/Cargo.lock index b4b82275..d4c2e640 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1259,23 +1259,25 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "chacha20" -version = "0.9.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fc89c7c5b9e7a02dfe45cd2367bae382f9ed31c61ca8debe5f827c420a2f08" +checksum = "5c80e5460aa66fe3b91d40bcbdab953a597b60053e34d684ac6903f863b680a6" dependencies = [ "cfg-if", - "cipher 0.4.3", + "cipher 0.3.0", "cpufeatures", + "zeroize", ] [[package]] name = "chacha20poly1305" -version = "0.9.0" -source = "git+https://github.com/RustCrypto/AEADs?rev=06dbfb5571687fd1bbe9d3c9b2193a1ba17f8e99#06dbfb5571687fd1bbe9d3c9b2193a1ba17f8e99" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18446b09be63d457bbec447509e85f662f32952b035ce892290396bc0b0cff5" dependencies = [ "aead 0.4.3", "chacha20", - "cipher 0.4.3", + "cipher 0.3.0", "poly1305", "zeroize", ] @@ -1327,17 +1329,6 @@ dependencies = [ "generic-array 0.14.6", ] -[[package]] -name = "cipher" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e" -dependencies = [ - "crypto-common", - "inout", - "zeroize", -] - [[package]] name = "clap" version = "4.2.1" @@ -1549,7 +1540,7 @@ dependencies = [ [[package]] name = "core-eth-relay-runtime" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "domain-pallet-executive", "domain-runtime-primitives", @@ -1606,7 +1597,7 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "core-payments-domain-runtime" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "domain-pallet-executive", "domain-runtime-primitives", @@ -1807,7 +1798,7 @@ checksum = "6548a0ad5d2549e111e1f6a11a6c2e2d00ce6a3dafe22948d67c2b443f775e52" [[package]] name = "cross-domain-message-gossip" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "futures", "parity-scale-codec", @@ -2390,7 +2381,7 @@ dependencies = [ [[package]] name = "domain-block-builder" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -2407,7 +2398,7 @@ dependencies = [ [[package]] name = "domain-block-preprocessor" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "domain-runtime-primitives", "parity-scale-codec", @@ -2432,7 +2423,7 @@ dependencies = [ [[package]] name = "domain-client-consensus-relay-chain" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-trait", "parking_lot 0.12.1", @@ -2448,7 +2439,7 @@ dependencies = [ [[package]] name = "domain-client-executor" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "crossbeam", "domain-block-builder", @@ -2490,7 +2481,7 @@ dependencies = [ [[package]] name = "domain-client-executor-gossip" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "futures", "parity-scale-codec", @@ -2508,7 +2499,7 @@ dependencies = [ [[package]] name = "domain-client-message-relayer" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-channel", "cross-domain-message-gossip", @@ -2535,7 +2526,7 @@ dependencies = [ [[package]] name = "domain-pallet-executive" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-executive", "frame-support", @@ -2552,7 +2543,7 @@ dependencies = [ [[package]] name = "domain-runtime-primitives" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "parity-scale-codec", "sp-api", @@ -2564,7 +2555,7 @@ dependencies = [ [[package]] name = "domain-service" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-trait", "clap", @@ -4115,15 +4106,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "inout" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" -dependencies = [ - "generic-array 0.14.6", -] - [[package]] name = "instant" version = "0.1.12" @@ -6202,7 +6184,7 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "orml-vesting" version = "0.4.1-dev" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6299,7 +6281,7 @@ dependencies = [ [[package]] name = "pallet-domain-registry" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6320,7 +6302,7 @@ dependencies = [ [[package]] name = "pallet-domains" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6337,7 +6319,7 @@ dependencies = [ [[package]] name = "pallet-executor-registry" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6355,7 +6337,7 @@ dependencies = [ [[package]] name = "pallet-feeds" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6371,7 +6353,7 @@ dependencies = [ [[package]] name = "pallet-grandpa-finality-verifier" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "finality-grandpa", "frame-support", @@ -6391,7 +6373,7 @@ dependencies = [ [[package]] name = "pallet-messenger" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6409,7 +6391,7 @@ dependencies = [ [[package]] name = "pallet-object-store" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6424,7 +6406,7 @@ dependencies = [ [[package]] name = "pallet-offences-subspace" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6439,7 +6421,7 @@ dependencies = [ [[package]] name = "pallet-receipts" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6455,7 +6437,7 @@ dependencies = [ [[package]] name = "pallet-rewards" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6468,7 +6450,7 @@ dependencies = [ [[package]] name = "pallet-runtime-configs" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6480,7 +6462,7 @@ dependencies = [ [[package]] name = "pallet-subspace" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6536,7 +6518,7 @@ dependencies = [ [[package]] name = "pallet-transaction-fees" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -6592,7 +6574,7 @@ dependencies = [ [[package]] name = "pallet-transporter" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "frame-system", @@ -8013,7 +7995,7 @@ dependencies = [ [[package]] name = "sc-consensus-fraud-proof" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-trait", "parity-scale-codec", @@ -8051,7 +8033,7 @@ dependencies = [ [[package]] name = "sc-consensus-subspace" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-trait", "fork-tree", @@ -8092,7 +8074,7 @@ dependencies = [ [[package]] name = "sc-consensus-subspace-rpc" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-oneshot", "futures", @@ -8643,7 +8625,7 @@ dependencies = [ [[package]] name = "sc-subspace-chain-specs" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "sc-chain-spec", "sc-service", @@ -9536,7 +9518,7 @@ dependencies = [ [[package]] name = "sp-consensus-subspace" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-trait", "log", @@ -9651,7 +9633,7 @@ dependencies = [ [[package]] name = "sp-domain-digests" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "parity-scale-codec", "sp-api", @@ -9663,7 +9645,7 @@ dependencies = [ [[package]] name = "sp-domains" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "blake2", "merlin", @@ -9689,7 +9671,7 @@ dependencies = [ [[package]] name = "sp-executor-registry" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "parity-scale-codec", "sp-domains", @@ -9787,7 +9769,7 @@ dependencies = [ [[package]] name = "sp-messenger" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "frame-support", "hash-db", @@ -9804,7 +9786,7 @@ dependencies = [ [[package]] name = "sp-objects" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "sp-api", "sp-std", @@ -9835,7 +9817,7 @@ dependencies = [ [[package]] name = "sp-receipts" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "parity-scale-codec", "sp-api", @@ -10271,7 +10253,7 @@ dependencies = [ [[package]] name = "subspace-archiving" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "parity-scale-codec", "rayon", @@ -10283,7 +10265,7 @@ dependencies = [ [[package]] name = "subspace-cli" -version = "0.3.0" +version = "0.3.1" dependencies = [ "bytesize", "bytesize-serde", @@ -10318,7 +10300,7 @@ dependencies = [ [[package]] name = "subspace-core-primitives" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "ark-bls12-381", "ark-ff", @@ -10346,7 +10328,7 @@ dependencies = [ [[package]] name = "subspace-erasure-coding" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "blst_from_scratch", "kzg", @@ -10356,7 +10338,7 @@ dependencies = [ [[package]] name = "subspace-farmer" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "anyhow", "async-trait", @@ -10405,7 +10387,7 @@ dependencies = [ [[package]] name = "subspace-farmer-components" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-trait", "fs2", @@ -10430,8 +10412,9 @@ dependencies = [ [[package]] name = "subspace-fraud-proof" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ + "domain-block-preprocessor", "domain-runtime-primitives", "futures", "hash-db", @@ -10440,19 +10423,22 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-core", + "sp-domain-digests", "sp-domains", + "sp-messenger", "sp-receipts", "sp-runtime", "sp-state-machine", "sp-trie", "subspace-wasm-tools", + "system-runtime-primitives", "tracing", ] [[package]] name = "subspace-networking" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "actix-web", "anyhow", @@ -10489,7 +10475,7 @@ dependencies = [ [[package]] name = "subspace-rpc-primitives" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "hex", "serde", @@ -10501,7 +10487,7 @@ dependencies = [ [[package]] name = "subspace-runtime" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "domain-runtime-primitives", "frame-benchmarking", @@ -10555,7 +10541,7 @@ dependencies = [ [[package]] name = "subspace-runtime-primitives" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "parity-scale-codec", "serde", @@ -10568,7 +10554,7 @@ dependencies = [ [[package]] name = "subspace-sdk" version = "0.1.0" -source = "git+https://github.com/subspace/subspace-sdk?rev=cc3460710f63a431faba7ea1572eda1971e0c9ee#cc3460710f63a431faba7ea1572eda1971e0c9ee" +source = "git+https://github.com/subspace/subspace-sdk?rev=2858928134fd497094986b130c0622904561a5f3#2858928134fd497094986b130c0622904561a5f3" dependencies = [ "anyhow", "async-trait", @@ -10593,6 +10579,7 @@ dependencies = [ "frame-system", "frame-system-rpc-runtime-api", "futures", + "hex", "hex-literal 0.4.1", "jsonrpsee-core", "libp2p-core 0.39.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -10665,15 +10652,17 @@ dependencies = [ [[package]] name = "subspace-service" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-trait", "derive_more", + "domain-block-preprocessor", "domain-runtime-primitives", "either", "frame-support", "frame-system-rpc-runtime-api", "futures", + "hex", "jsonrpsee", "pallet-transaction-payment-rpc", "pallet-transaction-payment-rpc-runtime-api", @@ -10731,7 +10720,7 @@ dependencies = [ [[package]] name = "subspace-solving" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "merlin", "schnorrkel", @@ -10741,7 +10730,7 @@ dependencies = [ [[package]] name = "subspace-transaction-pool" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "async-trait", "domain-runtime-primitives", @@ -10768,7 +10757,7 @@ dependencies = [ [[package]] name = "subspace-verification" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "merlin", "parity-scale-codec", @@ -10785,7 +10774,7 @@ dependencies = [ [[package]] name = "subspace-wasm-tools" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "sc-executor-common", "sp-domains", @@ -10939,7 +10928,7 @@ dependencies = [ [[package]] name = "system-domain-runtime" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "core-payments-domain-runtime", "domain-pallet-executive", @@ -10983,7 +10972,7 @@ dependencies = [ [[package]] name = "system-runtime-primitives" version = "0.1.0" -source = "git+https://github.com/subspace/subspace?rev=06d6fa27eab5665e32fd7859bd35d0a87df96d41#06d6fa27eab5665e32fd7859bd35d0a87df96d41" +source = "git+https://github.com/subspace/subspace?rev=2360052b08f1ce17f15256f7d6d1cd398f07f749#2360052b08f1ce17f15256f7d6d1cd398f07f749" dependencies = [ "parity-scale-codec", "sp-api", diff --git a/Cargo.toml b/Cargo.toml index 9759a484..bcf31db4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "subspace-cli" -version = "0.3.0" +version = "0.3.1" edition = "2021" [dependencies] @@ -8,7 +8,6 @@ bytesize = "1.1" bytesize-serde = "0.2" clap = { version = "4.1.1", features = ["derive"] } color-eyre = "0.6.2" -console-subscriber = "0.1" derivative = "2.2.0" dirs = "4.0.0" fdlimit = "0.2" @@ -31,16 +30,16 @@ tracing-error = "0.2.0" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } whoami = "1" -subspace-sdk = { git = "https://github.com/subspace/subspace-sdk", rev = "cc3460710f63a431faba7ea1572eda1971e0c9ee" } +subspace-sdk = { git = "https://github.com/subspace/subspace-sdk", rev = "2858928134fd497094986b130c0622904561a5f3" } # The only triple tested and confirmed as working in `jemallocator` crate is `x86_64-unknown-linux-gnu` [target.'cfg(all(target_arch = "x86_64", target_vendor = "unknown", target_os = "linux", target_env = "gnu"))'.dependencies] jemallocator = "0.5.0" -[patch.crates-io] -# TODO: Remove once chacha20poly1305 0.10 appears in libp2p's dependencies -chacha20poly1305 = { git = "https://github.com/RustCrypto/AEADs", rev = "06dbfb5571687fd1bbe9d3c9b2193a1ba17f8e99" } +[target.'cfg(tokio_unstable)'.dependencies] +console-subscriber = "0.1" +[patch.crates-io] # TODO: remove once tracing-appender has a new release tracing = { git = "https://github.com/tokio-rs/tracing", branch = "v0.1.x" } tracing-appender = { git = "https://github.com/tokio-rs/tracing", branch = "v0.1.x" } diff --git a/src/commands/farm.rs b/src/commands/farm.rs index 2ba007da..460d2416 100644 --- a/src/commands/farm.rs +++ b/src/commands/farm.rs @@ -14,8 +14,8 @@ use tokio::task::JoinHandle; use tracing::instrument; use crate::config::{validate_config, ChainConfig, Config}; -use crate::summary::{Rewards, Summary, SummaryUpdateFields}; -use crate::utils::{install_tracing, raise_fd_limit}; +use crate::summary::{Rewards, Summary, SummaryFilePointer, SummaryUpdateFields}; +use crate::utils::{install_tracing, raise_fd_limit, spawn_task}; /// allows us to detect multiple instances of the farmer and act on it pub(crate) const SINGLE_INSTANCE: &str = ".subspaceFarmer"; @@ -67,7 +67,7 @@ pub(crate) async fn farm(is_verbose: bool, executor: bool) -> Result<()> { } } - let summary = Summary::new(Some(farmer_config.plot_size)).await?; + let summary = SummaryFilePointer::new(Some(farmer_config.plot_size.clone())).await?; println!("Starting farmer ..."); let farmer = Arc::new(farmer_config.build(&node).await?); @@ -78,19 +78,25 @@ pub(crate) async fn farm(is_verbose: bool, executor: bool) -> Result<()> { let is_initial_progress_finished = Arc::new(AtomicBool::new(false)); let sector_size_bytes = farmer.get_info().await.map_err(Report::msg)?.sector_size; - let plotting_sub_handle = tokio::spawn(subscribe_to_plotting_progress( - summary.clone(), - farmer.clone(), - is_initial_progress_finished.clone(), - sector_size_bytes, - )); + let plotting_sub_handle = spawn_task( + "plotting_subscriber", + subscribe_to_plotting_progress( + summary.clone(), + farmer.clone(), + is_initial_progress_finished.clone(), + sector_size_bytes, + ), + ); - let solution_sub_handle = tokio::spawn(subscribe_to_solutions( - summary.clone(), - node.clone(), - is_initial_progress_finished.clone(), - reward_address, - )); + let solution_sub_handle = spawn_task( + "solution_subscriber", + subscribe_to_solutions( + summary.clone(), + node.clone(), + is_initial_progress_finished.clone(), + reward_address, + ), + ); Some((plotting_sub_handle, solution_sub_handle)) } else { @@ -132,7 +138,7 @@ async fn wait_on_farmer( } // shutting down the farmer and the node - let graceful_close_handle = tokio::spawn(async move { + let graceful_close_handle = spawn_task("graceful_shutdown_listener", async move { // if one of the subscriptions have not aborted yet, wait // Plotting might end, so we ignore result here @@ -186,7 +192,7 @@ async fn subscribe_to_node_syncing(node: &Node) -> Result<()> { } async fn subscribe_to_plotting_progress( - summary: Summary, + summary: SummaryFilePointer, farmer: Arc, is_initial_progress_finished: Arc, sector_size_bytes: u64, @@ -231,7 +237,7 @@ async fn subscribe_to_plotting_progress( } async fn subscribe_to_solutions( - summary: Summary, + summary: SummaryFilePointer, node: Arc, is_initial_progress_finished: Arc, reward_address: PublicKey, @@ -277,20 +283,8 @@ async fn subscribe_to_solutions( // error, we will // abandon this // mechanism - let (farmed_block_count, vote_count, total_rewards) = ( - summary - .get_farmed_block_count() - .await - .context("couldn't read farmed block count value, summary was corrupted")?, - summary - .get_vote_count() - .await - .context("couldn't read vote count value, summary was corrupted")?, - summary - .get_total_rewards() - .await - .context("couldn't read total rewards value, summary was corrupted")?, - ); + let Summary { total_rewards, farmed_block_count, vote_count, .. } = + summary.parse_summary().await.context("couldn't parse summary")?; if is_initial_progress_finished.load(Ordering::Relaxed) { print!( diff --git a/src/commands/info.rs b/src/commands/info.rs index 0d114e6a..3b6fe83e 100644 --- a/src/commands/info.rs +++ b/src/commands/info.rs @@ -2,7 +2,7 @@ use color_eyre::eyre::{Context, Result}; use single_instance::SingleInstance; use crate::commands::farm::SINGLE_INSTANCE; -use crate::summary::Summary; +use crate::summary::{Summary, SummaryFilePointer}; /// implementation of the `init` command. /// @@ -16,45 +16,24 @@ pub(crate) async fn info() -> Result<()> { println!("There is no active farmer instance..."); } - let summary = Summary::new(None).await?; + let summary = SummaryFilePointer::new(None).await?; + let Summary { + user_space_pledged, + farmed_block_count, + vote_count, + total_rewards, + initial_plotting_finished, + } = summary.parse_summary().await.context("couldn't parse summary file")?; - println!( - "You have pledged to the network: {}", - summary - .get_user_space_pledged() - .await - .context("Couldn't read the summary file, are you sure you ran the farm command?")? - ); + println!("You have pledged to the network: {user_space_pledged}"); - println!( - "Farmed {} block(s)", - summary - .get_farmed_block_count() - .await - .context("Couldn't read the summary file, are you sure you ran the farm command?")? - ); + println!("Farmed {farmed_block_count} block(s)"); - println!( - "Voted on {} block(s)", - summary - .get_vote_count() - .await - .context("Couldn't read the summary file, are you sure you ran the farm command?")? - ); + println!("Voted on {vote_count} block(s)"); - println!( - "{} SSC(s) earned!", - summary - .get_total_rewards() - .await - .context("Couldn't read the summary file, are you sure you ran the farm command?")? - ); + println!("{total_rewards} SSC(s) earned!",); - if summary - .get_initial_plotting_progress() - .await - .context("Couldn't read the summary file, are you sure you ran the farm command?")? - { + if initial_plotting_finished { println!("Initial plotting is finished!"); } else { println!("Initial plotting is not finished..."); diff --git a/src/commands/wipe.rs b/src/commands/wipe.rs index ddaaee8f..8bea1802 100644 --- a/src/commands/wipe.rs +++ b/src/commands/wipe.rs @@ -59,14 +59,20 @@ pub(crate) async fn wipe( } if wipe_summary { - delete_summary()? + match delete_summary() { + Ok(_) => println!("deleted the summary file"), + Err(_) => println!("Skipping wiping summary, could not find the file..."), + } } if wipe_config { - delete_config()? + match delete_config() { + Ok(_) => println!("deleted the config file"), + Err(_) => println!("Skipping wiping config, could not find the file..."), + } } - println!("Wipe successful!"); + println!("Wipe finished!"); Ok(()) } diff --git a/src/config.rs b/src/config.rs index 15b5d079..89b7eb30 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,7 +2,6 @@ use std::fs::{create_dir_all, remove_file, File}; use std::path::PathBuf; use std::str::FromStr; -use bytesize::ByteSize; use color_eyre::eyre::{eyre, Report, Result, WrapErr}; use derivative::Derivative; use serde::{Deserialize, Serialize}; @@ -10,14 +9,14 @@ use strum_macros::EnumIter; use subspace_sdk::farmer::{CacheDescription, Farmer}; use subspace_sdk::node::domains::core::ConfigBuilder; use subspace_sdk::node::{domains, DsnBuilder, NetworkBuilder, Node, Role}; -use subspace_sdk::{chain_spec, PlotDescription, PublicKey}; +use subspace_sdk::{chain_spec, ByteSize, PlotDescription, PublicKey}; use tracing::instrument; use crate::utils::{cache_directory_getter, provider_storage_dir_getter}; /// defaults for the user config file -pub(crate) const DEFAULT_PLOT_SIZE: bytesize::ByteSize = bytesize::ByteSize::gb(1); -pub(crate) const MIN_PLOT_SIZE: bytesize::ByteSize = bytesize::ByteSize::mib(32); +pub(crate) const DEFAULT_PLOT_SIZE: ByteSize = ByteSize::gb(1); +pub(crate) const MIN_PLOT_SIZE: ByteSize = ByteSize::mib(32); /// structure of the config toml file #[derive(Deserialize, Serialize, Debug)] @@ -97,8 +96,8 @@ impl NodeConfig { #[derive(Deserialize, Serialize, Clone, Derivative, Debug, PartialEq)] #[derivative(Default)] pub(crate) struct AdvancedFarmerSettings { - #[serde(with = "bytesize_serde", default, skip_serializing_if = "crate::utils::is_default")] - #[derivative(Default(value = "bytesize::ByteSize::gb(1)"))] + #[serde(default, skip_serializing_if = "crate::utils::is_default")] + #[derivative(Default(value = "subspace_sdk::ByteSize::gb(1)"))] pub(crate) cache_size: ByteSize, #[serde(default, flatten)] pub(crate) extra: toml::Table, @@ -109,7 +108,6 @@ pub(crate) struct AdvancedFarmerSettings { pub(crate) struct FarmerConfig { pub(crate) reward_address: PublicKey, pub(crate) plot_directory: PathBuf, - #[serde(with = "bytesize_serde")] pub(crate) plot_size: ByteSize, #[serde(default, skip_serializing_if = "crate::utils::is_default")] pub(crate) advanced: AdvancedFarmerSettings, diff --git a/src/main.rs b/src/main.rs index c15aec0d..ab5645a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,9 @@ mod config; mod summary; mod utils; +#[cfg(test)] +mod tests; + use clap::{Parser, Subcommand}; use color_eyre::eyre::{Context, Report}; use color_eyre::Help; diff --git a/src/summary.rs b/src/summary.rs index dcb5e231..b99a9244 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -7,9 +7,9 @@ use std::fs::remove_file; use std::path::PathBuf; use std::sync::Arc; -use bytesize::ByteSize; use color_eyre::eyre::{Context, Result}; use serde::{Deserialize, Serialize}; +use subspace_sdk::ByteSize; use tokio::fs::{create_dir_all, read_to_string, File, OpenOptions}; use tokio::io::AsyncWriteExt; use tokio::sync::Mutex; @@ -43,13 +43,12 @@ impl std::fmt::Display for Rewards { /// Struct for holding the information of what to be displayed with the `info` /// command #[derive(Deserialize, Serialize, Debug)] -struct FarmerSummary { - initial_plotting_finished: bool, - farmed_block_count: u64, - vote_count: u64, - total_rewards: Rewards, - #[serde(with = "bytesize_serde")] - user_space_pledged: ByteSize, +pub(crate) struct Summary { + pub(crate) initial_plotting_finished: bool, + pub(crate) farmed_block_count: u64, + pub(crate) vote_count: u64, + pub(crate) total_rewards: Rewards, + pub(crate) user_space_pledged: ByteSize, } #[derive(Default, Debug)] @@ -63,14 +62,17 @@ pub(crate) struct SummaryUpdateFields { /// utilizing persistent storage for the information to be displayed for the /// `info` command #[derive(Debug, Clone)] -pub(crate) struct Summary { +pub(crate) struct SummaryFilePointer { file: Arc>, } -impl Summary { - /// creates new summary file +impl SummaryFilePointer { + /// creates new summary file pointer + /// + /// if user_space_pledged is provided, it creates a new summary file + /// else, it tries to read the existing summary file #[instrument] - pub(crate) async fn new(user_space_pledged: Option) -> Result { + pub(crate) async fn new(user_space_pledged: Option) -> Result { let summary_path = summary_path(); let summary_dir = dirs::data_local_dir() .expect("couldn't get the default local data directory!") @@ -82,18 +84,19 @@ impl Summary { // File::create will truncate the existing file, so first // check if the file exists, if not, `open` will return an error // in this case, create the file and necessary directories + // if file exists, we do nothing if File::open(&summary_path).await.is_err() { let _ = create_dir_all(&summary_dir).await; let _ = File::create(&summary_path).await; - let initialization = FarmerSummary { + let initialization = Summary { initial_plotting_finished: false, farmed_block_count: 0, vote_count: 0, total_rewards: Rewards(0), user_space_pledged, }; - let summary_text = toml::to_string(&initialization) - .context("Failed to serialize FarmerSummary")?; + let summary_text = + toml::to_string(&initialization).context("Failed to serialize Summary")?; OpenOptions::new() .write(true) .truncate(true) @@ -104,7 +107,7 @@ impl Summary { } } - Ok(Summary { file: Arc::new(Mutex::new(summary_path)) }) + Ok(SummaryFilePointer { file: Arc::new(Mutex::new(summary_path)) }) } /// updates the summary file @@ -137,7 +140,7 @@ impl Summary { summary.total_rewards = new_reward; } - let new_summary = toml::to_string(&summary).context("Failed to serialize FarmerSummary")?; + let new_summary = toml::to_string(&summary).context("Failed to serialize Summary")?; let guard = self.file.lock().await; OpenOptions::new() @@ -151,47 +154,11 @@ impl Summary { Ok(()) } - /// retrives how much space has user pledged to the network from the summary - /// file - #[instrument] - pub(crate) async fn get_user_space_pledged(&self) -> Result { - let summary = self.parse_summary().await?; - Ok(summary.user_space_pledged) - } - - /// retrieves how many blocks have been farmed, from the summary file - #[instrument] - pub(crate) async fn get_farmed_block_count(&self) -> Result { - let summary = self.parse_summary().await?; - Ok(summary.farmed_block_count) - } - - /// retrieves the total amount of rewards in SSC - #[instrument] - pub(crate) async fn get_total_rewards(&self) -> Result { - let summary = self.parse_summary().await?; - Ok(summary.total_rewards) - } - - /// retrives how many votes did farmer issue - #[instrument] - pub(crate) async fn get_vote_count(&self) -> Result { - let summary = self.parse_summary().await?; - Ok(summary.vote_count) - } - - /// retrieves the status of the initial plotting, from the summary file - #[instrument] - pub(crate) async fn get_initial_plotting_progress(&self) -> Result { - let summary = self.parse_summary().await?; - Ok(summary.initial_plotting_finished) - } - - /// parses the summary file and returns [`FarmerSummary`] + /// parses the summary file and returns [`Summary`] #[instrument] - async fn parse_summary(&self) -> Result { + pub(crate) async fn parse_summary(&self) -> Result { let guard = self.file.lock().await; - let summary: FarmerSummary = toml::from_str(&read_to_string(&*guard).await?)?; + let summary: Summary = toml::from_str(&read_to_string(&*guard).await?)?; Ok(summary) } } diff --git a/src/tests.rs b/src/tests.rs new file mode 100644 index 00000000..0b8d123a --- /dev/null +++ b/src/tests.rs @@ -0,0 +1,135 @@ +use std::str::FromStr; + +use crate::config::ChainConfig; +use crate::utils::{ + apply_extra_options, cache_directory_getter, custom_log_dir, node_directory_getter, + node_name_parser, plot_directory_getter, plot_directory_parser, reward_address_parser, + size_parser, yes_or_no_parser, +}; + +#[test] +fn extra_options() { + let cargo_toml = toml::toml! { + name = "toml" + + [package] + version = "0.4.5" + authors = ["Alex Crichton "] + }; + let extra = toml::toml! { + name = "toml-edit" + option = true + + [package] + version = "0.4.6" + badges = ["travis-ci"] + }; + let result = toml::toml! { + name = "toml-edit" + option = true + + [package] + authors = ["Alex Crichton "] + version = "0.4.6" + badges = ["travis-ci"] + }; + + assert_eq!(apply_extra_options(&cargo_toml, extra).unwrap(), result); +} + +#[test] +fn yes_no_checker() { + assert!(yes_or_no_parser("yas").is_err()); + assert!(yes_or_no_parser("yess").is_err()); + assert!(yes_or_no_parser("y").is_ok()); +} + +#[test] +fn plot_directory_checker() { + assert!(plot_directory_parser("some-weird-location-that-does-not-exist").is_err()); + assert!(plot_directory_parser("some/weird/location/that/does/not/exist").is_err()); + assert!(plot_directory_parser("./").is_ok()); +} + +#[test] +fn node_name_checker() { + assert!(node_name_parser(" ").is_err()); + assert!(node_name_parser("root ").is_err()); + assert!(node_name_parser("ゴゴゴゴ yare yare daze").is_ok()); +} + +#[test] +fn reward_address_checker() { + // below address is randomly generated via metamask and then deleted + assert!(reward_address_parser("5FWr7j9DW4uy7K1JLmFN2R3eoae35PFDUfW7G42ARpBEUaN7").is_ok()); + assert!(reward_address_parser("sdjhfskjfhdksjhfsfhskjskdjhfdsfjhk").is_err()); +} + +#[test] +fn size_checker() { + assert!(size_parser("800MB").is_ok()); + assert!(size_parser("103gjie").is_err()); + assert!(size_parser("12GB").is_ok()); +} + +#[test] +fn chain_checker() { + assert!(ChainConfig::from_str("gemini3d").is_ok()); + assert!(ChainConfig::from_str("devv").is_err()); +} + +#[test] +fn plot_directory_tester() { + let plot_path = plot_directory_getter(); + + #[cfg(target_os = "macos")] + assert!(plot_path.ends_with("Library/Application Support/subspace-cli/plots")); + + #[cfg(target_os = "linux")] + assert!(plot_path.ends_with(".local/share/subspace-cli/plots")); + + #[cfg(target_os = "windows")] + assert!(plot_path.ends_with("AppData/Roaming/subspace-cli/plots")); +} + +#[test] +fn cache_directory_tester() { + let cache_path = cache_directory_getter(); + + #[cfg(target_os = "macos")] + assert!(cache_path.ends_with("Library/Application Support/subspace-cli/cache")); + + #[cfg(target_os = "linux")] + assert!(cache_path.ends_with(".local/share/subspace-cli/cache")); + + #[cfg(target_os = "windows")] + assert!(cache_path.ends_with("AppData/Roaming/subspace-cli/cache")); +} + +#[test] +fn node_directory_tester() { + let node_path = node_directory_getter(); + + #[cfg(target_os = "macos")] + assert!(node_path.ends_with("Library/Application Support/subspace-cli/node")); + + #[cfg(target_os = "linux")] + assert!(node_path.ends_with(".local/share/subspace-cli/node")); + + #[cfg(target_os = "windows")] + assert!(node_path.ends_with("AppData/Roaming/subspace-cli/node")); +} + +#[test] +fn custom_log_dir_test() { + let log_path = custom_log_dir(); + + #[cfg(target_os = "macos")] + assert!(log_path.ends_with("Library/Logs/subspace-cli")); + + #[cfg(target_os = "linux")] + assert!(log_path.ends_with(".local/share/subspace-cli/logs")); + + #[cfg(target_os = "windows")] + assert!(log_path.ends_with("AppData/Local/subspace-cli/logs")); +} diff --git a/src/utils.rs b/src/utils.rs index 9919b2fc..dfa95608 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -3,10 +3,9 @@ use std::fs::create_dir_all; use std::path::{Path, PathBuf}; use std::str::FromStr; -use bytesize::ByteSize; use color_eyre::eyre::{eyre, Context, Result}; use owo_colors::OwoColorize; -use subspace_sdk::PublicKey; +use subspace_sdk::{ByteSize, PublicKey}; use tracing::level_filters::LevelFilter; use tracing_appender::rolling::{RollingFileAppender, Rotation}; use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer}; @@ -154,7 +153,7 @@ fn data_dir_getter() -> PathBuf { } /// returns OS specific log directory -fn custom_log_dir() -> PathBuf { +pub(crate) fn custom_log_dir() -> PathBuf { let id = "subspace-cli"; #[cfg(target_os = "macos")] @@ -223,8 +222,13 @@ pub(crate) fn install_tracing(is_verbose: bool) { }; // start logger, after we acquire the bundle identifier - let tracing_layer = tracing_subscriber::registry() - .with(console_subscriber::spawn()) + #[cfg(tokio_unstable)] + let tracing_layer = tracing_subscriber::registry().with(console_subscriber::spawn()); + + #[cfg(not(tokio_unstable))] + let tracing_layer = tracing_subscriber::registry(); + + let tracing_layer = tracing_layer .with( BunyanFormattingLayer::new("subspace-cli".to_owned(), file_appender) .and_then(JsonStorageLayer) @@ -284,121 +288,24 @@ pub fn apply_extra_options( .expect("At this stage we know that config is always toml deserializable")) } -#[cfg(test)] -mod tests { - use super::*; - use crate::config::ChainConfig; - - #[test] - fn extra_options() { - let cargo_toml = toml::toml! { - name = "toml" - - [package] - version = "0.4.5" - authors = ["Alex Crichton "] - }; - let extra = toml::toml! { - name = "toml-edit" - option = true - - [package] - version = "0.4.6" - badges = ["travis-ci"] - }; - let result = toml::toml! { - name = "toml-edit" - option = true - - [package] - authors = ["Alex Crichton "] - version = "0.4.6" - badges = ["travis-ci"] - }; - - assert_eq!(apply_extra_options(&cargo_toml, extra).unwrap(), result); - } - - #[test] - fn node_name_checker() { - assert!(node_name_parser(" ").is_err()); - assert!(node_name_parser("root ").is_err()); - assert!(node_name_parser("ゴゴゴゴ yare yare daze").is_ok()); - } - - #[test] - fn reward_address_checker() { - // below address is randomly generated via metamask and then deleted - assert!(reward_address_parser("5FWr7j9DW4uy7K1JLmFN2R3eoae35PFDUfW7G42ARpBEUaN7").is_ok()); - assert!(reward_address_parser("sdjhfskjfhdksjhfsfhskjskdjhfdsfjhk").is_err()); - } - - #[test] - fn size_checker() { - assert!(size_parser("800MB").is_ok()); - assert!(size_parser("103gjie").is_err()); - assert!(size_parser("12GB").is_ok()); - } - - #[test] - fn chain_checker() { - assert!(ChainConfig::from_str("gemini3d").is_ok()); - assert!(ChainConfig::from_str("devv").is_err()); - } - - #[test] - fn plot_directory_tester() { - let plot_path = plot_directory_getter(); - - #[cfg(target_os = "macos")] - assert!(plot_path.ends_with("Library/Application Support/subspace-cli/plots")); - - #[cfg(target_os = "linux")] - assert!(plot_path.ends_with(".local/share/subspace-cli/plots")); - - #[cfg(target_os = "windows")] - assert!(plot_path.ends_with("AppData/Roaming/subspace-cli/plots")); - } - - #[test] - fn cache_directory_tester() { - let cache_path = cache_directory_getter(); - - #[cfg(target_os = "macos")] - assert!(cache_path.ends_with("Library/Application Support/subspace-cli/cache")); - - #[cfg(target_os = "linux")] - assert!(cache_path.ends_with(".local/share/subspace-cli/cache")); - - #[cfg(target_os = "windows")] - assert!(cache_path.ends_with("AppData/Roaming/subspace-cli/cache")); - } - - #[test] - fn node_directory_tester() { - let node_path = node_directory_getter(); - - #[cfg(target_os = "macos")] - assert!(node_path.ends_with("Library/Application Support/subspace-cli/node")); - - #[cfg(target_os = "linux")] - assert!(node_path.ends_with(".local/share/subspace-cli/node")); - - #[cfg(target_os = "windows")] - assert!(node_path.ends_with("AppData/Roaming/subspace-cli/node")); - } - - #[test] - fn custom_log_dir_test() { - let log_path = custom_log_dir(); - - #[cfg(target_os = "macos")] - assert!(log_path.ends_with("Library/Logs/subspace-cli")); - - #[cfg(target_os = "linux")] - assert!(log_path.ends_with(".local/share/subspace-cli/logs")); +#[cfg(tokio_unstable)] +pub(crate) fn spawn_task(name: impl AsRef, future: F) -> tokio::task::JoinHandle +where + F: futures::Future + Send + 'static, + F::Output: Send + 'static, +{ + tokio::task::Builder::new() + .name(name.as_ref()) + .spawn(future) + .expect("Spawning task never fails") +} - #[cfg(target_os = "windows")] - assert!(log_path.ends_with("AppData/Local/subspace-cli/logs")); - } +#[cfg(not(tokio_unstable))] +pub(crate) fn spawn_task(name: impl AsRef, future: F) -> tokio::task::JoinHandle +where + F: futures::Future + Send + 'static, + F::Output: Send + 'static, +{ + let _ = name; + tokio::task::spawn(future) }