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

[Neo Core Exception] Create WalletException and use it to replace all exceptions in wallet #3434

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Jul 20, 2024

Description

We use general exceptions in the neo core that is hard to tell the exact exception reason. Thus in this pr i define a new exception type WalletException, it contains multiple error types.

For instance, in CalculateNetworkFee method, the exception reason can be very different, but we will not know the cause of the exception if we catched the exception, as they are all ArgumentExceptions, thus we are not able to have an exact rpcserver response code.

Fixes #

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Existing tests that are related to the walletexception are updated accordingly.

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y
Copy link
Contributor Author

Jim8y commented Jul 20, 2024

Problem of this pr is that maybe its depencencies need to update there exception handling logic as the exception has being changed.

cschuchardt88
cschuchardt88 previously approved these changes Jul 21, 2024
@Jim8y Jim8y requested a review from shargon July 22, 2024 06:33
cschuchardt88
cschuchardt88 previously approved these changes Jul 23, 2024
@Jim8y Jim8y requested a review from shargon July 23, 2024 11:19
@Jim8y
Copy link
Contributor Author

Jim8y commented Jul 23, 2024

@shargon

@Jim8y
Copy link
Contributor Author

Jim8y commented Jul 25, 2024

@shargon any further suggestion?

src/Neo/Wallets/Wallet.cs Outdated Show resolved Hide resolved
@Jim8y Jim8y requested a review from cschuchardt88 July 29, 2024 14:14
src/Neo/Wallets/Wallet.cs Outdated Show resolved Hide resolved
@Jim8y Jim8y requested a review from shargon July 30, 2024 04:01
cschuchardt88
cschuchardt88 previously approved these changes Jul 30, 2024
src/Neo/Wallets/Helper.cs Outdated Show resolved Hide resolved
Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

I am reviewing the PR, @Jim8y. But there are many changes still to review and test here from my side.

@Jim8y Jim8y added the Blocked This issue can't be worked at the moment label Jul 31, 2024
@Jim8y
Copy link
Contributor Author

Jim8y commented Jul 31, 2024

blocked for vitor to review

Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

image

I have some problems with UT_Transactions.cs, It is not appearing in my test environment.
The same for Neo-Plugins.RpcServer.Tests.

@cschuchardt88
Copy link
Member

@vncoelho

You have to build 1st.

@vncoelho
Copy link
Member

@vncoelho

You have to build 1st.

And I also noticed it is a Partial Class, so they show differently later.
But as default the devcontainer runs dotnet build.
For some reason sometime it starts with problems.

Before I had dotnet restokre && dotnet build --no-restore
Perhaps it works better.

@@ -90,78 +104,90 @@ internal static byte[] XOR(byte[] x, byte[] y)
/// <returns>The network fee of the transaction.</returns>
public static long CalculateNetworkFee(this Transaction tx, DataCache snapshot, ProtocolSettings settings, Func<UInt160, byte[]> accountScript, long maxExecutionCost = ApplicationEngine.TestModeGas)
Copy link
Member

Choose a reason for hiding this comment

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

This will make conflicts into my never ending pull request #3385 :'(

Copy link
Member

Choose a reason for hiding this comment

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

We may merge #3385 as it is now and move non-standard verification scripts support to another issue. I think it's acceptable way since #3385 contains everything that's required except non-standard verification scripts handling.

Copy link
Contributor

Choose a reason for hiding this comment

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

Moved to #3539.

@@ -141,6 +141,7 @@ public WalletAccount CreateAccount()
{
var privateKey = new byte[32];
using var rng = RandomNumberGenerator.Create();
var maxTry = 100;
Copy link
Member

Choose a reason for hiding this comment

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

how much time it spend in 100 ? maybe is few number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not likly t happen,,,,,but will do 10

Copy link
Member

Choose a reason for hiding this comment

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

Before it was infinite...eahuehauea
Any number is good to me here, but 10 looks small but unlikely to happen.

@vncoelho vncoelho removed the Blocked This issue can't be worked at the moment label Aug 1, 2024
@vncoelho
Copy link
Member

vncoelho commented Aug 1, 2024

Tests completed from my side here. I will just check the code here on github again. But no blocker.

@Jim8y Jim8y requested a review from shargon August 2, 2024 01:25
…ndardize-exception

* 'standardize-exception' of github.com:Jim8y/neo:
  Clean using
  [Neo Core Add] add char support (neo-project#3441)
  [rpc] Extend `getversion` RPC response with additional protocol settings (neo-project#3443)
  update benchmark system (neo-project#3442)
  [`Optimization`] Parsing Smart Contract Script Analysis (neo-project#3420)
  `[Move]` Part-3 Classes into Different Library - `Neo.Extensions` (neo-project#3400)
@shargon
Copy link
Member

shargon commented Aug 2, 2024

I still reviewing this one

@Jim8y Jim8y added the Blocked This issue can't be worked at the moment label Aug 2, 2024
@Jim8y Jim8y removed the Blocked This issue can't be worked at the moment label Aug 10, 2024
@cschuchardt88
Copy link
Member

@Jim8y can you add this Issue to this PR since your changing alot

#3167

@@ -90,78 +104,90 @@ internal static byte[] XOR(byte[] x, byte[] y)
/// <returns>The network fee of the transaction.</returns>
public static long CalculateNetworkFee(this Transaction tx, DataCache snapshot, ProtocolSettings settings, Func<UInt160, byte[]> accountScript, long maxExecutionCost = ApplicationEngine.TestModeGas)
Copy link
Member

Choose a reason for hiding this comment

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

We may merge #3385 as it is now and move non-standard verification scripts support to another issue. I think it's acceptable way since #3385 contains everything that's required except non-standard verification scripts handling.

Comment on lines +72 to 75
catch (Exception ex) when (ex is not WalletException)
{
sb.EmitDynamicCall(asset_id, "decimals", CallFlags.ReadOnly);
sb.EmitDynamicCall(asset_id, "symbol", CallFlags.ReadOnly);
script = sb.ToArray();
throw WalletException.FromException(ex);
}
Copy link
Member

Choose a reason for hiding this comment

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

WalletException constructor is able to create WalletException from WalletException, so we can safely remove when (ex is not WalletException).

}
catch (Exception e) when (e is not WalletException)
{
throw new WalletException(WalletErrorType.InvalidPrivateKey, "Invalid WIF format.", e);
Copy link
Member

Choose a reason for hiding this comment

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

"Invalid WIF format."

It may be something else, because invalid WIF format is handled earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants