0.7.53
This commit is contained in:
@@ -47,9 +47,10 @@ impl TradeAggregationService {
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let transaction = transaction_context.transaction;
|
||||
if transaction.err_json.is_some() {
|
||||
if crate::trade_aggregation::transaction_has_effective_error(&transaction) {
|
||||
tracing::debug!(
|
||||
signature = %transaction.signature,
|
||||
err_json = ?transaction.err_json,
|
||||
"skipping trade aggregation for failed transaction"
|
||||
);
|
||||
return Ok(std::vec::Vec::new());
|
||||
@@ -199,6 +200,21 @@ impl TradeAggregationService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn transaction_has_effective_error(transaction: &crate::ChainTransactionDto) -> bool {
|
||||
let err_json = match transaction.err_json.as_ref() {
|
||||
Some(err_json) => err_json.trim(),
|
||||
None => return false,
|
||||
};
|
||||
if err_json.is_empty() {
|
||||
return false;
|
||||
}
|
||||
if err_json == "null" {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
async fn make_database() -> std::sync::Arc<crate::Database> {
|
||||
@@ -416,6 +432,51 @@ mod tests {
|
||||
assert_eq!(pair_metric.trade_count, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transaction_null_err_json_is_not_effective_error() {
|
||||
let transaction = crate::ChainTransactionDto::new(
|
||||
"sig-null-err".to_string(),
|
||||
Some(1),
|
||||
None,
|
||||
Some("test".to_string()),
|
||||
Some("0".to_string()),
|
||||
Some("null".to_string()),
|
||||
None,
|
||||
serde_json::json!({"meta":{"err":null}}).to_string(),
|
||||
);
|
||||
assert!(!super::transaction_has_effective_error(&transaction));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transaction_empty_err_json_is_not_effective_error() {
|
||||
let transaction = crate::ChainTransactionDto::new(
|
||||
"sig-empty-err".to_string(),
|
||||
Some(1),
|
||||
None,
|
||||
Some("test".to_string()),
|
||||
Some("0".to_string()),
|
||||
Some("".to_string()),
|
||||
None,
|
||||
serde_json::json!({"meta":{"err":null}}).to_string(),
|
||||
);
|
||||
assert!(!super::transaction_has_effective_error(&transaction));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transaction_non_null_err_json_is_effective_error() {
|
||||
let transaction = crate::ChainTransactionDto::new(
|
||||
"sig-real-err".to_string(),
|
||||
Some(1),
|
||||
None,
|
||||
Some("test".to_string()),
|
||||
Some("0".to_string()),
|
||||
Some(serde_json::json!({"InstructionError":[0,{"Custom":1}]}).to_string()),
|
||||
None,
|
||||
serde_json::json!({"meta":{"err":{"InstructionError":[0,{"Custom":1}]}}}).to_string(),
|
||||
);
|
||||
assert!(super::transaction_has_effective_error(&transaction));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn record_transaction_by_signature_skips_failed_transaction() {
|
||||
let database = make_database().await;
|
||||
|
||||
Reference in New Issue
Block a user