Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include txid in more failure logs #4396

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 45 additions & 18 deletions stackslib/src/chainstate/stacks/db/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,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 @@ -596,7 +597,7 @@ impl StacksChainState {
if !condition_code.check(u128::from(*amount_sent_condition), 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 @@ -640,7 +641,7 @@ impl StacksChainState {
.get_fungible_tokens(&account_principal, &asset_id)
.unwrap_or(0);
if !condition_code.check(u128::from(*amount_sent_condition), 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 @@ -674,7 +675,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 @@ -716,18 +717,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 @@ -737,11 +738,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 @@ -970,14 +971,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");
info!("{}", &msg);
info!("{}", &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");
info!("{}", &msg);
info!("{}", &msg; "txid" => %tx.txid());
return Err(Error::InvalidStacksTransaction(msg, false));
}

Expand Down Expand Up @@ -1029,6 +1030,7 @@ impl StacksChainState {
&tx.post_condition_mode,
origin_account,
asset_map,
tx.txid(),
)
.expect("FATAL: error while evaluating post-conditions")
},
Expand All @@ -1049,7 +1051,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());
janniks marked this conversation as resolved.
Show resolved Hide resolved
(return_value, asset_map, events)
}
Err(e) => match handle_clarity_runtime_error(e) {
Expand All @@ -1061,7 +1064,8 @@ 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) => {
Expand All @@ -1071,7 +1075,8 @@ impl StacksChainState {
"origin_nonce" => %origin_account.nonce,
"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 @@ -1095,7 +1100,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 @@ -1113,7 +1119,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 @@ -1127,7 +1134,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 @@ -1264,6 +1272,7 @@ impl StacksChainState {
&tx.post_condition_mode,
origin_account,
asset_map,
tx.txid(),
)
.expect("FATAL: error while evaluating post-conditions")
},
Expand Down Expand Up @@ -6863,6 +6872,12 @@ pub mod test {
mode,
origin,
&ft_transfer_2,
Txid(
"1232121232121232121232121232121232121232121232121232121232121232"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this string is too long. Try 32 chars: "12321212321212321212321212321212"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even simpler, Txid([0;32]).

.as_bytes()
.try_into()
.unwrap(),
),
)
.unwrap();
if result != expected_result {
Expand Down Expand Up @@ -7216,6 +7231,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 @@ -8033,6 +8054,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 Expand Up @@ -9038,7 +9065,7 @@ pub mod test {
(as-contract
(stx-transfer? amount tx-sender recipient))
)

(stx-transfer? u500000000 tx-sender (as-contract tx-sender))
"#;

Expand Down Expand Up @@ -9203,7 +9230,7 @@ pub mod test {
(as-contract
(stx-transfer? amount tx-sender recipient))
)

(stx-transfer? u500000000 tx-sender (as-contract tx-sender))
"#;

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 @@ -553,7 +553,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
15 changes: 14 additions & 1 deletion stackslib/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,7 @@ pub mod test {
use std::{fs, io, thread};

use clarity::boot_util::boot_code_id;
use clarity::vm::ast::parser::v1::CONTRACT_MAX_NAME_LENGTH;
use clarity::vm::ast::ASTRules;
use clarity::vm::costs::ExecutionCost;
use clarity::vm::database::STXBalance;
Expand Down Expand Up @@ -2403,7 +2404,19 @@ pub mod test {
let smart_contract = TransactionPayload::SmartContract(
TransactionSmartContract {
name: ContractName::try_from(
conf.test_name.replace("::", "-").to_string(),
conf.test_name
.replace("::", "-")
.to_string()
janniks marked this conversation as resolved.
Show resolved Hide resolved
.chars()
// ensure auto-generated contract names are not too long
.skip(
conf.test_name
.len()
.saturating_sub(CONTRACT_MAX_NAME_LENGTH),
)
.collect::<String>()
.trim_start_matches(|c: char| !c.is_alphabetic())
janniks marked this conversation as resolved.
Show resolved Hide resolved
.to_string(),
)
.expect("FATAL: invalid boot-code contract name"),
code_body: StacksString::from_str(&conf.setup_code)
Expand Down