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

feat(clarity): Improve emitted events for Clarity post-conditions #4814

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

ldiego08
Copy link

@ldiego08 ldiego08 commented May 21, 2024

Description

Adds post-condition validation status to Stacks transaction receipts.

Applicable issues

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo
  • New integration test(s) added to bitcoin-tests.yml

Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 86.35097% with 49 lines in your changes missing coverage. Please review.

Project coverage is 83.27%. Comparing base (abe0a0a) to head (fb41b66).
Report is 4 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #4814       +/-   ##
===========================================
+ Coverage   19.14%   83.27%   +64.12%     
===========================================
  Files         465      470        +5     
  Lines      333874   335454     +1580     
  Branches        0      323      +323     
===========================================
+ Hits        63932   279345   +215413     
+ Misses     269942    56101   -213841     
- Partials        0        8        +8     
Files Coverage Δ
stackslib/src/chainstate/stacks/db/blocks.rs 90.09% <100.00%> (+66.53%) ⬆️
stackslib/src/chainstate/stacks/events.rs 83.33% <ø> (ø)
testnet/stacks-node/src/event_dispatcher.rs 85.44% <83.33%> (+27.00%) ⬆️
stackslib/src/chainstate/stacks/db/transactions.rs 97.58% <92.99%> (+93.35%) ⬆️
stackslib/src/chainstate/stacks/mod.rs 74.57% <25.71%> (+66.02%) ⬆️

... and 434 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b7f7295...fb41b66. Read the comment docs.

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

You're on the right track with this PR. Thanks for sending it over! 🙏 Just need to add some test coverage and address a couple other nits.

@ldiego08
Copy link
Author

@jcnelson, thanks for reviewing! This PR is ready for a second look.

Here's a summary of the changes:

  • Return a TransactionPostConditionStatus struct instead of just the failed post-condition to account for cases where moved assets aren't covered by a post-condition.
  • Update tests related to post-conditions to cover for introduced changes.
  • Add a post-condition status matcher to help assert in tests.

#4744 mentions that upstream event dispatchers should be updated as well, but it seems like they leverage the same StacksTransactionReceipt struct, so no changes are needed. If this is not the case, please let me know what else needs updating, and I'll do so!

@ldiego08 ldiego08 requested a review from jcnelson May 26, 2024 16:46
@ldiego08
Copy link
Author

@jcnelson seems like #4744 refers to this code.. If so, what would the recommended JSON output be for the receipt's post_condition_status?

@ldiego08 ldiego08 marked this pull request as ready for review May 30, 2024 21:16
Copy link
Author

Choose a reason for hiding this comment

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

Update on event dispatcher JSON output: I've added the post_condition_status field to the payload object. Not entirely sure of its JSON shape. @jcnelson if a different shape is desired, please let me know.

@ldiego08
Copy link
Author

@jcnelson (or @wileyj) - this PR is ready for another look in case anyone has bandwidth.

@wileyj
Copy link
Contributor

wileyj commented Jun 24, 2024

thanks @ldiego08 - can you rebase this against the develop branch?

@ldiego08 ldiego08 changed the base branch from master to develop June 24, 2024 15:49
@ldiego08 ldiego08 requested review from a team as code owners June 24, 2024 15:49
@ldiego08 ldiego08 changed the base branch from develop to master June 24, 2024 15:50
@ldiego08 ldiego08 force-pushed the feat/improve-clarity-emitted-events-post-conditions branch from fb41b66 to 8323f0d Compare June 24, 2024 15:53
@CLAassistant
Copy link

CLAassistant commented Jun 24, 2024

CLA assistant check
All committers have signed the CLA.

@ldiego08 ldiego08 changed the base branch from master to develop June 24, 2024 15:53
@ldiego08
Copy link
Author

@wileyj - done! Thanks for pointing me in the right direction. With the right base branch, reviewer groups have been tagged and other workflows triggered. :)

@wileyj wileyj requested review from obycode June 24, 2024 15:58
Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution @ldiego08! I have some suggestions that I think would simplify the code a bit.

@@ -578,6 +591,7 @@ impl StacksChainState {
post_condition_mode: &TransactionPostConditionMode,
origin_account: &StacksAccount,
asset_map: &AssetMap,
post_condition_statuses: &mut Vec<TransactionPostConditionStatus>,
Copy link
Contributor

Choose a reason for hiding this comment

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

How about instead of adding this vec, we change the return value to Result<Option<TransactionPostConditionStatus> and it returns Ok(None) on success or else Ok(Some(failing_condition))? I think that could simplify things.

Copy link
Author

@ldiego08 ldiego08 Jun 27, 2024

Choose a reason for hiding this comment

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

@obycode I originally tried that approach, but things got tangled up quickly. This function is passed in a callback to the Clarity VM's run_contract_call and bubbling up the failed post-condition from here to here where the AbortedByCallback error is created would require a more extensive and invasive refactor. That's why I resourced to a "post-condition stream" vec as a simpler solution. Also, seems like the callback is expecting other error cases? Eager to hear your thoughts as I might be missing something.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. I appreciate your patience; I have had some higher priority items recently. Someone will try to take a look soon and help push this forward.

stackslib/src/chainstate/stacks/mod.rs Outdated Show resolved Hide resolved

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TransactionPostConditionStatus {
Success,
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 we can remove this case.

stackslib/src/chainstate/stacks/db/transactions.rs Outdated Show resolved Hide resolved
stackslib/src/chainstate/stacks/db/transactions.rs Outdated Show resolved Hide resolved
stackslib/src/chainstate/stacks/db/transactions.rs Outdated Show resolved Hide resolved
@@ -1614,6 +1689,42 @@ pub mod test {
&TestBurnStateDB_2_05 as &dyn BurnStateDB,
];

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TransactionPostConditionStatusAssert {
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 enum is unnecessary and could be removed with some refactoring of the test code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve emitted events for Clarity post-conditions
5 participants