From 30d753d7790ddd2d5c7abc6847a721c7faa6ded8 Mon Sep 17 00:00:00 2001 From: Yurii Koba Date: Thu, 19 Sep 2024 14:27:18 +0300 Subject: [PATCH] feat: handled internal error properly (#352) * feat: handled internal error properly * clippy --- Cargo.lock | 104 +++++------ Cargo.toml | 26 +-- rpc-server/src/errors.rs | 171 ------------------ rpc-server/src/main.rs | 15 +- rpc-server/src/modules/blocks/methods.rs | 105 ++++++++--- rpc-server/src/modules/clients/methods.rs | 25 ++- rpc-server/src/modules/gas/methods.rs | 10 +- rpc-server/src/modules/network/methods.rs | 130 ++++++++++--- .../modules/queries/contract_runner/mod.rs | 50 +++-- rpc-server/src/modules/queries/methods.rs | 49 ++++- rpc-server/src/modules/receipts/methods.rs | 28 +-- rpc-server/src/modules/state/methods.rs | 11 +- .../src/modules/transactions/methods.rs | 61 +++++-- 13 files changed, 408 insertions(+), 377 deletions(-) delete mode 100644 rpc-server/src/errors.rs diff --git a/Cargo.lock b/Cargo.lock index 4d755fa7..bc518b61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -678,9 +678,9 @@ dependencies = [ [[package]] name = "aws-sdk-s3" -version = "1.50.0" +version = "1.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56ac112fb11bcf25b4c17d90595c1232bae8841ee811c198e1a55c19789dfe3" +checksum = "c09fd4b5c7ed75f52b913b4f3ff0501dae7f8cb9125f6d45db4553980cbc0528" dependencies = [ "ahash 0.8.11", "aws-credential-types", @@ -3996,7 +3996,7 @@ dependencies = [ [[package]] name = "near-async" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "derive_more", @@ -4016,7 +4016,7 @@ dependencies = [ [[package]] name = "near-async-derive" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "proc-macro2", "quote", @@ -4026,7 +4026,7 @@ dependencies = [ [[package]] name = "near-cache" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "lru 0.12.4", ] @@ -4034,7 +4034,7 @@ dependencies = [ [[package]] name = "near-chain" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "assert_matches", @@ -4104,7 +4104,7 @@ dependencies = [ [[package]] name = "near-chain-configs" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "anyhow", "bytesize", @@ -4129,7 +4129,7 @@ dependencies = [ [[package]] name = "near-chain-primitives" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "near-crypto 2.2.1", "near-primitives 2.2.1", @@ -4142,7 +4142,7 @@ dependencies = [ [[package]] name = "near-chunks" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "borsh 1.5.1", @@ -4175,7 +4175,7 @@ dependencies = [ [[package]] name = "near-chunks-primitives" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "near-chain-primitives", "near-primitives 2.2.1", @@ -4184,7 +4184,7 @@ dependencies = [ [[package]] name = "near-client" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "actix-rt", @@ -4242,7 +4242,7 @@ dependencies = [ [[package]] name = "near-client-primitives" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "chrono", @@ -4276,7 +4276,7 @@ dependencies = [ [[package]] name = "near-config-utils" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "anyhow", "json_comments", @@ -4314,7 +4314,7 @@ dependencies = [ [[package]] name = "near-crypto" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "blake2 0.10.6", "borsh 1.5.1", @@ -4339,7 +4339,7 @@ dependencies = [ [[package]] name = "near-dyn-configs" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "anyhow", "near-chain-configs 2.2.1", @@ -4359,7 +4359,7 @@ dependencies = [ [[package]] name = "near-epoch-manager" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "borsh 1.5.1", "itertools 0.10.5", @@ -4392,7 +4392,7 @@ dependencies = [ [[package]] name = "near-fmt" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "near-primitives-core 2.2.1", ] @@ -4400,7 +4400,7 @@ dependencies = [ [[package]] name = "near-indexer" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "anyhow", @@ -4428,7 +4428,7 @@ dependencies = [ [[package]] name = "near-indexer-primitives" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "near-primitives 2.2.1", "serde", @@ -4438,7 +4438,7 @@ dependencies = [ [[package]] name = "near-jsonrpc" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "actix-cors 0.6.5", @@ -4489,7 +4489,7 @@ dependencies = [ [[package]] name = "near-jsonrpc-client" version = "0.13.0" -source = "git+https://github.com/kobayurii/near-jsonrpc-client-rs.git?branch=0.13.2#e3d5c5572552a26eaa534bc3222a37e4b2375ecb" +source = "git+https://github.com/kobayurii/near-jsonrpc-client-rs.git?branch=0.13.3#f0920d4f9e7d04f68920dcf2af0176ed7f83d0e9" dependencies = [ "borsh 1.5.1", "lazy_static", @@ -4507,7 +4507,7 @@ dependencies = [ [[package]] name = "near-jsonrpc-client" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix-http", "awc", @@ -4537,7 +4537,7 @@ dependencies = [ [[package]] name = "near-jsonrpc-primitives" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "arbitrary", "near-chain-configs 2.2.1", @@ -4554,7 +4554,7 @@ dependencies = [ [[package]] name = "near-lake-framework" version = "0.0.0" -source = "git+https://github.com/kobayurii/near-lake-framework-rs.git?branch=0.7.19#ed4fb2fdb774c15ab55919ffa229d3fb1e584d04" +source = "git+https://github.com/kobayurii/near-lake-framework-rs.git?branch=0.7.20#285e88382b25823141a0f80840d30f918c999ca2" dependencies = [ "anyhow", "async-stream", @@ -4578,7 +4578,7 @@ dependencies = [ [[package]] name = "near-mainnet-res" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "near-account-id", "near-chain-configs 2.2.1", @@ -4589,7 +4589,7 @@ dependencies = [ [[package]] name = "near-network" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "anyhow", @@ -4669,7 +4669,7 @@ dependencies = [ [[package]] name = "near-o11y" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "base64 0.21.7", @@ -4714,7 +4714,7 @@ dependencies = [ [[package]] name = "near-parameters" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "borsh 1.5.1", "enum-map", @@ -4731,7 +4731,7 @@ dependencies = [ [[package]] name = "near-performance-metrics" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "bitflags 1.3.2", @@ -4747,7 +4747,7 @@ dependencies = [ [[package]] name = "near-performance-metrics-macros" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "quote", "syn 2.0.77", @@ -4756,7 +4756,7 @@ dependencies = [ [[package]] name = "near-pool" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "borsh 1.5.1", "near-crypto 2.2.1", @@ -4811,7 +4811,7 @@ dependencies = [ [[package]] name = "near-primitives" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "arbitrary", "base64 0.21.7", @@ -4876,7 +4876,7 @@ dependencies = [ [[package]] name = "near-primitives-core" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "arbitrary", "base64 0.21.7", @@ -4896,7 +4896,7 @@ dependencies = [ [[package]] name = "near-rosetta-rpc" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "actix-cors 0.6.5", @@ -4938,7 +4938,7 @@ dependencies = [ [[package]] name = "near-rpc-error-core" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "quote", "serde", @@ -4960,7 +4960,7 @@ dependencies = [ [[package]] name = "near-rpc-error-macro" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "near-rpc-error-core 2.2.1", "serde", @@ -5003,12 +5003,12 @@ checksum = "855fd5540e3b4ff6fedf12aba2db1ee4b371b36f465da1363a6d022b27cb43b8" [[package]] name = "near-stdx" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" [[package]] name = "near-store" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "actix-rt", @@ -5052,12 +5052,12 @@ dependencies = [ [[package]] name = "near-structs-checker-core" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" [[package]] name = "near-structs-checker-lib" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "near-structs-checker-core", "near-structs-checker-macro", @@ -5066,12 +5066,12 @@ dependencies = [ [[package]] name = "near-structs-checker-macro" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" [[package]] name = "near-telemetry" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "awc", @@ -5091,7 +5091,7 @@ dependencies = [ [[package]] name = "near-time" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "once_cell", "serde", @@ -5102,7 +5102,7 @@ dependencies = [ [[package]] name = "near-vm-compiler" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "enumset", "finite-wasm", @@ -5118,7 +5118,7 @@ dependencies = [ [[package]] name = "near-vm-compiler-singlepass" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "dynasm 2.0.0", "dynasmrt 2.0.0", @@ -5139,7 +5139,7 @@ dependencies = [ [[package]] name = "near-vm-engine" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "backtrace", "cfg-if 1.0.0", @@ -5192,7 +5192,7 @@ dependencies = [ [[package]] name = "near-vm-runner" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "anyhow", "blst", @@ -5247,7 +5247,7 @@ dependencies = [ [[package]] name = "near-vm-types" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "indexmap 1.9.3", "num-traits", @@ -5258,7 +5258,7 @@ dependencies = [ [[package]] name = "near-vm-vm" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "backtrace", "cc", @@ -5279,7 +5279,7 @@ dependencies = [ [[package]] name = "near-wallet-contract" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "anyhow", "near-primitives-core 2.2.1", @@ -5290,7 +5290,7 @@ dependencies = [ [[package]] name = "nearcore" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "actix", "actix-rt", @@ -5380,7 +5380,7 @@ dependencies = [ [[package]] name = "node-runtime" version = "2.2.1" -source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork#f615ad70119d028e6c563e456b71093678c0883f" +source = "git+https://github.com/kobayurii/nearcore.git?branch=2.2.1-fork1#3a97591c46c1b62082de8a48a7da48bb0778a1bb" dependencies = [ "borsh 1.5.1", "near-crypto 2.2.1", diff --git a/Cargo.toml b/Cargo.toml index ffc9b7cf..847cc6ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,22 +51,22 @@ tx-details-storage = { path = "tx-details-storage" } logic-state-indexer = { path = "logic-state-indexer" } # Please, update the supported nearcore version in .cargo/config.toml file -near-async = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-indexer = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-client = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-o11y = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-indexer-primitives = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-primitives = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-chain-configs = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-crypto = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-jsonrpc = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-parameters = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork" } -near-vm-runner = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork", features = [ +near-async = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-indexer = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-client = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-o11y = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-indexer-primitives = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-primitives = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-chain-configs = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-crypto = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-jsonrpc = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-parameters = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1" } +near-vm-runner = { git = 'https://github.com/kobayurii/nearcore.git', branch = "2.2.1-fork1", features = [ "wasmer0_vm", "wasmer2_vm", "wasmtime_vm", "near_vm", ] } -near-lake-framework = { git = 'https://github.com/kobayurii/near-lake-framework-rs.git', branch = '0.7.19' } -near-jsonrpc-client = { git = 'https://github.com/kobayurii/near-jsonrpc-client-rs.git', branch = '0.13.2' } +near-lake-framework = { git = 'https://github.com/kobayurii/near-lake-framework-rs.git', branch = '0.7.20' } +near-jsonrpc-client = { git = 'https://github.com/kobayurii/near-jsonrpc-client-rs.git', branch = '0.13.3' } diff --git a/rpc-server/src/errors.rs b/rpc-server/src/errors.rs deleted file mode 100644 index 614ce836..00000000 --- a/rpc-server/src/errors.rs +++ /dev/null @@ -1,171 +0,0 @@ -use std::ops::{Deref, DerefMut}; - -use near_jsonrpc::primitives::errors::{RpcError, RpcErrorKind, RpcRequestValidationErrorKind}; -use near_jsonrpc_client::errors::{JsonRpcError, JsonRpcServerError}; -use serde_json::Value; - -#[derive(Debug, serde::Serialize)] -#[serde(transparent)] -pub struct RPCError(pub(crate) near_jsonrpc::primitives::errors::RpcError); - -impl From for near_jsonrpc::primitives::errors::RpcError { - fn from(err: RPCError) -> Self { - err.0 - } -} - -impl RPCError { - pub fn method_not_found(method_name: &str) -> Self { - RpcError { - code: -32_601, - message: "Method not found".to_owned(), - data: Some(Value::String(method_name.to_string())), - error_struct: Some(RpcErrorKind::RequestValidationError( - RpcRequestValidationErrorKind::MethodNotFound { - method_name: method_name.to_string(), - }, - )), - } - .into() - } - - pub(crate) fn unimplemented_error(method_name: &str) -> Self { - Self::from(near_jsonrpc::primitives::errors::RpcError::new( - -32601, - format!( - "Method `{}` is not implemented on this type of node. \ - Please send a request to NEAR JSON RPC instead.", - method_name - ), - None, - )) - } - - pub(crate) fn internal_error(msg: &str) -> Self { - Self::from(near_jsonrpc::primitives::errors::RpcError::new( - -32603, - String::from(msg), - None, - )) - } - - pub(crate) fn parse_error(msg: String) -> Self { - RpcError { - code: -32_700, - message: "Parse error".to_owned(), - data: Some(serde_json::Value::String(msg.clone())), - error_struct: Some( - near_jsonrpc::primitives::errors::RpcErrorKind::RequestValidationError( - near_jsonrpc::primitives::errors::RpcRequestValidationErrorKind::ParseError { - error_message: msg, - }, - ), - ), - } - .into() - } -} - -impl Deref for RPCError { - type Target = near_jsonrpc::primitives::errors::RpcError; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for RPCError { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl std::fmt::Display for RPCError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} - -impl From for RPCError { - fn from(parse_error: near_jsonrpc::primitives::errors::RpcParseError) -> Self { - Self(near_jsonrpc::primitives::errors::RpcError::parse_error( - parse_error.0, - )) - } -} - -impl From for RPCError { - fn from(rpc_error: near_jsonrpc::primitives::errors::RpcError) -> Self { - Self(rpc_error) - } -} - -impl From> for RPCError -where - near_jsonrpc::primitives::errors::RpcError: From, -{ - fn from(err: JsonRpcError) -> Self { - if let JsonRpcError::ServerError(JsonRpcServerError::HandlerError(error)) = err { - near_jsonrpc::primitives::errors::RpcError::from(error).into() - } else { - Self( - near_jsonrpc::primitives::errors::RpcError::serialization_error( - "Failed to serialize JsonRpcError".to_string(), - ), - ) - } - } -} - -#[derive(thiserror::Error, Debug, Clone)] -pub enum FunctionCallError { - #[error("Account ID \"{requested_account_id}\" is invalid")] - InvalidAccountId { - requested_account_id: near_primitives::types::AccountId, - }, - #[error("Account ID #{requested_account_id} does not exist")] - AccountDoesNotExist { - requested_account_id: near_primitives::types::AccountId, - }, - #[error("Internal error: #{error_message}")] - InternalError { error_message: String }, - #[error("VM error occurred: #{error_message}")] - VMError { error_message: String }, -} - -impl FunctionCallError { - pub fn to_rpc_query_error( - &self, - block_height: near_primitives::types::BlockHeight, - block_hash: near_primitives::hash::CryptoHash, - ) -> near_jsonrpc::primitives::types::query::RpcQueryError { - match self.clone() { - Self::InvalidAccountId { - requested_account_id, - } => near_jsonrpc::primitives::types::query::RpcQueryError::InvalidAccount { - requested_account_id, - block_height, - block_hash, - }, - Self::AccountDoesNotExist { - requested_account_id, - } => near_jsonrpc::primitives::types::query::RpcQueryError::UnknownAccount { - requested_account_id, - block_height, - block_hash, - }, - Self::InternalError { error_message } => { - near_jsonrpc::primitives::types::query::RpcQueryError::InternalError { - error_message, - } - } - Self::VMError { error_message } => { - near_jsonrpc::primitives::types::query::RpcQueryError::ContractExecutionError { - vm_error: error_message, - block_height, - block_hash, - } - } - } - } -} diff --git a/rpc-server/src/main.rs b/rpc-server/src/main.rs index 4adfefbb..cd3bca56 100644 --- a/rpc-server/src/main.rs +++ b/rpc-server/src/main.rs @@ -12,8 +12,6 @@ use near_jsonrpc::{ }; use serde_json::Value; -use errors::RPCError; - #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; @@ -22,7 +20,6 @@ extern crate lazy_static; mod cache; mod config; -mod errors; mod health; mod metrics; mod middlewares; @@ -35,8 +32,8 @@ pub(crate) const RPC_SERVER: &str = "read_rpc_server"; /// Serialises response of a query into JSON to be sent to the client. /// /// Returns an internal server error if the value fails to serialise. -fn serialize_response(value: impl serde::ser::Serialize) -> Result { - serde_json::to_value(value).map_err(|err| RPCError::internal_error(&err.to_string())) +fn serialize_response(value: impl serde::ser::Serialize) -> Result { + serde_json::to_value(value).map_err(|err| RpcError::serialization_error(err.to_string())) } /// Processes a specific method call. @@ -48,11 +45,11 @@ fn serialize_response(value: impl serde::ser::Serialize) -> Result( request: Request, callback: impl FnOnce(R) -> F, -) -> Result +) -> Result where R: RpcRequest, V: serde::ser::Serialize, - RPCError: std::convert::From, + RpcError: std::convert::From, F: std::future::Future>, { serialize_response(callback(R::parse(request.params)?).await?) @@ -77,7 +74,7 @@ async fn rpc_handler( modules::state::methods::view_state_paginated(data, request_data).await, ) } else { - Err(RPCError::parse_error( + Err(RpcError::parse_error( "Failed to parse request data".to_string(), )) } @@ -234,7 +231,7 @@ async fn rpc_handler( }) .await } - _ => Err(RPCError::method_not_found(method_name.as_ref())), + _ => Err(RpcError::method_not_found(method_name.clone())), }; match &result { diff --git a/rpc-server/src/modules/blocks/methods.rs b/rpc-server/src/modules/blocks/methods.rs index c5b06b24..7b7e79c5 100644 --- a/rpc-server/src/modules/blocks/methods.rs +++ b/rpc-server/src/modules/blocks/methods.rs @@ -3,7 +3,6 @@ use near_primitives::trie_key::TrieKey; use near_primitives::views::StateChangeValueView; use crate::config::ServerContext; -use crate::errors::RPCError; use crate::modules::blocks::utils::{ fetch_block_from_cache_or_get, fetch_chunk_from_s3, is_matching_change, }; @@ -14,9 +13,12 @@ use crate::modules::blocks::utils::{ /// another way to get `block` from read-rpc using `block_call` #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] pub async fn block( - data: actix_web::web::Data, + data: Data, request_data: near_jsonrpc::primitives::types::blocks::RpcBlockRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::blocks::RpcBlockResponse, + near_jsonrpc::primitives::types::blocks::RpcBlockError, +> { if let near_primitives::types::BlockReference::Finality( near_primitives::types::Finality::None, ) = &request_data.block_reference @@ -26,7 +28,14 @@ pub async fn block( let block_view = data .near_rpc_client .call(request_data, Some("block")) - .await?; + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::blocks::RpcBlockError::InternalError { + error_message: err.to_string(), + }, + ) + })?; return Ok(near_jsonrpc::primitives::types::blocks::RpcBlockResponse { block_view }); } }; @@ -38,21 +47,24 @@ pub async fn block( pub async fn chunk( data: Data, request_data: near_jsonrpc::primitives::types::chunks::RpcChunkRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::chunks::RpcChunkResponse, + near_jsonrpc::primitives::types::chunks::RpcChunkError, +> { tracing::debug!("`chunk` called with parameters: {:?}", request_data); - let result = fetch_chunk(&data, request_data.chunk_reference.clone()).await; + let chunk_result = fetch_chunk(&data, request_data.chunk_reference.clone()).await; #[cfg(feature = "shadow-data-consistency")] { crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, - &result, + &chunk_result, data.near_rpc_client.clone(), request_data, "chunk", ) .await; } - Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) + chunk_result } /// `EXPERIMENTAL_changes` rpc method implementation @@ -63,17 +75,26 @@ pub async fn chunk( pub async fn changes_in_block_by_type( data: Data, request_data: near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockByTypeRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockResponse, + near_jsonrpc::primitives::types::changes::RpcStateChangesError, +> { if let near_primitives::types::BlockReference::Finality( near_primitives::types::Finality::None, ) = &request_data.block_reference { if crate::metrics::OPTIMISTIC_UPDATING.is_not_working() { // Proxy if the optimistic updating is not working - return Ok(data + return data .near_rpc_client .call(request_data, Some("EXPERIMENTAL_changes")) - .await?); + .await.map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::changes::RpcStateChangesError::InternalError { + error_message: err.to_string(), + }, + ) + }); } }; @@ -88,18 +109,26 @@ pub async fn changes_in_block_by_type( pub async fn changes_in_block( data: Data, request_data: near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockRequest, -) -> Result -{ +) -> Result< + near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockByTypeResponse, + near_jsonrpc::primitives::types::changes::RpcStateChangesError, +> { if let near_primitives::types::BlockReference::Finality( near_primitives::types::Finality::None, ) = &request_data.block_reference { if crate::metrics::OPTIMISTIC_UPDATING.is_not_working() { // Proxy if the optimistic updating is not working - return Ok(data + return data .near_rpc_client .call(request_data, Some("EXPERIMENTAL_changes_in_block")) - .await?); + .await.map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::changes::RpcStateChangesError::InternalError { + error_message: err.to_string(), + }, + ) + }); } }; @@ -110,11 +139,14 @@ pub async fn changes_in_block( #[allow(unused_mut)] #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] async fn block_call( - data: actix_web::web::Data, + data: Data, mut block_request: near_jsonrpc::primitives::types::blocks::RpcBlockRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::blocks::RpcBlockResponse, + near_jsonrpc::primitives::types::blocks::RpcBlockError, +> { tracing::debug!("`block` called with parameters: {:?}", block_request); - let result = match fetch_block(&data, &block_request.block_reference, "block").await { + let block_result = match fetch_block(&data, &block_request.block_reference, "block").await { Ok(block) => { // increase block category metrics crate::metrics::increase_request_category_metrics( @@ -131,7 +163,7 @@ async fn block_call( #[cfg(feature = "shadow-data-consistency")] { - if let Ok(res) = &result { + if let Ok(res) = &block_result { if let near_primitives::types::BlockReference::Finality(_) = block_request.block_reference { @@ -143,7 +175,7 @@ async fn block_call( crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, - &result, + &block_result, data.near_rpc_client.clone(), block_request, "block", @@ -151,7 +183,7 @@ async fn block_call( .await; }; - Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) + block_result } /// fetch changes_in_block from read-rpc @@ -160,15 +192,21 @@ async fn block_call( async fn changes_in_block_call( data: Data, mut params: near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockRequest, -) -> Result -{ +) -> Result< + near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockByTypeResponse, + near_jsonrpc::primitives::types::changes::RpcStateChangesError, +> { 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)?; + .map_err(|err| { + near_jsonrpc::primitives::types::changes::RpcStateChangesError::UnknownBlock { + error_message: err.to_string(), + } + })?; let result = fetch_changes_in_block(&data, cache_block, ¶ms.block_reference).await; #[cfg(feature = "shadow-data-consistency")] @@ -188,7 +226,7 @@ async fn changes_in_block_call( .await; } - Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) + result } /// fetch changes_in_block_by_type from read-rpc @@ -197,11 +235,18 @@ async fn changes_in_block_call( async fn changes_in_block_by_type_call( data: Data, mut params: near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockByTypeRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::changes::RpcStateChangesInBlockResponse, + near_jsonrpc::primitives::types::changes::RpcStateChangesError, +> { let cache_block = fetch_block_from_cache_or_get(&data, ¶ms.block_reference, "EXPERIMENTAL_changes") .await - .map_err(near_jsonrpc::primitives::errors::RpcError::from)?; + .map_err(|err| { + near_jsonrpc::primitives::types::changes::RpcStateChangesError::UnknownBlock { + error_message: err.to_string(), + } + })?; let result = fetch_changes_in_block_by_type( &data, @@ -228,12 +273,12 @@ async fn changes_in_block_by_type_call( .await; } - Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) + result } #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] pub async fn fetch_block( - data: &actix_web::web::Data, + data: &Data, block_reference: &near_primitives::types::BlockReference, method_name: &str, ) -> Result< @@ -311,7 +356,7 @@ pub async fn fetch_block( #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] pub async fn fetch_chunk( - data: &actix_web::web::Data, + data: &Data, chunk_reference: near_jsonrpc::primitives::types::chunks::ChunkReference, ) -> Result< near_jsonrpc::primitives::types::chunks::RpcChunkResponse, diff --git a/rpc-server/src/modules/clients/methods.rs b/rpc-server/src/modules/clients/methods.rs index 5896a5f3..201988be 100644 --- a/rpc-server/src/modules/clients/methods.rs +++ b/rpc-server/src/modules/clients/methods.rs @@ -1,30 +1,41 @@ use actix_web::web::Data; use crate::config::ServerContext; -use crate::errors::RPCError; pub async fn light_client_proof( data: Data, request_data: near_jsonrpc::primitives::types::light_client::RpcLightClientExecutionProofRequest, ) -> Result< near_jsonrpc::primitives::types::light_client::RpcLightClientExecutionProofResponse, - RPCError, + near_jsonrpc::primitives::types::light_client::RpcLightClientProofError, > { - Ok(data + data .near_rpc_client .archival_call(request_data, Some("light_client_proof")) - .await?) + .await.map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::light_client::RpcLightClientProofError::InternalError { + error_message: err.to_string(), + }) + }) } pub async fn next_light_client_block( data: Data, request_data: near_jsonrpc::primitives::types::light_client::RpcLightClientNextBlockRequest, -) -> Result -{ +) -> Result< + near_jsonrpc::primitives::types::light_client::RpcLightClientNextBlockResponse, + near_jsonrpc::primitives::types::light_client::RpcLightClientNextBlockError, +> { match data .near_rpc_client .call(request_data, Some("next_light_client_block")) - .await? + .await.map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::light_client::RpcLightClientNextBlockError::InternalError { + error_message: err.to_string(), + }) + })? { Some(light_client_block) => Ok( near_jsonrpc::primitives::types::light_client::RpcLightClientNextBlockResponse { diff --git a/rpc-server/src/modules/gas/methods.rs b/rpc-server/src/modules/gas/methods.rs index 651fc501..0bc475c8 100644 --- a/rpc-server/src/modules/gas/methods.rs +++ b/rpc-server/src/modules/gas/methods.rs @@ -1,7 +1,6 @@ use actix_web::web::Data; use crate::config::ServerContext; -use crate::errors::RPCError; use crate::modules::blocks::utils::fetch_block_from_cache_or_get; use crate::modules::blocks::CacheBlock; @@ -10,7 +9,10 @@ use crate::modules::blocks::CacheBlock; pub async fn gas_price( data: Data, mut request_data: near_jsonrpc::primitives::types::gas_price::RpcGasPriceRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::gas_price::RpcGasPriceResponse, + near_jsonrpc::primitives::types::gas_price::RpcGasPriceError, +> { tracing::debug!("`gas_price` called with parameters: {:?}", request_data); let block_reference = match request_data.block_id.clone() { Some(block_id) => near_primitives::types::BlockReference::BlockId(block_id), @@ -45,9 +47,7 @@ pub async fn gas_price( .await; }; let gas_price_view = near_primitives::views::GasPriceView { - gas_price: cache_block - .map_err(near_jsonrpc::primitives::errors::RpcError::from)? - .gas_price, + gas_price: cache_block?.gas_price, }; Ok(near_jsonrpc::primitives::types::gas_price::RpcGasPriceResponse { gas_price_view }) } diff --git a/rpc-server/src/modules/network/methods.rs b/rpc-server/src/modules/network/methods.rs index 823e4bcf..3e73e43f 100644 --- a/rpc-server/src/modules/network/methods.rs +++ b/rpc-server/src/modules/network/methods.rs @@ -2,25 +2,42 @@ use actix_web::web::Data; use near_primitives::epoch_manager::{AllEpochConfig, EpochConfig}; use crate::config::ServerContext; -use crate::errors::RPCError; use crate::modules::blocks::utils::fetch_block_from_cache_or_get; use crate::modules::network::get_protocol_version; -pub async fn client_config(_data: Data) -> Result<(), RPCError> { - Err(RPCError::unimplemented_error("client_config")) +pub async fn client_config( + _data: Data, +) -> Result<(), near_jsonrpc::primitives::errors::RpcError> { + let message = "Method `client_config` is not implemented on this type of node. Please send a request to NEAR JSON RPC instead.".to_string(); + Err(near_jsonrpc::primitives::errors::RpcError::new( + 32601, message, None, + )) } -pub async fn maintenance_windows(_data: Data) -> Result<(), RPCError> { - Err(RPCError::unimplemented_error("maintenance_windows")) +pub async fn maintenance_windows( + _data: Data, +) -> Result<(), near_jsonrpc::primitives::errors::RpcError> { + let message = "Method `maintenance_windows` is not implemented on this type of node. Please send a request to NEAR JSON RPC instead.".to_string(); + Err(near_jsonrpc::primitives::errors::RpcError::new( + 32601, message, None, + )) } -pub async fn split_storage_info(_data: Data) -> Result<(), RPCError> { - Err(RPCError::unimplemented_error("split_storage_info")) +pub async fn split_storage_info( + _data: Data, +) -> Result<(), near_jsonrpc::primitives::errors::RpcError> { + let message = "Method `split_storage_info` is not implemented on this type of node. Please send a request to NEAR JSON RPC instead.".to_string(); + Err(near_jsonrpc::primitives::errors::RpcError::new( + 32601, message, None, + )) } pub async fn status( data: Data, -) -> Result { +) -> Result< + near_primitives::views::StatusResponse, + near_jsonrpc::primitives::types::status::RpcStatusError, +> { let final_block = data.blocks_info_by_finality.final_cache_block().await; let validators = data.blocks_info_by_finality.validators().await; let current_validators = validators @@ -79,33 +96,54 @@ pub async fn status( pub async fn health( data: Data, -) -> Result { +) -> Result< + crate::health::RPCHealthStatusResponse, + near_jsonrpc::primitives::types::status::RpcStatusError, +> { Ok(crate::health::RPCHealthStatusResponse::new(&data).await) } pub async fn network_info( data: Data, -) -> Result { - Ok(data - .near_rpc_client +) -> Result< + near_jsonrpc::primitives::types::network_info::RpcNetworkInfoResponse, + near_jsonrpc::primitives::types::network_info::RpcNetworkInfoError, +> { + data.near_rpc_client .call( near_jsonrpc_client::methods::network_info::RpcNetworkInfoRequest, Some("network_info"), ) - .await?) + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::network_info::RpcNetworkInfoError::InternalError { + error_message: err.to_string(), + }, + ) + }) } pub async fn validators( data: Data, request_data: near_jsonrpc::primitives::types::validator::RpcValidatorRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::validator::RpcValidatorResponse, + near_jsonrpc::primitives::types::validator::RpcValidatorError, +> { tracing::debug!("`validators` called with parameters: {:?}", request_data); // Latest epoch validators fetches from the Near RPC node if let near_primitives::types::EpochReference::Latest = &request_data.epoch_reference { - let validator_info = data - .near_rpc_client - .call(request_data, Some("validators")) - .await?; + let validator_info = + data.near_rpc_client + .call(request_data, Some("validators")) + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::validator::RpcValidatorError::InternalError { + error_message: err.to_string(), + }) + })?; return Ok( near_jsonrpc::primitives::types::validator::RpcValidatorResponse { validator_info }, ); @@ -124,7 +162,13 @@ pub async fn validators( let validator_info = data .near_rpc_client .call(request_data, Some("validators")) - .await?; + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::validator::RpcValidatorError::InternalError { + error_message: err.to_string(), + }) + })?; return Ok( near_jsonrpc::primitives::types::validator::RpcValidatorResponse { validator_info }, ); @@ -147,8 +191,7 @@ pub async fn validators( Ok( near_jsonrpc::primitives::types::validator::RpcValidatorResponse { - validator_info: validator_info - .map_err(near_jsonrpc::primitives::errors::RpcError::from)?, + validator_info: validator_info?, }, ) } @@ -156,7 +199,10 @@ pub async fn validators( pub async fn validators_ordered( data: Data, request_data: near_jsonrpc::primitives::types::validator::RpcValidatorsOrderedRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::validator::RpcValidatorsOrderedResponse, + near_jsonrpc::primitives::types::validator::RpcValidatorError, +> { if let Some(block_id) = &request_data.block_id { let block_reference = near_primitives::types::BlockReference::from(block_id.clone()); if let Ok(block) = fetch_block_from_cache_or_get( @@ -178,19 +224,35 @@ pub async fn validators_ordered( Ok(data .near_rpc_client .call(request_data, Some("EXPERIMENTAL_validators_ordered")) - .await?) + .await.map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::validator::RpcValidatorError::InternalError { + error_message: err.to_string(), + }) + })?) } else { // Proxy to archival rpc if the block garbage collected Ok(data .near_rpc_client .archival_call(request_data, Some("EXPERIMENTAL_validators_ordered")) - .await?) + .await.map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::validator::RpcValidatorError::InternalError { + error_message: err.to_string(), + }) + })?) } } else { Ok(data .near_rpc_client .call(request_data, Some("EXPERIMENTAL_validators_ordered")) - .await?) + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::validator::RpcValidatorError::InternalError { + error_message: err.to_string(), + }) + })?) } } else { // increase block category metrics @@ -206,20 +268,30 @@ pub async fn validators_ordered( Ok(data .near_rpc_client .call(request_data, Some("EXPERIMENTAL_validators_ordered")) - .await?) + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::validator::RpcValidatorError::InternalError { + error_message: err.to_string(), + }, + ) + })?) } } pub async fn genesis_config( data: Data, -) -> Result { +) -> Result { Ok(data.genesis_info.genesis_config.clone()) } pub async fn protocol_config( data: Data, request_data: near_jsonrpc::primitives::types::config::RpcProtocolConfigRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::config::RpcProtocolConfigResponse, + near_jsonrpc::primitives::types::config::RpcProtocolConfigError, +> { tracing::debug!( "`EXPERIMENTAL_protocol_config` called with parameters: {:?}", request_data @@ -241,7 +313,7 @@ pub async fn protocol_config( Ok( near_jsonrpc::primitives::types::config::RpcProtocolConfigResponse { - config_view: config_view.map_err(near_jsonrpc::primitives::errors::RpcError::from)?, + config_view: config_view?, }, ) } diff --git a/rpc-server/src/modules/queries/contract_runner/mod.rs b/rpc-server/src/modules/queries/contract_runner/mod.rs index 02eb8cbc..b21062d3 100644 --- a/rpc-server/src/modules/queries/contract_runner/mod.rs +++ b/rpc-server/src/modules/queries/contract_runner/mod.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use near_vm_runner::ContractRuntimeCache; -use crate::errors::FunctionCallError; use crate::modules::blocks::BlocksInfoByFinality; use code_storage::CodeStorage; @@ -65,13 +64,17 @@ pub async fn run_contract( Option, >, prefetch_state_size_limit: u64, -) -> Result { +) -> 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(), - })?; + .map_err( + |_| near_jsonrpc::primitives::types::query::RpcQueryError::UnknownAccount { + requested_account_id: account_id.clone(), + block_height: block.block_height, + block_hash: block.block_hash, + }, + )?; let (epoch_height, validators) = epoch_height_and_validators_with_balances(db_manager, blocks_info_by_finality, block) @@ -127,8 +130,12 @@ pub async fn run_contract( 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(), + .map_err(|_| { + near_jsonrpc::primitives::types::query::RpcQueryError::InvalidAccount { + requested_account_id: account_id.clone(), + block_height: block.block_height, + block_hash: block.block_hash, + } })?; contract_code_cache.put(code_hash, code.data.clone()).await; Contract::new(Some(code.data), code_hash) @@ -157,15 +164,21 @@ pub async fn run_contract( compiled_contract_code_cache, ) .await - .map_err(|e| FunctionCallError::InternalError { - error_message: e.to_string(), - })?; + .map_err( + |e| near_jsonrpc::primitives::types::query::RpcQueryError::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, - }) + Err( + near_jsonrpc::primitives::types::query::RpcQueryError::ContractExecutionError { + vm_error: message, + block_height: block.block_height, + block_hash: block.block_hash, + }, + ) } else { let logs = result.logs; let result = match result.return_data { @@ -181,7 +194,10 @@ 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> { +) -> Result< + (u64, HashMap), + near_jsonrpc::primitives::types::query::RpcQueryError, +> { 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; @@ -190,8 +206,10 @@ async fn epoch_height_and_validators_with_balances( 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(), + .map_err(|_| { + near_jsonrpc::primitives::types::query::RpcQueryError::InternalError { + error_message: "Failed to get epoch info".to_string(), + } })?; ( validators.epoch_height, diff --git a/rpc-server/src/modules/queries/methods.rs b/rpc-server/src/modules/queries/methods.rs index 8b2ee7c0..d309e825 100644 --- a/rpc-server/src/modules/queries/methods.rs +++ b/rpc-server/src/modules/queries/methods.rs @@ -1,7 +1,6 @@ use actix_web::web::Data; use crate::config::ServerContext; -use crate::errors::RPCError; use crate::modules::blocks::utils::fetch_block_from_cache_or_get; use crate::modules::blocks::CacheBlock; @@ -16,7 +15,10 @@ use super::utils::get_state_from_db; pub async fn query( data: Data, request_data: near_jsonrpc::primitives::types::query::RpcQueryRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::query::RpcQueryResponse, + near_jsonrpc::primitives::types::query::RpcQueryError, +> { // When the data check fails, we want to emit the log message and increment the // corresponding metric. Despite the metrics have "proxies" in their names, we // are not proxying the requests anymore and respond with the error to the client. @@ -42,7 +44,14 @@ pub async fn query( Ok(data .near_rpc_client .call(request_data, Some(method_name)) - .await?) + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::query::RpcQueryError::InternalError { + error_message: err.to_string(), + }, + ) + })?) } else { // query_call with optimistic block query_call(&data, request_data, method_name, true).await @@ -60,11 +69,18 @@ async fn query_call( mut query_request: near_jsonrpc::primitives::types::query::RpcQueryRequest, method_name: &str, is_optimistic: bool, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::query::RpcQueryResponse, + near_jsonrpc::primitives::types::query::RpcQueryError, +> { tracing::debug!("`query` call. Params: {:?}", query_request,); let block = fetch_block_from_cache_or_get(data, &query_request.block_reference, method_name) .await - .map_err(near_jsonrpc::primitives::errors::RpcError::from)?; + .map_err( + |_err| near_jsonrpc::primitives::types::query::RpcQueryError::UnknownBlock { + block_reference: query_request.block_reference.clone(), + }, + )?; let result = match &query_request.request { near_primitives::views::QueryRequest::ViewAccount { account_id } => { @@ -96,13 +112,27 @@ async fn query_call( Ok(data .near_rpc_client .call(query_request, Some("query_view_state_proofs")) - .await?) + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::query::RpcQueryError::InternalError { + error_message: err.to_string(), + }, + ) + })?) } else { // Proxy to archival rpc if the block garbage collected Ok(data .near_rpc_client .archival_call(query_request, Some("query_view_state_proofs")) - .await?) + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::query::RpcQueryError::InternalError { + error_message: err.to_string(), + }, + ) + })?) }; } else { view_state(data, block, account_id, prefix, is_optimistic).await @@ -144,7 +174,7 @@ async fn query_call( .await; } - Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) + result } #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] @@ -365,8 +395,7 @@ async fn function_call( maybe_optimistic_data, data.prefetch_state_size_limit, ) - .await - .map_err(|err| err.to_rpc_query_error(block.block_height, block.block_hash))?; + .await?; Ok(near_jsonrpc::primitives::types::query::RpcQueryResponse { kind: near_jsonrpc::primitives::types::query::QueryResponseKind::CallResult( diff --git a/rpc-server/src/modules/receipts/methods.rs b/rpc-server/src/modules/receipts/methods.rs index 2b8951a1..a17b0d17 100644 --- a/rpc-server/src/modules/receipts/methods.rs +++ b/rpc-server/src/modules/receipts/methods.rs @@ -1,5 +1,4 @@ use crate::config::ServerContext; -use crate::errors::RPCError; use crate::modules::transactions::try_get_transaction_details_by_hash; use actix_web::web::Data; @@ -9,15 +8,18 @@ use actix_web::web::Data; pub async fn receipt( data: Data, request_data: near_jsonrpc::primitives::types::receipts::RpcReceiptRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::receipts::RpcReceiptResponse, + near_jsonrpc::primitives::types::receipts::RpcReceiptError, +> { tracing::debug!("`receipt` call. Params: {:?}", request_data); - let result = fetch_receipt(&data, &request_data).await; + let receipt_result = fetch_receipt(&data, &request_data).await; #[cfg(feature = "shadow-data-consistency")] { crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, - &result, + &receipt_result, data.near_rpc_client.clone(), request_data, "EXPERIMENTAL_receipt", @@ -25,7 +27,7 @@ pub async fn receipt( .await; } - Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) + receipt_result } /// Fetches a receipt record by it's ID @@ -33,14 +35,16 @@ pub async fn receipt( pub async fn view_receipt_record( data: Data, request_data: near_jsonrpc::primitives::types::receipts::RpcReceiptRequest, -) -> Result { +) -> Result< + crate::modules::receipts::RpcReceiptRecordResponse, + near_jsonrpc::primitives::types::receipts::RpcReceiptError, +> { tracing::debug!("`view_receipt_record` call. Params: {:?}", request_data); - - let result = fetch_receipt_record(&data, &request_data, "view_receipt_record").await; - - Ok(result - .map_err(near_jsonrpc::primitives::errors::RpcError::from)? - .into()) + Ok( + fetch_receipt_record(&data, &request_data, "view_receipt_record") + .await? + .into(), + ) } #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] diff --git a/rpc-server/src/modules/state/methods.rs b/rpc-server/src/modules/state/methods.rs index ff3dfafa..fb24cd28 100644 --- a/rpc-server/src/modules/state/methods.rs +++ b/rpc-server/src/modules/state/methods.rs @@ -1,7 +1,6 @@ use actix_web::web::Data; 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_from_db_paginated; @@ -9,12 +8,14 @@ use crate::modules::state::utils::get_state_from_db_paginated; pub async fn view_state_paginated( data: Data, request_data: crate::modules::state::RpcViewStatePaginatedRequest, -) -> Result { +) -> Result< + crate::modules::state::RpcViewStatePaginatedResponse, + near_jsonrpc::primitives::errors::RpcError, +> { let block_reference = near_primitives::types::BlockReference::BlockId(request_data.block_id.clone()); - let block = fetch_block_from_cache_or_get(&data, &block_reference, "view_state_paginated") - .await - .map_err(near_jsonrpc::primitives::errors::RpcError::from)?; + let block = + fetch_block_from_cache_or_get(&data, &block_reference, "view_state_paginated").await?; let state_values = get_state_from_db_paginated( &data.db_manager, diff --git a/rpc-server/src/modules/transactions/methods.rs b/rpc-server/src/modules/transactions/methods.rs index 4c954550..ddfa0747 100644 --- a/rpc-server/src/modules/transactions/methods.rs +++ b/rpc-server/src/modules/transactions/methods.rs @@ -4,16 +4,24 @@ use near_primitives::views::FinalExecutionOutcomeViewEnum::{ }; use crate::config::ServerContext; -use crate::errors::RPCError; pub async fn send_tx( data: Data, request_data: near_jsonrpc::primitives::types::transactions::RpcSendTransactionRequest, -) -> Result { - Ok(data - .near_rpc_client +) -> Result< + near_jsonrpc::primitives::types::transactions::RpcTransactionResponse, + near_jsonrpc::primitives::types::transactions::RpcTransactionError, +> { + data.near_rpc_client .call(request_data, Some("send_tx")) - .await?) + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::transactions::RpcTransactionError::InternalError { + debug_info: err.to_string(), + }, + ) + }) } /// Queries status of a transaction by hash and returns the final transaction result. @@ -21,16 +29,19 @@ pub async fn send_tx( pub async fn tx( data: Data, request_data: near_jsonrpc::primitives::types::transactions::RpcTransactionStatusRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::transactions::RpcTransactionResponse, + near_jsonrpc::primitives::types::transactions::RpcTransactionError, +> { tracing::debug!("`tx` call. Params: {:?}", request_data); - let result = tx_status_common(&data, &request_data.transaction_info, false).await; + let tx_result = tx_status_common(&data, &request_data.transaction_info, false).await; #[cfg(feature = "shadow-data-consistency")] { crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, - &result, + &tx_result, data.near_rpc_client.clone(), // Note there is a difference in the implementation of the `tx` method in the `near_jsonrpc_client` // The method is `near_jsonrpc_client::methods::tx::RpcTransactionStatusRequest` in the client @@ -44,8 +55,7 @@ pub async fn tx( ) .await; } - - Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) + tx_result } /// Queries status of a transaction by hash, returning the final transaction result and details of all receipts. @@ -53,16 +63,19 @@ pub async fn tx( pub async fn tx_status( data: Data, request_data: near_jsonrpc::primitives::types::transactions::RpcTransactionStatusRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::transactions::RpcTransactionResponse, + near_jsonrpc::primitives::types::transactions::RpcTransactionError, +> { tracing::debug!("`tx_status` call. Params: {:?}", request_data); - let result = tx_status_common(&data, &request_data.transaction_info, true).await; + let tx_result = tx_status_common(&data, &request_data.transaction_info, true).await; #[cfg(feature = "shadow-data-consistency")] { crate::utils::shadow_compare_results_handler( data.shadow_data_consistency_rate, - &result, + &tx_result, data.near_rpc_client.clone(), // Note there is a difference in the implementation of the `EXPERIMENTAL_tx_status` method in the `near_jsonrpc_client` // The method is `near_jsonrpc_client::methods::EXPERIMENTAL_tx_status` in the client @@ -76,14 +89,14 @@ pub async fn tx_status( .await; } - Ok(result.map_err(near_jsonrpc::primitives::errors::RpcError::from)?) + tx_result } #[cfg_attr(feature = "tracing-instrumentation", tracing::instrument(skip(data)))] pub async fn broadcast_tx_async( data: Data, request_data: near_jsonrpc::primitives::types::transactions::RpcSendTransactionRequest, -) -> Result { +) -> Result { tracing::debug!("`broadcast_tx_async` call. Params: {:?}", request_data); let proxy_params = near_jsonrpc_client::methods::broadcast_tx_async::RpcBroadcastTxAsyncRequest { @@ -95,7 +108,9 @@ pub async fn broadcast_tx_async( .await { Ok(resp) => Ok(resp), - Err(err) => Err(RPCError::internal_error(&err.to_string())), + Err(err) => Err( + near_jsonrpc::primitives::errors::RpcError::new_internal_error(None, err.to_string()), + ), } } @@ -103,7 +118,10 @@ pub async fn broadcast_tx_async( pub async fn broadcast_tx_commit( data: Data, request_data: near_jsonrpc::primitives::types::transactions::RpcSendTransactionRequest, -) -> Result { +) -> Result< + near_jsonrpc::primitives::types::transactions::RpcTransactionResponse, + near_jsonrpc::primitives::types::transactions::RpcTransactionError, +> { tracing::debug!("`broadcast_tx_commit` call. Params: {:?}", request_data); let proxy_params = near_jsonrpc_client::methods::broadcast_tx_commit::RpcBroadcastTxCommitRequest { @@ -112,7 +130,14 @@ pub async fn broadcast_tx_commit( let result = data .near_rpc_client .call(proxy_params, Some("broadcast_tx_commit")) - .await?; + .await + .map_err(|err| { + err.handler_error().cloned().unwrap_or( + near_jsonrpc::primitives::types::transactions::RpcTransactionError::InternalError { + debug_info: err.to_string(), + }, + ) + })?; Ok( near_jsonrpc::primitives::types::transactions::RpcTransactionResponse { final_execution_outcome: Some(FinalExecutionOutcome(result)),