From ddde356b336ae21b247be6938a5ef77a9cbdcc19 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Dec 2021 02:31:02 +0000 Subject: [PATCH] bump tarpc from 0.26.2 to 0.27.2 and add BanksClientError (#21739) * chore: bump tarpc from 0.26.2 to 0.27.2 Bumps [tarpc](https://github.com/google/tarpc) from 0.26.2 to 0.27.2. - [Release notes](https://github.com/google/tarpc/releases) - [Changelog](https://github.com/google/tarpc/blob/master/RELEASES.md) - [Commits](https://github.com/google/tarpc/commits) --- updated-dependencies: - dependency-name: tarpc dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * [auto-commit] Update all Cargo lock files * Accommodate breaking changes * Reword incorrect error message * Add error module * Revert client Error type to io::Error; easy transition to BanksClientError * Bump tracing crates in programs Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot-buildkite Co-authored-by: Tyera Eulberg --- Cargo.lock | 19 +++++---- banks-client/Cargo.toml | 3 +- banks-client/src/error.rs | 62 +++++++++++++++++++++++++++ banks-client/src/lib.rs | 72 +++++++++++++++++++++++--------- banks-interface/Cargo.toml | 2 +- banks-server/Cargo.toml | 2 +- banks-server/src/banks_server.rs | 2 +- programs/bpf/Cargo.lock | 53 +++++++++++------------ 8 files changed, 155 insertions(+), 60 deletions(-) create mode 100644 banks-client/src/error.rs diff --git a/Cargo.lock b/Cargo.lock index 3b3d9fcef3..0b1d4d205c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2881,11 +2881,12 @@ dependencies = [ [[package]] name = "opentelemetry" -version = "0.13.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91cea1dfd50064e52db033179952d18c770cbc5dfefc8eba45d619357ba3914" +checksum = "e1cf9b1c4e9a6c4de793c632496fa490bdc0e1eea73f0c91394f7b6990935d22" dependencies = [ "async-trait", + "crossbeam-channel", "futures 0.3.19", "js-sys", "lazy_static", @@ -4539,6 +4540,7 @@ dependencies = [ "solana-runtime", "solana-sdk", "tarpc", + "thiserror", "tokio", "tokio-serde", ] @@ -6469,9 +6471,9 @@ dependencies = [ [[package]] name = "tarpc" -version = "0.26.2" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82cb992a07637db1bcc0e4511d0c58c3f3a03f509d7c6cc2826f7646deac2032" +checksum = "b85d0a9369a919ba0db919b142a2b704cd207dfc676f7a43c2d105d0bc225487" dependencies = [ "anyhow", "fnv", @@ -6493,9 +6495,9 @@ dependencies = [ [[package]] name = "tarpc-plugins" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea80818e6c75f81d961d7426c1b938cbea6b3a51533b5ee71b61f82166b7ef3d" +checksum = "0ee42b4e559f17bce0385ebf511a7beb67d5cc33c12c96b7f4e9789919d9c10f" dependencies = [ "proc-macro2 1.0.32", "quote 1.0.10", @@ -6854,6 +6856,7 @@ dependencies = [ "futures-sink", "pin-project", "serde", + "serde_json", ] [[package]] @@ -7049,9 +7052,9 @@ dependencies = [ [[package]] name = "tracing-opentelemetry" -version = "0.12.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99003208b647dae59dcefc49c98aecaa3512fbc29351685d4b9ef23a9218458e" +checksum = "599f388ecb26b28d9c1b2e4437ae019a7b336018b45ed911458cd9ebf91129f6" dependencies = [ "opentelemetry", "tracing", diff --git a/banks-client/Cargo.toml b/banks-client/Cargo.toml index 372c3f440d..b8f2daf3cf 100644 --- a/banks-client/Cargo.toml +++ b/banks-client/Cargo.toml @@ -15,7 +15,8 @@ futures = "0.3" solana-banks-interface = { path = "../banks-interface", version = "=1.10.0" } solana-program = { path = "../sdk/program", version = "=1.10.0" } solana-sdk = { path = "../sdk", version = "=1.10.0" } -tarpc = { version = "0.26.2", features = ["full"] } +tarpc = { version = "0.27.2", features = ["full"] } +thiserror = "1.0" tokio = { version = "1", features = ["full"] } tokio-serde = { version = "0.8", features = ["bincode"] } diff --git a/banks-client/src/error.rs b/banks-client/src/error.rs new file mode 100644 index 0000000000..de1bea79c1 --- /dev/null +++ b/banks-client/src/error.rs @@ -0,0 +1,62 @@ +use { + solana_sdk::{transaction::TransactionError, transport::TransportError}, + std::io, + tarpc::client::RpcError, + thiserror::Error, +}; + +/// Errors from BanksClient +#[derive(Error, Debug)] +pub enum BanksClientError { + #[error("client error: {0}")] + ClientError(&'static str), + + #[error(transparent)] + Io(#[from] io::Error), + + #[error(transparent)] + RpcError(#[from] RpcError), + + #[error("transport transaction error: {0}")] + TransactionError(#[from] TransactionError), +} + +impl BanksClientError { + pub fn unwrap(&self) -> TransactionError { + if let BanksClientError::TransactionError(err) = self { + err.clone() + } else { + panic!("unexpected transport error") + } + } +} + +impl From for io::Error { + fn from(err: BanksClientError) -> Self { + match err { + BanksClientError::ClientError(err) => Self::new(io::ErrorKind::Other, err.to_string()), + BanksClientError::Io(err) => err, + BanksClientError::RpcError(err) => Self::new(io::ErrorKind::Other, err.to_string()), + BanksClientError::TransactionError(err) => { + Self::new(io::ErrorKind::Other, err.to_string()) + } + } + } +} + +impl From for TransportError { + fn from(err: BanksClientError) -> Self { + match err { + BanksClientError::ClientError(err) => { + Self::IoError(io::Error::new(io::ErrorKind::Other, err.to_string())) + } + BanksClientError::Io(err) => { + Self::IoError(io::Error::new(io::ErrorKind::Other, err.to_string())) + } + BanksClientError::RpcError(err) => { + Self::IoError(io::Error::new(io::ErrorKind::Other, err.to_string())) + } + BanksClientError::TransactionError(err) => Self::TransactionError(err), + } + } +} diff --git a/banks-client/src/lib.rs b/banks-client/src/lib.rs index 1623705176..101a78422b 100644 --- a/banks-client/src/lib.rs +++ b/banks-client/src/lib.rs @@ -7,8 +7,9 @@ pub use solana_banks_interface::{BanksClient as TarpcClient, TransactionStatus}; use { + crate::error::BanksClientError, borsh::BorshDeserialize, - futures::{future::join_all, Future, FutureExt}, + futures::{future::join_all, Future, FutureExt, TryFutureExt}, solana_banks_interface::{BanksRequest, BanksResponse}, solana_program::{ clock::Slot, fee_calculator::FeeCalculator, hash::Hash, program_pack::Pack, pubkey::Pubkey, @@ -22,7 +23,7 @@ use { transaction::{self, Transaction}, transport, }, - std::io::{self, Error, ErrorKind}, + std::io, tarpc::{ client::{self, NewClient, RequestDispatch}, context::{self, Context}, @@ -33,6 +34,8 @@ use { tokio_serde::formats::Bincode, }; +mod error; + // This exists only for backward compatibility pub trait BanksClientExt {} @@ -58,7 +61,10 @@ impl BanksClient { ctx: Context, transaction: Transaction, ) -> impl Future> + '_ { - self.inner.send_transaction_with_context(ctx, transaction) + self.inner + .send_transaction_with_context(ctx, transaction) + .map_err(BanksClientError::from) // Remove this when return Err type updated to BanksClientError + .map_err(Into::into) } #[deprecated( @@ -73,6 +79,8 @@ impl BanksClient { #[allow(deprecated)] self.inner .get_fees_with_commitment_and_context(ctx, commitment) + .map_err(BanksClientError::from) // Remove this when return Err type updated to BanksClientError + .map_err(Into::into) } pub fn get_transaction_status_with_context( @@ -82,6 +90,8 @@ impl BanksClient { ) -> impl Future>> + '_ { self.inner .get_transaction_status_with_context(ctx, signature) + .map_err(BanksClientError::from) // Remove this when return Err type updated to BanksClientError + .map_err(Into::into) } pub fn get_slot_with_context( @@ -89,7 +99,10 @@ impl BanksClient { ctx: Context, commitment: CommitmentLevel, ) -> impl Future> + '_ { - self.inner.get_slot_with_context(ctx, commitment) + self.inner + .get_slot_with_context(ctx, commitment) + .map_err(BanksClientError::from) // Remove this when return Err type updated to BanksClientError + .map_err(Into::into) } pub fn get_block_height_with_context( @@ -97,7 +110,10 @@ impl BanksClient { ctx: Context, commitment: CommitmentLevel, ) -> impl Future> + '_ { - self.inner.get_block_height_with_context(ctx, commitment) + self.inner + .get_block_height_with_context(ctx, commitment) + .map_err(BanksClientError::from) // Remove this when return Err type updated to BanksClientError + .map_err(Into::into) } pub fn process_transaction_with_commitment_and_context( @@ -108,6 +124,8 @@ impl BanksClient { ) -> impl Future>>> + '_ { self.inner .process_transaction_with_commitment_and_context(ctx, transaction, commitment) + .map_err(BanksClientError::from) // Remove this when return Err type updated to BanksClientError + .map_err(Into::into) } pub fn get_account_with_commitment_and_context( @@ -118,6 +136,8 @@ impl BanksClient { ) -> impl Future>> + '_ { self.inner .get_account_with_commitment_and_context(ctx, address, commitment) + .map_err(BanksClientError::from) // Remove this when return Err type updated to BanksClientError + .map_err(Into::into) } /// Send a transaction and return immediately. The server will resend the @@ -148,9 +168,13 @@ impl BanksClient { pub fn get_sysvar(&mut self) -> impl Future> + '_ { self.get_account(T::id()).map(|result| { let sysvar = result? - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Sysvar not present"))?; + .ok_or(BanksClientError::ClientError("Sysvar not present")) + .map_err(io::Error::from)?; // Remove this map when return Err type updated to BanksClientError from_account::(&sysvar) - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Failed to deserialize sysvar")) + .ok_or(BanksClientError::ClientError( + "Failed to deserialize sysvar", + )) + .map_err(Into::into) // Remove this when return Err type updated to BanksClientError }) } @@ -164,7 +188,8 @@ impl BanksClient { /// method to get both a blockhash and the blockhash's last valid slot. #[deprecated(since = "1.9.0", note = "Please use `get_latest_blockhash` instead")] pub fn get_recent_blockhash(&mut self) -> impl Future> + '_ { - self.get_latest_blockhash() + #[allow(deprecated)] + self.get_fees().map(|result| Ok(result?.1)) } /// Send a transaction and return after the transaction has been rejected or @@ -178,11 +203,12 @@ impl BanksClient { ctx.deadline += Duration::from_secs(50); self.process_transaction_with_commitment_and_context(ctx, transaction, commitment) .map(|result| match result? { - None => { - Err(Error::new(ErrorKind::TimedOut, "invalid blockhash or fee-payer").into()) - } + None => Err(BanksClientError::ClientError( + "invalid blockhash or fee-payer", + )), Some(transaction_result) => Ok(transaction_result?), }) + .map_err(Into::into) // Remove this when return Err type updated to BanksClientError } /// Send a transaction and return until the transaction has been finalized or rejected. @@ -255,10 +281,12 @@ impl BanksClient { address: Pubkey, ) -> impl Future> + '_ { self.get_account(address).map(|result| { - let account = - result?.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Account not found"))?; + let account = result? + .ok_or(BanksClientError::ClientError("Account not found")) + .map_err(io::Error::from)?; // Remove this map when return Err type updated to BanksClientError T::unpack_from_slice(&account.data) - .map_err(|_| io::Error::new(io::ErrorKind::Other, "Failed to deserialize account")) + .map_err(|_| BanksClientError::ClientError("Failed to deserialize account")) + .map_err(Into::into) // Remove this when return Err type updated to BanksClientError }) } @@ -269,9 +297,8 @@ impl BanksClient { address: Pubkey, ) -> impl Future> + '_ { self.get_account(address).map(|result| { - let account = - result?.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "account not found"))?; - T::try_from_slice(&account.data) + let account = result?.ok_or(BanksClientError::ClientError("Account not found"))?; + T::try_from_slice(&account.data).map_err(Into::into) }) } @@ -330,7 +357,8 @@ impl BanksClient { .map(|result| { result? .map(|x| x.0) - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "account not found")) + .ok_or(BanksClientError::ClientError("valid blockhash not found")) + .map_err(Into::into) }) } @@ -348,6 +376,8 @@ impl BanksClient { ) -> impl Future>> + '_ { self.inner .get_latest_blockhash_with_commitment_and_context(ctx, commitment) + .map_err(BanksClientError::from) // Remove this when return Err type updated to BanksClientError + .map_err(Into::into) } pub fn get_fee_for_message_with_commitment_and_context( @@ -358,6 +388,8 @@ impl BanksClient { ) -> impl Future>> + '_ { self.inner .get_fee_for_message_with_commitment_and_context(ctx, commitment, message) + .map_err(BanksClientError::from) // Remove this when return Err type updated to BanksClientError + .map_err(Into::into) } } @@ -399,7 +431,7 @@ mod tests { } #[test] - fn test_banks_server_transfer_via_server() -> io::Result<()> { + fn test_banks_server_transfer_via_server() -> Result<(), BanksClientError> { // This test shows the preferred way to interact with BanksServer. // It creates a runtime explicitly (no globals via tokio macros) and calls // `runtime.block_on()` just once, to run all the async code. @@ -432,7 +464,7 @@ mod tests { } #[test] - fn test_banks_server_transfer_via_client() -> io::Result<()> { + fn test_banks_server_transfer_via_client() -> Result<(), BanksClientError> { // The caller may not want to hold the connection open until the transaction // is processed (or blockhash expires). In this test, we verify the // server-side functionality is available to the client. diff --git a/banks-interface/Cargo.toml b/banks-interface/Cargo.toml index 4a4304bc87..fe0bd95f42 100644 --- a/banks-interface/Cargo.toml +++ b/banks-interface/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" [dependencies] serde = { version = "1.0.132", features = ["derive"] } solana-sdk = { path = "../sdk", version = "=1.10.0" } -tarpc = { version = "0.26.2", features = ["full"] } +tarpc = { version = "0.27.2", features = ["full"] } [lib] crate-type = ["lib"] diff --git a/banks-server/Cargo.toml b/banks-server/Cargo.toml index 1760606c4c..8e52027051 100644 --- a/banks-server/Cargo.toml +++ b/banks-server/Cargo.toml @@ -16,7 +16,7 @@ solana-banks-interface = { path = "../banks-interface", version = "=1.10.0" } solana-runtime = { path = "../runtime", version = "=1.10.0" } solana-sdk = { path = "../sdk", version = "=1.10.0" } solana-send-transaction-service = { path = "../send-transaction-service", version = "=1.10.0" } -tarpc = { version = "0.26.2", features = ["full"] } +tarpc = { version = "0.27.2", features = ["full"] } tokio = { version = "1", features = ["full"] } tokio-serde = { version = "0.8", features = ["bincode"] } tokio-stream = "0.1" diff --git a/banks-server/src/banks_server.rs b/banks-server/src/banks_server.rs index d510cf5995..5cd4372a25 100644 --- a/banks-server/src/banks_server.rs +++ b/banks-server/src/banks_server.rs @@ -35,7 +35,7 @@ use { tarpc::{ context::Context, serde_transport::tcp, - server::{self, Channel, Incoming}, + server::{self, incoming::Incoming, Channel}, transport::{self, channel::UnboundedChannel}, ClientMessage, Response, }, diff --git a/programs/bpf/Cargo.lock b/programs/bpf/Cargo.lock index 2768b10f74..573370ef74 100644 --- a/programs/bpf/Cargo.lock +++ b/programs/bpf/Cargo.lock @@ -1068,7 +1068,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.7", + "pin-project-lite", "pin-utils", "slab", ] @@ -1318,7 +1318,7 @@ dependencies = [ "httparse", "httpdate", "itoa 0.4.5", - "pin-project-lite 0.2.7", + "pin-project-lite", "socket2", "tokio", "tower-service", @@ -1790,11 +1790,12 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "opentelemetry" -version = "0.13.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91cea1dfd50064e52db033179952d18c770cbc5dfefc8eba45d619357ba3914" +checksum = "e1cf9b1c4e9a6c4de793c632496fa490bdc0e1eea73f0c91394f7b6990935d22" dependencies = [ "async-trait", + "crossbeam-channel", "futures", "js-sys", "lazy_static", @@ -1897,12 +1898,6 @@ dependencies = [ "syn 1.0.67", ] -[[package]] -name = "pin-project-lite" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7505eeebd78492e0f6108f7171c4948dbb120ee8119d9d77d0afa5469bef67f" - [[package]] name = "pin-project-lite" version = "0.2.7" @@ -2199,7 +2194,7 @@ dependencies = [ "log", "mime", "percent-encoding", - "pin-project-lite 0.2.7", + "pin-project-lite", "rustls 0.19.0", "serde", "serde_json", @@ -2600,6 +2595,7 @@ dependencies = [ "solana-program 1.10.0", "solana-sdk", "tarpc", + "thiserror", "tokio", "tokio-serde", ] @@ -3752,9 +3748,9 @@ dependencies = [ [[package]] name = "tarpc" -version = "0.26.2" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82cb992a07637db1bcc0e4511d0c58c3f3a03f509d7c6cc2826f7646deac2032" +checksum = "b85d0a9369a919ba0db919b142a2b704cd207dfc676f7a43c2d105d0bc225487" dependencies = [ "anyhow", "fnv", @@ -3776,9 +3772,9 @@ dependencies = [ [[package]] name = "tarpc-plugins" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea80818e6c75f81d961d7426c1b938cbea6b3a51533b5ee71b61f82166b7ef3d" +checksum = "0ee42b4e559f17bce0385ebf511a7beb67d5cc33c12c96b7f4e9789919d9c10f" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.6", @@ -3913,7 +3909,7 @@ dependencies = [ "num_cpus", "once_cell", "parking_lot", - "pin-project-lite 0.2.7", + "pin-project-lite", "signal-hook-registry", "tokio-macros", "winapi", @@ -3954,6 +3950,7 @@ dependencies = [ "futures-sink", "pin-project", "serde", + "serde_json", ] [[package]] @@ -3963,7 +3960,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" dependencies = [ "futures-core", - "pin-project-lite 0.2.7", + "pin-project-lite", "tokio", ] @@ -3977,7 +3974,7 @@ dependencies = [ "futures-core", "futures-sink", "log", - "pin-project-lite 0.2.7", + "pin-project-lite", "slab", "tokio", ] @@ -3999,22 +3996,22 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.21" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "log", - "pin-project-lite 0.1.5", + "pin-project-lite", "tracing-attributes", "tracing-core", ] [[package]] name = "tracing-attributes" -version = "0.1.15" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.6", @@ -4023,18 +4020,18 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.17" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" dependencies = [ "lazy_static", ] [[package]] name = "tracing-opentelemetry" -version = "0.12.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99003208b647dae59dcefc49c98aecaa3512fbc29351685d4b9ef23a9218458e" +checksum = "599f388ecb26b28d9c1b2e4437ae019a7b336018b45ed911458cd9ebf91129f6" dependencies = [ "opentelemetry", "tracing",