create account

Notes Hive Public API node performance by bobinson

View this thread on: hive.blogpeakd.comecency.com
· @bobinson · (edited)
$266.22
Notes Hive Public API node performance
### Abstract



![image.png](https://images.hive.blog/DQmeKZYGw9p8xueqtRbhw2X2uPY7ro9jJX3hPbzVVr9Bj23/image.png)

----

As part of the Hive - Peerplays Sidechain implementation, we are now attempting to connect the sidechain listener to the Hive Public API endpoints. Previously we have been using fullfledged Hive TESTNET and Peerplays TESNET and the cross chain transfer from Hive TESTNET to Peerplays TESTNET was possible in around ~10 seconds. We have been expecting the same implementation to complete cross chain transfer of HIVE/HBD in less than 30 seconds. We have been streaming the Hive blockchain and looking for transactions in `account_history_api.get_transaction` every second. But with the Hive mainnet, the API nodes adds latency which results the cross chain swaps to slow down to around 80-100 seconds. 

Next steps are to attempt to listen for only the LIB (ie the irreversible blocks) every 3 seconds instead of looking for transactions every second. Further optimizations in the required RPC calls can also provide better performance.  (Results will be announced).

In general it looks like solutions like HAF, ie moving the account history to proven and battle tested general purposed databases like PostgreSQL can provide much needed response times for financial applications.


### Current Challenges



 - `block_api.get_block` call is slow (details to follow)

- `account_history_api.get_transaction` Often fails on the Hive Mainnet's public full nodes

- some of the nodes seems to have compiled with `SKIP_BY_TX_ID=ON` & thus fails to return full data.



### Hive - Peerplays Sidechain listener logic



The following logic is used for listening the transactions in the Hive blockchain in real time. Upon meeting the criteria, deposit or withdraw of HIVE/HBD assets are invoked and under goes consensus process by the Sidechain Operator Nodes. Note that the implementation is in C++ and for now we are using a slower curl based implementation that supports HTTPS as part of the Peerplays chain's Hive listener. Initially we have been using HTTP and thus that also might be adding a small amount of delay.

- call, once, `database_api.get_version` to get `chain_id `
- call, once, `condenser_api.get_config` to verify are we running on testnet or mainnet 
- loop start
- call, each second, `database_api.get_dynamic_global_properties` to monitor for new blocks (ie, we are looking into `head_block_number field`) 
- if** new block is available (ie, head_block_number is increased), we call `block_api.get_block`, to get the block 
- we are iterrating through block transactions, in order to find any transaction with `transfer_operation` of interest
- we call `account_history_api.get_transaction`, for each transaction id in a block (these calls fail on mainnet)

```
840114ms th_a       rpc_client.cpp:171            send_post_request    ] ### Request URL:    https://api.hive.blog:443      840114ms th_a       rpc_client.cpp:172            send_post_request    ] ### Request:        { "jsonrpc": "2.0", "id": 5, "method": "account_history_api.get_transaction", "params": { "id": "bbea1d35998433e534e8b57f0945c32d1bbd3bd0", "include_reversible": "true" } }      840114ms th_a       rpc_client.cpp:174            send_post_request    ] ### Response:       {"jsonrpc":"2.0","error":{"code":-32003,"message":"Assert Exception:false: Unknown Transaction bbea1d35998433e534e8b57f0945c32d1bbd3bd0","data":{"code":10,"name":"assert_exception","message":"Assert Exception","stack":[{"context":{"level":"error","file":"account_history_api.cpp","line":250,"method":"get_transaction","hostname":"","timestamp":"2021-10-12T13:14:00"},"format":"false: Unknown Transaction ${t}","data":{"t":"bbea1d35998433e534e8b57f0945c32d1bbd3bd0"}}]}},"id":5}
```

- we parse the transaction, looking for transfer_operation with son-account as a receiver 
- if we find it, we create appropriate deposit object 
- SONs are calling account_history_api_get_transaction, again during deposit object verification, to confirm that the deposit transaction exists, and that data in the transaction matches data in the deposit object (sender, receiver, asset symbol, amount) 
- for withdrawals we use network_broadcast_api.broadcast_transaction to bradcast payout transaction, and we monitor if the transaction reached irreeversible block, by calling database_api.get_dynamic_global_properties and looking into field last_irreversible_block_num. If transaction reached irreversible block, withdrawal is confirmed.



### Issue logs



- **account_history_api.get_transaction**

```
840114ms th_a       rpc_client.cpp:171            send_post_request    ] ### Request URL:    https://api.hive.blog:443      840114ms th_a       rpc_client.cpp:172            send_post_request    ] ### Request:        { "jsonrpc": "2.0", "id": 5, "method": "account_history_api.get_transaction", "params": { "id": "bbea1d35998433e534e8b57f0945c32d1bbd3bd0", "include_reversible": "true" } }      840114ms th_a       rpc_client.cpp:174            send_post_request    ] ### Response:       {"jsonrpc":"2.0","error":{"code":-32003,"message":"Assert Exception:false: Unknown Transaction bbea1d35998433e534e8b57f0945c32d1bbd3bd0","data":{"code":10,"name":"assert_exception","message":"Assert Exception","stack":[{"context":{"level":"error","file":"account_history_api.cpp","line":250,"method":"get_transaction","hostname":"","timestamp":"2021-10-12T13:14:00"},"format":"false: Unknown Transaction ${t}","data":{"t":"bbea1d35998433e534e8b57f0945c32d1bbd3bd0"}}]}},"id":5}
```

- **Nodes with SKIP_BY_TX_ID=ON**

  `curl -s --data '{"jsonrpc":"2.0","id":5,"method":"account_history_api.get_transaction","params":{"id":"bbea1d35998433e534e8b57f0945c32d1bbd3bd0","include_reversible":"true"}}' https://hive-api.3speak.tv/`

  **Response:**

  

  ```{"jsonrpc":"2.0","error":{"code":-32003,"message":"Assert Exception:false: This node's operator has disabled operation indexing by transaction_id","data":{"code":10,"name":"assert_exception","message":"Assert Exception","stack":[{"context":{"level":"error","file":"account_history_api.cpp","line":226,"method":"get_transaction","hostname":"","timestamp":"2021-10-13T12:05:21"},"format":"false: This node's operator has disabled operation indexing by transaction_id","data":{}}]}},"id":5}```

  

# Transaction times

---

| header | header |
| ------ | ------ |
| https://api.hive.blog | ~960ms |
| https://anyx.io | ~950ms avg |
| https://api.openhive.network | ~450ms |
| http://api.deathwing.me | 200ms avg |



Note that these tests are obviosly not done using multiple locations.

The commands used to test are here https://gitlab.com/PBSA/peerplays/-/issues/191#note_713042607
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 219 others
👎  ,
properties (23)
authorbobinson
permlinknotes-hive-public-api-node-performance
categoryhive-167922
json_metadata{"tags":["hive","api","haf","fullnodes","sidechain","peerplays"],"image":["https://images.hive.blog/DQmeKZYGw9p8xueqtRbhw2X2uPY7ro9jJX3hPbzVVr9Bj23/image.png"],"links":["https://api.hive.blog"],"app":"hiveblog/0.1","format":"markdown"}
created2021-10-26 11:36:51
last_update2021-10-26 13:07:15
depth0
children12
last_payout2021-11-02 11:36:51
cashout_time1969-12-31 23:59:59
total_payout_value133.158 HBD
curator_payout_value133.059 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,699
author_reputation55,343,141,313,811
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,301,790
net_rshares234,032,117,127,453
author_curate_reward""
vote details (285)
@bammbuss ·
You are working for the good of the platform. Thank you!
properties (22)
authorbammbuss
permlinkr1lgxx
categoryhive-167922
json_metadata{"app":"hiveblog/0.1"}
created2021-10-26 17:10:24
last_update2021-10-26 17:10:24
depth1
children0
last_payout2021-11-02 17:10: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_length56
author_reputation21,915,846,838,025
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,307,479
net_rshares0
@devosdevosi ·
![gif_good_job_85.gif](https://images.ecency.com/DQmWvKMhjiRBLMPCWoiHuyevQy8Li6UEDvbBGE3ec51hgCJ/gif_good_job_85.gif)

properties (22)
authordevosdevosi
permlinkre-bobinson-20211026t204025972z
categoryhive-167922
json_metadata{"tags":["hive","api","haf","fullnodes","sidechain","peerplays"],"app":"ecency/3.0.19-vision","format":"markdown+html"}
created2021-10-26 19:40:24
last_update2021-10-26 19:40:24
depth1
children0
last_payout2021-11-02 19:40: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_length119
author_reputation106,059,603,583,920
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,309,929
net_rshares0
@gargi ·
feeling good that some Indian  working to development of this platform..... really appreciating your work... keep it up 👍
properties (22)
authorgargi
permlinkr1lic1
categoryhive-167922
json_metadata{"app":"hiveblog/0.1"}
created2021-10-26 17:38:24
last_update2021-10-26 17:38:24
depth1
children0
last_payout2021-11-02 17:38: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_length121
author_reputation224,485,798,690,995
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,307,969
net_rshares0
@gtg ·
$7.82
Bunch of notes from me:
- Some API nodes (like mine) might have rate limiting enabled
- There's no point in using  `SKIP_BY_TX_ID=ON` these days 
- There's no need using such frequent `get_dynamic_properties` calls, blocks won't come faster than once per 3 seconds
- You can use `transaction_status_api` to track status of transactions, it should be way cheaper in matter of computer resources
- You could use local instance of a simple consensus node with `transaction_status_api` where you could run frequent calls against, while still using public node with account history for other calls.
👍  , , , , ,
properties (23)
authorgtg
permlinkr1mjre
categoryhive-167922
json_metadata{"app":"hiveblog/0.1"}
created2021-10-27 07:06:51
last_update2021-10-27 07:06:51
depth1
children1
last_payout2021-11-03 07:06:51
cashout_time1969-12-31 23:59:59
total_payout_value3.913 HBD
curator_payout_value3.912 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length593
author_reputation461,807,638,012,710
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,320,082
net_rshares6,877,286,380,650
author_curate_reward""
vote details (6)
@bobinson ·
Thanks @gtg for your points.


> Some API nodes (like mine) might have rate limiting enabled

That explains why there is a variation in the response times. 

> There's no point in using SKIP_BY_TX_ID=ON these days

Yes - We may need to create a post and inform everyone that the RocksDB based plugin works just fine irrespective either options.

I got confused by this one big time. At first ended up concluding the disparity from the TESTNET and the mainnet is this option. Only handful of nodes have this option using at this point.


The last 3 points ---> Yes, we are trying to use different calls and optimizing the workflow and it looks like the performance of the listener is much better now.

As for the local node, these nodes already runs a graphene based chain and we are trying to reduce the over all expense to run the sidechain nodes. This is one of the reasons to go with the public nodes.


Further it looks like HAF may make things even better and we can ignore the account history altogether.
👎  
properties (23)
authorbobinson
permlinkr1mphx
categoryhive-167922
json_metadata{"users":["gtg"],"app":"hiveblog/0.1"}
created2021-10-27 09:10:48
last_update2021-10-27 09:10:48
depth2
children0
last_payout2021-11-03 09:10: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_length1,010
author_reputation55,343,141,313,811
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,321,594
net_rshares-124,126,062
author_curate_reward""
vote details (1)
@indiaunited ·
Indiaunited Curation 1635267734843
This post has been manually curated by @bhattg from Indiaunited community. Join us on our [Discord Server](https://discord.gg/bGmS2tE). 

Do you know that you can earn a passive income by delegating to @indiaunited. We share 80 % of the curation rewards with the delegators. 

Here are some handy links for delegations: [100HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=185937.46335597092%20VESTS), [250HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=464843.6583899273%20VESTS), [500HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=929687.3167798546%20VESTS), [1000HP](https://hivesigner.com/sign/delegateVestingShares?delegator=&delegatee=indiaunited&vesting_shares=1859374.6335597092%20VESTS). 

Read our latest [announcement post](https://hive.blog/hive-186042/@indiaunited/indiaunited-2-0-active-again-with-a-lot-more-energy-this-time) to get more information. 

[![image.png](https://files.peakd.com/file/peakd-hive/bala41288/46eaz12N-image.png)](https://discord.gg/bGmS2tE) 

<sub>**Please contribute to the community by upvoting this comment and posts made by @indiaunited.**</sub>
properties (22)
authorindiaunited
permlinkindiaunited-1635267734843
categoryhive-167922
json_metadata{"app":"hiveblog/0.1","tags":["india","indiaunited"]}
created2021-10-26 17:02:15
last_update2021-10-26 17:02:15
depth1
children0
last_payout2021-11-02 17:02:15
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,251
author_reputation96,877,081,093,210
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,307,334
net_rshares0
@tobetada ·
thank you!
properties (22)
authortobetada
permlinkre-bobinson-r1lqcs
categoryhive-167922
json_metadata{"tags":["hive-167922"],"app":"peakd/2021.09.1"}
created2021-10-26 20:31:42
last_update2021-10-26 20:31:42
depth1
children0
last_payout2021-11-02 20:31:42
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_length10
author_reputation597,305,408,419,315
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,310,779
net_rshares0
@yabapmatt ·
Can this system also be used for cross-chain swaps between Hive and other platforms? I would be interested in discussing this with you if you have time and want to reach out.
properties (22)
authoryabapmatt
permlinkre-bobinson-r1lriy
categoryhive-167922
json_metadata{"tags":["hive-167922"],"app":"peakd/2021.09.1"}
created2021-10-26 20:56:57
last_update2021-10-26 20:56:57
depth1
children4
last_payout2021-11-02 20:56:57
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_length174
author_reputation160,224,638,135,630
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,311,195
net_rshares0
@bobinson · (edited)
$0.31
The tech is part of the core Peerplays blockchain and currently supports Bitcoin and Hive blockchains (Note Hive Support is in the final QA phase). Ethereum support is in progress. You can natively use the tech to swap HIVE to say BTC or HBD to BTC in couple of months. HIVE/HBD to ETH will be few months down the line. Ethereum support will also open up other pairs like HIVE to an ERC20 token. The swap itself will be done on the DEX and cross chain transfer will be using the decentralized, elected nodes (SONs).

Once the UI for the DEX is available, I think you or anyone can use the swap functionality out of the box. Once the UI is ready in a month or so, I can reach out.
👍  
👎  
properties (23)
authorbobinson
permlinkr1ls2c
categoryhive-167922
json_metadata{"app":"hiveblog/0.1"}
created2021-10-26 21:08:39
last_update2021-10-26 21:17:27
depth2
children3
last_payout2021-11-02 21:08:39
cashout_time1969-12-31 23:59:59
total_payout_value0.156 HBD
curator_payout_value0.155 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length679
author_reputation55,343,141,313,811
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,311,418
net_rshares273,486,742,734
author_curate_reward""
vote details (2)
@starkerz ·
$0.62
This is super great to hear! Looking forwards to doing such swaps with platforms that have integrated the SPK Network using this tech
👍  
properties (23)
authorstarkerz
permlinkr1lxpj
categoryhive-167922
json_metadata{"app":"hiveblog/0.1"}
created2021-10-26 23:10:36
last_update2021-10-26 23:10:36
depth3
children2
last_payout2021-11-02 23:10:36
cashout_time1969-12-31 23:59:59
total_payout_value0.310 HBD
curator_payout_value0.310 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length133
author_reputation107,542,654,432,900
root_title"Notes Hive Public API node performance"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id107,313,712
net_rshares541,707,248,325
author_curate_reward""
vote details (1)