create account

A Hacky Guide to Hive (part 1.5) by felixxx

View this thread on: hive.blogpeakd.comecency.com
· @felixxx · (edited)
$32.63
A Hacky Guide to Hive (part 1.5)
## Black Box

6 months ago, I attempted writing a guide for programming with Hive.
I tried [looking at Hive as a black box](/@felixxx/hive-as-a-black-box).
I still like that concept, but after reading it all again, I realized that I've jumped too far ahead.
I'll try taking shorter strides this time.
I also changed the title and theme a little.

I am trying to explain the exact same things as in the first guide, just with a different approach and more elaborate. By the end, [the examples I posted recently](/@felixxx/python-requests-for-hive-json-rpc), should make more sense.

I'll base the guide around [the publicly available nodes](https://developers.hive.io/quickstart/#quickstart-hive-full-nodes), and I'll further explain, why that doesn't matter, later, but in this part we need to look at how you _would_ install your own Hive node.

<center>![FELIXBOXANTENA.png](https://files.peakd.com/file/peakd-hive/felixxx/23tRr8Yp4tXotCaDyQxBvwuP5vf3E9431i97P6h9dbWU7r74B3GjeGnCc4rCVkEZNdgcS.png)</center>

## Hive Nodes

Hive is a software with open [source code](https://github.com/openhive-network/hive).
So... you can download the code, 
compile it and then run a node. (the rhyme!)

![FELIXBOXVHSTAPE400.png](https://files.peakd.com/file/peakd-hive/felixxx/23u5T9MdcSRK9mfZk2nC313eoiiSBMeUGLm1r7SApy1oWkCMfn1BTvkeH9viZhaj3rTB4.png)

### block_log

The Hive blockchain itself gets stored as series of events.
The events are all segmented in 3-second intervals, which are called blocks.
But in the end, all events end up in one long file called ``block_log``.
It's almost like a long tape recording.

![FELIXBOXANTENAVCR400.png](https://files.peakd.com/file/peakd-hive/felixxx/23tRrRPbsEUHkGdhiZ2WKxvG9YD1upstXFdaqgThCizDn847M2WgDa6aj5e2rSgY1w1Pj.png)

### Hived

[Compiling the code for a Hive node](/@gtg/witness-update-release-candidate-for-eclipse-is-out#build-eclipse) will leave you with a ``hived`` binary.
That's the ``Hive daemon``.
You then need to synchronize your node with the network.
This means, your Hive daemon needs to go through all blocks and replay all state changes that happened up until now. 
In the tape analogy, you could load a block_log into you hived tape recorder and fast forward the tape, going over all past events, called indexing.
The Hive daemon watches all events and creates databases in the background.

### tables

There are different modules you can activate for your node, called plugins.
What's important here: for the most part, the API calls represent _get_ methods for underlying database tables.

The blockchain itself only documents the **changes**.
For example: The balance of an account is not directly accessible on the blockchain.
While the blockchain contains all transfers to and from an account, the final balance needs to be calculated;
The data needs to be compiled first, for quick access.

![FELIXBOXANTENAVCRMOUTHPIECE400.png](https://files.peakd.com/file/peakd-hive/felixxx/23tGTdjW2co6HfV1eVGavf8HSbE8QKkHXJf2Tj6BwFrk3GgbK4Xp1rn6uajuz2EcfTo3w.png)

## Custom Client

I'll try to write a hacky guide on how to build your own custom client for Hive.
It will enable you to build slim, reliable, customized services for Hive and operate them on a budget.

This is approach isn't the best for all applications; If you want to do historical stuff, analyzing large amounts of data, statistics and such things, HiveSQL is better.

If you don't know, where else to start, this could be a good bet.
However, ironically, I got questions about this stuff myself.

## Questions

To some extent, Hive's still a black box to me.
I know how to use some of it, but I don't understand how some of it really works.
Sometimes, all I can hope for is that one of the gods of Hive takes pity and lets themselves down from the Olymp to answer to a mortal.

- Wouldn't witness nodes need tables for things like account balance? How do they know, if someone isn't _stealing_? 

- ``block_api.get_block_range`` seems to access a table where the block number is a key. Why is there no public method, which starts from the last entry? At least in SQL databases that's a request with _linear_ speed. (And I could get to the head block in one step). [It probably has something to do with block reversibility or rocksDB](/@dan/fractally-s-groundbreaking-new-database-outperforms-lmbdx-eos-hive-chainbase-rocksdb)...

The good part is, that it doesn't really matter; I don't have to fully understand all of it.
If there was a fundamental flaw in consensus finding, serialization, signing and other such things, it would be too lucrative to exploit it - someone would have found it and we'd know.

## Notes

- Since I will be using Python requests, you can use the exact same code to access your own node, locally, or the public nodes, via https.
- I will not attempt to sign and broadcast anything for users. I will build a small html + JS based client as example, implementing [keychain](https://github.com/hive-keychain/hive-keychain-extension), because as [the developer portal](https://developers.hive.io/quickstart/#quickstart-hive-full-nodes/) states:
>By utilizing Authenticating services, you can eliminate or give more confidence to user, so they are assured their keys are safe. They can securely interact with your application, website or service.
- I have medical issues with my hand, so I asked @manclar to help me with the images for these posts, and paid him for it.
- This is a work in progress and subject to change.
I appreciate all feedback, but please try to not comment 'That's not right' without further explanation. At least provide a link or something.

<sub>tagging:
@chrislybear, @ana-maria, @arc7icwolf, @slobberchops
If you want to be included/excluded from this list of subscribers, please let me know.</sub>



















👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 303 others
properties (23)
authorfelixxx
permlinka-hacky-guide-to-hive-part-15
categorydev
json_metadata"{"app":"peakd/2024.8.7","description":"Second attempt at writing a guide for Hive","format":"markdown","image":["https://files.peakd.com/file/peakd-hive/felixxx/23tRr8Yp4tXotCaDyQxBvwuP5vf3E9431i97P6h9dbWU7r74B3GjeGnCc4rCVkEZNdgcS.png","https://files.peakd.com/file/peakd-hive/felixxx/23u5T9MdcSRK9mfZk2nC313eoiiSBMeUGLm1r7SApy1oWkCMfn1BTvkeH9viZhaj3rTB4.png","https://files.peakd.com/file/peakd-hive/felixxx/23tRrRPbsEUHkGdhiZ2WKxvG9YD1upstXFdaqgThCizDn847M2WgDa6aj5e2rSgY1w1Pj.png","https://files.peakd.com/file/peakd-hive/felixxx/23tGTdjW2co6HfV1eVGavf8HSbE8QKkHXJf2Tj6BwFrk3GgbK4Xp1rn6uajuz2EcfTo3w.png"],"tags":["dev","hive-dev","hivedev","hive"],"users":["felixxx","gtg","dan","manclar","chrislybear","ana-maria","arc7icwolf","slobberchops"]}"
created2024-09-16 17:37:15
last_update2024-09-17 07:35:12
depth0
children18
last_payout2024-09-23 17:37:15
cashout_time1969-12-31 23:59:59
total_payout_value16.332 HBD
curator_payout_value16.294 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,792
author_reputation216,289,007,274,068
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,127,281
net_rshares110,343,786,026,980
author_curate_reward""
vote details (367)
@ana-maria · (edited)
Thank you for remembering and mentioning me. 
I probably wouldn't have time to jump into it right away, so I'm bookmarking this post to know where to start. 😉 
!ALIVE 
!LUV 
!PIZZA 
properties (22)
authorana-maria
permlinkre-felixxx-2024922t222624829z
categorydev
json_metadata{"tags":[],"app":"ecency/4.0.1-vision","format":"markdown+html"}
created2024-09-22 20:26:27
last_update2024-09-22 20:27:00
depth1
children1
last_payout2024-09-29 20:26:27
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_length181
author_reputation37,563,041,368,531
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,323,326
net_rshares0
@luvshares ·
@felixxx, @ana-maria<sub>(1/1)</sub> sent you LUV. | <a
    href="https://crrdlx.on.fleek.co/" style="text-decoration:none">tools</a> | <a 
    href="https://discord.gg/K5GvNhcPqR" style="text-decoration:none">discord</a> | <a href="https://peakd.com/c/hive-159259">community </a> | <a 
    href="https://hivewiki.netlify.app" style="text-decoration:none">HiveWiki</a> | <a href="https://ichthys.netlify.app" style="text-decoration:none"><>< daily</a>



<center>Made with <a href="https://peakd.com/@luvshares" target="_blank">LUV</a> by <a href="https://hive.blog/@crrdlx" target="_blank">crrdlx</a></center>
properties (22)
authorluvshares
permlinkre-re-felixxx-2024922t222624829z-20240922t202706z
categorydev
json_metadata"{"app": "beem/0.24.26"}"
created2024-09-22 20:27:06
last_update2024-09-22 20:27:06
depth2
children0
last_payout2024-09-29 20:27:06
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_length610
author_reputation5,651,102,754,153
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,323,334
net_rshares0
@arc7icwolf ·
Avid reader here! Always ready to learn new coding stuff :)
properties (22)
authorarc7icwolf
permlinkre-felixxx-sjx3ic
categorydev
json_metadata{"tags":["dev"],"app":"peakd/2024.8.7"}
created2024-09-16 18:03:51
last_update2024-09-16 18:03:51
depth1
children1
last_payout2024-09-23 18:03: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_length59
author_reputation504,097,326,062,538
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,127,704
net_rshares0
@felixxx ·
Next post I'll demonstrate a cool example.
This time, I had to provide some fundamentals...
properties (22)
authorfelixxx
permlinkre-arc7icwolf-sjx404
categorydev
json_metadata{"tags":["dev"],"app":"peakd/2024.8.7"}
created2024-09-16 18:14:33
last_update2024-09-16 18:14:33
depth2
children0
last_payout2024-09-23 18:14:33
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_length91
author_reputation216,289,007,274,068
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,127,861
net_rshares0
@chrislybear ·
Thank you for mentioning and remembering me about that topic! <3 
properties (22)
authorchrislybear
permlinkre-felixxx-sk6ja1
categorydev
json_metadata{"tags":["dev"],"app":"peakd/2024.8.7"}
created2024-09-21 20:22:48
last_update2024-09-21 20:22:48
depth1
children0
last_payout2024-09-28 20:22:48
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_length65
author_reputation84,678,912,905,760
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,292,867
net_rshares0
@manclar · (edited)
It seems to me that you have given a very good explanation of how the blockchain works. I didn't know that events were segmented every 3 seconds. Is there an explanation as to why that time was chosen and not another?


> While the blockchain contains all transfers to and from an account, the final balance needs to be calculated;
The data needs to be compiled first, for quick access.

I find this very interesting, and I would like to read an explanation of how this process is calculated or done.

Thanks for the mention and I see that the images in your post look good.

Interesting work, I will be waiting to read your hacky guide, and I know that new witnesses like @daddydog will be interested in taking a look.

pd: get well soon from your injury on your hand.
properties (22)
authormanclar
permlinkre-felixxx-sjx2zb
categorydev
json_metadata{"tags":"dev"}
created2024-09-16 17:52:24
last_update2024-09-16 17:53:54
depth1
children8
last_payout2024-09-23 17:52:24
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_length769
author_reputation327,129,089,386,387
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,127,545
net_rshares0
@felixxx ·
>It seems to me that you have given a very good explanation of how the blockchain works. I didn't know that events were segmented every 3 seconds. Is there an explanation as to why that time was chosen and not another?

Hive has a block time of 3 seconds.
Within those 3 seconds all sorts of things must happen; validation of transactions, serialzation, consensus finding and final signing of the block. That takes some time and communication around the globe and stuff.
As I understand it, 3 seconds is a limit, because of the speed which data travels with.

>I find this very interesting, and I would like to read an explanation of how this process is calculated or done.

Uhm...
For your account's balance, you just have to go though all blocks and summarize all transfers to and from your account (and all posting rewards and orders on the market and other stuff). In the end, the calculation is a (simple) addition (and subtraction), the result is a sum.
With every further transfer, the sum changes.
properties (22)
authorfelixxx
permlinkre-manclar-sjx3fj
categorydev
json_metadata{"tags":["dev"],"app":"peakd/2024.8.7"}
created2024-09-16 18:02:12
last_update2024-09-16 18:02:12
depth2
children7
last_payout2024-09-23 18:02:12
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_length1,005
author_reputation216,289,007,274,068
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,127,679
net_rshares0
@manclar ·
> For your account's balance, you just have to go though all blocks and summarize all transfers to and from your account (and all posting rewards and orders on the market and other stuff). In the end, the calculation is a (simple) addition (and subtraction), the result is a sum.
With every further transfer, the sum changes.

So this implies that the larger the user or blockchain data = the longer the response time will be, or does that not affect the process? 😒
properties (22)
authormanclar
permlinkre-felixxx-sjx3m0
categorydev
json_metadata{"tags":["dev"],"app":"peakd/2024.8.7"}
created2024-09-16 18:06:03
last_update2024-09-16 18:06:03
depth3
children6
last_payout2024-09-23 18:06:03
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_length465
author_reputation327,129,089,386,387
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,127,734
net_rshares0
@ph1102 ·
Oooh, a newbie tutorial! That's great to see!
We need more of these things where things are explained with language understandable for "normies" 😃

Thanks for doing this!

---
*I have picked this post on behalf of the @OurPick project! Check out our Reading Suggestions Posts!* 

[![Comment Footer.jpg](https://files.peakd.com/file/peakd-hive/ph1102/23vi6UCc5Wi27NhPSnLFHgzwUZ8NNdWdCkZe1b3VLFZxswQDucw7QiLa4zw64n4woS3BJ.jpg)](https://liotes.com/)
**Please consider voting for our [Liotes HIVE Witness](https://vote.hive.uno/@liotes). Thank you!**
properties (22)
authorph1102
permlinkre-felixxx-sjyc74
categorydev
json_metadata{"tags":["dev"],"app":"peakd/2024.8.7"}
created2024-09-17 10:09:03
last_update2024-09-17 10:09:03
depth1
children0
last_payout2024-09-24 10:09:03
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_length546
author_reputation970,643,452,892,428
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,159,431
net_rshares0
@pizzabot ·
<center>PIZZA!


$PIZZA slices delivered:
@ana-maria<sub>(2/5)</sub> tipped @felixxx 


</center>
properties (22)
authorpizzabot
permlinkre-a-hacky-guide-to-hive-part-15-20240922t202721z
categorydev
json_metadata"{"app": "pizzabot"}"
created2024-09-22 20:27:21
last_update2024-09-22 20:27:21
depth1
children0
last_payout2024-09-29 20:27:21
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_length97
author_reputation7,555,460,989,499
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,323,336
net_rshares0
@slobberchops ·
Sorry I have not got back to you, work has ramped up massively and I am involved in a large project now. My Python coding hat may well stay off for a while, at work it's all Powershell.
👍  
properties (23)
authorslobberchops
permlinkre-felixxx-sjy76m
categorydev
json_metadata{"tags":["dev"],"app":"peakd/2024.8.7"}
created2024-09-17 08:20:45
last_update2024-09-17 08:20:45
depth1
children1
last_payout2024-09-24 08:20:45
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_length185
author_reputation2,436,340,033,299,072
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,158,305
net_rshares640,335,118
author_curate_reward""
vote details (1)
@felixxx ·
Thanks for letting me know.
Best of luck with your project!
properties (22)
authorfelixxx
permlinkre-slobberchops-sjy8gm
categorydev
json_metadata{"tags":["dev"],"app":"peakd/2024.8.7"}
created2024-09-17 08:48:24
last_update2024-09-17 08:48:24
depth2
children0
last_payout2024-09-24 08:48:24
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_length59
author_reputation216,289,007,274,068
root_title"A Hacky Guide to Hive (part 1.5)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id137,158,623
net_rshares0