steemd produces incorrect JSON. No, really, no foolin, you can verify this for yourself. UPDATE: This is a piston-lib error

in #dawn-network7 years ago (edited)

In


my previous post I posted the code for a python script that streams the json output from steemd, and being a relative newbie to JSON encoding, I didn't realise that JSON does not use or accept single quotes. Here is the output of it (unmodified) from block one:

This has turned out to be an error in piston-lib, which I now am not using anymore, because it's broken and useless. @xeroc

{'extensions': [],
 'previous': '0000000000000000000000000000000000000000',
 'timestamp': '2016-03-24T16:05:00',
 'transaction_merkle_root': '0000000000000000000000000000000000000000',
 'transactions': [],
 'witness': 'initminer',
 'witness_signature': '204f8ad56a8f5cf722a02b035a61b500aa59b9519b2c33c77a80c0a714680a5a5a7a340d909d19996613c5e4ae92146b9add8a7a663eef37d837ef881477313043'}

This is the raw output that I pushed into a file you can see on ftp://projectinception.lt/block_log.json.xz (I am not making the uncompressed form because it is 31Gb (this is basically the whole block_logup until sometime yesterday).

Anyone who knows JSON can tell you this is the wrong format. But guess what, this is what comes out of an RPC node. I had to write this little gem to fix it:

        out_block = json.loads ( str ( block ).replace("'", '%temp%').replace('"', '\"').replace('%temp%', '"') )

and to be clear, this is how that data was acquired, in the same code:

props = rpc.get_dynamic_global_properties ( )
current_block = args.startblock
last_confirmed_block = props [ 'last_irreversible_block_num' ]
if args.startblock == -1:
  current_block = last_confirmed_block

while True:
    os.write ( 2, str.encode( "Block #" + str ( current_block ) + '\r' ) )
    #try:
    block = rpc.get_block(current_block)

I don't think this is @xeroc's error, this is a raw string coming out of steemd

This is the kind of inane nonsense that us developers are dealing with. I am making it known exactly what goes on because it is precisely this kind of repeated experience of incorrect programming that is probably an unspoken reason why so few developers are working with the chain.

I am doing this because I am determined to resolve this for the community and if Steemit isn't going to do the right thing, then we are going to give you all an exit route.

If you know a bit of how to work with python, you can find this code in the 'misc' repository on the dawn-network here: https://github.com/dawn-network/misc

Update

I have realised that the already long string substitution is going to break the single quotes inside the double quotes. I am importing the whole chain snapshot I made two days ago, so I have to write the correct substitution. I will write it in sed script because it will be a lot faster. Stay tuned for an update.

It gets worse too:

'Without any further ado, here is '
'the python script, it depends on '
"`piston-lib`'s module `pistonapi` "
'from @xeroc.\n'

For absolutely no good reason, now I have to write a very complex string processing algorithm that recognises correct sections, and leaves them alone, but fixes all the ones that are wrong. This is so nonstandard and wrong, my mind is blowing at the amount of work that this is going to cause me to have to do.

In fact I'd say that it would probably be less work after everything I have had to do so far, to just write a program that reads the binary data out of the block_log itself.

UPDATE

It is an error in piston-lib. So now I am quitting with working with python. Here is the request performed by curl:


curl --data '{"jsonrpc": "2.0", "method": "get_block", "params": [1], "id": 1 }' http://127.0.0.1:8090/rpc

{"id":1,"result":{"previous":"0000000000000000000000000000000000000000","timestamp":"2016-03-24T16:05:00","witness":"initminer","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"204f8ad56a8f5cf722a02b035a61b500aa59b9519b2c33c77a80c0a714680a5a5a7a340d909d19996613c5e4ae92146b9add8a7a663eef37d837ef881477313043","transactions":[]}}

😎


We can't code here! This is Whale country!

Vote #1 l0k1

Go to steemit.com/~witnesses to cast your vote by copying and pasting l0k1 into the text entry at the bottom of the leaderboard.

(note, my username is spelled El Zero Kay One or Lima Zero Kilo One, all lower case)

Sort:  

This has turned out to be an error in piston-lib, which I now am not using anymore, because it's broken and useless. @xeroc

How about you stop using pprint and instead use print(json.dumps(x))

All the data that is obtained through the API is python dict. If you don't convert it to JSON properly, it's not the error of the library, but an error in your code.

omg lol.
STEEM ERROR, steem is shit!
Oh no, piston error. Fucking dirt!
Erm...my own error? Can happen!

You are right, but other factors are bigger in my decision :) Like the ongoing issue of the unjust amplification of whale power, of the impossibility to get any of the issues that are leading to user attrition, the idiotic inflation policy, which I understand is thought to be necessary because of the forum system, which I think is the cart before the horse because reduced supply allows a more stable price. I mean, it would work, if the economy was growing at 100% or 9.5% per year, but the reality is the economy is shrinking so even 2% is too high. And because they invested so much in building a monolithic chain, within 5 years the block_log file will be over 200Gb in size. It's time to start again with a different model, and with people who don't secretly value more their bank balance than a growing community and internal economy. I am not covering the whole topic at all but there's too much and I have better things to do than explain what should be obvious.

Oh, btw, I used this:

variable = json.loads (x)
print (variable)

I may have used simplejson, in fact, but neither explains why the output came out in python string convention instead of json.

Good luck with your work, anyway. I just need to move to a more supportive environment where I can learn instead of spending so much time with such fractious people. (not you, of course).

Then please change the title to avoid misleading others.

I know JSON. But anyone who does not, can validate JSON over at http://jsonlint.com/

Pasting in the alleged JSON object above gives this error:
Expecting 'STRING', got 'undefined'

Turn the single quotes into double quotes and then you will have the strings in the proper format, and the object validates.

Good catch, @l0k1

yeah, how does this get past everyone for a whole year, is my question...

It did not get past me.

The way it "got past" everyone at steemit, inc is: LIES.

One day I will understand this better..

I just want to say that I've been saying this for more than eight months now. Corp-chains lie, and those lies have consequences for folks simply trying to do their job.

Thanks to @l0k1 and his diligence in this regard. Please know that lies on such a low level of a system, destroy it. To see my past posts coming to the exact same conclusion (there were many, many of which earned me more than my fair share of scorn and being called a liar, google faddat json steem. That should do more than well enough.

Regarding that exit route, you can participate in the creation of an exit, here:

https://discord.gg/8dWYbFS

Can this kind of in-congruence be abused by injection... ?

I doubt it could be abused but it certainly will waste a lot of time for developers.

Coin Marketplace

STEEM 0.19
TRX 0.13
JST 0.028
BTC 65178.97
ETH 3261.27
USDT 1.00
SBD 2.68