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

Improve consensus indexer #1023

Merged
merged 17 commits into from
Dec 10, 2024
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
53 changes: 39 additions & 14 deletions indexers/db/docker-entrypoint-initdb.d/init-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ CREATE TABLE consensus.account_histories (
reserved numeric NOT NULL,
total numeric,
created_at numeric NOT NULL,
updated_at numeric NOT NULL,
_id uuid NOT NULL,
_block_range int8range NOT NULL
);
Expand Down Expand Up @@ -137,6 +136,7 @@ ALTER TABLE consensus.account_rewards OWNER TO postgres;

CREATE TABLE consensus.accounts (
id text NOT NULL,
account_id text NOT NULL,
nonce numeric NOT NULL,
free numeric NOT NULL,
reserved numeric NOT NULL,
Expand All @@ -162,6 +162,26 @@ CREATE TABLE consensus.blocks (
blockchain_size numeric NOT NULL,
extrinsics_count integer NOT NULL,
events_count integer NOT NULL,
accounts_count integer NOT NULL,
transfers_count integer NOT NULL,
rewards_count integer NOT NULL,
block_rewards_count integer NOT NULL,
vote_rewards_count integer NOT NULL,
transfer_value numeric NOT NULL,
reward_value numeric NOT NULL,
block_reward_value numeric NOT NULL,
vote_reward_value numeric NOT NULL,
cumulative_extrinsics_count numeric NOT NULL,
cumulative_events_count numeric NOT NULL,
cumulative_accounts_count numeric NOT NULL,
cumulative_transfers_count numeric NOT NULL,
cumulative_rewards_count numeric NOT NULL,
cumulative_block_rewards_count numeric NOT NULL,
cumulative_vote_rewards_count numeric NOT NULL,
cumulative_transfer_value numeric NOT NULL,
cumulative_reward_value numeric NOT NULL,
cumulative_block_reward_value numeric NOT NULL,
cumulative_vote_reward_value numeric NOT NULL,
author_id text NOT NULL,
_id uuid NOT NULL,
_block_range int8range NOT NULL
Expand All @@ -172,6 +192,7 @@ CREATE TABLE consensus.event_modules (
id text NOT NULL,
section text NOT NULL,
method text NOT NULL,
name text NOT NULL,
_id uuid NOT NULL,
_block_range int8range NOT NULL
);
Expand Down Expand Up @@ -202,6 +223,7 @@ CREATE TABLE consensus.extrinsic_modules (
id text NOT NULL,
section text NOT NULL,
method text NOT NULL,
name text NOT NULL,
_id uuid NOT NULL,
_block_range int8range NOT NULL
);
Expand Down Expand Up @@ -235,6 +257,7 @@ ALTER TABLE consensus.extrinsics OWNER TO postgres;

CREATE TABLE consensus.log_kinds (
id text NOT NULL,
kind text NOT NULL,
_id uuid NOT NULL,
_block_range int8range NOT NULL
);
Expand All @@ -258,8 +281,9 @@ CREATE TABLE consensus.rewards (
id text NOT NULL,
block_height numeric NOT NULL,
block_hash text NOT NULL,
extrinsic_id text NOT NULL,
event_id text NOT NULL,
account_id text NOT NULL,
index_in_block numeric NOT NULL,
reward_type text NOT NULL,
amount numeric NOT NULL,
"timestamp" timestamp without time zone NOT NULL,
Expand All @@ -270,23 +294,24 @@ ALTER TABLE consensus.rewards OWNER TO postgres;

CREATE TABLE consensus.sections (
id text NOT NULL,
section text NOT NULL,
_id uuid NOT NULL,
_block_range int8range NOT NULL
);
ALTER TABLE consensus.sections OWNER TO postgres;

CREATE TABLE consensus.transfers (
id text NOT NULL,
block_height numeric NOT NULL,
block_hash text NOT NULL,
extrinsic_id text NOT NULL,
event_id text NOT NULL,
"from" text NOT NULL,
"to" text NOT NULL,
value numeric NOT NULL,
fee numeric NOT NULL,
success boolean NOT NULL,
"timestamp" numeric NOT NULL,
date timestamp without time zone NOT NULL,
created_at numeric NOT NULL,
"timestamp" timestamp without time zone NOT NULL,
_id uuid NOT NULL,
_block_range int8range NOT NULL
);
Expand Down Expand Up @@ -1081,10 +1106,12 @@ ALTER TABLE ONLY leaderboard.operator_withdrawals_total_counts

CREATE INDEX "0x08aa840e441d13bb" ON consensus.blocks USING gist (height, _block_range);
CREATE INDEX "0x09a98aa53fa2c2e3" ON consensus.logs USING btree (id);
CREATE INDEX "0x0aabe4e2902c545f" ON consensus.account_rewards USING gist (created_at, _block_range);
CREATE INDEX "0x0d1bd9e945ce43a3" ON consensus.event_modules USING gist (method, _block_range);
CREATE INDEX "0x12b6c780263a8815" ON consensus.transfers USING gist (block_height, _block_range);
CREATE INDEX "0x1532f5e4701949a5" ON consensus.extrinsics USING gist (hash, _block_range);
CREATE INDEX "0x1762232b2820e83d" ON consensus.extrinsic_modules USING gist (section, _block_range);
CREATE INDEX "0x19dcea041a0703f4" ON consensus.accounts USING gist (account_id, _block_range);
CREATE INDEX "0x1dd72f018721e423" ON consensus.extrinsic_modules USING gist (name, _block_range);
CREATE INDEX "0x1e967733a0d5db15" ON consensus.rewards USING btree (id);
CREATE INDEX "0x2481c1ffa5112599" ON consensus.logs USING gist (block_hash, _block_range);
CREATE INDEX "0x26e9de0ee335659c" ON consensus.extrinsic_modules USING btree (id);
Expand All @@ -1095,38 +1122,36 @@ CREATE INDEX "0x30b779cc3aeeeec6" ON consensus.events USING gist (extrinsic_id,
CREATE INDEX "0x358cafe370ac92ef" ON consensus.accounts USING gist (total, _block_range);
CREATE INDEX "0x3ae5d1670e99e612" ON consensus.transfers USING gist ("timestamp", _block_range);
CREATE INDEX "0x3d8ee08d232943ea" ON consensus.sections USING btree (id);
CREATE INDEX "0x4131da2c2ec8b5b7" ON consensus.transfers USING gist (date, _block_range);
CREATE INDEX "0x43615b2452f72359" ON consensus.account_profiles USING btree (id);
CREATE INDEX "0x444de3b3611c1fcd" ON consensus.account_histories USING gist (created_at, _block_range);
CREATE INDEX "0x47d5e34ca84a0356" ON consensus.rewards USING gist (event_id, _block_range);
CREATE INDEX "0x4a66afa700f00759" ON consensus.events USING gist (block_hash, _block_range);
CREATE INDEX "0x4b2e240a52e09d22" ON consensus.extrinsics USING gist (cid, _block_range);
CREATE INDEX "0x4c738865df5c227d" ON consensus.account_profiles USING gist (created_at, _block_range);
CREATE INDEX "0x4cb388e53e3e30f3" ON consensus.accounts USING btree (id);
CREATE INDEX "0x53fb0cf455c914c8" ON consensus.account_profiles USING gist (updated_at, _block_range);
CREATE INDEX "0x55286926221be2e7" ON consensus.event_modules USING btree (id);
CREATE INDEX "0x57fc196dcc99a091" ON consensus.events USING gist (block_height, _block_range);
CREATE INDEX "0x5921649101eeb57a" ON consensus.transfers USING gist (created_at, _block_range);
CREATE INDEX "0x59386a58438fa05a" ON consensus.extrinsics USING gist (section, _block_range);
CREATE INDEX "0x59f75d2bc1e6a0bc" ON consensus.blocks USING gist ("timestamp", _block_range);
CREATE INDEX "0x5b5ab04a8ff6f214" ON consensus.events USING gist (cid, _block_range);
CREATE INDEX "0x5c04eee35ba10ef1" ON consensus.extrinsic_modules USING gist (method, _block_range);
CREATE INDEX "0x5cfbdda34ba486b0" ON consensus.event_modules USING gist (name, _block_range);
CREATE INDEX "0x5eb8e024a00f2132" ON consensus.rewards USING gist (extrinsic_id, _block_range);
CREATE INDEX "0x6008270492da5713" ON consensus.events USING gist ("timestamp", _block_range);
CREATE INDEX "0x6131d72d57f2a188" ON consensus.blocks USING gist (hash, _block_range);
CREATE INDEX "0x61510445e44f4f2f" ON consensus.logs USING gist (index_in_block, _block_range);
CREATE INDEX "0x64128774d8de590c" ON consensus.log_kinds USING btree (id);
CREATE INDEX "0x6f53f38c566a1b3a" ON consensus.extrinsics USING gist (module, _block_range);
CREATE INDEX "0x6ffa574597ba780e" ON consensus.event_modules USING gist (section, _block_range);
CREATE INDEX "0x73cd163028b0b898" ON consensus.rewards USING gist (account_id, _block_range);
CREATE INDEX "0x73d8b9e481a083a2" ON consensus.transfers USING gist (block_hash, _block_range);
CREATE INDEX "0x774ec1c372b71838" ON consensus.events USING gist (sort_id, _block_range);
CREATE INDEX "0x786f1b7d3a4d3cc2" ON consensus.account_rewards USING btree (id);
CREATE INDEX "0x79131319c12e8920" ON consensus.transfers USING gist ("from", _block_range);
CREATE INDEX "0x79ff6a28c8a013aa" ON consensus.logs USING gist ("timestamp", _block_range);
CREATE INDEX "0x7b661a36dc0847a1" ON consensus.accounts USING gist (updated_at, _block_range);
CREATE INDEX "0x7ffad162028c7729" ON consensus.log_kinds USING gist (kind, _block_range);
CREATE INDEX "0x889e9f7e5a64267c" ON consensus.extrinsics USING gist (block_height, _block_range);
CREATE INDEX "0x946898e0d99da99d" ON consensus.blocks USING gist (sort_id, _block_range);
CREATE INDEX "0x9dc19a4dda2286f4" ON consensus.events USING gist (section, _block_range);
CREATE INDEX "0xa1455f2831f03723" ON consensus.rewards USING gist ("timestamp", _block_range);
CREATE INDEX "0xa81afc487642f92c" ON consensus.account_profiles USING gist (name, _block_range);
CREATE INDEX "0xb0f971b6213bd370" ON consensus.events USING gist (module, _block_range);
CREATE INDEX "0xb3d3d7d2b08d4e7e" ON consensus.rewards USING gist (block_hash, _block_range);
CREATE INDEX "0xb7bb46c9ebdd7fe1" ON consensus.transfers USING gist (extrinsic_id, _block_range);
Expand All @@ -1138,11 +1163,11 @@ CREATE INDEX "0xc7a7467355cf8dbb" ON consensus.extrinsics USING gist ("timestamp
CREATE INDEX "0xccedb032815757ed" ON consensus.blocks USING btree (id);
CREATE INDEX "0xd21b20c334f80c2e" ON consensus.account_histories USING btree (id);
CREATE INDEX "0xd8db4c8313621519" ON consensus.extrinsics USING btree (id);
CREATE INDEX "0xe0b781f836dc2f1a" ON consensus.account_histories USING gist (updated_at, _block_range);
CREATE INDEX "0xe2d1f5b9c21b141e" ON consensus.extrinsics USING gist (signer, _block_range);
CREATE INDEX "0xe56a7291c224fff9" ON consensus.transfers USING gist ("to", _block_range);
CREATE INDEX "0xe5bf5858bd35a276" ON consensus.events USING btree (id);
CREATE INDEX "0xf095c4017bdfed7d" ON consensus.rewards USING gist (block_height, _block_range);
CREATE INDEX "0xf167d3b68efcf448" ON consensus.sections USING gist (section, _block_range);
CREATE INDEX "0xf20fbf5a3f59a046" ON consensus.extrinsics USING gist (success, _block_range);
CREATE INDEX "0xf303d79993939441" ON consensus.rewards USING gist (reward_type, _block_range);
CREATE INDEX "0xf6317466d2b3ee74" ON consensus.logs USING gist (block_height, _block_range);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ select_permissions:
- nonce
- reserved
- total
- updated_at
- id
- _id
filter: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ select_permissions:
permission:
columns:
- _block_range
- _id
- account_id
- created_at
- free
- id
- nonce
- reserved
- total
- updated_at
- id
- _id
filter: {}
allow_aggregations: true
comment: ""
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,31 @@ select_permissions:
permission:
columns:
- _block_range
- accounts_count
- block_rewards_count
- events_count
- extrinsics_count
- rewards_count
- transfers_count
- vote_rewards_count
- block_reward_value
- blockchain_size
- cumulative_accounts_count
- cumulative_block_reward_value
- cumulative_block_rewards_count
- cumulative_events_count
- cumulative_extrinsics_count
- cumulative_reward_value
- cumulative_rewards_count
- cumulative_transfer_value
- cumulative_transfers_count
- cumulative_vote_reward_value
- cumulative_vote_rewards_count
- height
- reward_value
- space_pledged
- transfer_value
- vote_reward_value
- author_id
- extrinsics_root
- hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ select_permissions:
permission:
columns:
- _block_range
- _id
- id
- method
- name
- section
- _id
filter: {}
allow_aggregations: true
comment: ""
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ select_permissions:
- index_in_block
- args
- block_hash
- cid
- extrinsic_hash
- extrinsic_id
- id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ select_permissions:
permission:
columns:
- _block_range
- _id
- id
- method
- name
- section
- _id
filter: {}
allow_aggregations: true
comment: ""
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ select_permissions:
- tip
- args
- block_hash
- cid
- error
- hash
- id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ select_permissions:
permission:
columns:
- _block_range
- id
- _id
- id
- kind
filter: {}
allow_aggregations: true
comment: ""
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ select_permissions:
- _block_range
- amount
- block_height
- index_in_block
- account_id
- block_hash
- event_id
- extrinsic_id
- id
- reward_type
- timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ select_permissions:
columns:
- _block_range
- id
- section
- _id
filter: {}
allow_aggregations: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ select_permissions:
- role: user
permission:
columns:
- success
- _block_range
- _id
- created_at
- date
- block_height
- fee
- value
- block_hash
- event_id
- extrinsic_id
- fee
- from
- id
- success
- timestamp
- to
- value
- timestamp
- _id
filter: {}
allow_aggregations: true
comment: ""
4 changes: 2 additions & 2 deletions indexers/db/scripts/genisis-allocation-to-seeds/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ for (const entry of data) {

await accountsFile.write(
new TextEncoder().encode(
`INSERT INTO consensus.accounts (id, nonce, free, reserved, total, created_at, updated_at, _id, _block_range) VALUES ('${accountId}', 0, ${freeBalance}, ${reservedBalance}, ${totalBalance}, ${createdAt}, ${updatedAt}, '${_id}', '${_blockRange}');\n`
`INSERT INTO consensus.accounts (id, account_id, nonce, free, reserved, total, created_at, updated_at, _id, _block_range) VALUES ('${accountId}', '${accountId}', 0, ${freeBalance}, ${reservedBalance}, ${totalBalance}, ${createdAt}, ${updatedAt}, '${_id}', '${_blockRange}');\n`
)
);
await accountHistoriesFile.write(
new TextEncoder().encode(
`INSERT INTO consensus.account_histories (id, nonce, free, reserved, total, created_at, updated_at, _id, _block_range) VALUES ('${accountId}', 0, ${freeBalance}, ${reservedBalance}, ${totalBalance}, ${createdAt}, ${updatedAt}, '${_id}', '${_blockRange}');\n`
`INSERT INTO consensus.account_histories (id, nonce, free, reserved, total, created_at, _id, _block_range) VALUES ('${accountId}', 0, ${freeBalance}, ${reservedBalance}, ${totalBalance}, ${createdAt}, '${_id}', '${_blockRange}');\n`
)
);
}
Expand Down
Loading
Loading