Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep improving trigger logic for staking #1223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions indexers/db/docker-entrypoint-initdb.d/init-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,7 @@ CREATE TRIGGER ensure_cumulative_blocks
CREATE OR REPLACE FUNCTION staking.prevent_domain_block_histories_duplicate() RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
BEGIN
IF EXISTS (
SELECT 1
FROM staking.domain_block_histories
Expand All @@ -2366,7 +2366,7 @@ BEGIN
WHERE id = NEW.domain_id;

RETURN NEW;
END;
END;
$$;
ALTER FUNCTION staking.prevent_domain_block_histories_duplicate() OWNER TO postgres;

Expand Down Expand Up @@ -3052,7 +3052,22 @@ EXECUTE FUNCTION staking.update_operator_stakes();
CREATE OR REPLACE FUNCTION staking.update_domain_stakes() RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
DECLARE
last_domain_block_histories_domain_block_number staking.domain_block_histories.domain_block_number%TYPE;
BEGIN
SELECT domain_block_number
INTO last_domain_block_histories_domain_block_number
FROM staking.domain_block_histories
WHERE domain_id = NEW.domain_id
ORDER BY block_height DESC
LIMIT 1;

IF NOT FOUND THEN
SELECT
0 as domain_block_number
INTO last_domain_block_histories_domain_block_number;
END IF;

UPDATE staking.domains
SET
current_total_stake = NEW.current_total_stake,
Expand All @@ -3078,7 +3093,7 @@ BEGIN
NEW.domain_id || '-' || NEW.current_epoch_index,
NEW.domain_id,
NEW.current_epoch_index,
0,
last_domain_block_histories_domain_block_number, -- Fixed this line
0,
0,
NEW.timestamp,
Expand All @@ -3097,7 +3112,7 @@ BEGIN
updated_at = NEW.block_height;

RETURN NEW;
END;
END;
$$;
ALTER FUNCTION staking.update_domain_stakes() OWNER TO postgres;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ select_permissions:
- current_total_shares
- current_total_stake
- total_deposits
- total_deposits_count
- total_estimated_withdrawals
- total_tax_collected
- total_withdrawals
- total_withdrawals_count
- updated_at
- id
filter: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ select_permissions:
permission:
columns:
- _block_range
- block_height
- burned_balance
- consensus_block_number
- consensus_storage_fee
Expand All @@ -36,6 +37,7 @@ select_permissions:
- domain_block_id
- domain_id
- event_id
- extrinsic_id
- id
- operator_id
- _id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ select_permissions:
permission:
columns:
- _block_range
- effective_domain_epoch_pending
- effective_domain_id_pending
- _id
- account_id
- amount_pending
- block_height
- domain_id
- effective_domain_epoch_pending
- effective_domain_id_pending
- id
- nominator_id
- operator_id
- shares
- shares_known
- storage_fee_deposit
- storage_fee_deposit_known
- storage_fee_deposit_pending
- account_id
- id
- nominator_id
- operator_id
- _id
- timestamp
filter: {}
limit: 50
comment: ""
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ select_permissions:
- current_total_stake
- domain_id
- id
- timestamp
- _id
filter: {}
limit: 50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ select_permissions:
- total_burned_balance
- total_consensus_storage_fee
- total_deposits
- total_deposits_count
- total_domain_execution_fee
- total_estimated_withdrawals
- total_rejected_transfers_claimed
Expand All @@ -102,6 +103,7 @@ select_permissions:
- total_transfers_rejected
- total_volume
- total_withdrawals
- total_withdrawals_count
- transfers_in_count
- transfers_out_count
- transfers_rejected_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ select_permissions:
- operator_owner
- partial_status
- signing_key
- timestamp
- _id
filter: {}
limit: 50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ select_permissions:
- total_burned_balance
- total_consensus_storage_fee
- total_deposits
- total_deposits_count
- total_domain_execution_fee
- total_estimated_withdrawals
- total_rejected_transfers_claimed
Expand All @@ -117,6 +118,7 @@ select_permissions:
- total_transfers_rejected
- total_volume
- total_withdrawals
- total_withdrawals_count
- transfers_in_count
- transfers_out_count
- transfers_rejected_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ select_permissions:
- event_id
- extrinsic_id
- id
- nominator_id
- operator_id
- _id
filter: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ select_permissions:
permission:
columns:
- _block_range
- domain_epoch
- block_height
- shares
- storage_fee_refund
- total_withdrawal_amount
- unlock_at_confirmed_domain_block_number
- _id
- account_id
- block_height
- domain_epoch
- domain_id
- id
- nominator_id
- operator_id
- _id
- shares
- storage_fee_refund
- timestamp
- total_withdrawal_amount
- unlock_at_confirmed_domain_block_number
filter: {}
limit: 50
comment: ""