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 stack exception name #855

Merged
merged 8 commits into from
Dec 6, 2023
Merged

Fix stack exception name #855

merged 8 commits into from
Dec 6, 2023

Conversation

superboyiii
Copy link
Member

Close #854

@Jim8y
Copy link
Contributor

Jim8y commented Nov 30, 2023

a new field?

@superboyiii
Copy link
Member Author

superboyiii commented Nov 30, 2023

a new field?

Two kind of exception(one from vm, one from applicationlog), but they're using the same trigger. applicationlog exception could rewrite vm exception...

@superboyiii
Copy link
Member Author

Now it's the same result as invocation. @roman-khimov

Jim8y
Jim8y previously approved these changes Nov 30, 2023
@roman-khimov
Copy link
Contributor

The behavior we have in NeoGo now is that we return an array of elements in the stack. They can be proper stack items or they can be strings. Suppose you have a script leaving 1 and some bad item on the stack, with NeoGo you'd get

"stack": [
    {"type":"Integer","value":"1"},
    "error of some kind"
]

With this PR that would be

"stack": "error of some kind"

And this obviously loses more data that can be valuable for debugging, the number of elements left on the stack and all the proper elements can be helpful in many cases. I'd prefer having this kind of output in the end both for application log and test invocations.

@superboyiii
Copy link
Member Author

superboyiii commented Nov 30, 2023

"stack": "error of some kind"

So if 1000 stacks return 1000 error messages? And they are the same hard code message...

@roman-khimov
Copy link
Contributor

One stack item --- one error message, you serialize them one by one anyway, either you get a proper JSON or you get an error.

@superboyiii
Copy link
Member Author

@shargon What's your opinion?

@shargon
Copy link
Member

shargon commented Dec 1, 2023

If we add the stack, i prefer to add the stack item type, and the value, otherwise I prefer to use the exception field

@superboyiii
Copy link
Member Author

Tested. @shargon @roman-khimov
image

@shargon
Copy link
Member

shargon commented Dec 1, 2023

Why we don't use the exception field?

@superboyiii
Copy link
Member Author

Why we don't use the exception field?

These two exceptions are generated from different place, but applicationlog exception could re-write vm exception which doesn't make sense and can make some Dapp backend confusing a lot for handling these exceptions. For example: Ghostmarket.

Copy link
Contributor

@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.

How about test invocations (GetInvokeResult)?

OK otherwise.

src/ApplicationLogs/LogReader.cs Outdated Show resolved Hide resolved
@shargon
Copy link
Member

shargon commented Dec 1, 2023

Why we don't use the exception field?

These two exceptions are generated from different place, but applicationlog exception could re-write vm exception which doesn't make sense and can make some Dapp backend confusing a lot for handling these exceptions. For example: Ghostmarket.

What about change the exception field to be an array, also with type?

@roman-khimov
Copy link
Contributor

If it'd be separated, you wouldn't know which elements are bad. In some cases it might be useful. Imagine 3 items on the stack, the second one is bad, but the other two are OK and can be serialized, if you get two stack items and one exception, what was the original index of the element that has caused this exception?

@cschuchardt88
Copy link
Member

#807 And #842 implements AppclaitionEngine.Log for the meantime in application log for debug mode. Until core can be update to do it properly.

@superboyiii
Copy link
Member Author

Done. @roman-khimov @shargon

src/ApplicationLogs/LogReader.cs Show resolved Hide resolved
src/ApplicationLogs/LogReader.cs Outdated Show resolved Hide resolved
src/ApplicationLogs/LogReader.cs Outdated Show resolved Hide resolved
@superboyiii
Copy link
Member Author

@AnnaShaleva Could you review again? Any more improvement needed?

@superboyiii
Copy link
Member Author

@Liaojinghui @shargon Is it OK for you?

}
catch (Exception ex)
{
stack.Add("error: " + ex);
Copy link
Member

Choose a reason for hiding this comment

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

I dont think will output will help much. Seeing how the only reason it would fail is because its an interop and cant be serialized. Better to put an empty or null stackitem instead.

}
catch (Exception ex)
{
stack.Add("error: " + ex);
Copy link
Member

Choose a reason for hiding this comment

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

I dont think will output will help much. Seeing how the only reason it would fail is because its an interop and cant be serialized. Better to put an empty or null stackitem instead.

}
catch (Exception ex)
{
stack.Add("error: " + ex);
Copy link
Member

Choose a reason for hiding this comment

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

same

src/ApplicationLogs/LogReader.cs Outdated Show resolved Hide resolved
src/ApplicationLogs/LogReader.cs Outdated Show resolved Hide resolved
src/RpcServer/RpcServer.SmartContract.cs Outdated Show resolved Hide resolved
@superboyiii
Copy link
Member Author

Done @shargon

@@ -147,7 +147,7 @@ public static JObject BlockLogToJson(Block block, IReadOnlyList<Blockchain.Appli
}
catch (Exception ex)
{
stack.Add("error: " + ex);
stack.Add("error: " + ex.Message);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stack.Add("error: " + ex.Message);
stack.Add(item.GetInterface<object>().GetType().Name);

Copy link
Contributor

Choose a reason for hiding this comment

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

The error means that there was a stackitem, but it can't be serialized and therefore can't be presented in JSON output. Replacing it with NULL or any other element (empty/string with a name) would be wrong because that's not what's on the stack. Proper stack item (like suggested) would be misinterpreted as a real output from the execution, it has to be some error string in case of serialization failure.

Copy link
Member

Choose a reason for hiding this comment

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

But the ones that can't be output to json are iterators (storage); at least what i have ran into (on testnet).

@@ -102,7 +102,7 @@ private JObject GetInvokeResult(byte[] script, Signer[] signers = null, Witness[
}
catch (Exception ex)
{
stack.Add("error: " + ex);
stack.Add("error: " + ex.Message);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stack.Add("error: " + ex.Message);
stack.Add(item.GetInterface<object>().GetType().Name);

Copy link
Member Author

Choose a reason for hiding this comment

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

In this way, it will throw exception directly but can't get result stack!
725922486f0147421b02d13395e875b
Compare to current code:
302dc02b1c0fea24c7e69980f02256f

@@ -99,7 +99,7 @@ public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec)
}
catch (Exception ex)
{
stack.Add("error: " + ex);
stack.Add("error: " + ex.Message);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stack.Add("error: " + ex.Message);
stack.Add(item.GetInterface<object>().GetType().Name);

Copy link
Member Author

Choose a reason for hiding this comment

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

This can break applicationlog getting the stack:
3e8148970abed45ba6ef0e98c4161c3
But you can see it's on-chain:
7723fcd8ecae99fdf1a629501952ada

shargon
shargon previously approved these changes Dec 5, 2023
@shargon
Copy link
Member

shargon commented Dec 5, 2023

Maybe add the error description will not be deterministic between neo-go and c#?

@cschuchardt88
Copy link
Member

cschuchardt88 commented Dec 5, 2023

I think we should be doing this the proper way, indicating that there is an valid stackitem. We shouldnt be hiding it or saying there is something wrong with it; when there is not.

Edit:
#807 and neo-express handle the stackitems this way.

@roman-khimov
Copy link
Contributor

error description will not be deterministic between neo-go and c#?

Yes, it will differ.

@shargon
Copy link
Member

shargon commented Dec 5, 2023

error description will not be deterministic between neo-go and c#?

Yes, it will differ.

Then is better to change the message

@roman-khimov
Copy link
Contributor

I think we can settle on the fact that if you're receiving a string instead of a stack item, it's an error string and the original stack item couldn't be represented. And this string can be implementation-specific, just like data in JSON-RPC errors.

@superboyiii
Copy link
Member Author

@shargon @roman-khimov need approve

@shargon shargon merged commit f4a5705 into master Dec 6, 2023
2 checks passed
@shargon shargon deleted the fix-applicationlog-exception branch December 6, 2023 06:42
Jim8y added a commit to Jim8y/neo-modules that referenced this pull request Dec 13, 2023
* 'master' of github.com:neo-project/neo-modules:
  Fix workflow (neo-project#857)
  Fix stack exception name (neo-project#855)
  update workflow (neo-project#856)
  Refac build configs (neo-project#846)
  Hotfix for neo-project#850 (neo-project#853)
  Fix RpcNativeContract (neo-project#851)
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.

Tx showed HALT in ApplicationLogs but has exception returned
6 participants