Coming Soon: A Major Refactor of the Hive-Engine distribution-engine-smt, Maybe?

(edited)

Sometimes, a small bug report can lead you down a deep rabbit hole. What starts as a "quick fix" spirals into a multi-day project. That's exactly what happened over the last couple of days, and I'm excited to share the results of a major refactor that will soon be proposed for the Hive-Engine distribution-engine-smt.

The Problem

It all started when I noticed that the rewards on the 1UP outpost weren't being reported correctly; they were just showing a zero balance.

1up broken

My first step was to check the API call that the frontend uses. I tried it manually and was immediately greeted with a 500 Internal Server Error. Well, that's definitely not good.

api broken

The Investigation

This sent me digging into the source code of the distribution-engine-smt backend that Hive-Engine uses. What I found was... surprising. The code was still using the old beem library for its blockchain interactions. Gasp! No wonder it wasn't working correctly.

My initial thought was that I'd just do a quick update, swap it over to hive-nectar, and call it a day. But as I got deeper into the code, I realized that wasn't the only issue. Just like a lot of older codebases, it was using datetime objects that were not timezone-aware, had a lot of linting errors, and was cluttered with unused imports.

The "Quick Fix" That Snowballed

So, I started cleaning it up. I fixed the code, updated the libraries, and then it came time to build the database to see if my changes worked. The initial sync process was taking far too long, streaming the main Hive chain and the Hive-Engine sidechain block by block.

To solve this, I added a batch mode to process the blocks in 1,000-block chunks. (You might remember me adding that bulk query feature to nectarengine recently... now you know why!)

One thing led to another, and I ended up refactoring nearly the whole thing. The application now uses StreamHandlers for processing the blockchain and is, I feel, much easier to read and maintain.

The Results

And the results speak for themselves. After the refactor, the API call now works perfectly.

api working

Most importantly, with the API now feeding it the correct data, the 1UP outpost is displaying the rewards properly!

1up working

I have a tiny bit more work to do to button everything up, and then I'll be submitting an official pull request to the Hive-Engine team. Hopefully, they accept it so everyone can benefit from a more stable and reliable SMT API.

If you want to take a peek at it, have a gander at the GitHub Dev Branch.

As always,
Michael Garcia a.k.a. TheCrazyGM

0.05779258 BEE
2 comments

You're a fricking badass, my friend! That's extraordinary! I can't imagine that the Hive Engine team wouldn't accept it, as it obviously improves the functionality of the code. 😁 🙏 💚 ✨ 🤙

0.00059218 BEE

Congratulations @thecrazygm! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You have been a buzzy bee and published a post every day of the week.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

0.00058021 BEE