Skip to content
Snippets Groups Projects
Commit 846b5b3f authored by Michal Zander's avatar Michal Zander
Browse files

Add temporary hack for hf23

parent 1b455972
No related branches found
No related tags found
2 merge requests!168Update return types: VEST balances should be returned as strings to address JSON limitations,!146Rewrite other balance calculating loops
Pipeline #114047 passed
......@@ -11,30 +11,11 @@ WITH hardfork_hive_operation AS MATERIALIZED
SELECT
(SELECT id FROM accounts_view WHERE name = (body)->'value'->>'account') AS _account
),
balances AS (
UPDATE current_account_balances SET
balance = 0
FROM hardfork_hive_operation
WHERE account = _account
),
rewards AS (
UPDATE account_rewards SET
balance = 0
FROM hardfork_hive_operation
WHERE account = _account
),
delegations AS (
UPDATE account_delegations SET
delegated_vests = 0
FROM hardfork_hive_operation
WHERE account = _account
),
savings AS (
UPDATE account_savings SET
saving_balance = 0,
savings_withdraw_requests = 0
FROM hardfork_hive_operation
WHERE account = _account
)
UPDATE account_withdraws SET
vesting_withdraw_rate = 0,
......@@ -47,6 +28,54 @@ savings AS (
END
$$;
--this function won't be necessary after changes in hardfork_hive_operation
CREATE OR REPLACE FUNCTION process_hf_23(__hardfork_23_block INT)
RETURNS VOID
LANGUAGE 'plpgsql' VOLATILE
AS
$$
DECLARE
__balances INT;
__rewards INT;
__savings INT;
BEGIN
WITH hardfork_hive_operation AS MATERIALIZED (
SELECT
(SELECT av.id FROM accounts_view av WHERE av.name = (ov.body)->'value'->>'account') AS account_id
FROM operations_view ov
WHERE ov.op_type_id = 68 AND block_num = __hardfork_23_block
),
update_balances AS (
UPDATE current_account_balances cab SET
balance = 0
FROM hardfork_hive_operation hho
WHERE cab.account = hho.account_id
RETURNING cab.account AS cleaned_account_id
),
update_rewards AS (
UPDATE account_rewards ar SET
balance = 0
FROM hardfork_hive_operation hho
WHERE ar.account = hho.account_id
RETURNING ar.account AS cleaned_account_id
),
update_savings AS (
UPDATE account_savings acs SET
saving_balance = 0,
savings_withdraw_requests = 0
FROM hardfork_hive_operation hho
WHERE acs.account = hho.account_id
RETURNING acs.account AS cleaned_account_id
)
SELECT
(SELECT count(*) FROM update_balances) AS balances,
(SELECT count(*) FROM update_rewards) AS rewards,
(SELECT count(*) FROM update_savings) AS savings
INTO __balances, __rewards, __savings;
END
$$;
CREATE OR REPLACE FUNCTION process_hardfork(_hardfork_id INT)
RETURNS VOID
LANGUAGE 'plpgsql' VOLATILE
......
......@@ -264,6 +264,7 @@ $$
DECLARE
__start_ts timestamptz;
__end_ts timestamptz;
__hardfork_23_block INT := (SELECT block_num FROM hafd.applied_hardforks WHERE hardfork_num = 23);
BEGIN
PERFORM set_config('synchronous_commit', 'OFF', false);
......@@ -272,10 +273,39 @@ BEGIN
__start_ts := clock_timestamp();
END IF;
PERFORM process_block_range_balances(_from, _to);
PERFORM process_block_range_data(_from, _to);
PERFORM process_block_range_savings(_from, _to);
PERFORM process_block_range_rewards(_from, _to);
-- TODO: remove this hack after the hardfork_hive_operation is fixed
-- harfork_hive_operation lacks informations about rewards, savings and balances
-- to use rewards, savings and balances processed in query rather by insterting every operation to table
-- hf_23 accounts needs to be processed manually
-- Check if the block number hf_23 is within the range
IF __hardfork_23_block BETWEEN _from AND _to THEN
-- Enter a loop iterating from _from to hf_23
PERFORM process_block_range_balances(_from, __hardfork_23_block);
PERFORM process_block_range_data(_from, __hardfork_23_block);
PERFORM process_block_range_savings(_from, __hardfork_23_block);
PERFORM process_block_range_rewards(_from, __hardfork_23_block);
-- Manually process hardfork_hive_operation for balance, rewards, savings
PERFORM process_hf_23(__hardfork_23_block);
RAISE NOTICE 'Btracker processed hardfork 23 successfully';
IF __hardfork_23_block != _to THEN
-- Continue the loop from hf_23 to _to
PERFORM process_block_range_balances(__hardfork_23_block + 1, _to);
PERFORM process_block_range_data(__hardfork_23_block + 1, _to);
PERFORM process_block_range_savings(__hardfork_23_block + 1, _to);
PERFORM process_block_range_rewards(__hardfork_23_block + 1, _to);
END IF;
ELSE
-- If 41818752 is not in range, process the full range normally
PERFORM process_block_range_balances(_from, _to);
PERFORM process_block_range_data(_from, _to);
PERFORM process_block_range_savings(_from, _to);
PERFORM process_block_range_rewards(_from, _to);
END IF;
IF _logs THEN
__end_ts := clock_timestamp();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment