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(rpc): Re-organize RPC errors #2038

Merged
merged 11 commits into from
Jul 15, 2020
Merged

feat(rpc): Re-organize RPC errors #2038

merged 11 commits into from
Jul 15, 2020

Conversation

doitian
Copy link
Member

@doitian doitian commented Apr 23, 2020

This PR reworks on the RPC errors:

  • Use JSONRPC error code to differentiate different errors. Also prefix the error code in the message to be search engine friendly.
  • Make error message simple and easy to understand. The dump of the error is added as the data instead.
  • Avoid reusing the same error message for different reasons.

Breaking Changes

  • The error object date field is always absent before, now it can be a string which contains the detailed error information.
  • The code in error object is always -3 for all the CKB internal errors, now it can have different values to differentiate different errors. Check the file rpc/src/error.rs.
  • The error messages have been updated to improve readability.

JSON-RPC Errors

See JSON-RPC spec.

General Errors

CKBInternalError (-1)

Errors in this category are considered to never happen or only happen when the system resources are exhausted.

RPCModuleIsDisabled (-4)

Not all RPC modules are enabled by default. Please edit rpc.modules in the configuration file ckb.toml.

Alert

send_alert

AlertFailedToVerifySignatures (-1000)

Some signatures are invalid.

P2PFailedToBroadcast (-101)

Alert is saved locally but has failed to broadcast to the P2P network.

InvalidParams (-32602)

  • Expected params[0].notice_until in the future.

Chain

get_block_by_number

ChainIndexIsInconsistent (-201)

The index is inconsistent. It says a block hash is in the main chain, but cannot read it from database.

DatabaseIsCorrupt (-202)

The data read from database is dirty. Please report it as a bug.

get_header_by_number

ChainIndexIsInconsistent (-201)

The index is inconsistent. It says a block hash is in the main chain, but cannot read it from database.

get_cells_by_lock_hash

InvalidParams (-32602)

  • Expected from <= to in params[0].
  • Expected to - from <= 100.

ChainIndexIsInconsistent (-201)

The index is inconsistent. It says a block hash is in the main chain, but cannot read it from database.

Experiment

dry_run_transaction

TransactionFailedToResolve (-301)

Failed to resolve the referenced cells and headers used in the transaction, as inputs or dependencies.

TransactionFailedToVerify (-302)

Failed to verify the transaction.

calculate_dao_maximum_withdraw

DAOError (-5)

The given out point is not a valid cell for DAO computation.

CKBInternalError (-1)

Mathematics overflow.

Network

set_ban

InvalidParams (-32602)

  • Expected params[0] to be a valid IP address.
  • Expected params[1] to be in the list [insert, delete].

Pool

send_transaction

PoolRejectedTransactionByOutputsValidator (-1102)

The transaction is rejected by the validator specified by params[1]. If you really want to send transactions with advanced scripts, please set params[1] to "passthrough".

PoolRejectedTransactionByIllTransactionChecker (-1103)

Pool rejects some transactions which seem contain invalid VM instructions. See the issue link in the error message for details.

PoolRejectedTransactionByMinFeeRate (-1104)

The transaction fee rate must >= tx_pool.min_fee_rate in ckb.toml.

PoolRejectedTransactionByMaxAncestorsCountLimit (-1105)

The ancestors count must <= tx_pool.max_ancestors_count in ckb.toml.

PoolIsFull (-1106)

Pool is full.

PoolRejectedDuplicatedTransaction (-1107)

The transaction is already in the pool.

┌ TransactionFailedToResolve (-301)

Failed to resolve the referenced cells and headers used in the transaction, as inputs or dependencies.

┌ TransactionFailedToVerify (-302)

Failed to verify the transaction.

@doitian doitian requested review from a team and xxuejie April 23, 2020 07:41
@doitian doitian marked this pull request as draft April 23, 2020 08:07
@doitian doitian removed the request for review from xxuejie April 23, 2020 08:07
@doitian doitian added this to 👀 Awaiting review in CKB - Pull Requests Apr 27, 2020
@doitian doitian moved this from 👀 Awaiting review to 🚧 In progress in CKB - Pull Requests Apr 27, 2020
@doitian doitian changed the title feat(rpc): Organize RPC errors feat(rpc): Re-organize RPC errors Apr 30, 2020
@doitian doitian added b:rpc Break RPC interface breaking change The feature breaks consensus, database, message schema or RPC interface. labels Apr 30, 2020
@doitian doitian marked this pull request as ready for review April 30, 2020 02:12
@doitian doitian requested review from a team, yangby-cryptape and quake and removed request for a team April 30, 2020 02:12
yangby-cryptape
yangby-cryptape previously approved these changes May 1, 2020
@doitian
Copy link
Member Author

doitian commented May 5, 2020

Will fix the CI error today

@doitian doitian added the s:waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. label May 6, 2020
CKB - Pull Requests automation moved this from 🚧 In progress to 👀 Awaiting review May 12, 2020
@doitian
Copy link
Member Author

doitian commented May 12, 2020

@quake @yangby-cryptape fixed clippy, please review again.

quake
quake previously approved these changes May 26, 2020
@doitian
Copy link
Member Author

doitian commented Jun 22, 2020

bors try

bors bot added a commit that referenced this pull request Jun 22, 2020
@doitian
Copy link
Member Author

doitian commented Jun 22, 2020

Rebased, please review.

quake
quake previously approved these changes Jun 22, 2020
CKB - Pull Requests automation moved this from ✅ Reviewer approved to 👀 Awaiting review Jun 29, 2020
@doitian
Copy link
Member Author

doitian commented Jun 29, 2020

  • Rebased to resolve the alert module conflict b83b004
  • Added a new commit 1067c6a

quake
quake previously approved these changes Jun 29, 2020
CKB - Pull Requests automation moved this from 👀 Awaiting review to ✅ Reviewer approved Jun 29, 2020
zhangsoledad
zhangsoledad previously approved these changes Jun 29, 2020
@doitian
Copy link
Member Author

doitian commented Jun 30, 2020

bors r=quake,zhangsoledad

bors bot added a commit that referenced this pull request Jun 30, 2020
2038: feat(rpc): Re-organize RPC errors r=quake,zhangsoledad a=doitian

This PR reworks on the RPC errors:

* Use JSONRPC error code to differentiate different errors. Also prefix the error code in the message to be search engine friendly.
* Make error message simple and easy to understand. The dump of the error is added as the data instead.
* Avoid reusing the same error message for different reasons.

## Breaking Changes

* The error object `date` field is always absent before, now it can be a string which contains the detailed error information.
* The `code` in error object is always -3 for all the CKB internal errors, now it can have different values to differentiate different errors. Check the file `rpc/src/error.rs`.
* The error messages have been updated to improve readability.

## JSON-RPC Errors

See [JSON-RPC spec](https://www.jsonrpc.org/specification#error_object).

## General Errors

┌ `CKBInternalError (-1)`

Errors in this category are considered to never happen or only happen when the system resources are exhausted.

┌ `RPCModuleIsDisabled (-4)`

Not all RPC modules are enabled by default. Please edit `rpc.modules` in the configuration file `ckb.toml`.

## Alert

### `send_alert`

┌  `AlertFailedToVerifySignatures (-1000)`

Some signatures are invalid.


┌ `P2PFailedToBroadcast (-101)`

Alert is saved locally but has failed to broadcast to the P2P network.


┌ `InvalidParams (-32602)`

* Expected `params[0].notice_until` in the future.

## Chain

### `get_block_by_number`

┌ `ChainIndexIsInconsistent (-201)`

The index is inconsistent. It says a block hash is in the main chain, but cannot read it from database.

┌ `DatabaseIsCorrupt (-202)`

The data read from database is dirty. Please report it as a bug.

### `get_header_by_number`

┌ `ChainIndexIsInconsistent (-201)`

The index is inconsistent. It says a block hash is in the main chain, but cannot read it from database.


### `get_cells_by_lock_hash`

┌ `InvalidParams (-32602)`

* Expected `from <= to` in `params[0]`.
* Expected `to - from <= 100`.

┌ `ChainIndexIsInconsistent (-201)`

The index is inconsistent. It says a block hash is in the main chain, but cannot read it from database.


## Experiment

### `dry_run_transaction`

┌ `TransactionFailedToResolve (-301)`

Failed to resolve the referenced cells and headers used in the transaction, as inputs or dependencies.

┌ `TransactionFailedToVerify (-302)`

Failed to verify the transaction.

### `calculate_dao_maximum_withdraw`

┌ `DAOError (-5)`

The given out point is not a valid cell for DAO computation.

┌ `CKBInternalError (-1)`

Mathematics overflow.

## Network

### `set_ban`

┌ `InvalidParams (-32602)`

* Expected `params[0]` to be a valid IP address.
* Expected `params[1]` to be in the list [insert, delete].

## Pool

### `send_transaction`

┌ `PoolRejectedTransactionByOutputsValidator (-1102)`

The transaction is rejected by the validator specified by `params[1]`. If you really want to send transactions with advanced scripts, please set `params[1]` to "passthrough".

┌ `PoolRejectedTransactionByIllTransactionChecker (-1103)`

Pool rejects some transactions which seem contain invalid VM instructions. See the issue link in the error message for details.

┌ `PoolRejectedTransactionByMinFeeRate (-1104)`

The transaction fee rate must >= `tx_pool.min_fee_rate` in `ckb.toml`.

┌ `PoolRejectedTransactionByMaxAncestorsCountLimit (-1105)`

The ancestors count must <= `tx_pool.max_ancestors_count` in `ckb.toml`.

┌ `PoolIsFull (-1106)`

Pool is full.

┌ `PoolRejectedDuplicatedTransaction (-1107)`

The transaction is already in the pool.

┌ TransactionFailedToResolve (-301)

Failed to resolve the referenced cells and headers used in the transaction, as inputs or dependencies.

┌ TransactionFailedToVerify (-302)

Failed to verify the transaction.

Co-authored-by: ian <ian@nervos.org>
@bors
Copy link
Contributor

bors bot commented Jun 30, 2020

Build failed:

  • continuous-integration/travis-ci/push

@doitian doitian dismissed stale reviews from zhangsoledad and quake via 08ee29a June 30, 2020 09:20
@doitian doitian requested a review from keroro520 as a code owner June 30, 2020 09:20
CKB - Pull Requests automation moved this from ✅ Reviewer approved to 👀 Awaiting review Jun 30, 2020
@doitian
Copy link
Member Author

doitian commented Jun 30, 2020

Fix the expected error message in integration test 08ee29a

The error is renamed in 0a8bf97

@doitian
Copy link
Member Author

doitian commented Jul 6, 2020

bors try

bors bot added a commit that referenced this pull request Jul 6, 2020
@bors
Copy link
Contributor

bors bot commented Jul 6, 2020

try

Build succeeded:

  • continuous-integration/travis-ci/push

CKB - Pull Requests automation moved this from 👀 Awaiting review to ✅ Reviewer approved Jul 15, 2020
@doitian
Copy link
Member Author

doitian commented Jul 15, 2020

bors r=quake,yangby-cryptape

@bors
Copy link
Contributor

bors bot commented Jul 15, 2020

Build succeeded:

@bors bors bot merged commit 6492e3f into nervosnetwork:develop Jul 15, 2020
CKB - Pull Requests automation moved this from ✅ Reviewer approved to Done Jul 15, 2020
@doitian doitian deleted the better-rpc-error branch September 11, 2020 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b:rpc Break RPC interface breaking change The feature breaks consensus, database, message schema or RPC interface.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants