Skip to content

Commit 829a96e

Browse files
committed
feat: include PC abort reason in tx receipt
1 parent 9d4cc3a commit 829a96e

File tree

20 files changed

+217
-169
lines changed

20 files changed

+217
-169
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to the versioning scheme outlined in the [README.md](README.md).
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Include a reason string in the transaction receipt when a transaction is rolled back due to a post-condition. This should help users in understanding what went wrong.
13+
814
## [3.1.0.0.8]
915

1016
### Added

clarity/src/vm/clarity.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum Error {
2020
Interpreter(InterpreterError),
2121
BadTransaction(String),
2222
CostError(ExecutionCost, ExecutionCost),
23-
AbortedByCallback(Option<Value>, AssetMap, Vec<StacksTransactionEvent>),
23+
AbortedByCallback(Option<Value>, AssetMap, Vec<StacksTransactionEvent>, String),
2424
}
2525

2626
impl fmt::Display for Error {
@@ -175,9 +175,9 @@ pub trait TransactionConnection: ClarityConnection {
175175
&mut self,
176176
to_do: F,
177177
abort_call_back: A,
178-
) -> Result<(R, AssetMap, Vec<StacksTransactionEvent>, bool), E>
178+
) -> Result<(R, AssetMap, Vec<StacksTransactionEvent>, Option<String>), E>
179179
where
180-
A: FnOnce(&AssetMap, &mut ClarityDatabase) -> bool,
180+
A: FnOnce(&AssetMap, &mut ClarityDatabase) -> Option<String>,
181181
F: FnOnce(&mut OwnedEnvironment) -> Result<(R, AssetMap, Vec<StacksTransactionEvent>), E>,
182182
E: From<InterpreterError>;
183183

@@ -283,7 +283,7 @@ pub trait TransactionConnection: ClarityConnection {
283283
.stx_transfer(from, to, amount, memo)
284284
.map_err(Error::from)
285285
},
286-
|_, _| false,
286+
|_, _| None,
287287
)
288288
.map(|(value, assets, events, _)| (value, assets, events))
289289
}
@@ -305,7 +305,7 @@ pub trait TransactionConnection: ClarityConnection {
305305
max_execution_time: Option<std::time::Duration>,
306306
) -> Result<(Value, AssetMap, Vec<StacksTransactionEvent>), Error>
307307
where
308-
F: FnOnce(&AssetMap, &mut ClarityDatabase) -> bool,
308+
F: FnOnce(&AssetMap, &mut ClarityDatabase) -> Option<String>,
309309
{
310310
let expr_args: Vec<_> = args
311311
.iter()
@@ -332,8 +332,13 @@ pub trait TransactionConnection: ClarityConnection {
332332
abort_call_back,
333333
)
334334
.and_then(|(value, assets, events, aborted)| {
335-
if aborted {
336-
Err(Error::AbortedByCallback(Some(value), assets, events))
335+
if let Some(aborted) = aborted {
336+
Err(Error::AbortedByCallback(
337+
Some(value),
338+
assets,
339+
events,
340+
aborted,
341+
))
337342
} else {
338343
Ok((value, assets, events))
339344
}
@@ -357,7 +362,7 @@ pub trait TransactionConnection: ClarityConnection {
357362
max_execution_time: Option<std::time::Duration>,
358363
) -> Result<(AssetMap, Vec<StacksTransactionEvent>), Error>
359364
where
360-
F: FnOnce(&AssetMap, &mut ClarityDatabase) -> bool,
365+
F: FnOnce(&AssetMap, &mut ClarityDatabase) -> Option<String>,
361366
{
362367
let (_, asset_map, events, aborted) = self.with_abort_callback(
363368
|vm_env| {
@@ -378,8 +383,8 @@ pub trait TransactionConnection: ClarityConnection {
378383
},
379384
abort_call_back,
380385
)?;
381-
if aborted {
382-
Err(Error::AbortedByCallback(None, asset_map, events))
386+
if let Some(aborted) = aborted {
387+
Err(Error::AbortedByCallback(None, asset_map, events, aborted))
383388
} else {
384389
Ok((asset_map, events))
385390
}

stackslib/src/chainstate/coordinator/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pub fn setup_states_with_epochs(
391391
Value::UInt(burnchain.pox_constants.reward_cycle_length as u128),
392392
Value::UInt(burnchain.pox_constants.pox_rejection_fraction as u128),
393393
],
394-
|_, _| false,
394+
|_, _| None,
395395
None,
396396
)
397397
.expect("Failed to set burnchain parameters in PoX contract");

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4945,7 +4945,7 @@ impl NakamotoChainState {
49454945
&ast,
49464946
&contract_content,
49474947
None,
4948-
|_, _| false,
4948+
|_, _| None,
49494949
None,
49504950
)
49514951
.unwrap();

stackslib/src/chainstate/nakamoto/signer_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl NakamotoSigners {
335335
)
336336
})
337337
},
338-
|_, _| false,
338+
|_, _| None,
339339
)
340340
.expect("FATAL: failed to update signer stackerdb");
341341

stackslib/src/chainstate/stacks/boot/contract_tests.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ fn pox_2_delegate_extend_units() {
11771177
Value::UInt(25),
11781178
Value::UInt(0),
11791179
],
1180-
|_, _| false,
1180+
|_, _| None,
11811181
None,
11821182
)
11831183
})
@@ -1780,15 +1780,7 @@ fn test_deploy_smart_contract(
17801780
block.as_transaction(|tx| {
17811781
let (ast, analysis) =
17821782
tx.analyze_smart_contract(contract_id, version, content, ASTRules::PrecheckSize)?;
1783-
tx.initialize_smart_contract(
1784-
contract_id,
1785-
version,
1786-
&ast,
1787-
content,
1788-
None,
1789-
|_, _| false,
1790-
None,
1791-
)?;
1783+
tx.initialize_smart_contract(contract_id, version, &ast, content, None, |_, _| None, None)?;
17921784
tx.save_analysis(contract_id, &analysis)?;
17931785
return Ok(());
17941786
})

stackslib/src/chainstate/stacks/boot/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl StacksChainState {
562562
)
563563
})
564564
},
565-
|_, _| false,
565+
|_, _| None,
566566
)
567567
.expect("FATAL: failed to handle PoX unlock");
568568

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4175,7 +4175,7 @@ impl StacksChainState {
41754175
&boot_code_id(active_pox_contract, mainnet),
41764176
"stack-stx",
41774177
&args,
4178-
|_, _| false,
4178+
|_, _| None,
41794179
None,
41804180
)
41814181
});
@@ -4384,7 +4384,7 @@ impl StacksChainState {
43844384
until_burn_height_val,
43854385
reward_addr_val,
43864386
],
4387-
|_, _| false,
4387+
|_, _| None,
43884388
None,
43894389
)
43904390
});
@@ -4491,7 +4491,7 @@ impl StacksChainState {
44914491
Value::UInt(round.clone().into()),
44924492
Value::UInt(reward_cycle.clone().into()),
44934493
],
4494-
|_, _| false,
4494+
|_, _| None,
44954495
None,
44964496
)
44974497
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ impl StacksChainState {
16241624
&contract,
16251625
"set-burnchain-parameters",
16261626
&params,
1627-
|_, _| false,
1627+
|_, _| None,
16281628
None,
16291629
)
16301630
.expect("Failed to set burnchain parameters in PoX contract");

0 commit comments

Comments
 (0)