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

RPC: add error codes and response errors #3063

Merged
merged 10 commits into from
Aug 16, 2023

Conversation

tatiana-nspcc
Copy link
Contributor

@tatiana-nspcc tatiana-nspcc commented Jul 14, 2023

Problem

We should carefully distinguish all kinds of RPC errors on the server side. Each meaningful error should have a separate meaningful error code. The problem is described in #2248

Solution

Add new error codes and handle them

Ref. neo-project/proposals#156 and https://docs.google.com/spreadsheets/d/1VShwR1qdVeE7J4gGUBzSPnjAIWkhXb-VT9yvf9cau6I/edit#gid=0.

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

Good. Here are several issues that need to be fixed:

  1. The most significant is that some of errors specified in the proposal remain unused. We have to use all of them, e.g. pay attantion to the contract-based witness verification: errors returned from the blockchain core can be destinguished and RPC server have to distinguish them to return proper (and specific) result from invokecontractverify. Check the other methods as far.
  2. Each commit should contain changes that are grouped by meaning. If some change has a separate meaning or has its own purpose that is not related to the current commit, then create new commit for this change.
  3. Pay attantion to our GH action jobs, the results are attached to the PR. Some of our tests are failing (it's will be fixed in the next release), but the rest of the jobs hsould pass.
  4. Each commit message should include the "signed-off-by" line.
  5. Specify the issue that will be closed by this commit in the commit message: "Close rpc: take care of response errors and error codes #2248".
  6. Commit header should start with a component (or package) name that includes the most significant changes. Use "neorpc: add error codes and response errors" for the current commit.

pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/error.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/network/server.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
@@ -30,33 +30,95 @@ const (
const (
// RPCErrorCode is returned on RPC request processing error.
RPCErrorCode = -100
Copy link
Member

Choose a reason for hiding this comment

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

No longer needed after all of the changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, It's still used in non-specified errors

Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't be, but I guess you have not converted all of them yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get rid of this error code

pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Show resolved Hide resolved
pkg/neorpc/errors.go Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Merging #3063 (90f1b0f) into master (16d1d1e) will increase coverage by 0.12%.
Report is 3 commits behind head on master.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master    #3063      +/-   ##
==========================================
+ Coverage   84.65%   84.78%   +0.12%     
==========================================
  Files         329      329              
  Lines       43941    43953      +12     
==========================================
+ Hits        37200    37265      +65     
+ Misses       5229     5189      -40     
+ Partials     1512     1499      -13     
Files Changed Coverage Δ
cli/server/server.go 68.91% <0.00%> (ø)
pkg/services/rpcsrv/error.go 90.47% <ø> (-0.83%) ⬇️
pkg/services/rpcsrv/server.go 79.82% <74.44%> (+1.90%) ⬆️
pkg/core/blockchain.go 78.57% <100.00%> (ø)
pkg/neorpc/errors.go 83.87% <100.00%> (+14.17%) ⬆️

... and 7 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

It's time to squash all related commits and make the PR structure more clear. I'll review the RPC server part one more time after PR finalization.

pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/network/server.go Outdated Show resolved Hide resolved
pkg/network/server.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@tatiana-nspcc tatiana-nspcc left a comment

Choose a reason for hiding this comment

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

I need some help to get several errors. Anna, could you, please help me?

pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Show resolved Hide resolved
Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

I haven't reviewd the tests yet, but the overall structure is more clear now.

Note about the first commit: try to overwrite commit message to fit the commit header size limit. The rest of information can be placed into the commit message body.

pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
@tatiana-nspcc tatiana-nspcc force-pushed the rpcsrv-errors branch 4 times, most recently from 907b120 to 0809b6c Compare August 10, 2023 23:41
pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/error.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/neorpc/errors.go Show resolved Hide resolved
pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/client_test.go Show resolved Hide resolved
pkg/services/rpcsrv/client_test.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server_test.go Outdated Show resolved Hide resolved
AnnaShaleva
AnnaShaleva previously approved these changes Aug 15, 2023
Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

@AnnaShaleva, what do you think about adding

// ErrCompatGeneric is an error returned by nodes not compliant with the neo-project/proposals#156 (NeoGo pre-0.102.0 and all known C# versions). It can be returned for any call and doesn't have any specific meaning.
// Deprecated: to be removed after all nodes adopt new error standard.
ErrCompatGeneric = NewErrorWithCode(-100, "RPC error")
// ErrCompatNoOpenedWallet is an error code returned by nodes not compliant with the neo-project/proposals#156 (all known C# versions, NeoGo never used this code). It can be returned for wallet-related operations.
// Deprecated: to be removed after all nodes adopt new error standard.
ErrCompatGeneric = NewErrorWithCode(-400, "No opened wallet")

The rationale is rather simple, while our server no longer uses these codes they still can come from C# servers and while we consider them deprecated we better at least have some definition of them until C# implements our proposal.

We should also mention the proposal (and the fact that we use a completely different error code set in our server) in docs/rpc.md.

pkg/neorpc/errors.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Outdated Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
pkg/services/rpcsrv/server.go Show resolved Hide resolved
@AnnaShaleva
Copy link
Member

@AnnaShaleva, what do you think about adding

// ErrCompatGeneric is an error returned by nodes not compliant with the neo-project/proposals#156 (NeoGo pre-0.102.0 and all known C# versions). It can be returned for any call and doesn't have any specific meaning.
// Deprecated: to be removed after all nodes adopt new error standard.
ErrCompatGeneric = NewErrorWithCode(-100, "RPC error")
// ErrCompatNoOpenedWallet is an error code returned by nodes not compliant with the neo-project/proposals#156 (all known C# versions, NeoGo never used this code). It can be returned for wallet-related operations.
// Deprecated: to be removed after all nodes adopt new error standard.
ErrCompatGeneric = NewErrorWithCode(-400, "No opened wallet")

The rationale is rather simple, while our server no longer uses these codes they still can come from C# servers and while we consider them deprecated we better at least have some definition of them until C# implements our proposal.

Agree, let's do this. @tatiana-nspcc, and then we also need to add a note about these deprecated errors removal to our ROADMAP.md.

@AnnaShaleva AnnaShaleva dismissed their stale review August 15, 2023 15:31

Documentation adjustments are needed and minor fixes are required.

Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

31fe57d and 63dba39 can be squashed as well.

pkg/neorpc/errors.go Show resolved Hide resolved
docs/rpc.md Show resolved Hide resolved
pkg/neorpc/errors.go Show resolved Hide resolved
ROADMAP.md Outdated Show resolved Hide resolved
ErrAlreadyExists is in blockchain and ErrAlreadyInPool is in mempool.

Signed-off-by: Tatiana Nesterenko <[email protected]>
Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

Please, fix the links to proposal for all commit messages (use neo-project/proposals#156).

docs/rpc.md Outdated Show resolved Hide resolved
docs/rpc.md Outdated Show resolved Hide resolved
docs/rpc.md Outdated Show resolved Hide resolved
According to proposal:
neo-project/proposals#156

Close nspcc-dev#2248

Signed-off-by: Tatiana Nesterenko <[email protected]>
While our server no longer uses these codes (-100, -400) they still can come
from C# servers and while we consider them deprecated we better at least have
some definition of them until C# implements our proposal:
neo-project/proposals#156
Also adding description of deprecated RPC error codes in ROADMAP.md.

Signed-off-by: Tatiana Nesterenko <[email protected]>
No functional changes, just a refactoring.

Signed-off-by: Tatiana Nesterenko <[email protected]>
Follow the reference implementation, the behaviour was changed in
neo-project/neo-modules@237ef7d.

Signed-off-by: Tatiana Nesterenko <[email protected]>
No functional changes, just a refactoring.
Use more specific and meaningful names to be able to use these errors from external packages.

Signed-off-by: Tatiana Nesterenko <[email protected]>
This change makes code incompatible with C# node,
because currently no error is returned on invalid proof.
According to proposal:
neo-project/proposals#156
Also adding `verifyProof` descpiption in docs/rpc.md.

Signed-off-by: Tatiana Nesterenko <[email protected]>
Behaviour change.
`terminatesession` returns ErrUnknownSession in case of impossibility of finding session,
previously there was no-error response with `false` result.
`traverseIterator`returns ErrUnknownSession in case of impossibility of finding session,
previously there was no-error response with default result; `traverseIterator`returns ErrUnknownIterator,
there were no such errors before.
Accordingly to proposal:
neo-project/proposals#156
Also adding description of `traverseIterator` in docs/rpc.md.

Signed-off-by: Tatiana Nesterenko <[email protected]>
No functional changes, just a refactoring.
Change error text to be able to use this error from external packages.

Signed-off-by: Tatiana Nesterenko <[email protected]>
@roman-khimov roman-khimov merged commit 5c6a111 into nspcc-dev:master Aug 16, 2023
13 of 18 checks passed
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.

3 participants