From 3d7ec21e9397a4782df9ba82b64c1c38d793f387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Eng=C3=A9libert?= <tuxmain@zettascript.org> Date: Sat, 20 May 2023 11:12:41 +0200 Subject: [PATCH] wip --- Cargo.lock | 841 ++++++++++++-------- Cargo.toml | 10 + client/distance/Cargo.toml | 72 ++ client/distance/src/lib.rs | 169 ++++ distance-oracle/Cargo.toml | 17 + distance-oracle/src/main.rs | 241 ++++++ node/src/rpc.rs | 19 +- node/src/service.rs | 38 +- node/src/service/client.rs | 4 +- pallets/authority-members/src/lib.rs | 4 +- pallets/distance/Cargo.toml | 85 ++ pallets/distance/rpc/Cargo.toml | 64 ++ pallets/distance/rpc/runtime-api/Cargo.toml | 32 + pallets/distance/rpc/runtime-api/src/lib.rs | 31 + pallets/distance/rpc/src/lib.rs | 177 ++++ pallets/distance/src/lib.rs | 515 ++++++++++++ pallets/distance/src/median.rs | 143 ++++ pallets/distance/src/types.rs | 63 ++ pallets/duniter-wot/Cargo.toml | 6 +- pallets/duniter-wot/src/lib.rs | 22 +- pallets/duniter-wot/src/traits.rs | 30 + primitives/distance/Cargo.toml | 67 ++ primitives/distance/src/lib.rs | 133 ++++ runtime/common/Cargo.toml | 32 +- runtime/common/src/apis.rs | 8 + runtime/common/src/handlers.rs | 6 +- runtime/common/src/pallets_config.rs | 15 + runtime/common/src/providers.rs | 14 + runtime/gdev/Cargo.toml | 6 + runtime/gdev/src/lib.rs | 1 + 30 files changed, 2487 insertions(+), 378 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/main.rs create mode 100644 pallets/distance/Cargo.toml create mode 100644 pallets/distance/rpc/Cargo.toml create mode 100644 pallets/distance/rpc/runtime-api/Cargo.toml create mode 100644 pallets/distance/rpc/runtime-api/src/lib.rs create mode 100644 pallets/distance/rpc/src/lib.rs create mode 100644 pallets/distance/src/lib.rs create mode 100644 pallets/distance/src/median.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 1c0cd9e74..484e8fbfd 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,8 @@ dependencies = [ "pallet-balances", "pallet-certification", "pallet-collective", + "pallet-distance", + "pallet-distance-rpc-runtime-api", "pallet-duniter-account", "pallet-duniter-wot", "pallet-grandpa", @@ -905,6 +914,7 @@ dependencies = [ "sp-arithmetic", "sp-consensus-babe", "sp-core", + "sp-distance", "sp-membership", "sp-runtime", "sp-staking", @@ -913,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]] @@ -1218,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", ] @@ -1236,7 +1245,7 @@ dependencies = [ "cucumber-expressions", "derive_more", "either", - "futures 0.3.25", + "futures 0.3.26", "gherkin", "globwalk", "inventory", @@ -1304,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", @@ -1318,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", @@ -1330,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", @@ -1345,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", @@ -1421,6 +1430,29 @@ dependencies = [ "syn", ] +[[package]] +name = "dc-distance" +version = "1.0.0" +dependencies = [ + "frame-support", + "frame-system", + "log", + "once_cell", + "pallet-distance", + "parity-scale-codec", + "sc-client-api", + "scale-info", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-distance", + "sp-keystore", + "sp-rpc", + "sp-runtime", + "sp-std", + "thiserror", +] + [[package]] name = "der" version = "0.5.1" @@ -1528,6 +1560,19 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "distance-oracle" +version = "0.1.0" +dependencies = [ + "parity-scale-codec", + "rayon", + "sp-core", + "sp-distance", + "sp-runtime", + "subxt", + "tokio", +] + [[package]] name = "dns-parser" version = "0.8.0" @@ -1561,13 +1606,14 @@ name = "duniter" version = "0.3.0" dependencies = [ "async-io", - "clap 4.0.30", + "clap 4.1.4", "clap_complete", "common-runtime", + "dc-distance", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", - "futures 0.3.25", + "futures 0.3.26", "g1-runtime", "gdev-runtime", "gtest-runtime", @@ -1578,6 +1624,8 @@ dependencies = [ "maplit", "memmap2", "pallet-certification", + "pallet-distance-rpc", + "pallet-distance-rpc-runtime-api", "pallet-grandpa", "pallet-oneshot-account", "pallet-transaction-payment", @@ -1611,6 +1659,7 @@ dependencies = [ "sp-consensus", "sp-consensus-babe", "sp-core", + "sp-distance", "sp-finality-grandpa", "sp-inherents", "sp-io", @@ -1639,7 +1688,7 @@ dependencies = [ "clap 3.2.23", "ctrlc", "cucumber", - "env_logger", + "env_logger 0.9.3", "hex", "notify", "parity-scale-codec", @@ -1714,9 +1763,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", ] @@ -1751,9 +1800,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" @@ -1781,9 +1830,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", ] @@ -1794,7 +1843,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", @@ -1813,6 +1862,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" @@ -1862,7 +1924,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]] @@ -1935,11 +1997,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", ] @@ -1957,12 +2019,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", @@ -2084,7 +2146,7 @@ dependencies = [ "Inflector", "array-bytes", "chrono", - "clap 4.0.30", + "clap 4.1.4", "comfy-table", "frame-benchmarking", "frame-support", @@ -2347,9 +2409,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", @@ -2362,9 +2424,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", @@ -2372,15 +2434,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", @@ -2390,9 +2452,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" @@ -2411,9 +2473,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", @@ -2433,15 +2495,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" @@ -2451,9 +2513,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", @@ -2568,6 +2630,8 @@ dependencies = [ "pallet-balances", "pallet-certification", "pallet-collective", + "pallet-distance", + "pallet-distance-rpc-runtime-api", "pallet-duniter-account", "pallet-duniter-test-parameters", "pallet-duniter-wot", @@ -2603,6 +2667,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-vrf", "sp-core", + "sp-distance", "sp-finality-grandpa", "sp-inherents", "sp-io", @@ -2732,15 +2797,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", @@ -2762,9 +2827,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", @@ -2978,9 +3043,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" @@ -3096,9 +3161,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", @@ -3217,7 +3282,7 @@ dependencies = [ "async-io", "core-foundation", "fnv", - "futures 0.3.25", + "futures 0.3.26", "if-addrs", "ipnet", "log", @@ -3228,11 +3293,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", @@ -3346,12 +3410,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]] @@ -3383,9 +3447,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" @@ -3394,8 +3458,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", ] @@ -3425,9 +3489,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", ] @@ -3740,9 +3804,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" @@ -3763,7 +3827,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", @@ -3801,7 +3865,7 @@ dependencies = [ "ed25519-dalek", "either", "fnv", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "instant", "lazy_static", @@ -3830,7 +3894,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", @@ -3845,7 +3909,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", @@ -3870,7 +3934,7 @@ dependencies = [ "bytes", "either", "fnv", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "instant", "libp2p-core", @@ -3896,7 +3960,7 @@ dependencies = [ "async-io", "data-encoding", "dns-parser", - "futures 0.3.25", + "futures 0.3.26", "if-watch", "libp2p-core", "libp2p-swarm", @@ -3929,7 +3993,7 @@ checksum = "692664acfd98652de739a8acbb0a0d670f1d67190a49be6b4395e22c37337d89" dependencies = [ "asynchronous-codec", "bytes", - "futures 0.3.25", + "futures 0.3.26", "libp2p-core", "log", "nohash-hasher", @@ -3947,7 +4011,7 @@ checksum = "048155686bd81fe6cb5efdef0c6290f25ad32a0a42e8f4f72625cf6a505a206f" dependencies = [ "bytes", "curve25519-dalek 3.2.0", - "futures 0.3.25", + "futures 0.3.26", "lazy_static", "libp2p-core", "log", @@ -3967,7 +4031,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", @@ -3985,7 +4049,7 @@ checksum = "8827af16a017b65311a410bb626205a9ad92ec0473967618425039fa5231adc1" dependencies = [ "async-trait", "bytes", - "futures 0.3.25", + "futures 0.3.26", "instant", "libp2p-core", "libp2p-swarm", @@ -4003,7 +4067,7 @@ checksum = "46d13df7c37807965d82930c0e4b04a659efcb6cca237373b206043db5398ecf" dependencies = [ "either", "fnv", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "instant", "libp2p-core", @@ -4021,7 +4085,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", ] @@ -4033,7 +4097,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", @@ -4048,7 +4112,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", @@ -4063,7 +4127,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", @@ -4081,7 +4145,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", @@ -4096,7 +4160,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", @@ -4293,9 +4357,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" @@ -4318,7 +4382,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]] @@ -4528,9 +4592,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", @@ -4553,7 +4617,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", @@ -4655,9 +4719,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", @@ -4672,7 +4736,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", @@ -4682,13 +4746,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", ] @@ -4712,9 +4776,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", @@ -4736,9 +4800,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", @@ -4746,9 +4810,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", @@ -4803,9 +4867,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", ] @@ -4876,18 +4940,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", @@ -4908,20 +4972,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]] @@ -5137,6 +5201,59 @@ 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-distance-rpc" +version = "1.0.0" +dependencies = [ + "base64 0.13.1", + "frame-support", + "frame-system", + "jsonrpsee 0.15.1", + "pallet-distance-rpc-runtime-api", + "parity-scale-codec", + "scale-info", + "serde", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-distance", + "sp-rpc", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-distance-rpc-runtime-api" +version = "1.0.0" +dependencies = [ + "frame-support", + "pallet-distance", + "parity-scale-codec", + "sp-api", + "sp-runtime", +] + [[package]] name = "pallet-duniter-account" version = "3.0.0" @@ -5192,6 +5309,7 @@ dependencies = [ "frame-support", "frame-system", "pallet-certification", + "pallet-distance", "pallet-identity", "pallet-membership", "parity-scale-codec", @@ -5601,9 +5719,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", @@ -5616,9 +5734,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", @@ -5697,7 +5815,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]] @@ -5716,15 +5834,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]] @@ -5786,9 +5904,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", @@ -5796,9 +5914,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", @@ -5806,9 +5924,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", @@ -5819,13 +5937,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]] @@ -5969,9 +6087,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", @@ -5999,9 +6117,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", @@ -6022,11 +6140,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", ] @@ -6057,9 +6174,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", ] @@ -6103,9 +6220,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", @@ -6113,12 +6230,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", @@ -6148,9 +6265,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", @@ -6161,9 +6278,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", @@ -6318,9 +6435,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", @@ -6328,9 +6445,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", @@ -6392,9 +6509,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", @@ -6421,7 +6538,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", @@ -6444,11 +6561,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", @@ -6533,7 +6650,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", @@ -6603,13 +6720,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", @@ -6617,9 +6734,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", @@ -6641,11 +6758,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]] @@ -6672,7 +6789,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", ] @@ -6708,7 +6825,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", @@ -6777,9 +6894,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", @@ -6816,7 +6933,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", @@ -6868,7 +6985,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", @@ -6892,7 +7009,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", @@ -6922,7 +7039,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", @@ -6977,7 +7094,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", @@ -7010,7 +7127,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", @@ -7128,7 +7245,7 @@ dependencies = [ "dyn-clone", "finality-grandpa", "fork-tree", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "log", "parity-scale-codec", @@ -7164,7 +7281,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", @@ -7204,7 +7321,7 @@ dependencies = [ "either", "fnv", "fork-tree", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "ip_network", "libp2p", @@ -7243,7 +7360,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", @@ -7265,7 +7382,7 @@ dependencies = [ "async-trait", "bitflags", "bytes", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "libp2p", "linked_hash_set", @@ -7289,7 +7406,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", @@ -7307,7 +7424,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", @@ -7329,7 +7446,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", @@ -7358,7 +7475,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", @@ -7379,7 +7496,7 @@ dependencies = [ "array-bytes", "bytes", "fnv", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "hyper", "hyper-rustls", @@ -7406,7 +7523,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", @@ -7428,7 +7545,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", @@ -7458,7 +7575,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", @@ -7481,7 +7598,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", @@ -7494,7 +7611,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", @@ -7516,7 +7633,7 @@ dependencies = [ "async-trait", "directories", "exit-future", - "futures 0.3.25", + "futures 0.3.26", "futures-timer", "hash-db", "jsonrpsee 0.15.1", @@ -7598,7 +7715,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", @@ -7618,7 +7735,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", @@ -7678,7 +7795,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", @@ -7705,7 +7822,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", @@ -7718,7 +7835,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", @@ -7794,12 +7911,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]] @@ -7881,9 +7997,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", ] @@ -7908,9 +8024,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", @@ -7921,9 +8037,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", @@ -7955,18 +8071,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", @@ -8018,17 +8134,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" @@ -8154,14 +8259,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", @@ -8185,10 +8290,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", @@ -8295,7 +8400,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", @@ -8314,7 +8419,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", @@ -8407,7 +8512,7 @@ dependencies = [ "byteorder", "dyn-clonable", "ed25519-zebra", - "futures 0.3.25", + "futures 0.3.26", "hash-db", "hash256-std-hasher", "impl-serde", @@ -8485,6 +8590,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" @@ -8534,7 +8654,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", @@ -8571,7 +8691,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", @@ -8929,9 +9049,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", @@ -9016,7 +9136,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", @@ -9050,7 +9170,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", @@ -9122,7 +9242,7 @@ dependencies = [ "bitvec", "derivative", "frame-metadata", - "futures 0.3.25", + "futures 0.3.26", "getrandom 0.2.8", "hex", "jsonrpsee 0.16.2", @@ -9148,7 +9268,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", @@ -9288,9 +9408,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", @@ -9304,23 +9424,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" @@ -9427,15 +9537,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", @@ -9448,7 +9558,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -9511,9 +9621,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", ] @@ -9678,16 +9788,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", @@ -9721,9 +9831,9 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "digest 0.10.6", - "rand 0.7.3", + "rand 0.8.5", "static_assertions", ] @@ -9823,9 +9933,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" @@ -9844,9 +9954,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" @@ -10005,9 +10115,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", @@ -10015,9 +10125,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", @@ -10030,9 +10140,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", @@ -10042,9 +10152,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", @@ -10052,9 +10162,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", @@ -10065,9 +10175,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" @@ -10095,7 +10205,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", @@ -10190,7 +10300,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", @@ -10318,9 +10428,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", @@ -10356,9 +10466,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", @@ -10447,19 +10557,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" @@ -10475,9 +10609,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" @@ -10493,9 +10627,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" @@ -10511,9 +10645,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" @@ -10529,15 +10663,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" @@ -10553,9 +10687,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" @@ -10601,7 +10735,7 @@ name = "xtask" version = "0.1.0" dependencies = [ "anyhow", - "clap 4.0.30", + "clap 4.1.4", "frame-metadata", "graphql_client", "hex", @@ -10625,7 +10759,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", @@ -10681,10 +10815,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 42515b104..012d21e92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,11 +56,15 @@ sp-trie = { git = "https://github.com/duniter/substrate", branch = "duniter-subs [dependencies] # local dependencies common-runtime = { path = 'runtime/common' } +dc-distance = { path = 'client/distance' } 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-distance-rpc = { path = 'pallets/distance/rpc' } +pallet-distance-rpc-runtime-api = { path = 'pallets/distance/rpc/runtime-api' } pallet-oneshot-account = { path = 'pallets/oneshot-account' } +sp-distance = { path = 'primitives/distance' } sp-membership = { path = 'primitives/membership' } # crates.io dependencies @@ -130,9 +134,14 @@ 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/distance/rpc', + 'pallets/distance/rpc/runtime-api', 'pallets/duniter-test-parameters', 'pallets/duniter-test-parameters/macro', 'pallets/duniter-wot', @@ -143,6 +152,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..a5423be33 --- /dev/null +++ b/client/distance/Cargo.toml @@ -0,0 +1,72 @@ +[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" +once_cell = "1.16.0" +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.frame-system] +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-api] +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-blockchain] +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-rpc] +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' + +[dependencies.sp-std] +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..364ea4788 --- /dev/null +++ b/client/distance/src/lib.rs @@ -0,0 +1,169 @@ +// 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 once_cell::sync::OnceCell; +use sc_client_api::{ProvideUncles, StorageKey, StorageProvider}; +use scale_info::TypeInfo; +use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr}; +use sp_runtime::{generic::BlockId, traits::Block as BlockT, AccountId32, KeyTypeId}; +use std::path::PathBuf; + +type IdtyIndex = u32; + +static VALIDATOR_IDTY: OnceCell<IdtyIndex> = OnceCell::new(); + +#[derive(Debug, thiserror::Error)] +pub enum Error<B: BlockT> { + #[error("Could not retrieve the block hash for block id: {0:?}")] + NoHashForBlockId(BlockId<B>), +} + +/*pub fn find_validator_idty<B, C, Backend>(client: &C, + parent: B::Hash, keystore: SyncCryptoStorePtr, key_type_id: KeyTypeId) +where + B: BlockT, + C: ProvideUncles<B> + StorageProvider<B, Backend>, + Backend: sc_client_api::Backend<B>, { + let key_owner_key = + StorageKey(frame_support::storage::storage_prefix(b"Session", b"OwnerKey").to_vec()); + for key in SyncCryptoStore::sr25519_public_keys(keystore.as_ref(), key_type_id) { + client.storage(&BlockId::Hash(parent), key_owner_key) + } +}*/ + +/// Create a new [`sp_distance::InherentDataProvider`] at the given block. +pub fn create_distance_inherent_data_provider<B, C, Backend /*, ValidatorId*/>( + 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, + //ValidatorId: Decode, +{ + let &[owner_key] = owner_keys else { + return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new( + //distance_dir, + None + )) + }; + let owner_key = sp_runtime::AccountId32::new(owner_key.0); + + // TODO: + // * dc_distance::create_distance_inherent_data_provider(client_clone, parent, distance_dir) + // * est-ce qu'on a déjà publié un résultat ce round + // * avec storage provider dans client_clone: + // * récupérer liste des forgerons ayant publié résultat ce round + // * palette session: dans KeyOwner: récupérer notre clé forgeron à partir d'une de nos session_keys + // * sinon, pour quel round on veut un résultat + // * current_round_index dans storage provider (ou session index) + + 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>, // TODO document this limit + ConstU32<100>, + >::decode(&mut &raw.0[..]) + .expect("cannot decode EvaluationPool") + }); + + // Have we already published a result for this session? + for evaluator in published_results.1.iter() { + if evaluator == &owner_key { + return Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new( + //distance_dir, + None, + )); + } + } + + // Read evaluation result from file, if it exists + let mut 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( + //distance_dir, + None, + )); + } + }; + + /*let owner_key = ValidatorId::decode( + &mut &client + .storage( + &parent, + &StorageKey( + frame_support::storage::storage_prefix(b"Session", b"OwnerKey").to_vec(), + ), + )? + .expect("no Session::OwnerKey") + .0[..], + ) + .expect("cannot decode ValidatorId");*/ + + // TODO pour trouver session key: voir keystore + // node/src/command/key.rs + // Trouver la bonne clé avec SyncCryptoStore::sr25519_public_keys + // Trouver l'IdtyId correspondant + // Le metttre dans un OnceCell<IdtyId> + // Note : si l'IdtyId forgeron change sans redémarrer le nœud, les inhérents seront invalides + + Ok(sp_distance::InherentDataProvider::<IdtyIndex>::new( + //distance_dir, + 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..5c9952269 --- /dev/null +++ b/distance-oracle/Cargo.toml @@ -0,0 +1,17 @@ +[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" } +tokio = { version = "1.15.0", features = ["rt-multi-thread", "macros", "time"] } diff --git a/distance-oracle/src/main.rs b/distance-oracle/src/main.rs new file mode 100644 index 000000000..4c43bef1c --- /dev/null +++ b/distance-oracle/src/main.rs @@ -0,0 +1,241 @@ +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; + +#[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; + +#[tokio::main] +async fn main() { + let min_certs: u32 = 5; + + let client = Client::new().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_pool0(), + 1 => gdev::storage().distance().evaluation_pool1(), + 2 => gdev::storage().distance().evaluation_pool2(), + _ => unreachable!("n%3<3"), + }, + Some(parent_hash), + ) + .await + .unwrap() else { + // Nothing to do + return + }; + + // Stop if nothing to evaluate + if evaluation_pool.0 .0.is_empty() { + return; + } + + let evaluation_result_dir = PathBuf::from("/tmp/duniter/chains/gdev/distance"); + let evaluation_result_path = evaluation_result_dir.join((current_session + 1).to_string()); + + // Stop if already evaluated + if evaluation_result_path.try_exists().unwrap() { + return; + } + + let evaluation_block = client + .storage() + .fetch( + &gdev::storage().distance().evaluation_block(), + Some(parent_hash), + ) + .await + .unwrap() + .unwrap(); + + std::fs::create_dir_all(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 >= min_certs { + 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 >= min_certs); + let referees = members; + + let evaluation: Vec<Perbill> = evaluation_pool + .0 + .0 + .into_par_iter() + .map(|(idty, _)| { + Perbill::from_rational( + distance_rule(&received_certs, &referees, min_certs, 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( + &sp_distance::ComputationResult { + distances: evaluation, + } + .encode(), + ) + .unwrap(); +} + +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/node/src/rpc.rs b/node/src/rpc.rs index 36dee008a..1284d65c8 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -24,13 +24,13 @@ pub use sc_rpc_api::DenyUnsafe; use common_runtime::Block; -use common_runtime::{AccountId, Balance, Index}; +use common_runtime::{AccountId, Balance, IdtyIndex, Index}; use jsonrpsee::RpcModule; use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use std::sync::Arc; +use std::{path::PathBuf, sync::Arc}; /// Full client dependencies. pub struct FullDeps<C, P> { @@ -43,6 +43,8 @@ pub struct FullDeps<C, P> { /// Manual seal command sink pub command_sink_opt: Option<futures::channel::mpsc::Sender<manual_seal::EngineCommand<sp_core::H256>>>, + pub distance_dir: PathBuf, + //pub owner_key: Option<ValidatorId>, } /// Instantiate all full RPC extensions. @@ -54,11 +56,13 @@ where C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static, C: Send + Sync + 'static, C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>, + C::Api: pallet_distance_rpc::DistanceRuntimeApi<Block, IdtyIndex>, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>, C::Api: BlockBuilder<Block>, P: TransactionPool + 'static, { use manual_seal::rpc::{ManualSeal, ManualSealApiServer}; + use pallet_distance_rpc::{Distance, DistanceApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use substrate_frame_rpc_system::{System, SystemApiServer}; @@ -68,10 +72,12 @@ where pool, deny_unsafe, command_sink_opt, + distance_dir, + //owner_key, } = deps; module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; - module.merge(TransactionPayment::new(client).into_rpc())?; + module.merge(TransactionPayment::new(client.clone()).into_rpc())?; if let Some(command_sink) = command_sink_opt { // We provide the rpc handler with the sending end of the channel to allow the rpc @@ -83,6 +89,13 @@ where // `YourRpcStruct` should have a reference to a client, which is needed // to call into the runtime. // `module.merge(YourRpcTrait::into_rpc(YourRpcStruct::new(ReferenceToClient, ...)))?;` + /*module.merge(DistanceApiServer::into_rpc( + Distance::new( + client, + distance_dir, + ), + ))?;*/ + module.merge(Distance::new(client, distance_dir).into_rpc())?; Ok(module) } diff --git a/node/src/service.rs b/node/src/service.rs index 30edcb7ae..b6afb0025 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>>; @@ -430,6 +430,15 @@ where let enable_grandpa = !config.disable_grandpa; let prometheus_registry = config.prometheus_registry().cloned(); + let distance_dir = config.base_path.as_ref().map_or_else( + || PathBuf::from("/tmp"), + |base_path| { + base_path + .config_dir(config.chain_spec.id()) + .join("distance") + }, + ); // TODO improve this + let mut command_sink_opt = None; if role.is_authority() { let proposer_factory = sc_basic_authorship::ProposerFactory::new( @@ -521,6 +530,8 @@ where } else { let client_clone = client.clone(); let slot_duration = babe_link.config().slot_duration(); + let distance_dir = distance_dir.clone(); + let sync_cryptostore_ptr = keystore_container.sync_keystore(); let babe_config = babe::BabeParams { keystore: keystore_container.sync_keystore(), client: client.clone(), @@ -530,7 +541,16 @@ where sync_oracle: network.clone(), justification_sync_link: network.clone(), create_inherent_data_providers: move |parent, ()| { + // This closure is called during each block generation. + let client_clone = client_clone.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"), + )); + let babe_owner_keys_ref = babe_owner_keys.clone(); async move { let uncles = sc_consensus_uncles::create_uncles_inherent_data_provider( @@ -546,7 +566,19 @@ where slot_duration, ); - Ok((slot, timestamp, uncles)) + let distance = dc_distance::create_distance_inherent_data_provider::< + Block, + FullClient<RuntimeApi, Executor>, + FullBackend, + //common_runtime::AccountId, + >( + &*client_clone, + parent, + distance_dir, + &babe_owner_keys_ref.clone(), + )?; + + Ok((slot, timestamp, uncles, distance)) } }, force_authoring, @@ -574,6 +606,7 @@ where let pool = transaction_pool.clone(); //let select_chain = select_chain.clone(); //let chain_spec = config.chain_spec.cloned_box(); + let distance_dir = distance_dir.clone(); Box::new(move |deny_unsafe, _| { let deps = crate::rpc::FullDeps { @@ -588,6 +621,7 @@ where keystore: keystore.clone(), },*/ command_sink_opt: command_sink_opt.clone(), + distance_dir: distance_dir.clone(), }; crate::rpc::create_full(deps).map_err(Into::into) diff --git a/node/src/service/client.rs b/node/src/service/client.rs index 16cb4b412..4614d1023 100644 --- a/node/src/service/client.rs +++ b/node/src/service/client.rs @@ -14,7 +14,7 @@ // 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 common_runtime::{AccountId, Balance, Block, BlockNumber, Hash, Header, Index}; +use common_runtime::{AccountId, Balance, Block, BlockNumber, Hash, Header, IdtyIndex, Index}; use sc_client_api::{AuxStore, Backend as BackendT, BlockchainEvents, KeyIterator, UsageProvider}; use sp_api::{CallApiAt, NumberFor, ProvideRuntimeApi}; use sp_blockchain::{HeaderBackend, HeaderMetadata}; @@ -113,6 +113,7 @@ pub trait ExecuteWithClient { /// that it contains. pub trait RuntimeApiCollection: pallet_grandpa::fg_primitives::GrandpaApi<Block> + + pallet_distance_rpc_runtime_api::DistanceApi<Block, IdtyIndex> + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> + sp_api::ApiExt<Block> + sp_authority_discovery::AuthorityDiscoveryApi<Block> @@ -130,6 +131,7 @@ where impl<Api> RuntimeApiCollection for Api where Api: pallet_grandpa::fg_primitives::GrandpaApi<Block> + + pallet_distance_rpc_runtime_api::DistanceApi<Block, IdtyIndex> + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> + sp_api::ApiExt<Block> + sp_authority_discovery::AuthorityDiscoveryApi<Block> diff --git a/pallets/authority-members/src/lib.rs b/pallets/authority-members/src/lib.rs index 22865875f..cca644b64 100644 --- a/pallets/authority-members/src/lib.rs +++ b/pallets/authority-members/src/lib.rs @@ -30,14 +30,14 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; +pub use self::traits::*; pub use pallet::*; +pub use sp_staking::SessionIndex; 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..fe00b84a5 --- /dev/null +++ b/pallets/distance/Cargo.toml @@ -0,0 +1,85 @@ +[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', + 'frame-system/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/rpc/Cargo.toml b/pallets/distance/rpc/Cargo.toml new file mode 100644 index 000000000..447945bf5 --- /dev/null +++ b/pallets/distance/rpc/Cargo.toml @@ -0,0 +1,64 @@ +[package] +authors = ['tuxmain <tuxmain@zettascript.org>'] +description = 'FRAME pallet distance RPC.' +edition = '2021' +homepage = 'https://duniter.org' +license = 'AGPL-3.0' +name = 'pallet-distance-rpc' +readme = 'README.md' +repository = 'https://git.duniter.org/nodes/rust/duniter-v2s' +version = '1.0.0' + +[dependencies] + +pallet-distance-rpc-runtime-api = { path = "./runtime-api" } +sp-distance = { path = "../../../primitives/distance" } + +base64 = "0.13.1" +serde = { version = "1.0", features = ["derive"] } + +# substrate +jsonrpsee = { version = "0.15.1", features = ["server", "macros"] } +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.frame-system] +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-api] +git = 'https://github.com/duniter/substrate' +branch = 'duniter-substrate-v0.9.32' + +[dependencies.sp-blockchain] +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-rpc] +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' + +[dependencies.sp-std] +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/rpc/runtime-api/Cargo.toml b/pallets/distance/rpc/runtime-api/Cargo.toml new file mode 100644 index 000000000..7b0b463ce --- /dev/null +++ b/pallets/distance/rpc/runtime-api/Cargo.toml @@ -0,0 +1,32 @@ +[package] +authors = ['tuxmain <tuxmain@zettascript.org>'] +description = 'FRAME pallet distance RPC runtime API.' +edition = '2021' +homepage = 'https://duniter.org' +license = 'AGPL-3.0' +name = 'pallet-distance-rpc-runtime-api' +readme = 'README.md' +repository = 'https://git.duniter.org/nodes/rust/duniter-v2s' +version = '1.0.0' + +[dependencies] +pallet-distance = { path = "../../", default-features = false } +sp-api = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32", default-features = false } +sp-runtime = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32", default-features = false } + +[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' + +[features] +default = ["std"] +std = [ + "sp-api/std", +] diff --git a/pallets/distance/rpc/runtime-api/src/lib.rs b/pallets/distance/rpc/runtime-api/src/lib.rs new file mode 100644 index 000000000..71aa3f922 --- /dev/null +++ b/pallets/distance/rpc/runtime-api/src/lib.rs @@ -0,0 +1,31 @@ +// 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/>. + +#![cfg_attr(not(feature = "std"), no_std)] + +pub use pallet_distance::{ComputationMetadata, ComputationResult}; + +use codec::{Decode, Encode}; +use frame_support::pallet_prelude::*; + +// Here we declare the runtime API. It is implemented it the `impl` block in +// runtime amalgamator file (the `runtime/src/lib.rs`) +sp_api::decl_runtime_apis! { + pub trait DistanceApi<IdtyIndex: Decode + Encode + PartialEq + TypeInfo> { + fn get_computation_metadata() -> Option<ComputationMetadata>; + //fn publish_computation_result(computation_result: ComputationResult<IdtyIndex>); + } +} diff --git a/pallets/distance/rpc/src/lib.rs b/pallets/distance/rpc/src/lib.rs new file mode 100644 index 000000000..31e1a74ff --- /dev/null +++ b/pallets/distance/rpc/src/lib.rs @@ -0,0 +1,177 @@ +// 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 std::sync::Arc; + +use codec::{Decode, Encode}; +use frame_support::pallet_prelude::*; +use jsonrpsee::{ + core::{async_trait, RpcResult}, + proc_macros::rpc, + types::error::{CallError, ErrorObject}, +}; +use serde::{Deserialize, Serialize}; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; +use sp_runtime::{generic::BlockId, traits::Block as BlockT}; +use std::{io::Write, path::PathBuf}; + +pub use pallet_distance_rpc_runtime_api::{ComputationResult, DistanceApi as DistanceRuntimeApi}; + +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ComputationMetadata /*<Hash>*/ { + //pub block_hash: Hash, +} + +impl From<pallet_distance_rpc_runtime_api::ComputationMetadata> for ComputationMetadata { + fn from(_val: pallet_distance_rpc_runtime_api::ComputationMetadata) -> Self { + Self {} + } +} + +/*#[derive(Clone, Serialize, Deserialize)] +pub struct ComputationResult { + +} + +impl Into<pallet_distance_rpc_runtime_api::ComputationResult> for ComputationResult { + fn into(self) -> pallet_distance_rpc_runtime_api::ComputationResult { + pallet_distance_rpc_runtime_api::ComputationResult{} + } +}*/ + +#[rpc(client, server)] +pub trait DistanceApi<BlockHash, ResponseType> { + #[method(name = "distance_getComputationMetadata")] + fn get_computation_metadata( + &self, + at: Option<BlockHash>, + ) -> RpcResult<Option<ComputationMetadata>>; + #[method(name = "distance_publishComputationResult")] + fn publish_computation_result( + &self, + encoded_computation_result: String, //Bytes, + /*at: Option<BlockHash>,*/ + ) -> RpcResult<ResponseType>; +} + +/// Provides RPC methods to query a dispatchable's class, weight and fee. +pub struct Distance<C, P> { + /// Shared reference to the client. + client: Arc<C>, + computation_result_dir: PathBuf, + _marker: std::marker::PhantomData<P>, +} + +impl<C, P> Distance<C, P> { + /// Creates a new instance of the Distance Rpc helper. + pub fn new(client: Arc<C>, computation_result_dir: PathBuf) -> Self { + Self { + client, + computation_result_dir, + _marker: Default::default(), + } + } +} + +/// Error type of this RPC api. +pub enum Error { + /// The transaction was not decodable. + DecodeError, + /// The call to runtime failed. + RuntimeError, +} + +impl From<Error> for i32 { + fn from(e: Error) -> i32 { + match e { + Error::RuntimeError => 1, + Error::DecodeError => 2, + } + } +} + +#[async_trait] +impl<C, Block, IdtyIndex: 'static + Decode + Encode + PartialEq + Send + Sync + TypeInfo> + DistanceApiServer<<Block as BlockT>::Hash, ()> for Distance<C, (Block, IdtyIndex)> +where + Block: BlockT, + C: ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static, + C::Api: DistanceRuntimeApi<Block, IdtyIndex>, +{ + fn get_computation_metadata( + &self, + at: Option<Block::Hash>, + ) -> RpcResult<Option<ComputationMetadata>> { + let api = self.client.runtime_api(); + let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); + + api.get_computation_metadata(&at).map_or_else( + |e| { + Err(CallError::Custom(ErrorObject::owned( + Error::RuntimeError.into(), + "Unable to query dispatch info.", + Some(e.to_string()), + )) + .into()) + }, + |v| Ok(v.map(Into::into)), + ) + } + fn publish_computation_result( + &self, + encoded_computation_result: String, //Bytes, + /*at: Option<Block::Hash>,*/ + ) -> RpcResult<()> { + //let api = self.client.runtime_api(); + //let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash)); + + let encoded_computation_result = + base64::decode(encoded_computation_result).map_err(|e| { + CallError::Custom(ErrorObject::owned( + Error::DecodeError.into(), + "Bad encoding.", + Some(format!("{:?}", e)), + )) + })?; + + let computation_result: ComputationResult = + Decode::decode(&mut &*encoded_computation_result).map_err(|e| { + CallError::Custom(ErrorObject::owned( + Error::DecodeError.into(), + "Unable to query dispatch info.", + Some(format!("{:?}", e)), + )) + })?; + /*api.publish_computation_result(&at, computation_result) + .map_err(|e| { + CallError::Custom(ErrorObject::owned( + Error::RuntimeError.into(), + "Unable to query dispatch info.", + Some(e.to_string()), + )) + .into() + })?;*/ + std::fs::create_dir_all(&self.computation_result_dir)?; + let mut file = std::fs::File::create(self.computation_result_dir.join("result"))?; + file.write(&Encode::encode(&computation_result))?; + + Ok(()) + + //sp_distance::InherentDataProvider::from_computation_result(computation_result); + //todo!() + } +} diff --git a/pallets/distance/src/lib.rs b/pallets/distance/src/lib.rs new file mode 100644 index 000000000..079c9a648 --- /dev/null +++ b/pallets/distance/src/lib.rs @@ -0,0 +1,515 @@ +// 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 types; + +use median::*; +pub use pallet::*; +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::*; + 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 + { + /// Number of sessions before starting a new computation + type FinalityLag: Get<u32>; + /// Duration of a computation (in sessions) + type ComputationMaxDelay: Get<u32>; + // /// Maximum number of identities in the evaluation queue + //type QueueSize: Get<Option<u32>>; + /// 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>; + /// Because this pallet emits events, it depends on the runtime's definition of an event. + type RuntimeEvent: From<Event<Self, I>> + + IsType<<Self as frame_system::Config>::RuntimeEvent>; + } + + // STORAGE // + + /*#[pallet::storage] + pub type NextComputationMetadata<T: Config<I>, I: 'static = ()> = StorageValue< + _, + ComputationMetadata, + OptionQuery, + GetDefault, + >;*/ + + /*/// Identities to be evaluated in next sessions + #[pallet::storage] + pub type EvaluationQueue<T: Config<I>, I: 'static = ()> = StorageValue< + _, + BoundedVec<<T as pallet_certification::Config<I>>::IdtyIndex, T::MaxEvaluationsPerSession>, + ValueQuery, + >;*/ + + /*#[pallet::storage] + pub type IdentitiesBeingEvaluated<T: Config<I>, I: 'static = ()> = + StorageValue<_, Vec<<T as pallet_certification::Config<I>>::IdtyIndex>, OptionQuery>;*/ + + // /// Number of evaluators coming up with some value. + // /// Indexed by identity index, then by value. + //#[pallet::storage] + /*pub type EvaluatedIdentities<T: Config<I>, I: 'static = ()> = StorageMap< + _, + Twox64Concat, + <T as pallet_certification::Config<I>>::IdtyIndex, + MedianAcc<Perbill>, + OptionQuery, + GetDefault, + >;*/ + /*pub type StoragePublishedResults<T: Config<I>, I: 'static = ()> = StorageValue< + _, + //PublishedResults<<T as pallet_certification::Config<I>>::IdtyIndex, T::MaxEvaluationsPerSession, T::MaxEvaluatorsPerSession>, + ( + BoundedVec< + ( + <T as pallet_certification::Config<I>>::IdtyIndex, + MedianAcc<Perbill>, + ), + T::MaxEvaluationsPerSession, + >, + BoundedVec<T::AccountId, T::MaxEvaluatorsPerSession>, + ), + ValueQuery, + >;*/ + // TODO 3 storages qu'on lit en fonction de session index % 3 + + /*/// Number of evaluators coming up with some referee count, indexed by referee count. + #[pallet::storage] + pub type Referees<T: Config<I>, I: 'static = ()> = StorageValue<_, MedianAcc<u32>, OptionQuery>;*/ + + /*pub type EvaluationPool<T, I = ()> = ( + BoundedVec< + ( + <T as pallet_certification::Config<I>>::IdtyIndex, + MedianAcc<Perbill>, + ), + <T as Config<I>>::MaxEvaluationsPerSession, + >, + BoundedVec< + <T as frame_system::Config>::AccountId, + <T as Config<I>>::MaxEvaluatorsPerSession, + >, + );*/ + pub type EvaluationPool< + AccountId, + IdtyIndex, + MaxEvaluationsPerSession, + MaxEvaluatorsPerSession, + > = ( + BoundedVec<(IdtyIndex, MedianAcc<Perbill>), MaxEvaluationsPerSession>, + BoundedVec<AccountId, MaxEvaluatorsPerSession>, + ); + + /*#[pallet::storage] + pub type EvaluationPool0<T: Config<I>, I: 'static = ()> = + StorageValue<_, EvaluationPool<T, I>, ValueQuery>; + #[pallet::storage] + pub type EvaluationPool1<T: Config<I>, I: 'static = ()> = + StorageValue<_, EvaluationPool<T, I>, ValueQuery>; + #[pallet::storage] + pub type EvaluationPool2<T: Config<I>, I: 'static = ()> = + StorageValue<_, EvaluationPool<T, I>, ValueQuery>;*/ + #[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, + >; + + #[pallet::storage] + pub type EvaluationBlock<T: Config<I>, I: 'static = ()> = + StorageValue<_, <T as frame_system::Config>::Hash, ValueQuery>; + + // TODO replace bool by nothing or smth else + #[pallet::storage] + #[pallet::getter(fn distance_ok_identities)] + pub type DistanceOkIdentities<T: Config<I>, I: 'static = ()> = StorageMap< + _, + Twox64Concat, + <T as pallet_certification::Config<I>>::IdtyIndex, + 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) + + // EVENTS // + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event<T: Config<I>, I: 'static = ()> { + /// Outdistanced + /// [idty] + Outdistanced { + idty: <T as pallet_certification::Config<I>>::IdtyIndex, + }, + /// Distance OK + /// [idty] + DistanceOk { + idty: <T as pallet_certification::Config<I>>::IdtyIndex, + }, + } + + // ERRORS // + + #[pallet::error] + pub enum Error<T, I = ()> { + IdentityNotInEvaluation, + IdtyNotFound, + NonEligibleForEvaluation, + QueueFull, + TooManyEvaluators, + UnauthorizedIdentity, + WrongResultLength, + } + + #[pallet::hooks] + impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {} + + // 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>, + idty_index: <T as pallet_certification::Config<I>>::IdtyIndex, + ) -> DispatchResultWithPostInfo { + let _who = ensure_signed(origin)?; + // TODO check whether origin is authorized to request evaluation + + Pallet::<T, I>::do_evaluate_distance(idty_index)?; + 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, /*<<T as pallet_identity::Config>::IdtyIndex>*/ + ) -> DispatchResult { + ensure_none(origin)?; + //assert!(!DidUpdate::<T>::exists(), "At most one distance computation result can be submitted per block"); + + // TODO is it better to read and only write when needed, or to write in all cases, even if nothing is actually written? + + Pallet::<T, I>::mutate_result_pool( + pallet_session::CurrentIndex::<T>::get(), + |result_pool| { + ensure!( + computation_result.distances.len() == result_pool.0.len(), + Error::<T, I>::WrongResultLength + ); + + result_pool + .1 + .try_push( + pallet_authorship::Pallet::<T>::author() + .expect("Block author is needed to update distance evaluation"), + ) + .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); + /*try_mutate::<_, _, Error<T, I>, _>( + identity, + |median_acc| { + median_acc + .as_mut() + .ok_or(Error::<T, I>::IdentityNotInEvaluation)? + .push(result); + Ok(()) + }, + )?;*/ + } + + Ok(()) + }, + ) + } + } + + // PUBLIC FUNCTIONS // + + impl<T: Config<I>, I: 'static> Pallet<T, I> { + pub fn get_computation_metadata( + ) -> Option<ComputationMetadata /*<<T as frame_system::Config>::Hash>*/> { + None + } + /*pub fn publish_computation_result( + _computation_result: ComputationResult<<T as pallet_identity::Config>::IdtyIndex>, + ) { + }*/ + + pub fn do_evaluate_distance( + idty_index: <T as pallet_certification::Config<I>>::IdtyIndex, + ) -> Result<(), DispatchError> { + // TODO (maybe) check whether identity is already in queue + + 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 + ); + + ensure!( + pallet_identity::Identities::<T>::contains_key(idty_index), + Error::<T, I>::IdtyNotFound + ); + + 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. + 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"), + } + } + + /// Mutate the evaluation pool containing the results to be applied on the next session. + fn mutate_result_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 => EvaluationPool1::<T, I>::mutate, + 1 => EvaluationPool2::<T, I>::mutate, + 2 => EvaluationPool0::<T, I>::mutate, + _ => panic!("index % 3 < 3"), + })(f) + } + } + + 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. + 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() { + 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() { + Self::deposit_event(Event::DistanceOk { idty }); + DistanceOkIdentities::<T, I>::insert(idty, true); + } else { + Self::deposit_event(Event::Outdistanced { idty }); + } + } + } + + // TODO roll between the 3 states simultaneously + /*match index % 3 { + 0 => { + /*EvaluationQueue::<T, I>::drain() + .zip(0..<T as Config<I>>::MaxEvaluationsPerSession::get()) + .map(|((identity, _), _)| identity) + .for_each(|identity| { + EvaluatedIdentities::<T, I>::insert(identity, MedianAcc::new()) + });*/ + Pallet::get_open_pool(index) + .0 + .into_iter() + .for_each(|identity| { + Pallet::get_result_pool(index) + .0 + .try_push((identity, MedianAcc::new())) + .expect("unreachable") + }); + } + 1 => {} + 2 => { + for (_identity, median_acc) in + Pallet::get_result_pool(index).0.into_iter() + { + 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() { + todo!(); + } else { + todo!(); + } + } + } + } + _ => unreachable!("index % 3 < 3"), + }*/ + 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/*<<T as pallet_identity::Config>::IdtyIndex>*/>( + &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/types.rs b/pallets/distance/src/types.rs new file mode 100644 index 000000000..6eecd2513 --- /dev/null +++ b/pallets/distance/src/types.rs @@ -0,0 +1,63 @@ +// 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 crate::median::MedianAcc; + +pub use sp_distance::ComputationResult; + +use codec::{Decode, Encode}; +use frame_support::pallet_prelude::*; +use sp_inherents::IsFatalError; +//use sp_runtime::Perbill; +//use sp_std::vec::Vec; + +#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug, TypeInfo)] +pub struct ComputationMetadata /*<Hash>*/ { + //pub block_hash: Hash, +} + +// TODO solve this! -> MaxEncodedLen +/*#[derive(Encode, Decode, TypeInfo)] +pub struct PublishedResults<IdtyIndex, MaxEvaluationsPerSession, MaxEvaluatorsPerSession> { + pub distances: BoundedVec< + ( + IdtyIndex, + MedianAcc<Perbill>, + ), + MaxEvaluationsPerSession, + >, + pub evaluators: BoundedVec<IdtyIndex, MaxEvaluatorsPerSession>, +} + +impl<IdtyIndex, MaxEvaluationsPerSession, MaxEvaluatorsPerSession> Default for PublishedResults<IdtyIndex, MaxEvaluationsPerSession, MaxEvaluatorsPerSession> { + fn default() -> Self { + Self { + distances: Default::default(), + evaluators: Default::default(), + } + } +}*/ + +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] +pub enum InherentError { + Foo, +} + +impl IsFatalError for InherentError { + fn is_fatal_error(&self) -> bool { + false + } +} 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..b9c585525 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 { @@ -385,3 +393,13 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::OnRemovedCert<IdtyI Weight::zero() } } + +/*impl<T: Config<I>, I: 'static> pallet_distance::traits::OnEvent<T, I> for Pallet<T, I> { + fn on_event(distance_event: &pallet_distance::Event<T, I>) -> Weight { + match distance_event { + pallet_distance::Event::<T, I>::DistanceOk(idty) => {} + pallet_distance::Event::<T, I>::Outdistanced(_) => {} + } + Weight::zero() + } +}*/ diff --git a/pallets/duniter-wot/src/traits.rs b/pallets/duniter-wot/src/traits.rs new file mode 100644 index 000000000..15aacce1d --- /dev/null +++ b/pallets/duniter-wot/src/traits.rs @@ -0,0 +1,30 @@ +// Copyright 2021 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 crate::*; +use frame_support::pallet_prelude::*; + +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..1df53fe5d --- /dev/null +++ b/primitives/distance/src/lib.rs @@ -0,0 +1,133 @@ +// 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/>. + +//! 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 /*<IdtyIndex: Decode + Encode + PartialEq + TypeInfo>*/ { + pub distances: Vec<Perbill>, +} + +/*pub enum Event<IdtyId, MetaData = ()> { +}*/ + +#[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: ComputationResult<IdtyIndex>, + //computation_result_dir: PathBuf, + //result_expected_for_round: Option<u32>, // TODO (None => soit 2 premiers rounds, soit déjà publié) + computation_result: Option<ComputationResult>, + _p: PhantomData<IdtyIndex>, +} + +#[cfg(feature = "std")] +impl<IdtyIndex: Decode + Encode + PartialEq + TypeInfo> InherentDataProvider<IdtyIndex> { + /*pub fn from_computation_result(computation_result: ComputationResult<IdtyIndex>, computation_result_dir: PathBuf) -> Self { + Self { computation_result, computation_result_dir } + }*/ + pub fn new( + /*computation_result_dir: PathBuf*/ computation_result: Option<ComputationResult>, + ) -> Self { + Self { + //computation_result_dir, + 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> { + // TODO check whether to do something: check if round corresponds between file and self.expected_round + + // TODO match error + /*if let Ok(file) = std::fs::File::open(self.computation_result_dir.join("result")) { + let mut reader = codec::IoReader(file); + // TODO remove unwrap + inherent_data.put_data( + INHERENT_IDENTIFIER, + &ComputationResult::decode(&mut reader).unwrap(), + )?; + }*/ + 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; + } + + match InherentError::try_from(&INHERENT_IDENTIFIER, error)? { + o => Some(Err(sp_inherents::Error::Application(Box::from(o)))), + } + } +} diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 203a9fd6c..110092111 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,8 @@ std = [ 'pallet-babe/std', 'pallet-balances/std', 'pallet-certification/std', + 'pallet-distance/std', + 'pallet-distance-rpc-runtime-api/std', 'pallet-duniter-account/std', 'pallet-duniter-wot/std', 'pallet-grandpa/std', @@ -50,26 +52,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', ] 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-distance-rpc-runtime-api = { path = "../../pallets/distance/rpc/runtime-api", 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 } @@ -79,12 +84,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/apis.rs b/runtime/common/src/apis.rs index e31d84d6a..38b79c837 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -208,6 +208,14 @@ macro_rules! runtime_apis { TransactionPayment::query_fee_details(uxt, len) } } + impl pallet_distance_rpc_runtime_api::DistanceApi<Block, u32> for Runtime { + fn get_computation_metadata() -> Option<pallet_distance_rpc_runtime_api::ComputationMetadata/*<<T as frame_system::Config>::Hash>*/> { + Distance::get_computation_metadata() + } + /*fn publish_computation_result(computation_result: pallet_distance_rpc_runtime_api::ComputationResult<u32>) { + //Distance::publish_computation_result(computation_result) + }*/ + } #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime<Block> for Runtime where <Runtime as frame_system::Config>::BlockNumber: Clone + sp_std::fmt::Debug + sp_runtime::traits::AtLeast32BitUnsigned { 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 3aa82401a..b01d3c6bf 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -425,6 +425,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; @@ -474,12 +475,26 @@ 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 IdtyIndex: IdtyIndex; + type FinalityLag = frame_support::traits::ConstU32<1>; + type ComputationMaxDelay = frame_support::traits::ConstU32<1>; + //type QueueSize = frame_support::traits::ConstU32<800>; + type MaxEvaluationsPerSession = frame_support::traits::ConstU32<100>; + type MaxEvaluatorsPerSession = frame_support::traits::ConstU32<100>;// TODO <= number of blocks per session + type MinAccessibleReferees = MinAccessibleReferees; + type RuntimeEvent = RuntimeEvent; + } // 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..8597a3164 100644 --- a/runtime/common/src/providers.rs +++ b/runtime/common/src/providers.rs @@ -106,3 +106,17 @@ 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 { + true // TODO + } +} diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml index a30d763c4..52008cc89 100644 --- a/runtime/gdev/Cargo.toml +++ b/runtime/gdev/Cargo.toml @@ -64,6 +64,8 @@ std = [ 'pallet-balances/std', 'pallet-certification/std', 'pallet-collective/std', + 'pallet-distance/std', + 'pallet-distance-rpc-runtime-api/std', 'pallet-duniter-test-parameters/std', 'pallet-duniter-account/std', 'pallet-duniter-wot/std', @@ -95,6 +97,7 @@ 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 +141,8 @@ 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-distance-rpc-runtime-api = { path = "../../pallets/distance/rpc/runtime-api", 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 } @@ -148,6 +153,7 @@ 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 diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 90350ab3d..514b268e5 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, Event<T>} = 44, // Smith Sub-Wot SmithSubWot: pallet_duniter_wot::<Instance2>::{Pallet} = 50, -- GitLab