Skip to content

Commit 94b5ce8

Browse files
committed
fix: include txid in failure logs
1 parent 2c2afbc commit 94b5ce8

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

stackslib/src/chainstate/stacks/db/transactions.rs

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ impl StacksChainState {
550550
post_condition_mode: &TransactionPostConditionMode,
551551
origin_account: &StacksAccount,
552552
asset_map: &AssetMap,
553+
txid: Txid,
553554
) -> Result<bool, InterpreterError> {
554555
let mut checked_fungible_assets: HashMap<PrincipalData, HashSet<AssetIdentifier>> =
555556
HashMap::new();
@@ -578,7 +579,7 @@ impl StacksChainState {
578579
if !condition_code.check(*amount_sent_condition as u128, amount_sent) {
579580
info!(
580581
"Post-condition check failure on STX owned by {}: {:?} {:?} {}",
581-
account_principal, amount_sent_condition, condition_code, amount_sent
582+
account_principal, amount_sent_condition, condition_code, amount_sent; "txid" => %txid
582583
);
583584
return Ok(false);
584585
}
@@ -622,7 +623,7 @@ impl StacksChainState {
622623
.get_fungible_tokens(&account_principal, &asset_id)
623624
.unwrap_or(0);
624625
if !condition_code.check(*amount_sent_condition as u128, amount_sent) {
625-
info!("Post-condition check failure on fungible asset {} owned by {}: {} {:?} {}", &asset_id, account_principal, amount_sent_condition, condition_code, amount_sent);
626+
info!("Post-condition check failure on fungible asset {} owned by {}: {} {:?} {}", &asset_id, account_principal, amount_sent_condition, condition_code, amount_sent; "txid" => %txid);
626627
return Ok(false);
627628
}
628629

@@ -656,7 +657,7 @@ impl StacksChainState {
656657
.get_nonfungible_tokens(&account_principal, &asset_id)
657658
.unwrap_or(&empty_assets);
658659
if !condition_code.check(asset_value, assets_sent) {
659-
info!("Post-condition check failure on non-fungible asset {} owned by {}: {:?} {:?}", &asset_id, account_principal, &asset_value, condition_code);
660+
info!("Post-condition check failure on non-fungible asset {} owned by {}: {:?} {:?}", &asset_id, account_principal, &asset_value, condition_code; "txid" => %txid);
660661
return Ok(false);
661662
}
662663

@@ -698,18 +699,18 @@ impl StacksChainState {
698699
// each value must be covered
699700
for v in values {
700701
if !nfts.contains(&v.clone().try_into()?) {
701-
info!("Post-condition check failure: Non-fungible asset {} value {:?} was moved by {} but not checked", &asset_identifier, &v, &principal);
702+
info!("Post-condition check failure: Non-fungible asset {} value {:?} was moved by {} but not checked", &asset_identifier, &v, &principal; "txid" => %txid);
702703
return Ok(false);
703704
}
704705
}
705706
} else {
706707
// no values covered
707-
info!("Post-condition check failure: No checks for non-fungible asset type {} moved by {}", &asset_identifier, &principal);
708+
info!("Post-condition check failure: No checks for non-fungible asset type {} moved by {}", &asset_identifier, &principal; "txid" => %txid);
708709
return Ok(false);
709710
}
710711
} else {
711712
// no NFT for this principal
712-
info!("Post-condition check failure: No checks for any non-fungible assets, but moved {} by {}", &asset_identifier, &principal);
713+
info!("Post-condition check failure: No checks for any non-fungible assets, but moved {} by {}", &asset_identifier, &principal; "txid" => %txid);
713714
return Ok(false);
714715
}
715716
}
@@ -719,11 +720,11 @@ impl StacksChainState {
719720
checked_fungible_assets.get(&principal)
720721
{
721722
if !checked_ft_asset_ids.contains(&asset_identifier) {
722-
info!("Post-condition check failure: checks did not cover transfer of {} by {}", &asset_identifier, &principal);
723+
info!("Post-condition check failure: checks did not cover transfer of {} by {}", &asset_identifier, &principal; "txid" => %txid);
723724
return Ok(false);
724725
}
725726
} else {
726-
info!("Post-condition check failure: No checks for fungible token type {} moved by {}", &asset_identifier, &principal);
727+
info!("Post-condition check failure: No checks for fungible token type {} moved by {}", &asset_identifier, &principal; "txid" => %txid);
727728
return Ok(false);
728729
}
729730
}
@@ -950,14 +951,14 @@ impl StacksChainState {
950951
// Their presence in this variant makes the transaction invalid.
951952
if tx.post_conditions.len() > 0 {
952953
let msg = format!("Invalid Stacks transaction: TokenTransfer transactions do not support post-conditions");
953-
warn!("{}", &msg);
954+
warn!("{}", &msg; "txid" => %tx.txid());
954955

955956
return Err(Error::InvalidStacksTransaction(msg, false));
956957
}
957958

958959
if *addr == origin_account.principal {
959960
let msg = format!("Invalid TokenTransfer: address tried to send to itself");
960-
warn!("{}", &msg);
961+
warn!("{}", &msg; "txid" => %tx.txid());
961962
return Err(Error::InvalidStacksTransaction(msg, false));
962963
}
963964

@@ -1009,6 +1010,7 @@ impl StacksChainState {
10091010
&tx.post_condition_mode,
10101011
origin_account,
10111012
asset_map,
1013+
tx.txid(),
10121014
)
10131015
.expect("FATAL: error while evaluating post-conditions")
10141016
},
@@ -1026,7 +1028,8 @@ impl StacksChainState {
10261028
"function_name" => %contract_call.function_name,
10271029
"function_args" => %VecDisplay(&contract_call.function_args),
10281030
"return_value" => %return_value,
1029-
"cost" => ?total_cost);
1031+
"cost" => ?total_cost,
1032+
"txid" => %tx.txid());
10301033
(return_value, asset_map, events)
10311034
}
10321035
Err(e) => match handle_clarity_runtime_error(e) {
@@ -1035,14 +1038,16 @@ impl StacksChainState {
10351038
"contract_name" => %contract_id,
10361039
"function_name" => %contract_call.function_name,
10371040
"function_args" => %VecDisplay(&contract_call.function_args),
1038-
"error" => ?error);
1041+
"error" => ?error,
1042+
"txid" => %tx.txid());
10391043
(Value::err_none(), AssetMap::new(), vec![])
10401044
}
10411045
ClarityRuntimeTxError::AbortedByCallback(value, assets, events) => {
10421046
info!("Contract-call aborted by post-condition";
10431047
"contract_name" => %contract_id,
10441048
"function_name" => %contract_call.function_name,
1045-
"function_args" => %VecDisplay(&contract_call.function_args));
1049+
"function_args" => %VecDisplay(&contract_call.function_args),
1050+
"txid" => %tx.txid());
10461051
let receipt = StacksTransactionReceipt::from_condition_aborted_contract_call(
10471052
tx.clone(),
10481053
events,
@@ -1063,7 +1068,8 @@ impl StacksChainState {
10631068
"contract_name" => %contract_id,
10641069
"function_name" => %contract_call.function_name,
10651070
"function_args" => %VecDisplay(&contract_call.function_args),
1066-
"error" => %check_error);
1071+
"error" => %check_error,
1072+
"txid" => %tx.txid());
10671073

10681074
let receipt =
10691075
StacksTransactionReceipt::from_runtime_failure_contract_call(
@@ -1078,7 +1084,8 @@ impl StacksChainState {
10781084
"contract_name" => %contract_id,
10791085
"function_name" => %contract_call.function_name,
10801086
"function_args" => %VecDisplay(&contract_call.function_args),
1081-
"error" => %check_error);
1087+
"error" => %check_error,
1088+
"txid" => %tx.txid());
10821089
return Err(Error::ClarityError(clarity_error::Interpreter(
10831090
InterpreterError::Unchecked(check_error),
10841091
)));
@@ -1089,7 +1096,8 @@ impl StacksChainState {
10891096
"contract_name" => %contract_id,
10901097
"function_name" => %contract_call.function_name,
10911098
"function_args" => %VecDisplay(&contract_call.function_args),
1092-
"error" => ?e);
1099+
"error" => ?e,
1100+
"txid" => %tx.txid());
10931101
return Err(Error::ClarityError(e));
10941102
}
10951103
},
@@ -1226,6 +1234,7 @@ impl StacksChainState {
12261234
&tx.post_condition_mode,
12271235
origin_account,
12281236
asset_map,
1237+
tx.txid(),
12291238
)
12301239
.expect("FATAL: error while evaluating post-conditions")
12311240
},
@@ -6796,6 +6805,12 @@ pub mod test {
67966805
mode,
67976806
origin,
67986807
&ft_transfer_2,
6808+
Txid(
6809+
"1232121232121232121232121232121232121232121232121232121232121232"
6810+
.as_bytes()
6811+
.try_into()
6812+
.unwrap(),
6813+
),
67996814
)
68006815
.unwrap();
68016816
if result != expected_result {
@@ -7149,6 +7164,12 @@ pub mod test {
71497164
mode,
71507165
origin,
71517166
&nft_transfer_2,
7167+
Txid(
7168+
"1232121232121232121232121232121232121232121232121232121232121232"
7169+
.as_bytes()
7170+
.try_into()
7171+
.unwrap(),
7172+
),
71527173
)
71537174
.unwrap();
71547175
if result != expected_result {
@@ -7966,6 +7987,12 @@ pub mod test {
79667987
post_condition_mode,
79677988
origin_account,
79687989
asset_map,
7990+
Txid(
7991+
"1232121232121232121232121232121232121232121232121232121232121232"
7992+
.as_bytes()
7993+
.try_into()
7994+
.unwrap(),
7995+
),
79697996
)
79707997
.unwrap();
79717998
if result != expected_result {

stackslib/src/chainstate/stacks/miner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ impl TransactionResult {
548548
// recover original ClarityError
549549
ClarityRuntimeTxError::Acceptable { error, .. } => {
550550
if let clarity_error::Parse(ref parse_err) = error {
551-
info!("Parse error: {}", parse_err);
551+
info!("Parse error: {}", parse_err; "txid" => %tx.txid());
552552
match &parse_err.err {
553553
ParseErrors::ExpressionStackDepthTooDeep
554554
| ParseErrors::VaryExpressionStackDepthTooDeep => {

0 commit comments

Comments
 (0)