dhive: RPC Failover Support

in HiveDevs2 years ago (edited)


Greetings #Hivers & fellow developers,

I've just pushed a new version, 0.13.3, to dhive (JS library) that enables native RPC node failover-support. This feature is optional and is only active if an array of RPC nodes is given as the first argument in a Client.

import {Client} from '@hivechain/dhive'

// Failover
const client = new Client(['https://api.hive.blog', 'https://api.hivekings.com', 'https://anyx.io'], { failoverThreshold: 3 /* default */})

// No failover
const simpleClient = new Client('https://api.hive.blog')

Relevant Options Parameters

new Client(url, options)

- failoverThreshold (default: 3): Specifies the number of times the URLs (RPC nodes) should be iterated and retried in case of timeout errors. Requires the first URL parameter to be an array! It can be set to 0 to iterate and retry forever.

- timeout (default: 60 * 1000ms): Send timeout, how long to wait in milliseconds before giving up on an RPC call. It can be set to 0 to retry forever.

GitLab Pull Request (Code)


Why is this relevant?

Normally, you have to take care of potential failovers in your application yourself. This can produce redundant code. Having a native solution is far cleaner.

Another solution is a wrapper around dhive that enables failover. There is dsteem-pool, but it didn't work for me.


Code has been tested and everything should be working fine: https://gitlab.syncad.com/hive/dhive/-/blob/master/test/client.ts#L15-20

However, for very sensitive operations, please still be careful and rather double-check.

With this said:

If there are any problems/questions, please create an issue https://gitlab.syncad.com/hive/dhive/issues




Great work, dhive is getting way better by each day 🙌 💪

Amazing work. I didn't even know there was a dhive library. I've been using the hivechain dsteem library instead in my Hive Stream library. As you mention, failover support is something app authors have to work out themselves, but it can get really messy writing that kind of recursive code (especially using promises). I'm going to switch to this and remove my fail over code. It'll make my library so much cleaner.

Glad to see nice developments here

Wolf, I still can't upload pics on the hive blog.

It´s really exciting to see how much development has been going on in our new home. Thanks for your contribution @therealwolf, it´s much appreciated. Sorry for a bit of OT but I just wanted to ask you... would you be interested in supporting potential participants of this Hive onboarding initiative?

It is awesome to see this feature. Failover support is definitely a great feature and like you mentioned it is good to have it in the library itself than developers having it in their individual applications. Nice work 👌

Nice, automatic fallovers are important to make user experiences better, nobody like being greeted with a broken page because an RPC node happens to have a hickup.