## Context In these posts I try looking at Hive as a black box. I keep poking at it, to get some better insight on how it works. ### Hive Ops Heard on the street: Hive has ops. Virtual ops on the block. I investigate. π https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/felixxx/23uEwkJXVQZBWGMuTPbMF8HMbrgmFb8HsRrt8uPYCJVS2xKpwunsw1C7yQ14WRrjmSxa9.png ## block_api I've [demonstrated](/@felixxx/a-hacky-guide-to-hive-part-223-blocks-engine) how it should be possible to build a whole game engine around [block_ap.get_block_range](https://developers.hive.io/apidefinitions/#block_api.get_block_range), by just looking at all operations in a live stream. - api.py: ``` import requests def get_block_range(start, count, url): data = '{"jsonrpc":"2.0", "method":"block_api.get_block_range","params":{"starting_block_num":'+str(start)+',"count": '+str(count)+'},"id":1}' return requests.post(url, data) ``` Same 'api' as before. Returns the response raw. - get_ops: ``` def get_ops_with_block_range(start, count, url): response = api.get_block_range(start, count, url) blocks = response.json()['result']['blocks'] ops = [] for block in blocks: for transaction in block['transactions']: for operation in transaction['operations']: ops.append(operation) return ops ``` Operations are in transactions, transactions are in blocks. I need to iterate through that nest to collect all ops. ## condenser [condenser_api.get_ops_in_block](https://developers.hive.io/apidefinitions/#condenser_api.get_ops_in_block) can also return ops. - api: ``` def condenser_get_ops_in_block(block, url, only_virtual): data = '{"jsonrpc":"2.0", "method":"condenser_api.get_ops_in_block", "params":['+str(block)+','+only_virtual+'], "id":1}' return requests.post(url, data) ``` - get_ops: ``` def get_ops_with_condenser(num, url, only_virtual= 'false'): response = api.condenser_get_ops_in_block(num, url, only_virtual) ops = response.json()['result'] return ops ``` That should return the same ops as with block_api get_ops... ### Test ``` import time url = 'https://api.hive.blog' print(len(get_ops_with_block_range(89040499, 1, url))) time.sleep(2) print(len(get_ops_with_condenser(89040499, url))) ``` returns: ``` 91 143 ``` ## Virtual Operations There is a difference of **52**. [You can read more on virtual operations in the documentation](https://developers.hive.io/tutorials-recipes/virtual-operations-when-streaming-blockchain-transactions.html). btw: the examples there don't really work π, but: >Virtual operations (curation rewards, etc) are derived from blockchain activity, but arenβt actually stored as operations themselves. They happen based on consensus from the blockchain based on other user initiated operations. These virtual operations are NOT available on the head block, so a 100% live feed of this information would not be possible. In order then to follow these operations you would have to stream the last_irreversible_block. To get a feed of virtual operations, each of the block transactions needs to be investigated for the type of the operations. I would explain it more like this: >'Normal' operations are user operations. They are explicit. They need to be signed and broadcast by a user: Alice makes a post. Virtual operations are implicit: _When_ Alice makes a post, determines _when_ the post payout will be. Post and curation rewards must happen exactly 7 day later and are accounted for as virtual operations. But this is just a coding adventure, not a guide... #### Test ``` print(len(get_ops_with_condenser(89040499, url, only_virtual = 'true'))) >> 52 ``` ### account_history In more practical terms, the best endpoint I could find to get to virtual operations: [account_history_api.enum_virtual_ops](https://developers.hive.io/apidefinitions/#account_history_api.enum_virtual_ops) I **think** account_history plugin (not api) _must_ be activated on all nodes by default... Information behind all of this is scarce... - api.py: ``` def account_history_enum_virtual_ops(start, stop, url): data = '{"jsonrpc":"2.0", "method":"account_history_api.enum_virtual_ops", "params":{"block_range_begin":'+str(start)+',"block_range_end":'+str(stop)+'}, "id":1}' return requests.post(url, data) ``` - get_ops: ``` def get_ops_with_enum(start, stop, url): response = api.account_history_enum_virtual_ops(start, stop, url) return response.json()['result']['ops'] ``` Once again, the documentation is wrong. The ['ops'] is important, as the response actually looks like this: ``` next_block_range_begin next_operation_begin ops ops_by_block ``` 'next' is used with 'limit' for pagination. Anyways, after navigating to 'ops': ``` print(len(get_ops_with_enum(89040499, 89040500, url))) >> 52 ``` ## Reversibility If you actually visited the links from above, you probably noticed _reversibility_ being mentioned. In the documentation there are parts about _head block_ and such. Blocks used to be reversible for 1 minute. That was an issue. The HAF has a huge module 'fork manager' to deal with reversibility. But the Hive protocol got updated and blocks are kind of insta-irreversible now. ...for this post I am just hacking away at operations. I don't understand it well enough to try explaining things, but I'll investigate further... ## Conclusion There's more to it, than just looking at blocks. Virtual operations are not accessible by block_api. In terms of automating something: If all you ever need is user operations, [streaming](/@felixxx/a-hacky-guide-to-hive-part-222-customyoson) block_api could be reliable enough. Virtual ops are mostly dealing with delayed things like posting rewards - depending on what you want to build, it could matter...
author | felixxx |
---|---|
permlink | hive-as-a-black-box-operations |
category | dev |
json_metadata | "{"app":"peakd/2024.8.7","format":"markdown","description":"Dealing with ops","tags":["dev","hive-dev","hivedev","hive","python"],"users":["felixxx"],"image":["https://files.peakd.com/file/peakd-hive/felixxx/23uEwkJXVQZBWGMuTPbMF8HMbrgmFb8HsRrt8uPYCJVS2xKpwunsw1C7yQ14WRrjmSxa9.png"]}" |
created | 2024-09-25 06:13:18 |
last_update | 2024-09-25 06:13:18 |
depth | 0 |
children | 5 |
last_payout | 2024-10-02 06:13:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 10.624 HBD |
curator_payout_value | 10.606 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,838 |
author_reputation | 217,880,960,937,226 |
root_title | "Hive As A Black Box - Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 137,377,478 |
net_rshares | 70,744,380,780,604 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
leprechaun | 0 | 6,035,594,562 | 32.5% | ||
juanmiguelsalas | 0 | 7,458,084,611 | 10% | ||
kenny-crane | 0 | 795,244,883,711 | 50% | ||
good-karma | 0 | 12,114,929,111 | 1% | ||
jeffjagoe | 0 | 643,200,280,276 | 100% | ||
ace108 | 0 | 1,184,698,081,017 | 25% | ||
shaka | 0 | 7,407,180,070,654 | 100% | ||
avellana | 0 | 21,223,748,600 | 20% | ||
miketr | 0 | 197,222,028,540 | 60% | ||
someguy123 | 0 | 209,132,461,396 | 50% | ||
pollux.one | 0 | 694,611,703,815 | 80% | ||
uwelang | 0 | 1,105,694,184,689 | 50% | ||
phusionphil | 0 | 14,768,218,576 | 95% | ||
esteemapp | 0 | 2,678,806,003 | 1% | ||
alexvan | 0 | 96,852,972,976 | 100% | ||
privex | 0 | 64,533,263,711 | 100% | ||
danielsaori | 0 | 551,310,570,912 | 100% | ||
freebornsociety | 0 | 5,553,798,251 | 10% | ||
kilianmiguel | 0 | 2,165,649,507 | 10% | ||
tonyz | 0 | 640,463,537,077 | 64% | ||
leontr | 0 | 2,534,021,964 | 40% | ||
stayoutoftherz | 0 | 2,925,532,729,464 | 25% | ||
sanjeevm | 0 | 1,990,096,480,352 | 40% | ||
etblink | 0 | 323,138,976,966 | 50% | ||
musicgeek | 0 | 944,307,635 | 50% | ||
marketinggeek | 0 | 726,102,320 | 100% | ||
sportschain | 0 | 940,101,110 | 50% | ||
deathwing | 0 | 2,059,057,308,668 | 50% | ||
esteem.app | 0 | 316,103,361 | 1% | ||
der-prophet | 0 | 40,612,260,756 | 16.5% | ||
dkid14 | 0 | 344,857,225,612 | 100% | ||
emrebeyler | 0 | 3,581,968,602,971 | 35% | ||
maxinpower | 0 | 209,574,201,769 | 100% | ||
docmarenkristina | 0 | 790,897,589 | 50% | ||
mytechtrail | 0 | 17,201,551,952 | 15% | ||
fourfourfun | 0 | 4,266,175,156 | 12.5% | ||
abeba | 0 | 830,694,304 | 12.5% | ||
piotrgrafik | 0 | 1,043,307,175,074 | 80% | ||
investyourvote | 0 | 40,746,011,132 | 60% | ||
franciscomarval | 0 | 4,650,698,928 | 25% | ||
iddaa | 0 | 1,242,247,170 | 25% | ||
sudefteri | 0 | 35,190,570,936 | 50% | ||
movement19 | 0 | 1,745,607,982 | 6.25% | ||
akifane | 0 | 1,400,865,898 | 50% | ||
jagoe | 0 | 83,983,882,928 | 100% | ||
satren | 0 | 43,398,389,788 | 30% | ||
rivalzzz | 0 | 117,041,534,922 | 100% | ||
hlezama | 0 | 26,897,186,122 | 100% | ||
gadrian | 0 | 736,267,035,510 | 50% | ||
memepress | 0 | 1,624,544,154 | 47.5% | ||
solominer | 0 | 2,498,454,068,283 | 25% | ||
fw206 | 0 | 3,370,105,313,996 | 40% | ||
apshamilton | 0 | 1,002,496,115,748 | 50% | ||
radiosteemit | 0 | 4,288,962,099 | 25% | ||
hamismsf | 0 | 339,288,895,450 | 50% | ||
teamvn | 0 | 16,008,541,413 | 14.23% | ||
dalz | 0 | 1,752,055,431,729 | 100% | ||
smartvote | 0 | 158,069,340,279 | 6.2% | ||
yaelg | 0 | 33,830,481,505 | 45% | ||
altonos | 0 | 3,360,600,807 | 100% | ||
ynwa.andree | 0 | 241,287,849,562 | 100% | ||
lagitana | 0 | 1,051,652,318 | 20% | ||
berthold | 0 | 10,374,728,369 | 40% | ||
janettyanez | 0 | 1,267,834,471 | 25% | ||
brianoflondon | 0 | 8,038,125,847,763 | 100% | ||
captain.future | 0 | 4,885,087,506 | 100% | ||
kizumo | 0 | 197,859,666,031 | 100% | ||
kiel91 | 0 | 487,740,938,425 | 100% | ||
jpbliberty | 0 | 625,887,072,815 | 100% | ||
bluerobo | 0 | 531,486,561,165 | 100% | ||
leosoph | 0 | 193,222,935,958 | 100% | ||
blue.rabbit | 0 | 213,204,102,532 | 100% | ||
steemvpn | 0 | 37,051,908,004 | 95% | ||
ph1102 | 0 | 2,020,515,833,174 | 70% | ||
kittykate | 0 | 99,567,427,916 | 100% | ||
imbartley | 0 | 796,396,541 | 25% | ||
investinthefutur | 0 | 88,736,909,839 | 60% | ||
whangster79 | 0 | 3,843,764,156 | 25% | ||
stem.alfa | 0 | 1,794,679,919 | 50% | ||
dpoll.witness | 0 | 951,992,029 | 35% | ||
blocktvnews | 0 | 902,061,808 | 50% | ||
an-sich-wachsen | 0 | 4,206,939,847 | 33% | ||
lotto-de | 0 | 89,595,585,761 | 60% | ||
rcaine | 0 | 8,763,268,283 | 7% | ||
pavelsku | 0 | 15,476,995,620 | 12.5% | ||
iceledy | 0 | 842,274,904 | 100% | ||
danielhuhservice | 0 | 96,247,058,840 | 33% | ||
zelegations | 0 | 13,796,827,896 | 95% | ||
radiohive | 0 | 6,387,482,622 | 25% | ||
blue-witness | 0 | 938,092,683 | 100% | ||
tht | 0 | 36,182,314,626 | 100% | ||
timhorton | 0 | 13,382,268,233 | 95% | ||
cerberus-dji | 0 | 3,085,754,169 | 95% | ||
tht1 | 0 | 11,308,246,173 | 100% | ||
ecency | 0 | 433,614,520,183 | 1% | ||
kvfm | 0 | 524,786,633 | 12.5% | ||
hivecannabis | 0 | 11,555,946,042 | 95% | ||
laradio | 0 | 1,102,336,261 | 25% | ||
ecency.stats | 0 | 355,299,970 | 1% | ||
recoveryinc | 0 | 8,218,771,295 | 12.5% | ||
hive-108278 | 0 | 886,710,289 | 50% | ||
dying | 0 | 917,057,302 | 25% | ||
hive-vpn | 0 | 2,776,242,184 | 95% | ||
cleydimar2000 | 0 | 2,462,683,710 | 12.5% | ||
radiolovers | 0 | 5,154,768,690 | 25% | ||
trcommunity | 0 | 0 | 50% | ||
alberto0607 | 0 | 10,189,771,795 | 25% | ||
bea23 | 0 | 5,429,094,086 | 25% | ||
ciudadcreativa | 0 | 933,981,985 | 20% | ||
hykss.leo | 0 | 103,377,475,839 | 10% | ||
samrisso | 0 | 8,846,765,775 | 12.5% | ||
trostparadox | 0 | 3,031,851,605,106 | 100% | ||
coinomite | 0 | 555,173,164 | 100% | ||
ausbit.dev | 0 | 11,470,297,476 | 50% | ||
tomtothetom | 0 | 3,502,653,137 | 25% | ||
princeofbeyhive | 0 | 1,426,163,398 | 50% | ||
mein-senf-dazu | 0 | 355,972,026,383 | 100% | ||
madsbert | 0 | 859,769,335 | 99% | ||
hjrrodriguez | 0 | 59,359,085,114 | 100% | ||
holovision.stem | 0 | 563,479,116 | 50% | ||
lxsxl | 0 | 30,259,343,282 | 50% | ||
hivehydra | 0 | 886,643,032 | 90% | ||
podping | 0 | 703,055,400,219 | 100% | ||
meesterbrain | 0 | 586,096,513 | 32.5% | ||
t-nil | 0 | 1,875,822,695 | 30% | ||
dungeondog | 0 | 69,490,175,479 | 100% | ||
cryptoccshow | 0 | 6,613,988,179 | 50% | ||
bilgin70 | 0 | 23,494,313,141 | 25% | ||
ronymaffi | 0 | 3,026,354,923 | 25% | ||
acantoni | 0 | 3,236,263,046 | 12.5% | ||
snaqz | 0 | 2,485,119,112 | 100% | ||
eolianpariah2 | 0 | 1,801,555,192 | 0.5% | ||
arc7icwolf | 0 | 185,022,628,049 | 100% | ||
relf87 | 0 | 73,368,940,325 | 100% | ||
susurrodmisterio | 0 | 902,713,930 | 12.5% | ||
adventkalender | 0 | 2,397,982,070 | 50% | ||
kvinna | 0 | 1,553,330,524,764 | 99% | ||
heteroclite | 0 | 15,354,954,902 | 25% | ||
passenger777 | 0 | 47,846,377,168 | 25% | ||
patchwork | 0 | 2,891,835,809 | 50% | ||
palomap3 | 0 | 168,805,530,267 | 50% | ||
ridwanms | 0 | 9,792,786,393 | 100% | ||
duja | 0 | 22,838,781,014 | 100% | ||
dusunenkalpp | 0 | 25,782,972,996 | 50% | ||
ipexito | 0 | 899,722,525 | 40% | ||
visionarystudios | 0 | 7,567,602,180 | 100% | ||
visualblock | 0 | 67,691,901,171 | 25% | ||
mukadder | 0 | 70,829,603,491 | 35% | ||
juansitosaiyayin | 0 | 1,731,584,514 | 100% | ||
incublus | 0 | 467,893,325,867 | 50% | ||
ezgicop | 0 | 7,425,185,986 | 50% | ||
slicense | 0 | 1,944,839,771 | 60% | ||
megstarbies | 0 | 1,651,110,819 | 100% | ||
awildovasquez | 0 | 36,204,830,368 | 100% | ||
duskobgd | 0 | 84,114,851,103 | 100% | ||
hive-195880 | 0 | 1,095,891,634 | 25% | ||
naters | 0 | 487,814,773 | 100% | ||
hive-coding | 0 | 1,280,013,795 | 100% | ||
chinay04 | 0 | 52,145,185,295 | 100% | ||
hivegadgets | 0 | 2,143,995,519 | 50% | ||
e-sport-gamer | 0 | 2,366,122,147 | 33% | ||
hive-learn.more | 0 | 730,602,396 | 100% | ||
hpud.wettbewerb | 0 | 3,435,213,667 | 100% | ||
e-sport-girly | 0 | 1,857,872,793 | 33% | ||
hivetycoon | 0 | 1,668,409,219 | 100% | ||
foodiefrens | 0 | 462,080,431 | 100% | ||
empo.voter | 0 | 12,810,217,670,583 | 50% | ||
bellscoin | 0 | 1,534,211,161 | 100% | ||
learn2code | 0 | 879,724,477 | 50% | ||
hive-188753 | 0 | 1,274,435,171 | 50% | ||
hive-world-champ | 0 | 33,899,340,859 | 100% | ||
bostonadventures | 0 | 482,141,600,366 | 100% |
I was asking myself what those virtual ops were since I first encountered them... thanks for explaining it! I may have to update the scripts I was working on, because at the time I wasn't aware of this difference between the two APIs - *and I can't remember what API I used!*
author | arc7icwolf |
---|---|
permlink | re-felixxx-skcz7k |
category | dev |
json_metadata | {"tags":["dev"],"app":"peakd/2024.8.7"} |
created | 2024-09-25 07:52:33 |
last_update | 2024-09-25 07:52:33 |
depth | 1 |
children | 4 |
last_payout | 2024-10-02 07:52:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 276 |
author_reputation | 508,055,356,159,370 |
root_title | "Hive As A Black Box - Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 137,378,648 |
net_rshares | 0 |
btw: where are you running the scripts, if I may ask? At home or do you rent server space? Should I write something about server rental on privex?
author | felixxx |
---|---|
permlink | re-arc7icwolf-skd38m |
category | dev |
json_metadata | {"tags":["dev"],"app":"peakd/2024.8.7"} |
created | 2024-09-25 09:19:36 |
last_update | 2024-09-25 09:19:36 |
depth | 2 |
children | 3 |
last_payout | 2024-10-02 09:19:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 146 |
author_reputation | 217,880,960,937,226 |
root_title | "Hive As A Black Box - Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 137,379,695 |
net_rshares | 0 |
Right now I'm only running them locally on my pc when I test them π If I will ever become decent at coding I may consider to buy something small and cheap to create my own personal server, but I'd be happy to know something more about server rental :)
author | arc7icwolf |
---|---|
permlink | re-felixxx-skd3ty |
category | dev |
json_metadata | {"tags":["dev"],"app":"peakd/2024.8.7"} |
created | 2024-09-25 09:32:24 |
last_update | 2024-09-25 09:32:24 |
depth | 3 |
children | 2 |
last_payout | 2024-10-02 09:32:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 252 |
author_reputation | 508,055,356,159,370 |
root_title | "Hive As A Black Box - Operations" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 137,379,842 |
net_rshares | 0 |