diff --git a/Cargo.lock b/Cargo.lock index b44e85313..a93956647 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,7 +151,11 @@ dependencies = [ [[package]] name = "amcl" version = "0.3.0" -source = "git+https://github.com/Snowfork/milagro_bls#bc2b5b5e8d48b7e2e1bfaa56dc2d93e13cb32095" +source = "git+https://github.com/Snowfork/milagro_bls#7d1776edb42870b006430ece9741c15811e4c9e3" +dependencies = [ + "parity-scale-codec 3.5.0", + "scale-info", +] [[package]] name = "android_system_properties" @@ -173,9 +177,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6342bd4f5a1205d7f41e94a41a901f5647c938cdfa96036338e8533c9d6c2450" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" dependencies = [ "anstyle", "anstyle-parse", @@ -222,9 +226,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" [[package]] name = "array-init" @@ -479,9 +483,9 @@ dependencies = [ [[package]] name = "auto_impl" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a8c1df849285fbacd587de7818cc7d13be6cd2cbcd47a04fb1801b0e2706e33" +checksum = "fee3da8ef1276b0bee5dd1c7258010d8fffd31801447323115a25560e1327b89" dependencies = [ "proc-macro-error", "proc-macro2", @@ -550,15 +554,6 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" -[[package]] -name = "base64-compat" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a8d4d2746f89841e49230dd26917df1876050f95abafafbe34f47cb534b88d7" -dependencies = [ - "byteorder", -] - [[package]] name = "base64ct" version = "1.6.0" @@ -770,9 +765,9 @@ checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" [[package]] name = "bumpalo" -version = "3.12.1" +version = "3.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8" +checksum = "3c6ed94e98ecff0c12dd1b04c15ec0d7d9458ca8fe806cea6f12954efe74c63b" [[package]] name = "byte-slice-cast" @@ -983,9 +978,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.2.4" +version = "4.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ac1f6381d8d82ab4684768f89c0ea3afe66925ceadb4eeb3fc452ffc55d62" +checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938" dependencies = [ "clap_builder", "clap_derive", @@ -994,9 +989,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.4" +version = "4.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84080e799e54cff944f4b4a4b0e71630b0e0443b25b985175c7dddc1a859b749" +checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd" dependencies = [ "anstream", "anstyle", @@ -1095,7 +1090,7 @@ dependencies = [ "serde", "serde_derive", "sha2 0.10.6", - "sha3 0.10.7", + "sha3 0.10.8", "thiserror", ] @@ -1691,7 +1686,7 @@ dependencies = [ "rand 0.8.5", "rlp 0.5.2", "serde", - "sha3 0.10.7", + "sha3 0.10.8", "zeroize", ] @@ -1756,7 +1751,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.6", - "sha3 0.10.7", + "sha3 0.10.8", "thiserror", "uuid", ] @@ -1845,7 +1840,7 @@ dependencies = [ "regex", "serde", "serde_json", - "sha3 0.10.7", + "sha3 0.10.8", "thiserror", "uint 0.9.5", ] @@ -2111,7 +2106,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1a9e0597aa6b2fdc810ff58bc95e4eeaa2c219b3e615ed025106ecb027407d8" dependencies = [ "async-trait", - "auto_impl 1.0.1", + "auto_impl 1.1.0", "base64 0.13.1", "ethers-core", "futures-core", @@ -2209,7 +2204,6 @@ dependencies = [ "trin-state", "trin-types", "trin-utils 0.1.1-alpha.1", - "uds_windows", "ureq", ] @@ -2323,9 +2317,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" dependencies = [ "crc32fast", "miniz_oxide", @@ -3074,7 +3068,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" dependencies = [ - "parity-scale-codec 3.4.0", + "parity-scale-codec 3.5.0", ] [[package]] @@ -3278,25 +3272,13 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "68c16e1bfd491478ab155fd8b4896b86f9ede344949b641e61501e07c2b8b4d5" dependencies = [ "wasm-bindgen", ] -[[package]] -name = "jsonrpc" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f8423b78fc94d12ef1a4a9d13c348c9a78766dda0cc18817adf0faf77e670c8" -dependencies = [ - "base64-compat", - "serde", - "serde_derive", - "serde_json", -] - [[package]] name = "jsonrpsee" version = "0.15.1" @@ -3652,14 +3634,14 @@ dependencies = [ "ecdsa", "elliptic-curve", "sha2 0.10.6", - "sha3 0.10.7", + "sha3 0.10.8", ] [[package]] name = "keccak" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" dependencies = [ "cpufeatures 0.2.7", ] @@ -3695,9 +3677,9 @@ dependencies = [ [[package]] name = "lalrpop" -version = "0.19.10" +version = "0.19.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ada7ece1f5bc6d36eec2a4dc204135f14888209b3773df8fefcfe990fd4cbc" +checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" dependencies = [ "ascii-canvas", "bit-set", @@ -3707,7 +3689,6 @@ dependencies = [ "itertools", "lalrpop-util", "petgraph", - "pico-args", "regex", "regex-syntax 0.6.29", "string_cache", @@ -3718,9 +3699,9 @@ dependencies = [ [[package]] name = "lalrpop-util" -version = "0.19.10" +version = "0.19.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3b45d694c8074f77bc24fc26e47633c862a9cd3b48dd51209c02ba4c434d68" +checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" dependencies = [ "regex", ] @@ -3751,9 +3732,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" [[package]] name = "libc" -version = "0.2.142" +version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" [[package]] name = "libloading" @@ -3803,9 +3784,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +checksum = "56ee889ecc9568871456d42f603d6a0ce59ff328d291063a45cbdf0036baf6db" dependencies = [ "cc", "libc", @@ -3851,9 +3832,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.3.4" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36eb31c1778188ae1e64398743890d0877fef36d11521ac60406b42016e8c2cf" +checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f" [[package]] name = "lock_api" @@ -3938,12 +3919,14 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "milagro_bls" version = "1.5.0" -source = "git+https://github.com/Snowfork/milagro_bls#bc2b5b5e8d48b7e2e1bfaa56dc2d93e13cb32095" +source = "git+https://github.com/Snowfork/milagro_bls#7d1776edb42870b006430ece9741c15811e4c9e3" dependencies = [ "amcl", "hex", "lazy_static", + "parity-scale-codec 3.5.0", "rand 0.8.5", + "scale-info", "zeroize", ] @@ -3971,9 +3954,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", ] @@ -4205,7 +4188,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" dependencies = [ "arrayvec", - "auto_impl 1.0.1", + "auto_impl 1.1.0", "bytes 1.4.0", "ethereum-types 0.14.1", "open-fastrlp-derive", @@ -4289,9 +4272,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac" +checksum = "5ddb756ca205bd108aee3c62c6d3c994e1df84a59b9d6d4a5ea42ee1fd5a9a28" dependencies = [ "arrayvec", "bitvec 1.0.1", @@ -4533,12 +4516,6 @@ dependencies = [ "siphasher", ] -[[package]] -name = "pico-args" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" - [[package]] name = "pin-project" version = "1.0.12" @@ -4583,9 +4560,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "polling" @@ -4672,7 +4649,6 @@ dependencies = [ "trin-types", "trin-utils 0.1.1-alpha.1", "trin-validation", - "uds_windows", "url", "utp-rs", "validator", @@ -4841,9 +4817,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" dependencies = [ "proc-macro2", ] @@ -5155,9 +5131,9 @@ checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" [[package]] name = "reqwest" -version = "0.11.16" +version = "0.11.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" +checksum = "13293b639a097af28fc8a90f22add145a9c954e49d77da06263d58cf44d5fb91" dependencies = [ "base64 0.21.0", "bytes 1.4.0", @@ -5198,7 +5174,7 @@ dependencies = [ [[package]] name = "reth-ipc" version = "0.1.0" -source = "git+https://github.com/paradigmxyz/reth.git#546e191e8a9f081f83c0a9357497b93d28fc0275" +source = "git+https://github.com/paradigmxyz/reth.git#33ea2523b7272497ba89b79fc38935ac4aa78f27" dependencies = [ "async-trait", "bytes 1.4.0", @@ -5426,9 +5402,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.15" +version = "0.37.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0661814f891c57c930a610266415528da53c4933e6dea5fb350cbfe048a9ece" +checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" dependencies = [ "bitflags", "errno", @@ -5503,21 +5479,22 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cfdffd972d76b22f3d7f81c8be34b2296afd3a25e0a547bd9abe340a4dbbe97" +checksum = "dfdef77228a4c05dc94211441595746732131ad7f6530c6c18f045da7b7ab937" dependencies = [ + "bitvec 1.0.1", "cfg-if 1.0.0", "derive_more", - "parity-scale-codec 3.4.0", + "parity-scale-codec 3.5.0", "scale-info-derive", ] [[package]] name = "scale-info-derive" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61fa974aea2d63dd18a4ec3a49d59af9f34178c73a4f56d2f18205628d00681e" +checksum = "53012eae69e5aa5c14671942a5dd47de59d4cdcff8532a6dd0e081faf1119482" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5652,9 +5629,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.160" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" dependencies = [ "serde_derive", ] @@ -5682,9 +5659,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.160" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" dependencies = [ "proc-macro2", "quote", @@ -5855,9 +5832,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c2bb1a323307527314a36bfb73f24febb08ce2b8a554bf4ffd6f51ad15198c" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ "digest 0.10.6", "keccak", @@ -6392,21 +6369,21 @@ dependencies = [ [[package]] name = "time" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" +checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc" dependencies = [ "itoa", "serde", "time-core", - "time-macros 0.2.8", + "time-macros 0.2.9", ] [[package]] name = "time-core" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" @@ -6420,9 +6397,9 @@ dependencies = [ [[package]] name = "time-macros" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36" +checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" dependencies = [ "time-core", ] @@ -6467,7 +6444,7 @@ dependencies = [ "ascii", "chunked_transfer", "log", - "time 0.3.20", + "time 0.3.21", "url", ] @@ -6488,9 +6465,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.28.0" +version = "1.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c786bf8134e5a3a166db9b29ab8f48134739014a3eca7bc6bfa95d673b136f" +checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105" dependencies = [ "autocfg 1.1.0", "bytes 1.4.0", @@ -6731,10 +6708,11 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.38" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9cf6a813d3f40c88b0b6b6f29a5c95c6cdbf97c1f9cc53fb820200f5ad814d" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ + "cfg-if 1.0.0", "log", "pin-project-lite", "tracing-attributes", @@ -6807,15 +6785,15 @@ version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b98abb9e7300b9ac902cc04920945a874c1973e08c310627cc4458c04b70dd32" dependencies = [ - "trackable 1.2.0", + "trackable 1.3.0", "trackable_derive", ] [[package]] name = "trackable" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "017e2a1a93718e4e8386d037cfb8add78f1d690467f4350fb582f55af1203167" +checksum = "b15bd114abb99ef8cee977e517c8f37aee63f184f2d08e3e6ceca092373369ae" dependencies = [ "trackable_derive", ] @@ -6857,7 +6835,7 @@ name = "trin" version = "0.1.0" dependencies = [ "anyhow", - "clap 4.2.4", + "clap 4.2.7", "discv5", "enr", "eth2_ssz", @@ -6879,6 +6857,7 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "trin-beacon", "trin-bridge", "trin-history", "trin-state", @@ -6914,7 +6893,7 @@ name = "trin-bridge" version = "0.1.0" dependencies = [ "anyhow", - "clap 4.2.4", + "clap 4.2.7", "discv5", "eth2_ssz", "eth2_ssz_derive", @@ -6933,25 +6912,6 @@ dependencies = [ "trin-validation", ] -[[package]] -name = "trin-cli" -version = "0.1.0" -dependencies = [ - "anyhow", - "base64 0.13.1", - "clap 4.2.4", - "ethereum-types 0.12.1", - "ethportal-api", - "jsonrpc", - "nanotemplate", - "serde", - "serde_json", - "thiserror", - "trin-types", - "trin-utils 0.1.1-alpha.1", - "ureq", -] - [[package]] name = "trin-history" version = "0.1.0" @@ -7012,7 +6972,7 @@ dependencies = [ "anyhow", "base64 0.13.1", "bytes 1.4.0", - "clap 2.34.0", + "clap 4.2.7", "discv5", "env_logger 0.9.3", "eth2_ssz", @@ -7023,6 +6983,7 @@ dependencies = [ "ethnum", "keccak-hash", "lazy_static", + "nanotemplate", "quickcheck", "rand 0.8.5", "rlp 0.5.2", @@ -7036,7 +6997,6 @@ dependencies = [ "sha3 0.9.1", "snap", "stremio-serde-hex", - "structopt", "test-log", "thiserror", "tokio", @@ -7116,16 +7076,6 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" -[[package]] -name = "uds_windows" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce65604324d3cce9b966701489fbd0cf318cb1f7bd9dd07ac9a4ee6fb791930d" -dependencies = [ - "tempfile", - "winapi 0.3.9", -] - [[package]] name = "uint" version = "0.4.1" @@ -7152,9 +7102,9 @@ dependencies = [ [[package]] name = "uncased" -version = "0.9.7" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" +checksum = "9b9bc53168a4be7402ab86c3aad243a84dd7381d09be0eddc81280c1da95ca68" dependencies = [ "version_check", ] @@ -7426,9 +7376,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "5b6cb788c4e39112fbe1822277ef6fb3c55cd86b95cb3d3c4c1c9597e4ac74b4" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -7436,24 +7386,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "35e522ed4105a9d626d885b35d62501b30d9666283a5c8be12c14a8bdafe7822" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.15", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +checksum = "083abe15c5d88556b77bdf7aef403625be9e327ad37c62c4e4129af740168163" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -7463,9 +7413,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "358a79a0cb89d21db8120cbfb91392335913e4890665b1a7981d9e956903b434" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7473,22 +7423,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "4783ce29f09b9d93134d41297aded3a712b7b979e9c6f28c32cb88c973a94869" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.15", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "a901d592cafaa4d711bc324edfaff879ac700b19c3dfd60058d2b445be2691eb" [[package]] name = "wasm-timer" @@ -7507,9 +7457,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "16b5f940c7edfdc6d12126d98c9ef4d1b3d470011c47c76a6581df47ad9ba721" dependencies = [ "js-sys", "wasm-bindgen", @@ -7735,9 +7685,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.1" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" +checksum = "61de7bac303dc551fe038e2b3cef0f571087a47571ea6e79a87692ac99b99699" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 6a0bb4856..9a247762b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ parking_lot = "0.11.2" portalnet = { path = "portalnet" } prometheus_exporter = "0.8.4" rand = "0.8.4" -reth-ipc = { version = "0.1.0", git = "https://github.com/paradigmxyz/reth.git"} rlp = "0.5.0" rocksdb = "0.18.0" rpc = { path = "rpc"} @@ -44,6 +43,9 @@ trin-utils = { path = "trin-utils" } trin-validation = { path = "trin-validation" } utp-rs = "0.1.0-alpha.4" +[target.'cfg(not(windows))'.dependencies] +reth-ipc = { version = "0.1.0", git = "https://github.com/paradigmxyz/reth.git"} + [dev-dependencies] ethportal-peertest = { path = "ethportal-peertest" } ureq = { version = "2.5.0", features = ["json"] } @@ -55,7 +57,6 @@ members = [ "light-client", "rpc", "trin-beacon", - "trin-cli", "trin-history", "trin-state", "trin-types", diff --git a/book/src/users/monitoring.md b/book/src/users/monitoring.md index 20586286d..a6563b683 100644 --- a/book/src/users/monitoring.md +++ b/book/src/users/monitoring.md @@ -39,7 +39,11 @@ htop ``` ## Metrics +[Metrics setup no docker](#metrics-setup-no-docker) +[Metrics setup with docker](#metrics-setup-with-docker) + +## Metrics setup no docker Prometheus maintains a database of metrics (trin & system). Grafana converts metrics into graphs. Node exporter provides system information. ```mermaid graph TD; @@ -234,7 +238,7 @@ This will serve metrics over port 3000. Generate a grafana dashboard. From trin root directory: ```sh -cargo run -p trin-cli -- create-dashboard +cargo run -p trin -- create-dashboard http://localhost:3000 admin admin http://127.0.0.1:9090 ``` This will create a new monitoring database for trin. This will be visible in the grafana GUI, or directly at a URL similar to: @@ -279,3 +283,31 @@ ssh -N -L 3000:127.0.0.1:3000 username@mycomputer Then navigate to [http://127.0.0.1:3000](http://127.0.0.1:3000)` in a browser and login with username: admin, password: admin. Then navigate to the trin-app-metrics dashboard. +## Metrics setup with docker +1. Install Docker. +2. Run Prometheus, note that you MUST manually set the absolute path to your copy of Trin's `docs/metrics_config/`: +```sh +docker run -p 9090:9090 -v /**absolute/path/to/trin/docs/metrics_config**:/etc/prometheus --add-host=host.docker.internal:host-gateway prom/prometheus +``` +3. Run Grafana: +```sh +docker run -p 3000:3000 --add-host=host.docker.internal:host-gateway grafana/grafana:latest +``` +4. Start your Trin process with: +```sh +cargo run -p trin -- --enable-metrics-with-url 0.0.0.0:9100 --web3-http-address http://0.0.0.0:8545 --web3-transport http +``` +- The addresses must be bound to 0.0.0.0, because 127.0.0.1 only allows internal requests to + complete, and requests from docker instances are considered external. +- The `--enable-metrics-with-url` parameter is the address that Trin exports metrics to, and should be equal to the port to which your Prometheus server is targeting at the bottom of `metrics_config/prometheus.yml` +- The `--web-transport http` will allow Grafana to request routing table information from Trin via JSON-RPC over HTTP +5. From the root of the Trin repo, run `cargo run -p trin -- create-dashboard`. If you used different ports than detailed in the above steps, or you are not using docker, then this command's defaults will not work. Run the command with the `-h` flag to see how to provide non-default addresses or credentials. +6. Upon successful dashboard creation, navigate to the dashboard URL that the `create-dashboard` outputs. Use `admin`/`admin` to login. + +## Gotchas + +- If `create-dashboard` fails with an error, the most likely reason is that it has already been run. From within the Grafana UI, delete the "json-rpc" and "prometheus" datasources and the "trin" dashboard and re-run the command. + +- There is a limit on concurrent connections given by the threadpool. At last + doc update, that number was 2, but will surely change. If you leave + connections open, then new connections will block. \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index d1065fb5e..356ed9e97 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -23,8 +23,7 @@ COPY ./rpc ./rpc COPY ./src ./src COPY ./trin-beacon ./trin-beacon COPY ./trin-bridge ./trin-bridge -COPY ./trin-cli ./trin-cli -COPY ./trin-history ./trin-history +COPY ./trin-history ./trin-history COPY ./trin-state ./trin-state COPY ./trin-types ./trin-types COPY ./trin-utils ./trin-utils @@ -32,14 +31,13 @@ COPY ./trin-validation ./trin-validation COPY ./utp-testing ./utp-testing # build for release -RUN cargo build -p trin -p trin-cli --release +RUN cargo build -p trin --release # final base FROM ubuntu:22.04 # copy build artifacts from build stage COPY --from=builder /trin/target/release/trin /usr/bin/ -COPY --from=builder /trin/target/release/trin-cli /usr/bin/ COPY --from=builder /trin/target/release/purge_db /usr/bin/ ENV RUST_LOG=debug diff --git a/docker/Dockerfile.bridge b/docker/Dockerfile.bridge index f8a0f1322..6e322472a 100644 --- a/docker/Dockerfile.bridge +++ b/docker/Dockerfile.bridge @@ -20,8 +20,7 @@ COPY ./light-client ./light-client COPY ./src ./src COPY ./trin-beacon ./trin-beacon COPY ./trin-bridge ./trin-bridge -COPY ./trin-cli ./trin-cli -COPY ./trin-history ./trin-history +COPY ./trin-history ./trin-history COPY ./trin-state ./trin-state COPY ./trin-types ./trin-types COPY ./trin-utils ./trin-utils diff --git a/ethportal-peertest/Cargo.toml b/ethportal-peertest/Cargo.toml index f91bde19e..3e42432a8 100644 --- a/ethportal-peertest/Cargo.toml +++ b/ethportal-peertest/Cargo.toml @@ -23,7 +23,7 @@ hex = "0.4.3" hyper = { version = "0.14", features = ["full"] } jsonrpsee = {version="0.16.2", features = ["async-client", "client", "macros", "server"]} rand = "0.8.4" -reth-ipc = { version = "0.1.0", git = "https://github.com/paradigmxyz/reth.git"} + rocksdb = "0.18.0" serde_json = "1.0.89" structopt = "0.3.26" @@ -39,5 +39,5 @@ trin-types = { path = "../trin-types" } trin-utils = { path = "../trin-utils" } ureq = { version = "2.5.0", features = ["json"] } -[target.'cfg(windows)'.dependencies] -uds_windows = "1.0.1" +[target.'cfg(not(windows))'.dependencies] +reth-ipc = { version = "0.1.0", git = "https://github.com/paradigmxyz/reth.git"} diff --git a/ethportal-peertest/src/lib.rs b/ethportal-peertest/src/lib.rs index 3c83c4700..608b64b7d 100644 --- a/ethportal-peertest/src/lib.rs +++ b/ethportal-peertest/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg(unix)] pub mod constants; pub mod scenarios; diff --git a/newsfragments/736.fixed.md b/newsfragments/736.fixed.md new file mode 100644 index 000000000..84a4f2290 --- /dev/null +++ b/newsfragments/736.fixed.md @@ -0,0 +1,7 @@ +### Remove cli, fix windows compilation, move grafana create to TrinConfig, update trin-types to use clap + +1. removed json-rpc from ``trin-cli`` +2. removed encodekey from ``trin-cli`` +3. add cfg and add a few panics to clearly define what is not supported by windows so it can compile +4. remove ``trin-cli``, move Create Grafana dashboard to TrinConfig (as discussed in the meeting 5/11/2023), update ``trin-types`` from structopt to clap +5. update Trin Book \ No newline at end of file diff --git a/portalnet/Cargo.toml b/portalnet/Cargo.toml index 9e5118c0b..0ee5d3605 100644 --- a/portalnet/Cargo.toml +++ b/portalnet/Cargo.toml @@ -50,9 +50,6 @@ validator = { version = "0.13.0", features = ["derive"] } url = "2.3.1" utp-rs = "0.1.0-alpha.4" -[target.'cfg(windows)'.dependencies] -uds_windows = "1.0.1" - [dev-dependencies] env_logger = "0.9.0" quickcheck = "1.0.3" diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index fe495ec6c..e5de11794 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -17,6 +17,8 @@ portalnet = { path = "../portalnet"} trin-types = { path = "../trin-types"} trin-utils = { path = "../trin-utils"} tokio = { version = "1.14.0", features = ["full"] } -reth-ipc = { version = "0.1.0", git = "https://github.com/paradigmxyz/reth.git"} url = "2.3.1" serde_json = "1.0.95" + +[target.'cfg(not(windows))'.dependencies] +reth-ipc = { version = "0.1.0", git = "https://github.com/paradigmxyz/reth.git"} diff --git a/rpc/src/server_rpc.rs b/rpc/src/server_rpc.rs index 66efdea65..05ca83eff 100644 --- a/rpc/src/server_rpc.rs +++ b/rpc/src/server_rpc.rs @@ -2,6 +2,7 @@ use crate::jsonrpsee::server::{ServerBuilder as HttpServerBuilder, ServerHandle} use crate::{Discv5Api, HistoryNetworkApi, Web3Api}; use ethportal_api::{Discv5ApiServer, HistoryNetworkApiServer, Web3ApiServer}; use portalnet::discovery::Discovery; +#[cfg(unix)] use reth_ipc::server::Builder as IpcServerBuilder; use std::net::SocketAddr; use std::path::Path; @@ -31,6 +32,7 @@ impl JsonRpcServer { Ok(handle) } + #[cfg(unix)] pub async fn run_ipc( ipc_path: Box>, discv5: Arc, @@ -46,4 +48,13 @@ impl JsonRpcServer { let handle = server.start(api).await?; Ok(handle) } + + #[cfg(windows)] + pub async fn run_ipc( + _ipc_path: Box>, + _discv5: Arc, + _history_handler: mpsc::UnboundedSender, + ) -> anyhow::Result { + panic!("Windows doesn't support Unix Domain Sockets IPC, use --web3-transport http") + } } diff --git a/tests/self_peertest.rs b/tests/self_peertest.rs index a4c102f7d..991309848 100644 --- a/tests/self_peertest.rs +++ b/tests/self_peertest.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(all(unix, test))] mod test { use std::{ net::{IpAddr, Ipv4Addr}, diff --git a/trin-cli/Cargo.toml b/trin-cli/Cargo.toml deleted file mode 100644 index c7beb4957..000000000 --- a/trin-cli/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "trin-cli" -version = "0.1.0" -edition = "2021" -repository = "https://github.com/ethereum/trin/tree/master/trin-cli" -license = "GPL-3.0" -readme = "README.md" -keywords = ["ethereum", "portal-network"] -categories = ["cryptography::cryptocurrencies"] -description = "A CLI tool for interacting with a Trin client." -authors = ["https://github.com/ethereum/trin/graphs/contributors"] - -[dependencies] -anyhow = "1.0.68" -base64 = "0.13.0" -clap = { version = "4.2.1", features = ["derive"] } -ethereum-types = "0.12.1" -ethportal-api = { path = "../ethportal-api" } -jsonrpc = "0.12.0" -nanotemplate = "0.3.0" -serde = "1.0.150" -serde_json = { version = "1.0.89", features = ["raw_value"] } - -thiserror = "1.0.29" -trin-types = { path = "../trin-types" } -trin-utils = { path = "../trin-utils" } -ureq = { version = "2.5.0", features = ["json"] } - -[[bin]] -name="trin-cli" -path="src/main.rs" diff --git a/trin-cli/README.md b/trin-cli/README.md deleted file mode 100644 index 0fd7e8469..000000000 --- a/trin-cli/README.md +++ /dev/null @@ -1,122 +0,0 @@ -# trin-cli - -A little utility for running JSON-RPC commands against trin nodes. - -```sh -$ cargo run -p trin-cli -- json-rpc discv5_routingTableInfo -Attempting RPC. endpoint=discv5_routingTableInfo file=/tmp/trin-jsonrpc.ipc -{ - "id": 0, - "jsonrpc": "2.0", - "result": { - "buckets": [], - "localKey": "0x0d2a..f3f5" - } -} -``` - -### To send a parameter, use the `--params` flag. To use multiple parameters, enter them as a comma-separated string. -```sh -$ cargo run -p trin-cli -- json-rpc portal_statePing --params enr:.... -``` - -### If you have multiple nodes running you can manually select which one you communicate with: - -```sh -$ cargo run -p trin-cli -- json-rpc discv5_routingTableInfo --ipc /tmp/trin-jsonrpc-2.ipc -``` - -### To use trin-cli to encode content keys: -Check out the `Encode Content Keys` section of the [Getting Started docs](../docs/getting_started.md#encode-content-keys). - -### View routing table - -Each Trin client uses a routing table to maintain a record of members in the Portal network with whom it can communicate. At startup, your routing table should be empty (unless you've passed in the bootnode ENR's via the `--bootnodes` CLI param). - -View your routing table: - -```sh -cargo run -p trin-cli -- json-rpc discv5_routingTableInfo -``` - -View ENR information about your own Trin client: - -```sh -cargo run -p trin-cli -- json-rpc discv5_nodeInfo -``` - -### Connect to the Portal Network testnet - -You can send a message from the local node to a bootnode using JSON-RPC, automatically adding the bootnode to your routing table. - -Find a [testnet bootnode ENR](https://github.com/ethereum/portal-network-specs/blob/master/testnet.md). - -Send a `PING` to the node on any of the Portal sub-networks (currently, only history and state are supported in Trin). - -```sh -cargo run -p trin-cli -- json-rpc portal_historyPing --params -``` - -After pinging a bootnode, you should be able to see the messages being sent and received in your node's logs. Now you can check your routing table again, where you should see the pinged bootnode (along with other nodes the bootnode shared with you). Congrats! You're now connected to the Portal Network testnet. - -### Encode Content Keys - -Pieces of content (data) on the Portal Network have unique identifiers that we refer to as "content keys". To request a particular piece of content, you will need the corresponding content key. - -The encoding for the content key depends on the kind of content that the key refers to. - -See available content keys (e.g. block header): - -```sh -cargo run -p trin-cli -- encode-key -h -``` - -See arguments for a specific content key: - -```sh -cargo run -p trin-cli -- encode-key block-header -h -``` - -Example: - -```sh -$ cargo run -p trin-cli -- encode-key block-body --block-hash 59834fe81c78b1838745e4ac352e455ec23cb542658cbba91a4337759f5bf3fc -``` - -### Request Content - -Send a `FindContent` message to a Portal Network bootnode. - -```sh -cargo run -p trin-cli -- json-rpc portal_historyFindContent --params , -``` - -### Setting up local metrics reporting - -1. Install Docker. -2. Run Prometheus, note that you MUST manually set the absolute path to your copy of Trin's `docs/metrics_config/`: -```sh -docker run -p 9090:9090 -v /**absolute/path/to/trin/docs/metrics_config**:/etc/prometheus --add-host=host.docker.internal:host-gateway prom/prometheus -``` -3. Run Grafana: -```sh -docker run -p 3000:3000 --add-host=host.docker.internal:host-gateway grafana/grafana:latest -``` -4. Start your Trin process with: -```sh -cargo run -p trin -- --enable-metrics-with-url 0.0.0.0:9100 --web3-http-address http://0.0.0.0:8545 --web3-transport http -``` - - The addresses must be bound to 0.0.0.0, because 127.0.0.1 only allows internal requests to - complete, and requests from docker instances are considered external. - - The `--enable-metrics-with-url` parameter is the address that Trin exports metrics to, and should be equal to the port to which your Prometheus server is targeting at the bottom of `metrics_config/prometheus.yml` - - The `--web-transport http` will allow Grafana to request routing table information from Trin via JSON-RPC over HTTP -5. From the root of the Trin repo, run `cargo run -p trin-cli -- create-dashboard`. If you used different ports than detailed in the above steps, or you are not using docker, then this command's defaults will not work. Run the command with the `-h` flag to see how to provide non-default addresses or credentials. -6. Upon successful dashboard creation, navigate to the dashboard URL that the `create-dashboard` outputs. Use `admin`/`admin` to login. - -## Gotchas - -- If `create-dashboard` fails with an error, the most likely reason is that it has already been run. From within the Grafana UI, delete the "json-rpc" and "prometheus" datasources and the "trin" dashboard and re-run the command. - -- There is a limit on concurrent connections given by the threadpool. At last - doc update, that number was 2, but will surely change. If you leave - connections open, then new connections will block. diff --git a/trin-cli/src/main.rs b/trin-cli/src/main.rs deleted file mode 100644 index 8324659b1..000000000 --- a/trin-cli/src/main.rs +++ /dev/null @@ -1,362 +0,0 @@ -pub mod dashboard; -use clap::{Args, Parser, Subcommand}; - -#[cfg(unix)] -use std::os::unix::net::UnixStream; -#[cfg(windows)] -use uds_windows::UnixStream; - -use std::path::{Path, PathBuf}; - -use ethereum_types::H256; -use serde_json::value::RawValue; -use thiserror::Error; - -use dashboard::grafana::{GrafanaAPI, DASHBOARD_TEMPLATES}; -use ethportal_api::{BlockBodyKey, BlockHeaderKey, BlockReceiptsKey, HistoryContentKey}; -use trin_types::cli::DEFAULT_WEB3_IPC_PATH; -use trin_utils::bytes::hex_encode; - -#[derive(Parser, Debug, PartialEq)] -#[command( - name = "trin-cli", - version = "0.0.1", - author = "Ethereum Foundation", - about = "Portal Network command line utilities" -)] -enum Trin { - JsonRpc(JsonRpc), - #[command(subcommand)] - EncodeKey(EncodeKey), - CreateDashboard(DashboardConfig), -} - -#[derive(Args, Debug, PartialEq)] -#[command(name = "json-rpc", about = "Run JSON-RPC commands against a trin node")] -struct JsonRpc { - /// IPC path of target JSON-RPC endpoint. - #[arg(default_value = DEFAULT_WEB3_IPC_PATH, long)] - ipc: PathBuf, - - /// JSON-RPC method (e.g. discv5_routingTableInfo). - #[arg(required = true)] - endpoint: String, - - /// Comma-separated list of JSON-RPC parameters. - #[arg(long, value_delimiter = ',')] - params: Option>, -} - -// TODO: Remove clippy allow once a variant with non-"Block" prefix is added. -/// Encode a content key. -#[derive(Subcommand, Debug, PartialEq)] -#[allow(clippy::enum_variant_names)] -enum EncodeKey { - /// Encode the content key for a block header. - BlockHeader { - /// Hex-encoded block hash (omit '0x' prefix). - #[arg(long)] - block_hash: H256, - }, - /// Encode the content key for a block body. - BlockBody { - /// Hex-encoded block hash (omit '0x' prefix). - #[arg(long)] - block_hash: H256, - }, - /// Encode the content key for a block's transaction receipts. - BlockReceipts { - /// Hex-encoded block hash (omit '0x' prefix). - #[arg(long)] - block_hash: H256, - }, -} - -#[derive(Args, Debug, PartialEq)] -#[command(name = "create-dashboard")] -#[allow(clippy::enum_variant_names)] -struct DashboardConfig { - #[arg(default_value = "http://localhost:3000")] - grafana_address: String, - - #[arg(default_value = "admin")] - grafana_username: String, - - #[arg(default_value = "admin")] - grafana_password: String, - - #[arg(default_value = "http://host.docker.internal:9090")] - prometheus_address: String, -} - -fn main() -> Result<(), Box> { - match Trin::parse() { - Trin::JsonRpc(rpc) => json_rpc(rpc), - Trin::EncodeKey(content_key) => encode_content_key(content_key), - Trin::CreateDashboard(dashboard_config) => create_dashboard(dashboard_config), - } -} - -fn json_rpc(rpc: JsonRpc) -> Result<(), Box> { - let params: Option>> = rpc - .params - .map(|param| param.into_iter().map(jsonrpc::arg).collect()); - eprintln!( - "Attempting RPC. endpoint={} params={:?} file={}", - rpc.endpoint, - params, - rpc.ipc.to_string_lossy() - ); - let mut client = TrinClient::from_ipc(&rpc.ipc)?; - - let req = client.build_request(rpc.endpoint.as_str(), ¶ms); - let resp = client.make_request(req)?; - - println!("{}", serde_json::to_string_pretty(&resp).unwrap()); - - Ok(()) -} - -fn encode_content_key(content_key: EncodeKey) -> Result<(), Box> { - let key = match content_key { - EncodeKey::BlockHeader { block_hash } => { - HistoryContentKey::BlockHeaderWithProof(BlockHeaderKey { - block_hash: block_hash.into(), - }) - } - EncodeKey::BlockBody { block_hash } => HistoryContentKey::BlockBody(BlockBodyKey { - block_hash: block_hash.into(), - }), - EncodeKey::BlockReceipts { block_hash } => { - HistoryContentKey::BlockReceipts(BlockReceiptsKey { - block_hash: block_hash.into(), - }) - } - }; - - println!("{}", hex_encode(Into::>::into(key))); - - Ok(()) -} - -fn create_dashboard(dashboard_config: DashboardConfig) -> Result<(), Box> { - let grafana = GrafanaAPI::new( - dashboard_config.grafana_username, - dashboard_config.grafana_password, - dashboard_config.grafana_address, - ); - - let prometheus_uid = grafana.create_datasource( - "prometheus".to_string(), - "prometheus".to_string(), - dashboard_config.prometheus_address, - )?; - - // Create a dashboard from each pre-defined template - for template_path in DASHBOARD_TEMPLATES.iter() { - let dashboard_url = grafana.create_dashboard(template_path, &prometheus_uid)?; - println!("Dashboard successfully created: {dashboard_url}"); - } - - Ok(()) -} - -fn build_request<'a>( - method: &'a str, - raw_params: &'a Option>>, - request_id: u64, -) -> jsonrpc::Request<'a> { - match raw_params { - Some(val) => jsonrpc::Request { - method, - params: val, - id: serde_json::json!(request_id), - jsonrpc: Some("2.0"), - }, - None => jsonrpc::Request { - method, - params: &[], - id: serde_json::json!(request_id), - jsonrpc: Some("2.0"), - }, - } -} - -pub trait TryClone { - fn try_clone(&self) -> std::io::Result - where - Self: Sized; -} - -impl TryClone for UnixStream { - fn try_clone(&self) -> std::io::Result { - UnixStream::try_clone(self) - } -} - -pub struct TrinClient -where - S: std::io::Read + std::io::Write + TryClone, -{ - stream: S, - request_id: u64, -} - -impl TrinClient { - fn from_ipc(path: &Path) -> std::io::Result { - // TODO: a nice error if this file does not exist - Ok(Self { - stream: UnixStream::connect(path)?, - request_id: 0, - }) - } -} - -#[derive(Error, Debug)] -pub enum JsonRpcError { - #[error("Received malformed response: {0}")] - Malformed(serde_json::Error), - - #[error("Received empty response")] - Empty, -} - -// TryClone is used because JSON-RPC responses are not followed by EOF. We must read bytes -// from the stream until a complete object is detected, and the simplest way of doing that -// with available APIs is to give ownership of a Read to a serde_json::Deserializer. If we -// gave it exclusive ownership that would require us to open a new connection for every -// command we wanted to send! By making a clone (or, by trying to) we can have our cake -// and eat it too. -// -// TryClone is not necessary if TrinClient stays in this file forever; this script only -// needs to make a single request before it exits. However, in a future where TrinClient -// becomes the mechanism other parts of the codebase (such as peertester) use to act as -// JSON-RPC clients then this becomes necessary. So, this is slightly over-engineered but -// with an eye to future growth. -impl<'a, S> TrinClient -where - S: std::io::Read + std::io::Write + TryClone, -{ - fn build_request( - &mut self, - method: &'a str, - params: &'a Option>>, - ) -> jsonrpc::Request<'a> { - let result = build_request(method, params, self.request_id); - self.request_id += 1; - - result - } - - fn make_request(&mut self, req: jsonrpc::Request) -> Result { - let data = serde_json::to_vec(&req).unwrap(); - - self.stream.write_all(&data).unwrap(); - self.stream.flush().unwrap(); - - let clone = self.stream.try_clone().unwrap(); - let deser = serde_json::Deserializer::from_reader(clone); - - if let Some(obj) = deser.into_iter::().next() { - return obj.map_err(JsonRpcError::Malformed); - } - - // this should only happen when they immediately send EOF - Err(JsonRpcError::Empty) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use std::str::FromStr; - - #[test] - fn test_trin_with_json_rpc() { - let trin = Trin::parse_from([ - "test", - "json-rpc", - "--ipc", - "/tmp/trin.ipc", - "--params", - "p1,p2", - "discv5_routingTableInfo", - ]); - assert_eq!( - trin, - Trin::JsonRpc(JsonRpc { - ipc: PathBuf::from("/tmp/trin.ipc"), - endpoint: "discv5_routingTableInfo".to_string(), - params: Some(vec!["p1".to_string(), "p2".to_string()]), - }) - ); - } - - #[test] - fn test_trin_with_encode_key() { - const BLOCK_HASH: &str = - "0x9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"; - let trin = Trin::parse_from([ - "test", - "encode-key", - "block-header", - "--block-hash", - BLOCK_HASH, - ]); - assert_eq!( - trin, - Trin::EncodeKey(EncodeKey::BlockHeader { - block_hash: H256::from_str(BLOCK_HASH).unwrap() - }) - ); - - let trin = Trin::parse_from([ - "test", - "encode-key", - "block-body", - "--block-hash", - BLOCK_HASH, - ]); - assert_eq!( - trin, - Trin::EncodeKey(EncodeKey::BlockBody { - block_hash: H256::from_str(BLOCK_HASH).unwrap() - }) - ); - - let trin = Trin::parse_from([ - "test", - "encode-key", - "block-receipts", - "--block-hash", - BLOCK_HASH, - ]); - assert_eq!( - trin, - Trin::EncodeKey(EncodeKey::BlockReceipts { - block_hash: H256::from_str(BLOCK_HASH).unwrap() - }) - ); - } - - #[test] - fn test_trin_with_create_dashboard() { - let trin = Trin::parse_from([ - "test", - "create-dashboard", - "http://localhost:8787", - "username", - "password", - "http://docker:9090", - ]); - assert_eq!( - trin, - Trin::CreateDashboard(DashboardConfig { - grafana_address: "http://localhost:8787".to_string(), - grafana_username: "username".to_string(), - grafana_password: "password".to_string(), - prometheus_address: "http://docker:9090".to_string(), - }) - ); - } -} diff --git a/trin-types/Cargo.toml b/trin-types/Cargo.toml index 34673f2be..17d768694 100644 --- a/trin-types/Cargo.toml +++ b/trin-types/Cargo.toml @@ -14,7 +14,7 @@ authors = ["https://github.com/ethereum/trin/graphs/contributors"] anyhow = "1.0.68" base64 = "0.13.0" bytes = "1.3.0" -clap = "2.33.3" +clap = { version = "4.2.1", features = ["derive"] } discv5 = { version = "0.2.1", features = ["serde"]} eth_trie = "0.1.0" ethereum-types = "0.12.1" @@ -25,6 +25,7 @@ eth2_ssz_types = "0.2.1" keccak-hash = "0.8.0" lazy_static = "1.4.0" quickcheck = "1.0.3" +nanotemplate = "0.3.0" rand = "0.8.5" rlp = "0.5.0" rlp-derive = "0.1.0" @@ -35,7 +36,6 @@ serde_yaml = "0.9.17" sha2 = "0.10.1" sha3 = "0.9.1" snap = "1.1.0" -structopt = "0.3.26" stremio-serde-hex = "0.1.0" tree_hash = "0.4.0" tree_hash_derive = "0.4.0" diff --git a/trin-types/src/cli.rs b/trin-types/src/cli.rs index 98d499ef8..210da2bcc 100644 --- a/trin-types/src/cli.rs +++ b/trin-types/src/cli.rs @@ -1,7 +1,7 @@ use std::{env, ffi::OsString, fmt, net::SocketAddr, path::PathBuf, str::FromStr}; +use clap::{arg, Args, Parser, Subcommand}; use ethereum_types::H256; -use structopt::StructOpt; use url::Url; use crate::bootnodes::Bootnodes; @@ -19,6 +19,8 @@ pub const DEFAULT_STORAGE_CAPACITY_MB: &str = "100"; pub const DEFAULT_TRUSTED_PROVIDER: &str = "infura"; pub const DEFAULT_WEB3_TRANSPORT: &str = "ipc"; +use crate::dashboard::grafana::{GrafanaAPI, DASHBOARD_TEMPLATES}; + #[derive(Debug, PartialEq, Clone)] pub enum Web3TransportType { HTTP, @@ -34,31 +36,19 @@ impl fmt::Display for Web3TransportType { } } -#[derive(Debug, PartialEq, Eq)] -pub struct ParseWeb3TransportError; - -impl fmt::Display for ParseWeb3TransportError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "Invalid web3-transport arg. Expected either 'http' or 'ipc'" - ) - } -} - impl FromStr for Web3TransportType { - type Err = ParseWeb3TransportError; + type Err = &'static str; fn from_str(s: &str) -> Result { match s { "http" => Ok(Web3TransportType::HTTP), "ipc" => Ok(Web3TransportType::IPC), - _ => Err(ParseWeb3TransportError), + _ => Err("Invalid web3-transport arg. Expected either 'http' or 'ipc'"), } } } -#[derive(StructOpt, Debug, PartialEq, Clone)] +#[derive(Parser, Debug, PartialEq, Clone)] #[structopt( name = "trin", version = "0.0.1", @@ -66,112 +56,114 @@ impl FromStr for Web3TransportType { about = "Run an eth portal client" )] pub struct TrinConfig { - #[structopt( - default_value(DEFAULT_WEB3_TRANSPORT), + #[arg( + default_value = DEFAULT_WEB3_TRANSPORT, long = "web3-transport", help = "select transport protocol to serve json-rpc endpoint" )] pub web3_transport: Web3TransportType, - #[structopt( - default_value(DEFAULT_WEB3_HTTP_ADDRESS), + #[arg( + default_value = DEFAULT_WEB3_HTTP_ADDRESS, long = "web3-http-address", help = "address to accept json-rpc http connections" )] pub web3_http_address: Url, - #[structopt( - default_value(DEFAULT_WEB3_IPC_PATH), + #[arg( + default_value = DEFAULT_WEB3_IPC_PATH, long = "web3-ipc-path", help = "path to json-rpc endpoint over IPC" )] pub web3_ipc_path: PathBuf, - #[structopt( - default_value(DEFAULT_DISCOVERY_PORT), + #[arg( + default_value = DEFAULT_DISCOVERY_PORT, long = "discovery-port", help = "The UDP port to listen on." )] pub discovery_port: u16, - #[structopt( - default_value("default"), + #[arg( + default_value = "default", long = "bootnodes", help = "One or more comma-delimited base64-encoded ENR's or multiaddr strings of peers to initially add to the local routing table" )] pub bootnodes: Bootnodes, - #[structopt( + #[arg( long = "external-address", group = "external-ips", help = "(Only use this if you are behind a NAT) The address which will be advertised to peers (in an ENR). Changing it does not change which port or address trin binds to. Port number is required, ex: 127.0.0.1:9001" )] pub external_addr: Option, - #[structopt( + #[arg( long = "no-stun", group = "external-ips", help = "Do not use STUN to determine an external IP. Leaves ENR entry for IP blank. Some users report better connections over VPN." )] pub no_stun: bool, - #[structopt( - validator(check_private_key_length), + #[arg( long = "unsafe-private-key", + value_parser = check_private_key_length, help = "Hex encoded 32 byte private key (with 0x prefix) (considered unsafe as it's stored in terminal history - keyfile support coming soon)" )] pub private_key: Option, - #[structopt( + #[arg( long = "networks", help = "Comma-separated list of which portal subnetworks to activate", default_value = DEFAULT_SUBNETWORKS, - use_delimiter = true + use_value_delimiter = true )] pub networks: Vec, /// Storage capacity specified in megabytes. - #[structopt( + #[arg( default_value(DEFAULT_STORAGE_CAPACITY_MB), long, help = "Maximum number of megabytes of total data to store in the DB (actual usage will exceed limit due to overhead)" )] pub mb: u32, - #[structopt( + #[arg( long = "enable-metrics-with-url", help = "Enable prometheus metrics reporting (provide local IP/Port from which your Prometheus server is configured to fetch metrics)" )] pub enable_metrics_with_url: Option, - #[structopt( - short = "e", + #[arg( + short = 'e', long = "ephemeral", help = "Use temporary data storage that is deleted on exit." )] pub ephemeral: bool, - #[structopt( + #[arg( long = "trusted-provider", help = "Trusted provider to use. (options: 'infura' (default), 'pandaops' (devops) or 'custom')", default_value(DEFAULT_TRUSTED_PROVIDER) )] pub trusted_provider: TrustedProviderType, - #[structopt( + #[arg( long = "trusted-provider-url", - help = "URL for a trusted http provider. Must include a base, host and port (e.g., '://:').", - validator(check_url_format) + value_parser = check_url_format, + help = "URL for a trusted http provider. Must include a base, host and port (e.g., '://:')." )] pub trusted_provider_url: Option, - #[structopt( + #[arg( long = "master-accumulator-path", help = "Path to master accumulator for validation", - default_value(DEFAULT_MASTER_ACC_PATH), - parse(from_os_str) + default_value(DEFAULT_MASTER_ACC_PATH) )] pub master_acc_path: PathBuf, + + #[command(subcommand)] + pub command: Option, } impl Default for TrinConfig { @@ -201,6 +193,7 @@ impl Default for TrinConfig { trusted_provider: TrustedProviderType::Infura, trusted_provider_url: None, master_acc_path: PathBuf::from(DEFAULT_MASTER_ACC_PATH.to_string()), + command: None, } } } @@ -214,7 +207,15 @@ impl TrinConfig { I: Iterator, T: Into + Clone, { - let config = Self::from_iter_safe(args)?; + let config = Self::try_parse_from(args)?; + + if let Some(TrinConfigCommands::CreateDashboard(dashboard_config)) = config.command { + if let Err(err) = create_dashboard(dashboard_config) { + panic!("Creating dashboard failed {}", err); + } + // exit program since if the user uses create dashboard this is all we do + std::process::exit(0); + } match config.web3_transport { Web3TransportType::HTTP => match &config.web3_ipc_path.as_path().display().to_string()[..] { @@ -260,16 +261,16 @@ impl TrinConfig { } /// A validator function for CLI URL arguments. -fn check_url_format(url: String) -> Result<(), String> { - match Url::parse(&url) { - Ok(_) => Ok(()), +fn check_url_format(url: &str) -> Result { + match Url::parse(url) { + Ok(val) => Ok(val), Err(e) => panic!("Invalid URL '{url}', {e}"), } } -fn check_private_key_length(private_key: String) -> Result<(), String> { +fn check_private_key_length(private_key: &str) -> Result { if private_key.len() == 66 { - return Ok(()); + return H256::from_str(private_key).map_err(|err| format!("HexError: {}", err)); } panic!( "Invalid private key length: {}, expected 66 (0x-prefixed 32 byte hexstring)", @@ -293,6 +294,52 @@ impl fmt::Display for TrinConfig { } } +#[derive(Subcommand, Debug, Clone, PartialEq)] +#[allow(clippy::enum_variant_names)] +pub enum TrinConfigCommands { + CreateDashboard(DashboardConfig), +} + +#[derive(Args, Debug, Default, Clone, PartialEq)] +#[allow(clippy::enum_variant_names)] +pub struct DashboardConfig { + #[arg(default_value = "http://localhost:3000")] + pub grafana_address: String, + + #[arg(default_value = "admin")] + pub grafana_username: String, + + #[arg(default_value = "admin")] + pub grafana_password: String, + + #[arg(default_value = "http://host.docker.internal:9090")] + pub prometheus_address: String, +} + +pub fn create_dashboard( + dashboard_config: DashboardConfig, +) -> Result<(), Box> { + let grafana = GrafanaAPI::new( + dashboard_config.grafana_username, + dashboard_config.grafana_password, + dashboard_config.grafana_address, + ); + + let prometheus_uid = grafana.create_datasource( + "prometheus".to_string(), + "prometheus".to_string(), + dashboard_config.prometheus_address, + )?; + + // Create a dashboard from each pre-defined template + for template_path in DASHBOARD_TEMPLATES.iter() { + let dashboard_url = grafana.create_dashboard(template_path, &prometheus_uid)?; + println!("Dashboard successfully created: {dashboard_url}"); + } + + Ok(()) +} + #[cfg(test)] #[allow(clippy::unwrap_used)] mod test { @@ -577,6 +624,33 @@ mod test { assert_eq!(url.port(), Some(8546)); } + #[test] + fn test_trin_with_create_dashboard() { + let config = TrinConfig::try_parse_from([ + "trin", + "create-dashboard", + "http://localhost:8787", + "username", + "password", + "http://docker:9090", + ]) + .unwrap(); + if let Some(TrinConfigCommands::CreateDashboard(dashboard_config)) = config.command { + assert_eq!( + dashboard_config.grafana_address, + "http://localhost:8787".to_string() + ); + assert_eq!(dashboard_config.grafana_username, "username".to_string()); + assert_eq!(dashboard_config.grafana_password, "password".to_string()); + assert_eq!( + dashboard_config.prometheus_address, + "http://docker:9090".to_string() + ); + } else { + unreachable!("") + } + } + #[test] #[should_panic( expected = "--trusted-provider-url flag is incompatible with infura as the trusted provider." diff --git a/trin-cli/src/dashboard/collected-metrics-dashboard.json.template b/trin-types/src/dashboard/collected-metrics-dashboard.json.template similarity index 100% rename from trin-cli/src/dashboard/collected-metrics-dashboard.json.template rename to trin-types/src/dashboard/collected-metrics-dashboard.json.template diff --git a/trin-cli/src/dashboard/grafana.rs b/trin-types/src/dashboard/grafana.rs similarity index 97% rename from trin-cli/src/dashboard/grafana.rs rename to trin-types/src/dashboard/grafana.rs index d0f656804..d33a32b42 100644 --- a/trin-cli/src/dashboard/grafana.rs +++ b/trin-types/src/dashboard/grafana.rs @@ -5,7 +5,7 @@ use std::fs; use ureq; pub const DASHBOARD_TEMPLATES: &[&str] = - &["./trin-cli/src/dashboard/collected-metrics-dashboard.json.template"]; + &["./trin-types/src/dashboard/collected-metrics-dashboard.json.template"]; pub struct GrafanaAPI { basic_auth_string: String, diff --git a/trin-cli/src/dashboard/mod.rs b/trin-types/src/dashboard/mod.rs similarity index 100% rename from trin-cli/src/dashboard/mod.rs rename to trin-types/src/dashboard/mod.rs diff --git a/trin-types/src/lib.rs b/trin-types/src/lib.rs index 30b2d8d04..a14809f9d 100644 --- a/trin-types/src/lib.rs +++ b/trin-types/src/lib.rs @@ -8,6 +8,7 @@ pub mod consensus; pub mod constants; pub mod content_key; pub mod content_value; +pub mod dashboard; pub mod discv5; pub mod distance; pub mod enr;