Skip to content

Commit ebe6adb

Browse files
authored
Merge pull request #4396 from stacks-network/Add-txid-to-post-condition-check
fix: include txid in more failure logs
2 parents d11ed3c + ee2ef2d commit ebe6adb

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ impl StacksChainState {
578578
post_condition_mode: &TransactionPostConditionMode,
579579
origin_account: &StacksAccount,
580580
asset_map: &AssetMap,
581+
txid: Txid,
581582
) -> Result<bool, InterpreterError> {
582583
let mut checked_fungible_assets: HashMap<PrincipalData, HashSet<AssetIdentifier>> =
583584
HashMap::new();
@@ -606,7 +607,7 @@ impl StacksChainState {
606607
if !condition_code.check(u128::from(*amount_sent_condition), amount_sent) {
607608
info!(
608609
"Post-condition check failure on STX owned by {}: {:?} {:?} {}",
609-
account_principal, amount_sent_condition, condition_code, amount_sent
610+
account_principal, amount_sent_condition, condition_code, amount_sent; "txid" => %txid
610611
);
611612
return Ok(false);
612613
}
@@ -650,7 +651,7 @@ impl StacksChainState {
650651
.get_fungible_tokens(&account_principal, &asset_id)
651652
.unwrap_or(0);
652653
if !condition_code.check(u128::from(*amount_sent_condition), amount_sent) {
653-
info!("Post-condition check failure on fungible asset {} owned by {}: {} {:?} {}", &asset_id, account_principal, amount_sent_condition, condition_code, amount_sent);
654+
info!("Post-condition check failure on fungible asset {} owned by {}: {} {:?} {}", &asset_id, account_principal, amount_sent_condition, condition_code, amount_sent; "txid" => %txid);
654655
return Ok(false);
655656
}
656657

@@ -684,7 +685,7 @@ impl StacksChainState {
684685
.get_nonfungible_tokens(&account_principal, &asset_id)
685686
.unwrap_or(&empty_assets);
686687
if !condition_code.check(asset_value, assets_sent) {
687-
info!("Post-condition check failure on non-fungible asset {} owned by {}: {:?} {:?}", &asset_id, account_principal, &asset_value, condition_code);
688+
info!("Post-condition check failure on non-fungible asset {} owned by {}: {:?} {:?}", &asset_id, account_principal, &asset_value, condition_code; "txid" => %txid);
688689
return Ok(false);
689690
}
690691

@@ -726,18 +727,18 @@ impl StacksChainState {
726727
// each value must be covered
727728
for v in values {
728729
if !nfts.contains(&v.clone().try_into()?) {
729-
info!("Post-condition check failure: Non-fungible asset {} value {:?} was moved by {} but not checked", &asset_identifier, &v, &principal);
730+
info!("Post-condition check failure: Non-fungible asset {} value {:?} was moved by {} but not checked", &asset_identifier, &v, &principal; "txid" => %txid);
730731
return Ok(false);
731732
}
732733
}
733734
} else {
734735
// no values covered
735-
info!("Post-condition check failure: No checks for non-fungible asset type {} moved by {}", &asset_identifier, &principal);
736+
info!("Post-condition check failure: No checks for non-fungible asset type {} moved by {}", &asset_identifier, &principal; "txid" => %txid);
736737
return Ok(false);
737738
}
738739
} else {
739740
// no NFT for this principal
740-
info!("Post-condition check failure: No checks for any non-fungible assets, but moved {} by {}", &asset_identifier, &principal);
741+
info!("Post-condition check failure: No checks for any non-fungible assets, but moved {} by {}", &asset_identifier, &principal; "txid" => %txid);
741742
return Ok(false);
742743
}
743744
}
@@ -747,11 +748,11 @@ impl StacksChainState {
747748
checked_fungible_assets.get(&principal)
748749
{
749750
if !checked_ft_asset_ids.contains(&asset_identifier) {
750-
info!("Post-condition check failure: checks did not cover transfer of {} by {}", &asset_identifier, &principal);
751+
info!("Post-condition check failure: checks did not cover transfer of {} by {}", &asset_identifier, &principal; "txid" => %txid);
751752
return Ok(false);
752753
}
753754
} else {
754-
info!("Post-condition check failure: No checks for fungible token type {} moved by {}", &asset_identifier, &principal);
755+
info!("Post-condition check failure: No checks for fungible token type {} moved by {}", &asset_identifier, &principal; "txid" => %txid);
755756
return Ok(false);
756757
}
757758
}
@@ -980,14 +981,14 @@ impl StacksChainState {
980981
// Their presence in this variant makes the transaction invalid.
981982
if tx.post_conditions.len() > 0 {
982983
let msg = format!("Invalid Stacks transaction: TokenTransfer transactions do not support post-conditions");
983-
info!("{}", &msg);
984+
info!("{}", &msg; "txid" => %tx.txid());
984985

985986
return Err(Error::InvalidStacksTransaction(msg, false));
986987
}
987988

988989
if *addr == origin_account.principal {
989990
let msg = format!("Invalid TokenTransfer: address tried to send to itself");
990-
info!("{}", &msg);
991+
info!("{}", &msg; "txid" => %tx.txid());
991992
return Err(Error::InvalidStacksTransaction(msg, false));
992993
}
993994

@@ -1039,6 +1040,7 @@ impl StacksChainState {
10391040
&tx.post_condition_mode,
10401041
origin_account,
10411042
asset_map,
1043+
tx.txid(),
10421044
)
10431045
.expect("FATAL: error while evaluating post-conditions")
10441046
},
@@ -1274,6 +1276,7 @@ impl StacksChainState {
12741276
&tx.post_condition_mode,
12751277
origin_account,
12761278
asset_map,
1279+
tx.txid(),
12771280
)
12781281
.expect("FATAL: error while evaluating post-conditions")
12791282
},
@@ -6873,6 +6876,7 @@ pub mod test {
68736876
mode,
68746877
origin,
68756878
&ft_transfer_2,
6879+
Txid([0; 32]),
68766880
)
68776881
.unwrap();
68786882
if result != expected_result {
@@ -7226,6 +7230,7 @@ pub mod test {
72267230
mode,
72277231
origin,
72287232
&nft_transfer_2,
7233+
Txid([0; 32]),
72297234
)
72307235
.unwrap();
72317236
if result != expected_result {
@@ -8043,6 +8048,7 @@ pub mod test {
80438048
post_condition_mode,
80448049
origin_account,
80458050
asset_map,
8051+
Txid([0; 32]),
80468052
)
80478053
.unwrap();
80488054
if result != expected_result {

stackslib/src/chainstate/stacks/miner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ impl TransactionResult {
585585
// recover original ClarityError
586586
ClarityRuntimeTxError::Acceptable { error, .. } => {
587587
if let clarity_error::Parse(ref parse_err) = error {
588-
info!("Parse error: {}", parse_err);
588+
info!("Parse error: {}", parse_err; "txid" => %tx.txid());
589589
match &parse_err.err {
590590
ParseErrors::ExpressionStackDepthTooDeep
591591
| ParseErrors::VaryExpressionStackDepthTooDeep => {

stackslib/src/net/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,7 @@ pub mod test {
17341734

17351735
use clarity::boot_util::boot_code_id;
17361736
use clarity::types::sqlite::NO_PARAMS;
1737+
use clarity::vm::ast::parser::v1::CONTRACT_MAX_NAME_LENGTH;
17371738
use clarity::vm::ast::ASTRules;
17381739
use clarity::vm::costs::ExecutionCost;
17391740
use clarity::vm::database::STXBalance;
@@ -2486,7 +2487,17 @@ pub mod test {
24862487
let smart_contract = TransactionPayload::SmartContract(
24872488
TransactionSmartContract {
24882489
name: ContractName::try_from(
2489-
conf.test_name.replace("::", "-").to_string(),
2490+
conf.test_name
2491+
.replace("::", "-")
2492+
.chars()
2493+
.skip(
2494+
conf.test_name
2495+
.len()
2496+
.saturating_sub(CONTRACT_MAX_NAME_LENGTH),
2497+
)
2498+
.collect::<String>()
2499+
.trim_start_matches(|c: char| !c.is_alphabetic())
2500+
.to_string(),
24902501
)
24912502
.expect("FATAL: invalid boot-code contract name"),
24922503
code_body: StacksString::from_str(&conf.setup_code)

0 commit comments

Comments
 (0)