dsteem: getOperationsStream() Broken For "Latest"

in bug-hunting •  6 years ago 

computer-bug-cartoon-illustration.jpg

Three days ago I asked the question of how to import 'Latest' blocks instead of 'Irreversible' ones. The problem with retrieving only immutable blocks from the Steemit API is that it takes about 20 blocks before they become immutable. One minute lag is far too long for a significant percentage of applications.

The drawback of using 'Latest' is that you might use information that get's deleted from the blockchain. This is something dapps need to deal with in the event of bad blocks being created. I'm not sure how often this happens, but I assume not very.

Regardless, I've finally found a solution, and the difference between 3-6 seconds of lag compared to 50-70 seconds is certainly worth the risk.

However, where does the Steemit API retrieve the blocks from? I figure if I get the blocks directly from the witnesses I can cut that 3-6 seconds into even less time. I guess I'll worry about that later.


In any case, this is supposed to work:

Bugged

client.blockchain.getOperationsStream({mode:dsteem.BlockchainMode.Latest})

This simply does not work. Took me quite a while to figure out it is just flat out bugged. Using getBlockStream() instead works just fine:

Works

client.blockchain.getBlockStream({mode:dsteem.BlockchainMode.Latest})

It turns out dsteem.BlockchainMode.Latest actually just evaluates to 1


export enum BlockchainMode {
    /**
     * Only get irreversible blocks.
     */
    Irreversible,
    /**
     * Get all blocks.
     */
    Latest,
}

This is TypeScript... I'm not familiar with it, but apparently Latest just evaluates to 1 and Irreversible just evaluates to 0, so these are interchangeable. I assum enum is obviously short for enumerated so these things are just sitting in some kind of array being evaluated to integers.

Therefore, this code is equivalent to what I need (and how I am now writing it):

client.blockchain.getBlockStream({mode:1})

Another annoying thing about this whole situation is that importing the full blocks is a bit different than importing standalone operations. It took a few too many conversions in my code to make the switch.

Whatever, I did it... and I'm never going to import standalone operations again for various reasons including this bug. When it really comes down to it, it's smarter to import the full block so that you know you have everything and can database the information easier and with less worry that you have all the information.

Conclusion

Steemit API documentation is still abysmal.
The latest version of dsteem still doesn't work.
Using Version 10 still.

Hopefully after RocksDB they come back and fix stuff like this
instead of trying to push more SMT nonsense.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Steemit has been updating their own steem-js more frequently. Maybe it can do what you require and actually work? I'm just saying...

  ·  6 years ago (edited)

When in really comes down to it the functionality I need is VERY sparse.

I need to be able to Stream blocks.
I need to be able to post to the blockchain.

That's about it.
Input/Output

In the future I expect I'll be able to acquire all the functionality I need without even having to use Steemit's garbage API.

You know, I was wondering about that.

I thought they were going to make the switch to dsteem,
so perhaps I'm wasting my time.

dSteem was developed by a former contractor, and they forked it, which is now updated less than their main steem-js. nordeberg has been updating his original though. He's also the one who started the whole "fork Steemit out of their stake" pull request, and fiasco. So I don't think Steemit cares or wants to keep going with dSteem ;)

Sadly, I think we are going to see more of these bugs appear in dSteem. It has been a somewhat stable library, but now that Steemit's own library has pulled ahead, it's not going to be a feasible choice soon enough.

The advantage of dSteem used to be its asynchronous methods allowing you to use async/awaitwith them without needing to use the old Node-style callbacks and wrap in a Promise. But, for over a year now the steem-js package uses Promise.promisfy to wrap those Node-style callbacks for us.

I ditched using dSteem a little while ago, especially after all of that crap the dev tried pulling which caused STINC to power down their stake and the whole back and forth situation with Ned.

The upside of dSteem still is the documentation. The documentation sucks for the steem-js package, but it would make for a good community contribution if someone wanted to dig through the code. The unit tests are the real documentation for it at present.

Yeah I guess it's time to let dsteem die.
No worries, I suppose.

Thanks for the info.