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

native: fix unclaimedGas calculation #3594

Merged
merged 1 commit into from
Oct 4, 2024
Merged

native: fix unclaimedGas calculation #3594

merged 1 commit into from
Oct 4, 2024

Conversation

AliceInHunterland
Copy link
Contributor

@AliceInHunterland AliceInHunterland commented Sep 30, 2024

Fix difference with C#:

(base) ekaterinapavlova@MacBook-Air-4 neo-go % curl -X POST
http://seed1t5.neo.org:20332 -H 'Content-Type: application/json' -d '{
  "jsonrpc": "2.0",
  "method": "getapplicationlog",
  "params":
  ["61681ce24dffea5481e9a50b10159b43b7ebfc21967b0b06fee7ff69c7123e3f"],
  "id": 1
}' | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time
  Current
                                 Dload  Upload   Total   Spent    Left
                                 Speed
100   429    0   269  100   160    582    346 --:--:-- --:--:-- --:--:--
   930
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "executions" : [
         {
            "exception" : null,
            "gasconsumed" : "198754",
            "notifications" : [],
            "stack" : [
               {
                  "type" : "Integer",
                  "value" : "0"
               }
            ],
            "trigger" : "Application",
            "vmstate" : "HALT"
         }
      ],
      "txid" :
      "0x61681ce24dffea5481e9a50b10159b43b7ebfc21967b0b06fee7ff69c7123e3
      f"
   }
}

(base) ekaterinapavlova@MacBook-Air-4 neo-go % curl -X POST  https://rpc .t5.n3.nspcc.ru:20331 -H 'Content-Type: application/json' -d '{
  "jsonrpc": "2.0",
  "method": "getapplicationlog",
  "params":
  ["61681ce24dffea5481e9a50b10159b43b7ebfc21967b0b06fee7ff69c7123e3f"],
  "id": 1
}' | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time
  Current
                                 Dload  Upload   Total   Spent    Left
                                 Speed
100   583  100   423  100   160   1424    538 --:--:-- --:--:-- --:--:--
  1969
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "executions" : [
         {
            "exception" : "at instruction 120 (SYSCALL): can't calculate
             bonus of height unequal (BlockHeight + 1)",
            "gasconsumed" : "198754",
            "notifications" : [],
            "stack" : [
               {
                  "type" : "Integer",
                  "value" : "4704605"
               },
               {
                  "type" : "ByteString",
                  "value" : "KfYYlDe/fxqqqm1yr7o5XLnQ7uk="
               }
            ],
            "trigger" : "Application",
            "vmstate" : "FAULT"
         }
      ],
      "txid" :
      "0x61681ce24dffea5481e9a50b10159b43b7ebfc21967b0b06fee7ff69c7123e3
      f"
   }
}

(base) ekaterinapavlova@MacBook-Air-4 neo-go % ./bin/neo-go contract invokefunction -r https://rpc.t5.n3.nspcc.ru:20331 -w ./testnet_wallet .json 1e6f88377a6c6bc4f683a5fc61eed5645ec5f123 unclaimedGas e9eed0b95c39baaf726daaaa1a7fbf379418f629 4704605
Enter account NWtk9HYWsf1njtSzA3XNgwZXRtriACcJ9G password > Warning: FAULT VM state returned from the RPC node: at instruction 120 (SYSCALL): can't calculate bonus of height unequal (BlockHeight + 1). Use --force flag to send the transaction anyway.

Close #3589

Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 85.20%. Comparing base (b1068b1) to head (02727b1).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
pkg/core/native/native_neo.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3594   +/-   ##
=======================================
  Coverage   85.20%   85.20%           
=======================================
  Files         333      333           
  Lines       39005    39007    +2     
=======================================
+ Hits        33233    33235    +2     
- Misses       4203     4204    +1     
+ Partials     1569     1568    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

We need tests for it. IIUC the problem was just for zero (or nonexistent) balance? Regular balances behave differently (execution breaks), it's just a matter of check order?

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.

The fix itself is legit, please add results for the T5 test with non-zero Neo balance and also please, add unit-tests to cover uncovered paths in neo-go/pkg/core/native/native_test/neo_test.go.

pkg/core/native/native_neo.go Outdated Show resolved Hide resolved
@AnnaShaleva
Copy link
Member

it's just a matter of check order?

Yes, it is.

@roman-khimov
Copy link
Member

I'd say that our old code was a bit better since it checked inputs first and only touched the DB afterwards. But it's not worth fixing on the C# side at the same time (introducing HF-dependent behaviour).

pkg/core/native/native_test/neo_test.go Outdated Show resolved Hide resolved
pkg/core/native/native_test/neo_test.go Outdated Show resolved Hide resolved
pkg/core/native/native_test/neo_test.go Show resolved Hide resolved
@AnnaShaleva
Copy link
Member

AnnaShaleva commented Oct 3, 2024

Regular balances behave differently (execution breaks)

please add results for the T5 test with non-zero Neo balance

@AliceInHunterland, have you managed to invoke this method on T5 testnet for account with non-zero balance? Please, attach invocation results for both C# and Go nodes to the PR, for both cases when requested height is valid and invalid.

@AliceInHunterland
Copy link
Contributor Author

AliceInHunterland commented Oct 3, 2024

  1. non-zero balance, valid height
(base) neo-go % ./bin/neo-go contract invokefunction -r https://rpc.t5.n3.nspcc.ru:20331 -w ./testnet_wallet.json a460e9333ad2d906645b7ced9bffd532c90ed54e unclaimedGas3 Nc6LJ79RodHzaz5BghHGChMZYRa9GqJvES
Enter account NWtk9HYWsf1njtSzA3XNgwZXRtriACcJ9G password > 
Network fee: 0.00037284
System fee: 0.00264301
Total fee: 0.00301585
Relay transaction (y|N)> y
ae8bc01212c9dcf01c73c1e8a3e60c334e37351358fd9b00061b989a866cc81e

(base) neo-go % curl -X POST https://rpc.t5.n3.nspcc.ru:20331 -H 'Content-Type: application/json' -d '{
  "jsonrpc": "2.0",
  "method": "getapplicationlog",
  "params": ["ae8bc01212c9dcf01c73c1e8a3e60c334e37351358fd9b00061b989a866cc81e"],
  "id": 1
}' | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   425  100   277  100   148    606    323 --:--:-- --:--:-- --:--:--   932
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "executions" : [
         {
            "exception" : null,
            "gasconsumed" : "264301",
            "notifications" : [],
            "stack" : [
               {
                  "type" : "Integer",
                  "value" : "14306775"
               }
            ],
            "trigger" : "Application",
            "vmstate" : "HALT"
         }
      ],
      "txid" : "0xae8bc01212c9dcf01c73c1e8a3e60c334e37351358fd9b00061b989a866cc81e"
   }
}

neo-go % curl -X POST http://seed1t5.neo.org:20332 -H 'Content-Type: application/json' -d '{
  "jsonrpc": "2.0",              
  "method": "getapplicationlog",
  "params": ["ae8bc01212c9dcf01c73c1e8a3e60c334e37351358fd9b00061b989a866cc81e"],
  "id": 1
}' | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   424    0   276  100   148    480    257 --:--:-- --:--:-- --:--:--   738
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "executions" : [
         {
            "exception" : null,
            "gasconsumed" : "264301",
            "notifications" : [],
            "stack" : [
               {
                  "type" : "Integer",
                  "value" : "14306775"
               }
            ],
            "trigger" : "Application",
            "vmstate" : "HALT"
         }
      ],
      "txid" : "0xae8bc01212c9dcf01c73c1e8a3e60c334e37351358fd9b00061b989a866cc81e"
   }
}

@AliceInHunterland
Copy link
Contributor Author

AliceInHunterland commented Oct 3, 2024

  1. non-zero balance, invalid height
 neo-go % ./bin/neo-go contract invokefunction -r http://seed1t5.neo.org:20332 -w ./testnet_wallet.json a460e9333ad2d906645b7ced9bffd532c90ed54e unclaimedGas2 Nc6LJ79RodHzaz5BghHGChMZYRa9GqJvES
  
Enter account NWtk9HYWsf1njtSzA3XNgwZXRtriACcJ9G password > 
Warning: FAULT VM state returned from the RPC node: Specified argument was out of the range of valid values. (Parameter 'end').
Use --force flag to send the transaction anyway.

neo-go % ./bin/neo-go contract invokefunction -r https://rpc.t5.n3.nspcc.ru:20331 --force -w ./testnet_wallet.json a460e9333ad2d906645b7ced9bffd532c90ed54e unclaimedGas2 Nc6LJ79RodHzaz5BghHGChMZYRa9GqJvES
Enter account NWtk9HYWsf1njtSzA3XNgwZXRtriACcJ9G password > 
Warning: FAULT VM state returned from the RPC node: at instruction 120 (SYSCALL): can't calculate bonus of height unequal (BlockHeight + 1).
Sending transaction...
3bf040e87f93c49045d2550a1017358b554774999d711d840b312247d4153216

neo-go % curl -X POST https://rpc.t5.n3.nspcc.ru:20331 -H 'Content-Type: application/json' -d '{
  "jsonrpc": "2.0",                          
  "method": "getapplicationlog",
  "params": ["3bf040e87f93c49045d2550a1017358b554774999d711d840b312247d4153216"],
  "id": 1
}' | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   571  100   423  100   148   1442    504 --:--:-- --:--:-- --:--:--  1955
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "executions" : [
         {
            "exception" : "at instruction 120 (SYSCALL): can't calculate bonus of height unequal (BlockHeight + 1)",
            "gasconsumed" : "264292",
            "notifications" : [],
            "stack" : [
               {
                  "type" : "Integer",
                  "value" : "4740731"
               },
               {
                  "type" : "ByteString",
                  "value" : "sXfLIW+NGHL5jrNoJOl1cm0f8MI="
               }
            ],
            "trigger" : "Application",
            "vmstate" : "FAULT"
         }
      ],
      "txid" : "0x3bf040e87f93c49045d2550a1017358b554774999d711d840b312247d4153216"
   }
}

(base)  neo-go % curl -X POST http://seed1t5.neo.org:20332 -H 'Content-Type: application/json' -d '{
  "jsonrpc": "2.0",                          
  "method": "getapplicationlog",
  "params": ["3bf040e87f93c49045d2550a1017358b554774999d711d840b312247d4153216"],
  "id": 1
}' | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   470    0   322  100   148    371    170 --:--:-- --:--:-- --:--:--   542
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "executions" : [
         {
            "exception" : "Specified argument was out of the range of valid values. (Parameter 'end')",
            "gasconsumed" : "264292",
            "notifications" : [],
            "stack" : [],
            "trigger" : "Application",
            "vmstate" : "FAULT"
         }
      ],
      "txid" : "0x3bf040e87f93c49045d2550a1017358b554774999d711d840b312247d4153216"
   }
}

@AnnaShaleva
Copy link
Member

AnnaShaleva commented Oct 3, 2024

@AliceInHunterland, we need results for both C# and Go nodes for the same transaction. For 2 transaction is not even sent, use --force flag to send it and attach C#/Go application logs.

Also, reviewcomments are not fixed.

pkg/core/native/native_test/neo_test.go Outdated Show resolved Hide resolved
pkg/core/native/native_test/neo_test.go Outdated Show resolved Hide resolved
pkg/core/native/native_test/neo_test.go Outdated Show resolved Hide resolved
pkg/core/native/native_test/neo_test.go Outdated Show resolved Hide resolved
Fix difference with C#:
```
(base) ekaterinapavlova@MacBook-Air-4 neo-go % curl -X POST
http://seed1t5.neo.org:20332 -H 'Content-Type: application/json' -d '{
  "jsonrpc": "2.0",
  "method": "getapplicationlog",
  "params":
  ["61681ce24dffea5481e9a50b10159b43b7ebfc21967b0b06fee7ff69c7123e3f"],
  "id": 1
}' | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time
  Current
                                 Dload  Upload   Total   Spent    Left
                                 Speed
100   429    0   269  100   160    582    346 --:--:-- --:--:-- --:--:--
   930
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "executions" : [
         {
            "exception" : null,
            "gasconsumed" : "198754",
            "notifications" : [],
            "stack" : [
               {
                  "type" : "Integer",
                  "value" : "0"
               }
            ],
            "trigger" : "Application",
            "vmstate" : "HALT"
         }
      ],
      "txid" :
      "0x61681ce24dffea5481e9a50b10159b43b7ebfc21967b0b06fee7ff69c7123e3
      f"
   }
}
```
(base) ekaterinapavlova@MacBook-Air-4 neo-go % curl -X POST  https://rpc
.t5.n3.nspcc.ru:20331 -H 'Content-Type: application/json' -d '{
  "jsonrpc": "2.0",
  "method": "getapplicationlog",
  "params":
  ["61681ce24dffea5481e9a50b10159b43b7ebfc21967b0b06fee7ff69c7123e3f"],
  "id": 1
}' | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time
  Current
                                 Dload  Upload   Total   Spent    Left
                                 Speed
100   583  100   423  100   160   1424    538 --:--:-- --:--:-- --:--:--
  1969
{
   "id" : 1,
   "jsonrpc" : "2.0",
   "result" : {
      "executions" : [
         {
            "exception" : "at instruction 120 (SYSCALL): can't calculate
             bonus of height unequal (BlockHeight + 1)",
            "gasconsumed" : "198754",
            "notifications" : [],
            "stack" : [
               {
                  "type" : "Integer",
                  "value" : "4704605"
               },
               {
                  "type" : "ByteString",
                  "value" : "KfYYlDe/fxqqqm1yr7o5XLnQ7uk="
               }
            ],
            "trigger" : "Application",
            "vmstate" : "FAULT"
         }
      ],
      "txid" :
      "0x61681ce24dffea5481e9a50b10159b43b7ebfc21967b0b06fee7ff69c7123e3
      f"
   }
}

```
```
(base) ekaterinapavlova@MacBook-Air-4 neo-go % ./bin/neo-go contract
invokefunction -r https://rpc.t5.n3.nspcc.ru:20331 -w ./testnet_wallet
.json 1e6f88377a6c6bc4f683a5fc61eed5645ec5f123 unclaimedGas
e9eed0b95c39baaf726daaaa1a7fbf379418f629 4704605
Enter account NWtk9HYWsf1njtSzA3XNgwZXRtriACcJ9G password >
Warning: FAULT VM state returned from the RPC node: at instruction 120
(SYSCALL): can't calculate bonus of height unequal (BlockHeight + 1).
Use --force flag to send the transaction anyway.
```

Close #3589

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
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 to go, we need 0.106.4...

@AnnaShaleva AnnaShaleva merged commit c960a7e into master Oct 4, 2024
18 checks passed
@AnnaShaleva AnnaShaleva deleted the unclaimed-gas branch October 4, 2024 14:03
@AnnaShaleva AnnaShaleva changed the title vm: fix unclaimedGas calculation native: fix unclaimedGas calculation Oct 4, 2024
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.

unclaimedGas execution result difference
3 participants