Skip to content

Commit

Permalink
fix: include txid in failure logs
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Feb 26, 2024
1 parent 2c2afbc commit 94b5ce8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
59 changes: 43 additions & 16 deletions stackslib/src/chainstate/stacks/db/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ impl StacksChainState {
post_condition_mode: &TransactionPostConditionMode,
origin_account: &StacksAccount,
asset_map: &AssetMap,
txid: Txid,
) -> Result<bool, InterpreterError> {
let mut checked_fungible_assets: HashMap<PrincipalData, HashSet<AssetIdentifier>> =
HashMap::new();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -1009,6 +1010,7 @@ impl StacksChainState {
&tx.post_condition_mode,
origin_account,
asset_map,
tx.txid(),
)
.expect("FATAL: error while evaluating post-conditions")
},
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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),
)));
Expand All @@ -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));
}
},
Expand Down Expand Up @@ -1226,6 +1234,7 @@ impl StacksChainState {
&tx.post_condition_mode,
origin_account,
asset_map,
tx.txid(),
)
.expect("FATAL: error while evaluating post-conditions")
},
Expand Down Expand Up @@ -6796,6 +6805,12 @@ pub mod test {
mode,
origin,
&ft_transfer_2,
Txid(
"1232121232121232121232121232121232121232121232121232121232121232"
.as_bytes()
.try_into()
.unwrap(),
),
)
.unwrap();
if result != expected_result {
Expand Down Expand Up @@ -7149,6 +7164,12 @@ pub mod test {
mode,
origin,
&nft_transfer_2,
Txid(
"1232121232121232121232121232121232121232121232121232121232121232"
.as_bytes()
.try_into()
.unwrap(),
),
)
.unwrap();
if result != expected_result {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 94b5ce8

Please sign in to comment.