Client: Print the error kind on simulation failure (#462)

This commit is contained in:
Christian Kamm 2023-02-16 10:55:35 +01:00 committed by GitHub
parent a87705fa37
commit 6439eb5531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -26,6 +26,7 @@ use solana_client::nonblocking::rpc_client::RpcClient as RpcClientAsync;
use solana_sdk::address_lookup_table_account::AddressLookupTableAccount;
use solana_sdk::hash::Hash;
use solana_sdk::signer::keypair;
use solana_sdk::transaction::TransactionError;
use crate::account_fetcher::*;
use crate::context::{MangoGroupContext, Serum3MarketContext, TokenContext};
@ -1474,8 +1475,13 @@ struct Serum3Data<'a> {
#[derive(Debug, thiserror::Error)]
pub enum MangoClientError {
#[error("Transaction simulation error. Logs: {logs}")]
SendTransactionPreflightFailure { logs: String },
#[error("Transaction simulation error. Error: {err:?}, Logs: {}",
.logs.iter().join("; ")
)]
SendTransactionPreflightFailure {
err: Option<TransactionError>,
logs: Vec<String>,
},
}
pub struct TransactionBuilder<'a> {
@ -1552,13 +1558,12 @@ pub fn prettify_solana_client_error(
match err.kind() {
ClientErrorKind::RpcError(RpcError::RpcResponseError { data, .. }) => match data {
RpcResponseErrorData::SendTransactionPreflightFailure(s) => {
if let Some(logs) = s.logs.as_ref() {
return MangoClientError::SendTransactionPreflightFailure {
logs: logs.iter().join("; "),
err: s.err.clone(),
logs: s.logs.clone().unwrap_or_default(),
}
.into();
}
}
_ => {}
},
_ => {}

View File

@ -488,8 +488,12 @@ impl LiquidationState {
// Simulation errors due to liqee precondition failures on the liquidation instructions
// will commonly happen if our liquidator is late or if there are chain forks.
match err.downcast_ref::<client::MangoClientError>() {
Some(client::MangoClientError::SendTransactionPreflightFailure { logs }) => {
if logs.contains("HealthMustBeNegative") || logs.contains("IsNotBankrupt") {
Some(client::MangoClientError::SendTransactionPreflightFailure {
logs, ..
}) => {
if logs.iter().any(|line| {
line.contains("HealthMustBeNegative") || line.contains("IsNotBankrupt")
}) {
log_level = log::Level::Trace;
}
}