From 94b5ce88ed95c775557180b2f118b04af6fc4a3a Mon Sep 17 00:00:00 2001 From: janniks Date: Tue, 20 Feb 2024 15:57:39 +0100 Subject: [PATCH] fix: include txid in failure logs --- .../src/chainstate/stacks/db/transactions.rs | 59 ++++++++++++++----- stackslib/src/chainstate/stacks/miner.rs | 2 +- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/stackslib/src/chainstate/stacks/db/transactions.rs b/stackslib/src/chainstate/stacks/db/transactions.rs index e5e0bf19e9..85da970311 100644 --- a/stackslib/src/chainstate/stacks/db/transactions.rs +++ b/stackslib/src/chainstate/stacks/db/transactions.rs @@ -550,6 +550,7 @@ impl StacksChainState { post_condition_mode: &TransactionPostConditionMode, origin_account: &StacksAccount, asset_map: &AssetMap, + txid: Txid, ) -> Result { let mut checked_fungible_assets: HashMap> = HashMap::new(); @@ -578,7 +579,7 @@ impl StacksChainState { if !condition_code.check(*amount_sent_condition as u128, amount_sent) { info!( "Post-condition check failure on STX owned by {}: {:?} {:?} {}", - account_principal, amount_sent_condition, condition_code, amount_sent + account_principal, amount_sent_condition, condition_code, amount_sent; "txid" => %txid ); return Ok(false); } @@ -622,7 +623,7 @@ impl StacksChainState { .get_fungible_tokens(&account_principal, &asset_id) .unwrap_or(0); if !condition_code.check(*amount_sent_condition as u128, amount_sent) { - info!("Post-condition check failure on fungible asset {} owned by {}: {} {:?} {}", &asset_id, account_principal, amount_sent_condition, condition_code, amount_sent); + info!("Post-condition check failure on fungible asset {} owned by {}: {} {:?} {}", &asset_id, account_principal, amount_sent_condition, condition_code, amount_sent; "txid" => %txid); return Ok(false); } @@ -656,7 +657,7 @@ impl StacksChainState { .get_nonfungible_tokens(&account_principal, &asset_id) .unwrap_or(&empty_assets); if !condition_code.check(asset_value, assets_sent) { - info!("Post-condition check failure on non-fungible asset {} owned by {}: {:?} {:?}", &asset_id, account_principal, &asset_value, condition_code); + info!("Post-condition check failure on non-fungible asset {} owned by {}: {:?} {:?}", &asset_id, account_principal, &asset_value, condition_code; "txid" => %txid); return Ok(false); } @@ -698,18 +699,18 @@ impl StacksChainState { // each value must be covered for v in values { if !nfts.contains(&v.clone().try_into()?) { - info!("Post-condition check failure: Non-fungible asset {} value {:?} was moved by {} but not checked", &asset_identifier, &v, &principal); + info!("Post-condition check failure: Non-fungible asset {} value {:?} was moved by {} but not checked", &asset_identifier, &v, &principal; "txid" => %txid); return Ok(false); } } } else { // no values covered - info!("Post-condition check failure: No checks for non-fungible asset type {} moved by {}", &asset_identifier, &principal); + info!("Post-condition check failure: No checks for non-fungible asset type {} moved by {}", &asset_identifier, &principal; "txid" => %txid); return Ok(false); } } else { // no NFT for this principal - info!("Post-condition check failure: No checks for any non-fungible assets, but moved {} by {}", &asset_identifier, &principal); + info!("Post-condition check failure: No checks for any non-fungible assets, but moved {} by {}", &asset_identifier, &principal; "txid" => %txid); return Ok(false); } } @@ -719,11 +720,11 @@ impl StacksChainState { checked_fungible_assets.get(&principal) { if !checked_ft_asset_ids.contains(&asset_identifier) { - info!("Post-condition check failure: checks did not cover transfer of {} by {}", &asset_identifier, &principal); + info!("Post-condition check failure: checks did not cover transfer of {} by {}", &asset_identifier, &principal; "txid" => %txid); return Ok(false); } } else { - info!("Post-condition check failure: No checks for fungible token type {} moved by {}", &asset_identifier, &principal); + info!("Post-condition check failure: No checks for fungible token type {} moved by {}", &asset_identifier, &principal; "txid" => %txid); return Ok(false); } } @@ -950,14 +951,14 @@ impl StacksChainState { // Their presence in this variant makes the transaction invalid. if tx.post_conditions.len() > 0 { let msg = format!("Invalid Stacks transaction: TokenTransfer transactions do not support post-conditions"); - warn!("{}", &msg); + warn!("{}", &msg; "txid" => %tx.txid()); return Err(Error::InvalidStacksTransaction(msg, false)); } if *addr == origin_account.principal { let msg = format!("Invalid TokenTransfer: address tried to send to itself"); - warn!("{}", &msg); + warn!("{}", &msg; "txid" => %tx.txid()); return Err(Error::InvalidStacksTransaction(msg, false)); } @@ -1009,6 +1010,7 @@ impl StacksChainState { &tx.post_condition_mode, origin_account, asset_map, + tx.txid(), ) .expect("FATAL: error while evaluating post-conditions") }, @@ -1026,7 +1028,8 @@ impl StacksChainState { "function_name" => %contract_call.function_name, "function_args" => %VecDisplay(&contract_call.function_args), "return_value" => %return_value, - "cost" => ?total_cost); + "cost" => ?total_cost, + "txid" => %tx.txid()); (return_value, asset_map, events) } Err(e) => match handle_clarity_runtime_error(e) { @@ -1035,14 +1038,16 @@ impl StacksChainState { "contract_name" => %contract_id, "function_name" => %contract_call.function_name, "function_args" => %VecDisplay(&contract_call.function_args), - "error" => ?error); + "error" => ?error, + "txid" => %tx.txid()); (Value::err_none(), AssetMap::new(), vec![]) } ClarityRuntimeTxError::AbortedByCallback(value, assets, events) => { info!("Contract-call aborted by post-condition"; "contract_name" => %contract_id, "function_name" => %contract_call.function_name, - "function_args" => %VecDisplay(&contract_call.function_args)); + "function_args" => %VecDisplay(&contract_call.function_args), + "txid" => %tx.txid()); let receipt = StacksTransactionReceipt::from_condition_aborted_contract_call( tx.clone(), events, @@ -1063,7 +1068,8 @@ impl StacksChainState { "contract_name" => %contract_id, "function_name" => %contract_call.function_name, "function_args" => %VecDisplay(&contract_call.function_args), - "error" => %check_error); + "error" => %check_error, + "txid" => %tx.txid()); let receipt = StacksTransactionReceipt::from_runtime_failure_contract_call( @@ -1078,7 +1084,8 @@ impl StacksChainState { "contract_name" => %contract_id, "function_name" => %contract_call.function_name, "function_args" => %VecDisplay(&contract_call.function_args), - "error" => %check_error); + "error" => %check_error, + "txid" => %tx.txid()); return Err(Error::ClarityError(clarity_error::Interpreter( InterpreterError::Unchecked(check_error), ))); @@ -1089,7 +1096,8 @@ impl StacksChainState { "contract_name" => %contract_id, "function_name" => %contract_call.function_name, "function_args" => %VecDisplay(&contract_call.function_args), - "error" => ?e); + "error" => ?e, + "txid" => %tx.txid()); return Err(Error::ClarityError(e)); } }, @@ -1226,6 +1234,7 @@ impl StacksChainState { &tx.post_condition_mode, origin_account, asset_map, + tx.txid(), ) .expect("FATAL: error while evaluating post-conditions") }, @@ -6796,6 +6805,12 @@ pub mod test { mode, origin, &ft_transfer_2, + Txid( + "1232121232121232121232121232121232121232121232121232121232121232" + .as_bytes() + .try_into() + .unwrap(), + ), ) .unwrap(); if result != expected_result { @@ -7149,6 +7164,12 @@ pub mod test { mode, origin, &nft_transfer_2, + Txid( + "1232121232121232121232121232121232121232121232121232121232121232" + .as_bytes() + .try_into() + .unwrap(), + ), ) .unwrap(); if result != expected_result { @@ -7966,6 +7987,12 @@ pub mod test { post_condition_mode, origin_account, asset_map, + Txid( + "1232121232121232121232121232121232121232121232121232121232121232" + .as_bytes() + .try_into() + .unwrap(), + ), ) .unwrap(); if result != expected_result { diff --git a/stackslib/src/chainstate/stacks/miner.rs b/stackslib/src/chainstate/stacks/miner.rs index fd664a7dbf..04c3d7a2b5 100644 --- a/stackslib/src/chainstate/stacks/miner.rs +++ b/stackslib/src/chainstate/stacks/miner.rs @@ -548,7 +548,7 @@ impl TransactionResult { // recover original ClarityError ClarityRuntimeTxError::Acceptable { error, .. } => { if let clarity_error::Parse(ref parse_err) = error { - info!("Parse error: {}", parse_err); + info!("Parse error: {}", parse_err; "txid" => %tx.txid()); match &parse_err.err { ParseErrors::ExpressionStackDepthTooDeep | ParseErrors::VaryExpressionStackDepthTooDeep => {