RunOnFlux / flux

Flux, Your Gateway to a Decentralized World. https://home.runonflux.io https://api.runonflux.io https://docs.runonflux.io https://source.runonflux.io https://wiki.runonflux.io
https://home.runonflux.io
GNU Affero General Public License v3.0
234 stars 308 forks source link

Feature - enable fluxd subscription endpoint #1363

Closed MorningLightMountain713 closed 2 months ago

MorningLightMountain713 commented 2 months ago

What this pull does

This pull request is a precursor for one of my other pulls so I can make it smaller.

Background

Currently, we have to poll fluxd whenever we want updates. This means data is stale, and there is a lot of unnecessary cycles burnt looking for data, and we are using multiple levels of caching, which aren't really a good fit for what we are trying to do.

With the zmq endpoint enabled, we can subscribe to block updates, and know exactly when new information is ready to fetch. So we don't need to poll anymore.

This pub / sub endpoint is read only and only available on localhost.

Testing

I've tested this on Ubuntu 18 running Node 14.18.1 - the only caveat is that zeromq has to build from source on ubuntu 18, which takes roughly an extra 30 seconds to install on the first run.

I've tested it on an ubuntu 20 and 22 node - both update fine after the 20 minute timeout. (give fluxd time to warm up)

I've added quite a lot of tests and checks around the fluxd config file. Obviously we don't want to break fluxd. This is the process and the assumptions that have been made:

Assumption made that all nodes have zelcash.service as the supervisor of fluxd.

I'd like to get this run on a bunch of nodes first, or feedback on if there are nodes out there that are running non standard config file locations and stuff.

MorningLightMountain713 commented 2 months ago

All tests passing. We've cracked 2k tests!

Screenshot 2024-07-03 at 4 22 12 PM

MorningLightMountain713 commented 2 months ago

I added another check - if sudo systemctl status zelcash.service returns an error, we skip enabling zmq

The above command will return an error if the service is not running, or doesn't exist.

Have also added another test around this.

Fixed up function name where I had a typo too.

If we get this merged, I'll get a pull in to update the default fluxd multitoolbox config