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/runtime analysis errors #3234

Merged

Conversation

jcnelson
Copy link
Member

@jcnelson jcnelson commented Aug 1, 2022

This PR makes all Error::Unchecked(..) Clarity errors encountered at runtime into runtime errors that do not invalidate the block. This feature is gated and only takes effect in Stacks 2.1.

return Ok(receipt);
} else {
// prior to 2.1, this is not permitted in a block.
error!("Unexpected analysis error invalidating transaction: if included, this will invalidate a block";
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be warn! level -- error level logs should mean that something is wrong and that the operator of the node should be trying to take action to remedy it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

auth.clone(),
TransactionPayload::new_smart_contract(
&"foo-impl".to_string(),
&runtime_checkerror_trait.to_string(),
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to be runtime_checkerror_impl?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 8799 to 8811
let (fee, tx_receipt) = StacksChainState::process_transaction(
&mut conn,
&signed_test_trait_checkerror_tx,
false,
)
.unwrap();
assert_eq!(fee, 0);

assert!(tx_receipt.vm_error.is_some());
let err_str = tx_receipt.vm_error.unwrap();
assert!(err_str
.find("TypeValueError(OptionalType(TraitReferenceType(TraitIdentifier ")
.is_some());
Copy link
Member

Choose a reason for hiding this comment

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

Can you add checks to this test for the following:

  1. In 2.1, the fee (which should be positive for the test to actually assert a change) is assessed against the payer's account, and the nonce is bumped for the failed transaction.
  2. In 2.05, the fee isn't assessed (again, it needs to be positive) against the payer's account, and the nonce isn't bumped for the failed transaction.
  3. In 2.1, the transaction is committed, but there's no state change. To do this, I think you'd need to invoke (flip) at some point in the test method before triggering the error. Then just assert that flip hasn't changed after the tx.

Then, I think this needs an additional (very similar) battery of tests for the case where the "handled" error comes from a contract publish -- I think if you add a (test .foo-impl) invocation to the bottom of the contract publish, it'll create such a situation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

…dies in tests; test `contract-call?` within a smart contract for runtime checkerrors
@codecov
Copy link

codecov bot commented Aug 1, 2022

Codecov Report

Merging #3234 (18cf7e3) into feat/bill-fee-before-tx-processing (8573330) will increase coverage by 54.93%.
The diff coverage is 99.26%.

@@                           Coverage Diff                           @@
##           feat/bill-fee-before-tx-processing    #3234       +/-   ##
=======================================================================
+ Coverage                               29.82%   84.75%   +54.93%     
=======================================================================
  Files                                     276      276               
  Lines                                  221418   221917      +499     
=======================================================================
+ Hits                                    66035   188091   +122056     
+ Misses                                 155383    33826   -121557     
Impacted Files Coverage Δ
src/chainstate/stacks/events.rs 66.66% <ø> (ø)
src/chainstate/stacks/db/transactions.rs 98.12% <99.26%> (+92.44%) ⬆️
src/chainstate/stacks/db/blocks.rs 89.58% <100.00%> (+61.20%) ⬆️
src/burnchains/bitcoin/mod.rs 37.68% <0.00%> (ø)
src/main.rs 0.08% <0.00%> (+0.08%) ⬆️
testnet/stacks-node/src/node.rs 82.90% <0.00%> (+0.12%) ⬆️
...-node/src/burnchains/bitcoin_regtest_controller.rs 86.67% <0.00%> (+0.25%) ⬆️
testnet/puppet-chain/src/main.rs 0.41% <0.00%> (+0.41%) ⬆️
...t/stacks-node/src/burnchains/mocknet_controller.rs 77.48% <0.00%> (+0.43%) ⬆️
stacks-common/src/types/chainstate.rs 88.60% <0.00%> (+0.51%) ⬆️
... and 237 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

Copy link
Contributor

@gregorycoppola gregorycoppola left a comment

Choose a reason for hiding this comment

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

Overall, looks good to me.

  1. Waiting to see the response to kantai's question about tests.
  2. Seems like some context is missing from the description. Is there an issue or some higher-level plan you can link to explain why this is happening?

@jcnelson
Copy link
Member Author

jcnelson commented Aug 2, 2022

@gregorycoppola Seems like some context is missing from the description. Is there an issue or some higher-level plan you can link to explain why this is happening?

See #3107, which this PR addresses.

…e changes materialize when a transaction fails due to an analysis error found at runtime
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.

LGTM

Copy link
Member

@kantai kantai left a comment

Choose a reason for hiding this comment

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

LGTM!

@jcnelson jcnelson merged commit 14ea30a into feat/bill-fee-before-tx-processing Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants