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

Merged
merged 15 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 16 additions & 10 deletions stackslib/src/chainstate/stacks/db/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,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 @@ -606,7 +607,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 @@ -650,7 +651,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 @@ -684,7 +685,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 @@ -726,18 +727,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 @@ -747,11 +748,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 @@ -980,14 +981,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 @@ -1039,6 +1040,7 @@ impl StacksChainState {
&tx.post_condition_mode,
origin_account,
asset_map,
tx.txid(),
)
.expect("FATAL: error while evaluating post-conditions")
},
Expand Down Expand Up @@ -1274,6 +1276,7 @@ impl StacksChainState {
&tx.post_condition_mode,
origin_account,
asset_map,
tx.txid(),
)
.expect("FATAL: error while evaluating post-conditions")
},
Expand Down Expand Up @@ -6873,6 +6876,7 @@ pub mod test {
mode,
origin,
&ft_transfer_2,
Txid([0; 32]),
)
.unwrap();
if result != expected_result {
Expand Down Expand Up @@ -7226,6 +7230,7 @@ pub mod test {
mode,
origin,
&nft_transfer_2,
Txid([0; 32]),
)
.unwrap();
if result != expected_result {
Expand Down Expand Up @@ -8043,6 +8048,7 @@ pub mod test {
post_condition_mode,
origin_account,
asset_map,
Txid([0; 32]),
)
.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 @@ -585,7 +585,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
13 changes: 12 additions & 1 deletion stackslib/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,7 @@ pub mod test {

use clarity::boot_util::boot_code_id;
use clarity::types::sqlite::NO_PARAMS;
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 @@ -2486,7 +2487,17 @@ pub mod test {
let smart_contract = TransactionPayload::SmartContract(
TransactionSmartContract {
name: ContractName::try_from(
conf.test_name.replace("::", "-").to_string(),
conf.test_name
.replace("::", "-")
.chars()
.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
Loading