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

refactor: Improve script error #2164

Merged
merged 5 commits into from
Aug 4, 2020
Merged

refactor: Improve script error #2164

merged 5 commits into from
Aug 4, 2020

Conversation

doitian
Copy link
Member

@doitian doitian commented Jul 13, 2020

  • Add information to help locating which script produces the error, including the first input or output index, whether it is lock or type script.
  • Add extra info:
    • Add the upper limit in ExceededMaximumCycles
    • Add a link to the system script exit codes table for ValidationFailure

quake
quake previously approved these changes Jul 17, 2020
@doitian doitian added this to 👀 Awaiting review in CKB - Pull Requests Jul 20, 2020
driftluo
driftluo previously approved these changes Jul 23, 2020
CKB - Pull Requests automation moved this from 👀 Awaiting review to ✅ Reviewer approved Jul 23, 2020
BREAKING CHANGE: this commit has changed some public interfaces in
crate `ckb-script`. Some methods return `ckb_error::Error` as the error,
now they return `ckb_script::ScriptError`:

* `IllTransactionChecker::check`
* `IllScriptChecker::check`
* `TypeIdSystemScript::verify`
* `TransactionScriptsVerifier::extract_script`
* `TransactionScriptsVerifier::verify_single`

The display message returned from script verifier looks like:

```
Script(TransactionScriptError { source: Inputs[0], cause: ExceededMaximumCycles })
```

which was

```
Script(ScriptError(ExceededMaximumCycles))
```

The new message shows the first input or output index of the script
group that causes the error.
The limit can be applied in two different places:

* Block cycles limit. This is a consensus rule. Since the block total
  cycles must not exceed this limit, a single transaction should not
  either.
* Pool limit. This is a per node configuration. See option `max_tx_verify_cycles` in the config file `ckb.toml`. A node reject the transaction and stop relaying it when cycles exceed this limit.

Adding the limit value can help developers to figure out which limit is
currently applied upon the transaction.
Each script can define its own exit codes. Later, there may be a site
can search the exit code linked to the failed script. But now we only
have a table for the system scripts.

This commit adds the link to the system script exit codes table in the
error message..
Add the info whether the error is thrown when running lock or type
script.

It resolves the issue mentioned in
#2049 (comment)
```
error: redundant field names in struct initialization
  --> script/src/types.rs:20:13
   |
20 |             group_type: group_type,
   |             ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `group_type`
   |
   = note: `-D clippy::redundant-field-names` implied by `-D warnings`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
error: this `else { if .. }` block can be collapsed
  --> script/src/error.rs:49:16
   |
49 |           } else {
   |  ________________^
50 | |             if let Some(n) = script_group.output_indices.first() {
51 | |                 TransactionScriptErrorSource::Outputs(*n, script_group.group_type)
52 | |             } else {
53 | |                 TransactionScriptErrorSource::Unknown
54 | |             }
55 | |         }
   | |_________^
   |
   = note: `-D clippy::collapsible-if` implied by `-D warnings`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
help: try
   |
49 |         } else if let Some(n) = script_group.output_indices.first() {
50 |     TransactionScriptErrorSource::Outputs(*n, script_group.group_type)
51 | } else {
52 |     TransactionScriptErrorSource::Unknown
53 | }

error: this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)
   --> script/src/verify.rs:331:28
    |
331 |         script_group_type: &ScriptGroupType,
    |                            ^^^^^^^^^^^^^^^^ help: consider passing by value instead: `ScriptGroupType`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref

error: identical conversion
   --> script/src/verify.rs:408:17
    |
408 |             Err(ScriptError::ValidationFailure(code).into())
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `ScriptError::ValidationFailure(code)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_conversion  |
```
@doitian doitian dismissed stale reviews from driftluo and quake via 05cae4c July 31, 2020 03:28
CKB - Pull Requests automation moved this from ✅ Reviewer approved to 👀 Awaiting review Jul 31, 2020
@doitian doitian requested review from quake and driftluo July 31, 2020 03:29
@doitian
Copy link
Member Author

doitian commented Jul 31, 2020

Resolved conflicts with the data loader traits changes.

CKB - Pull Requests automation moved this from 👀 Awaiting review to ✅ Reviewer approved Aug 3, 2020
@quake
Copy link
Member

quake commented Aug 4, 2020

bors r=quake,zhangsoledad

@bors
Copy link
Contributor

bors bot commented Aug 4, 2020

Build succeeded:

  • continuous-integration/travis-ci/push

@bors bors bot merged commit d812102 into nervosnetwork:develop Aug 4, 2020
CKB - Pull Requests automation moved this from ✅ Reviewer approved to Done Aug 4, 2020
@doitian doitian deleted the better-script-error branch September 11, 2020 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants