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

getblockstats rpc call bug #1292

Merged
merged 2 commits into from
Sep 26, 2018

Conversation

iFoggz
Copy link
Member

@iFoggz iFoggz commented Sep 9, 2018

Fix for the rpc call of getblockstats.

essentially what was happening was the univalue handles differently between ui and command line call/http call

The problem was the division by 0 when the super_count was 0 resulting in a result leaving an empty result in json reply. essentially when univalue tried to process the read on it the json was invalid.

{
    "result": {
        "general": {
            "blocks": 300,
            "first_height": 662970,
            "last_height": 663269,
            "first_time": "09-08-2018 13:34:08",
            "last_time": "09-08-2018 21:42:56",
            "time_span_hour": 8.146666666666667,
            "min_blocksizek": 0.66796875,
            "max_blocksizek": 2.3623046875,
            "min_posdiff": 0.1908121344114042,
            "max_posdiff": 1.079405079553315
        },
        "counts": {
            "block": 300,
            "empty_block": 294,
            "transaction": 16,
            "proof_of_stake": 300,
            "boincreward": 57,
            "super": 0
        },
        "totals": {
            "block": 300,
            "research": 5959.07,
            "interest": 3000,
            "mint": 8959.02707068,
            "blocksizek": 277.5283203125,
            "posdiff": 132.7511044050859
        },
        "averages": {
            "research": 104.5450877192982,
            "interest": 10,
            "mint": 29.86342356893334,
            "spacing_sec": 97.76000000000001,
            "block_per_day": 883.7970540098199,
            "transaction": 2.666666666666667,
            "blocksizek": 0.9250944010416666,
            "posdiff": 0.4425036813502863,
            "super_spacing_hrs": 
        },
        "versions": {
            "v3.7.16.1-gf5ba8a39d": 0.6899999999999999,
            "v3.7.16.1-unk": 0.18,
            "v3.7.16.1-gb8a05cc63": 0.06,
            "v3.7.16.1-g79490a2c9": 0.03666666666666667,
            "v3.7.16.1-g44df901f0-dirty": 0.03,
            "v3.7.16.1-g44df901f0": 0.003333333333333334
        },
        "cpids": {
            "1963a6f109ea770c195a0e1afacd2eba": 0.4533333333333333,
            "INVESTOR": 0.34,
            "8f2a530cf6f73647af4c680c3471ea65": 0.08666666666666667,
            "363d6c820aef2dbbe082768b40feed0d": 0.02,
            "ae09ae64245d408ee781bcca0841e218": 0.01666666666666667,
            "bc0621a4ac4610ffa400a0d298c02e23": 0.01666666666666667,
            "d0cea85e7a4a3e30af709e672dace08b": 0.01666666666666667,
            "163f049997e8a2dee054d69a7720bf05": 0.01333333333333333,
            "d40e500cd13f2eaa895d374a3e7f3d86": 0.01333333333333333,
            "a914eba952be5dfcf73d926b508fd5fa": 0.01,
            "7d0d73fe026d66fd4ab8d5d8da32a611": 0.006666666666666667,
            "17029c4576fc8e66b21dfec118099199": 0.003333333333333334,
            "71e89425d98117eba0b2e86a5e517803": 0.003333333333333334
        },
        "orgs": {
            "bgb-desktop": 0.4533333333333333,
            "caraka": 0.1,
            "langfod-f1": 0.09,
            "barton26-pi": 0.08666666666666667,
            "TomasBrod.Sa.E": 0.06,
            "dc7d": 0.05,
            "noah-blaker": 0.02,
            "shmoogleosukami-win10-NN": 0.01666666666666667,
            "jamescowens-windows": 0.01666666666666667,
            "Nethhlek": 0.01666666666666667,
            "bgb-test-pool-stake-3": 0.01333333333333333,
            "ToggletonLinuxGit": 0.01333333333333333,
            "bgb-test-pool-stake-2": 0.01,
            "G_UK-Pi64-Buster": 0.006666666666666667,
            "bgb-test-pool-stake-1": 0.006666666666666667,
            "G_UK-x64-DebianStretch": 0.006666666666666667,
            "G_UK-Pi64-Stretch": 0.006666666666666667,
            "delta": 0.003333333333333334,
            "jamescowens-Odroid-XU4": 0.003333333333333334,
            "jamescowens-linux-compiled_from_git": 0.003333333333333334,
            "KarVi71": 0.003333333333333334,
            "koolobus-0-Win": 0.003333333333333334,
            "langfod": 0.003333333333333334,
            "langfod-nn1": 0.003333333333333334,
            "G_UK-PiZeroW-Raspbian": 0.003333333333333334
        }
    },
    "error": null,
    "id": 1
}

as you can see super_spacing_hrs

@iFoggz
Copy link
Member Author

iFoggz commented Sep 9, 2018

#1290

division by zero is undefined behaviour and the end result was this

@denravonska denravonska changed the base branch from development to staging September 9, 2018 04:16
@denravonska denravonska changed the base branch from staging to development September 9, 2018 04:16
@tomasbrod
Copy link
Member

Floating point division by zero IS defined by IEEE 754. The problem is handling of NaN, +inf and -inf surreal numbers.
I agree, I should have checked for zero divisor.

if (super_count > 0)
result.pushKV("super_spacing_hrs", (((double)l_last_time-(double)l_first_time)/(double)super_count)/3600.0);
else
result.pushKV("super_spacing_hrs", "N/A");
Copy link
Member

Choose a reason for hiding this comment

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

I think we should strive for not including "null" values in the JSON output, see https://google.github.io/styleguide/jsoncstyleguide.xml#Empty/Null_Property_Values

@denravonska denravonska added this to the Betsy milestone Sep 10, 2018
@denravonska denravonska changed the base branch from development to staging September 26, 2018 03:39
@denravonska denravonska merged commit 14e33c8 into gridcoin-community:staging Sep 26, 2018
denravonska added a commit that referenced this pull request Oct 19, 2018
Added:
 - Linux nodes can now stake superblocks using forwarded contracts #1060 (@tomasbrod).

Changed:
 - Replace interest with constant block reward #1160 (@tomasbrod).
   Fork is set to trigger at block 1420000.
 - Raise coinstake output count limit to 8 #1261 (@tomasbrod).
 - Port of Bitcoin hash implementation #1208 (@jamescowens).
 - Minor canges for the build documentation #1091 (@Lenni).
 - Allow sendmany to be used without an account specified #1158 (@Foggyx420).

Fixed:
 - Fix `cpids` and `validcpids` not returning the correct data #1233
   (@Foggyx420).
 - Fix `listsinceblock` not showing mined blocks to change addresses #501 (@Foggyx420).
 - Fix crash when raining using a locked wallet #1236 (@Foggyx420).
 - Fix invalid stake reward/fee calculation (@jamescowens).
 - Fix divide by zero bug in `getblockstats` RPC #1292 (@Foggyx420).
 - Bypass historical bad blocks on testnet #1252 (@Quezacoatl1).
 - Fix MacOS memorybarrier warnings #1193 (@ghost).

Removed:
 - Remove neuralhash from the getpeerinfo and node stats #1123 (@Foggyx420).
 - Remove obsolete NN code #1121 (@Foggyx420).
 - Remove (lower) Mint Limiter #1212 (@tomasbrod).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants