diff --git a/Cargo.lock b/Cargo.lock index 2ecce139..2d318227 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,7 +87,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "220044e6a1bb31ddee4e3db724d29767f352de47445a6cd75e1a173142136c83" dependencies = [ - "nom", + "nom 7.1.3", "vte", ] @@ -221,18 +221,18 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] name = "async-trait" -version = "0.1.85" +version = "0.1.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056" +checksum = "644dd749086bf3771a2fbc5f256fdb982d53f011c7d5d560304eafeecebce79d" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -454,7 +454,7 @@ checksum = "3fa76293b4f7bb636ab88fd78228235b5248b4d05cc589aed610f954af5d7c7a" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -465,9 +465,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" +checksum = "f61dac84819c6588b558454b194026eb1f09c293b9036ae9b159e74e73ab6cf9" [[package]] name = "bzip2" @@ -493,7 +493,7 @@ dependencies = [ [[package]] name = "casper-binary-port" version = "1.0.0" -source = "git+https://github.com/casper-network/casper-node.git?branch=dev#15ef9a9a36ddfe8184d4d22040d6a95db02dd32b" +source = "git+https://github.com/casper-network/casper-node.git?branch=dev#324929ed851ba7a1cda8c768c3292eae8868b625" dependencies = [ "bincode", "bytes", @@ -699,7 +699,7 @@ dependencies = [ [[package]] name = "casper-types" version = "5.0.0" -source = "git+https://github.com/casper-network/casper-node.git?branch=dev#15ef9a9a36ddfe8184d4d22040d6a95db02dd32b" +source = "git+https://github.com/casper-network/casper-node.git?branch=dev#324929ed851ba7a1cda8c768c3292eae8868b625" dependencies = [ "base16", "base64 0.13.1", @@ -742,9 +742,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.10" +version = "1.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229" +checksum = "e4730490333d58093109dc02c23174c3f4d490998c3fed3cc8e82d57afedb9cf" dependencies = [ "jobserver", "libc", @@ -798,7 +798,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -973,7 +973,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -996,7 +996,7 @@ dependencies = [ "ident_case", "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -1007,7 +1007,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -1077,20 +1077,20 @@ checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] name = "derive_more" -version = "0.99.18" +version = "0.99.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +checksum = "3da29a38df43d6f156149c9b43ded5e018ddff2a855cf2cfd62e8cd7d079c69f" dependencies = [ "convert_case", "proc-macro2 1.0.93", "quote 1.0.38", "rustc_version", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -1158,7 +1158,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -1181,9 +1181,9 @@ checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" [[package]] name = "dyn-clone" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" +checksum = "feeef44e73baff3a26d371801df019877a9866a8c493d315ab00177843314f35" [[package]] name = "ecdsa" @@ -1330,7 +1330,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74fef4569247a5f429d9156b9d0a2599914385dd189c539334c625d8099d90ab" dependencies = [ "futures-core", - "nom", + "nom 7.1.3", "pin-project-lite", ] @@ -1556,7 +1556,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -1903,7 +1903,7 @@ checksum = "999ce923619f88194171a67fb3e6d613653b8d4d6078b529b15a765da0edcc17" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -2441,7 +2441,7 @@ dependencies = [ "http 1.2.0", "hyper 1.6.0", "hyper-util", - "rustls 0.23.21", + "rustls 0.23.22", "rustls-pki-types", "tokio", "tokio-rustls", @@ -2611,7 +2611,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -2671,7 +2671,7 @@ checksum = "0122b7114117e64a63ac49f752a5ca4624d534c7b1c7de796ac196381cd2d947" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -2697,11 +2697,11 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "iso8601" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "924e5d73ea28f59011fec52a0d12185d496a9b075d360657aed2a5707f701153" +checksum = "c5c177cff824ab21a6f41079a4c401241c4e8be14f316c4c6b07d5fca351c98d" dependencies = [ - "nom", + "nom 8.0.0", ] [[package]] @@ -3013,7 +3013,7 @@ dependencies = [ "cfg-if", "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -3085,6 +3085,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nom" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3165,7 +3174,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -3252,9 +3261,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.69" +version = "0.10.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e534d133a060a3c19daec1eb3e98ec6f4685978834f2dbadfe2ec215bab64e" +checksum = "61cfb4e166a8bb8c9b55c500bc2308550148ece889be90f609377e58140f42c6" dependencies = [ "bitflags 2.8.0", "cfg-if", @@ -3273,7 +3282,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -3284,9 +3293,9 @@ checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" [[package]] name = "openssl-sys" -version = "0.9.104" +version = "0.9.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" +checksum = "8b22d5b84be05a8d6947c7cb71f7c849aa0f112acd4bf51c2a7c1c988ac0a9dc" dependencies = [ "cc", "libc", @@ -3424,22 +3433,22 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e2ec53ad785f4d35dac0adea7f7dc6f1bb277ad84a680c7afefeae05d1f5916" +checksum = "dfe2e71e1471fe07709406bf725f710b02927c9c54b2b5b2ec0e8087d97c327d" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56a66c0c55993aa927429d0f8a0abfd74f084e4d9c192cffed01e418d83eefb" +checksum = "f6e859e6e5bd50440ab63c47e3ebabc90f26251f7c73c3d3e837b74a1cc3fa67" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -3775,7 +3784,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -3987,7 +3996,7 @@ dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", "rust-embed-utils", - "syn 2.0.96", + "syn 2.0.98", "walkdir", ] @@ -4042,9 +4051,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.21" +version = "0.23.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f287924602bf649d949c63dc8ac8b235fa5387d394020705b80c4eb597ce5b8" +checksum = "9fb9263ab4eb695e42321db096e3b8fbd715a59b154d5c88d82db2175b681ba7" dependencies = [ "once_cell", "rustls-pki-types", @@ -4162,7 +4171,7 @@ dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", "serde_derive_internals", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -4207,7 +4216,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", "thiserror 1.0.69", ] @@ -4289,7 +4298,7 @@ checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -4300,7 +4309,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -4456,7 +4465,7 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bba3a93db0cc4f7bdece8bb09e77e2e785c20bfebf79eb8340ed80708048790" dependencies = [ - "nom", + "nom 7.1.3", "unicode_categories", ] @@ -4734,7 +4743,7 @@ dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", "rustversion", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -4747,7 +4756,7 @@ dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", "rustversion", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -4780,9 +4789,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.96" +version = "2.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" +checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", @@ -4812,7 +4821,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -4939,7 +4948,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -4950,7 +4959,7 @@ checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -5067,7 +5076,7 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -5086,7 +5095,7 @@ version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" dependencies = [ - "rustls 0.23.21", + "rustls 0.23.22", "tokio", ] @@ -5213,7 +5222,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -5454,7 +5463,7 @@ dependencies = [ "proc-macro-error", "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -5549,9 +5558,9 @@ dependencies = [ [[package]] name = "wait-timeout" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" dependencies = [ "libc", ] @@ -5648,7 +5657,7 @@ dependencies = [ "log", "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", "wasm-bindgen-shared", ] @@ -5683,7 +5692,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5953,9 +5962,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.25" +version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad699df48212c6cc6eb4435f35500ac6fd3b9913324f938aea302022ce19d310" +checksum = "1e90edd2ac1aa278a5c4599b1d89cf03074b610800f866d4026dc199d7929a28" dependencies = [ "memchr", ] @@ -6037,7 +6046,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", "synstructure", ] @@ -6059,7 +6068,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] @@ -6079,7 +6088,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", "synstructure", ] @@ -6108,7 +6117,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2 1.0.93", "quote 1.0.38", - "syn 2.0.96", + "syn 2.0.98", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a42dbc70..c4bcbd53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,4 +31,4 @@ toml = "0.5.8" tracing = { version = "0", default-features = false } tracing-subscriber = "0" serde = { version = "1", default-features = false } -jsonschema = "0.26.2" \ No newline at end of file +jsonschema = "0.26.2" diff --git a/rpc_sidecar/src/lib.rs b/rpc_sidecar/src/lib.rs index 2909f3e4..86f25209 100644 --- a/rpc_sidecar/src/lib.rs +++ b/rpc_sidecar/src/lib.rs @@ -8,7 +8,7 @@ mod speculative_exec_server; pub mod testing; use anyhow::Error; -use casper_binary_port::{BinaryRequest, BinaryRequestHeader}; +use casper_binary_port::{Command, CommandHeader}; use casper_types::bytesrepr::ToBytes; use casper_types::{bytesrepr, ProtocolVersion}; pub use config::{FieldParseError, NodeClientConfig, RpcConfig, RpcServerConfig}; @@ -25,7 +25,6 @@ pub use speculative_exec_config::Config as SpeculativeExecConfig; pub use speculative_exec_server::run as run_speculative_exec_server; use std::{net::SocketAddr, process::ExitCode, sync::Arc}; use tracing::warn; - /// Minimal casper protocol version supported by this sidecar. pub const SUPPORTED_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::from_parts(2, 0, 0); @@ -108,8 +107,8 @@ fn start_listening(address: &SocketAddr) -> anyhow::Result Result, bytesrepr::Error> { - let header = BinaryRequestHeader::new(SUPPORTED_PROTOCOL_VERSION, req.tag(), id); +fn encode_request(req: &Command, id: u16) -> Result, bytesrepr::Error> { + let header = CommandHeader::new(req.tag(), id); let mut bytes = Vec::with_capacity(header.serialized_length() + req.serialized_length()); header.write_bytes(&mut bytes)?; req.write_bytes(&mut bytes)?; diff --git a/rpc_sidecar/src/node_client.rs b/rpc_sidecar/src/node_client.rs index fab2492e..86640a06 100644 --- a/rpc_sidecar/src/node_client.rs +++ b/rpc_sidecar/src/node_client.rs @@ -1,6 +1,4 @@ -use crate::{ - config::ExponentialBackoffConfig, encode_request, NodeClientConfig, SUPPORTED_PROTOCOL_VERSION, -}; +use crate::{config::ExponentialBackoffConfig, encode_request, NodeClientConfig}; use anyhow::Error as AnyhowError; use async_trait::async_trait; use futures::{Future, SinkExt, StreamExt}; @@ -21,21 +19,21 @@ use tokio_util::codec::Framed; use casper_binary_port::{ AccountInformation, AddressableEntityInformation, BalanceResponse, BinaryMessage, - BinaryMessageCodec, BinaryRequest, BinaryResponse, BinaryResponseAndRequest, + BinaryMessageCodec, BinaryResponse, BinaryResponseAndRequest, Command, CommandHeader, ConsensusValidatorChanges, ContractInformation, DictionaryItemIdentifier, DictionaryQueryResult, EntityIdentifier, EraIdentifier, ErrorCode, GetRequest, GetTrieFullResult, GlobalStateEntityQualifier, GlobalStateQueryResult, GlobalStateRequest, - InformationRequest, KeyPrefix, NodeStatus, PackageIdentifier, PayloadEntity, PurseIdentifier, - RecordId, ResponseType, RewardResponse, SpeculativeExecutionResult, - TransactionWithExecutionInfo, ValueWithProof, + InformationRequest, InformationRequestTag, KeyPrefix, NodeStatus, PackageIdentifier, + PayloadEntity, PurseIdentifier, RecordId, ResponseType, RewardResponse, + SpeculativeExecutionResult, TransactionWithExecutionInfo, ValueWithProof, }; use casper_types::{ bytesrepr::{self, FromBytes, ToBytes}, contracts::ContractPackage, system::auction::DelegatorKind, AvailableBlockRange, BlockHash, BlockHeader, BlockIdentifier, BlockWithSignatures, - ChainspecRawBytes, Digest, GlobalStateIdentifier, Key, KeyTag, Package, Peers, ProtocolVersion, - PublicKey, StoredValue, Transaction, TransactionHash, Transfer, + ChainspecRawBytes, Digest, GlobalStateIdentifier, Key, KeyTag, Package, Peers, PublicKey, + StoredValue, Transaction, TransactionHash, Transfer, }; use std::{ fmt::{self, Display, Formatter}, @@ -55,7 +53,7 @@ const INITIAL_REQUEST_ID: u16 = 1; #[async_trait] pub trait NodeClient: Send + Sync { - async fn send_request(&self, req: BinaryRequest) -> Result; + async fn send_request(&self, req: Command) -> Result; async fn read_record( &self, @@ -66,12 +64,12 @@ pub trait NodeClient: Send + Sync { record_type_tag: record_id.into(), key: key.to_vec(), }; - self.send_request(BinaryRequest::Get(get)).await + self.send_request(Command::Get(get)).await } async fn read_info(&self, req: InformationRequest) -> Result { let get = req.try_into().expect("should always be able to convert"); - self.send_request(BinaryRequest::Get(get)).await + self.send_request(Command::Get(get)).await } async fn query_global_state( @@ -85,7 +83,7 @@ pub trait NodeClient: Send + Sync { GlobalStateEntityQualifier::Item { base_key, path }, ); let resp = self - .send_request(BinaryRequest::Get(GetRequest::State(Box::new(req)))) + .send_request(Command::Get(GetRequest::State(Box::new(req)))) .await?; parse_response::(&resp.into()) } @@ -100,7 +98,7 @@ pub trait NodeClient: Send + Sync { GlobalStateEntityQualifier::AllItems { key_tag }, ); let resp = self - .send_request(BinaryRequest::Get(GetRequest::State(Box::new(get)))) + .send_request(Command::Get(GetRequest::State(Box::new(get)))) .await?; parse_response::>(&resp.into())?.ok_or(Error::EmptyEnvelope) } @@ -115,7 +113,7 @@ pub trait NodeClient: Send + Sync { GlobalStateEntityQualifier::ItemsByPrefix { key_prefix }, ); let resp = self - .send_request(BinaryRequest::Get(GetRequest::State(Box::new(get)))) + .send_request(Command::Get(GetRequest::State(Box::new(get)))) .await?; parse_response::>(&resp.into())?.ok_or(Error::EmptyEnvelope) } @@ -130,14 +128,14 @@ pub trait NodeClient: Send + Sync { GlobalStateEntityQualifier::Balance { purse_identifier }, ); let resp = self - .send_request(BinaryRequest::Get(GetRequest::State(Box::new(get)))) + .send_request(Command::Get(GetRequest::State(Box::new(get)))) .await?; parse_response::(&resp.into())?.ok_or(Error::EmptyEnvelope) } async fn read_trie_bytes(&self, trie_key: Digest) -> Result>, Error> { let resp = self - .send_request(BinaryRequest::Get(GetRequest::Trie { trie_key })) + .send_request(Command::Get(GetRequest::Trie { trie_key })) .await?; let res = parse_response::(&resp.into())?.ok_or(Error::EmptyEnvelope)?; Ok(res.into_inner().map(>::from)) @@ -153,13 +151,13 @@ pub trait NodeClient: Send + Sync { GlobalStateEntityQualifier::DictionaryItem { identifier }, ); let resp = self - .send_request(BinaryRequest::Get(GetRequest::State(Box::new(get)))) + .send_request(Command::Get(GetRequest::State(Box::new(get)))) .await?; parse_response::(&resp.into()) } async fn try_accept_transaction(&self, transaction: Transaction) -> Result<(), Error> { - let request = BinaryRequest::TryAcceptTransaction { transaction }; + let request = Command::TryAcceptTransaction { transaction }; let response = self.send_request(request).await?; if response.is_success() { @@ -173,7 +171,7 @@ pub trait NodeClient: Send + Sync { &self, transaction: Transaction, ) -> Result { - let request = BinaryRequest::TrySpeculativeExec { transaction }; + let request = Command::TrySpeculativeExec { transaction }; let resp = self.send_request(request).await?; parse_response::(&resp.into())?.ok_or(Error::EmptyEnvelope) } @@ -731,30 +729,26 @@ pub enum Error { UnsupportedRewardsV1Request, #[error("purse was not found for given identifier")] PurseNotFound, - #[error("received a response with an unsupported protocol version: {0}")] - UnsupportedProtocolVersion(ProtocolVersion), #[error("received an unexpected node error: {message} ({code})")] UnexpectedNodeError { message: String, code: u16 }, #[error("binary protocol version mismatch")] - BinaryProtocolVersionMismatch, + CommandHeaderVersionMismatch, #[error("request was throttled by the node")] RequestThrottled, #[error("malformed information request")] MalformedInformationRequest, - #[error("malformed version bytes in header of binary request")] - MalformedBinaryVersion, + #[error("malformed version bytes in command header")] + TooLittleBytesForRequestHeaderVersion, #[error("malformed protocol version")] - MalformedProtocolVersion, + MalformedCommandHeaderVersion, #[error("malformed transfer record key")] TransferRecordMalformedKey, - #[error("malformed header of binary request")] - MalformedBinaryRequestHeader, - #[error("malformed binary request")] - MalformedBinaryRequest, + #[error("malformed command header")] + MalformedCommandHeader, + #[error("malformed command")] + MalformedCommand, #[error("not found")] NotFound, - #[error("header has unsupported protocol version")] - HeaderHasUnsupportedProtocolVersion, #[error("node reported internal error")] InternalNodeError, #[error("bad request")] @@ -782,7 +776,7 @@ impl Error { Ok(ErrorCode::SwitchBlockNotFound) => Self::SwitchBlockNotFound, Ok(ErrorCode::SwitchBlockParentNotFound) => Self::SwitchBlockParentNotFound, Ok(ErrorCode::UnsupportedRewardsV1Request) => Self::UnsupportedRewardsV1Request, - Ok(ErrorCode::BinaryProtocolVersionMismatch) => Self::BinaryProtocolVersionMismatch, + Ok(ErrorCode::CommandHeaderVersionMismatch) => Self::CommandHeaderVersionMismatch, Ok(ErrorCode::PurseNotFound) => Self::PurseNotFound, Ok( err @ (ErrorCode::InvalidDeployChainName @@ -868,16 +862,17 @@ impl Error { ) => Self::InvalidTransaction(InvalidTransactionOrDeploy::from(err)), Ok(ErrorCode::RequestThrottled) => Self::RequestThrottled, Ok(ErrorCode::MalformedInformationRequest) => Self::MalformedInformationRequest, - Ok(ErrorCode::MalformedBinaryVersion) => Self::MalformedBinaryVersion, - Ok(ErrorCode::MalformedProtocolVersion) => Self::MalformedProtocolVersion, + Ok(ErrorCode::TooLittleBytesForRequestHeaderVersion) => { + Self::TooLittleBytesForRequestHeaderVersion + } + Ok(ErrorCode::MalformedCommandHeaderVersion) => Self::MalformedCommandHeaderVersion, Ok(ErrorCode::TransferRecordMalformedKey) => Self::TransferRecordMalformedKey, - Ok(ErrorCode::MalformedBinaryRequestHeader) => Self::MalformedBinaryRequestHeader, - Ok(ErrorCode::MalformedBinaryRequest) => Self::MalformedBinaryRequest, + Ok(ErrorCode::MalformedCommandHeader) => Self::MalformedCommandHeader, + Ok(ErrorCode::MalformedCommand) => Self::MalformedCommand, Ok(err @ (ErrorCode::WasmPreprocessing | ErrorCode::InvalidItemVariant)) => { Self::SpecExecutionFailed(err.to_string()) } Ok(ErrorCode::NotFound) => Self::NotFound, - Ok(ErrorCode::UnsupportedProtocolVersion) => Self::HeaderHasUnsupportedProtocolVersion, Ok(ErrorCode::InternalError) => Self::InternalNodeError, Ok(ErrorCode::BadRequest) => Self::BadRequest, Ok(ErrorCode::UnsupportedRequest) => Self::UnsupportedRequest, @@ -901,7 +896,6 @@ impl Error { } struct Reconnect; -struct Shutdown; struct Notify { inner: tokio::sync::Notify, @@ -928,7 +922,6 @@ impl Notify { pub struct FramedNodeClient { client: Arc>>, reconnect: Arc>, - shutdown: Arc>, config: NodeClientConfig, current_request_id: Arc, } @@ -955,20 +948,14 @@ impl FramedNodeClient { .await?, )); - let shutdown = Notify::::new(); let reconnect = Notify::::new(); - let reconnect_loop = Self::reconnect_loop( - config.clone(), - Arc::clone(&stream), - Arc::clone(&shutdown), - Arc::clone(&reconnect), - ); + let reconnect_loop = + Self::reconnect_loop(config.clone(), Arc::clone(&stream), Arc::clone(&reconnect)); let keepalive_timeout = Duration::from_millis(config.keepalive_timeout_ms); let node_client = Arc::new(Self { client: Arc::clone(&stream), reconnect, - shutdown, config, current_request_id: AtomicU16::new(INITIAL_REQUEST_ID).into(), }); @@ -994,7 +981,6 @@ impl FramedNodeClient { async fn reconnect_loop( config: NodeClientConfig, client: Arc>>, - shutdown: Arc>, reconnect: Arc>, ) -> Result<(), AnyhowError> { loop { @@ -1004,10 +990,6 @@ impl FramedNodeClient { let new_client = Self::reconnect(&config.clone()).await?; *lock = new_client; }, - _ = shutdown.notified() => { - info!("node client shutdown has been requested"); - return Ok(()) - } } } } @@ -1018,13 +1000,18 @@ impl FramedNodeClient { ) -> Result<(), AnyhowError> { loop { tokio::time::sleep(keepalive_timeout).await; - client.send_request(BinaryRequest::KeepAliveRequest).await?; + client + .send_request(Command::Get(GetRequest::Information { + info_type_tag: InformationRequestTag::ProtocolVersion.into(), + key: vec![], + })) + .await?; } } async fn send_request_internal( &self, - req: &BinaryRequest, + req: &Command, client: &mut RwLockWriteGuard<'_, Framed>, ) -> Result { let (request_id, payload) = self.generate_payload(req); @@ -1065,7 +1052,7 @@ impl FramedNodeClient { ); Error::EnvelopeDeserialization })?; - match validate_response(resp, request_id, &self.shutdown) { + match validate_response(resp, request_id) { Ok(response) => return Ok(response), Err(err) if matches!(err, Error::RequestResponseIdMismatch { expected, got } if expected > got) => { @@ -1090,7 +1077,7 @@ impl FramedNodeClient { }) } - fn generate_payload(&self, req: &BinaryRequest) -> (u16, BinaryMessage) { + fn generate_payload(&self, req: &Command) -> (u16, BinaryMessage) { let next_id = self.next_id(); ( next_id, @@ -1162,7 +1149,7 @@ impl FramedNodeClient { #[async_trait] impl NodeClient for FramedNodeClient { - async fn send_request(&self, req: BinaryRequest) -> Result { + async fn send_request(&self, req: Command) -> Result { let mut client = match tokio::time::timeout( Duration::from_secs(self.config.client_access_timeout_secs), self.client.write(), @@ -1244,23 +1231,61 @@ pub enum PackageResponse { fn validate_response( resp: BinaryResponseAndRequest, expected_id: u16, - shutdown: &Notify, ) -> Result { - let original_id = resp.original_request_id(); + let original_id = match try_parse_request_id(resp.request()) { + Ok(id) => id, + Err(e) => { + error!("Error when decoding original_id: {}", e); + 0 + } + }; if original_id != expected_id { return Err(Error::RequestResponseIdMismatch { expected: expected_id, got: original_id, }); } + Ok(resp) +} - let version = resp.response().protocol_version(); - if version.is_compatible_with(&SUPPORTED_PROTOCOL_VERSION) { - Ok(resp) - } else { - info!("received a response with incompatible major version from the node {version}, shutting down"); - shutdown.notify_one(); - Err(Error::UnsupportedProtocolVersion(version)) +fn try_parse_request_id(request: &[u8]) -> Result { + if request.len() < 4 { + anyhow::bail!( + "Node responded with request that doesn't have enough bytes to read payload length" + ) + } + let (payload_length, remainder) = + u32::from_bytes(request).map_err(|e| anyhow::Error::msg(e.to_string()))?; + if payload_length != remainder.len() as u32 { + anyhow::bail!("Node responded with request that has a mismatch in declared bytes vs the payload length") + } + let (header, _) = extract_header(remainder)?; + Ok(header.id()) +} + +fn extract_header(payload: &[u8]) -> Result<(CommandHeader, &[u8]), anyhow::Error> { + const BINARY_VERSION_LENGTH_BYTES: usize = std::mem::size_of::(); + + if payload.len() < BINARY_VERSION_LENGTH_BYTES { + anyhow::bail!("Not enough bytes to read version of the command header"); + } + + let binary_protocol_version = match u16::from_bytes(payload) { + Ok((binary_protocol_version, _)) => binary_protocol_version, + Err(_) => { + anyhow::bail!("Could not read header version from request"); + } + }; + + if binary_protocol_version != CommandHeader::HEADER_VERSION { + anyhow::bail!("Header version does not meet expectation"); + } + + match CommandHeader::from_bytes(payload) { + Ok((header, remainder)) => Ok((header, remainder)), + Err(error) => { + anyhow::bail!("Malformed CommandHeader definition: {}", error); + } } } @@ -1345,95 +1370,11 @@ mod tests { }; use super::*; - use casper_binary_port::{BinaryRequestHeader, ReactorStateName}; + use casper_binary_port::{CommandHeader, ReactorStateName}; use casper_types::testing::TestRng; - use casper_types::{BlockSynchronizerStatus, CLValue, SemVer, TimeDiff, Timestamp}; - use futures::FutureExt; + use casper_types::{BlockSynchronizerStatus, CLValue, ProtocolVersion, TimeDiff, Timestamp}; use tokio::time::sleep; - #[tokio::test] - async fn should_reject_bad_major_version() { - let notify = Notify::::new(); - let bad_version = ProtocolVersion::from_parts(10, 0, 0); - - let request = get_dummy_request_payload(None); - - let result = validate_response( - BinaryResponseAndRequest::new( - BinaryResponse::from_value(AvailableBlockRange::RANGE_0_0, bad_version), - &request, - 0, - ), - 0, - ¬ify, - ); - - assert_eq!(result, Err(Error::UnsupportedProtocolVersion(bad_version))); - assert_eq!(notify.notified().now_or_never(), Some(())) - } - - #[tokio::test] - async fn should_accept_different_minor_version() { - let notify = Notify::::new(); - let version = ProtocolVersion::new(SemVer { - minor: SUPPORTED_PROTOCOL_VERSION.value().minor + 1, - ..SUPPORTED_PROTOCOL_VERSION.value() - }); - - let request = get_dummy_request_payload(None); - - let result = validate_response( - BinaryResponseAndRequest::new( - BinaryResponse::from_value(AvailableBlockRange::RANGE_0_0, version), - &request, - 0, - ), - 0, - ¬ify, - ); - - assert_eq!( - result, - Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(AvailableBlockRange::RANGE_0_0, version), - &request, - 0 - )) - ); - assert_eq!(notify.notified().now_or_never(), None) - } - - #[tokio::test] - async fn should_accept_different_patch_version() { - let notify = Notify::::new(); - let version = ProtocolVersion::new(SemVer { - patch: SUPPORTED_PROTOCOL_VERSION.value().patch + 1, - ..SUPPORTED_PROTOCOL_VERSION.value() - }); - - let request = get_dummy_request_payload(None); - - let result = validate_response( - BinaryResponseAndRequest::new( - BinaryResponse::from_value(AvailableBlockRange::RANGE_0_0, version), - &request, - 0, - ), - 0, - ¬ify, - ); - - assert_eq!( - result, - Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(AvailableBlockRange::RANGE_0_0, version), - &request, - 0 - )) - ); - assert_eq!(notify.notified().now_or_never(), None) - } - #[tokio::test] async fn given_client_and_no_node_should_fail_after_tries() { let config = NodeClientConfig::new_with_port_and_retries(1111, 2); @@ -1515,7 +1456,7 @@ mod tests { block_sync: BlockSynchronizerStatus::random(&mut rng), latest_switch_block_hash: None, }; - let response = BinaryResponse::from_value(value, protocol_version); + let response = BinaryResponse::from_value(value); // setup mock binary port with node status response let port = get_port(); @@ -1641,7 +1582,7 @@ mod tests { let generated_ids: Vec<_> = (INITIAL_REQUEST_ID..INITIAL_REQUEST_ID + 10) .map(|_| { let (_, binary_message) = c.generate_payload(&get_dummy_request()); - let header = BinaryRequestHeader::from_bytes(binary_message.payload()) + let header = CommandHeader::from_bytes(binary_message.payload()) .unwrap() .0; header.id() @@ -1656,16 +1597,14 @@ mod tests { #[test] fn should_reject_mismatched_request_id() { - let notify = Notify::::new(); - let expected_id = 1; let actual_id = 2; let req = get_dummy_request_payload(Some(actual_id)); - let resp = BinaryResponse::new_empty(ProtocolVersion::V2_0_0); - let resp_and_req = BinaryResponseAndRequest::new(resp, &req, actual_id); + let resp = BinaryResponse::new_empty(); + let resp_and_req = BinaryResponseAndRequest::new(resp, req); - let result = validate_response(resp_and_req, expected_id, ¬ify); + let result = validate_response(resp_and_req, expected_id); assert!(matches!( result, Err(Error::RequestResponseIdMismatch { expected, got }) if expected == 1 && got == 2 @@ -1675,10 +1614,10 @@ mod tests { let actual_id = 1; let req = get_dummy_request_payload(Some(actual_id)); - let resp = BinaryResponse::new_empty(ProtocolVersion::V2_0_0); - let resp_and_req = BinaryResponseAndRequest::new(resp, &req, actual_id); + let resp = BinaryResponse::new_empty(); + let resp_and_req = BinaryResponseAndRequest::new(resp, req); - let result = validate_response(resp_and_req, expected_id, ¬ify); + let result = validate_response(resp_and_req, expected_id); assert!(matches!( result, Err(Error::RequestResponseIdMismatch { expected, got }) if expected == 2 && got == 1 @@ -1687,16 +1626,14 @@ mod tests { #[test] fn should_accept_matching_request_id() { - let notify = Notify::::new(); - let expected_id = 1; let actual_id = 1; let req = get_dummy_request_payload(Some(actual_id)); - let resp = BinaryResponse::new_empty(ProtocolVersion::V2_0_0); - let resp_and_req = BinaryResponseAndRequest::new(resp, &req, actual_id); + let resp = BinaryResponse::new_empty(); + let resp_and_req = BinaryResponseAndRequest::new(resp, req); - let result = validate_response(resp_and_req, expected_id, ¬ify); + let result = validate_response(resp_and_req, expected_id); dbg!(&result); assert!(result.is_ok()) } @@ -1822,33 +1759,29 @@ mod tests { Error::MalformedInformationRequest )); assert!(matches!( - Error::from_error_code(ErrorCode::MalformedBinaryVersion as u16), - Error::MalformedBinaryVersion + Error::from_error_code(ErrorCode::TooLittleBytesForRequestHeaderVersion as u16), + Error::TooLittleBytesForRequestHeaderVersion )); assert!(matches!( - Error::from_error_code(ErrorCode::MalformedProtocolVersion as u16), - Error::MalformedProtocolVersion + Error::from_error_code(ErrorCode::MalformedCommandHeaderVersion as u16), + Error::MalformedCommandHeaderVersion )); assert!(matches!( Error::from_error_code(ErrorCode::TransferRecordMalformedKey as u16), Error::TransferRecordMalformedKey )); assert!(matches!( - Error::from_error_code(ErrorCode::MalformedBinaryRequestHeader as u16), - Error::MalformedBinaryRequestHeader + Error::from_error_code(ErrorCode::MalformedCommandHeader as u16), + Error::MalformedCommandHeader )); assert!(matches!( - Error::from_error_code(ErrorCode::MalformedBinaryRequest as u16), - Error::MalformedBinaryRequest + Error::from_error_code(ErrorCode::MalformedCommand as u16), + Error::MalformedCommand )); assert!(matches!( Error::from_error_code(ErrorCode::NotFound as u16), Error::NotFound )); - assert!(matches!( - Error::from_error_code(ErrorCode::UnsupportedProtocolVersion as u16), - Error::HeaderHasUnsupportedProtocolVersion - )); assert!(matches!( Error::from_error_code(ErrorCode::InternalError as u16), Error::InternalNodeError diff --git a/rpc_sidecar/src/rpcs/account.rs b/rpc_sidecar/src/rpcs/account.rs index bc175457..f143e29e 100644 --- a/rpc_sidecar/src/rpcs/account.rs +++ b/rpc_sidecar/src/rpcs/account.rs @@ -148,12 +148,12 @@ impl RpcWithParams for PutTransaction { #[cfg(test)] mod tests { use casper_binary_port::{ - BinaryRequest, BinaryResponse, BinaryResponseAndRequest, ErrorCode as BinaryPortErrorCode, + BinaryResponse, BinaryResponseAndRequest, Command, ErrorCode as BinaryPortErrorCode, }; - use casper_types::testing::TestRng; + use casper_types::{bytesrepr::Bytes, testing::TestRng}; use pretty_assertions::assert_eq; - use crate::{rpcs::ErrorCode, SUPPORTED_PROTOCOL_VERSION}; + use crate::rpcs::ErrorCode; use super::*; @@ -165,16 +165,13 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::TryAcceptTransaction { .. } => { - Ok(BinaryResponseAndRequest::new( - BinaryResponse::new_empty(SUPPORTED_PROTOCOL_VERSION), - &[], - 0, - )) - } + Command::TryAcceptTransaction { .. } => Ok(BinaryResponseAndRequest::new( + BinaryResponse::new_empty(), + Bytes::from(vec![]), + )), _ => unimplemented!(), } } @@ -207,16 +204,13 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::TryAcceptTransaction { .. } => { - Ok(BinaryResponseAndRequest::new( - BinaryResponse::new_empty(SUPPORTED_PROTOCOL_VERSION), - &[], - 0, - )) - } + Command::TryAcceptTransaction { .. } => Ok(BinaryResponseAndRequest::new( + BinaryResponse::new_empty(), + Bytes::from(vec![]), + )), _ => unimplemented!(), } } @@ -249,19 +243,13 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::TryAcceptTransaction { .. } => { - Ok(BinaryResponseAndRequest::new( - BinaryResponse::new_error( - BinaryPortErrorCode::InvalidTransactionBodyHash, - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, - )) - } + Command::TryAcceptTransaction { .. } => Ok(BinaryResponseAndRequest::new( + BinaryResponse::new_error(BinaryPortErrorCode::InvalidTransactionBodyHash), + Bytes::from(vec![]), + )), _ => unimplemented!(), } } diff --git a/rpc_sidecar/src/rpcs/chain.rs b/rpc_sidecar/src/rpcs/chain.rs index f2356370..2c1ab34b 100644 --- a/rpc_sidecar/src/rpcs/chain.rs +++ b/rpc_sidecar/src/rpcs/chain.rs @@ -402,13 +402,13 @@ async fn get_era_summary_by_block( mod tests { use std::convert::TryFrom; - use crate::{rpcs::test_utils::BinaryPortMock, ClientError, SUPPORTED_PROTOCOL_VERSION}; + use crate::{rpcs::test_utils::BinaryPortMock, ClientError}; use casper_binary_port::{ - BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest, - GlobalStateEntityQualifier, GlobalStateQueryResult, InformationRequest, - InformationRequestTag, RecordId, + BinaryResponse, BinaryResponseAndRequest, Command, GetRequest, GlobalStateEntityQualifier, + GlobalStateQueryResult, InformationRequest, InformationRequestTag, RecordId, }; use casper_types::{ + bytesrepr::Bytes, system::auction::{DelegatorKind, EraInfo, SeigniorageAllocation}, testing::TestRng, AsymmetricType, Block, BlockSignaturesV1, BlockSignaturesV2, BlockWithSignatures, @@ -731,39 +731,33 @@ mod tests { impl NodeClient for ValidBlockMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::BlockWithSignatures) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(self.block.clone(), SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(self.block.clone()), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::BlockHeader) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - self.block.block().clone_header(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(self.block.block().clone_header()), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::Record { + Command::Get(GetRequest::Record { record_type_tag, .. }) if RecordId::try_from(record_type_tag) == Ok(RecordId::Transfer) => { Ok(BinaryResponseAndRequest::new_legacy_test_response( RecordId::Transfer, &self.transfers, - SUPPORTED_PROTOCOL_VERSION, )) } req => unimplemented!("unexpected request: {:?}", req), @@ -780,7 +774,7 @@ mod tests { impl NodeClient for ValidEraSummaryMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { let expected_tag = if self.expect_no_block_identifier { InformationRequestTag::LatestSwitchBlockHeader @@ -788,19 +782,15 @@ mod tests { InformationRequestTag::BlockHeader }; match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(expected_tag) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - self.block.clone_header(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(self.block.clone_header()), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { @@ -810,15 +800,11 @@ mod tests { ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - GlobalStateQueryResult::new( - StoredValue::EraInfo(EraInfo::new()), - vec![], - ), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(GlobalStateQueryResult::new( + StoredValue::EraInfo(EraInfo::new()), + vec![], + )), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), diff --git a/rpc_sidecar/src/rpcs/info.rs b/rpc_sidecar/src/rpcs/info.rs index bd623070..d7894da1 100644 --- a/rpc_sidecar/src/rpcs/info.rs +++ b/rpc_sidecar/src/rpcs/info.rs @@ -625,13 +625,13 @@ fn version_string() -> String { mod tests { use std::convert::TryFrom; - use crate::{rpcs::ErrorCode, ClientError, SUPPORTED_PROTOCOL_VERSION}; + use crate::{rpcs::ErrorCode, ClientError}; use casper_binary_port::{ - BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest, InformationRequest, + BinaryResponse, BinaryResponseAndRequest, Command, GetRequest, InformationRequest, InformationRequestTag, RewardResponse, TransactionWithExecutionInfo, }; use casper_types::{ - bytesrepr::{FromBytes, ToBytes}, + bytesrepr::{Bytes, FromBytes, ToBytes}, testing::TestRng, BlockHash, TransactionV1, }; @@ -874,10 +874,10 @@ mod tests { impl NodeClient for ValidTransactionMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, key }) + Command::Get(GetRequest::Information { info_type_tag, key }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::Transaction) => { @@ -895,9 +895,8 @@ mod tests { TransactionWithExecutionInfo::from_bytes(&self.transaction_bytes) .expect("should deserialize transaction"); Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(transaction, SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(transaction), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -916,10 +915,10 @@ mod tests { impl NodeClient for RewardMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::Reward) => { @@ -930,9 +929,8 @@ mod tests { self.switch_block_hash, ); Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(resp, SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(resp), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), diff --git a/rpc_sidecar/src/rpcs/speculative_exec.rs b/rpc_sidecar/src/rpcs/speculative_exec.rs index 919637ae..be7cb4b1 100644 --- a/rpc_sidecar/src/rpcs/speculative_exec.rs +++ b/rpc_sidecar/src/rpcs/speculative_exec.rs @@ -170,13 +170,13 @@ mod tests { use std::convert::TryFrom; use casper_binary_port::{ - BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest, InformationRequestTag, + BinaryResponse, BinaryResponseAndRequest, Command, GetRequest, InformationRequestTag, SpeculativeExecutionResult, }; - use casper_types::testing::TestRng; + use casper_types::{bytesrepr::Bytes, testing::TestRng}; use pretty_assertions::assert_eq; - use crate::{ClientError, SUPPORTED_PROTOCOL_VERSION}; + use crate::ClientError; use super::*; @@ -234,29 +234,21 @@ mod tests { impl NodeClient for ValidSpecExecMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::BlockHeader) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - self.execution_result.clone(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(self.execution_result.clone()), + Bytes::from(vec![]), )) } - BinaryRequest::TrySpeculativeExec { .. } => Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - self.execution_result.clone(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + Command::TrySpeculativeExec { .. } => Ok(BinaryResponseAndRequest::new( + BinaryResponse::from_value(self.execution_result.clone()), + Bytes::from(vec![]), )), req => unimplemented!("unexpected request: {:?}", req), } diff --git a/rpc_sidecar/src/rpcs/state.rs b/rpc_sidecar/src/rpcs/state.rs index 1c6d4bb5..0244f7f1 100644 --- a/rpc_sidecar/src/rpcs/state.rs +++ b/rpc_sidecar/src/rpcs/state.rs @@ -1359,10 +1359,10 @@ mod tests { }, }; - use crate::{rpcs::ErrorCode, ClientError, SUPPORTED_PROTOCOL_VERSION}; + use crate::{rpcs::ErrorCode, ClientError}; use casper_binary_port::{ - AccountInformation, AddressableEntityInformation, BalanceResponse, BinaryRequest, - BinaryResponse, BinaryResponseAndRequest, ContractInformation, DictionaryQueryResult, + AccountInformation, AddressableEntityInformation, BalanceResponse, BinaryResponse, + BinaryResponseAndRequest, Command, ContractInformation, DictionaryQueryResult, ErrorCode as BinaryErrorCode, GetRequest, GlobalStateEntityQualifier, GlobalStateQueryResult, InformationRequestTag, KeyPrefix, ValueWithProof, }; @@ -1485,23 +1485,19 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::BlockHeader) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - self.block.clone_header(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(self.block.clone_header()), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::AllItems { @@ -1517,12 +1513,11 @@ mod tests { .map(|bid| StoredValue::Bid(bid.into())) .collect::>(); Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(bids, SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(bids), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::AllItems { @@ -1538,12 +1533,11 @@ mod tests { .map(StoredValue::BidKind) .collect::>(); Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(bids, SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(bids), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { @@ -1560,12 +1554,11 @@ mod tests { vec![], ); Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(result, SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(result), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { @@ -1582,7 +1575,7 @@ mod tests { StoredValue::CLValue(CLValue::from_t(1_u8).unwrap()), vec![], ); - BinaryResponse::from_value(result, SUPPORTED_PROTOCOL_VERSION) + BinaryResponse::from_value(result) } _ => { let result = GlobalStateQueryResult::new( @@ -1591,10 +1584,10 @@ mod tests { ), vec![], ); - BinaryResponse::from_value(result, SUPPORTED_PROTOCOL_VERSION) + BinaryResponse::from_value(result) } }; - Ok(BinaryResponseAndRequest::new(response, &[], 0)) + Ok(BinaryResponseAndRequest::new(response, Bytes::from(vec![]))) } req => unimplemented!("unexpected request: {:?}", req), @@ -1648,23 +1641,19 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::BlockHeader) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - self.block.clone_header(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(self.block.clone_header()), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::AllItems { @@ -1680,12 +1669,11 @@ mod tests { .map(|bid| StoredValue::Bid(bid.into())) .collect::>(); Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(bids, SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(bids), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::AllItems { @@ -1701,12 +1689,11 @@ mod tests { .map(StoredValue::BidKind) .collect::>(); Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(bids, SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(bids), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure(), ( @@ -1727,12 +1714,11 @@ mod tests { vec![], ); Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(result, SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(result), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { @@ -1743,12 +1729,11 @@ mod tests { ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::new_empty(SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::new_empty(), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { @@ -1763,9 +1748,8 @@ mod tests { if path == vec!["seigniorage_recipients_snapshot_version"] => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::new_empty(SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::new_empty(), + Bytes::from(vec![]), )) } _ => { @@ -1776,9 +1760,8 @@ mod tests { vec![], ); Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(result, SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(result), + Bytes::from(vec![]), )) } } @@ -1828,30 +1811,25 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::BlockHeader) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::new_empty(SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::new_empty(), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::AvailableBlockRange) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - AvailableBlockRange::RANGE_0_0, - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(AvailableBlockRange::RANGE_0_0), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -1882,29 +1860,25 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::Entity) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - AddressableEntityInformation::new( - self.addr, - ValueWithProof::new(self.entity.clone(), vec![]), - self.bytecode.as_ref().map(|bytecode| { - ValueWithProof::new(bytecode.clone(), vec![]) - }), - ), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(AddressableEntityInformation::new( + self.addr, + ValueWithProof::new(self.entity.clone(), vec![]), + self.bytecode + .as_ref() + .map(|bytecode| ValueWithProof::new(bytecode.clone(), vec![])), + )), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::ItemsByPrefix { @@ -1924,13 +1898,11 @@ mod tests { ) }) .collect::>(), - SUPPORTED_PROTOCOL_VERSION, ), - &[], - 0, + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::ItemsByPrefix { @@ -1946,13 +1918,11 @@ mod tests { .cloned() .map(StoredValue::EntryPoint) .collect::>(), - SUPPORTED_PROTOCOL_VERSION, ), - &[], - 0, + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::ItemsByPrefix { @@ -1962,12 +1932,8 @@ mod tests { ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - Vec::::new(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(Vec::::new()), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2090,26 +2056,22 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::Entity) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - ContractInformation::new( - self.hash, - ValueWithProof::new(self.contract.clone(), vec![]), - self.wasm.as_ref().map(|bytecode| { - ValueWithProof::new(bytecode.clone(), vec![]) - }), - ), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(ContractInformation::new( + self.hash, + ValueWithProof::new(self.contract.clone(), vec![]), + self.wasm + .as_ref() + .map(|bytecode| ValueWithProof::new(bytecode.clone(), vec![])), + )), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2170,17 +2132,16 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::Entity) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::new_empty(SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::new_empty(), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2215,20 +2176,19 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::Package) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - ValueWithProof::new(self.package.clone(), vec![]), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(ValueWithProof::new( + self.package.clone(), + vec![], + )), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2278,20 +2238,19 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::Package) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - ValueWithProof::new(self.package.clone(), vec![]), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(ValueWithProof::new( + self.package.clone(), + vec![], + )), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2379,23 +2338,19 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::BlockHeader) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - self.block.clone_header(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(self.block.clone_header()), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { @@ -2405,18 +2360,14 @@ mod tests { ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - GlobalStateQueryResult::new( - StoredValue::CLValue( - CLValue::from_t(Key::contract_entity_key(self.entity_hash)) - .unwrap(), - ), - vec![], + BinaryResponse::from_value(GlobalStateQueryResult::new( + StoredValue::CLValue( + CLValue::from_t(Key::contract_entity_key(self.entity_hash)) + .unwrap(), ), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + vec![], + )), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2455,23 +2406,19 @@ mod tests { impl NodeClient for ClientMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::BlockHeader) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - self.block.clone_header(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(self.block.clone_header()), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { @@ -2481,9 +2428,8 @@ mod tests { ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::new_empty(SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::new_empty(), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2668,22 +2614,21 @@ mod tests { impl NodeClient for ValidDictionaryQueryResultMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::DictionaryItem { .. } ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - DictionaryQueryResult::new(self.dict_key, self.query_result.clone()), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(DictionaryQueryResult::new( + self.dict_key, + self.query_result.clone(), + )), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2697,19 +2642,18 @@ mod tests { impl NodeClient for ValidGlobalStateResultMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { .. } ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(self.0.clone(), SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(self.0.clone()), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2726,32 +2670,27 @@ mod tests { impl NodeClient for ValidGlobalStateResultWithBlockMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::BlockHeader) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - self.block.clone_header(), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(self.block.clone_header()), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { .. } ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(self.result.clone(), SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(self.result.clone()), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2767,23 +2706,22 @@ mod tests { impl NodeClient for ValidLegacyAccountMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::Information { info_type_tag, .. }) + Command::Get(GetRequest::Information { info_type_tag, .. }) if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::Entity) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - AccountInformation::new(self.account.clone(), vec![]), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(AccountInformation::new( + self.account.clone(), + vec![], + )), + Bytes::from(vec![]), )) } - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Item { @@ -2793,15 +2731,11 @@ mod tests { ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value( - GlobalStateQueryResult::new( - StoredValue::Account(self.account.clone()), - vec![], - ), - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::from_value(GlobalStateQueryResult::new( + StoredValue::Account(self.account.clone()), + vec![], + )), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2815,19 +2749,18 @@ mod tests { impl NodeClient for ValidBalanceMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Balance { .. } ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::from_value(self.0.clone(), SUPPORTED_PROTOCOL_VERSION), - &[], - 0, + BinaryResponse::from_value(self.0.clone()), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), @@ -2841,22 +2774,18 @@ mod tests { impl NodeClient for BalancePurseNotFoundMock { async fn send_request( &self, - req: BinaryRequest, + req: Command, ) -> Result { match req { - BinaryRequest::Get(GetRequest::State(req)) + Command::Get(GetRequest::State(req)) if matches!( req.clone().destructure().1, GlobalStateEntityQualifier::Balance { .. } ) => { Ok(BinaryResponseAndRequest::new( - BinaryResponse::new_error( - BinaryErrorCode::PurseNotFound, - SUPPORTED_PROTOCOL_VERSION, - ), - &[], - 0, + BinaryResponse::new_error(BinaryErrorCode::PurseNotFound), + Bytes::from(vec![]), )) } req => unimplemented!("unexpected request: {:?}", req), diff --git a/rpc_sidecar/src/rpcs/test_utils.rs b/rpc_sidecar/src/rpcs/test_utils.rs index 24da20bb..5c4c86e5 100644 --- a/rpc_sidecar/src/rpcs/test_utils.rs +++ b/rpc_sidecar/src/rpcs/test_utils.rs @@ -2,26 +2,21 @@ use std::{collections::BTreeMap, convert::TryInto, sync::Arc}; use async_trait::async_trait; use casper_binary_port::{ - BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest, - GlobalStateEntityQualifier, GlobalStateQueryResult, GlobalStateRequest, InformationRequest, + BinaryResponse, BinaryResponseAndRequest, Command, GetRequest, GlobalStateEntityQualifier, + GlobalStateQueryResult, GlobalStateRequest, InformationRequest, }; use casper_types::{ addressable_entity::EntityKindTag, bytesrepr::ToBytes, system::auction::{Bid, BidKind, EraInfo, SEIGNIORAGE_RECIPIENTS_SNAPSHOT_KEY}, - AddressableEntityHash, BlockHeader, CLValue, GlobalStateIdentifier, Key, KeyTag, - ProtocolVersion, SemVer, StoredValue, + AddressableEntityHash, BlockHeader, CLValue, GlobalStateIdentifier, Key, KeyTag, StoredValue, }; -use once_cell::sync::Lazy; use tokio::sync::Mutex; use crate::{ClientError, NodeClient}; -pub(crate) static PROTOCOL_VERSION: Lazy = - Lazy::new(|| ProtocolVersion::new(SemVer::new(2, 0, 0))); - pub(crate) struct BinaryPortMock { - request_responses: Arc>>, + request_responses: Arc>>, } impl BinaryPortMock { @@ -43,12 +38,9 @@ impl BinaryPortMock { path: vec![], }, ); - let req = BinaryRequest::Get(GetRequest::State(Box::new(req))); + let req = Command::Get(GetRequest::State(Box::new(req))); let stored_value = StoredValue::EraInfo(era_info); - let res = BinaryResponse::from_value( - GlobalStateQueryResult::new(stored_value, vec![]), - *PROTOCOL_VERSION, - ); + let res = BinaryResponse::from_value(GlobalStateQueryResult::new(stored_value, vec![])); self.when_then(req, res).await; } @@ -60,8 +52,8 @@ impl BinaryPortMock { let get_request = information_request .try_into() .expect("should create request"); - let req = BinaryRequest::Get(get_request); - let res = BinaryResponse::from_option(Some(block_header), *PROTOCOL_VERSION); + let req = Command::Get(get_request); + let res = BinaryResponse::from_option(Some(block_header)); self.when_then(req, res).await; } @@ -78,8 +70,8 @@ impl BinaryPortMock { ))); let stored_values: Vec = bid_kinds.into_iter().map(StoredValue::BidKind).collect(); - let res = BinaryResponse::from_value(stored_values, *PROTOCOL_VERSION); - self.when_then(BinaryRequest::Get(req), res).await; + let res = BinaryResponse::from_value(stored_values); + self.when_then(Command::Get(req), res).await; } pub async fn add_bids_fetch_res( @@ -98,8 +90,8 @@ impl BinaryPortMock { .into_iter() .map(|b| StoredValue::Bid(Box::new(b))) .collect(); - let res = BinaryResponse::from_value(stored_values, *PROTOCOL_VERSION); - self.when_then(BinaryRequest::Get(req), res).await; + let res = BinaryResponse::from_value(stored_values); + self.when_then(Command::Get(req), res).await; } pub async fn add_system_registry( @@ -117,11 +109,8 @@ impl BinaryPortMock { let cl_value = CLValue::from_t(registry).unwrap(); let stored_value = StoredValue::CLValue(cl_value); - let res = BinaryResponse::from_value( - GlobalStateQueryResult::new(stored_value, vec![]), - *PROTOCOL_VERSION, - ); - self.when_then(BinaryRequest::Get(req), res).await; + let res = BinaryResponse::from_value(GlobalStateQueryResult::new(stored_value, vec![])); + self.when_then(Command::Get(req), res).await; } pub async fn add_seigniorage_snapshot_under_addressable_entity( @@ -140,9 +129,8 @@ impl BinaryPortMock { ))); let res = BinaryResponse::from_option( maybe_seigniorage_snapshot.map(|v| GlobalStateQueryResult::new(v, vec![])), - *PROTOCOL_VERSION, ); - self.when_then(BinaryRequest::Get(req), res).await; + self.when_then(Command::Get(req), res).await; } pub async fn add_seigniorage_snapshot_under_key_hash( @@ -161,14 +149,13 @@ impl BinaryPortMock { ))); let res = BinaryResponse::from_option( maybe_seigniorage_snapshot.map(|v| GlobalStateQueryResult::new(v, vec![])), - *PROTOCOL_VERSION, ); - self.when_then(BinaryRequest::Get(req), res).await; + self.when_then(Command::Get(req), res).await; } - pub async fn when_then(&self, when: BinaryRequest, then: BinaryResponse) { + pub async fn when_then(&self, when: Command, then: BinaryResponse) { let payload = when.to_bytes().unwrap(); - let response_and_request = BinaryResponseAndRequest::new(then, &payload, 0); + let response_and_request = BinaryResponseAndRequest::new(then, payload.into()); let mut guard = self.request_responses.lock().await; guard.push((when, response_and_request)); } @@ -176,10 +163,7 @@ impl BinaryPortMock { #[async_trait] impl NodeClient for BinaryPortMock { - async fn send_request( - &self, - req: BinaryRequest, - ) -> Result { + async fn send_request(&self, req: Command) -> Result { let mut guard = self.request_responses.lock().await; let (request, response) = guard.remove(0); if request != req { diff --git a/rpc_sidecar/src/testing/mod.rs b/rpc_sidecar/src/testing/mod.rs index cbbb47ec..0dfb9cd9 100644 --- a/rpc_sidecar/src/testing/mod.rs +++ b/rpc_sidecar/src/testing/mod.rs @@ -2,11 +2,11 @@ use std::sync::Arc; use std::time::Duration; use casper_binary_port::{ - BinaryMessage, BinaryMessageCodec, BinaryRequest, BinaryResponse, BinaryResponseAndRequest, + BinaryMessage, BinaryMessageCodec, BinaryResponse, BinaryResponseAndRequest, Command, GetRequest, GlobalStateQueryResult, }; -use casper_types::bytesrepr; -use casper_types::{bytesrepr::ToBytes, CLValue, ProtocolVersion, StoredValue}; +use casper_types::bytesrepr::Bytes; +use casper_types::{bytesrepr::ToBytes, CLValue, StoredValue}; use futures::{SinkExt, StreamExt}; use tokio::sync::Notify; use tokio::task::JoinHandle; @@ -14,7 +14,7 @@ use tokio::{ net::{TcpListener, TcpStream}, time::sleep, }; -use tokio_util::codec::Framed; +use tokio_util::codec::{Encoder, Framed}; use crate::encode_request; @@ -90,10 +90,9 @@ pub async fn start_mock_binary_port_responding_with_stored_value( ) -> JoinHandle<()> { let value = StoredValue::CLValue(CLValue::from_t("Foo").unwrap()); let data = GlobalStateQueryResult::new(value, vec![]); - let protocol_version = ProtocolVersion::from_parts(2, 0, 0); - let val = BinaryResponse::from_value(data, protocol_version); + let val = BinaryResponse::from_value(data); let request = get_dummy_request_payload(request_id); - let response = BinaryResponseAndRequest::new(val, &request, request_id.unwrap_or_default()); + let response = BinaryResponseAndRequest::new(val, request); start_mock_binary_port( port, response.to_bytes().unwrap(), @@ -111,8 +110,7 @@ pub async fn start_mock_binary_port_responding_with_given_response( binary_response: BinaryResponse, ) -> JoinHandle<()> { let request = get_dummy_request_payload(request_id); - let response = - BinaryResponseAndRequest::new(binary_response, &request, request_id.unwrap_or_default()); + let response = BinaryResponseAndRequest::new(binary_response, request); start_mock_binary_port( port, response.to_bytes().unwrap(), @@ -136,16 +134,18 @@ pub async fn start_mock_binary_port( handler } -pub(crate) fn get_dummy_request() -> BinaryRequest { - BinaryRequest::Get(GetRequest::Information { +pub(crate) fn get_dummy_request() -> Command { + Command::Get(GetRequest::Information { info_type_tag: 0, key: vec![], }) } -pub(crate) fn get_dummy_request_payload(request_id: Option) -> bytesrepr::Bytes { +pub(crate) fn get_dummy_request_payload(request_id: Option) -> Bytes { let dummy_request = get_dummy_request(); - encode_request(&dummy_request, request_id.unwrap_or_default()) - .unwrap() - .into() + let bytes = encode_request(&dummy_request, request_id.unwrap_or_default()).unwrap(); + let mut codec = BinaryMessageCodec::new(u32::MAX); + let mut buf = bytes::BytesMut::new(); + codec.encode(BinaryMessage::new(bytes), &mut buf).unwrap(); + Bytes::from(buf.freeze().to_vec()) }