neo-go icon indicating copy to clipboard operation
neo-go copied to clipboard

question: how to get panic message?

Open ixje opened this issue 3 years ago • 6 comments

I deployed your divisible NFT to the testnet. When I tried minting I initially made the mistake of not providing data in the transfer. Which caused an abort I assumed here https://github.com/nspcc-dev/neo-go/blob/3dbd36ef70c902ace1552b849a00a454a3fad73b/examples/nft-d/nft.go#L367-L369

The actual exception message was:

"exception": "at instruction 29 (SYSCALL): failed native call: at instruction 1861 (ABORT): ABORT",

I noticed this snippet slightly up in the code https://github.com/nspcc-dev/neo-go/blob/3dbd36ef70c902ace1552b849a00a454a3fad73b/examples/nft-d/nft.go#L354-L359

which I assumed would print the reason, but the logs don't show this. My question is; how do I get the panic message?

To reproduce

curl --location --request POST 'http://rpc1.t5.n3.nspcc.ru:21332/' \
--header 'Content-Type: text/plain' \
--data-raw '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "invokescript",
  "params": ["CwIAypo7DBSnXW9dVbO8uPNzxHuKeWjqtp/ryAwUSlJutU7JooD+W5Gsslkavh9RHzcUwB8MCHRyYW5zZmVyDBTPduKL0AYsSkeO41VhARMZ88+k0kFifVtS",[{"account":"0x371f511fbe1a59b2ac915bfe80a2c94eb56e524a","scopes":"CalledByEntry"}]]
}'

ixje avatar Sep 27 '22 11:09 ixje

how do I get the panic message?

Currently, the design of the contract doesn't allow the external user to get the panic message. As you noticed, the code snippet that handles panic message just logs it: https://github.com/nspcc-dev/neo-go/blob/3dbd36ef70c902ace1552b849a00a454a3fad73b/examples/nft-d/nft.go#L354-L359

The log message will be displayed inside the running node logs, so accessing the logs is the only way to get the logged panic message. ABORT doesn't have the ability to provide some message error with it. At the same time we can't replace util.Abort() with panic(message) because, according to the standard:

If the receiver doesn't want to receive this transfer it MUST abort the execution.

AnnaShaleva avatar Sep 27 '22 12:09 AnnaShaleva

Log messages are not saved, they're only visible in the node logs:

Sep 27 08:55:17 kaede neogo-testnet-rpc[417627]: 2022-09-27T08:55:17.183Z        INFO        runtime log        {"tx": "4d3b13fb5435e3f4cb1540aee14fec9f664a5b6a1a7f2af20e2afc93cd8016d9", "script": "c8eb9fb6ea68798a7bc473f3b8bcb3555d6f5da7", "msg": "invalid 'data'"}
Sep 27 08:55:17 kaede neogo-testnet-rpc[417627]: 2022-09-27T08:55:17.183Z        WARN        contract invocation failed        {"tx": "4d3b13fb5435e3f4cb1540aee14fec9f664a5b6a1a7f2af20e2afc93cd8016d9", "block": 797668, "error": "at instruction 29 (SYSCALL): failed native call: at instruction 1861 (ABORT): ABORT"}

roman-khimov avatar Sep 27 '22 12:09 roman-khimov

ah I see. I thought runtime.log was writing elsewhere (didn't look at the implementation). Feels like we kind of need opcode.ABORT_WITH_REASON, no?

ixje avatar Sep 27 '22 12:09 ixje

runtime.log

It's a regular System.Runtime.Log syscall.

opcode.ABORT_WITH_REASON

We have the same issue with ASSERT, related to neo-project/neo#2782. Maybe if we just save/return log messages it'd be OK (even though it'll not solve neo-project/neo#2782 completely).

roman-khimov avatar Sep 27 '22 12:09 roman-khimov

Log messages are not saved, they're only visible in the node logs:

Sep 27 08:55:17 kaede neogo-testnet-rpc[417627]: 2022-09-27T08:55:17.183Z        INFO        runtime log        {"tx": "4d3b13fb5435e3f4cb1540aee14fec9f664a5b6a1a7f2af20e2afc93cd8016d9", "script": "c8eb9fb6ea68798a7bc473f3b8bcb3555d6f5da7", "msg": "invalid 'data'"}
Sep 27 08:55:17 kaede neogo-testnet-rpc[417627]: 2022-09-27T08:55:17.183Z        WARN        contract invocation failed        {"tx": "4d3b13fb5435e3f4cb1540aee14fec9f664a5b6a1a7f2af20e2afc93cd8016d9", "block": 797668, "error": "at instruction 29 (SYSCALL): failed native call: at instruction 1861 (ABORT): ABORT"}

Should these log messages also show when I talk to the RPC server via invokescript or only for signed tx's?

ixje avatar Sep 27 '22 13:09 ixje

IIRC they'll be logged for invoke* too.

roman-khimov avatar Sep 27 '22 13:09 roman-khimov

So we have some defined behavior for runtime logs (they're available in node logs, but there is a chance that eventually we'll have something like neo-project/neo-modules#737) and we have neo-project/neo#2782 to track the potential protocol improvements (with neo-project/neo-vm#491). I think we don't have a lot left for this particular issue, so I'm closing it.

roman-khimov avatar Dec 08 '22 09:12 roman-khimov