helium / blockchain-etl

Blockchain follower that follows and stores the Helium blockchain
Apache License 2.0
64 stars 37 forks source link

validator_heartbeat_v1 transactions with update gateway_inventory last_block (instead of last_poc_challenge) #331

Closed riobah closed 11 months ago

riobah commented 2 years ago

This issue is to record the issue which was discussed on the blockchain-development Discord channel.

The issue was checked for a specific hotspot, but then it is seen that this is a more wide spread issue. Below was the hotspot checked:

etl=# select 
etl-#  reactivated_gw, 
etl-#  block as "block with reactivated_gw",
etl-#  case 
etl-#     when block = i.last_poc_challenge then 'last_poc_challenge'
etl-#     when block = i.last_block then 'last_block'
etl-#     else 'did not update'
etl-#  end as "field updated",
etl-#  i.last_poc_challenge, 
etl-#  i.last_block
etl-# from transactions t, gateway_inventory i
etl-# cross join lateral jsonb_array_elements_text ( fields -> 'reactivated_gws' ) as reactivated_gw
etl-# where i.address='112rnMxNSvqaAWyXxDg5T8zkcRcpdhdzcEJKiwbzErx2FpXgrcLw'
etl-#   and (block = i.last_poc_challenge or block = i.last_block)
etl-#   and type = 'validator_heartbeat_v1'
etl-#   and reactivated_gw = i.address
etl-# order by block desc;
                    reactivated_gw                    | block with reactivated_gw | field updated | last_poc_challenge | last_block 
------------------------------------------------------+---------------------------+---------------+--------------------+------------
 112rnMxNSvqaAWyXxDg5T8zkcRcpdhdzcEJKiwbzErx2FpXgrcLw |                   1355455 | last_block    |            1355450 |    1355455
(1 row)

And this is the transaction with different block values for the block column and the fields:

etl=# select block, hash, fields ->> 'hash', fields ->> 'height'
from transactions 
where hash = 'zd82TsSUsaxhFrlPad1woedqCT0kI4srq_RjoUFUkLM';
  block  |                    hash                     |                  ?column?                   | ?column? 
---------+---------------------------------------------+---------------------------------------------+----------
 1355455 | zd82TsSUsaxhFrlPad1woedqCT0kI4srq_RjoUFUkLM | zd82TsSUsaxhFrlPad1woedqCT0kI4srq_RjoUFUkLM | 1355450
(1 row)

This query is to show how the data for the hotspots are in general:

etl=# select 
etl-#  case 
etl-#     when block = i.last_poc_challenge then 'last_poc_challenge'
etl-#     when block = i.last_block then 'last_block'
etl-#     else 'did not update'
etl-#  end as field_updated,
etl-#  count(*)
etl-# from transactions t, gateway_inventory i
etl-# cross join lateral jsonb_array_elements_text ( fields -> 'reactivated_gws' ) as reactivated_gw
etl-# where (block = i.last_poc_challenge or block = i.last_block)
etl-#   and type = 'validator_heartbeat_v1'
etl-#   and reactivated_gw = i.address
etl-#   and t.block > 1300000
etl-#   and i.last_poc_challenge > 1300000
etl-#   and i.last_block > 1300000
etl-# group by field_updated;
   field_updated    | count  
--------------------+--------
 last_block         | 159615
 last_poc_challenge |   1687
(2 rows)