diff --git a/.github/workflows/crates-io.yml b/.github/workflows/crates-io.yml index eb7c0fd1b0f..130f2c24041 100644 --- a/.github/workflows/crates-io.yml +++ b/.github/workflows/crates-io.yml @@ -9,6 +9,7 @@ on: default: false version: description: "Workspace version to publish" + required: true type: string pull_request: branches: [master] diff --git a/Cargo.lock b/Cargo.lock index 3e114251f7c..95ff39947ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -285,12 +285,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "asn1_der" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "155a5a185e42c6b77ac7b88a15143d930a9e9727a5b7b77eed417404ab15c247" - [[package]] name = "assert_matches" version = "1.5.0" @@ -483,12 +477,6 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" -[[package]] -name = "base16ct" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" - [[package]] name = "base16ct" version = "0.2.0" @@ -1015,7 +1003,7 @@ checksum = "b9b68e3193982cd54187d71afdb2a271ad4cf8af157858e9cb911b91321de143" dependencies = [ "core2", "multibase", - "multihash 0.17.0", + "multihash", "serde", "unsigned-varint", ] @@ -2380,16 +2368,6 @@ dependencies = [ "wabt", ] -[[package]] -name = "der" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "der" version = "0.7.8" @@ -2682,12 +2660,12 @@ version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ - "der 0.7.8", + "der", "digest 0.10.7", "elliptic-curve", "rfc6979", "signature 2.1.0", - "spki 0.7.2", + "spki", ] [[package]] @@ -2705,7 +2683,7 @@ version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60f6d271ca33075c88028be6f04d502853d63a5ece419d269c15315d4fc1cf1d" dependencies = [ - "pkcs8 0.10.2", + "pkcs8", "signature 2.1.0", ] @@ -2717,8 +2695,6 @@ checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ "curve25519-dalek 3.2.0", "ed25519 1.5.3", - "rand 0.7.3", - "serde", "sha2 0.9.9", "zeroize", ] @@ -2763,15 +2739,15 @@ version = "0.13.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9775b22bc152ad86a0cf23f0f348b884b26add12bf741e7ffc4d4ab2ab4d205" dependencies = [ - "base16ct 0.2.0", + "base16ct", "crypto-bigint", "digest 0.10.7", "ff", "generic-array 0.14.7", "group", - "pkcs8 0.10.2", + "pkcs8", "rand_core 0.6.4", - "sec1 0.7.3", + "sec1", "subtle", "zeroize", ] @@ -3698,7 +3674,7 @@ dependencies = [ "jsonrpsee 0.16.3", "keyring", "lazy_static", - "libp2p 0.50.1", + "libp2p", "log", "nacl", "rand 0.8.5", @@ -4414,7 +4390,6 @@ version = "1.0.5" dependencies = [ "derive_more", "enum-iterator 1.4.1", - "gear-core", "gwasm-instrument", "wasmparser-nostd 0.100.1", "wat", @@ -4700,7 +4675,7 @@ version = "1.0.5" [[package]] name = "gtest" -version = "0.1.0" +version = "1.0.5" dependencies = [ "colored", "demo-custom", @@ -5657,27 +5632,6 @@ dependencies = [ "libc", ] -[[package]] -name = "libp2p" -version = "0.50.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7b0104790be871edcf97db9bd2356604984e623a08d825c3f27852290266b8" -dependencies = [ - "bytes", - "futures", - "futures-timer", - "getrandom 0.2.10", - "instant", - "libp2p-core 0.38.0", - "libp2p-identify 0.41.1", - "libp2p-metrics 0.11.0", - "libp2p-swarm 0.41.1", - "multiaddr 0.16.0", - "parking_lot 0.12.1", - "pin-project", - "smallvec", -] - [[package]] name = "libp2p" version = "0.51.4" @@ -5691,23 +5645,23 @@ dependencies = [ "instant", "libp2p-allow-block-list", "libp2p-connection-limits", - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-dns", - "libp2p-identify 0.42.2", + "libp2p-identify", "libp2p-identity", "libp2p-kad", "libp2p-mdns", - "libp2p-metrics 0.12.0", + "libp2p-metrics", "libp2p-noise", "libp2p-ping", "libp2p-quic", "libp2p-request-response", - "libp2p-swarm 0.42.2", + "libp2p-swarm", "libp2p-tcp", "libp2p-wasm-ext", "libp2p-websocket", "libp2p-yamux", - "multiaddr 0.17.1", + "multiaddr", "pin-project", ] @@ -5717,9 +5671,9 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "510daa05efbc25184458db837f6f9a5143888f1caa742426d92e1833ddd38a50" dependencies = [ - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.2", + "libp2p-swarm", "void", ] @@ -5729,46 +5683,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4caa33f1d26ed664c4fe2cca81a08c8e07d4c1c04f2f4ac7655c2dd85467fda0" dependencies = [ - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.2", + "libp2p-swarm", "void", ] -[[package]] -name = "libp2p-core" -version = "0.38.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6a8fcd392ff67af6cc3f03b1426c41f7f26b6b9aff2dc632c1c56dd649e571f" -dependencies = [ - "asn1_der", - "bs58 0.4.0", - "ed25519-dalek 1.0.1", - "either", - "fnv", - "futures", - "futures-timer", - "instant", - "log", - "multiaddr 0.16.0", - "multihash 0.16.3", - "multistream-select", - "once_cell", - "parking_lot 0.12.1", - "pin-project", - "prost", - "prost-build", - "rand 0.8.5", - "rw-stream-sink", - "sec1 0.3.0", - "sha2 0.10.8", - "smallvec", - "thiserror", - "unsigned-varint", - "void", - "zeroize", -] - [[package]] name = "libp2p-core" version = "0.39.2" @@ -5782,8 +5702,8 @@ dependencies = [ "instant", "libp2p-identity", "log", - "multiaddr 0.17.1", - "multihash 0.17.0", + "multiaddr", + "multihash", "multistream-select", "once_cell", "parking_lot 0.12.1", @@ -5804,34 +5724,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "146ff7034daae62077c415c2376b8057368042df6ab95f5432ad5e88568b1554" dependencies = [ "futures", - "libp2p-core 0.39.2", + "libp2p-core", "log", "parking_lot 0.12.1", "smallvec", "trust-dns-resolver", ] -[[package]] -name = "libp2p-identify" -version = "0.41.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c052d0026f4817b44869bfb6810f4e1112f43aec8553f2cb38881c524b563abf" -dependencies = [ - "asynchronous-codec", - "futures", - "futures-timer", - "libp2p-core 0.38.0", - "libp2p-swarm 0.41.1", - "log", - "lru 0.8.1", - "prost", - "prost-build", - "prost-codec", - "smallvec", - "thiserror", - "void", -] - [[package]] name = "libp2p-identify" version = "0.42.2" @@ -5842,11 +5741,11 @@ dependencies = [ "either", "futures", "futures-timer", - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.2", + "libp2p-swarm", "log", - "lru 0.10.1", + "lru", "quick-protobuf", "quick-protobuf-codec", "smallvec", @@ -5863,8 +5762,8 @@ dependencies = [ "bs58 0.4.0", "ed25519-dalek 2.0.0", "log", - "multiaddr 0.17.1", - "multihash 0.17.0", + "multiaddr", + "multihash", "quick-protobuf", "rand 0.8.5", "sha2 0.10.8", @@ -5886,9 +5785,9 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.2", + "libp2p-swarm", "log", "quick-protobuf", "rand 0.8.5", @@ -5909,9 +5808,9 @@ dependencies = [ "data-encoding", "futures", "if-watch", - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.2", + "libp2p-swarm", "log", "rand 0.8.5", "smallvec", @@ -5921,30 +5820,18 @@ dependencies = [ "void", ] -[[package]] -name = "libp2p-metrics" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad8a64f29da86005c86a4d2728b8a0719e9b192f4092b609fd8790acb9dec55" -dependencies = [ - "libp2p-core 0.38.0", - "libp2p-identify 0.41.1", - "libp2p-swarm 0.41.1", - "prometheus-client 0.18.1", -] - [[package]] name = "libp2p-metrics" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a42ec91e227d7d0dafa4ce88b333cdf5f277253873ab087555c92798db2ddd46" dependencies = [ - "libp2p-core 0.39.2", - "libp2p-identify 0.42.2", + "libp2p-core", + "libp2p-identify", "libp2p-kad", "libp2p-ping", - "libp2p-swarm 0.42.2", - "prometheus-client 0.19.0", + "libp2p-swarm", + "prometheus-client", ] [[package]] @@ -5956,7 +5843,7 @@ dependencies = [ "bytes", "curve25519-dalek 3.2.0", "futures", - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", "log", "once_cell", @@ -5980,8 +5867,8 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.39.2", - "libp2p-swarm 0.42.2", + "libp2p-core", + "libp2p-swarm", "log", "rand 0.8.5", "void", @@ -5997,7 +5884,7 @@ dependencies = [ "futures", "futures-timer", "if-watch", - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", "libp2p-tls", "log", @@ -6018,31 +5905,11 @@ dependencies = [ "async-trait", "futures", "instant", - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.2", - "rand 0.8.5", - "smallvec", -] - -[[package]] -name = "libp2p-swarm" -version = "0.41.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2a35472fe3276b3855c00f1c032ea8413615e030256429ad5349cdf67c6e1a0" -dependencies = [ - "either", - "fnv", - "futures", - "futures-timer", - "instant", - "libp2p-core 0.38.0", - "log", - "pin-project", + "libp2p-swarm", "rand 0.8.5", "smallvec", - "thiserror", - "void", ] [[package]] @@ -6056,7 +5923,7 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", "libp2p-swarm-derive", "log", @@ -6087,7 +5954,7 @@ dependencies = [ "futures-timer", "if-watch", "libc", - "libp2p-core 0.39.2", + "libp2p-core", "log", "socket2 0.4.9", "tokio", @@ -6101,7 +5968,7 @@ checksum = "ff08d13d0dc66e5e9ba6279c1de417b84fa0d0adc3b03e5732928c180ec02781" dependencies = [ "futures", "futures-rustls", - "libp2p-core 0.39.2", + "libp2p-core", "libp2p-identity", "rcgen", "ring", @@ -6120,7 +5987,7 @@ checksum = "77dff9d32353a5887adb86c8afc1de1a94d9e8c3bc6df8b2201d7cdf5c848f43" dependencies = [ "futures", "js-sys", - "libp2p-core 0.39.2", + "libp2p-core", "parity-send-wrapper", "wasm-bindgen", "wasm-bindgen-futures", @@ -6135,7 +6002,7 @@ dependencies = [ "either", "futures", "futures-rustls", - "libp2p-core 0.39.2", + "libp2p-core", "log", "parking_lot 0.12.1", "quicksink", @@ -6152,7 +6019,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd21d950662700a385d4c6d68e2f5f54d778e97068cdd718522222ef513bda" dependencies = [ "futures", - "libp2p-core 0.39.2", + "libp2p-core", "log", "thiserror", "yamux", @@ -6326,15 +6193,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "lru" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6e8aaa3f231bb4bd57b84b2d5dc3ae7f350265df8aa96492e0bc394a1571909" -dependencies = [ - "hashbrown 0.12.3", -] - [[package]] name = "lru" version = "0.10.1" @@ -6649,24 +6507,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" -[[package]] -name = "multiaddr" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aebdb21e90f81d13ed01dc84123320838e53963c2ca94b60b305d3fa64f31e" -dependencies = [ - "arrayref", - "byteorder", - "data-encoding", - "multibase", - "multihash 0.16.3", - "percent-encoding", - "serde", - "static_assertions", - "unsigned-varint", - "url", -] - [[package]] name = "multiaddr" version = "0.17.1" @@ -6678,7 +6518,7 @@ dependencies = [ "data-encoding", "log", "multibase", - "multihash 0.17.0", + "multihash", "percent-encoding", "serde", "static_assertions", @@ -6697,19 +6537,6 @@ dependencies = [ "data-encoding-macro", ] -[[package]] -name = "multihash" -version = "0.16.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c346cf9999c631f002d8f977c4eaeaa0e6386f16007202308d0b3757522c2cc" -dependencies = [ - "core2", - "digest 0.10.7", - "multihash-derive", - "sha2 0.10.8", - "unsigned-varint", -] - [[package]] name = "multihash" version = "0.17.0" @@ -8593,24 +8420,14 @@ dependencies = [ "futures-io", ] -[[package]] -name = "pkcs8" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" -dependencies = [ - "der 0.6.1", - "spki 0.6.0", -] - [[package]] name = "pkcs8" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der 0.7.8", - "spki 0.7.2", + "der", + "spki", ] [[package]] @@ -8826,18 +8643,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "prometheus-client" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83cd1b99916654a69008fd66b4f9397fbe08e6e51dfe23d4417acf5d3b8cb87c" -dependencies = [ - "dtoa", - "itoa", - "parking_lot 0.12.1", - "prometheus-client-derive-text-encode", -] - [[package]] name = "prometheus-client" version = "0.19.0" @@ -8861,17 +8666,6 @@ dependencies = [ "syn 2.0.41", ] -[[package]] -name = "prometheus-client-derive-text-encode" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a455fbcb954c1a7decf3c586e860fd7889cddf4b8e164be736dbac95a953cd" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "proptest" version = "1.4.0" @@ -8924,19 +8718,6 @@ dependencies = [ "which", ] -[[package]] -name = "prost-codec" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc34979ff898b6e141106178981ce2596c387ea6e62533facfc61a37fc879c0" -dependencies = [ - "asynchronous-codec", - "bytes", - "prost", - "thiserror", - "unsigned-varint", -] - [[package]] name = "prost-derive" version = "0.11.9" @@ -10194,7 +9975,7 @@ dependencies = [ "futures", "futures-timer", "ip_network", - "libp2p 0.51.4", + "libp2p", "linked_hash_set", "log", "mockall", @@ -10265,7 +10046,7 @@ dependencies = [ "ahash 0.8.6", "futures", "futures-timer", - "libp2p 0.51.4", + "libp2p", "log", "sc-network", "sc-network-common", @@ -10304,7 +10085,7 @@ dependencies = [ "array-bytes", "async-channel", "futures", - "libp2p 0.51.4", + "libp2p", "log", "parity-scale-codec", "sc-network", @@ -10325,7 +10106,7 @@ dependencies = [ "fork-tree", "futures", "futures-timer", - "libp2p 0.51.4", + "libp2p", "log", "mockall", "parity-scale-codec", @@ -10355,7 +10136,7 @@ source = "git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v1 dependencies = [ "array-bytes", "futures", - "libp2p 0.51.4", + "libp2p", "log", "parity-scale-codec", "sc-network", @@ -10378,7 +10159,7 @@ dependencies = [ "futures-timer", "hyper", "hyper-rustls", - "libp2p 0.51.4", + "libp2p", "log", "num_cpus", "once_cell", @@ -10620,7 +10401,7 @@ source = "git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v1 dependencies = [ "chrono", "futures", - "libp2p 0.51.4", + "libp2p", "log", "parking_lot 0.12.1", "pin-project", @@ -10930,29 +10711,16 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" -[[package]] -name = "sec1" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" -dependencies = [ - "base16ct 0.1.1", - "der 0.6.1", - "generic-array 0.14.7", - "pkcs8 0.9.0", - "zeroize", -] - [[package]] name = "sec1" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ - "base16ct 0.2.0", - "der 0.7.8", + "base16ct", + "der", "generic-array 0.14.7", - "pkcs8 0.10.2", + "pkcs8", "subtle", "zeroize", ] @@ -11389,7 +11157,7 @@ dependencies = [ "hex", "itertools", "log", - "lru 0.10.1", + "lru", "parking_lot 0.12.1", "rand 0.8.5", "serde", @@ -12202,16 +11970,6 @@ dependencies = [ "strum 0.24.1", ] -[[package]] -name = "spki" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" -dependencies = [ - "base64ct", - "der 0.6.1", -] - [[package]] name = "spki" version = "0.7.2" @@ -12219,7 +11977,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" dependencies = [ "base64ct", - "der 0.7.8", + "der", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 267a377e22b..b5b521f083a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -430,7 +430,7 @@ impl-trait-for-tuples = "0.2.2" # pall indexmap = "2.1.0" # utils/weight-diff indicatif = "*" # utils/wasm-gen keyring = "1.2.1" # gcli -libp2p = "=0.50.1" # gcli (same version as sc-consensus) +libp2p = "=0.51.4" # gcli (same version as sc-consensus) mimalloc = { version = "0.1.39", default-features = false } # node/cli nacl = "0.5.3" # gcli nonempty = "0.8.1" # utils/utils diff --git a/Makefile b/Makefile index 147ed020b68..a48a07cf491 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ show: @ ./scripts/gear.sh show -.PHONY: pre-commit +.PHONY: pre-commit # Here should be no release builds to keep checks fast. pre-commit: fmt clippy test check-runtime-imports .PHONY: check-spec @@ -178,8 +178,7 @@ purge-dev-chain-release: @ ./scripts/gear.sh run purge-dev-chain --release # Test section -.PHONY: test # \ - There should be no release builds to keep checks fast. +.PHONY: test # Here should be no release builds to keep checks fast. test: test-gear .PHONY: test-release @@ -190,15 +189,18 @@ test-doc: @ ./scripts/gear.sh test docs .PHONY: test-gear -test-gear: #\ - We use lazy-pages feature for pallet-gear-debug due to cargo building issue \ - and fact that pallet-gear default is lazy-pages. - @ ./scripts/gear.sh test gear --exclude gclient --exclude gcli --exclude gsdk +test-gear: # Crates except gclient, gcli, gsdk are excluded to significantly decrease time. + @ ./scripts/gear.sh test gear \ + --exclude gclient \ + --exclude gcli \ + --exclude gsdk \ + --exclude gear-authorship \ + --exclude pallet-gear-staking-rewards \ + --exclude gear-wasm-gen \ + --exclude demo-stack-allocations .PHONY: test-gear-release -test-gear-release: # \ - We use lazy-pages feature for pallet-gear-debug due to cargo building issue \ - and fact that pallet-gear default is lazy-pages. +test-gear-release: @ ./scripts/gear.sh test gear --release --exclude gclient --exclude gcli --exclude gsdk .PHONY: test-gsdk diff --git a/common/src/pallet_tests.rs b/common/src/pallet_tests.rs index 8fdb6b1a044..430084a134b 100644 --- a/common/src/pallet_tests.rs +++ b/common/src/pallet_tests.rs @@ -20,9 +20,8 @@ //! for various pallets of Substrate. //! All used types should be in scope. -use frame_support::{pallet_prelude::*, weights::RuntimeDbWeight}; +use frame_support::{pallet_prelude::*, sp_runtime::Perbill, weights::RuntimeDbWeight}; use frame_system::limits::BlockWeights; -use sp_arithmetic::Perbill; #[macro_export] macro_rules! impl_pallet_balances { diff --git a/gcli/src/cmd/key.rs b/gcli/src/cmd/key.rs index f4ea4d5f715..a2959b5ef4d 100644 --- a/gcli/src/cmd/key.rs +++ b/gcli/src/cmd/key.rs @@ -161,10 +161,7 @@ impl Key { let pair = Keypair::generate(); println!("Secret: 0x{}", hex::encode(pair.secret().as_ref())); - println!( - "Peer ID: {}", - PublicKey::Ed25519(pair.public()).to_peer_id() - ); + println!("Peer ID: {}", PublicKey::from(pair.public()).to_peer_id()); } fn info

(title: &str, signer: &P, seed: Option>) @@ -203,14 +200,11 @@ impl Key { PublicKey, }; let pair = Keypair::from( - SecretKey::from_bytes(&mut hex::decode(secret)?) + SecretKey::try_from_bytes(&mut hex::decode(secret)?) .map_err(|_| crate::result::Error::BadNodeKey)?, ); - println!( - "Peer ID: {}", - PublicKey::Ed25519(pair.public()).to_peer_id() - ); + println!("Peer ID: {}", PublicKey::from(pair.public()).to_peer_id()); Ok(()) } diff --git a/gsdk/tests/rpc.rs b/gsdk/tests/rpc.rs index 307f679b76e..b790a25f73c 100644 --- a/gsdk/tests/rpc.rs +++ b/gsdk/tests/rpc.rs @@ -28,6 +28,36 @@ use utils::{alice_account_id, dev_node, node_uri}; mod utils; +#[tokio::test] +async fn pallet_errors_formatting() -> Result<()> { + let node = dev_node(); + let api = Api::new(Some(&node_uri(&node))).await?; + + let err = api + .calculate_upload_gas( + [0u8; 32].into(), + /* invalid code */ vec![], + vec![], + 0, + true, + None, + ) + .await + .expect_err("Must return error"); + + let expected_err = Error::Subxt(SubxtError::Rpc(RpcError::ClientError(Box::new( + CallError::Custom(ErrorObject::owned( + 8000, + "Runtime error", + Some("Extrinsic `gear.upload_program` failed: 'ProgramConstructionFailed'"), + )), + )))); + + assert_eq!(format!("{err}"), format!("{expected_err}")); + + Ok(()) +} + #[tokio::test] async fn test_calculate_upload_gas() -> Result<()> { let node = dev_node(); diff --git a/gtest/Cargo.toml b/gtest/Cargo.toml index c091b9b977a..73f8817e787 100644 --- a/gtest/Cargo.toml +++ b/gtest/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "gtest" -version = "0.1.0" +description = "Testing utils for developing Gear programs." +version.workspace = true authors.workspace = true edition.workspace = true license.workspace = true diff --git a/pallets/gear/rpc/src/lib.rs b/pallets/gear/rpc/src/lib.rs index 7e85786071f..f45ef755ea1 100644 --- a/pallets/gear/rpc/src/lib.rs +++ b/pallets/gear/rpc/src/lib.rs @@ -39,11 +39,11 @@ use sp_runtime::traits::Block as BlockT; use std::sync::Arc; /// Converts a runtime trap into a [`CallError`]. -fn runtime_error_into_rpc_error(err: impl std::fmt::Debug) -> JsonRpseeError { +fn runtime_error_into_rpc_error(err: impl std::fmt::Display) -> JsonRpseeError { CallError::Custom(ErrorObject::owned( 8000, "Runtime error", - Some(format!("{err:?}")), + Some(format!("{err}")), )) .into() } diff --git a/pallets/gear/src/runtime_api.rs b/pallets/gear/src/runtime_api.rs index e9630b34191..d7ba184458e 100644 --- a/pallets/gear/src/runtime_api.rs +++ b/pallets/gear/src/runtime_api.rs @@ -21,12 +21,15 @@ use crate::queue::{ActorResult, QueueStep}; use common::ActiveProgram; use core::convert::TryFrom; use core_processor::common::PrechargedDispatch; +use frame_support::traits::PalletInfo; use gear_core::{code::TryNewCodeConfig, pages::WasmPage, program::MemoryInfix}; use gear_wasm_instrument::syscalls::SyscallName; +use sp_runtime::{DispatchErrorWithPostInfo, ModuleError}; // Multiplier 6 was experimentally found as median value for performance, // security and abilities for calculations on-chain. pub(crate) const RUNTIME_API_BLOCK_LIMITS_COUNT: u64 = 6; +pub(crate) const ALLOWANCE_LIMIT_ERR: &str = "Calculation gas limit exceeded. Use your own RPC node with `--rpc-calculations-multiplier` parameter raised"; pub(crate) struct CodeWithMemoryData { pub instrumented_code: InstrumentedCode, @@ -69,16 +72,45 @@ where QueueOf::::clear(); + let map_extrinsic_err = |extrinsic_name: &'static str, + e: DispatchErrorWithPostInfo| + -> Vec { + let error_module_idx = if let DispatchError::Module(ModuleError { index, .. }) = e.error + { + Some(index as usize) + } else { + None + }; + + let error_message: &'static str = e.into(); + + let gear_module_idx = + <::PalletInfo as PalletInfo>::index::>() + .expect("No index found for the gear pallet in the runtime!"); + + let mut res = format!("Extrinsic `gear.{extrinsic_name}` failed: '{error_message}'"); + + if let Some(module_idx) = error_module_idx.filter(|i| *i != gear_module_idx) { + res = format!("{res} (pallet index of the error: {module_idx}"); + } + + res.into_bytes() + }; + + let internal_err = |message: &'static str| -> Vec { + format!("Internal error: entered unreachable code '{message}'").into_bytes() + }; + match kind { HandleKind::Init(code) => { let salt = b"calculate_gas_salt".to_vec(); + Self::upload_program(who.into(), code, salt, payload, initial_gas, value, false) - .map_err(|e| { - format!("Internal error: upload_program failed with '{e:?}'").into_bytes() - })?; + .map_err(|e| map_extrinsic_err("upload_program", e))?; } HandleKind::InitByHash(code_id) => { let salt = b"calculate_gas_salt".to_vec(); + Self::create_program( who.into(), code_id, @@ -88,21 +120,15 @@ where value, false, ) - .map_err(|e| { - format!("Internal error: create_program failed with '{e:?}'").into_bytes() - })?; + .map_err(|e| map_extrinsic_err("create_program", e))?; } HandleKind::Handle(destination) => { Self::send_message(who.into(), destination, payload, initial_gas, value, false) - .map_err(|e| { - format!("Internal error: send_message failed with '{e:?}'").into_bytes() - })?; + .map_err(|e| map_extrinsic_err("send_message", e))?; } HandleKind::Reply(reply_to_id, _status_code) => { Self::send_reply(who.into(), reply_to_id, payload, initial_gas, value, false) - .map_err(|e| { - format!("Internal error: send_reply failed with '{e:?}'").into_bytes() - })?; + .map_err(|e| map_extrinsic_err("send_reply", e))?; } HandleKind::Signal(_signal_from, _status_code) => { return Err(b"Gas calculation for `handle_signal` is not supported".to_vec()); @@ -111,10 +137,10 @@ where let (main_message_id, main_program_id) = QueueOf::::iter() .next() - .ok_or_else(|| b"Internal error: failed to get last message".to_vec()) + .ok_or_else(|| internal_err("Failed to get last message from the queue")) .and_then(|queued| { queued - .map_err(|_| b"Internal error: failed to retrieve queued dispatch".to_vec()) + .map_err(|_| internal_err("Failed to extract queued dispatch")) .map(|dispatch| (dispatch.id(), dispatch.destination())) })?; @@ -135,13 +161,11 @@ where loop { if QueueProcessingOf::::denied() { - return Err( - b"Calculation gas limit exceeded. Consider using custom built node.".to_vec(), - ); + return Err(ALLOWANCE_LIMIT_ERR.as_bytes().to_vec()); } let Some(queued_dispatch) = - QueueOf::::dequeue().map_err(|_| b"MQ storage corrupted".to_vec())? + QueueOf::::dequeue().map_err(|_| internal_err("Message queue corrupted"))? else { break; }; @@ -164,8 +188,9 @@ where .reply_details() .map(|rd| rd.to_reply_code().is_success()) .unwrap_or(false); + let gas_limit = GasHandlerOf::::get_limit(dispatch_id) - .map_err(|_| b"Internal error: unable to get gas limit".to_vec())?; + .map_err(|_| internal_err("Failed to get gas limit"))?; let skip_if_allowed = success_reply && gas_limit == 0; @@ -177,7 +202,10 @@ where balance: balance.unique_saturated_into(), get_actor_data, }; - let journal = step.execute().unwrap_or_else(|e| unreachable!("{e:?}")); + + let journal = step + .execute() + .map_err(|_| internal_err("Queue execution error"))?; let get_main_limit = || { // For case when node is not consumed and has any (even zero) balance @@ -201,7 +229,7 @@ where let get_origin_msg_of = |msg_id| { GasHandlerOf::::get_origin_key(msg_id) - .map_err(|_| b"Internal error: unable to get origin key".to_vec()) + .map_err(|_| internal_err("Failed to get origin key")) }; let from_main_chain = |msg_id| get_origin_msg_of(msg_id).map(|v| v == main_message_id.into()); @@ -239,8 +267,7 @@ where .gas_limit() .or_else(|| GasHandlerOf::::get_limit(dispatch.id()).ok()) .ok_or_else(|| { - b"Internal error: unable to get gas limit after execution" - .to_vec() + internal_err("Failed to get gas limit after execution") })?; reserved = reserved.saturating_add(gas_limit); @@ -260,7 +287,9 @@ where } if (message_id == main_message_id || !allow_other_panics) && !(skip_if_allowed && allow_skip_zero_replies) => { - return Err(format!("Program terminated with a trap: {trap}").into_bytes()); + return Err( + format!("Program terminated with a trap: '{trap}'").into_bytes() + ); } _ => (), diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index 10145f39e27..10304d457cb 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -44,7 +44,7 @@ use crate::{ USER_3, }, pallet, - runtime_api::RUNTIME_API_BLOCK_LIMITS_COUNT, + runtime_api::{ALLOWANCE_LIMIT_ERR, RUNTIME_API_BLOCK_LIMITS_COUNT}, AccountIdOf, BlockGasLimitOf, Config, CostsPerBlockOf, CurrencyOf, DbWeightOf, DispatchStashOf, Error, Event, GasAllowanceOf, GasBalanceOf, GasHandlerOf, GasInfo, GearBank, MailboxOf, ProgramStorageOf, QueueOf, Schedule, TaskPoolOf, WaitlistOf, @@ -8341,22 +8341,19 @@ fn call_forbidden_function() { run_to_block(2, None); - let res = Gear::calculate_gas_info( + let err = Gear::calculate_gas_info( USER_1.into_origin(), HandleKind::Handle(prog_id), EMPTY_PAYLOAD.to_vec(), 0, true, true, - ); + ) + .expect_err("Must return error"); - assert_eq!( - res, - Err(format!( - "Program terminated with a trap: {}", - TrapExplanation::ForbiddenFunction, - )) - ); + let trap = TrapExplanation::ForbiddenFunction; + + assert_eq!(err, format!("Program terminated with a trap: '{trap}'")); }); } @@ -13111,10 +13108,7 @@ fn calculate_gas_fails_when_calculation_limit_exceeded() { ); assert!(gas_info_result.is_err()); - assert_eq!( - gas_info_result.unwrap_err(), - "Calculation gas limit exceeded. Consider using custom built node." - ); + assert_eq!(gas_info_result.unwrap_err(), ALLOWANCE_LIMIT_ERR); // ok result when we use custom multiplier let gas_info_result = Gear::calculate_gas_info_impl( diff --git a/utils/crates-io/src/handler.rs b/utils/crates-io/src/handler.rs new file mode 100644 index 00000000000..9788aa8dbab --- /dev/null +++ b/utils/crates-io/src/handler.rs @@ -0,0 +1,232 @@ +// This file is part of Gear. + +// Copyright (C) 2021-2023 Gear Technologies Inc. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Handlers for patching manifests. + +use crate::Manifest; +use anyhow::Result; +use cargo_metadata::Package; +use toml_edit::Document; + +/// Get the crates-io name of the provided package. +pub fn crates_io_name(pkg: &str) -> &str { + // `gear-core-processor` is taken by others, see the docs + // of [`core-processor::patch_workspace`] for more details. + if pkg == "gear-core-processor" { + "core-processor" + } else { + pkg + } +} + +/// Patch specified manifest by provided name. +pub fn patch(pkg: &Package) -> Result { + let mut manifest = Manifest::new(pkg)?; + let doc = &mut manifest.manifest; + + match manifest.name.as_str() { + "gear-core-processor" => core_processor::patch(doc), + "gear-runtime-interface" => runtime_interface::patch(doc), + "gear-sandbox" => sandbox::patch(doc), + "gear-sandbox-host" => sandbox_host::patch(doc), + "gmeta" => gmeta::patch(doc), + "gmeta-codegen" => gmeta_codegen::patch(doc), + _ => {} + } + + Ok(manifest) +} + +/// Patch package alias. +pub fn patch_alias(index: &mut Vec<&str>) { + for (package, alias) in crate::PACKAGE_ALIAS { + if index.contains(&package) { + index.push(alias); + } + } +} + +/// Patch the workspace manifest. +pub fn patch_workspace(name: &str, table: &mut toml_edit::InlineTable) { + match name { + "core-processor" | "gear-core-processor" => core_processor::patch_workspace(name, table), + sub if sub.starts_with("sp-") => substrate::patch_workspace(name, table), + _ => {} + } +} + +// Trim the version of dev dependency. +// +// issue: https://github.com/rust-lang/cargo/issues/4242 +fn trim_dev_dep(name: &str, manifest: &mut Document) { + if let Some(dep) = manifest["dev-dependencies"][name].as_inline_table_mut() { + dep.remove("workspace"); + dep.insert("version", "~1".into()); + } + + if let Some(dep) = manifest["dev-dependencies"][name].as_table_like_mut() { + dep.remove("workspace"); + dep.insert("version", toml_edit::value("~1")); + } +} + +/// gear-core-processor handler. +mod core_processor { + use toml_edit::{Document, InlineTable}; + + /// Pointing the package name of core-processor to + /// `core-processor` on `crates-io` since this is + /// the one we own. + pub fn patch_workspace(name: &str, table: &mut InlineTable) { + match name { + // Remove the path definition to point core-processor to + // crates-io. + "core-processor" => { + table.remove("package"); + } + // Points to `core-processor` for the one on crates-io. + "gear-core-processor" => { + table.insert("package", "core-processor".into()); + } + _ => {} + } + } + + /// Patch the manifest of core-processor. + pub fn patch(manifest: &mut Document) { + manifest["package"]["name"] = toml_edit::value("core-processor"); + } +} + +/// gmeta handler +mod gmeta { + use super::trim_dev_dep; + use toml_edit::Document; + + /// Patch the manifest of gmetadata. + pub fn patch(manifest: &mut Document) { + trim_dev_dep("gstd", manifest); + trim_dev_dep("gear-wasm-builder", manifest); + } +} + +/// gmeta handler +mod gmeta_codegen { + use super::trim_dev_dep; + use toml_edit::Document; + + /// Patch the manifest of gmeta. + pub fn patch(manifest: &mut Document) { + trim_dev_dep("gstd", manifest); + trim_dev_dep("gmeta", manifest); + } +} + +mod runtime_interface { + use crate::GP_RUNTIME_INTERFACE_VERSION; + use toml_edit::Document; + + /// Patch the manifest of runtime-interface. + /// + /// We need to patch the manifest of package again because + /// `sp_runtime_interface_proc_macro` includes some hardcode + /// that could not locate alias packages. + pub fn patch(manifest: &mut Document) { + let Some(wi) = manifest["dependencies"]["sp-runtime-interface"].as_table_mut() else { + return; + }; + wi.insert("version", toml_edit::value(GP_RUNTIME_INTERFACE_VERSION)); + wi.insert("package", toml_edit::value("gp-runtime-interface")); + wi.remove("workspace"); + } +} + +/// sandbox handler. +mod sandbox { + use toml_edit::Document; + + /// Replace the wasmi module to the crates-io version. + pub fn patch(manifest: &mut Document) { + let Some(wasmi) = manifest["dependencies"]["wasmi"].as_inline_table_mut() else { + return; + }; + wasmi.insert("package", "gwasmi".into()); + wasmi.insert("version", "0.30.0".into()); + wasmi.remove("branch"); + wasmi.remove("git"); + } +} + +/// sandbox_host handler. +mod sandbox_host { + use toml_edit::Document; + + /// Replace the wasmi module to the crates-io version. + pub fn patch(manifest: &mut Document) { + let Some(wasmi) = manifest["dependencies"]["wasmi"].as_inline_table_mut() else { + return; + }; + wasmi.insert("version", "0.13.2".into()); + wasmi.remove("branch"); + wasmi.remove("git"); + } +} + +/// substrate handler. +mod substrate { + use crate::GP_RUNTIME_INTERFACE_VERSION; + use toml_edit::InlineTable; + + /// Patch the substrate packages in the manifest of workspace. + /// + /// NOTE: The packages inside of this function are located at + /// . + pub fn patch_workspace(name: &str, table: &mut InlineTable) { + match name { + // sp-allocator is outdated on crates.io, last + // 3.0.0 forever, here we use gp-allocator instead. + "sp-allocator" => { + table.insert("version", "4.1.1".into()); + table.insert("package", "gp-allocator".into()); + } + // Our sp-wasm-interface is different from the + // original one. + "sp-wasm-interface" => { + table.insert("package", "gp-wasm-interface".into()); + table.insert("version", "7.0.1".into()); + } + // Related to sp-wasm-interface. + "sp-wasm-interface-common" => { + table.insert("version", "7.0.1".into()); + } + // Related to sp-wasm-interface. + "sp-runtime-interface" => { + table.insert("version", GP_RUNTIME_INTERFACE_VERSION.into()); + table.insert("package", "gp-runtime-interface".into()); + } + // The versions of these packages on crates.io are incorrect. + "sp-arithmetic" | "sp-core" | "sp-rpc" | "sp-version" => { + table.insert("version", "21.0.0".into()); + } + _ => {} + } + + table.remove("branch"); + table.remove("git"); + } +} diff --git a/utils/crates-io/src/lib.rs b/utils/crates-io/src/lib.rs index 454b60615c0..f75d37b77cb 100644 --- a/utils/crates-io/src/lib.rs +++ b/utils/crates-io/src/lib.rs @@ -19,6 +19,7 @@ //! crates-io-manager library #![deny(missing_docs)] +mod handler; mod manifest; mod publisher; mod version; @@ -28,12 +29,14 @@ use anyhow::Result; use std::process::{Command, ExitStatus}; /// Required Packages without local dependencies. -pub const SAFE_DEPENDENCIES: [&str; 10] = [ +pub const SAFE_DEPENDENCIES: [&str; 12] = [ "actor-system-error", "galloc", "gear-stack-buffer", "gear-core-errors", "gear-common-codegen", + "gear-runtime-primitives", + "gear-sandbox-env", "gear-wasm-instrument", "gmeta-codegen", "gsdk-codegen", @@ -42,16 +45,50 @@ pub const SAFE_DEPENDENCIES: [&str; 10] = [ ]; /// Required packages with local dependencies. -pub const STACKED_DEPENDENCIES: [&str; 5] = - ["gcore", "gmeta", "gear-core", "gear-utils", "gear-common"]; +/// +/// NOTE: DO NOT change the order of this array. +pub const STACKED_DEPENDENCIES: [&str; 13] = [ + "gcore", + "gmeta", + "gear-core", + "gear-utils", + "gear-common", + "gear-sandbox-host", + "gear-lazy-pages-common", + "gear-lazy-pages", + "gear-runtime-interface", + "gear-lazy-pages-interface", + "gear-sandbox", + "gear-core-backend", + "gear-core-processor", +]; /// Packages need to be published. -pub const PACKAGES: [&str; 5] = ["gear-wasm-builder", "gstd", "gsdk", "gclient", "gcli"]; +/// +/// NOTE: DO NOT change the order of this array. +pub const PACKAGES: [&str; 6] = [ + "gear-wasm-builder", + "gstd", + "gtest", + "gsdk", + "gclient", + "gcli", +]; + +/// Alias for packages. +pub const PACKAGE_ALIAS: [(&str, &str); 2] = [ + ("gear-core-processor", "core-processor"), + ("gear-runtime-primitives", "runtime-primitives"), +]; + +/// The working version of sp-wasm-interface. +pub const GP_RUNTIME_INTERFACE_VERSION: &str = "7.0.5"; /// Check the input package pub fn check(manifest: &str) -> Result { Command::new("cargo") .arg("check") + .arg("--lib") .arg("--manifest-path") .arg(manifest) .status() diff --git a/utils/crates-io/src/main.rs b/utils/crates-io/src/main.rs index 15fc0b0fe85..896a1946073 100644 --- a/utils/crates-io/src/main.rs +++ b/utils/crates-io/src/main.rs @@ -52,10 +52,10 @@ fn main() -> Result<()> { let publisher = Publisher::new()?; match command { - Command::Check => publisher.build(None)?.check(), - Command::Publish { version } => publisher.build(version)?.publish(), + Command::Check => publisher.build(false, None)?.check(), + Command::Publish { version } => publisher.build(true, version)?.publish(), Command::Build => { - publisher.build(None)?; + publisher.build(false, None)?; Ok(()) } } diff --git a/utils/crates-io/src/manifest.rs b/utils/crates-io/src/manifest.rs index 942a43118cc..99555655808 100644 --- a/utils/crates-io/src/manifest.rs +++ b/utils/crates-io/src/manifest.rs @@ -18,28 +18,24 @@ //! Manifest utils for crates-io-manager +use crate::{handler, version}; use anyhow::{anyhow, Result}; use cargo_metadata::Package; -use std::{fs, path::PathBuf}; +use std::{ + fs, + ops::{Deref, DerefMut}, + path::PathBuf, +}; use toml_edit::Document; -use crate::version; - const WORKSPACE_NAME: &str = "__gear_workspace"; -/// Cargo manifest with path -pub struct Manifest { - /// Crate name - pub name: String, - /// Cargo manifest - pub manifest: Document, - /// Path of the manifest - pub path: PathBuf, -} +/// Workspace instance, which is a wrapper of [`Manifest`]. +pub struct Workspace(Manifest); -impl Manifest { - /// Get the workspace manifest - pub fn workspace() -> Result { +impl Workspace { + /// Get the workspace manifest with version overridden. + pub fn lookup(version: Option) -> Result { let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .ancestors() .nth(2) @@ -47,35 +43,34 @@ impl Manifest { .ok_or_else(|| anyhow::anyhow!("Could not find workspace manifest"))? .canonicalize()?; - Ok(Self { + let mut workspace: Self = Manifest { name: WORKSPACE_NAME.to_string(), manifest: fs::read_to_string(&path)?.parse()?, path, - }) - } - - /// Complete the manifest of the specified crate from - /// the workspace manifest - pub fn manifest(&self, pkg: &Package) -> Result { - self.ensure_workspace()?; + } + .into(); + + // NOTE: renaming version here is required because it could + // be easy to publish incorrect version to crates.io by mistake + // in testing. + { + let version = if let Some(version) = version { + version + } else { + workspace.version()? + "-" + &version::hash()? + }; - // Complete documentation as from - let mut manifest: Document = fs::read_to_string(&pkg.manifest_path)?.parse()?; - let name = pkg.name.clone(); - manifest["package"]["documentation"] = toml_edit::value(format!("https://docs.rs/{name}")); + workspace.manifest["workspace"]["package"]["version"] = toml_edit::value(version); + } - Ok(Self { - name, - manifest, - path: pkg.manifest_path.clone().into(), - }) + Ok(workspace) } /// complete the versions of the specified crates - pub fn complete_versions(&mut self, index: &[&str]) -> Result<()> { - self.ensure_workspace()?; + pub fn complete(&mut self, mut index: Vec<&str>) -> Result<()> { + handler::patch_alias(&mut index); - let version = self.manifest["workspace"]["package"]["version"] + let version = self.0.manifest["workspace"]["package"]["version"] .clone() .as_str() .ok_or_else(|| anyhow!("Could not find version in workspace manifest"))? @@ -97,29 +92,12 @@ impl Manifest { dep["version"] = toml_edit::value(version.clone()); } - self.rename_deps()?; + self.rename()?; Ok(()) } - /// Set version for the workspace. - pub fn with_version(mut self, version: Option) -> Result { - self.ensure_workspace()?; - - let version = if let Some(version) = version { - version - } else { - self.version()? + "-" + &version::hash()? - }; - - self.manifest["workspace"]["package"]["version"] = toml_edit::value(version); - - Ok(self) - } - /// Get version from the current manifest. pub fn version(&self) -> Result { - self.ensure_workspace()?; - Ok(self.manifest["workspace"]["package"]["version"] .as_str() .ok_or_else(|| { @@ -131,58 +109,79 @@ impl Manifest { .to_string()) } - /// Write manifest to disk. - pub fn write(&self) -> Result<()> { - fs::write(&self.path, self.manifest.to_string()).map_err(Into::into) - } - - /// Rename dependencies - fn rename_deps(&mut self) -> Result<()> { - self.ensure_workspace()?; - + /// Rename worskapce manifest. + fn rename(&mut self) -> Result<()> { let Some(deps) = self.manifest["workspace"]["dependencies"].as_table_like_mut() else { return Ok(()); }; for (name, dep) in deps.iter_mut() { let name = name.get(); - if !name.starts_with("sp-") { + let Some(table) = dep.as_inline_table_mut() else { continue; - } - - // Format dotted values into inline table. - if let Some(table) = dep.as_table_mut() { - table.remove("branch"); - table.remove("git"); - table.remove("workspace"); - - if name == "sp-arithmetic" { - // NOTE: the required version of sp-arithmetic is 6.0.0 in - // git repo, but 7.0.0 in crates.io, so we need to fix it. - table.insert("version", toml_edit::value("7.0.0")); - } - - // Force the dep to be inline table in case of losing - // documentation. - let mut inline = table.clone().into_inline_table(); - inline.fmt(); - *dep = toml_edit::value(inline); }; + + handler::patch_workspace(name, table); } Ok(()) } +} - /// Ensure the current function is called on the workspace manifest - /// - /// TODO: remove this interface after #3565 - fn ensure_workspace(&self) -> Result<()> { - if self.name != WORKSPACE_NAME { - return Err(anyhow!( - "This method can only be called on the workspace manifest" - )); - } +impl From for Workspace { + fn from(manifest: Manifest) -> Self { + Self(manifest) + } +} - Ok(()) +impl Deref for Workspace { + type Target = Manifest; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for Workspace { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +/// Cargo manifest with path +pub struct Manifest { + /// Crate name + pub name: String, + /// Cargo manifest + pub manifest: Document, + /// Path of the manifest + pub path: PathBuf, +} + +impl Manifest { + /// Complete the manifest of the specified crate from + /// the workspace manifest + pub fn new(pkg: &Package) -> Result { + // Complete documentation as from + let mut manifest: Document = fs::read_to_string(&pkg.manifest_path)?.parse()?; + let name = pkg.name.clone(); + manifest["package"]["documentation"] = toml_edit::value(format!("https://docs.rs/{name}")); + + Ok(Self { + name, + manifest, + path: pkg.manifest_path.clone().into(), + }) + } + + /// Write manifest to disk. + pub fn write(&self) -> Result<()> { + fs::write(&self.path, self.manifest.to_string()).map_err(Into::into) + } +} + +impl From for Manifest { + fn from(workspace: Workspace) -> Self { + workspace.0 } } diff --git a/utils/crates-io/src/publisher.rs b/utils/crates-io/src/publisher.rs index 0155eea94c8..2153cdac6f8 100644 --- a/utils/crates-io/src/publisher.rs +++ b/utils/crates-io/src/publisher.rs @@ -18,7 +18,9 @@ //! Packages publisher -use crate::{Manifest, PACKAGES, SAFE_DEPENDENCIES, STACKED_DEPENDENCIES}; +use crate::{ + handler, manifest::Workspace, Manifest, PACKAGES, SAFE_DEPENDENCIES, STACKED_DEPENDENCIES, +}; use anyhow::Result; use cargo_metadata::{Metadata, MetadataCommand, Package}; use std::collections::{BTreeMap, HashMap}; @@ -59,9 +61,9 @@ impl Publisher { /// 1. Replace git dependencies to crates-io dependencies. /// 2. Rename version of all local packages /// 3. Patch dependencies if needed - pub fn build(mut self, version: Option) -> Result { + pub fn build(mut self, verify: bool, version: Option) -> Result { let index = self.index.keys().map(|s| s.as_ref()).collect::>(); - let mut workspace = Manifest::workspace()?.with_version(version)?; + let mut workspace = Workspace::lookup(version)?; let version = workspace.version()?; for pkg @ Package { name, .. } in &self.metadata.packages { @@ -69,20 +71,20 @@ impl Publisher { continue; } - println!("Verifying {}@{} ...", &name, &version); - if crate::verify(name, &version)? { + if verify && crate::verify(name, &version)? { println!("Package {}@{} already published .", &name, &version); continue; } self.graph - .insert(self.index.get(name).cloned(), workspace.manifest(pkg)?); + .insert(self.index.get(name).cloned(), handler::patch(pkg)?); } - // Flush new manifests to disk - workspace.complete_versions(&index)?; - let mut manifests = self.graph.values().collect::>(); - manifests.push(&workspace); + workspace.complete(index)?; + + // write manifests to disk. + let manifest = workspace.into(); + let manifests = [self.graph.values().collect::>(), vec![&manifest]].concat(); manifests .iter() .map(|m| m.write()) diff --git a/utils/crates-io/src/version.rs b/utils/crates-io/src/version.rs index 4986ef927fc..b5fd0e657f7 100644 --- a/utils/crates-io/src/version.rs +++ b/utils/crates-io/src/version.rs @@ -22,6 +22,8 @@ use anyhow::{anyhow, Result}; use serde::Deserialize; use std::process::Command; +use crate::handler; + #[derive(Debug, Deserialize)] struct Resp { pub versions: Vec, @@ -34,16 +36,24 @@ struct Version { /// Verify if the package has already been published. pub fn verify(name: &str, version: &str) -> Result { + println!("Verifying {}@{} ...", &name, &version); + let client = reqwest::blocking::Client::builder() .user_agent("gear-crates-io-manager") .build()?; - let resp = client - .get(format!("https://crates.io/api/v1/crates/{name}/versions")) + if let Ok(resp) = client + .get(format!( + "https://crates.io/api/v1/crates/{}/versions", + handler::crates_io_name(name) + )) .send()? - .json::()?; + .json::() + { + return Ok(resp.versions.into_iter().any(|v| v.num == version)); + } - Ok(resp.versions.into_iter().any(|v| v.num == version)) + Ok(false) } /// Get the short hash of the current commit. diff --git a/utils/wasm-instrument/Cargo.toml b/utils/wasm-instrument/Cargo.toml index b3dc15dfe39..f1df578f9b6 100644 --- a/utils/wasm-instrument/Cargo.toml +++ b/utils/wasm-instrument/Cargo.toml @@ -18,7 +18,6 @@ enum-iterator.workspace = true [dev-dependencies] wasmparser.workspace = true wat.workspace = true -gear-core.workspace = true [features] default = ["std"]