From f4bed52129b4643c4caa94f23cc36f4fc85124ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Eng=C3=A9libert?= <tuxmain@zettascript.org> Date: Fri, 9 Jun 2023 18:40:14 +0200 Subject: [PATCH] feat: distance --- Cargo.lock | 799 +++++++++++++++------------ Cargo.toml | 27 +- client/distance/Cargo.toml | 51 ++ client/distance/src/lib.rs | 112 ++++ distance-oracle/Cargo.toml | 31 ++ distance-oracle/src/lib.rs | 279 ++++++++++ distance-oracle/src/main.rs | 23 + docs/api/manual.md | 3 + docs/user/distance.md | 27 + node/src/service.rs | 61 +- pallets/authority-members/src/lib.rs | 7 +- pallets/distance/Cargo.toml | 91 +++ pallets/distance/src/lib.rs | 382 +++++++++++++ pallets/distance/src/median.rs | 143 +++++ pallets/distance/src/traits.rs | 21 + pallets/distance/src/types.rs | 28 + pallets/duniter-wot/Cargo.toml | 6 +- pallets/duniter-wot/src/lib.rs | 12 +- pallets/duniter-wot/src/mock.rs | 2 + pallets/duniter-wot/src/traits.rs | 27 + primitives/distance/Cargo.toml | 67 +++ primitives/distance/src/lib.rs | 110 ++++ resources/metadata.scale | Bin 131109 -> 132872 bytes runtime/common/Cargo.toml | 30 +- runtime/common/src/handlers.rs | 6 +- runtime/common/src/pallets_config.rs | 13 + runtime/common/src/providers.rs | 15 + runtime/gdev/Cargo.toml | 24 +- runtime/gdev/src/lib.rs | 1 + 29 files changed, 1999 insertions(+), 399 deletions(-) create mode 100644 client/distance/Cargo.toml create mode 100644 client/distance/src/lib.rs create mode 100644 distance-oracle/Cargo.toml create mode 100644 distance-oracle/src/lib.rs create mode 100644 distance-oracle/src/main.rs create mode 100644 docs/user/distance.md create mode 100644 pallets/distance/Cargo.toml create mode 100644 pallets/distance/src/lib.rs create mode 100644 pallets/distance/src/median.rs create mode 100644 pallets/distance/src/traits.rs create mode 100644 pallets/distance/src/types.rs create mode 100644 pallets/duniter-wot/src/traits.rs create mode 100644 primitives/distance/Cargo.toml create mode 100644 primitives/distance/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index d00e4ff66..45bd3257e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" dependencies = [ - "gimli 0.27.0", + "gimli 0.27.1", ] [[package]] @@ -313,9 +313,9 @@ checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" [[package]] name = "async-trait" -version = "0.1.60" +version = "0.1.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" +checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" dependencies = [ "proc-macro2", "quote", @@ -337,9 +337,9 @@ dependencies = [ [[package]] name = "atomic-waker" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" +checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" [[package]] name = "atty" @@ -369,7 +369,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.30.0", + "object 0.30.3", "rustc-demangle", ] @@ -397,6 +397,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + [[package]] name = "base64ct" version = "1.5.3" @@ -554,11 +560,12 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "0.2.17" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +checksum = "b7f0778972c64420fdedc63f09919c8a88bda7b25135357fd25a5d9f3257e832" dependencies = [ "memchr", + "serde", ] [[package]] @@ -572,9 +579,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.11.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byte-slice-cast" @@ -602,15 +609,15 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "camino" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad0e1e3e88dd237a156ab9f571021b8a158caa0ae44b1968a241efb5144c1e" +checksum = "c77df041dc383319cc661b428b6961a005db4d6808d5e12536931b1ca9556055" dependencies = [ "serde", ] @@ -639,9 +646,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" dependencies = [ "jobserver", ] @@ -763,13 +770,13 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.30" +version = "4.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656ad1e55e23d287773f7d8192c300dc715c3eeded93b3da651d11c42cfd74d2" +checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" dependencies = [ "bitflags", - "clap_derive 4.0.21", - "clap_lex 0.3.0", + "clap_derive 4.1.0", + "clap_lex 0.3.1", "is-terminal", "once_cell", "strsim", @@ -778,11 +785,11 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.0.6" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b3c9eae0de7bf8e3f904a5e40612b21fb2e2e566456d177809a48b892d24da" +checksum = "3d6540eedc41f8a5a76cf3d8d458057dcdf817be4158a55b5f861f7a5483de75" dependencies = [ - "clap 4.0.30", + "clap 4.1.4", ] [[package]] @@ -791,7 +798,7 @@ version = "3.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" dependencies = [ - "heck 0.4.0", + "heck 0.4.1", "proc-macro-error", "proc-macro2", "quote", @@ -800,11 +807,11 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.0.21" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" dependencies = [ - "heck 0.4.0", + "heck 0.4.1", "proc-macro-error", "proc-macro2", "quote", @@ -822,9 +829,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade" dependencies = [ "os_str_bytes", ] @@ -854,9 +861,9 @@ dependencies = [ [[package]] name = "comfy-table" -version = "6.1.3" +version = "6.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e621e7e86c46fd8a14c32c6ae3cb95656621b4743a27d0cffedb831d46e7ad21" +checksum = "6e7b787b0dc42e8111badfdbe4c3059158ccb2db8780352fa1b01e8ccf45cc4d" dependencies = [ "strum", "strum_macros", @@ -878,6 +885,7 @@ dependencies = [ "pallet-balances", "pallet-certification", "pallet-collective", + "pallet-distance", "pallet-duniter-account", "pallet-duniter-wot", "pallet-grandpa", @@ -905,6 +913,7 @@ dependencies = [ "sp-arithmetic", "sp-consensus-babe", "sp-core", + "sp-distance", "sp-membership", "sp-runtime", "sp-staking", @@ -914,25 +923,24 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" +checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" dependencies = [ "crossbeam-utils", ] [[package]] name = "console" -version = "0.15.2" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c" +checksum = "c3d79fbe8970a77e3e34151cc13d3b3e248aa0faaecb9f6091fa07ebefe5ad60" dependencies = [ "encode_unicode", "lazy_static", "libc", - "terminal_size", "unicode-width", - "winapi 0.3.9", + "windows-sys 0.42.0", ] [[package]] @@ -1219,7 +1227,7 @@ version = "3.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1631ca6e3c59112501a9d87fd86f21591ff77acd31331e8a73f8d80a65bbdd71" dependencies = [ - "nix 0.26.1", + "nix 0.26.2", "windows-sys 0.42.0", ] @@ -1237,7 +1245,7 @@ dependencies = [ "cucumber-expressions", "derive_more", "either", - "futures 0.3.25", + "futures 0.3.26", "gherkin", "globwalk", "inventory", @@ -1305,9 +1313,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-pre.5" +version = "4.0.0-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67bc65846be335cb20f4e52d49a437b773a2c1fdb42b19fc84e79e6f6771536f" +checksum = "8da00a7a9a4eb92a0a0f8e75660926d48f0d0f3c537e455c457bcdaa1e16b1ac" dependencies = [ "cfg-if 1.0.0", "fiat-crypto", @@ -1319,9 +1327,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.85" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd" +checksum = "bc831ee6a32dd495436e317595e639a587aa9907bef96fe6e6abc290ab6204e9" dependencies = [ "cc", "cxxbridge-flags", @@ -1331,9 +1339,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.85" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0" +checksum = "94331d54f1b1a8895cd81049f7eaaaef9d05a7dcb4d1fd08bf3ff0806246789d" dependencies = [ "cc", "codespan-reporting", @@ -1346,15 +1354,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.85" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59" +checksum = "48dcd35ba14ca9b40d6e4b4b39961f23d835dbb8eed74565ded361d93e1feb8a" [[package]] name = "cxxbridge-macro" -version = "1.0.85" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6" +checksum = "81bbeb29798b407ccd82a3324ade1a7286e0d29851475990b612670f6f5124d2" dependencies = [ "proc-macro2", "quote", @@ -1422,6 +1430,23 @@ dependencies = [ "syn", ] +[[package]] +name = "dc-distance" +version = "1.0.0" +dependencies = [ + "frame-support", + "log", + "pallet-distance", + "parity-scale-codec", + "sc-client-api", + "scale-info", + "sp-core", + "sp-distance", + "sp-keystore", + "sp-runtime", + "thiserror", +] + [[package]] name = "der" version = "0.5.1" @@ -1529,6 +1554,20 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "distance-oracle" +version = "0.1.0" +dependencies = [ + "clap 4.1.4", + "parity-scale-codec", + "rayon", + "sp-core", + "sp-distance", + "sp-runtime", + "subxt", + "tokio", +] + [[package]] name = "dns-parser" version = "0.8.0" @@ -1562,13 +1601,15 @@ name = "duniter" version = "0.3.0" dependencies = [ "async-io", - "clap 4.0.30", + "clap 4.1.4", "clap_complete", "common-runtime", + "dc-distance", + "distance-oracle", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", - "futures 0.3.25", + "futures 0.3.26", "g1-runtime", "gdev-runtime", "gtest-runtime", @@ -1613,6 +1654,7 @@ dependencies = [ "sp-consensus", "sp-consensus-babe", "sp-core", + "sp-distance", "sp-finality-grandpa", "sp-inherents", "sp-io", @@ -1641,7 +1683,7 @@ dependencies = [ "clap 3.2.23", "ctrlc", "cucumber", - "env_logger", + "env_logger 0.9.3", "hex", "notify", "parity-scale-codec", @@ -1716,9 +1758,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ "signature", ] @@ -1753,9 +1795,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "elliptic-curve" @@ -1783,9 +1825,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "encoding_rs" -version = "0.8.31" +version = "0.8.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" dependencies = [ "cfg-if 1.0.0", ] @@ -1796,7 +1838,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" dependencies = [ - "heck 0.4.0", + "heck 0.4.1", "proc-macro2", "quote", "syn", @@ -1815,6 +1857,19 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "environmental" version = "1.1.4" @@ -1864,7 +1919,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e43f2f1833d64e33f15592464d6fdd70f349dda7b1a53088eb83cd94014008c5" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", ] [[package]] @@ -1937,11 +1992,11 @@ checksum = "a214f5bb88731d436478f3ae1f8a277b62124089ba9fb67f4f93fb100ef73c90" [[package]] name = "file-per-thread-logger" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e16290574b39ee41c71aeb90ae960c504ebaf1e2a1c87bd52aa56ed6e1a02f" +checksum = "84f2e425d9790201ba4af4630191feac6dcc98765b118d4d18e91d23c2353866" dependencies = [ - "env_logger", + "env_logger 0.10.0", "log", ] @@ -1959,12 +2014,12 @@ dependencies = [ [[package]] name = "finality-grandpa" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b22349c6a11563a202d95772a68e0fcf56119e74ea8a2a19cf2301460fcd0df5" +checksum = "e24e6c429951433ccb7c87fd528c60084834dcd14763182c1f83291bcde24c34" dependencies = [ "either", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "log", "num-traits", @@ -2086,7 +2141,7 @@ dependencies = [ "Inflector", "array-bytes", "chrono", - "clap 4.0.30", + "clap 4.1.4", "comfy-table", "frame-benchmarking", "frame-support", @@ -2349,9 +2404,9 @@ checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" [[package]] name = "futures" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" dependencies = [ "futures-channel", "futures-core", @@ -2364,9 +2419,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" dependencies = [ "futures-core", "futures-sink", @@ -2374,15 +2429,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" [[package]] name = "futures-executor" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" +checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" dependencies = [ "futures-core", "futures-task", @@ -2392,9 +2447,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" +checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" [[package]] name = "futures-lite" @@ -2413,9 +2468,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ "proc-macro2", "quote", @@ -2435,15 +2490,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" [[package]] name = "futures-task" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" [[package]] name = "futures-timer" @@ -2453,9 +2508,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ "futures 0.1.31", "futures-channel", @@ -2570,6 +2625,7 @@ dependencies = [ "pallet-balances", "pallet-certification", "pallet-collective", + "pallet-distance", "pallet-duniter-account", "pallet-duniter-test-parameters", "pallet-duniter-wot", @@ -2605,6 +2661,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-vrf", "sp-core", + "sp-distance", "sp-finality-grandpa", "sp-inherents", "sp-io", @@ -2734,15 +2791,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793" +checksum = "221996f774192f0f718773def8201c4ae31f02616a54ccfc2d358bb0e5cefdec" [[package]] name = "globset" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" dependencies = [ "aho-corasick", "bstr", @@ -2764,9 +2821,9 @@ dependencies = [ [[package]] name = "gloo-timers" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c4a8d6391675c6b2ee1a6c8d06e8e2d03605c44cec1270675985a4c2a5500b" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" dependencies = [ "futures-channel", "futures-core", @@ -2981,9 +3038,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" @@ -3099,9 +3156,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.23" +version = "0.14.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" +checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" dependencies = [ "bytes", "futures-channel", @@ -3220,7 +3277,7 @@ dependencies = [ "async-io", "core-foundation", "fnv", - "futures 0.3.25", + "futures 0.3.26", "if-addrs", "ipnet", "log", @@ -3231,11 +3288,10 @@ dependencies = [ [[package]] name = "ignore" -version = "0.4.18" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" +checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" dependencies = [ - "crossbeam-utils", "globset", "lazy_static", "log", @@ -3349,12 +3405,12 @@ checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" [[package]] name = "io-lifetimes" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" dependencies = [ "libc", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -3386,9 +3442,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.7.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" +checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "is-terminal" @@ -3397,8 +3453,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ "hermit-abi 0.2.6", - "io-lifetimes 1.0.3", - "rustix 0.36.5", + "io-lifetimes 1.0.5", + "rustix 0.36.7", "windows-sys 0.42.0", ] @@ -3428,9 +3484,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -3743,9 +3799,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.138" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libm" @@ -3766,7 +3822,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec878fda12ebec479186b3914ebc48ff180fa4c51847e11a1a68bf65249e02c1" dependencies = [ "bytes", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "getrandom 0.2.8", "instant", @@ -3804,7 +3860,7 @@ dependencies = [ "ed25519-dalek", "either", "fnv", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "instant", "lazy_static", @@ -3833,7 +3889,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2322c9fb40d99101def6a01612ee30500c89abbbecb6297b3cd252903a4c1720" dependencies = [ "async-std-resolver", - "futures 0.3.25", + "futures 0.3.26", "libp2p-core", "log", "parking_lot 0.12.1", @@ -3848,7 +3904,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf9a121f699e8719bda2e6e9e9b6ddafc6cff4602471d6481c1067930ccb29b" dependencies = [ "asynchronous-codec", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "libp2p-core", "libp2p-swarm", @@ -3873,7 +3929,7 @@ dependencies = [ "bytes", "either", "fnv", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "instant", "libp2p-core", @@ -3899,7 +3955,7 @@ dependencies = [ "async-io", "data-encoding", "dns-parser", - "futures 0.3.25", + "futures 0.3.26", "if-watch", "libp2p-core", "libp2p-swarm", @@ -3932,7 +3988,7 @@ checksum = "692664acfd98652de739a8acbb0a0d670f1d67190a49be6b4395e22c37337d89" dependencies = [ "asynchronous-codec", "bytes", - "futures 0.3.25", + "futures 0.3.26", "libp2p-core", "log", "nohash-hasher", @@ -3950,7 +4006,7 @@ checksum = "048155686bd81fe6cb5efdef0c6290f25ad32a0a42e8f4f72625cf6a505a206f" dependencies = [ "bytes", "curve25519-dalek 3.2.0", - "futures 0.3.25", + "futures 0.3.26", "lazy_static", "libp2p-core", "log", @@ -3970,7 +4026,7 @@ version = "0.40.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7228b9318d34689521349a86eb39a3c3a802c9efc99a0568062ffb80913e3f91" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "instant", "libp2p-core", @@ -3988,7 +4044,7 @@ checksum = "8827af16a017b65311a410bb626205a9ad92ec0473967618425039fa5231adc1" dependencies = [ "async-trait", "bytes", - "futures 0.3.25", + "futures 0.3.26", "instant", "libp2p-core", "libp2p-swarm", @@ -4006,7 +4062,7 @@ checksum = "46d13df7c37807965d82930c0e4b04a659efcb6cca237373b206043db5398ecf" dependencies = [ "either", "fnv", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "instant", "libp2p-core", @@ -4024,7 +4080,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0eddc4497a8b5a506013c40e8189864f9c3a00db2b25671f428ae9007f3ba32" dependencies = [ - "heck 0.4.0", + "heck 0.4.1", "quote", "syn", ] @@ -4036,7 +4092,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9839d96761491c6d3e238e70554b856956fca0ab60feb9de2cd08eed4473fa92" dependencies = [ "async-io", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "if-watch", "libc", @@ -4051,7 +4107,7 @@ version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a17b5b8e7a73e379e47b1b77f8a82c4721e97eca01abcd18e9cd91a23ca6ce97" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "js-sys", "libp2p-core", "parity-send-wrapper", @@ -4066,7 +4122,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3758ae6f89b2531a24b6d9f5776bda6a626b60a57600d7185d43dfa75ca5ecc4" dependencies = [ "either", - "futures 0.3.25", + "futures 0.3.26", "futures-rustls", "libp2p-core", "log", @@ -4084,7 +4140,7 @@ version = "0.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d6874d66543c4f7e26e3b8ca9a6bead351563a13ab4fafd43c7927f7c0d6c12" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "libp2p-core", "log", "parking_lot 0.12.1", @@ -4099,7 +4155,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" dependencies = [ "arrayref", - "base64", + "base64 0.13.1", "digest 0.9.0", "hmac-drbg", "libsecp256k1-core", @@ -4296,9 +4352,9 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "matrixmultiply" @@ -4321,7 +4377,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb" dependencies = [ - "rustix 0.36.5", + "rustix 0.36.7", ] [[package]] @@ -4531,9 +4587,9 @@ dependencies = [ [[package]] name = "multihash-derive" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" dependencies = [ "proc-macro-crate", "proc-macro-error", @@ -4556,7 +4612,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8552ab875c1313b97b8d20cb857b9fd63e2d1d6a0a1b53ce9821e575405f27a" dependencies = [ "bytes", - "futures 0.3.25", + "futures 0.3.26", "log", "pin-project", "smallvec", @@ -4658,9 +4714,9 @@ dependencies = [ [[package]] name = "netlink-packet-utils" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" +checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" dependencies = [ "anyhow", "byteorder", @@ -4675,7 +4731,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65b4b14489ab424703c092062176d52ba55485a89c076b4f9db05092b7223aa6" dependencies = [ "bytes", - "futures 0.3.25", + "futures 0.3.26", "log", "netlink-packet-core", "netlink-sys", @@ -4685,13 +4741,13 @@ dependencies = [ [[package]] name = "netlink-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92b654097027250401127914afb37cb1f311df6610a9891ff07a757e94199027" +checksum = "260e21fbb6f3d253a14df90eb0000a6066780a15dd901a7519ce02d77a94985b" dependencies = [ "async-io", "bytes", - "futures 0.3.25", + "futures 0.3.26", "libc", "log", ] @@ -4715,9 +4771,9 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a58d1d356c6597d08cde02c2f09d785b09e28711837b1ed667dc652c08a694" +checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ "bitflags", "cfg-if 1.0.0", @@ -4739,9 +4795,9 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "nom" -version = "7.1.1" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr", "minimal-lexical", @@ -4749,9 +4805,9 @@ dependencies = [ [[package]] name = "nom_locate" -version = "4.0.0" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37794436ca3029a3089e0b95d42da1f0b565ad271e4d3bb4bad0c7bb70b10605" +checksum = "b1e299bf5ea7b212e811e71174c5d1a5d065c4c0ad0c8691ecb1f97e3e66025e" dependencies = [ "bytecount", "memchr", @@ -4806,9 +4862,9 @@ dependencies = [ [[package]] name = "num-complex" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" dependencies = [ "num-traits", ] @@ -4879,18 +4935,18 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.5.7" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9" +checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b" dependencies = [ "num_enum_derive", ] [[package]] name = "num_enum_derive" -version = "0.5.7" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce" +checksum = "2be1598bf1c313dcdd12092e3f1920f463462525a21b7b4e11b4168353d0123e" dependencies = [ "proc-macro2", "quote", @@ -4911,20 +4967,20 @@ dependencies = [ [[package]] name = "object" -version = "0.30.0" +version = "0.30.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239da7f290cfa979f43f85a8efeee9a8a76d0827c356d37f9d3d7254d6b537fb" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" dependencies = [ - "parking_lot_core 0.9.5", + "parking_lot_core 0.9.7", ] [[package]] @@ -5141,6 +5197,27 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-distance" +version = "1.0.0" +dependencies = [ + "frame-support", + "frame-system", + "pallet-authority-members", + "pallet-authorship", + "pallet-certification", + "pallet-identity", + "pallet-membership", + "pallet-session", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-distance", + "sp-inherents", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-duniter-account" version = "3.0.0" @@ -5196,6 +5273,7 @@ dependencies = [ "frame-support", "frame-system", "pallet-certification", + "pallet-distance", "pallet-identity", "pallet-membership", "parity-scale-codec", @@ -5606,9 +5684,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.2.1" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "366e44391a8af4cfd6002ef6ba072bae071a96aafca98d7d448a34c5dca38b6a" +checksum = "c3840933452adf7b3b9145e27086a5a3376c619dca1a21b1e5a5af0d54979bed" dependencies = [ "arrayvec 0.7.2", "bitvec", @@ -5621,9 +5699,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.1.3" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9299338969a3d2f491d65f140b00ddec470858402f888af98e8642fb5e8965cd" +checksum = "86b26a931f824dd4eca30b3e43bb4f31cd5f0d3a403c5f5ff27106b805bfde7b" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5702,7 +5780,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.5", + "parking_lot_core 0.9.7", ] [[package]] @@ -5721,15 +5799,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.5" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -5791,9 +5869,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.1" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc8bed3549e0f9b0a2a78bf7c0018237a2cdf085eecbbc048e52612438e4e9d0" +checksum = "4ab62d2fa33726dbe6321cc97ef96d8cde531e3eeaf858a058de53a8a6d40d8f" dependencies = [ "thiserror", "ucd-trie", @@ -5801,9 +5879,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.1" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdc078600d06ff90d4ed238f0119d84ab5d43dbaad278b0e33a8820293b32344" +checksum = "8bf026e2d0581559db66d837fe5242320f525d85c76283c61f4d51a1238d65ea" dependencies = [ "pest", "pest_generator", @@ -5811,9 +5889,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.1" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28a1af60b1c4148bb269006a750cff8e2ea36aff34d2d96cf7be0b14d1bed23c" +checksum = "2b27bd18aa01d91c8ed2b61ea23406a676b42d82609c6e2581fba42f0c15f17f" dependencies = [ "pest", "pest_meta", @@ -5824,13 +5902,13 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.1" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fec8605d59fc2ae0c6c1aefc0c7c7a9769732017c0ce07f7a9cfffa7b4404f20" +checksum = "9f02b677c1859756359fc9983c2e56a0237f18624a3789528804406b7e915e5d" dependencies = [ "once_cell", "pest", - "sha1", + "sha2 0.10.6", ] [[package]] @@ -5974,9 +6052,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "predicates" -version = "2.1.4" +version = "2.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f54fc5dc63ed3bbf19494623db4f3af16842c0d975818e469022d09e53f0aa05" +checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" dependencies = [ "difflib", "float-cmp", @@ -6004,9 +6082,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8992a85d8e93a28bdf76137db888d3874e3b230dee5ed8bebac4c9f7617773" +checksum = "e97e3215779627f01ee256d2fad52f3d95e8e1c11e9fc6fd08f7cd455d5d5c78" dependencies = [ "proc-macro2", "syn", @@ -6027,11 +6105,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.2.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "once_cell", "thiserror", "toml", ] @@ -6062,9 +6139,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" dependencies = [ "unicode-ident", ] @@ -6108,9 +6185,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c01db6702aa05baa3f57dec92b8eeeeb4cb19e894e73996b32a4093289e54592" +checksum = "21dc42e00223fc37204bd4aa177e69420c604ca4a183209a8f9de30c6d934698" dependencies = [ "bytes", "prost-derive", @@ -6118,12 +6195,12 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb5320c680de74ba083512704acb90fe00f28f79207286a848e730c45dd73ed6" +checksum = "a3f8ad728fb08fe212df3c05169e940fbb6d9d16a877ddde14644a983ba2012e" dependencies = [ "bytes", - "heck 0.4.0", + "heck 0.4.1", "itertools", "lazy_static", "log", @@ -6153,9 +6230,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8842bad1a5419bca14eac663ba798f6bc19c413c2fdceb5f3ba3b0932d96720" +checksum = "8bda8c0881ea9f722eb9629376db3d0b903b462477c1aafcb0566610ac28ac5d" dependencies = [ "anyhow", "itertools", @@ -6166,9 +6243,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "017f79637768cde62820bc2d4fe0e45daaa027755c323ad077767c6c5f173091" +checksum = "a5e0526209433e96d83d750dd81a99118edbc55739e7e61a46764fd2ad537788" dependencies = [ "bytes", "prost", @@ -6323,9 +6400,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" dependencies = [ "either", "rayon-core", @@ -6333,9 +6410,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -6397,9 +6474,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", @@ -6426,7 +6503,7 @@ name = "remote-externalities" version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "env_logger", + "env_logger 0.9.3", "log", "parity-scale-codec", "serde", @@ -6449,11 +6526,11 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.13" +version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" +checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" dependencies = [ - "base64", + "base64 0.21.0", "bytes", "encoding_rs", "futures-core", @@ -6538,7 +6615,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "322c53fd76a18698f1c27381d58091de3a043d356aa5bd0d510608b565f469a0" dependencies = [ "async-global-executor", - "futures 0.3.25", + "futures 0.3.26", "log", "netlink-packet-route", "netlink-proto", @@ -6608,13 +6685,13 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.5" +version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588" +checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" dependencies = [ "bitflags", "errno", - "io-lifetimes 1.0.3", + "io-lifetimes 1.0.5", "libc", "linux-raw-sys 0.1.4", "windows-sys 0.42.0", @@ -6622,9 +6699,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.7" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" dependencies = [ "log", "ring", @@ -6646,11 +6723,11 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" dependencies = [ - "base64", + "base64 0.21.0", ] [[package]] @@ -6677,7 +6754,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26338f5e09bb721b85b135ea05af7767c90b52f6de4f087d4f4a3a9d64e7dc04" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "pin-project", "static_assertions", ] @@ -6713,7 +6790,7 @@ name = "sc-basic-authorship" version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "log", "parity-scale-codec", @@ -6782,9 +6859,9 @@ source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9 dependencies = [ "array-bytes", "chrono", - "clap 4.0.30", + "clap 4.1.4", "fdlimit", - "futures 0.3.25", + "futures 0.3.26", "libp2p", "log", "names", @@ -6821,7 +6898,7 @@ version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "fnv", - "futures 0.3.25", + "futures 0.3.26", "hash-db", "log", "parity-scale-codec", @@ -6873,7 +6950,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "async-trait", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "libp2p", "log", @@ -6897,7 +6974,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "async-trait", - "futures 0.3.25", + "futures 0.3.26", "log", "parity-scale-codec", "sc-block-builder", @@ -6927,7 +7004,7 @@ source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9 dependencies = [ "async-trait", "fork-tree", - "futures 0.3.25", + "futures 0.3.26", "log", "merlin", "num-bigint 0.2.6", @@ -6982,7 +7059,7 @@ source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9 dependencies = [ "assert_matches", "async-trait", - "futures 0.3.25", + "futures 0.3.26", "jsonrpsee 0.15.1", "log", "parity-scale-codec", @@ -7015,7 +7092,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "async-trait", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "log", "parity-scale-codec", @@ -7133,7 +7210,7 @@ dependencies = [ "dyn-clone", "finality-grandpa", "fork-tree", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "log", "parity-scale-codec", @@ -7169,7 +7246,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "ansi_term", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "log", "parity-util-mem", @@ -7209,7 +7286,7 @@ dependencies = [ "either", "fnv", "fork-tree", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "ip_network", "libp2p", @@ -7248,7 +7325,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "cid", - "futures 0.3.25", + "futures 0.3.26", "libp2p", "log", "prost", @@ -7270,7 +7347,7 @@ dependencies = [ "async-trait", "bitflags", "bytes", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "libp2p", "linked_hash_set", @@ -7294,7 +7371,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "ahash", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "libp2p", "log", @@ -7312,7 +7389,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "array-bytes", - "futures 0.3.25", + "futures 0.3.26", "libp2p", "log", "parity-scale-codec", @@ -7334,7 +7411,7 @@ source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9 dependencies = [ "array-bytes", "fork-tree", - "futures 0.3.25", + "futures 0.3.26", "libp2p", "log", "lru 0.7.8", @@ -7363,7 +7440,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "array-bytes", - "futures 0.3.25", + "futures 0.3.26", "hex", "libp2p", "log", @@ -7384,7 +7461,7 @@ dependencies = [ "array-bytes", "bytes", "fnv", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "hyper", "hyper-rustls", @@ -7411,7 +7488,7 @@ name = "sc-peerset" version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "libp2p", "log", "sc-utils", @@ -7433,7 +7510,7 @@ name = "sc-rpc" version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "hash-db", "jsonrpsee 0.15.1", "log", @@ -7463,7 +7540,7 @@ name = "sc-rpc-api" version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "jsonrpsee 0.15.1", "log", "parity-scale-codec", @@ -7486,7 +7563,7 @@ name = "sc-rpc-server" version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "jsonrpsee 0.15.1", "log", "serde_json", @@ -7499,7 +7576,7 @@ name = "sc-rpc-spec-v2" version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "hex", "jsonrpsee 0.15.1", "parity-scale-codec", @@ -7521,7 +7598,7 @@ dependencies = [ "async-trait", "directories", "exit-future", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "hash-db", "jsonrpsee 0.15.1", @@ -7603,7 +7680,7 @@ name = "sc-sysinfo" version = "6.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "libc", "log", "rand 0.7.3", @@ -7623,7 +7700,7 @@ version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "chrono", - "futures 0.3.25", + "futures 0.3.26", "libp2p", "log", "parking_lot 0.12.1", @@ -7683,7 +7760,7 @@ version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "async-trait", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "linked-hash-map", "log", @@ -7710,7 +7787,7 @@ version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "async-trait", - "futures 0.3.25", + "futures 0.3.26", "log", "serde", "sp-blockchain", @@ -7723,7 +7800,7 @@ name = "sc-utils" version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "lazy_static", "log", @@ -7799,12 +7876,11 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ - "lazy_static", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] @@ -7886,9 +7962,9 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9512ffd81e3a3503ed401f79c33168b9148c75038956039166cd750eaa037c3" +checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" dependencies = [ "secp256k1-sys", ] @@ -7913,9 +7989,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.7.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ "bitflags", "core-foundation", @@ -7926,9 +8002,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" dependencies = [ "core-foundation-sys", "libc", @@ -7960,18 +8036,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.151" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.151" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", @@ -8023,17 +8099,6 @@ dependencies = [ "opaque-debug 0.3.0", ] -[[package]] -name = "sha1" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" -dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.10.6", -] - [[package]] name = "sha2" version = "0.8.2" @@ -8159,14 +8224,14 @@ checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" [[package]] name = "snow" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "774d05a3edae07ce6d68ea6984f3c05e9bba8927e3dd591e3b479e5b03213d0d" +checksum = "12ba5f4d4ff12bdb6a169ed51b7c48c0e0ac4b0b4b31012b2571e97d78d3201d" dependencies = [ "aes-gcm", "blake2", "chacha20poly1305", - "curve25519-dalek 4.0.0-pre.5", + "curve25519-dalek 4.0.0-rc.0", "rand_core 0.6.4", "ring", "rustc_version", @@ -8190,10 +8255,10 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" dependencies = [ - "base64", + "base64 0.13.1", "bytes", "flate2", - "futures 0.3.25", + "futures 0.3.26", "httparse", "log", "rand 0.8.5", @@ -8300,7 +8365,7 @@ name = "sp-blockchain" version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "log", "lru 0.7.8", "parity-scale-codec", @@ -8319,7 +8384,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "async-trait", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "log", "parity-scale-codec", @@ -8412,7 +8477,7 @@ dependencies = [ "byteorder", "dyn-clonable", "ed25519-zebra", - "futures 0.3.25", + "futures 0.3.26", "hash-db", "hash256-std-hasher", "impl-serde", @@ -8490,6 +8555,21 @@ dependencies = [ "syn", ] +[[package]] +name = "sp-distance" +version = "3.0.0" +dependencies = [ + "async-trait", + "frame-support", + "parity-scale-codec", + "scale-info", + "serde", + "sp-inherents", + "sp-runtime", + "sp-std", + "thiserror", +] + [[package]] name = "sp-externalities" version = "0.12.0" @@ -8539,7 +8619,7 @@ version = "6.0.0" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "bytes", - "futures 0.3.25", + "futures 0.3.26", "hash-db", "libsecp256k1", "log", @@ -8576,7 +8656,7 @@ version = "0.12.0" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "async-trait", - "futures 0.3.25", + "futures 0.3.26", "merlin", "parity-scale-codec", "parking_lot 0.12.1", @@ -8934,9 +9014,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.36.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d92659e7d18d82b803824a9ba5a6022cff101c3491d027c1c1d8d30e749284" +checksum = "e40c020d72bc0a9c5660bb71e4a6fdef081493583062c474740a7d59f55f0e7b" dependencies = [ "Inflector", "num-format", @@ -9021,7 +9101,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ - "heck 0.4.0", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -9055,7 +9135,7 @@ version = "4.0.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ "frame-system-rpc-runtime-api", - "futures 0.3.25", + "futures 0.3.26", "jsonrpsee 0.15.1", "log", "parity-scale-codec", @@ -9127,7 +9207,7 @@ dependencies = [ "bitvec", "derivative", "frame-metadata", - "futures 0.3.25", + "futures 0.3.26", "getrandom 0.2.8", "hex", "jsonrpsee 0.16.2", @@ -9153,7 +9233,7 @@ source = "git+https://github.com/duniter/subxt.git?branch=duniter-substrate-v0.9 dependencies = [ "darling", "frame-metadata", - "heck 0.4.0", + "heck 0.4.1", "hex", "jsonrpsee 0.16.2", "parity-scale-codec", @@ -9293,9 +9373,9 @@ dependencies = [ [[package]] name = "tera" -version = "1.17.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d4685e72cb35f0eb74319c8fe2d3b61e93da5609841cde2cb87fcc3bea56d20" +checksum = "3df578c295f9ec044ff1c829daf31bb7581d5b3c2a7a3d87419afe1f2531438c" dependencies = [ "globwalk", "lazy_static", @@ -9309,23 +9389,13 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" -dependencies = [ - "libc", - "winapi 0.3.9", -] - [[package]] name = "termtree" version = "0.4.0" @@ -9432,15 +9502,15 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.23.0" +version = "1.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" +checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" dependencies = [ "autocfg", "bytes", @@ -9453,7 +9523,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -9516,9 +9586,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.10" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] @@ -9683,16 +9753,16 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.32#7f8b8db65b441ce1d1b2ffb26ebde314b54e117c" dependencies = [ - "clap 4.0.30", + "clap 4.1.4", "frame-try-runtime", "log", "parity-scale-codec", @@ -9726,7 +9796,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "digest 0.10.6", "rand 0.8.5", "static_assertions", @@ -9828,9 +9898,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" [[package]] name = "unicode-ident" @@ -9849,9 +9919,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" @@ -10010,9 +10080,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -10020,9 +10090,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", @@ -10035,9 +10105,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.33" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -10047,9 +10117,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -10057,9 +10127,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", @@ -10070,9 +10140,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "wasm-gc-api" @@ -10100,7 +10170,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "js-sys", "parking_lot 0.11.2", "pin-utils", @@ -10195,7 +10265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcd849399d17d2270141cfe47fa0d91ee52d5f8ea9b98cf7ddde0d53e5f79882" dependencies = [ "anyhow", - "base64", + "base64 0.13.1", "bincode", "directories-next", "file-per-thread-logger", @@ -10323,9 +10393,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" dependencies = [ "js-sys", "wasm-bindgen", @@ -10361,9 +10431,9 @@ dependencies = [ [[package]] name = "which" -version = "4.3.0" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" dependencies = [ "either", "libc", @@ -10452,19 +10522,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_x86_64_msvc 0.42.1", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.1", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" @@ -10480,9 +10574,9 @@ checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" @@ -10498,9 +10592,9 @@ checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" @@ -10516,9 +10610,9 @@ checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] name = "windows_i686_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" @@ -10534,15 +10628,15 @@ checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" @@ -10558,9 +10652,9 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "windows_x86_64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "winreg" @@ -10606,7 +10700,7 @@ name = "xtask" version = "0.1.0" dependencies = [ "anyhow", - "clap 4.0.30", + "clap 4.1.4", "frame-metadata", "graphql_client", "hex", @@ -10630,7 +10724,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d9ba232399af1783a58d8eb26f6b5006fbefe2dc9ef36bd283324792d03ea5" dependencies = [ - "futures 0.3.25", + "futures 0.3.26", "log", "nohash-hasher", "parking_lot 0.12.1", @@ -10686,10 +10780,11 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.4+zstd.1.5.2" +version = "2.0.6+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" +checksum = "68a3f9792c0c3dc6c165840a75f47ae1f4da402c2d006881129579f6597e801b" dependencies = [ "cc", "libc", + "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index 0896f98b8..16f852337 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,10 +32,10 @@ runtime-benchmarks = [ 'sc-client-db/runtime-benchmarks', ] try-runtime = [ - #"g1-runtime/try-runtime", - "gdev-runtime/try-runtime", - #"gtest-runtime/try-runtime", - "try-runtime-cli" + #"g1-runtime/try-runtime", + "gdev-runtime/try-runtime", + #"gtest-runtime/try-runtime", + "try-runtime-cli", ] [build-dependencies] @@ -48,19 +48,28 @@ rusty-hook = "^0.11.2" # Dependencies for specific targets [target.'cfg(any(target_arch="x86_64", target_arch="aarch64"))'.dependencies] -sc-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32", default-features = false, features = ["wasmtime"] } -sc-service = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32", default-features = false, features = ["wasmtime"] } -sp-trie = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32", features = ["memory-tracker"] } +sc-cli = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32", default-features = false, features = [ + "wasmtime", +] } +sc-service = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32", default-features = false, features = [ + "wasmtime", +] } +sp-trie = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32", features = [ + "memory-tracker", +] } [dependencies] # local dependencies common-runtime = { path = 'runtime/common' } +dc-distance = { path = 'client/distance' } +distance-oracle = { path = 'distance-oracle', optional = true } g1-runtime = { path = 'runtime/g1', optional = true } gdev-runtime = { path = 'runtime/gdev', optional = true } gtest-runtime = { path = 'runtime/gtest', optional = true } pallet-certification = { path = 'pallets/certification' } pallet-oneshot-account = { path = 'pallets/oneshot-account' } +sp-distance = { path = 'primitives/distance' } sp-membership = { path = 'primitives/membership' } # crates.io dependencies @@ -131,9 +140,12 @@ try-runtime-cli = { git = "https://github.com/duniter/substrate", branch = "duni resolver = "2" members = [ + 'client/distance', + 'distance-oracle', 'end2end-tests', 'live-tests', 'pallets/certification', + 'pallets/distance', 'pallets/duniter-test-parameters', 'pallets/duniter-test-parameters/macro', 'pallets/duniter-wot', @@ -144,6 +156,7 @@ members = [ 'pallets/universal-dividend', 'pallets/upgrade-origin', 'primitives/membership', + 'primitives/distance', 'runtime/common', 'runtime/gdev', 'xtask', diff --git a/client/distance/Cargo.toml b/client/distance/Cargo.toml new file mode 100644 index 000000000..27f16c31e --- /dev/null +++ b/client/distance/Cargo.toml @@ -0,0 +1,51 @@ +[package] +authors = ['tuxmain <tuxmain@zettascript.org>'] +description = 'Duniter client distance' +edition = '2021' +homepage = 'https://duniter.org' +license = 'AGPL-3.0' +name = 'dc-distance' +readme = 'README.md' +repository = 'https://git.duniter.org/nodes/rust/duniter-v2s' +version = '1.0.0' + +[dependencies] + +pallet-distance = { path = "../../pallets/distance" } +sp-distance = { path = "../../primitives/distance" } + +log = "0.4" +thiserror = "1.0.30" + +# substrate +scale-info = { version = "2.1.1", features = ["derive"] } + +[dependencies.codec] +features = ['derive'] +package = 'parity-scale-codec' +version = '3.1.5' + +[dependencies.frame-support] +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sc-client-api] +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-core] +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-keystore] +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-runtime] +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +### DOC ### + +[package.metadata.docs.rs] +targets = ['x86_64-unknown-linux-gnu'] diff --git a/client/distance/src/lib.rs b/client/distance/src/lib.rs new file mode 100644 index 000000000..87a973c7c --- /dev/null +++ b/client/distance/src/lib.rs @@ -0,0 +1,112 @@ +// Copyright 2022 Axiom-Team +// +// This file is part of Substrate-Libre-Currency. +// +// Substrate-Libre-Currency is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Substrate-Libre-Currency 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. + +use codec::{Decode, Encode}; +use frame_support::pallet_prelude::*; +use sc_client_api::{ProvideUncles, StorageKey, StorageProvider}; +use scale_info::TypeInfo; +use sp_runtime::{generic::BlockId, traits::Block as BlockT, AccountId32}; +use std::path::PathBuf; + +type IdtyIndex = u32; + +#[derive(Debug, thiserror::Error)] +pub enum Error<B: BlockT> { + #[error("Could not retrieve the block hash for block id: {0:?}")] + NoHashForBlockId(BlockId<B>), +} + +/// Create a new [`sp_distance::InherentDataProvider`] at the given block. +pub fn create_distance_inherent_data_provider<B, C, Backend>( + client: &C, + parent: B::Hash, + distance_dir: PathBuf, + owner_keys: &[sp_core::sr25519::Public], +) -> Result<sp_distance::InherentDataProvider<IdtyIndex>, sc_client_api::blockchain::Error> +where + B: BlockT, + C: ProvideUncles<B> + StorageProvider<B, Backend>, + Backend: sc_client_api::Backend<B>, + IdtyIndex: Decode + Encode + PartialEq + TypeInfo, +{ + let &[owner_key] = owner_keys else { + return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new( + None + )) + }; + let owner_key = sp_runtime::AccountId32::new(owner_key.0); + + let session_index = client + .storage( + &parent, + &StorageKey( + frame_support::storage::storage_prefix(b"Session", b"CurrentIndex").to_vec(), + ), + ) + .expect("CurrentIndex is Err") + .map_or(0, |raw| { + u32::decode(&mut &raw.0[..]).expect("cannot decode CurrentIndex") + }); + + let published_results = client + .storage( + &parent, + &StorageKey( + frame_support::storage::storage_prefix( + b"Distance", + match session_index % 3 { + 0 => b"StoragePublishedResults1", + 1 => b"StoragePublishedResults2", + 2 => b"StoragePublishedResults0", + _ => unreachable!("n%3<3"), + }, + ) + .to_vec(), + ), + )? + .map_or_else(Default::default, |raw| { + pallet_distance::EvaluationPool::< + AccountId32, + IdtyIndex, + ConstU32<100>, + ConstU32<100>, + >::decode(&mut &raw.0[..]) + .expect("cannot decode EvaluationPool") + }); + + // Have we already published a result for this session? + if published_results.1.contains(&owner_key) { + return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None)); + } + + // Read evaluation result from file, if it exists + let evaluation_result = match std::fs::read(distance_dir.join(session_index.to_string())) { + Ok(data) => data, + Err(e) => { + match e.kind() { + std::io::ErrorKind::NotFound => {} + _ => { + log::error!("Cannot read distance evaluation result file: {e:?}"); + } + } + return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(None)); + } + }; + + Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new(Some( + sp_distance::ComputationResult::decode(&mut evaluation_result.as_slice()).unwrap(), + ))) +} diff --git a/distance-oracle/Cargo.toml b/distance-oracle/Cargo.toml new file mode 100644 index 000000000..8869a5fc6 --- /dev/null +++ b/distance-oracle/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "distance-oracle" +version = "0.1.0" +authors = ["tuxmain <tuxmain@zettascript.org>"] +repository = "https://git.duniter.org/nodes/rust/duniter-v2s" +license = "AGPL-3.0-only" +edition = "2021" + +[dependencies] +sp-distance = { path = "../primitives/distance" } + +codec = { package = "parity-scale-codec", version = "3.1.5" } +rayon = "1.7.0" +sp-core = { git = "https://github.com/duniter/substrate.git", branch = "duniter-substrate-v0.9.32" } +sp-runtime = { git = "https://github.com/duniter/substrate.git", branch = "duniter-substrate-v0.9.32" } +subxt = { git = 'https://github.com/duniter/subxt.git', branch = "duniter-substrate-v0.9.32" } + +# standalone only +clap = { version = "4.0", features = ["derive"], optional = true } +tokio = { version = "1.15.0", features = [ + "rt-multi-thread", + "macros", +], optional = true } + +[features] +default = ["standalone"] +standalone = ["clap", "tokio"] + +[[bin]] +name = "distance-oracle" +required-features = ["standalone"] diff --git a/distance-oracle/src/lib.rs b/distance-oracle/src/lib.rs new file mode 100644 index 000000000..1f503b7b2 --- /dev/null +++ b/distance-oracle/src/lib.rs @@ -0,0 +1,279 @@ +use codec::Encode; +use rayon::iter::{IntoParallelIterator, ParallelIterator}; +use std::collections::{HashMap, HashSet}; +use std::io::Write; +use std::path::PathBuf; +use subxt::ext::sp_runtime::Perbill; +use subxt::storage::StorageKey; + +pub struct Settings { + pub evaluation_result_dir: PathBuf, + pub min_certs_for_referee: u32, + pub rpc_url: String, +} + +impl Default for Settings { + fn default() -> Self { + Self { + evaluation_result_dir: PathBuf::from("/tmp/duniter/chains/gdev/distance"), + min_certs_for_referee: 2, + rpc_url: String::from("ws://127.0.0.1:9944"), + } + } +} + +#[subxt::subxt(runtime_metadata_path = "../resources/metadata.scale")] +pub mod gdev {} + +pub type Client = subxt::OnlineClient<GdevConfig>; + +pub enum GdevConfig {} +impl subxt::config::Config for GdevConfig { + type Index = u32; + type BlockNumber = u32; + type Hash = sp_core::H256; + type Hashing = subxt::ext::sp_runtime::traits::BlakeTwo256; + type AccountId = subxt::ext::sp_runtime::AccountId32; + type Address = subxt::ext::sp_runtime::MultiAddress<Self::AccountId, u32>; + type Header = subxt::ext::sp_runtime::generic::Header< + Self::BlockNumber, + subxt::ext::sp_runtime::traits::BlakeTwo256, + >; + type Signature = subxt::ext::sp_runtime::MultiSignature; + type ExtrinsicParams = subxt::tx::BaseExtrinsicParams<Self, Tip>; +} + +#[derive(Copy, Clone, Debug, Default, Encode)] +pub struct Tip { + #[codec(compact)] + tip: u64, +} + +impl Tip { + pub fn new(amount: u64) -> Self { + Tip { tip: amount } + } +} + +impl From<u64> for Tip { + fn from(n: u64) -> Self { + Self::new(n) + } +} + +type IdtyIndex = u32; + +pub async fn run(settings: Settings) { + let client = Client::from_url(settings.rpc_url).await.unwrap(); + + let parent_hash = client + .storage() + .fetch(&gdev::storage().system().parent_hash(), None) + .await + .unwrap() + .unwrap(); + + let current_session = client + .storage() + .fetch( + &gdev::storage().session().current_index(), + Some(parent_hash), + ) + .await + .unwrap() + .unwrap_or_default(); + + // Fetch the pending identities + let Some(evaluation_pool) = client + .storage() + .fetch( + &match current_session % 3 { + 0 => gdev::storage().distance().evaluation_pool1(), + 1 => gdev::storage().distance().evaluation_pool2(), + 2 => gdev::storage().distance().evaluation_pool0(), + _ => unreachable!("n%3<3"), + }, + Some(parent_hash), + ) + .await + .unwrap() else { + println!("Pool does not exist"); + return + }; + + // Stop if nothing to evaluate + if evaluation_pool.0 .0.is_empty() { + println!("Pool is empty"); + return; + } + + let evaluation_result_path = settings + .evaluation_result_dir + .join((current_session + 1).to_string()); + + // Stop if already evaluated + if evaluation_result_path.try_exists().unwrap() { + println!("File already exists"); + return; + } + + let evaluation_block = client + .storage() + .fetch( + &gdev::storage().distance().evaluation_block(), + Some(parent_hash), + ) + .await + .unwrap() + .unwrap(); + + std::fs::create_dir_all(&settings.evaluation_result_dir).unwrap(); + + // member idty -> issued certs + let mut members = HashMap::<IdtyIndex, u32>::new(); + + let mut members_iter = client + .storage() + .iter( + gdev::storage().membership().membership(0), + 100, + Some(evaluation_block), + ) + .await + .unwrap(); + while let Some((member_idty, _membership_expire)) = members_iter.next().await.unwrap() { + members.insert(idty_id_from_storage_key(&member_idty), 0); + } + + // idty -> received certs + let mut received_certs = HashMap::<IdtyIndex, Vec<IdtyIndex>>::new(); + + let mut certs_iter = client + .storage() + .iter( + gdev::storage().cert().certs_by_receiver(0), + 100, + Some(evaluation_block), + ) + .await + .unwrap(); + while let Some((receiver, issuers)) = certs_iter.next().await.unwrap() { + let receiver = idty_id_from_storage_key(&receiver); + // Update members' issued certs count + if issuers.len() as u32 >= settings.min_certs_for_referee { + for (issuer, _removable_on) in issuers.iter() { + if let Some(issued_certs) = members.get_mut(issuer) { + *issued_certs += 1; + } + } + } else { + // This member is not referee + members.remove(&receiver); + } + received_certs.insert( + receiver, + issuers + .into_iter() + .map(|(issuer, _removable_on)| issuer) + .collect(), + ); + } + + // Only retain referees + // TODO benchmark: can it be faster? (maybe using drain_filter) + members.retain(|_idty, issued_certs| *issued_certs >= settings.min_certs_for_referee); + let referees = members; + + let evaluation: Vec<Perbill> = evaluation_pool + .0 + .0 + .into_par_iter() + .map(|(idty, _)| { + Perbill::from_rational( + distance_rule( + &received_certs, + &referees, + settings.min_certs_for_referee, + idty, + ), + referees.len() as u32, + ) + }) + .collect(); + + let mut evaluation_result_file = std::fs::OpenOptions::new() + .write(true) + .create_new(true) + .open(evaluation_result_path) + .unwrap(); + evaluation_result_file + .write_all( + &sp_distance::ComputationResult { + distances: evaluation, + } + .encode(), + ) + .unwrap(); + + // Remove old results + let mut files_to_remove = Vec::new(); + for entry in settings.evaluation_result_dir.read_dir().unwrap().flatten() { + if let Ok(entry_name) = entry.file_name().into_string() { + if let Ok(entry_session) = entry_name.parse::<isize>() { + if current_session as isize - entry_session > 3 { + files_to_remove.push(entry.path()); + } + } + } + } + files_to_remove.into_iter().for_each(|f| { + std::fs::remove_file(&f).unwrap_or_else(move |e| { + eprintln!("Warning: Cannot remove old result file `{f:?}`: {e:?}") + }); + }); +} + +fn distance_rule_recursive( + received_certs: &HashMap<IdtyIndex, Vec<IdtyIndex>>, + referees: &HashMap<IdtyIndex, u32>, + idty: IdtyIndex, + accessible_referees: &mut std::collections::HashSet<IdtyIndex>, + depth: u32, +) { + if referees.contains_key(&idty) { + accessible_referees.insert(idty); + } + if depth == 0 { + return; + } + for &certifier in received_certs.get(&idty).expect("unreachable").iter() { + distance_rule_recursive( + received_certs, + referees, + certifier, + accessible_referees, + depth - 1, + ); + } +} + +fn distance_rule( + received_certs: &HashMap<IdtyIndex, Vec<IdtyIndex>>, + referees: &HashMap<IdtyIndex, u32>, + depth: u32, + idty: IdtyIndex, +) -> u32 { + let mut accessible_referees = HashSet::<u32>::new(); + distance_rule_recursive( + received_certs, + referees, + idty, + &mut accessible_referees, + depth + 1, + ); + accessible_referees.len() as u32 +} + +fn idty_id_from_storage_key(storage_key: &StorageKey) -> IdtyIndex { + u32::from_le_bytes(storage_key.as_ref()[40..44].try_into().unwrap()) +} diff --git a/distance-oracle/src/main.rs b/distance-oracle/src/main.rs new file mode 100644 index 000000000..7d6e222b1 --- /dev/null +++ b/distance-oracle/src/main.rs @@ -0,0 +1,23 @@ +use clap::Parser; + +#[derive(Debug, clap::Parser)] +struct Cli { + #[clap(short = 'd', long, default_value = "/tmp/duniter/chains/gdev/distance")] + evaluation_result_dir: String, + #[clap(short = 'c', long, default_value = "2")] + min_certs_for_referee: u32, + #[clap(short = 'u', long, default_value = "ws://127.0.0.1:9944")] + rpc_url: String, +} + +#[tokio::main] +async fn main() { + let cli = Cli::parse(); + + distance_oracle::run(distance_oracle::Settings { + evaluation_result_dir: cli.evaluation_result_dir.into(), + min_certs_for_referee: cli.min_certs_for_referee, + rpc_url: cli.rpc_url, + }) + .await; +} diff --git a/docs/api/manual.md b/docs/api/manual.md index 6ef23fce5..0b9a91eb7 100644 --- a/docs/api/manual.md +++ b/docs/api/manual.md @@ -20,6 +20,9 @@ Only use `identity` pallet. The `membership` calls are disabled. 1. The account that wants to gain membership needs to exists. 1. Any account that already has membership and respects the identity creation period can create an identity for another account, using `identity.createIdentity`. 1. The account has to confirm its identity with a name, using `identity.confirmIdentity`. The name must be ASCII alphanumeric, punctuation or space characters: ``/^[-!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~a-zA-Z0-9 ]{3,64}$/`` (additionally, trailing spaces and double spaces are forbidden, as a phishing countermeasure). If the name is already used, the call will fail. +1. 4 different member accounts must certify the account using `cert.addCert`. +1. The distance evaluation must be requested for the pending identity using `distance.evaluateDistance`. +1. 3 sessions later, if the distance rule is respected, `identity.validateIdentity` can be called. ## Change key diff --git a/docs/user/distance.md b/docs/user/distance.md new file mode 100644 index 000000000..9685d2e46 --- /dev/null +++ b/docs/user/distance.md @@ -0,0 +1,27 @@ +# Distance rule evaluation + +The [distance rule](https://duniter.org/blog/duniter-deep-dive-wot/) is computationally too heavy to be handled by the runtime. Therefore it is computed offchain using the distance oracle. + +Distance evaluation is operated on a voluntary basis by individual smiths. Since evaluators can lie or make errors, the result considered for applying the distance rule is the median of results published by the different evaluators. + +## Running distance evaluation + +Any smith member authoring blocks can run a distance evaluation oracle. It is better to have a machine more powerful than the reference machine. + +The simplest way is to run the oracle on the same machine as Duniter. + +Build the oracle: + + cargo build --release -p distance-oracle + +It will be available at `./target/release/distance-oracle`. Move it to somewhere appropriate. + +Add this line to your cron with the command `crontab -e`: (add option `-u <user>` to edit another user's cron) + + 4,24,44 * * * * /absolute/path/to/distance-oracle + +The precise hours don't matter so you can pick random values, but it should run at least one time per hour, and running it more often decreases the risk of problem in case of missing blocks or temporary network failure. + +If the evaluation ran successfully in a session, the next runs in the same session won't re-evaluate the same data. + +No additional configuration is needed for Duniter. diff --git a/node/src/service.rs b/node/src/service.rs index 6562b6584..747a56b1e 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -31,7 +31,7 @@ use sc_service::{error::Error as ServiceError, Configuration, PartialComponents, use sc_telemetry::{Telemetry, TelemetryWorker}; use sp_core::H256; use sp_runtime::traits::BlakeTwo256; -use std::{sync::Arc, time::Duration}; +use std::{path::PathBuf, sync::Arc, time::Duration}; type FullClient<RuntimeApi, Executor> = sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>; @@ -309,7 +309,7 @@ where Some(Box::new(justification_import)), client.clone(), select_chain.clone(), - move |_, ()| async move { + move |_parent, ()| async move { let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); let slot = @@ -431,6 +431,15 @@ where let mut command_sink_opt = None; if role.is_authority() { + let distance_dir = config.base_path.as_ref().map_or_else( + || PathBuf::from("/tmp/duniter-distance"), + |base_path| { + base_path + .config_dir(config.chain_spec.id()) + .join("distance") + }, + ); + let proposer_factory = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), client.clone(), @@ -439,6 +448,9 @@ where telemetry.as_ref().map(|x| x.handle()), ); + let sync_cryptostore_ptr = keystore_container.sync_keystore(); + let client = client.clone(); + if sealing.is_manual_consensus() { let commands_stream: Box<dyn Stream<Item = EngineCommand<H256>> + Send + Sync + Unpin> = match sealing { @@ -489,7 +501,6 @@ where ) .expect("failed to create BabeConsensusDataProvider"); - let client_clone = client.clone(); task_manager.spawn_essential_handle().spawn_blocking( "manual-seal", Some("block-authoring"), @@ -501,8 +512,14 @@ where commands_stream, select_chain, consensus_data_provider: Some(Box::new(babe_consensus_data_provider)), - create_inherent_data_providers: move |_, _| { - let client = client_clone.clone(); + create_inherent_data_providers: move |parent, _| { + let client = client.clone(); + let distance_dir = distance_dir.clone(); + let babe_owner_keys = + std::sync::Arc::new(sp_keystore::SyncCryptoStore::sr25519_public_keys( + sync_cryptostore_ptr.as_ref(), + sp_runtime::KeyTypeId(*b"babe"), + )); async move { let timestamp = manual_seal::consensus::timestamp::SlotTimestampProvider::new_babe( @@ -512,13 +529,20 @@ where let babe = sp_consensus_babe::inherents::InherentDataProvider::new( timestamp.slot(), ); - Ok((timestamp, babe)) + let distance = + dc_distance::create_distance_inherent_data_provider::< + Block, + FullClient<RuntimeApi, Executor>, + FullBackend, + >( + &*client, parent, distance_dir, &babe_owner_keys.clone() + )?; + Ok((timestamp, babe, distance)) } }, }), ); } else { - let client_clone = client.clone(); let slot_duration = babe_link.config().slot_duration(); let babe_config = babe::BabeParams { keystore: keystore_container.sync_keystore(), @@ -529,12 +553,19 @@ where sync_oracle: network.clone(), justification_sync_link: network.clone(), create_inherent_data_providers: move |parent, ()| { - let client_clone = client_clone.clone(); + // This closure is called during each block generation. + + let client = client.clone(); + let distance_dir = distance_dir.clone(); + let babe_owner_keys = + std::sync::Arc::new(sp_keystore::SyncCryptoStore::sr25519_public_keys( + sync_cryptostore_ptr.as_ref(), + sp_runtime::KeyTypeId(*b"babe"), + )); async move { let uncles = sc_consensus_uncles::create_uncles_inherent_data_provider( - &*client_clone, - parent, + &*client, parent, )?; let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); @@ -545,7 +576,15 @@ where slot_duration, ); - Ok((slot, timestamp, uncles)) + let distance = dc_distance::create_distance_inherent_data_provider::< + Block, + FullClient<RuntimeApi, Executor>, + FullBackend, + >( + &*client, parent, distance_dir, &babe_owner_keys.clone() + )?; + + Ok((slot, timestamp, uncles, distance)) } }, force_authoring, diff --git a/pallets/authority-members/src/lib.rs b/pallets/authority-members/src/lib.rs index d4f299c36..4f855eae6 100644 --- a/pallets/authority-members/src/lib.rs +++ b/pallets/authority-members/src/lib.rs @@ -17,6 +17,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::type_complexity)] +pub mod impls; pub mod traits; mod types; pub mod weights; @@ -30,17 +31,15 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; -pub mod impls; pub use impls::*; - pub use pallet::*; +pub use sp_staking::SessionIndex; +pub use traits::*; pub use types::*; pub use weights::WeightInfo; -use self::traits::*; use frame_support::traits::Get; use sp_runtime::traits::Convert; -use sp_staking::SessionIndex; use sp_std::prelude::*; #[frame_support::pallet] diff --git a/pallets/distance/Cargo.toml b/pallets/distance/Cargo.toml new file mode 100644 index 000000000..47f1f6710 --- /dev/null +++ b/pallets/distance/Cargo.toml @@ -0,0 +1,91 @@ +[package] +authors = ['tuxmain <tuxmain@zettascript.org>'] +description = 'FRAME pallet distance.' +edition = '2021' +homepage = 'https://duniter.org' +license = 'AGPL-3.0' +name = 'pallet-distance' +readme = 'README.md' +repository = 'https://git.duniter.org/nodes/rust/duniter-v2s' +version = '1.0.0' + +[features] +default = ['std'] +std = [ + 'codec/std', + 'frame-support/std', + 'pallet-authority-members/std', + 'pallet-authorship/std', + 'pallet-certification/std', + 'pallet-identity/std', + 'pallet-membership/std', + 'pallet-session/std', + 'sp-core/std', + 'sp-distance/std', + 'sp-runtime/std', + 'sp-std/std', +] + +[dependencies] + +pallet-authority-members = { path = "../authority-members", default-features = false } +pallet-certification = { path = "../certification", default-features = false } +pallet-identity = { path = "../identity", default-features = false } +pallet-membership = { path = "../membership", default-features = false } +sp-distance = { path = "../../primitives/distance", default-features = false } + +# substrate +scale-info = { version = "2.1.1", default-features = false, features = [ + "derive", +] } + +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '3.1.5' + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.frame-system] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.pallet-authorship] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.pallet-session] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-core] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-inherents] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-std] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +### DOC ### + +[package.metadata.docs.rs] +targets = ['x86_64-unknown-linux-gnu'] diff --git a/pallets/distance/src/lib.rs b/pallets/distance/src/lib.rs new file mode 100644 index 000000000..cce777e7d --- /dev/null +++ b/pallets/distance/src/lib.rs @@ -0,0 +1,382 @@ +// Copyright 2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +#![cfg_attr(not(feature = "std"), no_std)] + +mod median; +mod traits; +mod types; + +use median::*; +pub use pallet::*; +pub use traits::*; +pub use types::*; + +use frame_support::traits::StorageVersion; +use pallet_authority_members::SessionIndex; +use sp_distance::{InherentError, INHERENT_IDENTIFIER}; +use sp_inherents::{InherentData, InherentIdentifier}; +use sp_std::convert::TryInto; + +type IdtyIndex = u32; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use frame_support::{pallet_prelude::*, traits::ReservableCurrency, BoundedBTreeSet}; + use frame_system::pallet_prelude::*; + use sp_runtime::Perbill; + + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + #[pallet::storage_version(STORAGE_VERSION)] + #[pallet::without_storage_info] + pub struct Pallet<T, I = ()>(PhantomData<(T, I)>); + #[pallet::config] + pub trait Config<I: 'static = ()>: + frame_system::Config + + pallet_authorship::Config + + pallet_certification::Config<I, IdtyIndex = IdtyIndex> + + pallet_identity::Config<IdtyIndex = IdtyIndex> + + pallet_session::Config + { + type Currency: ReservableCurrency<Self::AccountId>; + /// Amount reserved during evaluation + #[pallet::constant] + type EvaluationPrice: Get< + <Self::Currency as frame_support::traits::Currency<Self::AccountId>>::Balance, + >; + /// Maximum number of identities to be evaluated in a session + type MaxEvaluationsPerSession: Get<u32>; + /// Maximum number of evaluators in a session + type MaxEvaluatorsPerSession: Get<u32>; + /// Minimum ratio of accessible referees + type MinAccessibleReferees: Get<Perbill>; + // /// Handler for the evaluation price in case of negative result + type ResultExpiration: Get<u32>; + } + + // STORAGE // + + pub type EvaluationPool< + AccountId, + IdtyIndex, + MaxEvaluationsPerSession, + MaxEvaluatorsPerSession, + > = ( + BoundedVec<(IdtyIndex, MedianAcc<Perbill>), MaxEvaluationsPerSession>, + BoundedBTreeSet<AccountId, MaxEvaluatorsPerSession>, + ); + + #[pallet::storage] + pub type EvaluationPool0<T: Config<I>, I: 'static = ()> = StorageValue< + _, + EvaluationPool< + <T as frame_system::Config>::AccountId, + <T as pallet_certification::Config<I>>::IdtyIndex, + <T as Config<I>>::MaxEvaluationsPerSession, + <T as Config<I>>::MaxEvaluatorsPerSession, + >, + ValueQuery, + >; + #[pallet::storage] + pub type EvaluationPool1<T: Config<I>, I: 'static = ()> = StorageValue< + _, + EvaluationPool< + <T as frame_system::Config>::AccountId, + <T as pallet_certification::Config<I>>::IdtyIndex, + <T as Config<I>>::MaxEvaluationsPerSession, + <T as Config<I>>::MaxEvaluatorsPerSession, + >, + ValueQuery, + >; + #[pallet::storage] + pub type EvaluationPool2<T: Config<I>, I: 'static = ()> = StorageValue< + _, + EvaluationPool< + <T as frame_system::Config>::AccountId, + <T as pallet_certification::Config<I>>::IdtyIndex, + <T as Config<I>>::MaxEvaluationsPerSession, + <T as Config<I>>::MaxEvaluatorsPerSession, + >, + ValueQuery, + >; + + /// Block for which the distance rule must be checked + #[pallet::storage] + pub type EvaluationBlock<T: Config<I>, I: 'static = ()> = + StorageValue<_, <T as frame_system::Config>::Hash, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn distance_ok_identities)] + pub type IdentitiesDistanceStatus<T: Config<I>, I: 'static = ()> = StorageMap< + _, + Twox64Concat, + <T as pallet_certification::Config<I>>::IdtyIndex, + DistanceStatus, + OptionQuery, + >; + + /// Did evaluation get updated in this block? + #[pallet::storage] + pub(super) type DidUpdate<T: Config<I>, I: 'static = ()> = StorageValue<_, bool, ValueQuery>; + + // session_index % 3: + // storage_id + 0 => pending + // storage_id + 1 => receives results + // storage_id + 2 => receives new identities + // (this avoids problems for session_index < 3) + + // ERRORS // + + #[pallet::error] + pub enum Error<T, I = ()> { + AlreadyInEvaluation, + CannotReserve, + ManyEvaluationsByAuthor, + ManyEvaluationsInBlock, + NoAuthor, + NoIdentity, + NonEligibleForEvaluation, + QueueFull, + TooManyEvaluators, + WrongResultLength, + } + + #[pallet::hooks] + impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> { + /// dummy `on_initialize` to return the weight used in `on_finalize`. + fn on_initialize(_n: BlockNumberFor<T>) -> Weight { + // weight of `on_finalize` + //T::WeightInfo::on_finalize()// TODO uncomment when benchmarking + Weight::zero() + } + + /// # <weight> + /// - `O(1)` + /// - 1 storage deletion (codec `O(1)`). + /// # </weight> + fn on_finalize(_n: BlockNumberFor<T>) { + DidUpdate::<T, I>::take(); + } + } + + // CALLS // + + #[pallet::call] + impl<T: Config<I>, I: 'static> Pallet<T, I> { + /// Request an identity to be evaluated + #[pallet::weight(1_000_000_000)] + pub fn evaluate_distance(origin: OriginFor<T>) -> DispatchResultWithPostInfo { + let who = ensure_signed(origin)?; + + let idty = pallet_identity::IdentityIndexOf::<T>::get(&who) + .ok_or(Error::<T, I>::NoIdentity)?; + + ensure!( + IdentitiesDistanceStatus::<T, I>::get(idty).is_none(), + Error::<T, I>::AlreadyInEvaluation + ); + + Pallet::<T, I>::do_evaluate_distance(who, idty)?; + Ok(().into()) + } + + /// (Inherent) Push an evaluation result to the pool + #[pallet::weight(1_000_000_000)] + pub fn update_evaluation( + origin: OriginFor<T>, + computation_result: ComputationResult, + ) -> DispatchResult { + ensure_none(origin)?; + ensure!( + !DidUpdate::<T, I>::exists(), + Error::<T, I>::ManyEvaluationsInBlock, + ); + + Pallet::<T, I>::mutate_current_pool( + pallet_session::CurrentIndex::<T>::get().wrapping_add(1), + |result_pool| { + ensure!( + computation_result.distances.len() == result_pool.0.len(), + Error::<T, I>::WrongResultLength + ); + + let author = + pallet_authorship::Pallet::<T>::author().ok_or(Error::<T, I>::NoAuthor)?; + + if result_pool + .1 + .try_insert(author) + .map_err(|_| Error::<T, I>::TooManyEvaluators)? + { + for (distance_value, (_identity, median_acc)) in computation_result + .distances + .into_iter() + .zip(result_pool.0.iter_mut()) + { + median_acc.push(distance_value); + } + + Ok(()) + } else { + Err(Error::<T, I>::ManyEvaluationsByAuthor.into()) + } + }, + ) + } + } + + // PUBLIC FUNCTIONS // + + impl<T: Config<I>, I: 'static> Pallet<T, I> { + pub fn do_evaluate_distance( + who: T::AccountId, + idty_index: <T as pallet_certification::Config<I>>::IdtyIndex, + ) -> Result<(), DispatchError> { + Pallet::<T, I>::mutate_current_pool( + pallet_session::CurrentIndex::<T>::get(), + |current_pool| { + ensure!( + current_pool.0.len() + < (<T as Config<I>>::MaxEvaluationsPerSession::get() as usize), + Error::<T, I>::QueueFull + ); + + T::Currency::reserve(&who, <T as Config<I>>::EvaluationPrice::get())?; + + current_pool + .0 + .try_push((idty_index, median::MedianAcc::new())) + .map_err(|_| Error::<T, I>::QueueFull)?; + + Ok(()) + }, + ) + } + } + + // INTERNAL FUNCTIONS // + + impl<T: Config<I>, I: 'static> Pallet<T, I> { + /// Mutate the evaluation pool containing the results to be applied on this session. + fn mutate_current_pool< + R, + F: FnOnce( + &mut EvaluationPool< + <T as frame_system::Config>::AccountId, + <T as pallet_certification::Config<I>>::IdtyIndex, + <T as Config<I>>::MaxEvaluationsPerSession, + <T as Config<I>>::MaxEvaluatorsPerSession, + >, + ) -> R, + >( + index: SessionIndex, + f: F, + ) -> R { + match index % 3 { + 0 => EvaluationPool2::<T, I>::mutate(f), + 1 => EvaluationPool0::<T, I>::mutate(f), + 2 => EvaluationPool1::<T, I>::mutate(f), + _ => panic!("index % 3 < 3"), + } + } + + /// Take the evaluation pool containing the results to be applied on this session. + #[allow(clippy::type_complexity)] + fn take_current_pool( + index: SessionIndex, + ) -> EvaluationPool< + <T as frame_system::Config>::AccountId, + <T as pallet_certification::Config<I>>::IdtyIndex, + <T as Config<I>>::MaxEvaluationsPerSession, + <T as Config<I>>::MaxEvaluatorsPerSession, + > { + match index % 3 { + 0 => EvaluationPool2::<T, I>::take(), + 1 => EvaluationPool0::<T, I>::take(), + 2 => EvaluationPool1::<T, I>::take(), + _ => panic!("index % 3 < 3"), + } + } + } + + impl<T: Config<I>, I: 'static> pallet_authority_members::OnNewSession for Pallet<T, I> { + fn on_new_session(index: SessionIndex) -> Weight { + EvaluationBlock::<T, I>::set(frame_system::Pallet::<T>::parent_hash()); + + // Apply the results from the current pool (which was previous session's result pool) + // We take the results so the pool is left empty for the new session. + #[allow(clippy::type_complexity)] + let current_pool: EvaluationPool< + <T as frame_system::Config>::AccountId, + <T as pallet_certification::Config<I>>::IdtyIndex, + <T as Config<I>>::MaxEvaluationsPerSession, + <T as Config<I>>::MaxEvaluatorsPerSession, + > = Pallet::<T, I>::take_current_pool(index); + for (idty, median_acc) in current_pool.0.into_iter() { + let Some(idty_value) = + pallet_identity::Identities::<T>::get(idty) else {continue}; + let account_id = idty_value.owner_key; + if let Some(median_result) = median_acc.get_median() { + let median = match median_result { + MedianResult::One(m) => m, + MedianResult::Two(m1, m2) => m1 + (m2 - m1) / 2, // Avoid overflow (since max is 1) + }; + if median >= T::MinAccessibleReferees::get() { + IdentitiesDistanceStatus::<T, I>::insert(idty, DistanceStatus::Valid); + T::Currency::unreserve( + &account_id, + <T as Config<I>>::EvaluationPrice::get(), + ); + } else { + IdentitiesDistanceStatus::<T, I>::remove(idty); + <T as Config<I>>::Currency::slash_reserved( + &account_id, + <T as Config<I>>::EvaluationPrice::get(), + ); + } + } else { + IdentitiesDistanceStatus::<T, I>::remove(idty); + T::Currency::unreserve(&account_id, <T as Config<I>>::EvaluationPrice::get()); + } + } + Weight::zero() + } + } + + #[pallet::inherent] + impl<T: Config<I>, I: 'static> ProvideInherent for Pallet<T, I> { + type Call = Call<T, I>; + type Error = InherentError; + + const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; + + fn create_inherent(data: &InherentData) -> Option<Self::Call> { + data.get_data::<ComputationResult>(&INHERENT_IDENTIFIER) + .expect("Distance inherent data not correctly encoded") + .map(|inherent_data| Call::update_evaluation { + computation_result: inherent_data, + }) + } + fn is_inherent(call: &Self::Call) -> bool { + matches!(call, Self::Call::update_evaluation { .. }) + } + } +} diff --git a/pallets/distance/src/median.rs b/pallets/distance/src/median.rs new file mode 100644 index 000000000..065efb311 --- /dev/null +++ b/pallets/distance/src/median.rs @@ -0,0 +1,143 @@ +// Copyright 2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +use frame_support::pallet_prelude::*; +use sp_std::{cmp::Ordering, vec::Vec}; + +#[derive(Clone, Debug, Decode, Default, Encode, TypeInfo)] +pub struct MedianAcc<T: Clone + Decode + Encode + Ord + TypeInfo> { + samples: Vec<(T, u32)>, + median_index: Option<u32>, + median_subindex: u32, +} + +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum MedianResult<T: Clone + Ord> { + One(T), + Two(T, T), +} + +impl<T: Clone + Decode + Encode + Ord + TypeInfo> MedianAcc<T> { + pub fn new() -> Self { + Self { + samples: Vec::new(), + median_index: None, + median_subindex: 0, + } + } + + pub fn push(&mut self, sample: T) { + if let Some(median_index) = &mut self.median_index { + match self + .samples + .binary_search_by_key(&sample, |(s, _n)| s.clone()) + { + Ok(sample_index) => { + self.samples.get_mut(sample_index).expect("unreachable").1 += 1; + match (sample_index as u32).cmp(median_index) { + Ordering::Greater => { + if self.median_subindex + == self + .samples + .get(*median_index as usize) + .expect("unreachable") + .1 + * 2 + - 1 + { + self.median_subindex = 0; + *median_index += 1; + } else { + self.median_subindex += 1; + } + } + Ordering::Equal => { + self.median_subindex += 1; + } + Ordering::Less => { + if self.median_subindex == 0 { + *median_index -= 1; + self.median_subindex = self + .samples + .get(*median_index as usize) + .expect("unreachable") + .1 + * 2 + - 1; + } else { + self.median_subindex -= 1; + } + } + } + } + Err(sample_index) => { + self.samples.insert(sample_index, (sample, 1)); + if *median_index as usize >= sample_index { + if self.median_subindex == 0 { + self.median_subindex = self + .samples + .get(*median_index as usize) + .expect("unreachable") + .1 + * 2 + - 1; + } else { + self.median_subindex -= 1; + *median_index += 1; + } + } else if self.median_subindex + == self + .samples + .get(*median_index as usize) + .expect("unreachable") + .1 + * 2 + - 1 + { + self.median_subindex = 0; + *median_index += 1; + } else { + self.median_subindex += 1; + } + } + } + } else { + self.samples.push((sample, 1)); + self.median_index = Some(0); + } + } + + pub fn get_median(&self) -> Option<MedianResult<T>> { + self.median_index.map(|median_index| { + let (median_sample, median_n) = self + .samples + .get(median_index as usize) + .expect("unreachable"); + if self.median_subindex == median_n * 2 - 1 { + MedianResult::Two( + median_sample.clone(), + self.samples + .get(median_index as usize + 1) + .expect("unreachable") + .0 + .clone(), + ) + } else { + MedianResult::One(median_sample.clone()) + } + }) + } +} diff --git a/pallets/distance/src/traits.rs b/pallets/distance/src/traits.rs new file mode 100644 index 000000000..4d34c5de0 --- /dev/null +++ b/pallets/distance/src/traits.rs @@ -0,0 +1,21 @@ +// Copyright 2023 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +pub trait HandleNegativeEvaluation<T: crate::Config<I>, I: 'static> { + /// Do something with the reserved amount on the account, + /// when distance evaluation result is negative. + fn handle_negative_evaluation(account_id: T::AccountId); +} diff --git a/pallets/distance/src/types.rs b/pallets/distance/src/types.rs new file mode 100644 index 000000000..2d3edf946 --- /dev/null +++ b/pallets/distance/src/types.rs @@ -0,0 +1,28 @@ +// Copyright 2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +pub use sp_distance::ComputationResult; + +use codec::{Decode, Encode}; +use frame_support::pallet_prelude::*; + +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] +pub enum DistanceStatus { + /// Identity is in evaluation. + Pending, + /// Identity respects the distance + Valid, +} diff --git a/pallets/duniter-wot/Cargo.toml b/pallets/duniter-wot/Cargo.toml index 252e9e8a4..1af0bcfa9 100644 --- a/pallets/duniter-wot/Cargo.toml +++ b/pallets/duniter-wot/Cargo.toml @@ -18,6 +18,7 @@ std = [ 'frame-system/std', 'frame-benchmarking/std', 'pallet-certification/std', + 'pallet-distance/std', 'pallet-identity/std', 'pallet-membership/std', 'serde', @@ -32,11 +33,14 @@ try-runtime = ['frame-support/try-runtime'] [dependencies] pallet-certification = { path = "../certification", default-features = false } pallet-identity = { path = "../identity", default-features = false } +pallet-distance = { path = "../distance", default-features = false } pallet-membership = { path = "../membership", default-features = false } sp-membership = { path = "../../primitives/membership", default-features = false } # substrate -scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +scale-info = { version = "2.1.1", default-features = false, features = [ + "derive", +] } [dependencies.codec] default-features = false diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index 50a41c70b..b52fd00c7 100644 --- a/pallets/duniter-wot/src/lib.rs +++ b/pallets/duniter-wot/src/lib.rs @@ -23,11 +23,15 @@ mod mock; #[cfg(test)] mod tests; +pub mod traits; + /*#[cfg(feature = "runtime-benchmarks")] mod benchmarking;*/ pub use pallet::*; +use traits::*; + use frame_support::dispatch::UnfilteredDispatchable; use frame_support::pallet_prelude::*; use frame_system::RawOrigin; @@ -60,6 +64,8 @@ pub mod pallet { + pallet_identity::Config<IdtyIndex = IdtyIndex> + pallet_membership::Config<I, IdtyId = IdtyIndex> { + /// Distance evaluation provider + type IsDistanceOk: IsDistanceOk<IdtyIndex>; #[pallet::constant] type FirstIssuableOn: Get<Self::BlockNumber>; #[pallet::constant] @@ -242,7 +248,8 @@ impl<T: Config<I>, I: 'static> sp_membership::traits::CheckMembershipCallAllowed fn check_idty_allowed_to_claim_membership(idty_index: &IdtyIndex) -> Result<(), DispatchError> { let idty_cert_meta = pallet_certification::Pallet::<T, I>::idty_cert_meta(idty_index); ensure!( - idty_cert_meta.received_count >= T::MinCertForMembership::get(), + idty_cert_meta.received_count >= T::MinCertForMembership::get() + && T::IsDistanceOk::is_distance_ok(idty_index), Error::<T, I>::IdtyNotAllowedToClaimMembership ); Ok(()) @@ -252,7 +259,8 @@ impl<T: Config<I>, I: 'static> sp_membership::traits::CheckMembershipCallAllowed fn check_idty_allowed_to_renew_membership(idty_index: &IdtyIndex) -> Result<(), DispatchError> { if let Some(idty_value) = pallet_identity::Pallet::<T>::identity(idty_index) { ensure!( - idty_value.status == IdtyStatus::Validated, + idty_value.status == IdtyStatus::Validated + && T::IsDistanceOk::is_distance_ok(idty_index), Error::<T, I>::IdtyNotAllowedToRenewMembership ); } else { diff --git a/pallets/duniter-wot/src/mock.rs b/pallets/duniter-wot/src/mock.rs index a2e645a13..75d87d48a 100644 --- a/pallets/duniter-wot/src/mock.rs +++ b/pallets/duniter-wot/src/mock.rs @@ -101,6 +101,7 @@ impl pallet_duniter_wot::Config<Instance1> for Test { type MinCertForMembership = MinCertForMembership; type MinCertForCreateIdtyRight = MinCertForCreateIdtyRight; type FirstIssuableOn = FirstIssuableOn; + type IsDistanceOk = crate::traits::DistanceAlwaysOk; } // Identity @@ -189,6 +190,7 @@ impl pallet_duniter_wot::Config<Instance2> for Test { type MinCertForMembership = SmithMinCertForMembership; type MinCertForCreateIdtyRight = frame_support::traits::ConstU32<0>; type FirstIssuableOn = SmithFirstIssuableOn; + type IsDistanceOk = crate::traits::DistanceAlwaysOk; } // SmithMembership diff --git a/pallets/duniter-wot/src/traits.rs b/pallets/duniter-wot/src/traits.rs new file mode 100644 index 000000000..7c3d7b220 --- /dev/null +++ b/pallets/duniter-wot/src/traits.rs @@ -0,0 +1,27 @@ +// Copyright 2023 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +pub trait IsDistanceOk<IdtyId> { + fn is_distance_ok(idty_id: &IdtyId) -> bool; +} + +pub struct DistanceAlwaysOk; + +impl<IdtyId> IsDistanceOk<IdtyId> for DistanceAlwaysOk { + fn is_distance_ok(_idty_id: &IdtyId) -> bool { + true + } +} diff --git a/primitives/distance/Cargo.toml b/primitives/distance/Cargo.toml new file mode 100644 index 000000000..f8ff3e5f3 --- /dev/null +++ b/primitives/distance/Cargo.toml @@ -0,0 +1,67 @@ +[package] +authors = ['librelois <c@elo.tf>'] +description = 'primitives for pallet distance.' +edition = "2021" +homepage = 'https://duniter.org' +license = 'AGPL-3.0' +name = 'sp-distance' +readme = 'README.md' +repository = 'https://git.duniter.org/nodes/rust/duniter-v2s' +version = '3.0.0' + +[features] +default = ['std'] +std = [ + 'async-trait', + 'codec/std', + 'frame-support/std', + 'serde', + 'sp-inherents/std', + 'sp-runtime/std', + 'sp-std/std', + 'thiserror' +] +try-runtime = ['frame-support/try-runtime'] + +[dependencies] +async-trait = { version = "0.1.50", optional = true } +thiserror = { version = "1.0.30", optional = true } + +# substrate +scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } + +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = "3.1.5" + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.serde] +version = "1.0.101" +optional = true +features = ["derive"] + +[dependencies.sp-inherents] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-std] +default-features = false +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +### DOC ### + +[package.metadata.docs.rs] +targets = ['x86_64-unknown-linux-gnu'] diff --git a/primitives/distance/src/lib.rs b/primitives/distance/src/lib.rs new file mode 100644 index 000000000..997224181 --- /dev/null +++ b/primitives/distance/src/lib.rs @@ -0,0 +1,110 @@ +// Copyright 2023 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +//! Defines types and traits for users of pallet distance. + +#![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::type_complexity)] + +use codec::{Decode, Encode}; +use frame_support::RuntimeDebug; +use scale_info::TypeInfo; +//#[cfg(feature = "std")] +//use serde::{Deserialize, Serialize}; +use sp_inherents::{InherentData, InherentIdentifier, IsFatalError}; +use sp_runtime::Perbill; +use sp_std::vec::Vec; +#[cfg(feature = "std")] +use std::marker::PhantomData; + +pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"distanc0"; + +#[derive(Clone, Decode, Encode, PartialEq, RuntimeDebug, TypeInfo)] +pub struct ComputationResult { + pub distances: Vec<Perbill>, +} + +#[derive(Encode, sp_runtime::RuntimeDebug)] +#[cfg_attr(feature = "std", derive(Decode, thiserror::Error))] +pub enum InherentError { + #[cfg_attr(feature = "std", error("InvalidComputationResultFile"))] + InvalidComputationResultFile, +} + +impl IsFatalError for InherentError { + fn is_fatal_error(&self) -> bool { + match self { + InherentError::InvalidComputationResultFile => false, + } + } +} + +impl InherentError { + #[cfg(feature = "std")] + pub fn try_from(id: &InherentIdentifier, mut data: &[u8]) -> Option<Self> { + if id == &INHERENT_IDENTIFIER { + <InherentError as codec::Decode>::decode(&mut data).ok() + } else { + None + } + } +} + +#[cfg(feature = "std")] +pub struct InherentDataProvider<IdtyIndex: Decode + Encode + PartialEq + TypeInfo> { + computation_result: Option<ComputationResult>, + _p: PhantomData<IdtyIndex>, +} + +#[cfg(feature = "std")] +impl<IdtyIndex: Decode + Encode + PartialEq + TypeInfo> InherentDataProvider<IdtyIndex> { + pub fn new(computation_result: Option<ComputationResult>) -> Self { + Self { + computation_result, + _p: PhantomData, + } + } +} + +#[cfg(feature = "std")] +#[async_trait::async_trait] +impl<IdtyIndex: Decode + Encode + PartialEq + TypeInfo + Send + Sync> + sp_inherents::InherentDataProvider for InherentDataProvider<IdtyIndex> +{ + fn provide_inherent_data( + &self, + inherent_data: &mut InherentData, + ) -> Result<(), sp_inherents::Error> { + if let Some(computation_result) = &self.computation_result { + inherent_data.put_data(INHERENT_IDENTIFIER, computation_result)?; + } + Ok(()) + } + + async fn try_handle_error( + &self, + identifier: &InherentIdentifier, + error: &[u8], + ) -> Option<Result<(), sp_inherents::Error>> { + if *identifier != INHERENT_IDENTIFIER { + return None; + } + + Some(Err(sp_inherents::Error::Application(Box::from( + InherentError::try_from(&INHERENT_IDENTIFIER, error)?, + )))) + } +} diff --git a/resources/metadata.scale b/resources/metadata.scale index 6c236f8d95a610f8b1044687302dd08fea17a14d..c5d992edbe02769551ed0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Zff@UTYjjMr#?a)3H{PXNFCUvcB^DN zsAnJzxFi!VViJXf@{6?jG5PF8WHJf^pI)S7s6j6H7$*YA?yo7JC@`oSvoPXYTF#e| zJ$q{Gg_+c8)gE$G)S3-j51ORs6Ox=m|L;%G0&d|Wg5=-7q`PeU6f+PguYQWr<Ws{g z!HGVRoG6Wx6Ru*6Jo*_4b+`Vf&(IHq-t{@g(3L;cgRAmye?<##V{`#izrqE&`GzZG z#VNA&3bM$}K6(vl^h*2!_tF6te}Qf_m5-HQe@PWUnsoM%BlHm>=`~#?QpXuZ8k1Cp zv|S@(`$wesY3l9ErC(r;TyY&6kR{)}j`*Nl9%%$PoS~M#KJaTyVVEy-ZXjCC<@vJu z2FCJshB*D{8z>;Fm0x{Fno}g#eov)Rk^JTN(2PD~qWtQ6tQ+az=^>PqZm5Ir6%cOB zoSKIk;TA=c+kPM;sg*NsBGqU}rt0-K@pB&B!0!t$tZ`O2Yw8qGft(=+F_ueK`T%3A z$T$Cvu>`t^Ym8-vP`5G*;R!_7tmkJ^n`XB@Pi6F9ioJ3JXM!{|$ikLjpI&NV7Hr<n zGg>&e=iKsb%Qd&Fz-%wJ^6fKBXhF4Bx`h6hLLK)uZk=Mn7H{xFj&W;(3CY%|>*e$u r=XM{)d<p^%gXfdn9(#*=sdk2Mk2hyNKc;r@?UFoTn5C0%Z|DCDt^gU^ diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 4a7412e77..bb74d5ea4 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -8,11 +8,11 @@ edition = "2021" [features] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", 'frame-support/runtime-benchmarks', 'frame-system-benchmarking/runtime-benchmarks', 'frame-system/runtime-benchmarks', - "pallet-babe/runtime-benchmarks", + "pallet-babe/runtime-benchmarks", 'pallet-balances/runtime-benchmarks', 'pallet-certification/runtime-benchmarks', 'pallet-collective/runtime-benchmarks', @@ -38,6 +38,7 @@ std = [ 'pallet-babe/std', 'pallet-balances/std', 'pallet-certification/std', + 'pallet-distance/std', 'pallet-duniter-account/std', 'pallet-duniter-wot/std', 'pallet-grandpa/std', @@ -50,27 +51,29 @@ std = [ 'pallet-scheduler/std', 'pallet-timestamp/std', 'pallet-treasury/std', - 'pallet-universal-dividend/std', - "serde/std", - "serde_derive", + 'pallet-universal-dividend/std', + "serde/std", + "serde_derive", 'sp-arithmetic/std', 'sp-core/std', + 'sp-distance/std', 'sp-membership/std', 'sp-runtime/std', 'sp-std/std', 'sp-weights/std', ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-babe/try-runtime", - "pallet-grandpa/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-babe/try-runtime", + "pallet-grandpa/try-runtime", ] [dependencies] duniter-primitives = { path = '../../primitives/duniter', default-features = false } pallet-authority-members = { path = '../../pallets/authority-members', default-features = false } pallet-certification = { path = '../../pallets/certification', default-features = false } +pallet-distance = { path = "../../pallets/distance", default-features = false } pallet-duniter-account = { path = '../../pallets/duniter-account', default-features = false } pallet-duniter-wot = { path = '../../pallets/duniter-wot', default-features = false } pallet-identity = { path = '../../pallets/identity', default-features = false } @@ -80,12 +83,17 @@ pallet-provide-randomness = { path = '../../pallets/provide-randomness', default pallet-upgrade-origin = { path = '../../pallets/upgrade-origin', default-features = false } pallet-universal-dividend = { path = '../../pallets/universal-dividend', default-features = false } pallet-session-benchmarking = { path = '../../pallets/session-benchmarking', default-features = false } +sp-distance = { path = '../../primitives/distance', default-features = false } sp-membership = { path = '../../primitives/membership', default-features = false } # Crates.io -codec = { package = "parity-scale-codec", version = "3.1.5", features = ["derive"], default-features = false } +codec = { package = "parity-scale-codec", version = "3.1.5", features = [ + "derive", +], default-features = false } log = { version = "0.4.14", default-features = false } -scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +scale-info = { version = "2.1.1", default-features = false, features = [ + "derive", +] } serde = { version = "1.0.101", default-features = false } serde_derive = { version = "1.0.101", optional = true } smallvec = "1.6.1" diff --git a/runtime/common/src/handlers.rs b/runtime/common/src/handlers.rs index 95a6ccabd..e573fec14 100644 --- a/runtime/common/src/handlers.rs +++ b/runtime/common/src/handlers.rs @@ -28,11 +28,11 @@ use sp_runtime::traits::IsMember; pub struct OnNewSessionHandler<Runtime>(core::marker::PhantomData<Runtime>); impl<Runtime> pallet_authority_members::traits::OnNewSession for OnNewSessionHandler<Runtime> where - Runtime: pallet_provide_randomness::Config, + Runtime: pallet_provide_randomness::Config + pallet_distance::Config<Instance1>, { - fn on_new_session(_index: sp_staking::SessionIndex) -> Weight { + fn on_new_session(index: sp_staking::SessionIndex) -> Weight { pallet_provide_randomness::Pallet::<Runtime>::on_new_epoch(); - Weight::zero() + pallet_distance::Pallet::<Runtime, Instance1>::on_new_session(index) } } diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index f289dfac1..a858556cd 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -432,6 +432,7 @@ macro_rules! pallets_config { use frame_support::instances::Instance1; impl pallet_duniter_wot::Config<Instance1> for Runtime { type FirstIssuableOn = WotFirstCertIssuableOn; + type IsDistanceOk = common_runtime::providers::MainWotIsDistanceOk<Runtime, Instance1>; type IsSubWot = frame_support::traits::ConstBool<false>; type MinCertForMembership = WotMinCertForMembership; type MinCertForCreateIdtyRight = WotMinCertForCreateIdtyRight; @@ -481,12 +482,24 @@ macro_rules! pallets_config { type WeightInfo = common_runtime::weights::pallet_certification_cert::WeightInfo<Runtime>; type ValidityPeriod = ValidityPeriod; } + parameter_types! { + pub const MinAccessibleReferees: Perbill = Perbill::from_percent(80); + } + impl pallet_distance::Config<Instance1> for Runtime { + type Currency = Balances; + type EvaluationPrice = frame_support::traits::ConstU64<1000>; + type MaxEvaluationsPerSession = frame_support::traits::ConstU32<1000>; + type MaxEvaluatorsPerSession = frame_support::traits::ConstU32<100>; + type MinAccessibleReferees = MinAccessibleReferees; + type ResultExpiration = frame_support::traits::ConstU32<720>; + } // SMITHSÂ SUB-WOT // use frame_support::instances::Instance2; impl pallet_duniter_wot::Config<Instance2> for Runtime { type FirstIssuableOn = SmithWotFirstCertIssuableOn; + type IsDistanceOk = pallet_duniter_wot::traits::DistanceAlwaysOk; type IsSubWot = frame_support::traits::ConstBool<true>; type MinCertForMembership = SmithWotMinCertForMembership; type MinCertForCreateIdtyRight = frame_support::traits::ConstU32<0>; diff --git a/runtime/common/src/providers.rs b/runtime/common/src/providers.rs index 4582513b9..e227aa7ef 100644 --- a/runtime/common/src/providers.rs +++ b/runtime/common/src/providers.rs @@ -106,3 +106,18 @@ where } } } + +pub struct MainWotIsDistanceOk<T, I>(PhantomData<(T, I)>); + +impl<T, I> + pallet_duniter_wot::traits::IsDistanceOk<<T as pallet_certification::Config<I>>::IdtyIndex> + for MainWotIsDistanceOk<T, I> +where + T: pallet_distance::Config<I>, + I: 'static, +{ + fn is_distance_ok(idty_id: &<T as pallet_certification::Config<I>>::IdtyIndex) -> bool { + pallet_distance::Pallet::<T, I>::distance_ok_identities(idty_id) + == Some(pallet_distance::DistanceStatus::Valid) + } +} diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml index 8c8fd7788..71b927566 100644 --- a/runtime/gdev/Cargo.toml +++ b/runtime/gdev/Cargo.toml @@ -50,7 +50,7 @@ runtime-benchmarks = [ ] std = [ 'codec/std', - 'common-runtime/std', + 'common-runtime/std', 'frame-executive/std', 'frame-support/std', 'frame-system-rpc-runtime-api/std', @@ -64,6 +64,7 @@ std = [ 'pallet-balances/std', 'pallet-certification/std', 'pallet-collective/std', + 'pallet-distance/std', 'pallet-duniter-test-parameters/std', 'pallet-duniter-account/std', 'pallet-duniter-wot/std', @@ -74,10 +75,10 @@ std = [ 'pallet-provide-randomness/std', 'pallet-im-online/std', 'pallet-multisig/std', - "pallet-offences/std", + "pallet-offences/std", 'pallet-preimage/std', 'pallet-proxy/std', - "pallet-scheduler/std", + "pallet-scheduler/std", 'pallet-session/std', 'pallet-sudo/std', 'pallet-universal-dividend/std', @@ -87,14 +88,15 @@ std = [ 'pallet-transaction-payment/std', 'pallet-treasury/std', 'pallet-utility/std', - "serde/std", - "serde_derive", + "serde/std", + "serde_derive", 'sp-api/std', 'sp-arithmetic/std', 'sp-authority-discovery/std', 'sp-block-builder/std', 'sp-consensus-babe/std', 'sp-core/std', + 'sp-distance/std', 'sp-inherents/std', 'sp-offchain/std', 'sp-membership/std', @@ -138,6 +140,7 @@ sp-keyring = { git = 'https://github.com/duniter/substrate', branch = 'duniter-s common-runtime = { path = "../common", default-features = false } pallet-authority-members = { path = '../../pallets/authority-members', default-features = false } pallet-certification = { path = '../../pallets/certification', default-features = false } +pallet-distance = { path = "../../pallets/distance", default-features = false } pallet-duniter-test-parameters = { path = '../../pallets/duniter-test-parameters', default-features = false } pallet-duniter-account = { path = '../../pallets/duniter-account', default-features = false } pallet-duniter-wot = { path = '../../pallets/duniter-wot', default-features = false } @@ -149,13 +152,18 @@ pallet-provide-randomness = { path = '../../pallets/provide-randomness', default pallet-universal-dividend = { path = '../../pallets/universal-dividend', default-features = false } pallet-session-benchmarking = { path = '../../pallets/session-benchmarking', default-features = false } pallet-upgrade-origin = { path = '../../pallets/upgrade-origin', default-features = false } +sp-distance = { path = '../../primitives/distance', default-features = false } sp-membership = { path = '../../primitives/membership', default-features = false } # crates.io -codec = { package = "parity-scale-codec", version = "3.1.5", features = ["derive"], default-features = false } +codec = { package = "parity-scale-codec", version = "3.1.5", features = [ + "derive", +], default-features = false } log = { version = "0.4.17", default-features = false } hex-literal = { version = '0.3.1', optional = true } -scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } +scale-info = { version = "2.1.1", default-features = false, features = [ + "derive", +] } serde = { version = "1.0.101", default-features = false } serde_derive = { version = "1.0.101", optional = true } @@ -164,7 +172,7 @@ frame-try-runtime = { git = 'https://github.com/duniter/substrate', branch = 'du frame-executive = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false } frame-support = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false } frame-system = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false } -frame-system-rpc-runtime-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false} +frame-system-rpc-runtime-api = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false } pallet-atomic-swap = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false } pallet-authority-discovery = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false } pallet-authorship = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false } diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 770191a20..b6cda8436 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -336,6 +336,7 @@ construct_runtime!( Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 41, Membership: pallet_membership::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 42, Cert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 43, + Distance: pallet_distance::<Instance1>::{Pallet, Call, Storage, Inherent} = 44, // Smith Sub-Wot SmithSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 50, -- GitLab