stacks-core icon indicating copy to clipboard operation
stacks-core copied to clipboard

Incorrect tx_status after error

Open friedger opened this issue 4 years ago • 2 comments

Describe the bug The tx_status of https://stacks-node-api.mainnet.stacks.co/extended/v1/tx/0x38e2f50a4c410e2835a3497d0a7f68c2e81150a3f95956333c31d7b68beb647b?chain=mainnet is shown as abort_by_post_condition. However, the tx result is (err u5).

Expected behavior I'd expect the tx status as abort_by_response

Additional context First reported on https://github.com/blockstack/stacks-blockchain-api/issues/671 because the explorer shows the status of the tx wrongly.

friedger avatar Jul 23 '21 17:07 friedger

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '22 01:08 stale[bot]

Has this been fixed?

friedger avatar Aug 12 '22 05:08 friedger

Temporarily assigning @zone117x so this issue has an owner. Please feel free to re-assign as you see fit.

jcnelson avatar Feb 22 '23 03:02 jcnelson

I doubt I'm going to be working on code around this anytime soon. @friedger do you feel strongly that this behavior should be changed? I'm inclined to close this unless someone more familiar with this area of the code agrees with the change request.

zone117x avatar Feb 23 '23 12:02 zone117x

Yes, this is very visible and confusing for developers like the explorer developers.

Users of the explorer see the big warning that the post conditions were not satisfied.

As a workaround we could update the documentation and say that abort_by_poatxonditions does not imply that the tx was aborted by post conditions. This is only the case if the tx result is ok.

friedger avatar Feb 23 '23 15:02 friedger

As a workaround we could update the documentation and say that abort_by_post_conditions does not imply that the tx was aborted by post conditions

Would you agree that this is somewhat of an order of precedence issue with what we declare as the cause of the abort? If the tx had an error result, and also did not fulfill the post-condition requirements, then it sounds like the abort "reason" could arguably be both? Either way, I agree a more helpful error message should be displayed.

It sounds like this is something that could be handled client side. Both the tx status and result properties are available for clients to display a more helpful message like you've described.

If we changed this on the stacks-node, it would technically be breaking change to the event-stream history. And on the API side, I'd prefer not to override/transform data from the stacks-node. That usually backfires and causes more confusion.

zone117x avatar Feb 24 '23 11:02 zone117x

However, this is a bug.

friedger avatar Feb 24 '23 12:02 friedger

Assigning to @kantai to give some input. I'm not going to be working on this area of the code either way.

zone117x avatar Feb 24 '23 18:02 zone117x

Is this a bug, or just something that needs more information in the specification?

The transaction runs, and the result of the execution is (err u5). The transaction does not transfer the asset SP497E7RX3233ATBS2AB9G4WTHB63X5PBSP5VGAQ.boomboxes-cycle-12.b-12, which is required by the post condition. The stacks-node sees that the post condition failed and aborts the transaction.

It's true that the transaction would have been aborted because of (err u5) anyways, but regardless of this, the transaction's post conditions are not met: the stacks-node always checks post conditions, even if the transaction was being aborted.

The value result of the transaction is always provided exactly so that clients can differentiate between these kinds of cases.

kantai avatar Feb 24 '23 19:02 kantai

Thank you for the clarification.

Are there well known use cases where post conditions are met and the tx aborts due to an error?

friedger avatar Feb 24 '23 19:02 friedger

I’ll find a specific transaction to link, but you could always create such a case with the post conditions set to ALLOW mode. Contracts that have side effects without assets could also exhibit this case (for example, a PoX transaction can abort without any post conditions) even if you were using post conditions in DENY mode.

kantai avatar Feb 24 '23 19:02 kantai

Here's an example: https://explorer.hiro.so/txid/0xdbf8ae41ef3e9e709cda18f42ae3ea46783dcc5e6435fc246a4a28e8ce407722?chain=mainnet

kantai avatar Feb 24 '23 20:02 kantai

There is never a tx with a post condition that is satisfied when the tx fails with an error.

friedger avatar Feb 25 '23 07:02 friedger

Not exactly -- a transaction with one of [SENT_GT, SENT_GE, SENT_EQ] (for FTs) or [SENT] (for NFTs) condition codes cannot have their post condition satisfied when the tx fails with an error (because the post condition is asserting that something got sent, but because the tx failed with error, nothing did).

However, transactions with [SENT_LE, SENT_LT] or [NOT_SENT] condition codes can have their post condition satisfied when the tx fails with an error.

kantai avatar Feb 27 '23 16:02 kantai

I see. Thank you

friedger avatar Feb 27 '23 19:02 friedger