Skip to content

New block API

#96 (closed) (haf_api_node is in sync on steem-11)

tl;dr:

  • reversed order of pages (similar to hafah-api/accounts/{account-name}/operations)
  • filtering by operations or account returns LIMITED result (max 10 pages - performance reasons)
  • filtering by operations or account requires keeping track of block-range object (especially important when sharing links to filtered page)
  • posibility to easly generate more pages than initially generated (when above filters are used)

https://local.bc.fqdn.pl - 5m blocks test node


1. default view is simple - the page num is stable and going through pages does NOT require the to-block filtering

--first page for `block-range` {"from" : 1, "to" : (head-block)} 
explain analyze
SELECT * FROM hafbe_endpoints.get_block_by_op(
	NULL,
	NULL,
	NULL,
	100,
	'desc',
	NULL,
	NULL,
	NULL
)
--Execution Time: 32.829 ms

--last page for `block-range` {"from" : 1, "to" : (head-block)} 
explain analyze
SELECT * FROM hafbe_endpoints.get_block_by_op(
	NULL,
	NULL,
	1,
	100,
	'desc',
	NULL,
	NULL,
	NULL
)
--Execution Time: 8.447 ms

The same when from-block or to-block is used, the pages are always fully saturated.

--first page for `block-range` {"from" : 20000000, "to" : 30000000} 
explain analyze
SELECT * FROM hafbe_endpoints.get_block_by_op(
	NULL,
	NULL,
	NULL,
	100,
	'desc',
	'20000000',
	'30000000',
	NULL
)
--Execution Time: 31.605 ms

--last page for `block-range` {"from" : 20000000, "to" : 30000000} 
explain analyze
SELECT * FROM hafbe_endpoints.get_block_by_op(
	NULL,
	NULL,
	1,
	100,
	'desc',
	'20000000',
	'30000000',
	NULL
)
--Execution Time: 49.124 ms

Example first page

{
   "total_blocks":94124375,
   "total_pages":941244,
   "block_range":{
      "from":1,
      "to":94124375
   },
   "blocks_result":[
      {
         "block_num":94124375,
         "created_at":"2025-03-14T09:18:45",
         "producer_account":"ocd-witness",
         "producer_reward":"498141477",
         "trx_count":16,
         "hash":"059c3957fb7195e454f1197a03a34b249cc7af73",
         "prev":"059c39569f99db2c3f0982c9bce5b1b78240d5f1",
         "operations":[
            {
               "op_type_id":0,
               "op_count":1
            },
            {
               "op_type_id":18,
               "op_count":13
            },
            {
               "op_type_id":39,
               "op_count":1
            },
            {
               "op_type_id":42,
               "op_count":1
            },
            {
               "op_type_id":61,
               "op_count":1
            },
            {
               "op_type_id":64,
               "op_count":1
            },
            {
               "op_type_id":72,
               "op_count":1
            }
         ]
      },
      {
         "block_num":94124374,
         "created_at":"2025-03-14T09:18:42",
         "producer_account":"roelandp",
         "producer_reward":"498141478",
         "trx_count":24,
         "hash":"059c39569f99db2c3f0982c9bce5b1b78240d5f1",
         "prev":"059c3955c5a15589bf99d3bacf0cbcaa3fd41a84",
         "operations":[
            {
               "op_type_id":0,
               "op_count":2
            },
            {
               "op_type_id":1,
               "op_count":1
            },
            {
               "op_type_id":3,
               "op_count":1
            },
            {
               "op_type_id":18,
               "op_count":18
            },
            {
               "op_type_id":39,
               "op_count":1
            },
            {
               "op_type_id":42,
               "op_count":1
            },
            {
               "op_type_id":64,
               "op_count":1
            },
            {
               "op_type_id":72,
               "op_count":2
            },
            {
               "op_type_id":77,
               "op_count":1
            }
         ]
      },
      {
         "block_num":94124373,
         "created_at":"2025-03-14T09:18:39",
         "producer_account":"quochuy",
         "producer_reward":"498141480",
         "trx_count":15,
         "hash":"059c3955c5a15589bf99d3bacf0cbcaa3fd41a84",
         "prev":"059c3954db9813683b47afd65ad87acc73f2f188",
         "operations":[
            {
               "op_type_id":0,
               "op_count":2
            },
            {
               "op_type_id":18,
               "op_count":11
            },
            {
               "op_type_id":39,
               "op_count":2
            },
            {
               "op_type_id":61,
               "op_count":1
            },
            {
               "op_type_id":64,
               "op_count":1
            },
            {
               "op_type_id":72,
               "op_count":2
            }
         ]
      },
      (...)
   ]
}

2. Below examples are relevant to ALL filtering options (by operations, by account, by path-filter)

-- first page
explain analyze
SELECT * FROM hafbe_endpoints.get_block_by_op(
	'74',
	NULL,
	NULL,
	100,
	'desc',
	NULL,
	NULL,
	NULL
)
--Execution Time: 102.597 ms
{
   "total_blocks":1000,
   "total_pages":10,
   "block_range":{
      "from":94002553,
      "to":94124375
   },
   "blocks_result":[
      {
         "block_num":94124358,
         "created_at":"2025-03-14T09:17:54",
         "producer_account":"threespeak",
         "producer_reward":"498141501",
         "trx_count":20,
         "hash":"059c3946214ebfeed55cd6bb438dfe35a6f3dffc",
         "prev":"059c3945e782cbd006a2f0aaabf71ad22be42112",
         "operations":[
            {
               "op_type_id":74,
               "op_count":1
            }
         ]
      },
      {
         "block_num":94124346,
         "created_at":"2025-03-14T09:17:18",
         "producer_account":"ocd-witness",
         "producer_reward":"498141519",
         "trx_count":21,
         "hash":"059c393a5b99cf607891c022bf402dc84d816952",
         "prev":"059c3939df44273c57d9a055681e66bf508a6b77",
         "operations":[
            {
               "op_type_id":74,
               "op_count":1
            }
         ]
      },
      {
         "block_num":94124230,
         "created_at":"2025-03-14T09:11:27",
         "producer_account":"abit",
         "producer_reward":"498141687",
         "trx_count":17,
         "hash":"059c38c65f051c1cc268b089f45e15f256780878",
         "prev":"059c38c50ab51093d7edabe0c0c7968a0422eaf7",
         "operations":[
            {
               "op_type_id":74,
               "op_count":1
            }
         ]
      },
      (...)
   ]
}

"block-range": {"from" : 94002553, "to" : 94124375}- (94124375 - was my headblock)

Going through pages on FILTERED view requires filter on to-block the pages are calculated based on result set, so to be sure that ALL next pages are related to the first we iterate using to-block equal to to parameter from block-range object

-- last page
explain analyze
SELECT * FROM hafbe_endpoints.get_block_by_op(
	'74',
	NULL,
	1,
	100,
	'desc',
	NULL,
	'94124375',
	NULL
)
--Execution Time: 84.701 ms

After reaching the last page (page is reversed like in account-history so the last page is 1) we can generate NEW set of pages for the same filter (in this example it is filtered by operation 74) by CHANGING the to-block to from parameter from block-range object then the new block-range object is generated and the sequence can be repeated UNTIL the from parameter is equal to 1

-- first page (next group)
explain analyze
SELECT * FROM hafbe_endpoints.get_block_by_op(
	'74',
	NULL,
	NULL,
	100,
	'desc',
	NULL,
	'94002553',
	NULL
)
--Execution Time: 107.602 ms

"block-range": {"from" : 1, "to" : 94124375}- (94124375 - was my headblock)

** If block-range from parameter is 1 (or equal to from-block filter - if used in API call), it means there is NO more blocks to generate and the currently generated total_pages is everything to show**

-- first page 
explain analyze
SELECT * FROM hafbe_endpoints.get_block_by_op(
	'68',
	NULL,
	NULL,
	100,
	'desc',
	NULL,
	NULL,
	NULL
)
--Execution Time: 2.162 ms
{
   "total_blocks":1,
   "total_pages":1,
   "block_range":{
      "from":1,
      "to":94124375
   },
   "blocks_result":[
      {
         "block_num":41818752,
         "created_at":"2020-03-20T14:00:00",
         "producer_account":"toke2049",
         "producer_reward":"485690870",
         "trx_count":10,
         "hash":"027e1a8078788dd29c210ff3a948dc89902ce497",
         "prev":"027e1a7ff47713b4578bc2293e134aa8a01a0031",
         "operations":[
            {
               "op_type_id":68,
               "op_count":328
            }
         ]
      }
   ]
}

Operation 68 happened only in one block so the block-range object {"from" : 1, "to" : 94124375} indicates there are no more pages to generate

Edited by Michal Zander

Merge request reports

Loading