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

Fix/sc txn errors #523

Closed
wants to merge 1 commit into from
Closed

Fix/sc txn errors #523

wants to merge 1 commit into from

Conversation

bbist
Copy link
Contributor

@bbist bbist commented Sep 14, 2021

This PR fixes the problem pointed out in 0chain/zboxcli#53, but is part of general solution that handles all smartcontract errors.
As the failed smartcontract transaction (+ it's error) become part of a block, the application should ensure that both the block generator as well as the block verifier gets same error while processing same transaction. Otherwise, the verification would fail and the block would be discarded.

@bbist bbist changed the base branch from master to staging September 14, 2021 10:04
return
txn.TransactionOutput = err.Error()
txn.Status = transaction.TxnFail
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Please do not ignore the returned error if the transaction execute failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was the intention that failed smart contract transactions not be considered internal failures and instead become part of the block. If an error is returned, a transaction will be ignored.
Could you suggest some unintended consequences if you're aware of something?

Copy link
Member

Choose a reason for hiding this comment

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

Transactions could fail for different reasons, and we can not ignore all of the transactions directly. Check the following situations:
a) The transactions are invalid by themself, we should and must ignore them (The question is whether this transactions could be packed into a block, need further check)
b) The transactions are valid, and it could be executed successfully by most of the miners and sharders, except some miners that do not have sufficient state in MPT. In this situation, if we ignore the transaction, and continue the block state compute, the block's MPT state would be different from others, and we will see the mismatch state hash error. What we should do is return, instead of continue the block state computing.

Copy link
Member

Choose a reason for hiding this comment

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

So basically, we need to differ the transaction fail errors.
a) invalid transactions by themself
b) Transactions are valid, but the miner is not ready yet to execute the transactions.

Choose a reason for hiding this comment

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

Might be a dumb question, but could we check the transaction validity when the client submits it? Then it'd be no surprise for the txn to be discarded and not included in the block.

Copy link
Member

@dabasov dabasov Nov 25, 2021

Choose a reason for hiding this comment

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

valid point by @peterlimg.I can add a little bit, there can be 3 main cases:

  1. transaction is malformed or has invalid signature or anything else that can be validated at the time of receiving
  2. transaction can't be executed now, but can be executed in the future (no funds yet for transfer and so on) not sure that there are lots of cases, since we use transaction creation time for sequencing.
  3. transaction causes error to smart contract

regarding this cases

  1. should not be included into the block and should be excluded from tx_pool asap, we have to collect statistics on malicious senders by ip or something similar
  2. should be stored in the tx_pool for some time and if can't be executed successfully should be included into the block
  3. should be included into the block

@dabasov
Copy link
Member

dabasov commented Sep 20, 2021

Am i right, that this change is needed first of all to charge clients even for failed SC transactions?

@bbist
Copy link
Contributor Author

bbist commented Sep 20, 2021

Am i right, that this change is needed first of all to charge clients even for failed SC transactions?

Yes.

I expect there to be problems with repeatability of a transaction output between generator and verifiers, which can lead to discarded blocks because of failed verification. We need to make sure that miners get same error when processing same transaction, both during generation and verification.

When it comes to clients, for now I've changed gosdk to treat failed transaction as errors, and use transaction output as error message.

@peterlimg
Copy link
Member

Might be a dumb question, but could we check the transaction validity when the client submits it? Then it'd be no surprise for the txn to be discarded and not included in the block.

Miners must validate the transactions no matter whether the transactions have been validated in clients end, we can't guarantee that all clients are honest.

@shaktals
Copy link

shaktals commented Oct 7, 2021

Might be a dumb question, but could we check the transaction validity when the client submits it? Then it'd be no surprise for the txn to be discarded and not included in the block.

Miners must validate the transactions no matter whether the transactions have been validated in clients end, we can't guarantee that all clients are honest.

What I meant is, as soon as the backend receives a txn, he runs validation, and on the response to the request informs the client that it is not valid. Then it'd be no surprise for the client when txn is discarded.

@guruhubb
Copy link
Member

guruhubb commented Oct 7, 2021

Might be a dumb question, but could we check the transaction validity when the client submits it? Then it'd be no surprise for the txn to be discarded and not included in the block.

Miners must validate the transactions no matter whether the transactions have been validated in clients end, we can't guarantee that all clients are honest.

What I meant is, as soon as the backend receives a txn, he runs validation, and on the response to the request informs the client that it is not valid. Then it'd be no surprise for the client when txn is discarded.

It needs to be part of the finalized block otherwise it can be a Byzantine miner

@peterlimg
Copy link
Member

Fixed in PR #930

@peterlimg peterlimg closed this Mar 21, 2022
@peterlimg peterlimg deleted the fix/sc-txn-errors branch December 3, 2022 02:17
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.

None yet

5 participants