create account

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

View this thread on: hive.blogpeakd.comecency.com
· @thecrazygm · (edited)
$41.15
Coming Soon: A Major Refactor of the Hive-Engine distribution-engine-smt, Maybe?
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](https://files.peakd.com/file/peakd-hive/thecrazygm/23t8D6MsrmvtwBDKxExiUQYJzkLGbUzjuw1kdtL57dm7rfu8wmWt8WGP9nAVZtnBy9j3W.png)

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](https://files.peakd.com/file/peakd-hive/thecrazygm/23t72wiabGmWrQ9mN6ckFGrqxx35ZmKhve5TFAVFjkb67UFSZTA5hBKZcvR6iHSY5yU5K.png)

#### 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](https://files.peakd.com/file/peakd-hive/thecrazygm/23swZX8rPywbbdt4JpTtD2ouobreByu388EZsB6vDT149W9RFXGhoT4p2a14cvpTZ1g23.png)

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

![1up working](https://files.peakd.com/file/peakd-hive/thecrazygm/23tHb6kpjALDMr6arRTZKSBJgDgX2SHCxsMN75Pjkn9RyjGhEqcnS8Hrchhzh8mxk6LPx.png)

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](https://github.com/TheCrazyGM/distribution-engine-smt/tree/dev).

As always,
Michael Garcia a.k.a. TheCrazyGM
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 168 others
👎  
properties (23)
authorthecrazygm
permlinkcoming-soon-a-major-refactor-of-the-hive-engine-distribution-engine-smt-maybe
categoryhive-186392
json_metadata{"app":"peakd/2025.7.3","format":"markdown","image":["https://files.peakd.com/file/peakd-hive/thecrazygm/23t8D6MsrmvtwBDKxExiUQYJzkLGbUzjuw1kdtL57dm7rfu8wmWt8WGP9nAVZtnBy9j3W.png","https://files.peakd.com/file/peakd-hive/thecrazygm/23t72wiabGmWrQ9mN6ckFGrqxx35ZmKhve5TFAVFjkb67UFSZTA5hBKZcvR6iHSY5yU5K.png","https://files.peakd.com/file/peakd-hive/thecrazygm/23swZX8rPywbbdt4JpTtD2ouobreByu388EZsB6vDT149W9RFXGhoT4p2a14cvpTZ1g23.png","https://files.peakd.com/file/peakd-hive/thecrazygm/23tHb6kpjALDMr6arRTZKSBJgDgX2SHCxsMN75Pjkn9RyjGhEqcnS8Hrchhzh8mxk6LPx.png"],"tags":["dev","hiveengine","scot","smt","tribes","archon","pimp","proofofbrain","oneup","arcadecolony"],"users":[]}
created2025-07-20 13:13:39
last_update2025-07-20 14:43:54
depth0
children2
last_payout2025-07-27 13:13:39
cashout_time1969-12-31 23:59:59
total_payout_value18.920 HBD
curator_payout_value22.232 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,207
author_reputation117,140,459,738,175
root_title"Coming Soon: A Major Refactor of the Hive-Engine distribution-engine-smt, Maybe?"
beneficiaries
0.
accountthecrazygm.bank
weight1,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id144,238,173
net_rshares134,202,694,550,525
author_curate_reward""
vote details (233)
@hivebuzz ·
Congratulations @thecrazygm! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

<table><tr><td><img src="https://images.hive.blog/60x60/https://hivebuzz.me/badges/postallweek.png"></td><td>You have been a buzzy bee and published a post every day of the week.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@thecrazygm) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>

👍  
👎  ,
properties (23)
authorhivebuzz
permlinknotify-1753069311
categoryhive-186392
json_metadata{"image":["https://hivebuzz.me/notify.t6.png"]}
created2025-07-21 03:41:51
last_update2025-07-21 03:41:51
depth1
children0
last_payout2025-07-28 03:41:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length607
author_reputation369,471,453,088,962
root_title"Coming Soon: A Major Refactor of the Hive-Engine distribution-engine-smt, Maybe?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id144,259,509
net_rshares-8,709,346,908
author_curate_reward""
vote details (3)
@tydynrain ·
$0.03
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. 😁 🙏 💚 ✨ 🤙 
👍  
properties (23)
authortydynrain
permlinkre-thecrazygm-2025720t20947899z
categoryhive-186392
json_metadata{"links":[],"type":"comment","tags":["hive-186392","dev","hiveengine","scot","smt","tribes","archon","pimp","proofofbrain","oneup","arcadecolony"],"app":"ecency/3.3.3-mobile","format":"markdown+html"}
created2025-07-21 06:09:51
last_update2025-07-21 06:09:51
depth1
children0
last_payout2025-07-28 06:09:51
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length187
author_reputation209,979,605,186,825
root_title"Coming Soon: A Major Refactor of the Hive-Engine distribution-engine-smt, Maybe?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id144,261,142
net_rshares80,827,552,000
author_curate_reward""
vote details (1)