meritlabs / merit

Merit aims to be the world's most adopted digital currency.
https://www.merit.me
MIT License
192 stars 20 forks source link

RPC getblocktemplate returns version: -1476395008 #392

Open nickoarg opened 6 years ago

nickoarg commented 6 years ago

Describe the issue

Pool receives an incorrect version data in the rpc response for getworktemplate

Can you reliably reproduce the issue?

Yes

If so, please list the steps to reproduce below:

  1. Compile in linux, ubuntu 16.04
  2. run meritd --daemon
  3. curl --user rpcpool --data-binary '{"jsonrpc":"1.0", "method" : "getblocktemplate","params" : [{"capabilities" : ["coinbasetxn","workid","coinbase/append"]}],"id" : 2}' -H 'content-type: text/plain;' http://127.0.0.1:8332/

get: Enter host password for user 'rpcpool': {"result":{"capabilities":["proposal"],"version":-1476395008,"previousblockhash": ...

Expected behaviour

Version should be valid System.UInt32

Actual behaviour

meritd returned an invalid value

Screenshots.

image

What version of merit-core are you using?

Self compiled from source

Machine specs:

nickoarg commented 6 years ago

https://github.com/meritlabs/merit/blob/da2c1449daa6e88746428edddacbf6afc5103363/src/rpc/mining.cpp#L714

Removed that line, recomiled and it works.

tonypizzicato commented 6 years ago

@nickoarg what's your gcc version?

tonypizzicato commented 6 years ago

can you try to replace this line with result.push_back(Pair("version", static_cast<uint64_t>(pblock->nVersion))); and paste returned block version here?

barrystyle commented 6 years ago
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int main()
{
        uint32_t versionBits = -1476395008;
        printf("%08x \n", versionBits);

        return(0);
}

a8000000

while not conventional, the version is just fine..

nickoarg commented 6 years ago

Hi Tony,

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.

And the returned bloc after modifying with the suggested change: System.Exception: There was a problem deserializing the response from the coin wallet. ---> Newtonsoft.Json.JsonSerializationException: Error converting value 18446744072233156608 to type 'System.UInt32'. Path 'result.version', line 6, position 35. ---> System.InvalidOperationException: Can not convert from BigInteger to System.UInt32. ---> System.OverflowException: Value was either too large or too small for an Int64.

barrystyle commented 6 years ago

System.Exception: There was a problem deserializing the response from the coin wallet. ---> Newtonsoft.Json.JsonSerializationException: Error converting value 18446744072233156608 to type 'System.UInt32'. Path 'result.version', line 6, position 35. ---> System.InvalidOperationException: Can not convert from BigInteger to System.UInt32. ---> System.OverflowException: Value was either too large or too small for an Int64.

thats not an issue with gcc, thats from .net, where are you seeing this?

nickoarg commented 6 years ago

At the pool software. Yes, is the .net that is complaining. But the json Object deserializator is external, so I beleive that the merit node is returning an unexpected value.

tonypizzicato commented 6 years ago

looks like a quick fix can be result.push_back(Pair("version", strprintf("%u", pblock->nVersion))); we need to figure out why this is happening though

nickoarg commented 6 years ago
System.Exception: There was a problem deserializing the response from the coin wallet. ---> Newtonsoft.Json.JsonSerializationException: Error converting value "-1476395008" to type 'System.UInt32'. Path 'result.version', line 7, position 28. ---> System.OverflowException: Value was either too large or too small for a UInt32.
  at System.Number.ParseUInt32 (System.String value, System.Globalization.NumberStyles options, System.Globalization.NumberFormatInfo numfmt) <0x7f9edd1eab70 + 0x0013a> in <2943701620b54f86b436d3ffad010412>:0

I'm still getting this error

    //result.push_back(Pair("version", pblock->nVersion));
    result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
    result.push_back(Pair("version", strprintf("%u", pblock->nVersion)));
barrystyle commented 6 years ago

@nickoarg https://github.com/bonesoul/CoiniumServ/issues/933 shows a similar issue where it overflows a uint32/64 using dotnet, might provide some clues?

i can speak authoritatively here and say icemining (the first non-dev pool) interprets the version -1476395008 as versionbits a8000000, with no issues on submitblock, nor warnings like unknown block versions are being mined, which I have recently observed in the past few days.

interpreting version as a uint32 should return 2818572288, then as hex a8000000.

not a great solution, but try: result.push_back(Pair("version", strprintf("%u", 2818572288)));

nickoarg commented 6 years ago

I've updated the node to 0.6.4 and the issue persists. I'll see if I can use bonesoul/CoiniumServ#933

barrystyle commented 6 years ago

@nickoarg try this: https://github.com/barrystyle/merit/commit/e6f5794c15534e08c9454a5b4cb20ff88fb79d57

have submitted PR to merits team

nickoarg commented 6 years ago

Just tried that. Same result:

21:06:17 [Fatal] [Program] [global] Terminating because of unhandled exception!
System.Exception: There was a problem deserializing the response from the coin wallet. ---> Newtonsoft.Json.JsonSerializationException: Error converting value -1476395008 to type 'System.UInt32'. Path 'result.version', line 6, position 26. ---> System.OverflowException: Value was either too large or too small for a UInt32.
  at System.Int64.System.IConvertible.ToUInt32 (System.IFormatProvider provider) <0x7f0bf51e6680 + 0x0002d> in <2943701620b54f86b436d3ffad010412>:0
  at System.Convert.ChangeType (System.Object value, System.Type conversionType, System.IFormatProvider provider) <0x7f0bf51bbe60 + 0x0028d> in <2943701620b54f86b436d3ffad010412>:0
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType (Newtonsoft.Json.JsonReader reader, System.Object value, System.Globalization.CultureInfo culture, Newtonsoft.Json.Serialization.JsonContract contract, System.Type targetType) [0x000c0] in <b1d2c1d6f4dd47bea2964bdd6464f67d>:0

Running over Mono 5.14.0.177 (tarball Mon Aug 6 09:13:43 UTC 2018), framework: 4.5 (v4.0.30319.42000).

barrystyle commented 6 years ago

its still displaying -1476395008? do you want to doublecheck & compile again?

the build displays that number on my machine pre-patch.. the patch gives 671088640 as a result

nickoarg commented 6 years ago

Yes, confirmed. image

image

barrystyle commented 6 years ago

can you post the output of:

merit-cli getblocktemplate '{"capabilities":["coinbasetxn","workid","coinbase/append"]}'

nickoarg commented 6 years ago

Sure

ubuntu@ip-172-31-86-11:~/merit$ merit-cli getblocktemplate '{"capabilities":["coinbasetxn","workid","coinbase/append"]}'
{
  "capabilities": [
    "proposal"
  ],
  "version": -1476395008,
  "previousblockhash": "472524a6771cad88361f404da4b0b9df6c6c2183268b601214156a2172817fe0",
  "transactions": [
    {
      "data": "02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0503a1b00500ffffffff1609ca9a3b000000001976a914f7f82309321e87b27bb0b69716e83d2ea698631f88ac0694a603000000001976a91460442c3a09a673e3df8e024e3c3d90232f21354188ac1a80ec02000000001976a914ac53076781e72c07042a435e8395223887ef648088ac2fbb1503000000001976a9144a0b2940c041e0328dd127ee03addddb6696b55488acb89eb103000000001976a9142c930dff417ce135d133a0d6b4bd91b27885390788ac128b8303000000001976a91467495491b4673de8299b1f6a983b3c719be09f4f88ac611e3503000000001976a914d76c02e7bcff8d864ff3557b83e40b7dfdfab93d88ac67024c03000000001976a9146e92f83064c5bba2c1f73b4cb6947512bc62467b88aca30cb502000000001976a914db0bb09cc5b465f503b2cedd82d8dc6eb80cb72e88ac49ca3103000000001976a914ee34a60e8fe4223c0ad57600b7d70713c73c216e88acbb0d7603000000001976a9145cdcaad0a61feeff8c474d50daf79885bd08694188ace668cb02000000001976a914772fee9f5780658825c943d4c11c623eb69cd48388ac21b10503000000001976a91491b993ce95e687a1cc901a31c7b63d3333607e5788ac06e3c502000000001976a9146cad0cd440df9d2132567af43e94b60b0b9a0c1088ac6647c902000000001976a9148896c31b61795506e4337dde338f295ef3ddac4c88acaad39c02000000001976a9147b7531de9c60c036d286bd5ccf9906d74f46931288ac8cd0d502000000001976a91481b2e30dc37bebdf8fe81e3dbf3807e56ce1cf1a88acbbd6d402000000001976a91420e6f1131d3560322470e1432632a0f604f36c2688acea2e6602000000001976a91404d95d1bdec745b6e5efd181d47b2ec7eb55861088ac75a27402000000001976a9146b6fd12aa5b86e7b059877db10daa86632a19d5088acac3a5c02000000001976a9145efede3c12ecd5d214a86003322b00cb21a5fc1288ac0000000000000000266a24aa21a9ed598bdca4eab6001d5753ba33e9a50b1986649f4b477948b5f761decd6b742b4e00000000",
      "coinbase": true,
      "txid": "3cae4c385dddaa657a51120b472df9a3a74b9ed38570c4c3412b8d0ff11097df",
      "hash": "3cae4c385dddaa657a51120b472df9a3a74b9ed38570c4c3412b8d0ff11097df",
      "depends": [
      ],
      "fee": 0,
      "sigops": 84,
      "weight": 3304
    }
  ],
  "invites": [
    {
      "data": "03000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0503a1b00500ffffffff0101000000000000001976a914e8d78696984c62609ac13707d3383c66b7196f3d88ac00000000",
      "txid": "f65edc71282becef846c55e48f45dc66ac216632c8cb296a419e48fc58bab0b5",
      "hash": "f65edc71282becef846c55e48f45dc66ac216632c8cb296a419e48fc58bab0b5",
      "depends": [
      ],
      "sigops": 84,
      "weight": 360
    }
  ],
  "referrals": [
  ],
  "coinbaseaux": {
    "flags": ""
  },
  "coinbasevalue": 1000000009,
  "longpollid": "472524a6771cad88361f404da4b0b9df6c6c2183268b601214156a2172817fe050",
  "target": "0000a76a00000000000000000000000000000000000000000000000000000000",
  "mintime": 1536794080,
  "mutable": [
    "time",
    "transactions",
    "invites",
    "referrals",
    "prevblock"
  ],
  "noncerange": "00000000ffffffff",
  "sigoplimit": 240000,
  "sizelimit": 16000000,
  "weightlimit": 16000000,
  "curtime": 1536960673,
  "bits": "1f00a76a",
  "edgebits": 26,
  "height": 372897,
  "default_witness_commitment": "6a24aa21a9ed598bdca4eab6001d5753ba33e9a50b1986649f4b477948b5f761decd6b742b4e"
}
barrystyle commented 6 years ago

ok, what response does it give once the patch is removed & daemon recompiled?

nickoarg commented 6 years ago

Confirmed, same output, even with make clean, git pull, all fresh.

ubuntu@ip-172-31-86-11:~/merit-pool$ merit-cli getblocktemplate '{"capabilities":["coinbasetxn","workid","coinbase/append"]}'
{
  "capabilities": [
    "proposal"
  ],
  "version": -1476395008,
  "previousblockhash": "8e9e27a26c1ca17f49d7e25b085ba931f1539269f5acb9b1fd644717d4ec0e19",
barrystyle commented 6 years ago

the only other thing i can think of is a path issue or forgetting to run 'make install' at end of compile. try running those commands directly from the build folder (prefaced with ./ like ./merit-cli)

actually, you cant write to /usr without sudo'ing (i notice youre not root)..

nickoarg commented 6 years ago

Hi, sorry for the delay, same result by making sure that I'm running the latest.

ubuntu@ip-172-31-86-11:~/merit/src$ ./merit-cli getblocktemplate '{"capabilities":["coinbasetxn","workid","coinbase/append"]}'
{
  "capabilities": [
    "proposal"
  ],
  "version": -1476395008,
barrystyle commented 6 years ago

As root; can you run: find / -name meritd | xargs ls -la