diff --git a/CHANGELOG.md b/CHANGELOG.md index d6694a4e..c9b67cf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased](https://github.com/near/read-rpc/compare/v0.2.8...HEAD) +## [Unreleased](https://github.com/near/read-rpc/compare/main...develop) + +## [0.2.9](https://github.com/near/read-rpc/releases/tag/v0.2.9) +### Supported Nearcore Version +- nearcore v1.39.1 +- rust v1.77.0 + +### What's Changed +* Refactoring, extending and improving the metrics +* Refactoring and improving `query.call_function` +* Added `view_receipt_record` rpc endpoint ## [0.2.8](https://github.com/near/read-rpc/releases/tag/v0.2.8) ### Supported Nearcore Version diff --git a/Cargo.lock b/Cargo.lock index 51429fea..352941b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,11 +30,11 @@ dependencies = [ "futures-util", "log", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "pin-project-lite", "smallvec", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", ] [[package]] @@ -50,7 +50,7 @@ dependencies = [ "memchr", "pin-project-lite", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "tracing", ] @@ -86,16 +86,16 @@ dependencies = [ [[package]] name = "actix-http" -version = "3.6.0" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d223b13fd481fc0d1f83bb12659ae774d9e3601814c68a0bc539731698cca743" +checksum = "4eb9843d84c775696c37d9a418bbb01b932629d01870722c0f13eb3f95e2536d" dependencies = [ "actix-codec", "actix-rt", "actix-service", "actix-utils", "ahash 0.8.11", - "base64 0.21.7", + "base64 0.22.1", "bitflags 2.5.0", "brotli", "bytes", @@ -118,7 +118,7 @@ dependencies = [ "sha1", "smallvec", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "tracing", "zstd", ] @@ -130,18 +130,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] name = "actix-router" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22475596539443685426b6bdadb926ad0ecaefdfc5fb05e5e3441f15463c511" +checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8" dependencies = [ "bytestring", + "cfg-if 1.0.0", "http 0.2.12", "regex", + "regex-lite", "serde", "tracing", ] @@ -187,9 +189,9 @@ dependencies = [ [[package]] name = "actix-tls" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4cce60a2f2b477bc72e5cde0af1812a6e82d8fd85b5570a5dcf2a5bf2c5be5f" +checksum = "ac453898d866cdbecdbc2334fe1738c747b4eba14a677261f2b768ba05329389" dependencies = [ "actix-rt", "actix-service", @@ -202,7 +204,7 @@ dependencies = [ "pin-project-lite", "tokio", "tokio-openssl", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "tracing", ] @@ -218,9 +220,9 @@ dependencies = [ [[package]] name = "actix-web" -version = "4.5.1" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a6556ddebb638c2358714d853257ed226ece6023ef9364f23f0c70737ea984" +checksum = "b1cf67dadb19d7c95e5a299e2dda24193b89d5d4f33a3b9800888ede9e19aa32" dependencies = [ "actix-codec", "actix-http", @@ -247,6 +249,7 @@ dependencies = [ "once_cell", "pin-project-lite", "regex", + "regex-lite", "serde", "serde_json", "serde_urlencoded", @@ -265,7 +268,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -276,7 +279,7 @@ checksum = "7c7db3d5a9718568e4cf4a537cfd7070e6e6ff7481510d0237fb529ac850f6d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -300,7 +303,7 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ - "getrandom 0.2.14", + "getrandom 0.2.15", "once_cell", "version_check", ] @@ -312,7 +315,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if 1.0.0", - "getrandom 0.2.14", + "getrandom 0.2.15", "once_cell", "version_check", "zerocopy", @@ -344,9 +347,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "android-tzdata" @@ -365,47 +368,48 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -413,9 +417,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "arbitrary" @@ -490,18 +494,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] name = "async-trait" -version = "0.1.79" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -522,15 +526,15 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "awc" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68c09cc97310b926f01621faee652f3d1b0962545a3cec6c9ac07def9ea36c2c" +checksum = "fe6b67e44fb95d1dc9467e3930383e115f9b4ed60ca689db41409284e967a12d" dependencies = [ "actix-codec", "actix-http", @@ -538,7 +542,7 @@ dependencies = [ "actix-service", "actix-tls", "actix-utils", - "base64 0.21.7", + "base64 0.22.1", "bytes", "cfg-if 1.0.0", "cookie", @@ -562,9 +566,9 @@ dependencies = [ [[package]] name = "aws-config" -version = "1.1.10" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48730d0b4c3d91c43d0d37168831d9fd0e065ad4a889a2ee9faf8d34c3d2804d" +checksum = "40ddbfb5db93d62521f47b3f223da0884a2f02741ff54cb9cda192a0e73ba08b" dependencies = [ "aws-credential-types", "aws-runtime", @@ -579,7 +583,7 @@ dependencies = [ "aws-smithy-types", "aws-types", "bytes", - "fastrand 2.0.2", + "fastrand 2.1.0", "hex", "http 0.2.12", "hyper", @@ -593,9 +597,9 @@ dependencies = [ [[package]] name = "aws-credential-types" -version = "1.1.8" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa8587ae17c8e967e4b05a62d495be2fb7701bec52a97f7acfe8a29f938384c8" +checksum = "e16838e6c9e12125face1c1eff1343c75e3ff540de98ff7ebd61874a89bcfeb9" dependencies = [ "aws-smithy-async", "aws-smithy-runtime-api", @@ -610,7 +614,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aeeee1a5defa63cba39097a510dfe63ef53658fc8995202a610f6a8a4d03639" dependencies = [ "attohttpc", - "dirs 4.0.0", + "dirs", "rust-ini", "serde", "serde-xml-rs", @@ -630,9 +634,9 @@ dependencies = [ [[package]] name = "aws-runtime" -version = "1.1.9" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ee6903f9d0197510eb6b44c4d86b493011d08b4992938f7b9be0333b6685aa" +checksum = "75588e7ee5e8496eed939adac2035a6dbab9f7eb2acdd9ab2d31856dab6f3955" dependencies = [ "aws-credential-types", "aws-sigv4", @@ -643,7 +647,7 @@ dependencies = [ "aws-smithy-types", "aws-types", "bytes", - "fastrand 2.0.2", + "fastrand 2.1.0", "http 0.2.12", "http-body 0.4.6", "percent-encoding", @@ -654,9 +658,9 @@ dependencies = [ [[package]] name = "aws-sdk-s3" -version = "1.22.0" +version = "1.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644c5939c1b78097d37f3341708978d68490070d4b0f8fa91f0878678c06a7ef" +checksum = "966646a69665bb0427460d78747204317f6639bdf5ec61305c4c5195af3dc086" dependencies = [ "ahash 0.8.11", "aws-credential-types", @@ -673,7 +677,7 @@ dependencies = [ "aws-smithy-xml", "aws-types", "bytes", - "fastrand 2.0.2", + "fastrand 2.1.0", "hex", "hmac", "http 0.2.12", @@ -689,9 +693,9 @@ dependencies = [ [[package]] name = "aws-sdk-sso" -version = "1.19.0" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2be5ba83b077b67a6f7a1927eb6b212bf556e33bd74b5eaa5aa6e421910803a" +checksum = "fef2d9ca2b43051224ed326ed9960a85e277b7d554a2cd0397e57c0553d86e64" dependencies = [ "aws-credential-types", "aws-runtime", @@ -711,9 +715,9 @@ dependencies = [ [[package]] name = "aws-sdk-ssooidc" -version = "1.19.0" +version = "1.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "022ca669825f841aef17b12d4354ef2b8651e4664be49f2d9ea13e4062a80c9f" +checksum = "c869d1f5c4ee7437b79c3c1664ddbf7a60231e893960cf82b2b299a5ccf2cc5d" dependencies = [ "aws-credential-types", "aws-runtime", @@ -733,9 +737,9 @@ dependencies = [ [[package]] name = "aws-sdk-sts" -version = "1.19.0" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e4a5f5cb007347c1ab34a6d56456301dfada921fc9e57d687ecb08baddd11ff" +checksum = "9e2b4a632a59e4fab7abf1db0d94a3136ad7871aba46bebd1fdb95c7054afcdb" dependencies = [ "aws-credential-types", "aws-runtime", @@ -756,9 +760,9 @@ dependencies = [ [[package]] name = "aws-sigv4" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d6f29688a4be9895c0ba8bef861ad0c0dac5c15e9618b9b7a6c233990fc263" +checksum = "58b56f1cbe6fd4d0c2573df72868f20ab1c125ca9c9dbce17927a463433a2e57" dependencies = [ "aws-credential-types", "aws-smithy-eventstream", @@ -828,9 +832,9 @@ dependencies = [ [[package]] name = "aws-smithy-http" -version = "0.60.7" +version = "0.60.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f10fa66956f01540051b0aa7ad54574640f748f9839e843442d99b970d3aff9" +checksum = "4a7de001a1b9a25601016d8057ea16e31a45fdca3751304c8edf4ad72e706c08" dependencies = [ "aws-smithy-eventstream", "aws-smithy-runtime-api", @@ -868,16 +872,16 @@ dependencies = [ [[package]] name = "aws-smithy-runtime" -version = "1.2.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c53572b4cd934ee5e8461ad53caa36e9d246aaef42166e3ac539e206a925d330" +checksum = "c9ac79e9f3a4d576f3cd4a470a0275b138d9e7b11b1cd514a6858ae0a79dd5bb" dependencies = [ "aws-smithy-async", "aws-smithy-http", "aws-smithy-runtime-api", "aws-smithy-types", "bytes", - "fastrand 2.0.2", + "fastrand 2.1.0", "h2", "http 0.2.12", "http-body 0.4.6", @@ -894,9 +898,9 @@ dependencies = [ [[package]] name = "aws-smithy-runtime-api" -version = "1.3.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccb2b3a7030dc9a3c9a08ce0b25decea5130e9db19619d4dffbbff34f75fe850" +checksum = "04ec42c2f5c0e7796a2848dde4d9f3bf8ce12ccbb3d5aa40c52fa0cdd61a1c47" dependencies = [ "aws-smithy-async", "aws-smithy-types", @@ -911,9 +915,9 @@ dependencies = [ [[package]] name = "aws-smithy-types" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abe14dceea1e70101d38fbf2a99e6a34159477c0fb95e68e05c66bd7ae4c3729" +checksum = "baf98d97bba6ddaba180f1b1147e202d8fe04940403a95a3f826c790f931bbd1" dependencies = [ "base64-simd", "bytes", @@ -932,23 +936,23 @@ dependencies = [ "serde", "time", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", ] [[package]] name = "aws-smithy-xml" -version = "0.60.7" +version = "0.60.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "872c68cf019c0e4afc5de7753c4f7288ce4b71663212771bf5e4542eb9346ca9" +checksum = "d123fbc2a4adc3c301652ba8e149bf4bc1d1725affb9784eb20c953ace06bf55" dependencies = [ "xmlparser", ] [[package]] name = "aws-types" -version = "1.1.9" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb278e322f16f59630a83b6b2dc992a0b48aa74ed47b4130f193fae0053d713" +checksum = "a807d90cd50a969b3d95e4e7ad1491fcae13c6e83948d8728363ecc09d66343a" dependencies = [ "aws-credential-types", "aws-smithy-async", @@ -998,6 +1002,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64-simd" version = "0.8.0" @@ -1022,7 +1032,7 @@ checksum = "9324c8014cd04590682b34f1e9448d38f0674d0f7b2dc553331016ef0e4e9ebc" dependencies = [ "autocfg", "libm", - "num-bigint 0.4.4", + "num-bigint 0.4.5", "num-integer", "num-traits", ] @@ -1054,7 +1064,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -1147,11 +1157,11 @@ dependencies = [ [[package]] name = "borsh" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0901fc8eb0aca4c83be0106d6f2db17d86a08dfc2c25f0e84464bf381158add6" +checksum = "dbe5b10e214954177fb1dc9fbd20a1a2608fe99e6c832033bdc7cea287a20d77" dependencies = [ - "borsh-derive 1.4.0", + "borsh-derive 1.5.0", "cfg_aliases", ] @@ -1170,15 +1180,15 @@ dependencies = [ [[package]] name = "borsh-derive" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51670c3aa053938b0ee3bd67c3817e471e626151131b934038e83c5bf8de48f5" +checksum = "d7a8646f94ab393e43e8b35a2558b1624bed28b97ee09c5d15456e3c9463f46d" dependencies = [ "once_cell", "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", "syn_derive", ] @@ -1206,9 +1216,9 @@ dependencies = [ [[package]] name = "brotli" -version = "3.5.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d640d25bc63c50fb1f0b545ffd80207d2e10a4c965530809b40ba3386825c391" +checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -1217,9 +1227,9 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "2.5.1" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f" +checksum = "e6221fe77a248b9117d431ad93761222e1cf8ff282d9d1d5d9f53d6299a1cf76" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -1328,12 +1338,13 @@ checksum = "a2698f953def977c68f935bb0dfa959375ad4638570e969e2f1e9f433cbf1af6" [[package]] name = "cc" -version = "1.0.92" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" dependencies = [ "jobserver", "libc", + "once_cell", ] [[package]] @@ -1365,9 +1376,9 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "chrono" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", @@ -1375,7 +1386,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -1429,7 +1440,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -1472,36 +1483,36 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "combine" -version = "4.6.6" +version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" dependencies = [ "bytes", "futures-core", "memchr", "pin-project-lite", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", ] [[package]] name = "concurrent-queue" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" dependencies = [ "crossbeam-utils", ] [[package]] name = "configuration" -version = "0.2.8" +version = "0.2.9" dependencies = [ "anyhow", "aws-credential-types", @@ -1516,7 +1527,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "toml 0.8.12", + "toml 0.8.13", "tracing", "tracing-opentelemetry 0.19.0", "tracing-stackdriver", @@ -1623,7 +1634,7 @@ dependencies = [ "cranelift-entity", "cranelift-isle", "gimli", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "log", "regalloc2", "smallvec", @@ -1735,9 +1746,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.4.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if 1.0.0", ] @@ -1757,9 +1768,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.12" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" dependencies = [ "crossbeam-utils", ] @@ -1794,9 +1805,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crunchy" @@ -1923,7 +1934,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -1938,12 +1949,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" +checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" dependencies = [ - "darling_core 0.20.8", - "darling_macro 0.20.8", + "darling_core 0.20.9", + "darling_macro 0.20.9", ] [[package]] @@ -1962,16 +1973,16 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" +checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", - "strsim 0.10.0", - "syn 2.0.58", + "strsim 0.11.1", + "syn 2.0.65", ] [[package]] @@ -1987,13 +1998,13 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" +checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ - "darling_core 0.20.8", + "darling_core 0.20.9", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -2003,20 +2014,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if 1.0.0", - "hashbrown 0.14.3", - "lock_api 0.4.11", + "hashbrown 0.14.5", + "lock_api 0.4.12", "once_cell", - "parking_lot_core 0.9.9", + "parking_lot_core 0.9.10", ] [[package]] name = "database" -version = "0.2.8" +version = "0.2.9" dependencies = [ "anyhow", "async-trait", "bigdecimal", - "borsh 1.4.0", + "borsh 1.5.0", "bytes", "configuration", "diesel", @@ -2024,13 +2035,15 @@ dependencies = [ "diesel_migrations", "futures", "hex", + "lazy_static", "near-chain-configs 1.39.1", "near-crypto 1.39.1", "near-indexer-primitives", "near-primitives 1.39.1", - "num-bigint 0.4.4", + "num-bigint 0.4.5", "num-traits", "prettytable-rs", + "prometheus", "readnode-primitives", "scylla", "scylla-cql", @@ -2056,9 +2069,9 @@ dependencies = [ [[package]] name = "deadpool-runtime" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63dfa964fe2a66f3fde91fc70b267fe193d822c7e603e2a675a49a7f46ad3f49" +checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" [[package]] name = "debugid" @@ -2108,7 +2121,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -2157,16 +2170,16 @@ dependencies = [ [[package]] name = "diesel" -version = "2.1.5" +version = "2.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03fc05c17098f21b89bc7d98fe1dd3cce2c11c2ad8e145f2a44fe08ed28eb559" +checksum = "ff236accb9a5069572099f0b350a92e9560e8e63a9b8d546162f4a5e03026bb2" dependencies = [ "bigdecimal", "bitflags 2.5.0", "byteorder", "diesel_derives", "itoa", - "num-bigint 0.4.4", + "num-bigint 0.4.5", "num-integer", "num-traits", "pq-sys", @@ -2190,14 +2203,14 @@ dependencies = [ [[package]] name = "diesel_derives" -version = "2.1.3" +version = "2.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d02eecb814ae714ffe61ddc2db2dd03e6c49a42e269b5001355500d431cce0c" +checksum = "14701062d6bed917b5c7103bdffaee1e4609279e240488ad24e7bd979ca6866c" dependencies = [ "diesel_table_macro_syntax", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -2217,7 +2230,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" dependencies = [ - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -2255,16 +2268,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ - "dirs-sys 0.3.7", -] - -[[package]] -name = "dirs" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" -dependencies = [ - "dirs-sys 0.4.1", + "dirs-sys", ] [[package]] @@ -2288,18 +2292,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "dirs-sys" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" -dependencies = [ - "libc", - "option-ext", - "redox_users", - "windows-sys 0.48.0", -] - [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -2313,9 +2305,9 @@ dependencies = [ [[package]] name = "dissimilar" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86e3bdc80eee6e16b2b6b0f87fbc98c04bee3455e35174c0de1a125d0688c632" +checksum = "59f8e79d1fbf76bdfbde321e902714bf6c49df88a7dda6fc682fc2979226962d" [[package]] name = "dlv-list" @@ -2424,9 +2416,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "elastic-array" @@ -2471,9 +2463,9 @@ checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" [[package]] name = "encoding_rs" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ "cfg-if 1.0.0", ] @@ -2495,7 +2487,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -2513,15 +2505,15 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08b6c6ab82d70f08844964ba10c7babb716de2ecaeab9be5717918a5177d3af" dependencies = [ - "darling 0.20.8", + "darling 0.20.9", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] name = "epoch-indexer" -version = "0.2.8" +version = "0.2.9" dependencies = [ "anyhow", "clap", @@ -2545,11 +2537,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "erased-serde" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b73807008a3c7f171cc40312f37d95ef0396e048b5848d775f54b1a4dd4a0d3" +checksum = "24e2389d65ab4fab27dc2a5de7b191e1f6617d1f1c8855c0dc569c94a4cbb18d" dependencies = [ "serde", + "typeid", ] [[package]] @@ -2565,9 +2558,9 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys 0.52.0", @@ -2621,9 +2614,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "ff" @@ -2637,9 +2630,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "finite-wasm" @@ -2680,9 +2673,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", "miniz_oxide", @@ -2816,7 +2809,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -2903,9 +2896,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", "libc", @@ -2955,7 +2948,7 @@ dependencies = [ "indexmap 2.2.6", "slab", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "tracing", ] @@ -2988,9 +2981,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash 0.8.11", "allocator-api2", @@ -3292,7 +3285,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "serde", ] @@ -3311,9 +3304,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" dependencies = [ "cfg-if 1.0.0", ] @@ -3341,6 +3334,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[package]] name = "isahc" version = "1.7.2" @@ -3392,9 +3391,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.28" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] @@ -3417,7 +3416,7 @@ checksum = "9dbbfed4e59ba9750e15ba154fdfd9329cee16ff3df539c2666b70f58cc32105" [[package]] name = "jsonrpc-v2" version = "0.11.0" -source = "git+https://github.com/kobayurii/jsonrpc-v2?branch=master#ee01c71bcd2e131d787988728b7288734c2371df" +source = "git+https://github.com/kobayurii/jsonrpc-v2?branch=fork#5432ca0d6e028ec20fb70d947d6a5c492d308699" dependencies = [ "actix-service", "actix-web", @@ -3482,9 +3481,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" @@ -3493,7 +3492,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if 1.0.0", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -3504,9 +3503,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libmimalloc-sys" -version = "0.1.37" +version = "0.1.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81eb4061c0582dedea1cbc7aff2240300dd6982e0239d1c99e65c1dbf4a30ba7" +checksum = "0e7bb23d733dfcc8af652a78b7bf232f0e967710d044732185e561e47c0336b6" dependencies = [ "cc", "libc", @@ -3553,9 +3552,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "local-channel" @@ -3585,9 +3584,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -3634,7 +3633,7 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc" dependencies = [ - "hashbrown 0.14.3", + "hashbrown 0.14.5", ] [[package]] @@ -3708,7 +3707,7 @@ checksum = "5cf92c10c7e361d6b99666ec1c6f9805b0bea2c3bd8c78dc6fe98ac5bd78db11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -3811,9 +3810,9 @@ dependencies = [ [[package]] name = "mimalloc" -version = "0.1.41" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f41a2280ded0da56c8cf898babb86e8f10651a34adcfff190ae9a1159c6908d" +checksum = "e9186d86b79b52f4a77af65604b51225e8db1d6ee7e3f41aec1e40829c71a176" dependencies = [ "libmimalloc-sys", ] @@ -3851,9 +3850,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -3912,7 +3911,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35cbb989542587b47205e608324ddd391f0cee1c22b4b64ae49f458334b95907" dependencies = [ - "borsh 1.4.0", + "borsh 1.5.0", "serde", ] @@ -3950,7 +3949,7 @@ source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#81472 dependencies = [ "actix", "assert_matches", - "borsh 1.4.0", + "borsh 1.5.0", "bytesize", "chrono", "crossbeam-channel", @@ -4047,7 +4046,7 @@ version = "1.39.1" source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#814725874d755bbf449a84669c13eb3c206c374d" dependencies = [ "actix", - "borsh 1.4.0", + "borsh 1.5.0", "chrono", "derive-enum-from-into", "derive_more", @@ -4093,7 +4092,7 @@ dependencies = [ "actix-rt", "anyhow", "async-trait", - "borsh 1.4.0", + "borsh 1.5.0", "chrono", "cloud-storage", "derive_more", @@ -4189,7 +4188,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2991d2912218a80ec0733ac87f84fa803accea105611eea209d4419271957667" dependencies = [ "blake2", - "borsh 1.4.0", + "borsh 1.5.0", "bs58", "c2-chacha", "curve25519-dalek", @@ -4215,7 +4214,7 @@ version = "1.39.1" source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#814725874d755bbf449a84669c13eb3c206c374d" dependencies = [ "blake2", - "borsh 1.4.0", + "borsh 1.5.0", "bs58", "c2-chacha", "curve25519-dalek", @@ -4258,7 +4257,7 @@ name = "near-epoch-manager" version = "1.39.1" source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#814725874d755bbf449a84669c13eb3c206c374d" dependencies = [ - "borsh 1.4.0", + "borsh 1.5.0", "itertools 0.10.5", "near-cache", "near-chain-configs 1.39.1", @@ -4366,7 +4365,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "18ad81e015f7aced8925d5b9ba3f369b36da9575c15812cfd0786bc1213284ca" dependencies = [ - "borsh 1.4.0", + "borsh 1.5.0", "lazy_static", "log", "near-chain-configs 0.20.1", @@ -4384,7 +4383,7 @@ name = "near-jsonrpc-client" version = "0.9.0" source = "git+https://github.com/kobayurii/near-jsonrpc-client-rs.git?branch=0.9.0#58776d507b45a64461de0659a6342af58d872feb" dependencies = [ - "borsh 1.4.0", + "borsh 1.5.0", "lazy_static", "log", "near-chain-configs 1.39.1", @@ -4488,7 +4487,7 @@ dependencies = [ "arc-swap", "assert_matches", "async-trait", - "borsh 1.4.0", + "borsh 1.5.0", "bytes", "bytesize", "chrono", @@ -4510,7 +4509,7 @@ dependencies = [ "near-store", "once_cell", "opentelemetry 0.17.0", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "pin-project", "protobuf 3.4.0", "protobuf-codegen", @@ -4525,7 +4524,7 @@ dependencies = [ "time", "tokio", "tokio-stream", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "tracing", ] @@ -4591,7 +4590,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9f16a59b6c3e69b0585be951af6fe42a0ba86c0e207cb8c63badd19efd16680" dependencies = [ "assert_matches", - "borsh 1.4.0", + "borsh 1.5.0", "enum-map", "near-account-id", "near-primitives-core 0.20.1", @@ -4609,7 +4608,7 @@ version = "1.39.1" source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#814725874d755bbf449a84669c13eb3c206c374d" dependencies = [ "assert_matches", - "borsh 1.4.0", + "borsh 1.5.0", "enum-map", "near-account-id", "near-primitives-core 1.39.1", @@ -4634,7 +4633,7 @@ dependencies = [ "once_cell", "strum 0.24.1", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "tracing", ] @@ -4644,7 +4643,7 @@ version = "1.39.1" source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#814725874d755bbf449a84669c13eb3c206c374d" dependencies = [ "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -4652,7 +4651,7 @@ name = "near-pool" version = "1.39.1" source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#814725874d755bbf449a84669c13eb3c206c374d" dependencies = [ - "borsh 1.4.0", + "borsh 1.5.0", "near-crypto 1.39.1", "near-o11y 1.39.1", "near-primitives 1.39.1", @@ -4668,7 +4667,7 @@ checksum = "0462b067732132babcc89d5577db3bfcb0a1bcfbaaed3f2db4c11cd033666314" dependencies = [ "arbitrary", "base64 0.21.7", - "borsh 1.4.0", + "borsh 1.5.0", "bytesize", "cfg-if 1.0.0", "chrono", @@ -4709,7 +4708,7 @@ source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#81472 dependencies = [ "arbitrary", "base64 0.21.7", - "borsh 1.4.0", + "borsh 1.5.0", "bytesize", "cfg-if 1.0.0", "chrono", @@ -4751,7 +4750,7 @@ checksum = "8443eb718606f572c438be6321a097a8ebd69f8e48d953885b4f16601af88225" dependencies = [ "arbitrary", "base64 0.21.7", - "borsh 1.4.0", + "borsh 1.5.0", "bs58", "derive_more", "enum-map", @@ -4772,7 +4771,7 @@ source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#81472 dependencies = [ "arbitrary", "base64 0.21.7", - "borsh 1.4.0", + "borsh 1.5.0", "bs58", "derive_more", "enum-map", @@ -4826,7 +4825,7 @@ checksum = "80fca203c51edd9595ec14db1d13359fb9ede32314990bf296b6c5c4502f6ab7" dependencies = [ "quote", "serde", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -4836,7 +4835,7 @@ source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#81472 dependencies = [ "quote", "serde", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -4848,7 +4847,7 @@ dependencies = [ "fs2", "near-rpc-error-core 0.20.1", "serde", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -4859,7 +4858,7 @@ dependencies = [ "fs2", "near-rpc-error-core 1.39.1", "serde", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -4869,12 +4868,12 @@ source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#81472 [[package]] name = "near-state-indexer" -version = "0.2.8" +version = "0.2.9" dependencies = [ "actix", "actix-web", "anyhow", - "borsh 1.4.0", + "borsh 1.5.0", "clap", "configuration", "database", @@ -4914,7 +4913,7 @@ dependencies = [ "actix", "actix-rt", "anyhow", - "borsh 1.4.0", + "borsh 1.5.0", "bytesize", "crossbeam", "derive_more", @@ -5036,7 +5035,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c56c80bdb1954808f59bd36a9112377197b38d424991383bf05f52d0fe2e0da5" dependencies = [ "base64 0.21.7", - "borsh 1.4.0", + "borsh 1.5.0", "ed25519-dalek", "enum-map", "memoffset 0.8.0", @@ -5066,7 +5065,7 @@ source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#81472 dependencies = [ "anyhow", "base64 0.21.7", - "borsh 1.4.0", + "borsh 1.5.0", "ed25519-dalek", "enum-map", "finite-wasm", @@ -5165,10 +5164,10 @@ dependencies = [ "actix-web", "anyhow", "awc", - "borsh 1.4.0", + "borsh 1.5.0", "chrono", "cloud-storage", - "dirs 4.0.0", + "dirs", "easy-ext", "futures", "hex", @@ -5249,7 +5248,7 @@ name = "node-runtime" version = "1.39.1" source = "git+https://github.com/kobayurii/nearcore.git?branch=1.39.1-fork#814725874d755bbf449a84669c13eb3c206c374d" dependencies = [ - "borsh 1.4.0", + "borsh 1.5.0", "hex", "near-chain-configs 1.39.1", "near-crypto 1.39.1", @@ -5335,11 +5334,10 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", ] @@ -5374,9 +5372,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -5409,7 +5407,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -5425,7 +5423,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "crc32fast", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "indexmap 2.2.6", "memchr", ] @@ -5465,7 +5463,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -5634,12 +5632,6 @@ dependencies = [ "tokio-stream", ] -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" - [[package]] name = "ordered-float" version = "2.10.1" @@ -5704,7 +5696,7 @@ dependencies = [ "paperclip-actix", "paperclip-core", "paperclip-macros", - "semver 1.0.22", + "semver 1.0.23", "serde", "serde_derive", "serde_json", @@ -5795,12 +5787,12 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ - "lock_api 0.4.11", - "parking_lot_core 0.9.9", + "lock_api 0.4.12", + "parking_lot_core 0.9.10", ] [[package]] @@ -5819,22 +5811,22 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.4.1", + "redox_syscall 0.5.1", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "peeking_take_while" @@ -5861,7 +5853,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "perf-testing" -version = "0.2.8" +version = "0.2.9" dependencies = [ "anyhow", "chrono", @@ -5880,9 +5872,9 @@ dependencies = [ [[package]] name = "petgraph" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", "indexmap 2.2.6", @@ -5923,7 +5915,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -6034,12 +6026,12 @@ checksum = "aa06bd51638b6e76ac9ba9b6afb4164fa647bd2916d722f2623fbb6d1ed8bdba" [[package]] name = "prettyplease" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -6120,24 +6112,24 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" dependencies = [ "unicode-ident", ] [[package]] name = "prometheus" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" +checksum = "3d33c28a30771f7f96db69893f78b857f7450d7e0237e9c8fc6427a81bae7ed1" dependencies = [ "cfg-if 1.0.0", "fnv", "lazy_static", "memchr", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "protobuf 2.28.0", "thiserror", ] @@ -6294,9 +6286,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -6366,7 +6358,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.14", + "getrandom 0.2.15", ] [[package]] @@ -6436,17 +6428,17 @@ dependencies = [ [[package]] name = "read-rpc-server" -version = "0.2.8" +version = "0.2.9" dependencies = [ "actix-cors 0.7.0", + "actix-http", "actix-web", "anyhow", "assert-json-diff", - "borsh 1.4.0", + "borsh 1.5.0", "chrono", "configuration", "database", - "dirs 5.0.1", "erased-serde", "futures", "futures-locks", @@ -6464,16 +6456,14 @@ dependencies = [ "near-parameters 1.39.1", "near-primitives 1.39.1", "near-vm-runner 1.39.1", - "paste", "prometheus", "readnode-primitives", "redis", "rustc_version 0.4.0", "serde", "serde_json", - "sysinfo 0.30.9", + "sysinfo 0.30.12", "thiserror", - "time", "tokio", "tokio-stream", "tracing", @@ -6482,10 +6472,10 @@ dependencies = [ [[package]] name = "readnode-primitives" -version = "0.2.8" +version = "0.2.9" dependencies = [ "anyhow", - "borsh 1.4.0", + "borsh 1.5.0", "near-chain-configs 1.39.1", "near-indexer-primitives", "num-traits", @@ -6513,7 +6503,7 @@ dependencies = [ "socket2", "tokio", "tokio-retry", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "url", ] @@ -6532,13 +6522,22 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.5.0", +] + [[package]] name = "redox_users" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ - "getrandom 0.2.14", + "getrandom 0.2.15", "libredox", "thiserror", ] @@ -6668,7 +6667,7 @@ dependencies = [ "system-configuration", "tokio", "tokio-native-tls", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "tower-service", "url", "wasm-bindgen", @@ -6718,7 +6717,7 @@ checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", "cfg-if 1.0.0", - "getrandom 0.2.14", + "getrandom 0.2.15", "libc", "spin 0.9.8", "untrusted 0.9.0", @@ -6826,9 +6825,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" @@ -6857,17 +6856,17 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.22", + "semver 1.0.23", ] [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", - "errno 0.3.8", + "errno 0.3.9", "libc", "linux-raw-sys", "windows-sys 0.52.0", @@ -6875,9 +6874,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.10" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring 0.17.8", @@ -6918,9 +6917,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "rxml" @@ -6941,9 +6940,9 @@ checksum = "22a197350ece202f19a166d1ad6d9d6de145e1d2a8ef47db299abe164dbd7530" [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" @@ -7025,7 +7024,7 @@ dependencies = [ "chrono", "lz4_flex", "num-bigint 0.3.3", - "num-bigint 0.4.4", + "num-bigint 0.4.5", "num_enum", "scylla-macros", "secrecy", @@ -7042,10 +7041,10 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb6085ff9c3fd7e5163826901d39164ab86f11bdca16b2f766a00c528ff9cef9" dependencies = [ - "darling 0.20.8", + "darling 0.20.9", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -7098,11 +7097,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -7111,9 +7110,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -7130,9 +7129,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "semver-parser" @@ -7142,9 +7141,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" dependencies = [ "serde_derive", ] @@ -7182,13 +7181,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -7202,9 +7201,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -7219,14 +7218,14 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] name = "serde_spanned" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" dependencies = [ "serde", ] @@ -7245,11 +7244,11 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.7.0" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a" +checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", "chrono", "hex", "indexmap 1.9.3", @@ -7263,14 +7262,14 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.7.0" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655" +checksum = "65569b702f41443e8bc8bbb1c5779bd0450bbe723b56198980e80ec45780bce2" dependencies = [ - "darling 0.20.8", + "darling 0.20.9", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -7341,9 +7340,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -7459,9 +7458,9 @@ checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b" [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -7503,11 +7502,11 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "state-indexer" -version = "0.2.8" +version = "0.2.9" dependencies = [ "actix-web", "anyhow", - "borsh 1.4.0", + "borsh 1.5.0", "clap", "configuration", "database", @@ -7635,9 +7634,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" dependencies = [ "proc-macro2", "quote", @@ -7653,7 +7652,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -7679,9 +7678,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.9" +version = "0.30.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9a84fe4cfc513b41cb2596b624e561ec9e7e1c4b46328e496ed56a53514ef2a" +checksum = "732ffa00f53e6b2af46208fba5718d9662a421049204e156328b66791ffa15ae" dependencies = [ "cfg-if 1.0.0", "core-foundation-sys", @@ -7738,7 +7737,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if 1.0.0", - "fastrand 2.0.2", + "fastrand 2.1.0", "rustix", "windows-sys 0.52.0", ] @@ -7756,22 +7755,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -7818,9 +7817,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", @@ -7839,9 +7838,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", @@ -7873,7 +7872,7 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "pin-project-lite", "signal-hook-registry", "socket2", @@ -7900,7 +7899,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -7938,7 +7937,7 @@ dependencies = [ "futures-channel", "futures-util", "log", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "percent-encoding", "phf", "pin-project-lite", @@ -7947,7 +7946,7 @@ dependencies = [ "rand 0.8.5", "socket2", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "whoami", ] @@ -7999,16 +7998,15 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -8034,21 +8032,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.12" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.9", + "toml_edit 0.22.13", ] [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] @@ -8079,15 +8077,15 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.9" +version = "0.22.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c" dependencies = [ "indexmap 2.2.6", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.5", + "winnow 0.6.8", ] [[package]] @@ -8147,7 +8145,7 @@ dependencies = [ "rand 0.8.5", "slab", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "tower-layer", "tower-service", "tracing", @@ -8210,7 +8208,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -8347,11 +8345,11 @@ dependencies = [ [[package]] name = "tx-indexer" -version = "0.2.8" +version = "0.2.9" dependencies = [ "actix-web", "anyhow", - "borsh 1.4.0", + "borsh 1.5.0", "clap", "configuration", "database", @@ -8369,6 +8367,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "typeid" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "059d83cc991e7a42fc37bd50941885db0888e34209f8cfd9aab07ddec03bc9cf" + [[package]] name = "typenum" version = "1.17.0" @@ -8425,9 +8429,9 @@ checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" [[package]] name = "unsafe-libyaml" @@ -8476,7 +8480,7 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ - "getrandom 0.2.14", + "getrandom 0.2.15", ] [[package]] @@ -8533,9 +8537,9 @@ checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" [[package]] name = "waker-fn" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" [[package]] name = "want" @@ -8585,7 +8589,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", "wasm-bindgen-shared", ] @@ -8619,7 +8623,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -8868,7 +8872,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" dependencies = [ "indexmap 2.2.6", - "semver 1.0.22", + "semver 1.0.23", ] [[package]] @@ -9077,7 +9081,7 @@ checksum = "09b5575a75e711ca6c36bb9ad647c93541cdc8e34218031acba5da3f35919dd3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] @@ -9175,7 +9179,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ "windows-core", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -9184,7 +9188,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -9202,7 +9206,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -9222,17 +9226,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -9243,9 +9248,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -9255,9 +9260,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -9267,9 +9272,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -9279,9 +9290,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -9291,9 +9302,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -9303,9 +9314,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -9315,9 +9326,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" @@ -9330,9 +9341,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" dependencies = [ "memchr", ] @@ -9385,22 +9396,22 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.65", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e9c1a9d1..c59b267c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "0.2.8" +version = "0.2.9" authors = ["Near Inc "] edition = "2021" rust-version = "1.77.0" diff --git a/database/Cargo.toml b/database/Cargo.toml index 4a7fa50e..535df2f8 100644 --- a/database/Cargo.toml +++ b/database/Cargo.toml @@ -19,8 +19,10 @@ diesel_migrations = { version = "2.1.0", optional = true } futures = "0.3.5" hex = "0.4.3" prettytable-rs = { version = "0.10", optional = true } +lazy_static = "1.4.0" num-bigint = { version = "0.4.4", optional = true } num-traits = { version = "0.2.15", optional = true } +prometheus = "0.13.1" scylla = { version = "0.12.0", features = ["full-serialization"], optional = true } scylla-cql = { version = "0.1.0", optional = true } serde = { version = "1.0.145", features = ["derive"]} diff --git a/database/src/base/rpc_server.rs b/database/src/base/rpc_server.rs index 5bda1a67..68f1e6c0 100644 --- a/database/src/base/rpc_server.rs +++ b/database/src/base/rpc_server.rs @@ -4,18 +4,21 @@ pub trait ReaderDbManager { async fn get_block_by_hash( &self, block_hash: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result; /// Searches the block height and shard id by the given chunk hash async fn get_block_by_chunk_hash( &self, chunk_hash: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result; /// Returns all state keys for the given account id async fn get_state_keys_all( &self, account_id: &near_primitives::types::AccountId, + method_name: &str, ) -> anyhow::Result>; /// Returns state keys for the given account id by page @@ -23,6 +26,7 @@ pub trait ReaderDbManager { &self, account_id: &near_primitives::types::AccountId, page_token: crate::PageToken, + method_name: &str, ) -> anyhow::Result<(Vec, crate::PageToken)>; /// Returns state keys for the given account id filtered by the given prefix @@ -30,6 +34,7 @@ pub trait ReaderDbManager { &self, account_id: &near_primitives::types::AccountId, prefix: &[u8], + method_name: &str, ) -> anyhow::Result>; /// Returns the state value for the given key of the given account at the given block height @@ -38,6 +43,7 @@ pub trait ReaderDbManager { account_id: &near_primitives::types::AccountId, block_height: near_primitives::types::BlockHeight, key_data: readnode_primitives::StateKey, + method_name: &str, ) -> ( readnode_primitives::StateKey, readnode_primitives::StateValue, @@ -48,6 +54,7 @@ pub trait ReaderDbManager { &self, account_id: &near_primitives::types::AccountId, request_block_height: near_primitives::types::BlockHeight, + method_name: &str, ) -> anyhow::Result>; /// Returns the contract code at the given block height @@ -55,6 +62,7 @@ pub trait ReaderDbManager { &self, account_id: &near_primitives::types::AccountId, request_block_height: near_primitives::types::BlockHeight, + method_name: &str, ) -> anyhow::Result>>; /// Returns the near_primitives::account::AccessKey at the given block height @@ -63,6 +71,7 @@ pub trait ReaderDbManager { account_id: &near_primitives::types::AccountId, request_block_height: near_primitives::types::BlockHeight, public_key: near_crypto::PublicKey, + method_name: &str, ) -> anyhow::Result>; #[cfg(feature = "account_access_keys")] @@ -70,28 +79,33 @@ pub trait ReaderDbManager { &self, account_id: &near_primitives::types::AccountId, block_height: near_primitives::types::BlockHeight, + method_name: &str, ) -> anyhow::Result>>; /// Returns the near_primitives::views::ReceiptView at the given receipt_id async fn get_receipt_by_id( &self, receipt_id: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result; /// Returns the readnode_primitives::TransactionDetails at the given transaction hash async fn get_transaction_by_hash( &self, transaction_hash: &str, + method_name: &str, ) -> anyhow::Result; /// Returns the readnode_primitives::TransactionDetails at the given transaction hash async fn get_indexed_transaction_by_hash( &self, transaction_hash: &str, + method_name: &str, ) -> anyhow::Result; /// Returns the readnode_primitives::TransactionDetails at the given transaction hash async fn get_indexing_transaction_by_hash( &self, transaction_hash: &str, + method_name: &str, ) -> anyhow::Result; /// Returns the block height and shard id by the given block height @@ -99,23 +113,27 @@ pub trait ReaderDbManager { &self, block_height: near_primitives::types::BlockHeight, shard_id: near_primitives::types::ShardId, + method_name: &str, ) -> anyhow::Result; /// Returns epoch validators info by the given epoch id async fn get_validators_by_epoch_id( &self, epoch_id: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result; /// Return epoch validators info by the given epoch end block height async fn get_validators_by_end_block_height( &self, block_height: near_primitives::types::BlockHeight, + method_name: &str, ) -> anyhow::Result; /// Return protocol config by the given epoch id async fn get_protocol_config_by_epoch_id( &self, epoch_id: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result; } diff --git a/database/src/lib.rs b/database/src/lib.rs index 42c4cca8..0ca555b0 100644 --- a/database/src/lib.rs +++ b/database/src/lib.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate lazy_static; + mod base; use crate::base::BaseDbManager; @@ -16,6 +19,7 @@ pub mod postgres; #[cfg(feature = "postgres_db")] pub use postgres::{models, schema}; +pub(crate) mod metrics; pub mod primitives; pub async fn prepare_db_manager(config: &configuration::DatabaseConfig) -> anyhow::Result diff --git a/database/src/metrics.rs b/database/src/metrics.rs new file mode 100644 index 00000000..11f4c382 --- /dev/null +++ b/database/src/metrics.rs @@ -0,0 +1,25 @@ +use prometheus::{IntCounterVec, Opts}; + +type Result = std::result::Result; + +fn register_int_counter_vec( + name: &str, + help: &str, + label_names: &[&str], +) -> Result { + let opts = Opts::new(name, help); + let counter = IntCounterVec::new(opts, label_names)?; + prometheus::register(Box::new(counter.clone()))?; + Ok(counter) +} + +// TODO: Implement metrics for postgres database +// https://github.com/near/read-rpc/issues/260 +lazy_static! { + pub(crate) static ref DATABASE_READ_QUERIES: IntCounterVec = register_int_counter_vec( + "database_read_queries_counter", + "Total number of database read queries by method_name and table_name", + &["method_name", "table_name"] + ) + .unwrap(); +} diff --git a/database/src/postgres/rpc_server.rs b/database/src/postgres/rpc_server.rs index 02141a8f..17bc32f8 100644 --- a/database/src/postgres/rpc_server.rs +++ b/database/src/postgres/rpc_server.rs @@ -29,6 +29,7 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_block_by_hash( &self, block_hash: near_indexer_primitives::CryptoHash, + _method_name: &str, ) -> anyhow::Result { let block_height = crate::models::Block::get_block_height_by_hash( Self::get_connection(&self.pg_pool).await?, @@ -43,6 +44,7 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_block_by_chunk_hash( &self, chunk_hash: near_indexer_primitives::CryptoHash, + _method_name: &str, ) -> anyhow::Result { let block_height_shard_id = crate::models::Chunk::get_block_height_by_chunk_hash( Self::get_connection(&self.pg_pool).await?, @@ -63,6 +65,7 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_state_keys_all( &self, account_id: &near_primitives::types::AccountId, + _method_name: &str, ) -> anyhow::Result> { let result = crate::models::AccountState::get_state_keys_all( Self::get_connection(&self.pg_pool).await?, @@ -78,6 +81,7 @@ impl crate::ReaderDbManager for PostgresDBManager { &self, account_id: &near_primitives::types::AccountId, prefix: &[u8], + _method_name: &str, ) -> anyhow::Result> { let hex_str_prefix = hex::encode(prefix); let result = crate::models::AccountState::get_state_keys_by_prefix( @@ -95,6 +99,7 @@ impl crate::ReaderDbManager for PostgresDBManager { &self, account_id: &near_primitives::types::AccountId, page_token: crate::PageToken, + _method_name: &str, ) -> anyhow::Result<(Vec, crate::PageToken)> { let (state_keys, next_page_token) = crate::models::AccountState::get_state_keys_by_page( Self::get_connection(&self.pg_pool).await?, @@ -114,6 +119,7 @@ impl crate::ReaderDbManager for PostgresDBManager { account_id: &near_primitives::types::AccountId, block_height: near_primitives::types::BlockHeight, key_data: readnode_primitives::StateKey, + _method_name: &str, ) -> ( readnode_primitives::StateKey, readnode_primitives::StateValue, @@ -142,6 +148,7 @@ impl crate::ReaderDbManager for PostgresDBManager { &self, account_id: &near_primitives::types::AccountId, request_block_height: near_primitives::types::BlockHeight, + _method_name: &str, ) -> anyhow::Result> { let account_data = crate::models::StateChangesAccount::get_account( Self::get_connection(&self.pg_pool).await?, @@ -172,6 +179,7 @@ impl crate::ReaderDbManager for PostgresDBManager { &self, account_id: &near_primitives::types::AccountId, request_block_height: near_primitives::types::BlockHeight, + _method_name: &str, ) -> anyhow::Result>> { let contract_data = crate::models::StateChangesContract::get_contract( Self::get_connection(&self.pg_pool).await?, @@ -203,6 +211,7 @@ impl crate::ReaderDbManager for PostgresDBManager { account_id: &near_primitives::types::AccountId, request_block_height: near_primitives::types::BlockHeight, public_key: near_crypto::PublicKey, + _method_name: &str, ) -> anyhow::Result> { let key_data = borsh::to_vec(&public_key)?; let access_key_data = crate::models::StateChangesAccessKey::get_access_key( @@ -237,6 +246,7 @@ impl crate::ReaderDbManager for PostgresDBManager { &self, account_id: &near_primitives::types::AccountId, block_height: near_primitives::types::BlockHeight, + _method_name: &str, ) -> anyhow::Result>> { let active_access_keys = crate::models::StateChangesAccessKeys::get_active_access_keys( Self::get_connection(&self.pg_pool).await?, @@ -257,6 +267,7 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_receipt_by_id( &self, receipt_id: near_indexer_primitives::CryptoHash, + _method_name: &str, ) -> anyhow::Result { let receipt = crate::models::ReceiptMap::get_receipt_by_id( Self::get_connection(&self.pg_pool).await?, @@ -274,11 +285,15 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_transaction_by_hash( &self, transaction_hash: &str, + method_name: &str, ) -> anyhow::Result { - if let Ok(transaction) = self.get_indexed_transaction_by_hash(transaction_hash).await { + if let Ok(transaction) = self + .get_indexed_transaction_by_hash(transaction_hash, method_name) + .await + { Ok(transaction) } else { - self.get_indexing_transaction_by_hash(transaction_hash) + self.get_indexing_transaction_by_hash(transaction_hash, method_name) .await } } @@ -286,6 +301,7 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_indexed_transaction_by_hash( &self, transaction_hash: &str, + _method_name: &str, ) -> anyhow::Result { let transaction_data = crate::models::TransactionDetail::get_transaction_by_hash( Self::get_connection(&self.pg_pool).await?, @@ -298,6 +314,7 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_indexing_transaction_by_hash( &self, transaction_hash: &str, + _method_name: &str, ) -> anyhow::Result { let data_value = crate::models::TransactionCache::get_transaction_by_hash( Self::get_connection(&self.pg_pool).await?, @@ -332,6 +349,7 @@ impl crate::ReaderDbManager for PostgresDBManager { &self, block_height: near_primitives::types::BlockHeight, shard_id: near_primitives::types::ShardId, + _method_name: &str, ) -> anyhow::Result { let block_height_shard_id = crate::models::Chunk::get_stored_block_height( Self::get_connection(&self.pg_pool).await?, @@ -354,6 +372,7 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_validators_by_epoch_id( &self, epoch_id: near_indexer_primitives::CryptoHash, + _method_name: &str, ) -> anyhow::Result { let epoch = crate::models::Validators::get_validators( Self::get_connection(&self.pg_pool).await?, @@ -382,6 +401,7 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_validators_by_end_block_height( &self, block_height: near_primitives::types::BlockHeight, + _method_name: &str, ) -> anyhow::Result { let epoch = crate::models::Validators::get_validators_epoch_end_height( Self::get_connection(&self.pg_pool).await?, @@ -412,6 +432,7 @@ impl crate::ReaderDbManager for PostgresDBManager { async fn get_protocol_config_by_epoch_id( &self, epoch_id: near_indexer_primitives::CryptoHash, + _method_name: &str, ) -> anyhow::Result { let protocol_config = crate::models::ProtocolConfig::get_protocol_config( Self::get_connection(&self.pg_pool).await?, diff --git a/database/src/scylladb/rpc_server.rs b/database/src/scylladb/rpc_server.rs index 6f7095f0..5f153f28 100644 --- a/database/src/scylladb/rpc_server.rs +++ b/database/src/scylladb/rpc_server.rs @@ -160,7 +160,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_block_by_hash( &self, block_hash: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.blocks"]) + .inc(); let (result,) = Self::execute_prepared_query( &self.scylla_session, &self.get_block_by_hash, @@ -179,7 +183,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_block_by_chunk_hash( &self, chunk_hash: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.chunks"]) + .inc(); let block_height_shard_id = Self::execute_prepared_query( &self.scylla_session, &self.get_block_by_chunk_id, @@ -208,7 +216,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_state_keys_all( &self, account_id: &near_primitives::types::AccountId, + method_name: &str, ) -> anyhow::Result> { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.account_state"]) + .inc(); let mut paged_query = self.get_all_state_keys.clone(); paged_query.set_page_size(25000); let mut rows_stream = self @@ -233,7 +245,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { &self, account_id: &near_primitives::types::AccountId, page_token: crate::PageToken, + method_name: &str, ) -> anyhow::Result<(Vec, crate::PageToken)> { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.account_state"]) + .inc(); let mut paged_query = self.get_all_state_keys.clone(); paged_query.set_page_size(1000); @@ -265,7 +281,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { &self, account_id: &near_primitives::types::AccountId, prefix: &[u8], + method_name: &str, ) -> anyhow::Result> { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.account_state"]) + .inc(); let hex_str_prefix = hex::encode(prefix); let result = Self::execute_prepared_query( &self.scylla_session, @@ -288,10 +308,14 @@ impl crate::ReaderDbManager for ScyllaDBManager { account_id: &near_primitives::types::AccountId, block_height: near_primitives::types::BlockHeight, key_data: readnode_primitives::StateKey, + method_name: &str, ) -> ( readnode_primitives::StateKey, readnode_primitives::StateValue, ) { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.state_changes_data"]) + .inc(); let value = match Self::execute_prepared_query( &self.scylla_session, &self.get_state_key_value, @@ -320,7 +344,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { &self, account_id: &near_primitives::types::AccountId, request_block_height: near_primitives::types::BlockHeight, + method_name: &str, ) -> anyhow::Result> { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.state_changes_account"]) + .inc(); let (block_height, block_hash, data_blob) = Self::execute_prepared_query( &self.scylla_session, &self.get_account, @@ -347,7 +375,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { &self, account_id: &near_primitives::types::AccountId, request_block_height: near_primitives::types::BlockHeight, + method_name: &str, ) -> anyhow::Result>> { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.state_changes_contract"]) + .inc(); let (block_height, block_hash, contract_code) = Self::execute_prepared_query( &self.scylla_session, &self.get_contract_code, @@ -375,7 +407,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { account_id: &near_primitives::types::AccountId, request_block_height: near_primitives::types::BlockHeight, public_key: near_crypto::PublicKey, + method_name: &str, ) -> anyhow::Result> { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.state_changes_access_key"]) + .inc(); let key_data = borsh::to_vec(&public_key)?; let (block_height, block_hash, data_blob) = Self::execute_prepared_query( &self.scylla_session, @@ -404,7 +440,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { &self, account_id: &near_primitives::types::AccountId, block_height: near_primitives::types::BlockHeight, + method_name: &str, ) -> anyhow::Result>> { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.account_access_keys"]) + .inc(); let (account_keys,) = Self::execute_prepared_query( &self.scylla_session, &self.get_account_access_keys, @@ -423,7 +463,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_receipt_by_id( &self, receipt_id: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "tx_indexer.receipts_map"]) + .inc(); let row = Self::execute_prepared_query( &self.scylla_session, &self.get_receipt, @@ -440,11 +484,15 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_transaction_by_hash( &self, transaction_hash: &str, + method_name: &str, ) -> anyhow::Result { - if let Ok(transaction) = self.get_indexed_transaction_by_hash(transaction_hash).await { + if let Ok(transaction) = self + .get_indexed_transaction_by_hash(transaction_hash, method_name) + .await + { Ok(transaction) } else { - self.get_indexing_transaction_by_hash(transaction_hash) + self.get_indexing_transaction_by_hash(transaction_hash, method_name) .await } } @@ -454,7 +502,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_indexed_transaction_by_hash( &self, transaction_hash: &str, + method_name: &str, ) -> anyhow::Result { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "tx_indexer.transactions_details"]) + .inc(); let (data_value,) = Self::execute_prepared_query( &self.scylla_session, &self.get_transaction_by_hash, @@ -481,7 +533,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_indexing_transaction_by_hash( &self, transaction_hash: &str, + method_name: &str, ) -> anyhow::Result { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "tx_indexer_cache.transactions"]) + .inc(); let (data_value,) = Self::execute_prepared_query( &self.scylla_session, &self.get_indexing_transaction_by_hash, @@ -493,6 +549,9 @@ impl crate::ReaderDbManager for ScyllaDBManager { let mut transaction_details = borsh::from_slice::(&data_value)?; + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "tx_indexer_cache.receipts_outcomes"]) + .inc(); let mut rows_stream = self .scylla_session .execute_iter( @@ -523,7 +582,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { &self, block_height: near_primitives::types::BlockHeight, shard_id: near_primitives::types::ShardId, + method_name: &str, ) -> anyhow::Result { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.chunks"]) + .inc(); let rows = Self::execute_prepared_query( &self.scylla_session, &self.get_stored_at_block_height_and_shard_id_by_block_height, @@ -551,7 +614,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_validators_by_epoch_id( &self, epoch_id: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.validators"]) + .inc(); let (epoch_height, validators_info) = Self::execute_prepared_query( &self.scylla_session, &self.get_validators_by_epoch_id, @@ -577,7 +644,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_protocol_config_by_epoch_id( &self, epoch_id: near_primitives::hash::CryptoHash, + method_name: &str, ) -> anyhow::Result { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.protocol_configs"]) + .inc(); let (protocol_config,) = Self::execute_prepared_query( &self.scylla_session, &self.get_protocol_config_by_epoch_id, @@ -596,7 +667,11 @@ impl crate::ReaderDbManager for ScyllaDBManager { async fn get_validators_by_end_block_height( &self, block_height: near_primitives::types::BlockHeight, + method_name: &str, ) -> anyhow::Result { + crate::metrics::DATABASE_READ_QUERIES + .with_label_values(&[method_name, "state_indexer.validators"]) + .inc(); let (epoch_id, epoch_height, validators_info) = Self::execute_prepared_query( &self.scylla_session, &self.get_validators_by_end_block_height, diff --git a/docs/CUSTOM_RPC_METHODS.md b/docs/CUSTOM_RPC_METHODS.md index 6a7db218..33927ed9 100644 --- a/docs/CUSTOM_RPC_METHODS.md +++ b/docs/CUSTOM_RPC_METHODS.md @@ -85,3 +85,34 @@ Next page response: ``` In the last page response `next_page_token` field will be `null`. +# view_receipt_record + +The `view_receipt_record` method is a custom method that allows you to view the record of the receipt by its ID. + +## How to use it +### Example + +Request: +```json +{ + "jsonrpc": "2.0", + "id": "dontcare", + "method": "view_receipt_record", + "params": { + "receipt_id": "6aB1XxfnhuQ83FWHb5xyqssGnaD5CUQgxHpbAVJFRrPe" + } +} +``` +Response: +```json +{ + "id": "dontcare", + "jsonrpc": "2.0", + "result": { + "block_height": 118875440, + "parent_transaction_hash": "6iJgcM5iZrWuhG4ZpUyX6ivtMQUho2S1JRdBYdY7Y7vX", + "receipt_id": "6aB1XxfnhuQ83FWHb5xyqssGnaD5CUQgxHpbAVJFRrPe", + "shard_id": 0 + } +} +``` diff --git a/docs/RPC_METHODS.md b/docs/RPC_METHODS.md index 7d45dae3..a610206e 100644 --- a/docs/RPC_METHODS.md +++ b/docs/RPC_METHODS.md @@ -1,33 +1,34 @@ -| **Method** | **status** | **Note** | -|----------------------------------|---------------|-----------------------------------------------------------------------------| -| view_state_paginated | Included | Custom method. See details [here](../docs/CUSTOM_RPC_METHODS.md) | -| query.view_account | Included | | -| query.view_code | Included | | -| query.view_state | Included | | -| query.call_function | Included | | -| query.view_access_key | Included | | -| query.view_access_key_list | Proxy | Planned. It will be implemented in the future. | -| block | Included | | -| broadcast_tx_async | Proxy | PROXY_ONLY. Immediately proxy to a real RPC. | -| broadcast_tx_commit | Proxy | PROXY_ONLY. Immediately proxy to a real RPC. | -| chunk | Included | | -| gas_price | Included | | -| health | Included | Health includes the info about the syncing state of the node of rpc-server. | -| light_client_proof | Proxy | | -| next_light_client_block | Proxy | | -| network_info | Proxy | PROXY_ONLY. Immediately proxy to a real RPC. | -| status | Included | | -| send_tx | Proxy | PROXY_ONLY. Immediately proxy to a real RPC. | -| tx | Included | | -| validators | Included | | -| client_config | Unimplemented | | -| EXPERIMENTAL_changes | Included | | -| EXPERIMENTAL_changes_in_block | Included | | -| EXPERIMENTAL_genesis_config | Included | Cache it on the start. | -| EXPERIMENTAL_light_client_proof | Proxy | | -| EXPERIMENTAL_protocol_config | Included | | -| EXPETIMENTAL_receipt | Included | | -| EXPERIMENTAL_tx_status | Included | | -| EXPERIMENTAL_validators_ordered | Proxy | | -| EXPERIMENTAL_maintenance_windows | Unimplemented | | -| EXPERIMENTAL_split_storage_info | Unimplemented | | +| **Method** | **status** | **Note** | +|-----------------------------------|---------------|-----------------------------------------------------------------------------| +| view_state_paginated | Included | Custom method. See details [here](../docs/CUSTOM_RPC_METHODS.md) | +| view_receipt_record | Included | Custom method. See details [here](../docs/CUSTOM_RPC_METHODS.md) | +| query.view_account | Included | | +| query.view_code | Included | | +| query.view_state | Included | | +| query.call_function | Included | | +| query.view_access_key | Included | | +| query.view_access_key_list | Proxy | Planned. It will be implemented in the future. | +| block | Included | | +| broadcast_tx_async | Proxy | PROXY_ONLY. Immediately proxy to a real RPC. | +| broadcast_tx_commit | Proxy | PROXY_ONLY. Immediately proxy to a real RPC. | +| chunk | Included | | +| gas_price | Included | | +| health | Included | Health includes the info about the syncing state of the node of rpc-server. | +| light_client_proof | Proxy | | +| next_light_client_block | Proxy | | +| network_info | Proxy | PROXY_ONLY. Immediately proxy to a real RPC. | +| status | Included | | +| send_tx | Proxy | PROXY_ONLY. Immediately proxy to a real RPC. | +| tx | Included | | +| validators | Included | | +| client_config | Unimplemented | | +| EXPERIMENTAL_changes | Included | | +| EXPERIMENTAL_changes_in_block | Included | | +| EXPERIMENTAL_genesis_config | Included | Cache it on the start. | +| EXPERIMENTAL_light_client_proof | Proxy | | +| EXPERIMENTAL_protocol_config | Included | | +| EXPETIMENTAL_receipt | Included | | +| EXPERIMENTAL_tx_status | Included | | +| EXPERIMENTAL_validators_ordered | Proxy | | +| EXPERIMENTAL_maintenance_windows | Unimplemented | | +| EXPERIMENTAL_split_storage_info | Unimplemented | | diff --git a/near-state-indexer/src/utils.rs b/near-state-indexer/src/utils.rs index 2c44ac12..8336a03e 100644 --- a/near-state-indexer/src/utils.rs +++ b/near-state-indexer/src/utils.rs @@ -97,7 +97,7 @@ pub(crate) async fn update_block_streamer_message( let update_height_feature = redis_set_cmd .arg(format!("{}_height", block_type)) .arg(block_height) - .query_async::(&mut redis_client_clone); + .query_async::(&mut redis_client_clone); // Update the block streamer message // Create a clone of the redis client and redis cmd to avoid borrowing issues diff --git a/readnode-primitives/src/lib.rs b/readnode-primitives/src/lib.rs index 4f73080c..aba339d1 100644 --- a/readnode-primitives/src/lib.rs +++ b/readnode-primitives/src/lib.rs @@ -177,6 +177,7 @@ pub struct QueryData { pub block_height: near_indexer_primitives::types::BlockHeight, pub block_hash: CryptoHash, } + pub struct ReceiptRecord { pub receipt_id: CryptoHash, pub parent_transaction_hash: CryptoHash, diff --git a/rpc-server/Cargo.toml b/rpc-server/Cargo.toml index 77a049f1..3f6fe022 100644 --- a/rpc-server/Cargo.toml +++ b/rpc-server/Cargo.toml @@ -12,28 +12,26 @@ anyhow = "1.0.51" rustc_version = "0.4" [dependencies] +actix-http = "3.6.0" actix-web = "4.5.1" actix-cors = "0.7.0" anyhow = "1.0.70" assert-json-diff = { version = "2.0.2", optional = true } borsh = "1.3.1" chrono = "0.4.19" -dirs = "5.0.1" erased-serde = "0.4.2" futures = "0.3.24" futures-locks = "0.7.1" hex = "0.4.3" -jsonrpc-v2 = { git = "https://github.com/kobayurii/jsonrpc-v2", branch = "master" } +jsonrpc-v2 = { git = "https://github.com/kobayurii/jsonrpc-v2", branch = "fork" } lazy_static = "1.4.0" lru = "0.12.2" mimalloc = { version = "0.1.41", default-features = false } -paste = "1.0.14" prometheus = "0.13.1" redis = { version = "0.25.2", features = ["tokio-comp", "connection-manager"] } serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0.85" thiserror = "1.0.40" -time = "0.3.34" tokio = { version = "1.36.0", features = ["full", "tracing"] } tokio-stream = { version = "0.1.12" } tracing = { version = "0.1.36", features = ["std"] } diff --git a/rpc-server/src/errors.rs b/rpc-server/src/errors.rs index 3194e03e..feaa98f8 100644 --- a/rpc-server/src/errors.rs +++ b/rpc-server/src/errors.rs @@ -2,7 +2,7 @@ use std::ops::{Deref, DerefMut}; use near_jsonrpc_client::errors::{JsonRpcError, JsonRpcServerError}; -type BoxedSerialize = Box; +type BoxedSerialize = Box; #[derive(Debug, serde::Serialize)] #[serde(transparent)] diff --git a/rpc-server/src/main.rs b/rpc-server/src/main.rs index bb5226e5..0142af2d 100644 --- a/rpc-server/src/main.rs +++ b/rpc-server/src/main.rs @@ -1,4 +1,3 @@ -use actix_web::dev::Service; use jsonrpc_v2::{Data, Server}; use mimalloc::MiMalloc; @@ -13,6 +12,7 @@ mod config; mod errors; mod health; mod metrics; +mod middlewares; mod modules; mod utils; @@ -91,6 +91,10 @@ async fn main() -> anyhow::Result<()> { "view_state_paginated", modules::state::methods::view_state_paginated, ) + .with_method( + "view_receipt_record", + modules::receipts::methods::view_receipt_record, + ) // requests methods .with_method("query", modules::queries::methods::query) // basic requests methods @@ -169,12 +173,7 @@ async fn main() -> anyhow::Result<()> { .wrap(cors) .wrap(tracing_actix_web::TracingLogger::default()) // wrapper to count rpc total requests - .wrap_fn(|request, service| { - if request.path() == "/" { - metrics::TOTAL_REQUESTS_COUNTER.inc(); - }; - service.call(request) - }) + .wrap(middlewares::RequestsCounters) .app_data(actix_web::web::Data::new(server_context.clone())) .service( actix_web::web::service("/") diff --git a/rpc-server/src/metrics.rs b/rpc-server/src/metrics.rs index dc3f7801..dbfd6135 100644 --- a/rpc-server/src/metrics.rs +++ b/rpc-server/src/metrics.rs @@ -1,11 +1,15 @@ use actix_web::{get, Responder}; -use prometheus::{Encoder, IntCounter, IntGauge, Opts}; +use prometheus::{Encoder, IntCounterVec, IntGauge, IntGaugeVec, Opts}; type Result = std::result::Result; -fn try_create_int_counter(name: &str, help: &str) -> Result { +fn register_int_counter_vec( + name: &str, + help: &str, + label_names: &[&str], +) -> Result { let opts = Opts::new(name, help); - let counter = IntCounter::with_opts(opts)?; + let counter = IntCounterVec::new(opts, label_names)?; prometheus::register(Box::new(counter.clone()))?; Ok(counter) } @@ -17,6 +21,17 @@ fn try_create_int_gauge(name: &str, help: &str) -> Result Result { + let opts = Opts::new(name, help); + let counter = IntGaugeVec::new(opts, label_names)?; + prometheus::register(Box::new(counter.clone()))?; + Ok(counter) +} + // Struct to store the optimistic updating state // This is used to track if the optimistic updating is working or not // By default, it is set as working @@ -26,6 +41,7 @@ pub struct OptimisticUpdating { impl OptimisticUpdating { pub fn new() -> Self { + OPTIMISTIC_STATUS.set(0); Self { is_not_working: std::sync::atomic::AtomicBool::new(false), } @@ -51,618 +67,108 @@ impl OptimisticUpdating { // Set optimistic updating as not working pub fn set_not_working(&self) { self.set(true); + OPTIMISTIC_STATUS.set(1); } // Set optimistic updating as working pub fn set_working(&self) { self.set(false); + OPTIMISTIC_STATUS.set(0); } } +// Is not a metric, but a global variable to track the optimistic updating status lazy_static! { - pub(crate) static ref OPTIMISTIC_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "total_optimistic_requests", - "Total number of the request where finality was set to optimistic" - ) - .unwrap(); - pub(crate) static ref FINAL_BLOCK_HEIGHT: IntGauge = try_create_int_gauge( - "final_block_height", - "The final block height from the perspective of the READ RPC server" - ) - .unwrap(); - pub(crate) static ref OPTIMISTIC_BLOCK_HEIGHT: IntGauge = try_create_int_gauge( - "optimistic_block_height", - "The optimistic block height from the perspective of the READ RPC server" - ) - .unwrap(); - pub(crate) static ref OPTIMISTIC_UPDATING: OptimisticUpdating = OptimisticUpdating::new(); - - // REQUESTS TOTAL COUNTERS - // total requests counter - pub(crate) static ref TOTAL_REQUESTS_COUNTER: IntCounter = try_create_int_counter( - "total_request_counter", - "Total number requests" - ) - .unwrap(); - pub(crate) static ref PROXY_OPTIMISTIC_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "proxy_optimistic_requests", - "Total number of the request where finality was set to optimistic and proxy to regular nodes" - ) - .unwrap(); - pub(crate) static ref PROXY_REQUESTS_TO_REGULAR_NODES_COUNTER: IntCounter = try_create_int_counter( - "proxy_request_to_regular_nodes_counter", - "Total number requests proxy to regular nodes" - ) - .unwrap(); - pub(crate) static ref PROXY_REQUESTS_TO_ARCHIVAL_NODES_COUNTER: IntCounter = try_create_int_counter( - "proxy_request_to_archival_nodes_counter", - "Total number requests proxy to archival nodes" - ) - .unwrap(); - - // query requests counters - pub(crate) static ref QUERY_VIEW_ACCOUNT_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "query_view_account_requests_counter", - "Total number requests to the query view account endpoint" - ) - .unwrap(); - pub(crate) static ref QUERY_VIEW_CODE_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "query_view_code_requests_counter", - "Total number requests to the query view code endpoint" - ) - .unwrap(); - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "query_view_access_key_requests_counter", - "Total number requests to the query view access key endpoint" - ).unwrap(); - pub(crate) static ref QUERY_VIEW_STATE_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "query_view_state_requests_counter", - "Total number requests to the query view state endpoint" - ).unwrap(); - pub(crate) static ref QUERY_FUNCTION_CALL_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "query_function_call_requests_counter", - "Total number requests to the query function call endpoint" - ).unwrap(); - pub(crate) static ref QUERY_VIEW_ACCESS_KEYS_LIST_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "query_access_keys_list_requests_counter", - "Total number requests to the query access keys list endpoint" - ).unwrap(); - - // blocks requests counters - pub(crate) static ref BLOCK_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "block_requests_counter", - "Total number requests to the block endpoint" - ).unwrap(); - pub(crate) static ref CHNGES_IN_BLOCK_BY_TYPE_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "changes_in_block_by_type_requests_counter", - "Total number requests to the changes in block by type endpoint" - ).unwrap(); - pub(crate) static ref CHNGES_IN_BLOCK_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "changes_in_block_requests_counter", - "Total number requests to the changes in block endpoint" - ).unwrap(); - pub(crate) static ref CHUNK_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "chunk_requests_counter", - "Total number requests to the chunk endpoint" - ).unwrap(); - - // gas_price requests counters - pub(crate) static ref GAS_PRICE_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "gas_price_requests_counter", - "Total number requests to the gas_price endpoint" - ).unwrap(); - - // transactions requests counters - pub(crate) static ref TX_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "tx_requests_counter", - "Total number requests to the tx endpoint" - ).unwrap(); - pub(crate) static ref TX_STATUS_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "tx_status_requests_counter", - "Total number requests to the tx status endpoint" - ).unwrap(); - pub(crate) static ref RECEIPT_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "receipt_requests_counter", - "Total number requests to the receipt endpoint" - ).unwrap(); - - // validators requests counters - pub(crate) static ref VALIDATORS_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "validators_requests_counter", - "Total number requests to the validators endpoint" - ).unwrap(); - - // protocol config requests counters - pub(crate) static ref PROTOCOL_CONFIG_REQUESTS_TOTAL: IntCounter = try_create_int_counter( - "protocol_config_requests_counter", - "Total number requests to the protocol_config endpoint" - ).unwrap(); -} - -// Error counters -// QUERY counters -lazy_static! { - // QUERY.view_account - pub(crate) static ref QUERY_VIEW_ACCOUNT_ERROR_0: IntCounter = try_create_int_counter( - "query_view_account_error_0", - "Query.view_account error 0: ReadRPC success, NEAR RPC success" - ) - .unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCOUNT_ERROR_1: IntCounter = try_create_int_counter( - "query_view_account_error_1", - "Query.view_account error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCOUNT_ERROR_2: IntCounter = try_create_int_counter( - "query_view_account_error_2", - "Query.view_account error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCOUNT_ERROR_3: IntCounter = try_create_int_counter( - "query_view_account_error_3", - "Query.view_account error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCOUNT_ERROR_4: IntCounter = try_create_int_counter( - "query_view_account_error_4", - "Query.view_account error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end QUERY.view_account -} - -lazy_static! { - // QUERY.view_code - pub(crate) static ref QUERY_VIEW_CODE_ERROR_0: IntCounter = try_create_int_counter( - "query_view_code_error_0", - "Query.view_code error 0: ReadRPC success, NEAR RPC success" - ) - .unwrap(); - - pub(crate) static ref QUERY_VIEW_CODE_ERROR_1: IntCounter = try_create_int_counter( - "query_view_code_error_1", - "Query.view_code error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_CODE_ERROR_2: IntCounter = try_create_int_counter( - "query_view_code_error_2", - "Query.view_code error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_CODE_ERROR_3: IntCounter = try_create_int_counter( - "query_view_code_error_3", - "Query.view_code error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_CODE_ERROR_4: IntCounter = try_create_int_counter( - "query_view_code_error_4", - "Query.view_code error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end QUERY.view_code -} - -lazy_static! { - // QUERY.view_access_key - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_ERROR_0: IntCounter = try_create_int_counter( - "query_view_access_key_error_0", - "Query.view_access_key error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_ERROR_1: IntCounter = try_create_int_counter( - "query_view_access_key_error_1", - "Query.view_access_key error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_ERROR_2: IntCounter = try_create_int_counter( - "query_view_access_key_error_2", - "Query.view_access_key error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_ERROR_3: IntCounter = try_create_int_counter( - "query_view_access_key_error_3", - "Query.view_access_key error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_ERROR_4: IntCounter = try_create_int_counter( - "query_view_access_key_error_4", - "Query.view_access_key error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end QUERY.view_access_key -} - -lazy_static! { - // QUERY.view_state - pub(crate) static ref QUERY_VIEW_STATE_ERROR_0: IntCounter = try_create_int_counter( - "query_view_state_error_0", - "Query.view_state error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_STATE_ERROR_1: IntCounter = try_create_int_counter( - "query_view_state_error_1", - "Query.view_state error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_STATE_ERROR_2: IntCounter = try_create_int_counter( - "query_view_state_error_2", - "Query.view_state error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_STATE_ERROR_3: IntCounter = try_create_int_counter( - "query_view_state_error_3", - "Query.view_state error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_STATE_ERROR_4: IntCounter = try_create_int_counter( - "query_view_state_error_4", - "Query.view_state error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end QUERY.view_state -} - -lazy_static! { - // QUERY.function_call - pub(crate) static ref QUERY_FUNCTION_CALL_ERROR_0: IntCounter = try_create_int_counter( - "query_function_call_error_0", - "Query.function_call error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_FUNCTION_CALL_ERROR_1: IntCounter = try_create_int_counter( - "query_function_call_error_1", - "Query.function_call error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_FUNCTION_CALL_ERROR_2: IntCounter = try_create_int_counter( - "query_function_call_error_2", - "Query.function_call error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_FUNCTION_CALL_ERROR_3: IntCounter = try_create_int_counter( - "query_function_call_error_3", - "Query.function_call error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_FUNCTION_CALL_ERROR_4: IntCounter = try_create_int_counter( - "query_function_call_error_4", - "Query.function_call error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end QUERY.function_call -} - -lazy_static! { - // QUERY.view_access_key_list - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_LIST_ERROR_0: IntCounter = try_create_int_counter( - "query_view_access_key_list_error_0", - "Query.view_access_key_list error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_LIST_ERROR_1: IntCounter = try_create_int_counter( - "query_view_access_key_list_error_1", - "Query.view_access_key_list error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_LIST_ERROR_2: IntCounter = try_create_int_counter( - "query_view_access_key_list_error_2", - "Query.view_access_key_list error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_LIST_ERROR_3: IntCounter = try_create_int_counter( - "query_view_access_key_list_error_3", - "Query.view_access_key_list error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref QUERY_VIEW_ACCESS_KEY_LIST_ERROR_4: IntCounter = try_create_int_counter( - "query_view_access_key_list_error_4", - "Query.view_access_key_list error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end QUERY.view_access_key_list -} -// end QUERY - -lazy_static! { - // BLOCK - pub(crate) static ref BLOCK_ERROR_0: IntCounter = try_create_int_counter( - "block_error_0", - "Block error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref BLOCK_ERROR_1: IntCounter = try_create_int_counter( - "block_error_1", - "Block error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref BLOCK_ERROR_2: IntCounter = try_create_int_counter( - "block_error_2", - "Block error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref BLOCK_ERROR_3: IntCounter = try_create_int_counter( - "block_error_3", - "Block error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref BLOCK_ERROR_4: IntCounter = try_create_int_counter( - "block_error_4", - "Block error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end BLOCK -} - -lazy_static! { - // CHUNK - pub(crate) static ref CHUNK_ERROR_0: IntCounter = try_create_int_counter( - "chunk_error_0", - "Chunk error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref CHUNK_ERROR_1: IntCounter = try_create_int_counter( - "chunk_error_1", - "Chunk error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref CHUNK_ERROR_2: IntCounter = try_create_int_counter( - "chunk_error_2", - "Chunk error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref CHUNK_ERROR_3: IntCounter = try_create_int_counter( - "chunk_error_3", - "Chunk error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref CHUNK_ERROR_4: IntCounter = try_create_int_counter( - "chunk_error_4", - "Chunk error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end CHUNK -} - -lazy_static! { - // GAS_PRICE - pub(crate) static ref GAS_PRICE_ERROR_0: IntCounter = try_create_int_counter( - "gas_price_error_0", - "Gas_price error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref GAS_PRICE_ERROR_1: IntCounter = try_create_int_counter( - "gas_price_error_1", - "Gas_price error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref GAS_PRICE_ERROR_2: IntCounter = try_create_int_counter( - "gas_price_error_2", - "Gas_price error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref GAS_PRICE_ERROR_3: IntCounter = try_create_int_counter( - "gas_price_error_3", - "Gas_price error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref GAS_PRICE_ERROR_4: IntCounter = try_create_int_counter( - "gas_price_error_4", - "Gas_price error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end GAS_PRICE -} - -lazy_static! { - // VALIDATORS - pub(crate) static ref VALIDATORS_ERROR_0: IntCounter = try_create_int_counter( - "validators_error_0", - "validators error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref VALIDATORS_ERROR_1: IntCounter = try_create_int_counter( - "validators_error_1", - "Validators error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref VALIDATORS_ERROR_2: IntCounter = try_create_int_counter( - "validators_error_2", - "Validators error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref VALIDATORS_ERROR_3: IntCounter = try_create_int_counter( - "validators_error_3", - "Validators error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref VALIDATORS_ERROR_4: IntCounter = try_create_int_counter( - "validators_error_4", - "Validators error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end VALIDATORS -} - -lazy_static! { - // PROTOCOL_CONFIG - pub(crate) static ref PROTOCOL_CONFIG_ERROR_0: IntCounter = try_create_int_counter( - "protocol_config_error_0", - "Protocol config error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref PROTOCOL_CONFIG_ERROR_1: IntCounter = try_create_int_counter( - "protocol_config_error_1", - "Protocol config error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref PROTOCOL_CONFIG_ERROR_2: IntCounter = try_create_int_counter( - "protocol_config_error_2", - "Protocol config error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref PROTOCOL_CONFIG_ERROR_3: IntCounter = try_create_int_counter( - "protocol_config_error_3", - "Protocol config error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref PROTOCOL_CONFIG_ERROR_4: IntCounter = try_create_int_counter( - "protocol_config_error_4", - "Protocol config error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end PROTOCOL_CONFIG -} - -lazy_static! { - // TX - pub(crate) static ref TX_ERROR_0: IntCounter = try_create_int_counter( - "tx_error_0", - "Tx error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref TX_ERROR_1: IntCounter = try_create_int_counter( - "tx_error_1", - "Tx error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref TX_ERROR_2: IntCounter = try_create_int_counter( - "tx_error_2", - "Tx error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref TX_ERROR_3: IntCounter = try_create_int_counter( - "tx_error_3", - "Tx error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref TX_ERROR_4: IntCounter = try_create_int_counter( - "tx_error_4", - "Tx error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end TX } +// Metrics lazy_static! { - // TX_STATUS - pub(crate) static ref EXPERIMENTAL_TX_STATUS_ERROR_0: IntCounter = try_create_int_counter( - "tx_status_error_0", - "TxStatus error 0: ReadRPC success, NEAR RPC success" + pub(crate) static ref LATEST_BLOCK_HEIGHT_BY_FINALITIY: IntGaugeVec = register_int_gauge_vec( + "latest_block_height_by_finality", + "Latest block height by finality", + &["block_type"] // This declares a label named `block_type` ).unwrap(); - pub(crate) static ref EXPERIMENTAL_TX_STATUS_ERROR_1: IntCounter = try_create_int_counter( - "tx_status_error_1", - "TxStatus error 1: ReadRPC success, NEAR RPC error" + pub(crate) static ref METHOD_CALLS_COUNTER: IntCounterVec = register_int_counter_vec( + "method_calls_counter", + "Total number of calls to the method", + &["method_name"] // This declares a label named `method name` ).unwrap(); - pub(crate) static ref EXPERIMENTAL_TX_STATUS_ERROR_2: IntCounter = try_create_int_counter( - "tx_status_error_2", - "TxStatus error 2: ReadRPC error, NEAR RPC success" + pub(crate) static ref REQUESTS_COUNTER: IntCounterVec = register_int_counter_vec( + "requests_counter", + "Total number of requests", + &["request_type"] // This declares a label named `request_type` ).unwrap(); - pub(crate) static ref EXPERIMENTAL_TX_STATUS_ERROR_3: IntCounter = try_create_int_counter( - "tx_status_error_3", - "TxStatus error 3: ReadRPC error, NEAR RPC error" + pub(crate) static ref OPTIMISTIC_STATUS: IntGauge = try_create_int_gauge( + "optimistic_status", + "Optimistic updating status. 0: working, 1: not working", ).unwrap(); - pub(crate) static ref EXPERIMENTAL_TX_STATUS_ERROR_4: IntCounter = try_create_int_counter( - "tx_status_error_4", - "TxStatus error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end TX_STATUS -} - -lazy_static! { - // CHANGES_IN_BLOCK_BY_TYPE - pub(crate) static ref CHANGES_IN_BLOCK_BY_TYPE_ERROR_0: IntCounter = try_create_int_counter( - "changes_in_block_by_type_error_0", - "ChangesInBlockByType error 0: ReadRPC success, NEAR RPC success" + // Error metrics + // 0: ReadRPC success, NEAR RPC success" + // 1: ReadRPC success, NEAR RPC error" + // 2: ReadRPC error, NEAR RPC success" + // 3: ReadRPC error, NEAR RPC error" + // 4: Failed to compare. Network or parsing error" + pub(crate) static ref REQUESTS_ERRORS: IntCounterVec = register_int_counter_vec( + "requests_methods_errors", + "Total number of errors for method with code", + &["method", "error_type"] ).unwrap(); - pub(crate) static ref CHANGES_IN_BLOCK_BY_TYPE_ERROR_1: IntCounter = try_create_int_counter( - "changes_in_block_by_type_error_1", - "ChangesInBlockByType error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref CHANGES_IN_BLOCK_BY_TYPE_ERROR_2: IntCounter = try_create_int_counter( - "changes_in_block_by_type_error_2", - "ChangesInBlockByType error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref CHANGES_IN_BLOCK_BY_TYPE_ERROR_3: IntCounter = try_create_int_counter( - "changes_in_block_by_type_error_3", - "ChangesInBlockByType error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref CHANGES_IN_BLOCK_BY_TYPE_ERROR_4: IntCounter = try_create_int_counter( - "changes_in_block_by_type_error_4", - "ChangesInBlockByType error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end CHANGES_IN_BLOCK_BY_TYPE } -lazy_static! { - // CHANGES_IN_BLOCK - pub(crate) static ref CHANGES_IN_BLOCK_ERROR_0: IntCounter = try_create_int_counter( - "changes_in_block_error_0", - "ChangesInBlock error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref CHANGES_IN_BLOCK_ERROR_1: IntCounter = try_create_int_counter( - "changes_in_block_error_1", - "ChangesInBlock error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref CHANGES_IN_BLOCK_ERROR_2: IntCounter = try_create_int_counter( - "changes_in_block_error_2", - "ChangesInBlock error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref CHANGES_IN_BLOCK_ERROR_3: IntCounter = try_create_int_counter( - "changes_in_block_error_3", - "ChangesInBlock error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref CHANGES_IN_BLOCK_ERROR_4: IntCounter = try_create_int_counter( - "changes_in_block_error_4", - "ChangesInBlock error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end CHANGES_IN_BLOCK -} - -lazy_static! { - // RECEIPT - pub(crate) static ref RECEIPT_ERROR_0: IntCounter = try_create_int_counter( - "receipt_error_0", - "Receipt error 0: ReadRPC success, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref RECEIPT_ERROR_1: IntCounter = try_create_int_counter( - "receipt_error_1", - "Receipt error 1: ReadRPC success, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref RECEIPT_ERROR_2: IntCounter = try_create_int_counter( - "receipt_error_2", - "Receipt error 2: ReadRPC error, NEAR RPC success" - ).unwrap(); - - pub(crate) static ref RECEIPT_ERROR_3: IntCounter = try_create_int_counter( - "receipt_error_3", - "Receipt error 3: ReadRPC error, NEAR RPC error" - ).unwrap(); - - pub(crate) static ref RECEIPT_ERROR_4: IntCounter = try_create_int_counter( - "receipt_error_4", - "Receipt error 4: Failed to compare. Network or parsing error" - ).unwrap(); - // end RECEIPT -} - -lazy_static! { - // ARCHIVAL PROXY CALL COUNTERS - pub(crate) static ref ARCHIVAL_PROXY_QUERY_VIEW_STATE_WITH_INCLUDE_PROOFS: IntCounter = try_create_int_counter( - "archive_proxy_query_view_state_with_include_proofs", - "Total number of the request to the archive nodes query_view_state with include_proofs" - ).unwrap(); - pub(crate) static ref ARCHIVAL_PROXY_LIGHT_CLIENT_PROOF: IntCounter = try_create_int_counter( - "archive_proxy_light_client_proof", - "Total number of the request to the archive nodes light_client_proof" - ).unwrap(); - pub(crate) static ref ARCHIVAL_PROXY_NEXT_LIGHT_CLIENT_BLOCK: IntCounter = try_create_int_counter( - "archive_proxy_next_light_client_block", - "Total number of the request to the archive nodes next_light_client_block" - ).unwrap(); +/// Help method to increment block category metrics +/// Main idea is to have a single place to increment metrics +/// It should help to analyze the most popular requests +/// And build s better caching strategy +pub async fn increase_request_category_metrics( + data: &jsonrpc_v2::Data, + block_reference: &near_primitives::types::BlockReference, + block_height: Option, +) { + match block_reference { + near_primitives::types::BlockReference::BlockId(_) => { + let final_block = data.blocks_info_by_finality.final_cache_block().await; + let expected_earliest_available_block = + final_block.block_height - 5 * data.genesis_info.genesis_config.epoch_length; + if block_height.unwrap_or_default() > expected_earliest_available_block { + // This is request to regular nodes which includes 5 last epochs + REQUESTS_COUNTER.with_label_values(&["regular"]).inc(); + } else { + // This is a request to archival nodes which include blocks from genesis (later than 5 epochs ago) + REQUESTS_COUNTER.with_label_values(&["historical"]).inc(); + } + } + near_primitives::types::BlockReference::Finality(finality) => { + match finality { + // Increase the REQUESTS_COUNTER `final` metric + // if the request has final finality + near_primitives::types::Finality::DoomSlug + | near_primitives::types::Finality::Final => { + REQUESTS_COUNTER.with_label_values(&["final"]).inc(); + } + // Increase the REQUESTS_COUNTER `optimistic` metric + // if the request has optimistic finality + near_primitives::types::Finality::None => { + REQUESTS_COUNTER.with_label_values(&["optimistic"]).inc(); + // Increase the REQUESTS_COUNTER `proxy_optimistic` metric + // if the optimistic is not updating and proxy to native JSON-RPC + if crate::metrics::OPTIMISTIC_UPDATING.is_not_working() { + REQUESTS_COUNTER + .with_label_values(&["proxy_optimistic"]) + .inc(); + } + } + } + } + near_primitives::types::BlockReference::SyncCheckpoint(_) => { + REQUESTS_COUNTER.with_label_values(&["historical"]).inc(); + } + } } /// Exposes prometheus metrics diff --git a/rpc-server/src/middlewares.rs b/rpc-server/src/middlewares.rs new file mode 100644 index 00000000..cd74ff55 --- /dev/null +++ b/rpc-server/src/middlewares.rs @@ -0,0 +1,116 @@ +use crate::metrics::{METHOD_CALLS_COUNTER, REQUESTS_COUNTER}; +use actix_web::dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform}; +use futures::future::LocalBoxFuture; +use futures::StreamExt; +use jsonrpc_v2::{Params, RequestObject}; +use near_jsonrpc::RpcRequest; +use serde_json::Value; +use std::future::{ready, Ready}; + +// Middleware to count requests and methods calls +// This middleware is used to count the number of requests and the number of calls to each method +pub struct RequestsCounters; + +impl Transform for RequestsCounters +where + S: Service, Error = actix_web::Error> + 'static, + S::Future: 'static, + B: 'static, +{ + type Response = ServiceResponse; + type Error = actix_web::Error; + type Transform = RequestsCountersMiddleware; + type InitError = (); + type Future = Ready>; + + fn new_transform(&self, service: S) -> Self::Future { + ready(Ok(RequestsCountersMiddleware { + service: std::sync::Arc::new(service), + })) + } +} + +pub struct RequestsCountersMiddleware { + service: std::sync::Arc, +} + +impl Service for RequestsCountersMiddleware +where + S: Service, Error = actix_web::Error> + 'static, + S::Future: 'static, + B: 'static, +{ + type Response = ServiceResponse; + type Error = actix_web::Error; + type Future = LocalBoxFuture<'static, Result>; + + forward_ready!(service); + + fn call(&self, request: ServiceRequest) -> Self::Future { + let service_clone = self.service.clone(); + Box::pin(async move { + if request.path() != "/" { + return service_clone.call(request).await; + } + + REQUESTS_COUNTER.with_label_values(&["total"]).inc(); + + let (req, mut payload) = request.into_parts(); + let mut body = actix_web::web::BytesMut::new(); + while let Some(chunk) = &payload.next().await { + match chunk { + Ok(chunk) => body.extend_from_slice(chunk), + Err(e) => { + tracing::error!("Error receiving payload: {:?}", e); + } + }; + } + + if let Ok(obj) = serde_json::from_slice::(&body) { + let method = obj.method_ref(); + if method == "query" { + let params = match Params::from_request_object(&obj) { + Ok(Params(params)) => params, + Err(_) => { + tracing::error!("Error parsing request params"); + Value::default() + } + }; + if let Ok(query_request) = + near_jsonrpc::primitives::types::query::RpcQueryRequest::parse(params) + { + let method = match &query_request.request { + near_primitives::views::QueryRequest::ViewAccount { .. } => { + "query_view_account" + } + near_primitives::views::QueryRequest::ViewCode { .. } => { + "query_view_code" + } + near_primitives::views::QueryRequest::ViewState { .. } => { + "query_view_state" + } + near_primitives::views::QueryRequest::ViewAccessKey { .. } => { + "query_view_access_key" + } + near_primitives::views::QueryRequest::ViewAccessKeyList { .. } => { + "query_view_access_key_list" + } + near_primitives::views::QueryRequest::CallFunction { .. } => { + "query_call_function" + } + }; + METHOD_CALLS_COUNTER.with_label_values(&[method]).inc() + } + } else { + METHOD_CALLS_COUNTER.with_label_values(&[method]).inc() + } + }; + + let mut request = ServiceRequest::from_request(req); + let (_, mut payload) = actix_http::h1::Payload::create(true); + payload.unread_data(body.into()); + request.set_payload(payload.into()); + service_clone.call(request).await + }) + } +} diff --git a/rpc-server/src/modules/blocks/methods.rs b/rpc-server/src/modules/blocks/methods.rs index 1311c8b1..afb3c6ca 100644 --- a/rpc-server/src/modules/blocks/methods.rs +++ b/rpc-server/src/modules/blocks/methods.rs @@ -23,13 +23,15 @@ pub async fn block( near_primitives::types::Finality::None, ) = &block_request.block_reference { - // Increase the OPTIMISTIC_REQUESTS_TOTAL metric - // if the request has optimistic finality - crate::metrics::OPTIMISTIC_REQUESTS_TOTAL.inc(); if crate::metrics::OPTIMISTIC_UPDATING.is_not_working() { - // Increase the PROXY_OPTIMISTIC_REQUESTS_TOTAL metric - // if optimistic not updating and proxy to near-rpc - crate::metrics::PROXY_OPTIMISTIC_REQUESTS_TOTAL.inc(); + // increase metrics before proxy request + crate::metrics::increase_request_category_metrics( + &data, + &block_request.block_reference, + None, + ) + .await; + // Proxy if the optimistic updating is not working let block_view = data.near_rpc_client.call(block_request).await?; return Ok(near_jsonrpc::primitives::types::blocks::RpcBlockResponse { block_view }); } @@ -45,22 +47,17 @@ pub async fn chunk( ) -> Result { tracing::debug!("`chunk` called with parameters: {:?}", params); let chunk_request = near_jsonrpc::primitives::types::chunks::RpcChunkRequest::parse(params)?; - crate::metrics::CHUNK_REQUESTS_TOTAL.inc(); let result = fetch_chunk(&data, chunk_request.chunk_reference.clone()).await; #[cfg(feature = "shadow_data_consistency")] { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::CHUNK_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &result, data.near_rpc_client.clone(), chunk_request, - "CHUNK", + "chunk", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "CHUNK") - }; + .await; } Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) } @@ -83,13 +80,15 @@ pub async fn changes_in_block_by_type( near_primitives::types::Finality::None, ) = &changes_in_block_request.block_reference { - // Increase the OPTIMISTIC_REQUESTS_TOTAL metric - // if the request has optimistic finality - crate::metrics::OPTIMISTIC_REQUESTS_TOTAL.inc(); if crate::metrics::OPTIMISTIC_UPDATING.is_not_working() { - // Increase the PROXY_OPTIMISTIC_REQUESTS_TOTAL metric - // if optimistic not updating and proxy to near-rpc - crate::metrics::PROXY_OPTIMISTIC_REQUESTS_TOTAL.inc(); + // increase metrics before proxy request + crate::metrics::increase_request_category_metrics( + &data, + &changes_in_block_request.block_reference, + None, + ) + .await; + // Proxy if the optimistic updating is not working return Ok(data.near_rpc_client.call(changes_in_block_request).await?); } }; @@ -114,13 +113,15 @@ pub async fn changes_in_block( near_primitives::types::Finality::None, ) = &changes_in_block_request.block_reference { - // Increase the OPTIMISTIC_REQUESTS_TOTAL metric - // if the request has optimistic finality - crate::metrics::OPTIMISTIC_REQUESTS_TOTAL.inc(); if crate::metrics::OPTIMISTIC_UPDATING.is_not_working() { - // Increase the PROXY_OPTIMISTIC_REQUESTS_TOTAL metric - // if optimistic not updating and proxy to near-rpc - crate::metrics::PROXY_OPTIMISTIC_REQUESTS_TOTAL.inc(); + // increase metrics before proxy request + crate::metrics::increase_request_category_metrics( + &data, + &changes_in_block_request.block_reference, + None, + ) + .await; + // Proxy if the optimistic updating is not working return Ok(data.near_rpc_client.call(changes_in_block_request).await?); } }; @@ -136,8 +137,19 @@ async fn block_call( mut block_request: near_jsonrpc::primitives::types::blocks::RpcBlockRequest, ) -> Result { tracing::debug!("`block` called with parameters: {:?}", block_request); - crate::metrics::BLOCK_REQUESTS_TOTAL.inc(); - let result = fetch_block(&data, block_request.block_reference.clone()).await; + let result = match fetch_block(&data, &block_request.block_reference, "block").await { + Ok(block) => { + // increase block category metrics + crate::metrics::increase_request_category_metrics( + &data, + &block_request.block_reference, + Some(block.block_view.header.height), + ) + .await; + Ok(block) + } + Err(err) => Err(err), + }; #[cfg(feature = "shadow_data_consistency")] { @@ -151,18 +163,14 @@ async fn block_call( } }; - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::BLOCK_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &result, data.near_rpc_client.clone(), block_request, - "BLOCK", + "block", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "BLOCK") - }; + .await; }; Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) @@ -176,10 +184,22 @@ async fn changes_in_block_call( mut params: near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockRequest, ) -> Result { - crate::metrics::CHNGES_IN_BLOCK_REQUESTS_TOTAL.inc(); - let cache_block = fetch_block_from_cache_or_get(&data, params.block_reference.clone()) - .await - .map_err(near_jsonrpc::primitives::errors::RpcError::from)?; + let cache_block = fetch_block_from_cache_or_get( + &data, + ¶ms.block_reference, + "EXPERIMENTAL_changes_in_block", + ) + .await + .map_err(near_jsonrpc::primitives::errors::RpcError::from)?; + + // increase block category metrics + crate::metrics::increase_request_category_metrics( + &data, + ¶ms.block_reference, + Some(cache_block.block_height), + ) + .await; + let result = fetch_changes_in_block(&data, cache_block, ¶ms.block_reference).await; #[cfg(feature = "shadow_data_consistency")] { @@ -188,18 +208,14 @@ async fn changes_in_block_call( near_primitives::types::BlockId::Height(cache_block.block_height), ) } - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::CHNGES_IN_BLOCK_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &result, data.near_rpc_client.clone(), params, - "CHANGES_IN_BLOCK", + "EXPERIMENTAL_changes_in_block", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "CHANGES_IN_BLOCK") - }; + .await; } Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) @@ -212,10 +228,19 @@ async fn changes_in_block_by_type_call( data: Data, mut params: near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockByTypeRequest, ) -> Result { - crate::metrics::CHNGES_IN_BLOCK_BY_TYPE_REQUESTS_TOTAL.inc(); - let cache_block = fetch_block_from_cache_or_get(&data, params.block_reference.clone()) - .await - .map_err(near_jsonrpc::primitives::errors::RpcError::from)?; + let cache_block = + fetch_block_from_cache_or_get(&data, ¶ms.block_reference, "EXPERIMENTAL_changes") + .await + .map_err(near_jsonrpc::primitives::errors::RpcError::from)?; + + // increase block category metrics + crate::metrics::increase_request_category_metrics( + &data, + ¶ms.block_reference, + Some(cache_block.block_height), + ) + .await; + let result = fetch_changes_in_block_by_type( &data, cache_block, @@ -231,18 +256,14 @@ async fn changes_in_block_by_type_call( near_primitives::types::BlockId::Height(cache_block.block_height), ) } - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::CHNGES_IN_BLOCK_BY_TYPE_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &result, data.near_rpc_client.clone(), params, - "CHANGES_IN_BLOCK_BY_TYPE", + "EXPERIMENTAL_changes", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "CHANGES_IN_BLOCK_BY_TYPE") - }; + .await; } Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) @@ -251,7 +272,8 @@ async fn changes_in_block_by_type_call( #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] pub async fn fetch_block( data: &Data, - block_reference: near_primitives::types::BlockReference, + block_reference: &near_primitives::types::BlockReference, + method_name: &str, ) -> Result< near_jsonrpc::primitives::types::blocks::RpcBlockResponse, near_jsonrpc::primitives::types::blocks::RpcBlockError, @@ -259,9 +281,13 @@ pub async fn fetch_block( tracing::debug!("`fetch_block` call"); let block_height = match block_reference { near_primitives::types::BlockReference::BlockId(block_id) => match block_id { - near_primitives::types::BlockId::Height(block_height) => Ok(block_height), + near_primitives::types::BlockId::Height(block_height) => Ok(*block_height), near_primitives::types::BlockId::Hash(block_hash) => { - match data.db_manager.get_block_by_hash(block_hash).await { + match data + .db_manager + .get_block_by_hash(*block_hash, method_name) + .await + { Ok(block_height) => Ok(block_height), Err(err) => { tracing::error!("Failed to fetch block by hash: {}", err); @@ -336,7 +362,7 @@ pub async fn fetch_chunk( } => match block_id { near_primitives::types::BlockId::Height(block_height) => data .db_manager - .get_block_by_height_and_shard_id(block_height, shard_id) + .get_block_by_height_and_shard_id(block_height, shard_id, "chunk") .await .map_err(|_err| { near_jsonrpc::primitives::types::chunks::RpcChunkError::InvalidShardId { @@ -347,7 +373,7 @@ pub async fn fetch_chunk( near_primitives::types::BlockId::Hash(block_hash) => { let block_height = data .db_manager - .get_block_by_hash(block_hash) + .get_block_by_hash(block_hash, "chunk") .await .map_err(|err| { tracing::error!("Failed to fetch block by hash: {}", err); @@ -360,7 +386,7 @@ pub async fn fetch_chunk( }, near_jsonrpc::primitives::types::chunks::ChunkReference::ChunkHash { chunk_id } => data .db_manager - .get_block_by_chunk_hash(chunk_id) + .get_block_by_chunk_hash(chunk_id, "chunk") .await .map_err( |_err| near_jsonrpc::primitives::types::chunks::RpcChunkError::UnknownChunk { diff --git a/rpc-server/src/modules/blocks/utils.rs b/rpc-server/src/modules/blocks/utils.rs index ae5181a9..b4ec01e0 100644 --- a/rpc-server/src/modules/blocks/utils.rs +++ b/rpc-server/src/modules/blocks/utils.rs @@ -78,15 +78,16 @@ pub async fn fetch_chunk_from_s3( #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] pub async fn fetch_block_from_cache_or_get( data: &jsonrpc_v2::Data, - block_reference: near_primitives::types::BlockReference, + block_reference: &near_primitives::types::BlockReference, + method_name: &str, ) -> Result { - let block = match block_reference.clone() { + let block = match block_reference { near_primitives::types::BlockReference::BlockId(block_id) => { let block_height = match block_id { - near_primitives::types::BlockId::Height(block_height) => block_height, + near_primitives::types::BlockId::Height(block_height) => *block_height, near_primitives::types::BlockId::Hash(hash) => data .db_manager - .get_block_by_hash(hash) + .get_block_by_hash(*hash, method_name) .await .map_err(|err| { near_jsonrpc::primitives::types::blocks::RpcBlockError::UnknownBlock { @@ -124,7 +125,7 @@ pub async fn fetch_block_from_cache_or_get( match block { Some(block) => Ok(block), None => { - let block_from_s3 = fetch_block(data, block_reference).await?; + let block_from_s3 = fetch_block(data, block_reference, method_name).await?; let block = CacheBlock::from(&block_from_s3.block_view); data.blocks_cache.put(block.block_height, block).await; diff --git a/rpc-server/src/modules/clients/methods.rs b/rpc-server/src/modules/clients/methods.rs index cce82ca1..1bb51949 100644 --- a/rpc-server/src/modules/clients/methods.rs +++ b/rpc-server/src/modules/clients/methods.rs @@ -14,7 +14,9 @@ pub async fn light_client_proof( near_jsonrpc::primitives::types::light_client::RpcLightClientExecutionProofRequest::parse( params, )?; - crate::metrics::ARCHIVAL_PROXY_LIGHT_CLIENT_PROOF.inc(); + crate::metrics::REQUESTS_COUNTER + .with_label_values(&["archive_proxy_light_client_proof"]) + .inc(); Ok(data.near_rpc_client.archival_call(request).await?) } @@ -27,8 +29,7 @@ pub async fn next_light_client_block( near_jsonrpc::primitives::types::light_client::RpcLightClientNextBlockRequest::parse( params, )?; - crate::metrics::ARCHIVAL_PROXY_NEXT_LIGHT_CLIENT_BLOCK.inc(); - match data.near_rpc_client.archival_call(request).await? { + match data.near_rpc_client.call(request).await? { Some(light_client_block) => Ok( near_jsonrpc::primitives::types::light_client::RpcLightClientNextBlockResponse { light_client_block: Some(std::sync::Arc::new(light_client_block)), diff --git a/rpc-server/src/modules/gas/methods.rs b/rpc-server/src/modules/gas/methods.rs index 26cb642e..a2799cf4 100644 --- a/rpc-server/src/modules/gas/methods.rs +++ b/rpc-server/src/modules/gas/methods.rs @@ -17,7 +17,6 @@ pub async fn gas_price( "`gas_price` called with parameters: {:?}", gas_price_request ); - crate::metrics::GAS_PRICE_REQUESTS_TOTAL.inc(); let block_reference = match gas_price_request.block_id.clone() { Some(block_id) => near_primitives::types::BlockReference::BlockId(block_id), None => near_primitives::types::BlockReference::Finality( @@ -41,18 +40,14 @@ pub async fn gas_price( Err(err) => Err(err), }; - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::GAS_PRICE_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &result, data.near_rpc_client.clone(), gas_price_request, - "GAS_PRICE", + "gas_price", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "GAS_PRICE") - }; + .await; }; let gas_price_view = near_primitives::views::GasPriceView { gas_price: cache_block @@ -67,7 +62,7 @@ async fn gas_price_call( data: &Data, block_reference: near_primitives::types::BlockReference, ) -> Result { - let block = fetch_block_from_cache_or_get(data, block_reference) + let block = fetch_block_from_cache_or_get(data, &block_reference, "gas_price") .await .map_err(|err| { near_jsonrpc::primitives::types::gas_price::RpcGasPriceError::UnknownBlock { diff --git a/rpc-server/src/modules/network/methods.rs b/rpc-server/src/modules/network/methods.rs index 0cc8cf81..89c63ede 100644 --- a/rpc-server/src/modules/network/methods.rs +++ b/rpc-server/src/modules/network/methods.rs @@ -99,7 +99,6 @@ pub async fn validators( ) -> Result { let request = near_jsonrpc::primitives::types::validator::RpcValidatorRequest::parse(params)?; tracing::debug!("`validators` called with parameters: {:?}", request); - crate::metrics::VALIDATORS_REQUESTS_TOTAL.inc(); // Latest epoch validators fetches from the Near RPC node if let near_primitives::types::EpochReference::Latest = &request.epoch_reference { let validator_info = data.near_rpc_client.call(request).await?; @@ -128,18 +127,14 @@ pub async fn validators( #[cfg(feature = "shadow_data_consistency")] { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::VALIDATORS_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &validator_info, data.near_rpc_client.clone(), request, - "VALIDATORS", + "validators", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "VALIDATORS") - }; + .await; } Ok( @@ -159,7 +154,13 @@ pub async fn validators_ordered( if let Some(block_id) = &request.block_id { let block_reference = near_primitives::types::BlockReference::from(block_id.clone()); - if let Ok(block) = fetch_block_from_cache_or_get(&data, block_reference).await { + if let Ok(block) = fetch_block_from_cache_or_get( + &data, + &block_reference, + "EXPERIMENTAL_validators_ordered", + ) + .await + { let final_block = data.blocks_info_by_finality.final_cache_block().await; // `expected_earliest_available_block` calculated by formula: // `final_block_height` - `node_epoch_count` * `epoch_length` @@ -199,25 +200,20 @@ pub async fn protocol_config( ); let protocol_config_request = near_jsonrpc::primitives::types::config::RpcProtocolConfigRequest::parse(params)?; - crate::metrics::PROTOCOL_CONFIG_REQUESTS_TOTAL.inc(); let config_view = protocol_config_call(&data, protocol_config_request.block_reference.clone()).await; #[cfg(feature = "shadow_data_consistency")] { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::PROTOCOL_CONFIG_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &config_view, data.near_rpc_client.clone(), protocol_config_request, - "PROTOCOL_CONFIG", + "EXPERIMENTAL_protocol_config", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "PROTOCOL_CONFIG") - }; + .await; } Ok( @@ -237,20 +233,20 @@ async fn validators_call( let validators = match &validator_request.epoch_reference { near_primitives::types::EpochReference::EpochId(epoch_id) => data .db_manager - .get_validators_by_epoch_id(epoch_id.0) + .get_validators_by_epoch_id(epoch_id.0, "validators") .await .map_err(|_err| { near_jsonrpc::primitives::types::validator::RpcValidatorError::UnknownEpoch })?, near_primitives::types::EpochReference::BlockId(block_id) => { let block_reference = near_primitives::types::BlockReference::BlockId(block_id.clone()); - let block = fetch_block_from_cache_or_get(data, block_reference) + let block = fetch_block_from_cache_or_get(data, &block_reference, "validators") .await .map_err(|_err| { near_jsonrpc::primitives::types::validator::RpcValidatorError::UnknownEpoch })?; data.db_manager - .get_validators_by_end_block_height(block.block_height) + .get_validators_by_end_block_height(block.block_height, "validators") .await.map_err(|_err| { near_jsonrpc::primitives::types::validator::RpcValidatorError::ValidatorInfoUnavailable })? @@ -269,13 +265,14 @@ async fn protocol_config_call( near_chain_configs::ProtocolConfigView, near_jsonrpc::primitives::types::config::RpcProtocolConfigError, > { - let block = fetch_block_from_cache_or_get(data, block_reference) - .await - .map_err(|err| { - near_jsonrpc::primitives::types::config::RpcProtocolConfigError::UnknownBlock { - error_message: err.to_string(), - } - })?; + let block = + fetch_block_from_cache_or_get(data, &block_reference, "EXPERIMENTAL_protocol_config") + .await + .map_err(|err| { + near_jsonrpc::primitives::types::config::RpcProtocolConfigError::UnknownBlock { + error_message: err.to_string(), + } + })?; let protocol_config = if data .blocks_info_by_finality @@ -333,7 +330,7 @@ async fn protocol_config_call( protocol_config.into() } else { data.db_manager - .get_protocol_config_by_epoch_id(block.epoch_id) + .get_protocol_config_by_epoch_id(block.epoch_id, "EXPERIMENTAL_protocol_config") .await .map_err(|err| { near_jsonrpc::primitives::types::config::RpcProtocolConfigError::InternalError { diff --git a/rpc-server/src/modules/queries/contract_runner/code_storage.rs b/rpc-server/src/modules/queries/contract_runner/code_storage.rs new file mode 100644 index 00000000..ecd86267 --- /dev/null +++ b/rpc-server/src/modules/queries/contract_runner/code_storage.rs @@ -0,0 +1,295 @@ +use std::collections::HashMap; + +use crate::modules::queries::utils::get_state_key_value_from_db; +use database::ReaderDbManager; +use futures::executor::block_on; + +pub type Result = ::std::result::Result; + +pub struct CodeStorage { + db_manager: std::sync::Arc>, + account_id: near_primitives::types::AccountId, + block_height: near_primitives::types::BlockHeight, + validators: HashMap, + data_count: u64, + is_optimistic: bool, + optimistic_data: + HashMap>, +} + +pub struct StorageValuePtr { + value: Vec, +} + +impl near_vm_runner::logic::ValuePtr for StorageValuePtr { + fn len(&self) -> u32 { + self.value.len() as u32 + } + + fn deref(&self) -> Result> { + Ok(self.value.clone()) + } +} + +impl CodeStorage { + pub fn init( + db_manager: std::sync::Arc>, + account_id: near_primitives::types::AccountId, + block_height: near_primitives::types::BlockHeight, + validators: HashMap, + optimistic_data: HashMap< + readnode_primitives::StateKey, + Option, + >, + ) -> Self { + Self { + db_manager, + account_id, + block_height, + validators, + data_count: Default::default(), // TODO: Using for generate_data_id + is_optimistic: !optimistic_data.is_empty(), + optimistic_data, + } + } + + fn get_state_key_data(&self, key: &[u8]) -> readnode_primitives::StateValue { + let get_db_data = get_state_key_value_from_db( + &self.db_manager, + &self.account_id, + self.block_height, + key.to_vec(), + "query_call_function", + ); + let (_, data) = block_on(get_db_data); + data + } + + fn optimistic_storage_get( + &self, + key: &[u8], + ) -> Result>> { + if let Some(value) = self.optimistic_data.get(key) { + Ok(value.as_ref().map(|data| { + Box::new(StorageValuePtr { + value: data.clone(), + }) as Box<_> + })) + } else { + self.database_storage_get(key) + } + } + + fn database_storage_get( + &self, + key: &[u8], + ) -> Result>> { + let data = self.get_state_key_data(key); + Ok(if !data.is_empty() { + Some(Box::new(StorageValuePtr { value: data }) as Box<_>) + } else { + None + }) + } + + fn optimistic_storage_has_key(&mut self, key: &[u8]) -> Result { + if let Some(value) = self.optimistic_data.get(key) { + Ok(value.is_some()) + } else { + self.database_storage_has_key(key) + } + } + + fn database_storage_has_key(&mut self, key: &[u8]) -> Result { + Ok(!self.get_state_key_data(key).is_empty()) + } +} + +impl near_vm_runner::logic::External for CodeStorage { + #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] + fn storage_set(&mut self, _key: &[u8], _value: &[u8]) -> Result<()> { + Err(near_vm_runner::logic::VMLogicError::HostError( + near_vm_runner::logic::HostError::ProhibitedInView { + method_name: String::from("storage_set"), + }, + )) + } + + #[cfg_attr( + feature = "tracing-instrumentation", + tracing::instrument(skip(self, _mode)) + )] + fn storage_get( + &self, + key: &[u8], + _mode: near_vm_runner::logic::StorageGetMode, + ) -> Result>> { + if self.is_optimistic { + self.optimistic_storage_get(key) + } else { + self.database_storage_get(key) + } + } + + #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] + fn storage_remove(&mut self, _key: &[u8]) -> Result<()> { + Err(near_vm_runner::logic::VMLogicError::HostError( + near_vm_runner::logic::HostError::ProhibitedInView { + method_name: String::from("storage_remove"), + }, + )) + } + + #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] + fn storage_remove_subtree(&mut self, _prefix: &[u8]) -> Result<()> { + Err(near_vm_runner::logic::VMLogicError::HostError( + near_vm_runner::logic::HostError::ProhibitedInView { + method_name: String::from("storage_remove_subtree"), + }, + )) + } + + #[cfg_attr( + feature = "tracing-instrumentation", + tracing::instrument(skip(self, _mode)) + )] + fn storage_has_key( + &mut self, + key: &[u8], + _mode: near_vm_runner::logic::StorageGetMode, + ) -> Result { + if self.is_optimistic { + self.optimistic_storage_has_key(key) + } else { + self.database_storage_has_key(key) + } + } + + #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] + fn generate_data_id(&mut self) -> near_primitives::hash::CryptoHash { + // TODO: Should be improvement in future + // Generates some hash for the data ID to receive data. + // This hash should not be functionality + let data_id = near_primitives::hash::hash(&self.data_count.to_le_bytes()); + self.data_count += 1; + data_id + } + + #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] + fn get_trie_nodes_count(&self) -> near_vm_runner::logic::TrieNodesCount { + near_vm_runner::logic::TrieNodesCount { + db_reads: 0, + mem_reads: 0, + } + } + + #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] + fn validator_stake( + &self, + account_id: &near_primitives::types::AccountId, + ) -> Result> { + Ok(self.validators.get(account_id).cloned()) + } + + #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] + fn validator_total_stake(&self) -> Result { + Ok(self.validators.values().sum()) + } + + fn create_receipt( + &mut self, + _receipt_indices: Vec, + _receiver_id: near_primitives::types::AccountId, + ) -> Result { + Err(near_vm_runner::logic::VMLogicError::HostError( + near_vm_runner::logic::HostError::ProhibitedInView { + method_name: String::from("create_receipt"), + }, + )) + } + + fn append_action_create_account( + &mut self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + ) -> Result<()> { + Ok(()) + } + + fn append_action_deploy_contract( + &mut self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + _code: Vec, + ) -> Result<()> { + Ok(()) + } + + fn append_action_function_call_weight( + &mut self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + _method_name: Vec, + _args: Vec, + _attached_deposit: near_primitives::types::Balance, + _prepaid_gas: near_primitives::types::Gas, + _gas_weight: near_primitives::types::GasWeight, + ) -> Result<()> { + Ok(()) + } + + fn append_action_transfer( + &mut self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + _deposit: near_primitives::types::Balance, + ) -> Result<()> { + Ok(()) + } + + fn append_action_stake( + &mut self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + _stake: near_primitives::types::Balance, + _public_key: near_crypto::PublicKey, + ) { + } + + fn append_action_add_key_with_full_access( + &mut self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + _public_key: near_crypto::PublicKey, + _nonce: near_primitives::types::Nonce, + ) { + } + + fn append_action_add_key_with_function_call( + &mut self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + _public_key: near_crypto::PublicKey, + _nonce: near_primitives::types::Nonce, + _allowance: Option, + _receiver_id: near_primitives::types::AccountId, + _method_names: Vec>, + ) -> Result<()> { + Ok(()) + } + + fn append_action_delete_key( + &mut self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + _public_key: near_crypto::PublicKey, + ) { + } + + fn append_action_delete_account( + &mut self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + _beneficiary_id: near_primitives::types::AccountId, + ) -> Result<()> { + Ok(()) + } + + fn get_receipt_receiver( + &self, + _receipt_index: near_vm_runner::logic::types::ReceiptIndex, + ) -> &near_primitives::types::AccountId { + panic!("Prohibited in view. `get_receipt_receiver`"); + } +} diff --git a/rpc-server/src/modules/queries/contract_runner/mod.rs b/rpc-server/src/modules/queries/contract_runner/mod.rs new file mode 100644 index 00000000..72e1178b --- /dev/null +++ b/rpc-server/src/modules/queries/contract_runner/mod.rs @@ -0,0 +1,242 @@ +use std::collections::HashMap; + +use near_vm_runner::internal::VMKindExt; +use near_vm_runner::ContractRuntimeCache; + +use crate::errors::FunctionCallError; +use crate::modules::blocks::BlocksInfoByFinality; + +use code_storage::CodeStorage; + +mod code_storage; + +pub struct RunContractResponse { + pub result: Vec, + pub logs: Vec, + pub block_height: near_primitives::types::BlockHeight, + pub block_hash: near_primitives::hash::CryptoHash, +} + +#[allow(clippy::too_many_arguments)] +#[cfg_attr( + feature = "tracing-instrumentation", + tracing::instrument(skip(db_manager, compiled_contract_code_cache, contract_code_cache)) +)] +pub async fn run_contract( + account_id: &near_primitives::types::AccountId, + method_name: &str, + args: &near_primitives::types::FunctionArgs, + db_manager: &std::sync::Arc>, + compiled_contract_code_cache: &std::sync::Arc, + contract_code_cache: &std::sync::Arc< + crate::cache::RwLockLruMemoryCache>, + >, + blocks_info_by_finality: &std::sync::Arc, + block: crate::modules::blocks::CacheBlock, + max_gas_burnt: near_primitives::types::Gas, + optimistic_data: HashMap< + readnode_primitives::StateKey, + Option, + >, +) -> Result { + let contract = db_manager + .get_account(account_id, block.block_height, "query_call_function") + .await + .map_err(|_| FunctionCallError::AccountDoesNotExist { + requested_account_id: account_id.clone(), + })?; + + let (epoch_height, validators) = + epoch_height_and_validators_with_balances(db_manager, blocks_info_by_finality, block) + .await?; + + // Prepare context for the VM run contract + let public_key = near_crypto::PublicKey::empty(near_crypto::KeyType::ED25519); + let random_seed = near_primitives::utils::create_random_seed( + block.latest_protocol_version, + near_primitives::hash::CryptoHash::default(), + block.state_root, + ); + let context = near_vm_runner::logic::VMContext { + current_account_id: account_id.clone(), + signer_account_id: account_id.clone(), + signer_account_pk: borsh::to_vec(&public_key).expect("Failed to serialize"), + predecessor_account_id: account_id.clone(), + input: args.to_vec(), + block_height: block.block_height, + block_timestamp: block.block_timestamp, + epoch_height, + account_balance: contract.data.amount(), + account_locked_balance: contract.data.locked(), + storage_usage: contract.data.storage_usage(), + attached_deposit: 0, + prepaid_gas: max_gas_burnt, + random_seed, + view_config: Some(near_primitives::config::ViewConfig { max_gas_burnt }), + output_data_receivers: vec![], + }; + + // Init runtime config for each protocol version + let store = near_parameters::RuntimeConfigStore::free(); + let config = store + .get_config(block.latest_protocol_version) + .wasm_config + .clone(); + let vm_config = near_parameters::vm::Config { + vm_kind: config.vm_kind.replace_with_wasmtime_if_unsupported(), + ..config + }; + let code_hash = contract.data.code_hash(); + + // Check if the contract code is already in the cache + let key = near_vm_runner::get_contract_cache_key(code_hash, &vm_config); + let contract_code = if compiled_contract_code_cache.has(&key).unwrap_or(false) { + None + } else { + Some(match contract_code_cache.get(&code_hash).await { + Some(code) => near_vm_runner::ContractCode::new(code, Some(code_hash)), + None => { + let code = db_manager + .get_contract_code(account_id, block.block_height, "query_call_function") + .await + .map_err(|_| FunctionCallError::InvalidAccountId { + requested_account_id: account_id.clone(), + })?; + contract_code_cache + .put(contract.data.code_hash(), code.data.clone()) + .await; + near_vm_runner::ContractCode::new(code.data, Some(contract.data.code_hash())) + } + }) + }; + + // Init an external scylla interface for the Runtime logic + let code_storage = CodeStorage::init( + db_manager.clone(), + account_id.clone(), + block.block_height, + validators, + optimistic_data, + ); + + // Execute the contract in the near VM + let result = run_code_in_vm_runner( + code_hash, + contract_code, + method_name.to_string(), + context, + code_storage, + vm_config, + compiled_contract_code_cache, + ) + .await + .map_err(|e| FunctionCallError::InternalError { + error_message: e.to_string(), + })?; + + if let Some(err) = result.aborted { + let message = format!("wasm execution failed with error: {:?}", err); + Err(FunctionCallError::VMError { + error_message: message, + }) + } else { + let logs = result.logs; + let result = match result.return_data { + near_vm_runner::logic::ReturnData::Value(buf) => buf, + near_vm_runner::logic::ReturnData::ReceiptIndex(_) + | near_vm_runner::logic::ReturnData::None => vec![], + }; + Ok(RunContractResponse { + result, + logs, + block_height: block.block_height, + block_hash: block.block_hash, + }) + } +} + +async fn epoch_height_and_validators_with_balances( + db_manager: &std::sync::Arc>, + blocks_info_by_finality: &std::sync::Arc, + block: crate::modules::blocks::CacheBlock, +) -> Result<(u64, HashMap), FunctionCallError> { + let (epoch_height, epoch_validators) = + if blocks_info_by_finality.final_cache_block().await.epoch_id == block.epoch_id { + let validators = blocks_info_by_finality.validators().await; + (validators.epoch_height, validators.current_validators) + } else { + let validators = db_manager + .get_validators_by_epoch_id(block.epoch_id, "query_call_function") + .await + .map_err(|_| FunctionCallError::InternalError { + error_message: "Failed to get epoch info".to_string(), + })?; + ( + validators.epoch_height, + validators.validators_info.current_validators, + ) + }; + Ok(( + epoch_height, + epoch_validators + .iter() + .map(|validator| (validator.account_id.clone(), validator.stake)) + .collect(), + )) +} + +#[allow(clippy::too_many_arguments)] +#[cfg_attr( + feature = "tracing-instrumentation", + tracing::instrument(skip(context, code_storage, contract_code, compiled_contract_code_cache)) +)] +async fn run_code_in_vm_runner( + code_hash: near_primitives::hash::CryptoHash, + contract_code: Option, + method_name: String, + context: near_vm_runner::logic::VMContext, + mut code_storage: CodeStorage, + vm_config: near_parameters::vm::Config, + compiled_contract_code_cache: &std::sync::Arc, +) -> Result { + let compiled_contract_code_cache_handle = compiled_contract_code_cache.handle(); + let span = tracing::debug_span!("run_code_in_vm_runner"); + + let results = tokio::task::spawn_blocking(move || { + let _entered = span.entered(); + let promise_results = vec![]; + let fees = near_parameters::RuntimeFeesConfig::free(); + + let runtime = vm_config + .vm_kind + .runtime(vm_config.clone()) + .expect("runtime has not been enabled at compile time"); + + if let Some(code) = &contract_code { + runtime + .precompile(code, &compiled_contract_code_cache_handle) + .expect("Compilation failed") + .expect("Cache failed"); + }; + + runtime.run( + code_hash, + None, + &method_name, + &mut code_storage, + &context, + &fees, + &promise_results, + Some(&compiled_contract_code_cache_handle), + ) + }) + .await; + match results { + Ok(result) => result, + Err(err) => Err( + near_vm_runner::logic::errors::VMRunnerError::WasmUnknownError { + debug_message: format!("Failed to run contract: {:?}", err), + }, + ), + } +} diff --git a/rpc-server/src/modules/queries/methods.rs b/rpc-server/src/modules/queries/methods.rs index 8f380e7e..820a0de5 100644 --- a/rpc-server/src/modules/queries/methods.rs +++ b/rpc-server/src/modules/queries/methods.rs @@ -2,12 +2,14 @@ use crate::config::ServerContext; use crate::errors::RPCError; use crate::modules::blocks::utils::fetch_block_from_cache_or_get; use crate::modules::blocks::CacheBlock; -#[cfg(feature = "account_access_keys")] -use crate::modules::queries::utils::fetch_list_access_keys_from_db; -use crate::modules::queries::utils::{get_state_keys_from_db, run_contract, RunContractResponse}; use jsonrpc_v2::{Data, Params}; use near_jsonrpc::RpcRequest; +use super::contract_runner; +#[cfg(feature = "account_access_keys")] +use super::utils::fetch_list_access_keys_from_db; +use super::utils::get_state_from_db; + /// `query` rpc method implementation /// calls proxy_rpc_call to get `query` from near-rpc if request parameters not supported by read-rpc /// as example: BlockReference for Finality::None is not supported by read-rpc when near_state_indexer is not running @@ -23,13 +25,15 @@ pub async fn query( near_primitives::types::Finality::None, ) = &query_request.block_reference { - // Increase the OPTIMISTIC_REQUESTS_TOTAL metric - // if the request has optimistic finality - crate::metrics::OPTIMISTIC_REQUESTS_TOTAL.inc(); return if crate::metrics::OPTIMISTIC_UPDATING.is_not_working() { - // Increase the PROXY_OPTIMISTIC_REQUESTS_TOTAL metric - // if optimistic not updating and proxy to near-rpc - crate::metrics::PROXY_OPTIMISTIC_REQUESTS_TOTAL.inc(); + // increase metrics before proxy request + crate::metrics::increase_request_category_metrics( + &data, + &query_request.block_reference, + None, + ) + .await; + // Proxy if the optimistic updating is not working Ok(data.near_rpc_client.call(query_request).await?) } else { // query_call with optimistic block @@ -50,31 +54,33 @@ async fn query_call( ) -> Result { tracing::debug!("`query` call. Params: {:?}", query_request,); - let block = fetch_block_from_cache_or_get(data, query_request.block_reference.clone()) + let block = fetch_block_from_cache_or_get(data, &query_request.block_reference, "query") .await .map_err(near_jsonrpc::primitives::errors::RpcError::from)?; + + // increase block category metrics + crate::metrics::increase_request_category_metrics( + data, + &query_request.block_reference, + Some(block.block_height), + ) + .await; let result = match &query_request.request { near_primitives::views::QueryRequest::ViewAccount { account_id } => { - crate::metrics::QUERY_VIEW_ACCOUNT_REQUESTS_TOTAL.inc(); view_account(data, block, account_id, is_optimistic).await } near_primitives::views::QueryRequest::ViewCode { account_id } => { - crate::metrics::QUERY_VIEW_CODE_REQUESTS_TOTAL.inc(); view_code(data, block, account_id, is_optimistic).await } near_primitives::views::QueryRequest::ViewAccessKey { account_id, public_key, - } => { - crate::metrics::QUERY_VIEW_ACCESS_KEY_REQUESTS_TOTAL.inc(); - view_access_key(data, block, account_id, public_key, is_optimistic).await - } + } => view_access_key(data, block, account_id, public_key, is_optimistic).await, near_primitives::views::QueryRequest::ViewState { account_id, prefix, include_proof, } => { - crate::metrics::QUERY_VIEW_STATE_REQUESTS_TOTAL.inc(); if *include_proof { // TODO: We can calculate the proof for state only on regular or archival nodes. let final_block = data.blocks_info_by_finality.final_cache_block().await; @@ -89,7 +95,9 @@ async fn query_call( Ok(data.near_rpc_client.call(query_request).await?) } else { // Increase the QUERY_VIEW_STATE_INCLUDE_PROOFS metric if we proxy to archival rpc - crate::metrics::ARCHIVAL_PROXY_QUERY_VIEW_STATE_WITH_INCLUDE_PROOFS.inc(); + crate::metrics::REQUESTS_COUNTER + .with_label_values(&["archive_proxy_view_state_proofs"]) + .inc(); // Proxy to archival rpc if the block garbage collected Ok(data.near_rpc_client.archival_call(query_request).await?) }; @@ -102,13 +110,30 @@ async fn query_call( method_name, args, } => { - crate::metrics::QUERY_FUNCTION_CALL_REQUESTS_TOTAL.inc(); - function_call(data, block, account_id, method_name, args, is_optimistic).await + // TODO: Temporary solution to proxy for poolv1.near + // It should be removed after migration to the postgres db + if account_id.to_string().ends_with("poolv1.near") { + let final_block = data.blocks_info_by_finality.final_cache_block().await; + // `expected_earliest_available_block` calculated by formula: + // `final_block_height` - `node_epoch_count` * `epoch_length` + // Now near store 5 epochs, it can be changed in the future + // epoch_length = 43200 blocks + let expected_earliest_available_block = + final_block.block_height - 5 * data.genesis_info.genesis_config.epoch_length; + return if block.block_height > expected_earliest_available_block { + // Proxy to regular rpc if the block is available + Ok(data.near_rpc_client.call(query_request).await?) + } else { + // Proxy to archival rpc if the block garbage collected + Ok(data.near_rpc_client.archival_call(query_request).await?) + }; + } else { + function_call(data, block, account_id, method_name, args, is_optimistic).await + } } #[allow(unused_variables)] // `account_id` is used in the `#[cfg(feature = "account_access_keys")]` branch. near_primitives::views::QueryRequest::ViewAccessKeyList { account_id } => { - crate::metrics::QUERY_VIEW_ACCESS_KEYS_LIST_REQUESTS_TOTAL.inc(); #[cfg(not(feature = "account_access_keys"))] { let final_block = data.blocks_info_by_finality.final_cache_block().await; @@ -135,7 +160,7 @@ async fn query_call( #[cfg(feature = "shadow_data_consistency")] { - let request_copy = query_request.request.clone(); + // let request_copy = query_request.request.clone(); // Since we do queries with the clause WHERE block_height <= X, we need to // make sure that the block we are doing a shadow data consistency check for @@ -156,98 +181,24 @@ async fn query_call( // are not proxying the requests anymore and respond with the error to the client. // Since we already have the dashboard using these metric names, we don't want to // change them and reuse them for the observability of the shadow data consistency checks. - match request_copy { - near_primitives::views::QueryRequest::ViewAccount { .. } => { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::QUERY_VIEW_ACCOUNT_REQUESTS_TOTAL.get(), - data.shadow_data_consistency_rate, - &result, - data.near_rpc_client.clone(), - query_request, - "QUERY_VIEW_ACCOUNT", - ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "QUERY_VIEW_ACCOUNT") - }; - } - near_primitives::views::QueryRequest::ViewCode { .. } => { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::QUERY_VIEW_CODE_REQUESTS_TOTAL.get(), - data.shadow_data_consistency_rate, - &result, - data.near_rpc_client.clone(), - query_request, - "QUERY_VIEW_CODE", - ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "QUERY_VIEW_CODE") - }; - } - near_primitives::views::QueryRequest::ViewAccessKey { .. } => { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::QUERY_VIEW_ACCESS_KEY_REQUESTS_TOTAL.get(), - data.shadow_data_consistency_rate, - &result, - data.near_rpc_client.clone(), - query_request, - "QUERY_VIEW_ACCESS_KEY", - ) - .await - { - crate::utils::capture_shadow_consistency_error!( - err_code, - "QUERY_VIEW_ACCESS_KEY" - ) - }; - } - near_primitives::views::QueryRequest::ViewState { .. } => { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::QUERY_VIEW_STATE_REQUESTS_TOTAL.get(), - data.shadow_data_consistency_rate, - &result, - data.near_rpc_client.clone(), - query_request, - "QUERY_VIEW_STATE", - ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "QUERY_VIEW_STATE") - }; - } - near_primitives::views::QueryRequest::CallFunction { .. } => { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::QUERY_FUNCTION_CALL_REQUESTS_TOTAL.get(), - data.shadow_data_consistency_rate, - &result, - data.near_rpc_client.clone(), - query_request, - "QUERY_FUNCTION_CALL", - ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "QUERY_FUNCTION_CALL") - }; - } + let method_name = match &query_request.request { + near_primitives::views::QueryRequest::ViewAccount { .. } => "query_view_account", + near_primitives::views::QueryRequest::ViewCode { .. } => "query_view_code", + near_primitives::views::QueryRequest::ViewAccessKey { .. } => "query_view_access_key", + near_primitives::views::QueryRequest::ViewState { .. } => "query_view_state", + near_primitives::views::QueryRequest::CallFunction { .. } => "query_call_function", near_primitives::views::QueryRequest::ViewAccessKeyList { .. } => { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::QUERY_VIEW_ACCESS_KEYS_LIST_REQUESTS_TOTAL.get(), - data.shadow_data_consistency_rate, - &result, - data.near_rpc_client.clone(), - query_request, - "QUERY_VIEW_ACCESS_KEY_LIST", - ) - .await - { - crate::utils::capture_shadow_consistency_error!( - err_code, - "QUERY_VIEW_ACCESS_KEY_LIST" - ) - }; + "query_view_access_key_list" } }; + crate::utils::shadow_compare_results_handler( + data.shadow_data_consistency_rate, + &result, + data.near_rpc_client.clone(), + query_request, + method_name, + ) + .await; } Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) @@ -270,9 +221,9 @@ async fn view_account( is_optimistic ); let account_view = if is_optimistic { - optimistic_view_account(data, block, account_id).await? + optimistic_view_account(data, block, account_id, "query_view_account").await? } else { - database_view_account(data, block, account_id).await? + database_view_account(data, block, account_id, "query_view_account").await? }; Ok(near_jsonrpc::primitives::types::query::RpcQueryResponse { kind: near_jsonrpc::primitives::types::query::QueryResponseKind::ViewAccount(account_view), @@ -286,6 +237,7 @@ async fn optimistic_view_account( data: &Data, block: CacheBlock, account_id: &near_primitives::types::AccountId, + method_name: &str, ) -> Result< near_primitives::views::AccountView, near_jsonrpc::primitives::types::query::RpcQueryError, @@ -307,7 +259,7 @@ async fn optimistic_view_account( ) } } else { - database_view_account(data, block, account_id).await + database_view_account(data, block, account_id, method_name).await } } @@ -316,13 +268,14 @@ async fn database_view_account( data: &Data, block: CacheBlock, account_id: &near_primitives::types::AccountId, + method_name: &str, ) -> Result< near_primitives::views::AccountView, near_jsonrpc::primitives::types::query::RpcQueryError, > { let account = data .db_manager - .get_account(account_id, block.block_height) + .get_account(account_id, block.block_height, method_name) .await .map_err( |_err| near_jsonrpc::primitives::types::query::RpcQueryError::UnknownAccount { @@ -353,13 +306,13 @@ async fn view_code( ); let (code, account) = if is_optimistic { tokio::try_join!( - optimistic_view_code(data, block, account_id), - optimistic_view_account(data, block, account_id), + optimistic_view_code(data, block, account_id, "query_view_code"), + optimistic_view_account(data, block, account_id, "query_view_code"), )? } else { tokio::try_join!( - database_view_code(data, block, account_id), - database_view_account(data, block, account_id), + database_view_code(data, block, account_id, "query_view_code"), + database_view_account(data, block, account_id, "query_view_code"), )? }; @@ -380,6 +333,7 @@ async fn optimistic_view_code( data: &Data, block: CacheBlock, account_id: &near_primitives::types::AccountId, + method_name: &str, ) -> Result, near_jsonrpc::primitives::types::query::RpcQueryError> { let contract_code = if let Ok(result) = data .blocks_info_by_finality @@ -398,7 +352,7 @@ async fn optimistic_view_code( ); } } else { - database_view_code(data, block, account_id).await? + database_view_code(data, block, account_id, method_name).await? }; Ok(contract_code) } @@ -408,10 +362,11 @@ async fn database_view_code( data: &Data, block: CacheBlock, account_id: &near_primitives::types::AccountId, + method_name: &str, ) -> Result, near_jsonrpc::primitives::types::query::RpcQueryError> { Ok(data .db_manager - .get_contract_code(account_id, block.block_height) + .get_contract_code(account_id, block.block_height, method_name) .await .map_err( |_err| near_jsonrpc::primitives::types::query::RpcQueryError::NoContractCode { @@ -444,38 +399,17 @@ async fn function_call( is_optimistic, ); - let call_results = if is_optimistic { - optimistic_function_call(data, block, account_id, method_name, args).await + // Depending on the optimistic flag we need to run the contract with the optimistic + // state changes or not. + let maybe_optimistic_data = if is_optimistic { + data.blocks_info_by_finality + .optimistic_state_changes_in_block(account_id, &[]) + .await } else { - database_function_call(data, block, account_id, method_name, args).await + Default::default() }; - let call_results = - call_results.map_err(|err| err.to_rpc_query_error(block.block_height, block.block_hash))?; - Ok(near_jsonrpc::primitives::types::query::RpcQueryResponse { - kind: near_jsonrpc::primitives::types::query::QueryResponseKind::CallResult( - near_primitives::views::CallResult { - result: call_results.result, - logs: call_results.logs, - }, - ), - block_height: block.block_height, - block_hash: block.block_hash, - }) -} -#[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] -async fn optimistic_function_call( - data: &Data, - block: CacheBlock, - account_id: &near_primitives::types::AccountId, - method_name: &str, - args: &near_primitives::types::FunctionArgs, -) -> Result { - let optimistic_data = data - .blocks_info_by_finality - .optimistic_state_changes_in_block(account_id, &[]) - .await; - run_contract( + let call_results = contract_runner::run_contract( account_id, method_name, args, @@ -485,32 +419,22 @@ async fn optimistic_function_call( &data.blocks_info_by_finality, block, data.max_gas_burnt, - optimistic_data, // run contract with optimistic data + maybe_optimistic_data, ) - .await -} + .await; -#[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] -async fn database_function_call( - data: &Data, - block: CacheBlock, - account_id: &near_primitives::types::AccountId, - method_name: &str, - args: &near_primitives::types::FunctionArgs, -) -> Result { - run_contract( - account_id, - method_name, - args, - &data.db_manager, - &data.compiled_contract_code_cache, - &data.contract_code_cache, - &data.blocks_info_by_finality, - block, - data.max_gas_burnt, - Default::default(), // run contract with empty optimistic data - ) - .await + let call_results = + call_results.map_err(|err| err.to_rpc_query_error(block.block_height, block.block_hash))?; + Ok(near_jsonrpc::primitives::types::query::RpcQueryResponse { + kind: near_jsonrpc::primitives::types::query::QueryResponseKind::CallResult( + near_primitives::views::CallResult { + result: call_results.result, + logs: call_results.logs, + }, + ), + block_height: block.block_height, + block_hash: block.block_hash, + }) } #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] @@ -564,8 +488,14 @@ async fn optimistic_view_state( .blocks_info_by_finality .optimistic_state_changes_in_block(account_id, prefix) .await; - let state_from_db = - get_state_keys_from_db(&data.db_manager, account_id, block.block_height, prefix).await; + let state_from_db = get_state_from_db( + &data.db_manager, + account_id, + block.block_height, + prefix, + "query_view_state", + ) + .await; if state_from_db.is_empty() && optimistic_data.is_empty() { Err( near_jsonrpc::primitives::types::query::RpcQueryError::UnknownAccount { @@ -615,8 +545,14 @@ async fn database_view_state( Vec, near_jsonrpc::primitives::types::query::RpcQueryError, > { - let state_from_db = - get_state_keys_from_db(&data.db_manager, account_id, block.block_height, prefix).await; + let state_from_db = get_state_from_db( + &data.db_manager, + account_id, + block.block_height, + prefix, + "query_view_state", + ) + .await; if state_from_db.is_empty() { Err( near_jsonrpc::primitives::types::query::RpcQueryError::UnknownAccount { @@ -710,7 +646,12 @@ async fn database_view_access_key( > { let access_key = data .db_manager - .get_access_key(account_id, block.block_height, public_key.clone()) + .get_access_key( + account_id, + block.block_height, + public_key.clone(), + "query_view_access_key", + ) .await .map_err( |_err| near_jsonrpc::primitives::types::query::RpcQueryError::UnknownAccessKey { diff --git a/rpc-server/src/modules/queries/mod.rs b/rpc-server/src/modules/queries/mod.rs index 342c1f83..e363fa87 100644 --- a/rpc-server/src/modules/queries/mod.rs +++ b/rpc-server/src/modules/queries/mod.rs @@ -1,305 +1,3 @@ -use std::collections::HashMap; - -use database::ReaderDbManager; -use futures::executor::block_on; - +mod contract_runner; pub mod methods; pub mod utils; - -pub type Result = ::std::result::Result; - -pub struct CodeStorage { - db_manager: std::sync::Arc>, - account_id: near_primitives::types::AccountId, - block_height: near_primitives::types::BlockHeight, - validators: HashMap, - data_count: u64, - is_optimistic: bool, - prefetched_data: - Option>, - optimistic_data: - HashMap>, -} - -pub struct StorageValuePtr { - value: Vec, -} - -impl near_vm_runner::logic::ValuePtr for StorageValuePtr { - fn len(&self) -> u32 { - self.value.len() as u32 - } - - fn deref(&self) -> Result> { - Ok(self.value.clone()) - } -} - -impl CodeStorage { - pub fn init( - db_manager: std::sync::Arc>, - account_id: near_primitives::types::AccountId, - block_height: near_primitives::types::BlockHeight, - validators: HashMap, - prefetched_data: Option< - HashMap, - >, - optimistic_data: HashMap< - readnode_primitives::StateKey, - Option, - >, - ) -> Self { - Self { - db_manager, - account_id, - block_height, - validators, - data_count: Default::default(), // TODO: Using for generate_data_id - is_optimistic: !optimistic_data.is_empty(), - prefetched_data, - optimistic_data, - } - } - - fn get_state_key_data(&self, key: &[u8]) -> readnode_primitives::StateValue { - if let Some(prefetched_data) = &self.prefetched_data { - prefetched_data.get(key).cloned().unwrap_or_default() - } else { - let get_db_data = self.db_manager.get_state_key_value( - &self.account_id, - self.block_height, - key.to_vec(), - ); - let (_, data) = block_on(get_db_data); - data - } - } - - fn optimistic_storage_get( - &self, - key: &[u8], - ) -> Result>> { - if let Some(value) = self.optimistic_data.get(key) { - Ok(value.as_ref().map(|data| { - Box::new(StorageValuePtr { - value: data.clone(), - }) as Box<_> - })) - } else { - self.database_storage_get(key) - } - } - - fn database_storage_get( - &self, - key: &[u8], - ) -> Result>> { - let data = self.get_state_key_data(key); - Ok(if !data.is_empty() { - Some(Box::new(StorageValuePtr { value: data }) as Box<_>) - } else { - None - }) - } - - fn optimistic_storage_has_key(&mut self, key: &[u8]) -> Result { - if let Some(value) = self.optimistic_data.get(key) { - Ok(value.is_some()) - } else { - self.database_storage_has_key(key) - } - } - - fn database_storage_has_key(&mut self, key: &[u8]) -> Result { - Ok(!self.get_state_key_data(key).is_empty()) - } -} - -impl near_vm_runner::logic::External for CodeStorage { - #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] - fn storage_set(&mut self, _key: &[u8], _value: &[u8]) -> Result<()> { - Err(near_vm_runner::logic::VMLogicError::HostError( - near_vm_runner::logic::HostError::ProhibitedInView { - method_name: String::from("storage_set"), - }, - )) - } - - #[cfg_attr( - feature = "tracing-instrumentation", - tracing::instrument(skip(self, _mode)) - )] - fn storage_get( - &self, - key: &[u8], - _mode: near_vm_runner::logic::StorageGetMode, - ) -> Result>> { - if self.is_optimistic { - self.optimistic_storage_get(key) - } else { - self.database_storage_get(key) - } - } - - #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] - fn storage_remove(&mut self, _key: &[u8]) -> Result<()> { - Err(near_vm_runner::logic::VMLogicError::HostError( - near_vm_runner::logic::HostError::ProhibitedInView { - method_name: String::from("storage_remove"), - }, - )) - } - - #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] - fn storage_remove_subtree(&mut self, _prefix: &[u8]) -> Result<()> { - Err(near_vm_runner::logic::VMLogicError::HostError( - near_vm_runner::logic::HostError::ProhibitedInView { - method_name: String::from("storage_remove_subtree"), - }, - )) - } - - #[cfg_attr( - feature = "tracing-instrumentation", - tracing::instrument(skip(self, _mode)) - )] - fn storage_has_key( - &mut self, - key: &[u8], - _mode: near_vm_runner::logic::StorageGetMode, - ) -> Result { - if self.is_optimistic { - self.optimistic_storage_has_key(key) - } else { - self.database_storage_has_key(key) - } - } - - #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] - fn generate_data_id(&mut self) -> near_primitives::hash::CryptoHash { - // TODO: Should be improvement in future - // Generates some hash for the data ID to receive data. - // This hash should not be functionality - let data_id = near_primitives::hash::hash(&self.data_count.to_le_bytes()); - self.data_count += 1; - data_id - } - - #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] - fn get_trie_nodes_count(&self) -> near_vm_runner::logic::TrieNodesCount { - near_vm_runner::logic::TrieNodesCount { - db_reads: 0, - mem_reads: 0, - } - } - - #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] - fn validator_stake( - &self, - account_id: &near_primitives::types::AccountId, - ) -> Result> { - Ok(self.validators.get(account_id).cloned()) - } - - #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(self)))] - fn validator_total_stake(&self) -> Result { - Ok(self.validators.values().sum()) - } - - fn create_receipt( - &mut self, - _receipt_indices: Vec, - _receiver_id: near_primitives::types::AccountId, - ) -> Result { - Err(near_vm_runner::logic::VMLogicError::HostError( - near_vm_runner::logic::HostError::ProhibitedInView { - method_name: String::from("create_receipt"), - }, - )) - } - - fn append_action_create_account( - &mut self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - ) -> Result<()> { - Ok(()) - } - - fn append_action_deploy_contract( - &mut self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - _code: Vec, - ) -> Result<()> { - Ok(()) - } - - fn append_action_function_call_weight( - &mut self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - _method_name: Vec, - _args: Vec, - _attached_deposit: near_primitives::types::Balance, - _prepaid_gas: near_primitives::types::Gas, - _gas_weight: near_primitives::types::GasWeight, - ) -> Result<()> { - Ok(()) - } - - fn append_action_transfer( - &mut self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - _deposit: near_primitives::types::Balance, - ) -> Result<()> { - Ok(()) - } - - fn append_action_stake( - &mut self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - _stake: near_primitives::types::Balance, - _public_key: near_crypto::PublicKey, - ) { - } - - fn append_action_add_key_with_full_access( - &mut self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - _public_key: near_crypto::PublicKey, - _nonce: near_primitives::types::Nonce, - ) { - } - - fn append_action_add_key_with_function_call( - &mut self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - _public_key: near_crypto::PublicKey, - _nonce: near_primitives::types::Nonce, - _allowance: Option, - _receiver_id: near_primitives::types::AccountId, - _method_names: Vec>, - ) -> Result<()> { - Ok(()) - } - - fn append_action_delete_key( - &mut self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - _public_key: near_crypto::PublicKey, - ) { - } - - fn append_action_delete_account( - &mut self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - _beneficiary_id: near_primitives::types::AccountId, - ) -> Result<()> { - Ok(()) - } - - fn get_receipt_receiver( - &self, - _receipt_index: near_vm_runner::logic::types::ReceiptIndex, - ) -> &near_primitives::types::AccountId { - panic!("Prohibited in view. `get_receipt_receiver`"); - } -} diff --git a/rpc-server/src/modules/queries/utils.rs b/rpc-server/src/modules/queries/utils.rs index fffe9f56..320e789b 100644 --- a/rpc-server/src/modules/queries/utils.rs +++ b/rpc-server/src/modules/queries/utils.rs @@ -1,54 +1,84 @@ use std::collections::HashMap; use futures::StreamExt; -use near_vm_runner::internal::VMKindExt; -use near_vm_runner::ContractRuntimeCache; -use crate::errors::FunctionCallError; -use crate::modules::blocks::BlocksInfoByFinality; -use crate::modules::queries::CodeStorage; - -pub struct RunContractResponse { - pub result: Vec, - pub logs: Vec, - pub block_height: near_primitives::types::BlockHeight, - pub block_hash: near_primitives::hash::CryptoHash, +// Function to get state key value from the database +// This function to wrap the database call to get state key value +// It is using for debug in jaeger tracing +#[cfg_attr( + feature = "tracing-instrumentation", + tracing::instrument(skip(db_manager)) +)] +pub async fn get_state_key_value_from_db( + db_manager: &std::sync::Arc>, + account_id: &near_primitives::types::AccountId, + block_height: near_primitives::types::BlockHeight, + key_data: readnode_primitives::StateKey, + method_name: &str, +) -> ( + readnode_primitives::StateKey, + readnode_primitives::StateValue, +) { + db_manager + .get_state_key_value(account_id, block_height, key_data, method_name) + .await } +// Function to get state keys from the database +// This function to wrap the database call to get state keys +// It is using for debug in jaeger tracing #[cfg_attr( feature = "tracing-instrumentation", tracing::instrument(skip(db_manager)) )] pub async fn get_state_keys_from_db( + db_manager: &std::sync::Arc>, + account_id: &near_primitives::types::AccountId, + prefix: &[u8], + method_name: &str, +) -> anyhow::Result> { + if !prefix.is_empty() { + db_manager + .get_state_keys_by_prefix(account_id, prefix, method_name) + .await + } else { + db_manager.get_state_keys_all(account_id, method_name).await + } +} + +#[cfg_attr( + feature = "tracing-instrumentation", + tracing::instrument(skip(db_manager)) +)] +pub async fn get_state_from_db( db_manager: &std::sync::Arc>, account_id: &near_primitives::types::AccountId, block_height: near_primitives::types::BlockHeight, prefix: &[u8], + method_name: &str, ) -> HashMap { tracing::debug!( - "`get_state_keys_from_db` call. AccountId {}, block {}, prefix {:?}", + "`get_state_from_db` call. AccountId {}, block {}, prefix {:?}", account_id, block_height, prefix, ); let mut data: HashMap = HashMap::new(); - let result = { - if !prefix.is_empty() { - db_manager - .get_state_keys_by_prefix(account_id, prefix) - .await - } else { - db_manager.get_state_keys_all(account_id).await - } - }; - match result { + + match get_state_keys_from_db(db_manager, account_id, prefix, method_name).await { Ok(state_keys) => { // 3 nodes * 8 cpus * 100 = 2400 // TODO: 2400 is hardcoded value. Make it configurable. for state_keys_chunk in state_keys.chunks(2400) { let futures = state_keys_chunk.iter().map(|state_key| { - db_manager.get_state_key_value(account_id, block_height, state_key.clone()) + get_state_key_value_from_db( + db_manager, + account_id, + block_height, + state_key.clone(), + method_name, + ) }); let mut tasks = futures::stream::FuturesUnordered::from_iter(futures); while let Some((state_key, state_value)) = tasks.next().await { @@ -79,7 +109,7 @@ pub async fn fetch_list_access_keys_from_db( block_height, ); let account_keys = db_manager - .get_account_access_keys(account_id, block_height) + .get_account_access_keys(account_id, block_height, "query_view_access_key_list") .await?; let account_keys_view = account_keys .into_iter() @@ -97,231 +127,3 @@ pub async fn fetch_list_access_keys_from_db( .collect(); Ok(account_keys_view) } - -#[allow(clippy::too_many_arguments)] -#[cfg_attr( - feature = "tracing-instrumentation", - tracing::instrument(skip(context, code_storage, contract_code, compiled_contract_code_cache)) -)] -async fn run_code_in_vm_runner( - code_hash: near_primitives::hash::CryptoHash, - contract_code: Option, - method_name: String, - context: near_vm_runner::logic::VMContext, - mut code_storage: CodeStorage, - vm_config: near_parameters::vm::Config, - compiled_contract_code_cache: &std::sync::Arc, -) -> Result { - let compiled_contract_code_cache_handle = compiled_contract_code_cache.handle(); - let results = tokio::task::spawn_blocking(move || { - let promise_results = vec![]; - let fees = near_parameters::RuntimeFeesConfig::free(); - - let runtime = vm_config - .vm_kind - .runtime(vm_config.clone()) - .expect("runtime has not been enabled at compile time"); - - if let Some(code) = &contract_code { - runtime - .precompile(code, &compiled_contract_code_cache_handle) - .expect("Compilation failed") - .expect("Cache failed"); - }; - - runtime.run( - code_hash, - None, - &method_name, - &mut code_storage, - &context, - &fees, - &promise_results, - Some(&compiled_contract_code_cache_handle), - ) - }) - .await; - match results { - Ok(result) => result, - Err(err) => Err( - near_vm_runner::logic::errors::VMRunnerError::WasmUnknownError { - debug_message: format!("Failed to run contract: {:?}", err), - }, - ), - } -} - -#[allow(clippy::too_many_arguments)] -#[cfg_attr( - feature = "tracing-instrumentation", - tracing::instrument(skip(db_manager, compiled_contract_code_cache, contract_code_cache)) -)] -pub async fn run_contract( - account_id: &near_primitives::types::AccountId, - method_name: &str, - args: &near_primitives::types::FunctionArgs, - db_manager: &std::sync::Arc>, - compiled_contract_code_cache: &std::sync::Arc, - contract_code_cache: &std::sync::Arc< - crate::cache::RwLockLruMemoryCache>, - >, - blocks_info_by_finality: &std::sync::Arc, - block: crate::modules::blocks::CacheBlock, - max_gas_burnt: near_primitives::types::Gas, - optimistic_data: HashMap< - readnode_primitives::StateKey, - Option, - >, -) -> Result { - let contract = db_manager - .get_account(account_id, block.block_height) - .await - .map_err(|_| FunctionCallError::AccountDoesNotExist { - requested_account_id: account_id.clone(), - })?; - - let (epoch_height, epoch_validators) = - if blocks_info_by_finality.final_cache_block().await.epoch_id == block.epoch_id { - let validators = blocks_info_by_finality.validators().await; - (validators.epoch_height, validators.current_validators) - } else { - let validators = db_manager - .get_validators_by_epoch_id(block.epoch_id) - .await - .map_err(|_| FunctionCallError::InternalError { - error_message: "Failed to get epoch info".to_string(), - })?; - ( - validators.epoch_height, - validators.validators_info.current_validators, - ) - }; - let validators = epoch_validators - .iter() - .map(|validator| (validator.account_id.clone(), validator.stake)) - .collect(); - - // Prepare context for the VM run contract - let public_key = near_crypto::PublicKey::empty(near_crypto::KeyType::ED25519); - let random_seed = near_primitives::utils::create_random_seed( - block.latest_protocol_version, - near_primitives::hash::CryptoHash::default(), - block.state_root, - ); - let context = near_vm_runner::logic::VMContext { - current_account_id: account_id.clone(), - signer_account_id: account_id.clone(), - signer_account_pk: borsh::to_vec(&public_key).expect("Failed to serialize"), - predecessor_account_id: account_id.clone(), - input: args.to_vec(), - block_height: block.block_height, - block_timestamp: block.block_timestamp, - epoch_height, - account_balance: contract.data.amount(), - account_locked_balance: contract.data.locked(), - storage_usage: contract.data.storage_usage(), - attached_deposit: 0, - prepaid_gas: max_gas_burnt, - random_seed, - view_config: Some(near_primitives::config::ViewConfig { max_gas_burnt }), - output_data_receivers: vec![], - }; - - // Init runtime config for each protocol version - let store = near_parameters::RuntimeConfigStore::free(); - let config = store - .get_config(block.latest_protocol_version) - .wasm_config - .clone(); - let vm_config = near_parameters::vm::Config { - vm_kind: config.vm_kind.replace_with_wasmtime_if_unsupported(), - ..config - }; - let code_hash = contract.data.code_hash(); - // Check if the contract code is already in the cache - - let key = near_vm_runner::get_contract_cache_key(code_hash, &vm_config); - let contract_code = if compiled_contract_code_cache.has(&key).unwrap_or(false) { - None - } else { - Some(match contract_code_cache.get(&code_hash).await { - Some(code) => near_vm_runner::ContractCode::new(code, Some(code_hash)), - None => { - let code = db_manager - .get_contract_code(account_id, block.block_height) - .await - .map_err(|_| FunctionCallError::InvalidAccountId { - requested_account_id: account_id.clone(), - })?; - contract_code_cache - .put(contract.data.code_hash(), code.data.clone()) - .await; - near_vm_runner::ContractCode::new(code.data, Some(contract.data.code_hash())) - } - }) - }; - - // TODO: Refactor this part. It's a temporary solution to fetch state keys from DB for the poolv1.near contracts - // https://github.com/near/read-rpc/issues/150 - let contract_state = if account_id.to_string().ends_with("poolv1.near") { - if let Ok(result) = tokio::time::timeout( - std::time::Duration::from_secs(20), - get_state_keys_from_db(db_manager, account_id, block.block_height, &[]), - ) - .await - { - tracing::debug!("State keys fetched from DB"); - Some(result) - } else { - tracing::error!("Failed to fetch state keys from DB"); - None - } - } else { - None - }; - - // Init an external scylla interface for the Runtime logic - let code_storage = CodeStorage::init( - db_manager.clone(), - account_id.clone(), - block.block_height, - validators, - contract_state, - optimistic_data, - ); - - // Execute the contract in the near VM - let result = run_code_in_vm_runner( - code_hash, - contract_code, - method_name.to_string(), - context, - code_storage, - vm_config, - compiled_contract_code_cache, - ) - .await - .map_err(|e| FunctionCallError::InternalError { - error_message: e.to_string(), - })?; - - if let Some(err) = result.aborted { - let message = format!("wasm execution failed with error: {:?}", err); - Err(FunctionCallError::VMError { - error_message: message, - }) - } else { - let logs = result.logs; - let result = match result.return_data { - near_vm_runner::logic::ReturnData::Value(buf) => buf, - near_vm_runner::logic::ReturnData::ReceiptIndex(_) - | near_vm_runner::logic::ReturnData::None => vec![], - }; - Ok(RunContractResponse { - result, - logs, - block_height: block.block_height, - block_hash: block.block_hash, - }) - } -} diff --git a/rpc-server/src/modules/receipts/methods.rs b/rpc-server/src/modules/receipts/methods.rs index 36dbb55c..422b5291 100644 --- a/rpc-server/src/modules/receipts/methods.rs +++ b/rpc-server/src/modules/receipts/methods.rs @@ -13,29 +13,41 @@ pub async fn receipt( tracing::debug!("`receipt` call. Params: {:?}", params); let receipt_request = near_jsonrpc::primitives::types::receipts::RpcReceiptRequest::parse(params)?; - crate::metrics::RECEIPT_REQUESTS_TOTAL.inc(); let result = fetch_receipt(&data, &receipt_request).await; #[cfg(feature = "shadow_data_consistency")] { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::RECEIPT_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &result, data.near_rpc_client.clone(), receipt_request, - "RECEIPT", + "EXPERIMENTAL_receipt", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "RECEIPT") - }; + .await; } Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) } +/// Fetches a receipt record by it's ID +#[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] +pub async fn view_receipt_record( + data: Data, + Params(params): Params, +) -> Result { + tracing::debug!("`view_receipt_record` call. Params: {:?}", params); + let receipt_request = + near_jsonrpc::primitives::types::receipts::RpcReceiptRequest::parse(params)?; + + let result = fetch_receipt_record(&data, &receipt_request, "view_receipt_record").await; + + Ok(result + .map_err(near_jsonrpc::primitives::errors::RpcError::from)? + .into()) +} + #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] async fn fetch_receipt( data: &Data, @@ -46,21 +58,15 @@ async fn fetch_receipt( > { let receipt_id = request.receipt_reference.receipt_id; - let receipt_record = data - .db_manager - .get_receipt_by_id(receipt_id) - .await - .map_err(|err| { - tracing::warn!("Error in `receipt` call: {:?}", err); - near_jsonrpc::primitives::types::receipts::RpcReceiptError::UnknownReceipt { - receipt_id, - } - })?; + let receipt_record = fetch_receipt_record(data, request, "EXPERIMENTAL_receipt").await?; // Getting the raw Vec of the TransactionDetails from ScyllaDB let transaction_details = data .db_manager - .get_transaction_by_hash(&receipt_record.parent_transaction_hash.to_string()) + .get_transaction_by_hash( + &receipt_record.parent_transaction_hash.to_string(), + "EXPERIMENTAL_receipt", + ) .await .map_err(|err| { tracing::warn!("Error in `receipt` call: {:?}", err); @@ -87,3 +93,25 @@ async fn fetch_receipt( Ok(near_jsonrpc::primitives::types::receipts::RpcReceiptResponse { receipt_view }) } + +#[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] +async fn fetch_receipt_record( + data: &Data, + request: &near_jsonrpc::primitives::types::receipts::RpcReceiptRequest, + method_name: &str, +) -> Result< + readnode_primitives::ReceiptRecord, + near_jsonrpc::primitives::types::receipts::RpcReceiptError, +> { + let receipt_id = request.receipt_reference.receipt_id; + + data.db_manager + .get_receipt_by_id(receipt_id, method_name) + .await + .map_err(|err| { + tracing::warn!("Error in `{}` call: {:?}", method_name, err); + near_jsonrpc::primitives::types::receipts::RpcReceiptError::UnknownReceipt { + receipt_id, + } + }) +} diff --git a/rpc-server/src/modules/receipts/mod.rs b/rpc-server/src/modules/receipts/mod.rs index 93d46dac..1a54123b 100644 --- a/rpc-server/src/modules/receipts/mod.rs +++ b/rpc-server/src/modules/receipts/mod.rs @@ -1 +1,20 @@ pub mod methods; + +#[derive(serde::Serialize, serde::Deserialize, Debug)] +pub struct RpcReceiptRecordResponse { + pub receipt_id: near_indexer_primitives::CryptoHash, + pub parent_transaction_hash: near_indexer_primitives::CryptoHash, + pub block_height: near_indexer_primitives::types::BlockHeight, + pub shard_id: near_indexer_primitives::types::ShardId, +} + +impl From for RpcReceiptRecordResponse { + fn from(receipt: readnode_primitives::ReceiptRecord) -> Self { + Self { + receipt_id: receipt.receipt_id, + parent_transaction_hash: receipt.parent_transaction_hash, + block_height: receipt.block_height, + shard_id: receipt.shard_id, + } + } +} diff --git a/rpc-server/src/modules/state/methods.rs b/rpc-server/src/modules/state/methods.rs index ec31b761..eeaf1b29 100644 --- a/rpc-server/src/modules/state/methods.rs +++ b/rpc-server/src/modules/state/methods.rs @@ -1,7 +1,7 @@ use crate::config::ServerContext; use crate::errors::RPCError; use crate::modules::blocks::utils::fetch_block_from_cache_or_get; -use crate::modules::state::utils::get_state_keys_from_db_paginated; +use crate::modules::state::utils::get_state_from_db_paginated; use jsonrpc_v2::{Data, Params}; pub async fn view_state_paginated( @@ -9,11 +9,11 @@ pub async fn view_state_paginated( Params(params): Params, ) -> Result { let block_reference = near_primitives::types::BlockReference::BlockId(params.block_id.clone()); - let block = fetch_block_from_cache_or_get(&data, block_reference) + let block = fetch_block_from_cache_or_get(&data, &block_reference, "view_state_paginated") .await .map_err(near_jsonrpc::primitives::errors::RpcError::from)?; - let state_values = get_state_keys_from_db_paginated( + let state_values = get_state_from_db_paginated( &data.db_manager, ¶ms.account_id, block.block_height, diff --git a/rpc-server/src/modules/state/utils.rs b/rpc-server/src/modules/state/utils.rs index 5ae28ed2..55f7fc2e 100644 --- a/rpc-server/src/modules/state/utils.rs +++ b/rpc-server/src/modules/state/utils.rs @@ -6,24 +6,29 @@ use futures::StreamExt; feature = "tracing-instrumentation", tracing::instrument(skip(db_manager)) )] -pub async fn get_state_keys_from_db_paginated( +pub async fn get_state_from_db_paginated( db_manager: &std::sync::Arc>, account_id: &near_primitives::types::AccountId, block_height: near_primitives::types::BlockHeight, page_token: database::PageToken, ) -> crate::modules::state::PageStateValues { tracing::debug!( - "`get_state_keys_from_db_paginated` call. AccountId {}, block {}, page_token {:?}", + "`get_state_from_db_paginated` call. AccountId {}, block {}, page_token {:?}", account_id, block_height, page_token, ); if let Ok((state_keys, next_page_token)) = db_manager - .get_state_keys_by_page(account_id, page_token) + .get_state_keys_by_page(account_id, page_token, "view_state_paginated") .await { let futures = state_keys.iter().map(|state_key| { - db_manager.get_state_key_value(account_id, block_height, state_key.clone()) + db_manager.get_state_key_value( + account_id, + block_height, + state_key.clone(), + "view_state_paginated", + ) }); let mut tasks = futures::stream::FuturesUnordered::from_iter(futures); let mut data: HashMap = diff --git a/rpc-server/src/modules/transactions/methods.rs b/rpc-server/src/modules/transactions/methods.rs index 3a9ead6b..8f689dc8 100644 --- a/rpc-server/src/modules/transactions/methods.rs +++ b/rpc-server/src/modules/transactions/methods.rs @@ -21,17 +21,15 @@ pub async fn tx( Params(params): Params, ) -> Result { tracing::debug!("`tx` call. Params: {:?}", params); - crate::metrics::TX_REQUESTS_TOTAL.inc(); let tx_status_request = near_jsonrpc::primitives::types::transactions::RpcTransactionStatusRequest::parse(params)?; - let result = tx_status_common(&data, &tx_status_request.transaction_info, false).await; + let result = tx_status_common(&data, &tx_status_request.transaction_info, false, "tx").await; #[cfg(feature = "shadow_data_consistency")] { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::TX_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &result, data.near_rpc_client.clone(), @@ -43,12 +41,9 @@ pub async fn tx( transaction_info: tx_status_request.transaction_info, wait_until: tx_status_request.wait_until, }, - "TX", + "tx", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "TX") - }; + .await; } Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) @@ -61,17 +56,21 @@ pub async fn tx_status( Params(params): Params, ) -> Result { tracing::debug!("`tx_status` call. Params: {:?}", params); - crate::metrics::TX_STATUS_REQUESTS_TOTAL.inc(); let tx_status_request = near_jsonrpc::primitives::types::transactions::RpcTransactionStatusRequest::parse(params)?; - let result = tx_status_common(&data, &tx_status_request.transaction_info, true).await; + let result = tx_status_common( + &data, + &tx_status_request.transaction_info, + true, + "EXPERIMENTAL_tx_status", + ) + .await; #[cfg(feature = "shadow_data_consistency")] { - if let Some(err_code) = crate::utils::shadow_compare_results_handler( - crate::metrics::TX_STATUS_REQUESTS_TOTAL.get(), + crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, &result, data.near_rpc_client.clone(), @@ -82,12 +81,9 @@ pub async fn tx_status( transaction_info: tx_status_request.transaction_info, wait_until: tx_status_request.wait_until, }, - "EXPERIMENTAL_TX_STATUS", + "EXPERIMENTAL_tx_status", ) - .await - { - crate::utils::capture_shadow_consistency_error!(err_code, "EXPERIMENTAL_TX_STATUS") - }; + .await; } Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) @@ -156,6 +152,7 @@ async fn tx_status_common( data: &Data, transaction_info: &near_jsonrpc::primitives::types::transactions::TransactionInfo, fetch_receipt: bool, + method_name: &str, ) -> Result< near_jsonrpc::primitives::types::transactions::RpcTransactionResponse, near_jsonrpc::primitives::types::transactions::RpcTransactionError, @@ -173,7 +170,7 @@ async fn tx_status_common( let transaction_details = data .db_manager - .get_transaction_by_hash(&tx_hash.to_string()) + .get_transaction_by_hash(&tx_hash.to_string(), method_name) .await .map_err(|_err| { near_jsonrpc::primitives::types::transactions::RpcTransactionError::UnknownTransaction { diff --git a/rpc-server/src/utils.rs b/rpc-server/src/utils.rs index 8ab47221..56d2ebe8 100644 --- a/rpc-server/src/utils.rs +++ b/rpc-server/src/utils.rs @@ -3,7 +3,6 @@ use crate::modules::network::epoch_config_from_protocol_config_view; #[cfg(feature = "shadow_data_consistency")] use assert_json_diff::{assert_json_matches_no_panic, CompareMode, Config, NumericMode}; use futures::StreamExt; -use std::path::PathBuf; #[cfg(feature = "shadow_data_consistency")] const DEFAULT_RETRY_COUNT: u8 = 3; @@ -67,7 +66,9 @@ impl JsonRpcClient { M: near_jsonrpc_client::methods::RpcMethod + std::fmt::Debug, { tracing::debug!("PROXY call. {:?}", params); - crate::metrics::PROXY_REQUESTS_TO_REGULAR_NODES_COUNTER.inc(); + crate::metrics::REQUESTS_COUNTER + .with_label_values(&["regular_proxy"]) + .inc(); self.rpc_call(params, false).await } @@ -80,7 +81,9 @@ impl JsonRpcClient { M: near_jsonrpc_client::methods::RpcMethod + std::fmt::Debug, { tracing::debug!("ARCHIVAL PROXY call. {:?}", params); - crate::metrics::PROXY_REQUESTS_TO_ARCHIVAL_NODES_COUNTER.inc(); + crate::metrics::REQUESTS_COUNTER + .with_label_values(&["archive_proxy"]) + .inc(); self.rpc_call(params, true).await } @@ -117,10 +120,14 @@ pub async fn get_final_block( // https://github.com/tikv/rust-prometheus/issues/470 if optimistic { // optimistic block height - crate::metrics::OPTIMISTIC_BLOCK_HEIGHT.set(i64::try_from(block_view.header.height)?); + crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["optimistic"]) + .set(i64::try_from(block_view.header.height)?); } else { // final block height - crate::metrics::FINAL_BLOCK_HEIGHT.set(i64::try_from(block_view.header.height)?); + crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["final"]) + .set(i64::try_from(block_view.header.height)?); } Ok(block_view) } @@ -156,7 +163,11 @@ async fn handle_streamer_message( let block = BlockInfo::new_from_streamer_message(streamer_message).await; let block_cache = block.block_cache; - if block_cache.block_height as i64 > crate::metrics::FINAL_BLOCK_HEIGHT.get() { + if block_cache.block_height as i64 + > crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["final"]) + .get() + { if blocks_info_by_finality.final_cache_block().await.epoch_id != block_cache.epoch_id { tracing::info!("New epoch started: {:?}", block_cache.epoch_id); blocks_info_by_finality @@ -168,7 +179,9 @@ async fn handle_streamer_message( blocks_cache .put(block_cache.block_height, block_cache) .await; - crate::metrics::FINAL_BLOCK_HEIGHT.set(i64::try_from(block_cache.block_height)?); + crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["final"]) + .set(i64::try_from(block_cache.block_height)?); } Ok(()) } @@ -284,15 +297,19 @@ pub async fn update_optimistic_block_regularly( let optimistic_block = BlockInfo::new_from_streamer_message(streamer_message).await; let optimistic_block_cache = optimistic_block.block_cache; if optimistic_block_cache.block_height as i64 - > crate::metrics::OPTIMISTIC_BLOCK_HEIGHT.get() + > crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["optimistic"]) + .get() { blocks_info_by_finality .update_optimistic_block(optimistic_block) .await; - crate::metrics::OPTIMISTIC_BLOCK_HEIGHT.set( - i64::try_from(optimistic_block_cache.block_height) - .expect("Invalid optimistic block height"), - ); + crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["optimistic"]) + .set( + i64::try_from(optimistic_block_cache.block_height) + .expect("Invalid optimistic block height"), + ); } } Err(err) => { @@ -302,7 +319,12 @@ pub async fn update_optimistic_block_regularly( // When an optimistic block is not updated, or it is lower than the final block // we need to mark that optimistic updating is not working - if crate::metrics::OPTIMISTIC_BLOCK_HEIGHT.get() <= crate::metrics::FINAL_BLOCK_HEIGHT.get() + if crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["optimistic"]) + .get() + <= crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["final"]) + .get() && !crate::metrics::OPTIMISTIC_UPDATING.is_not_working() { tracing::warn!( @@ -313,7 +335,12 @@ pub async fn update_optimistic_block_regularly( // When an optimistic block is updated, and it is greater than the final block // we need to mark that optimistic updating is working - if crate::metrics::OPTIMISTIC_BLOCK_HEIGHT.get() > crate::metrics::FINAL_BLOCK_HEIGHT.get() + if crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["optimistic"]) + .get() + > crate::metrics::LATEST_BLOCK_HEIGHT_BY_FINALITIY + .with_label_values(&["final"]) + .get() && crate::metrics::OPTIMISTIC_UPDATING.is_not_working() { crate::metrics::OPTIMISTIC_UPDATING.set_working(); @@ -345,21 +372,22 @@ pub fn friendly_memory_size_format(memory_size_bytes: usize) -> String { #[cfg(feature = "shadow_data_consistency")] pub async fn shadow_compare_results_handler( - method_total_requests: u64, shadow_rate: f64, read_rpc_result: &Result, near_rpc_client: JsonRpcClient, params: M, - method_metric_name: &str, -) -> Option -where + method_name: &str, +) where M: near_jsonrpc_client::methods::RpcMethod + std::fmt::Debug, ::Response: serde::ser::Serialize, ::Error: std::fmt::Debug + serde::ser::Serialize, T: serde::ser::Serialize, E: std::fmt::Debug + serde::ser::Serialize, { - if is_should_shadow_compare_results(method_total_requests, shadow_rate).await { + let method_total_requests = crate::metrics::METHOD_CALLS_COUNTER + .with_label_values(&[method_name]) + .get(); + let err_code = if is_should_shadow_compare_results(method_total_requests, shadow_rate).await { let meta_data = format!("{:?}", params); let (read_rpc_response_json, is_response_ok) = match read_rpc_result { Ok(res) => (serde_json::to_value(res), true), @@ -390,7 +418,7 @@ where tracing::warn!( target: "shadow_data_consistency", "Shadow data check: ERROR\n{}:{}: {}\n{}", - method_metric_name, + method_name, reason.code(), meta_data, format!("{}, ReadRPC: {:?}, NearRPC: {:?}", reason.reason(), read_rpc_response, near_rpc_response), @@ -400,17 +428,22 @@ where tracing::warn!( target: "shadow_data_consistency", "Shadow data check: ERROR\n{}:4: {}\n{:?}", - method_metric_name, + method_name, meta_data, format!("NearRPC: {}, ReadRPC: {:?}", err, read_rpc_response_meta_data), ); - Some(4) + Some("4".to_string()) } } } } else { None - } + }; + if let Some(err_code) = &err_code { + crate::metrics::REQUESTS_ERRORS + .with_label_values(&[method_name, err_code]) + .inc(); + }; } #[cfg(feature = "shadow_data_consistency")] @@ -601,12 +634,12 @@ pub enum DataMismatchReason { impl DataMismatchReason { /// This method converts the reason into a number from 0 to 3. These numbers are used in the /// metrics like BLOCK_ERROR_0, BLOCK_ERROR_1, BLOCK_ERROR_2, BLOCK_ERROR_3 etc. - pub fn code(&self) -> usize { + pub fn code(&self) -> String { match self { - DataMismatchReason::ReadRpcSuccessNearRpcSuccess => 0, - DataMismatchReason::ReadRpcSuccessNearRpcError => 1, - DataMismatchReason::ReadRpcErrorNearRpcSuccess => 2, - DataMismatchReason::ReadRpcErrorNearRpcError => 3, + DataMismatchReason::ReadRpcSuccessNearRpcSuccess => "0".to_string(), + DataMismatchReason::ReadRpcSuccessNearRpcError => "1".to_string(), + DataMismatchReason::ReadRpcErrorNearRpcSuccess => "2".to_string(), + DataMismatchReason::ReadRpcErrorNearRpcError => "3".to_string(), } } @@ -694,53 +727,3 @@ fn generate_array_key(value: &serde_json::Value) -> String { }), } } - -#[cfg(feature = "shadow_data_consistency")] -macro_rules! capture_shadow_consistency_error { - ($err_code:ident, $method_metric_name:expr) => { - match $err_code { - 0 => { - paste::paste! { - crate::metrics::[<$method_metric_name _ERROR_0>].inc(); - } - } - 1 => { - paste::paste! { - crate::metrics::[<$method_metric_name _ERROR_1>].inc(); - } - } - 2 => { - paste::paste! { - crate::metrics::[<$method_metric_name _ERROR_2>].inc(); - } - } - 3 => { - paste::paste! { - crate::metrics::[<$method_metric_name _ERROR_3>].inc(); - } - } - _ => { - paste::paste! { - crate::metrics::[<$method_metric_name _ERROR_4>].inc(); - } - } - } - }; -} - -#[cfg(feature = "shadow_data_consistency")] -pub(crate) use capture_shadow_consistency_error; - -#[allow(unused)] -pub fn get_home_dir() -> PathBuf { - if let Ok(near_home) = std::env::var("NEAR_HOME") { - return near_home.into(); - } - - if let Some(mut home) = dirs::home_dir() { - home.push(".near"); - return home; - } - - PathBuf::default() -}