diff --git a/db/drop_indexes_for_batch_processing.sql b/db/drop_indexes_for_batch_processing.sql new file mode 100644 index 0000000..30adc82 --- /dev/null +++ b/db/drop_indexes_for_batch_processing.sql @@ -0,0 +1,91 @@ +-- +goose Up +-- log indexes +DROP INDEX eth.log_topic3_index; +DROP INDEX eth.log_topic2_index; +DROP INDEX eth.log_topic1_index; +DROP INDEX eth.log_topic0_index; +DROP INDEX eth.log_address_index; +DROP INDEX eth.log_cid_index; + +-- access list indexes +DROP INDEX eth.access_list_storage_keys_index; +DROP INDEX eth.access_list_element_address_index; + +-- state account indexes +DROP INDEX eth.storage_root_index; +DROP index eth.account_state_path_index; + +-- storage node indexes +DROP INDEX eth.storage_node_type_index; +DROP INDEX eth.storage_path_index; +DROP INDEX eth.storage_cid_index; +DROP INDEX eth.storage_leaf_key_index; +DROP INDEX eth.storage_state_path_index; + +-- state node indexes +DROP INDEX eth.state_node_type_index; +DROP INDEX eth.state_path_index; +DROP INDEX eth.state_cid_index; +DROP INDEX eth.state_leaf_key_index; + +-- receipt indexes +DROP INDEX eth.rct_contract_hash_index; +DROP INDEX eth.rct_contract_index; +DROP INDEX eth.rct_leaf_cid_index; + +-- transaction indexes +DROP INDEX eth.tx_src_index; +DROP INDEX eth.tx_dst_index; +DROP INDEX eth.tx_cid_index; + +-- header indexes +DROP INDEX eth.timestamp_index; +DROP INDEX eth.state_root_index; +DROP INDEX eth.header_cid_index; +DROP INDEX eth.block_number_index; + +-- +goose Down +-- header indexes +CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number); +CREATE INDEX header_cid_index ON eth.header_cids USING btree (cid); +CREATE INDEX state_root_index ON eth.header_cids USING btree (state_root); +CREATE INDEX timestamp_index ON eth.header_cids USING brin (timestamp); + +-- transaction indexes +CREATE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid); +CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst); +CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src); + +-- receipt indexes +CREATE INDEX rct_leaf_cid_index ON eth.receipt_cids USING btree (leaf_cid); +CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract); +CREATE INDEX rct_contract_hash_index ON eth.receipt_cids USING btree (contract_hash); + +-- state node indexes +CREATE INDEX state_leaf_key_index ON eth.state_cids USING btree (state_leaf_key); +CREATE INDEX state_cid_index ON eth.state_cids USING btree (cid); +CREATE INDEX state_path_index ON eth.state_cids USING btree (state_path); +CREATE INDEX state_node_type_index ON eth.state_cids USING btree (node_type); + +-- storage node indexes +CREATE INDEX storage_state_path_index ON eth.storage_cids USING btree (state_path); +CREATE INDEX storage_leaf_key_index ON eth.storage_cids USING btree (storage_leaf_key); +CREATE INDEX storage_cid_index ON eth.storage_cids USING btree (cid); +CREATE INDEX storage_path_index ON eth.storage_cids USING btree (storage_path); +CREATE INDEX storage_node_type_index ON eth.storage_cids USING btree (node_type); + +-- state accounts indexes +CREATE INDEX account_state_path_index ON eth.state_accounts USING btree (state_path); +CREATE INDEX storage_root_index ON eth.state_accounts USING btree (storage_root); + +-- access list indexes +CREATE INDEX access_list_element_address_index ON eth.access_list_element USING btree (address); +CREATE INDEX access_list_storage_keys_index ON eth.access_list_element USING gin (storage_keys); + +-- log indexes +CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid); +CREATE INDEX log_address_index ON eth.log_cids USING btree (address); +CREATE INDEX log_topic0_index ON eth.log_cids USING btree (topic0); +CREATE INDEX log_topic1_index ON eth.log_cids USING btree (topic1); +CREATE INDEX log_topic2_index ON eth.log_cids USING btree (topic2); +CREATE INDEX log_topic3_index ON eth.log_cids USING btree (topic3); diff --git a/db/migrations/00001_create_ipfs_blocks_table.sql b/db/migrations/00001_create_ipfs_blocks_table.sql index 6e3941e..4b017bc 100644 --- a/db/migrations/00001_create_ipfs_blocks_table.sql +++ b/db/migrations/00001_create_ipfs_blocks_table.sql @@ -1,6 +1,6 @@ -- +goose Up CREATE TABLE IF NOT EXISTS public.blocks ( - key TEXT UNIQUE NOT NULL, + key TEXT PRIMARY KEY, data BYTEA NOT NULL ); diff --git a/db/migrations/00004_create_eth_header_cids_table.sql b/db/migrations/00004_create_eth_header_cids_table.sql index f01b116..f5a8a1c 100644 --- a/db/migrations/00004_create_eth_header_cids_table.sql +++ b/db/migrations/00004_create_eth_header_cids_table.sql @@ -1,24 +1,22 @@ -- +goose Up CREATE TABLE eth.header_cids ( - id SERIAL PRIMARY KEY, - block_number BIGINT NOT NULL, - block_hash VARCHAR(66) NOT NULL, - parent_hash VARCHAR(66) NOT NULL, - cid TEXT NOT NULL, - mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - td NUMERIC NOT NULL, - node_id INTEGER NOT NULL REFERENCES nodes (id) ON DELETE CASCADE, - reward NUMERIC NOT NULL, - state_root VARCHAR(66) NOT NULL, - tx_root VARCHAR(66) NOT NULL, - receipt_root VARCHAR(66) NOT NULL, - uncle_root VARCHAR(66) NOT NULL, - bloom BYTEA NOT NULL, - timestamp NUMERIC NOT NULL, - times_validated INTEGER NOT NULL DEFAULT 1, - base_fee BIGINT, - UNIQUE (block_number, block_hash) + block_hash VARCHAR(66) PRIMARY KEY, + block_number BIGINT NOT NULL, + parent_hash VARCHAR(66) NOT NULL, + cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + td NUMERIC NOT NULL, + node_id INTEGER NOT NULL REFERENCES nodes (id) ON DELETE CASCADE, + reward NUMERIC NOT NULL, + state_root VARCHAR(66) NOT NULL, + tx_root VARCHAR(66) NOT NULL, + receipt_root VARCHAR(66) NOT NULL, + uncle_root VARCHAR(66) NOT NULL, + bloom BYTEA NOT NULL, + timestamp NUMERIC NOT NULL, + times_validated INTEGER NOT NULL DEFAULT 1, + base_fee BIGINT ); -- +goose Down -DROP TABLE eth.header_cids; \ No newline at end of file +DROP TABLE eth.header_cids; diff --git a/db/migrations/00005_create_eth_uncle_cids_table.sql b/db/migrations/00005_create_eth_uncle_cids_table.sql index c46cafb..d173fa3 100644 --- a/db/migrations/00005_create_eth_uncle_cids_table.sql +++ b/db/migrations/00005_create_eth_uncle_cids_table.sql @@ -1,14 +1,12 @@ -- +goose Up CREATE TABLE eth.uncle_cids ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES eth.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - block_hash VARCHAR(66) NOT NULL, - parent_hash VARCHAR(66) NOT NULL, - cid TEXT NOT NULL, - mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - reward NUMERIC NOT NULL, - UNIQUE (header_id, block_hash) + block_hash VARCHAR(66) PRIMARY KEY, + header_id VARCHAR(66) NOT NULL REFERENCES eth.header_cids (block_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + parent_hash VARCHAR(66) NOT NULL, + cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + reward NUMERIC NOT NULL ); -- +goose Down -DROP TABLE eth.uncle_cids; \ No newline at end of file +DROP TABLE eth.uncle_cids; diff --git a/db/migrations/00006_create_eth_transaction_cids_table.sql b/db/migrations/00006_create_eth_transaction_cids_table.sql index fc65932..918741d 100644 --- a/db/migrations/00006_create_eth_transaction_cids_table.sql +++ b/db/migrations/00006_create_eth_transaction_cids_table.sql @@ -1,16 +1,14 @@ -- +goose Up CREATE TABLE eth.transaction_cids ( - id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES eth.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - tx_hash VARCHAR(66) NOT NULL, - index INTEGER NOT NULL, - cid TEXT NOT NULL, - mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - dst VARCHAR(66) NOT NULL, - src VARCHAR(66) NOT NULL, - tx_data BYTEA, - tx_type BYTEA, - UNIQUE (header_id, tx_hash) + tx_hash VARCHAR(66) PRIMARY KEY, + header_id VARCHAR(66) NOT NULL REFERENCES eth.header_cids (block_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + index INTEGER NOT NULL, + cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + dst VARCHAR(66) NOT NULL, + src VARCHAR(66) NOT NULL, + tx_data BYTEA, + tx_type INTEGER ); -- +goose Down diff --git a/db/migrations/00007_create_eth_receipt_cids_table.sql b/db/migrations/00007_create_eth_receipt_cids_table.sql index ee1cc35..ac11da5 100644 --- a/db/migrations/00007_create_eth_receipt_cids_table.sql +++ b/db/migrations/00007_create_eth_receipt_cids_table.sql @@ -1,16 +1,14 @@ -- +goose Up CREATE TABLE eth.receipt_cids ( - id SERIAL PRIMARY KEY, - tx_id INTEGER NOT NULL REFERENCES eth.transaction_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - leaf_cid TEXT NOT NULL, - leaf_mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - contract VARCHAR(66), - contract_hash VARCHAR(66), - post_state VARCHAR(66), - post_status INTEGER, - log_root VARCHAR(66), - UNIQUE (tx_id) + tx_id VARCHAR(66) PRIMARY KEY REFERENCES eth.transaction_cids (tx_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + leaf_cid TEXT NOT NULL, + leaf_mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + contract VARCHAR(66), + contract_hash VARCHAR(66), + post_state VARCHAR(66), + post_status INTEGER, + log_root VARCHAR(66) ); -- +goose Down -DROP TABLE eth.receipt_cids; \ No newline at end of file +DROP TABLE eth.receipt_cids; diff --git a/db/migrations/00008_create_eth_state_cids_table.sql b/db/migrations/00008_create_eth_state_cids_table.sql index ccece96..b075db0 100644 --- a/db/migrations/00008_create_eth_state_cids_table.sql +++ b/db/migrations/00008_create_eth_state_cids_table.sql @@ -1,15 +1,14 @@ -- +goose Up CREATE TABLE eth.state_cids ( - id BIGSERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES eth.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - state_leaf_key VARCHAR(66), - cid TEXT NOT NULL, - mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - state_path BYTEA, - node_type INTEGER NOT NULL, - diff BOOLEAN NOT NULL DEFAULT FALSE, - UNIQUE (header_id, state_path) + header_id VARCHAR(66) NOT NULL REFERENCES eth.header_cids (block_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + state_leaf_key VARCHAR(66), + cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + state_path BYTEA NOT NULL, + node_type INTEGER NOT NULL, + diff BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY (header_id, state_path) ); -- +goose Down -DROP TABLE eth.state_cids; \ No newline at end of file +DROP TABLE eth.state_cids; diff --git a/db/migrations/00009_create_eth_storage_cids_table.sql b/db/migrations/00009_create_eth_storage_cids_table.sql index 954fb46..8179eb2 100644 --- a/db/migrations/00009_create_eth_storage_cids_table.sql +++ b/db/migrations/00009_create_eth_storage_cids_table.sql @@ -1,15 +1,16 @@ -- +goose Up CREATE TABLE eth.storage_cids ( - id BIGSERIAL PRIMARY KEY, - state_id BIGINT NOT NULL REFERENCES eth.state_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - storage_leaf_key VARCHAR(66), - cid TEXT NOT NULL, - mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - storage_path BYTEA, - node_type INTEGER NOT NULL, - diff BOOLEAN NOT NULL DEFAULT FALSE, - UNIQUE (state_id, storage_path) + header_id VARCHAR(66) NOT NULL, + state_path BYTEA NOT NULL, + storage_leaf_key VARCHAR(66), + cid TEXT NOT NULL, + mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + storage_path BYTEA NOT NULL, + node_type INTEGER NOT NULL, + diff BOOLEAN NOT NULL DEFAULT FALSE, + FOREIGN KEY (header_id, state_path) REFERENCES eth.state_cids (header_id, state_path) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + PRIMARY KEY (header_id, state_path, storage_path) ); -- +goose Down -DROP TABLE eth.storage_cids; \ No newline at end of file +DROP TABLE eth.storage_cids; diff --git a/db/migrations/00010_create_eth_state_accouts_table.sql b/db/migrations/00010_create_eth_state_accouts_table.sql index 8a7e870..17e6023 100644 --- a/db/migrations/00010_create_eth_state_accouts_table.sql +++ b/db/migrations/00010_create_eth_state_accouts_table.sql @@ -1,13 +1,14 @@ -- +goose Up CREATE TABLE eth.state_accounts ( - id SERIAL PRIMARY KEY, - state_id BIGINT NOT NULL REFERENCES eth.state_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - balance NUMERIC NOT NULL, - nonce INTEGER NOT NULL, - code_hash BYTEA NOT NULL, - storage_root VARCHAR(66) NOT NULL, - UNIQUE (state_id) + header_id VARCHAR(66) NOT NULL, + state_path BYTEA NOT NULL, + balance NUMERIC NOT NULL, + nonce INTEGER NOT NULL, + code_hash BYTEA NOT NULL, + storage_root VARCHAR(66) NOT NULL, + FOREIGN KEY (header_id, state_path) REFERENCES eth.state_cids (header_id, state_path) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + PRIMARY KEY (header_id, state_path) ); -- +goose Down -DROP TABLE eth.state_accounts; \ No newline at end of file +DROP TABLE eth.state_accounts; diff --git a/db/migrations/00011_create_eth_access_list_elements_table.sql b/db/migrations/00011_create_eth_access_list_elements_table.sql new file mode 100644 index 0000000..947c9b9 --- /dev/null +++ b/db/migrations/00011_create_eth_access_list_elements_table.sql @@ -0,0 +1,11 @@ +-- +goose Up +CREATE TABLE eth.access_list_element ( + tx_id VARCHAR(66) NOT NULL REFERENCES eth.transaction_cids (tx_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + index INTEGER NOT NULL, + address VARCHAR(66), + storage_keys VARCHAR(66)[], + PRIMARY KEY (tx_id, index) +); + +-- +goose Down +DROP TABLE eth.access_list_element; diff --git a/db/migrations/00012_create_eth_log_cids_table.sql b/db/migrations/00012_create_eth_log_cids_table.sql new file mode 100644 index 0000000..9d487cd --- /dev/null +++ b/db/migrations/00012_create_eth_log_cids_table.sql @@ -0,0 +1,18 @@ +-- +goose Up +CREATE TABLE eth.log_cids ( + rct_id VARCHAR(66) NOT NULL REFERENCES eth.receipt_cids (tx_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + leaf_cid TEXT NOT NULL, + leaf_mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + address VARCHAR(66) NOT NULL, + log_data BYTEA, + index INTEGER NOT NULL, + topic0 VARCHAR(66), + topic1 VARCHAR(66), + topic2 VARCHAR(66), + topic3 VARCHAR(66), + PRIMARY KEY (rct_id, index) +); + +-- +goose Down +-- log indexes +DROP TABLE eth.log_cids; diff --git a/db/migrations/00011_create_postgraphile_comments.sql b/db/migrations/00013_create_postgraphile_comments.sql similarity index 100% rename from db/migrations/00011_create_postgraphile_comments.sql rename to db/migrations/00013_create_postgraphile_comments.sql diff --git a/db/migrations/00013_create_cid_indexes.sql b/db/migrations/00014_create_cid_indexes.sql similarity index 66% rename from db/migrations/00013_create_cid_indexes.sql rename to db/migrations/00014_create_cid_indexes.sql index 5fd4161..454a297 100644 --- a/db/migrations/00013_create_cid_indexes.sql +++ b/db/migrations/00014_create_cid_indexes.sql @@ -1,76 +1,76 @@ -- +goose Up -- header indexes CREATE INDEX block_number_index ON eth.header_cids USING brin (block_number); - -CREATE INDEX block_hash_index ON eth.header_cids USING btree (block_hash); - CREATE INDEX header_cid_index ON eth.header_cids USING btree (cid); - CREATE INDEX header_mh_index ON eth.header_cids USING btree (mh_key); - CREATE INDEX state_root_index ON eth.header_cids USING btree (state_root); - CREATE INDEX timestamp_index ON eth.header_cids USING brin (timestamp); +-- uncle indexes +CREATE INDEX uncle_header_id_index ON eth.uncle_cids USING btree (header_id); + -- transaction indexes CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id); - -CREATE INDEX tx_hash_index ON eth.transaction_cids USING btree (tx_hash); - CREATE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid); - CREATE INDEX tx_mh_index ON eth.transaction_cids USING btree (mh_key); - CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst); - CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src); -- receipt indexes -CREATE INDEX rct_tx_id_index ON eth.receipt_cids USING btree (tx_id); - CREATE INDEX rct_leaf_cid_index ON eth.receipt_cids USING btree (leaf_cid); - CREATE INDEX rct_leaf_mh_index ON eth.receipt_cids USING btree (leaf_mh_key); - CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract); - CREATE INDEX rct_contract_hash_index ON eth.receipt_cids USING btree (contract_hash); -- state node indexes -CREATE INDEX state_header_id_index ON eth.state_cids USING btree (header_id); - CREATE INDEX state_leaf_key_index ON eth.state_cids USING btree (state_leaf_key); - CREATE INDEX state_cid_index ON eth.state_cids USING btree (cid); - CREATE INDEX state_mh_index ON eth.state_cids USING btree (mh_key); - CREATE INDEX state_path_index ON eth.state_cids USING btree (state_path); - CREATE INDEX state_node_type_index ON eth.state_cids USING btree (node_type); -- storage node indexes -CREATE INDEX storage_state_id_index ON eth.storage_cids USING btree (state_id); - +CREATE INDEX storage_state_path_index ON eth.storage_cids USING btree (state_path); CREATE INDEX storage_leaf_key_index ON eth.storage_cids USING btree (storage_leaf_key); - CREATE INDEX storage_cid_index ON eth.storage_cids USING btree (cid); - CREATE INDEX storage_mh_index ON eth.storage_cids USING btree (mh_key); - CREATE INDEX storage_path_index ON eth.storage_cids USING btree (storage_path); - CREATE INDEX storage_node_type_index ON eth.storage_cids USING btree (node_type); -- state accounts indexes -CREATE INDEX account_state_id_index ON eth.state_accounts USING btree (state_id); - +CREATE INDEX account_state_path_index ON eth.state_accounts USING btree (state_path); CREATE INDEX storage_root_index ON eth.state_accounts USING btree (storage_root); +-- access list indexes +CREATE INDEX access_list_element_address_index ON eth.access_list_element USING btree (address); +CREATE INDEX access_list_storage_keys_index ON eth.access_list_element USING gin (storage_keys); + +-- log indexes +CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key); +CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid); +CREATE INDEX log_address_index ON eth.log_cids USING btree (address); +CREATE INDEX log_topic0_index ON eth.log_cids USING btree (topic0); +CREATE INDEX log_topic1_index ON eth.log_cids USING btree (topic1); +CREATE INDEX log_topic2_index ON eth.log_cids USING btree (topic2); +CREATE INDEX log_topic3_index ON eth.log_cids USING btree (topic3); + -- +goose Down +-- log indexes +DROP INDEX eth.log_topic3_index; +DROP INDEX eth.log_topic2_index; +DROP INDEX eth.log_topic1_index; +DROP INDEX eth.log_topic0_index; +DROP INDEX eth.log_address_index; +DROP INDEX eth.log_cid_index; +DROP INDEX eth.log_mh_index; + +-- access list indexes +DROP INDEX eth.access_list_storage_keys_index; +DROP INDEX eth.access_list_element_address_index; + -- state account indexes DROP INDEX eth.storage_root_index; -DROP INDEX eth.account_state_id_index; +DROP index eth.account_state_path_index; -- storage node indexes DROP INDEX eth.storage_node_type_index; @@ -78,7 +78,7 @@ DROP INDEX eth.storage_path_index; DROP INDEX eth.storage_mh_index; DROP INDEX eth.storage_cid_index; DROP INDEX eth.storage_leaf_key_index; -DROP INDEX eth.storage_state_id_index; +DROP INDEX eth.storage_state_path_index; -- state node indexes DROP INDEX eth.state_node_type_index; @@ -86,27 +86,26 @@ DROP INDEX eth.state_path_index; DROP INDEX eth.state_mh_index; DROP INDEX eth.state_cid_index; DROP INDEX eth.state_leaf_key_index; -DROP INDEX eth.state_header_id_index; -- receipt indexes DROP INDEX eth.rct_contract_hash_index; DROP INDEX eth.rct_contract_index; DROP INDEX eth.rct_leaf_mh_index; DROP INDEX eth.rct_leaf_cid_index; -DROP INDEX eth.rct_tx_id_index; -- transaction indexes DROP INDEX eth.tx_src_index; DROP INDEX eth.tx_dst_index; DROP INDEX eth.tx_mh_index; DROP INDEX eth.tx_cid_index; -DROP INDEX eth.tx_hash_index; DROP INDEX eth.tx_header_id_index; +-- uncle indexes +DROP INDEX eth.uncle_header_id_index; + -- header indexes DROP INDEX eth.timestamp_index; DROP INDEX eth.state_root_index; DROP INDEX eth.header_mh_index; DROP INDEX eth.header_cid_index; -DROP INDEX eth.block_hash_index; -DROP INDEX eth.block_number_index; \ No newline at end of file +DROP INDEX eth.block_number_index; diff --git a/db/migrations/00015_create_access_list_table.sql b/db/migrations/00015_create_access_list_table.sql deleted file mode 100644 index 3e27a63..0000000 --- a/db/migrations/00015_create_access_list_table.sql +++ /dev/null @@ -1,15 +0,0 @@ --- +goose Up -CREATE TABLE eth.access_list_element ( - id SERIAL PRIMARY KEY, - tx_id INTEGER NOT NULL REFERENCES eth.transaction_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - index INTEGER NOT NULL, - address VARCHAR(66), - storage_keys VARCHAR(66)[], - UNIQUE (tx_id, index) -); - -CREATE INDEX accesss_list_element_address_index ON eth.access_list_element USING btree (address); - --- +goose Down -DROP INDEX eth.accesss_list_element_address_index; -DROP TABLE eth.access_list_element; diff --git a/db/migrations/00012_potgraphile_triggers.sql b/db/migrations/00015_potgraphile_triggers.sql similarity index 100% rename from db/migrations/00012_potgraphile_triggers.sql rename to db/migrations/00015_potgraphile_triggers.sql diff --git a/db/migrations/00016_create_eth_log_cids_table.sql b/db/migrations/00016_create_eth_log_cids_table.sql deleted file mode 100644 index 85de978..0000000 --- a/db/migrations/00016_create_eth_log_cids_table.sql +++ /dev/null @@ -1,61 +0,0 @@ --- +goose Up -CREATE TABLE eth.log_cids ( - id SERIAL PRIMARY KEY, - leaf_cid TEXT NOT NULL, - leaf_mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - receipt_id INTEGER NOT NULL REFERENCES eth.receipt_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - address VARCHAR(66) NOT NULL, - log_data BYTEA, - index INTEGER NOT NULL, - topic0 VARCHAR(66), - topic1 VARCHAR(66), - topic2 VARCHAR(66), - topic3 VARCHAR(66), - UNIQUE (receipt_id, index) -); - -CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key); - -CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid); - -CREATE INDEX log_rct_id_index ON eth.log_cids USING btree (receipt_id); - --- --- Name: log_topic0_index; Type: INDEX; Schema: eth; Owner: - --- - -CREATE INDEX log_topic0_index ON eth.log_cids USING btree (topic0); - - --- --- Name: log_topic1_index; Type: INDEX; Schema: eth; Owner: - --- - -CREATE INDEX log_topic1_index ON eth.log_cids USING btree (topic1); - - --- --- Name: log_topic2_index; Type: INDEX; Schema: eth; Owner: - --- - -CREATE INDEX log_topic2_index ON eth.log_cids USING btree (topic2); - - --- --- Name: log_topic3_index; Type: INDEX; Schema: eth; Owner: - --- - -CREATE INDEX log_topic3_index ON eth.log_cids USING btree (topic3); - - --- +goose Down --- log indexes -DROP INDEX eth.log_mh_index; -DROP INDEX eth.log_cid_index; -DROP INDEX eth.log_rct_id_index; -DROP INDEX eth.log_topic0_index; -DROP INDEX eth.log_topic1_index; -DROP INDEX eth.log_topic2_index; -DROP INDEX eth.log_topic3_index; - -DROP TABLE eth.log_cids; diff --git a/db/migrations/00014_create_stored_functions.sql b/db/migrations/00016_create_stored_functions.sql similarity index 98% rename from db/migrations/00014_create_stored_functions.sql rename to db/migrations/00016_create_stored_functions.sql index cdf579c..1198052 100644 --- a/db/migrations/00014_create_stored_functions.sql +++ b/db/migrations/00016_create_stored_functions.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE FUNCTION was_state_leaf_removed(key character varying, hash ch RETURNS boolean AS $$ SELECT state_cids.node_type = 3 FROM eth.state_cids - INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id) + INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.block_hash) WHERE state_leaf_key = key AND block_number <= (SELECT block_number FROM eth.header_cids @@ -135,4 +135,4 @@ DROP FUNCTION was_state_leaf_removed; DROP FUNCTION canonical_header_id; DROP FUNCTION canonical_header_from_array; DROP FUNCTION has_child; -DROP TYPE child_result; \ No newline at end of file +DROP TYPE child_result; diff --git a/schema.sql b/schema.sql index d23164d..c864dae 100644 --- a/schema.sql +++ b/schema.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 10.12 --- Dumped by pg_dump version 14.0 (Ubuntu 14.0-1.pgdg20.04+1) +-- Dumped from database version 14beta3 +-- Dumped by pg_dump version 14beta3 SET statement_timeout = 0; SET lock_timeout = 0; @@ -25,14 +25,15 @@ CREATE SCHEMA eth; SET default_tablespace = ''; +SET default_table_access_method = heap; + -- -- Name: header_cids; Type: TABLE; Schema: eth; Owner: - -- CREATE TABLE eth.header_cids ( - id integer NOT NULL, - block_number bigint NOT NULL, block_hash character varying(66) NOT NULL, + block_number bigint NOT NULL, parent_hash character varying(66) NOT NULL, cid text NOT NULL, mh_key text NOT NULL, @@ -230,7 +231,7 @@ CREATE FUNCTION public.was_state_leaf_removed(key character varying, hash charac AS $$ SELECT state_cids.node_type = 3 FROM eth.state_cids - INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id) + INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.block_hash) WHERE state_leaf_key = key AND block_number <= (SELECT block_number FROM eth.header_cids @@ -244,63 +245,21 @@ $$; -- CREATE TABLE eth.access_list_element ( - id integer NOT NULL, - tx_id integer NOT NULL, + tx_id character varying(66) NOT NULL, index integer NOT NULL, address character varying(66), storage_keys character varying(66)[] ); --- --- Name: access_list_element_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.access_list_element_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: access_list_element_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.access_list_element_id_seq OWNED BY eth.access_list_element.id; - - --- --- Name: header_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.header_cids_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: header_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.header_cids_id_seq OWNED BY eth.header_cids.id; - - -- -- Name: log_cids; Type: TABLE; Schema: eth; Owner: - -- CREATE TABLE eth.log_cids ( - id integer NOT NULL, + rct_id character varying(66) NOT NULL, leaf_cid text NOT NULL, leaf_mh_key text NOT NULL, - receipt_id integer NOT NULL, address character varying(66) NOT NULL, log_data bytea, index integer NOT NULL, @@ -311,33 +270,12 @@ CREATE TABLE eth.log_cids ( ); --- --- Name: log_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.log_cids_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: log_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.log_cids_id_seq OWNED BY eth.log_cids.id; - - -- -- Name: receipt_cids; Type: TABLE; Schema: eth; Owner: - -- CREATE TABLE eth.receipt_cids ( - id integer NOT NULL, - tx_id integer NOT NULL, + tx_id character varying(66) NOT NULL, leaf_cid text NOT NULL, leaf_mh_key text NOT NULL, contract character varying(66), @@ -348,33 +286,13 @@ CREATE TABLE eth.receipt_cids ( ); --- --- Name: receipt_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.receipt_cids_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: receipt_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.receipt_cids_id_seq OWNED BY eth.receipt_cids.id; - - -- -- Name: state_accounts; Type: TABLE; Schema: eth; Owner: - -- CREATE TABLE eth.state_accounts ( - id integer NOT NULL, - state_id bigint NOT NULL, + header_id character varying(66) NOT NULL, + state_path bytea NOT NULL, balance numeric NOT NULL, nonce integer NOT NULL, code_hash bytea NOT NULL, @@ -382,111 +300,51 @@ CREATE TABLE eth.state_accounts ( ); --- --- Name: state_accounts_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.state_accounts_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: state_accounts_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.state_accounts_id_seq OWNED BY eth.state_accounts.id; - - -- -- Name: state_cids; Type: TABLE; Schema: eth; Owner: - -- CREATE TABLE eth.state_cids ( - id bigint NOT NULL, - header_id integer NOT NULL, + header_id character varying(66) NOT NULL, state_leaf_key character varying(66), cid text NOT NULL, mh_key text NOT NULL, - state_path bytea, + state_path bytea NOT NULL, node_type integer NOT NULL, diff boolean DEFAULT false NOT NULL ); --- --- Name: state_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.state_cids_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: state_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.state_cids_id_seq OWNED BY eth.state_cids.id; - - -- -- Name: storage_cids; Type: TABLE; Schema: eth; Owner: - -- CREATE TABLE eth.storage_cids ( - id bigint NOT NULL, - state_id bigint NOT NULL, + header_id character varying(66) NOT NULL, + state_path bytea NOT NULL, storage_leaf_key character varying(66), cid text NOT NULL, mh_key text NOT NULL, - storage_path bytea, + storage_path bytea NOT NULL, node_type integer NOT NULL, diff boolean DEFAULT false NOT NULL ); --- --- Name: storage_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.storage_cids_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: storage_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.storage_cids_id_seq OWNED BY eth.storage_cids.id; - - -- -- Name: transaction_cids; Type: TABLE; Schema: eth; Owner: - -- CREATE TABLE eth.transaction_cids ( - id integer NOT NULL, - header_id integer NOT NULL, tx_hash character varying(66) NOT NULL, + header_id character varying(66) NOT NULL, index integer NOT NULL, cid text NOT NULL, mh_key text NOT NULL, dst character varying(66) NOT NULL, src character varying(66) NOT NULL, tx_data bytea, - tx_type bytea + tx_type integer ); @@ -497,34 +355,13 @@ CREATE TABLE eth.transaction_cids ( COMMENT ON TABLE eth.transaction_cids IS '@name EthTransactionCids'; --- --- Name: transaction_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.transaction_cids_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: transaction_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.transaction_cids_id_seq OWNED BY eth.transaction_cids.id; - - -- -- Name: uncle_cids; Type: TABLE; Schema: eth; Owner: - -- CREATE TABLE eth.uncle_cids ( - id integer NOT NULL, - header_id integer NOT NULL, block_hash character varying(66) NOT NULL, + header_id character varying(66) NOT NULL, parent_hash character varying(66) NOT NULL, cid text NOT NULL, mh_key text NOT NULL, @@ -532,26 +369,6 @@ CREATE TABLE eth.uncle_cids ( ); --- --- Name: uncle_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: - --- - -CREATE SEQUENCE eth.uncle_cids_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: uncle_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: - --- - -ALTER SEQUENCE eth.uncle_cids_id_seq OWNED BY eth.uncle_cids.id; - - -- -- Name: blocks; Type: TABLE; Schema: public; Owner: - -- @@ -642,69 +459,6 @@ CREATE SEQUENCE public.nodes_id_seq ALTER SEQUENCE public.nodes_id_seq OWNED BY public.nodes.id; --- --- Name: access_list_element id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.access_list_element ALTER COLUMN id SET DEFAULT nextval('eth.access_list_element_id_seq'::regclass); - - --- --- Name: header_cids id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.header_cids ALTER COLUMN id SET DEFAULT nextval('eth.header_cids_id_seq'::regclass); - - --- --- Name: log_cids id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.log_cids ALTER COLUMN id SET DEFAULT nextval('eth.log_cids_id_seq'::regclass); - - --- --- Name: receipt_cids id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.receipt_cids ALTER COLUMN id SET DEFAULT nextval('eth.receipt_cids_id_seq'::regclass); - - --- --- Name: state_accounts id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.state_accounts ALTER COLUMN id SET DEFAULT nextval('eth.state_accounts_id_seq'::regclass); - - --- --- Name: state_cids id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.state_cids ALTER COLUMN id SET DEFAULT nextval('eth.state_cids_id_seq'::regclass); - - --- --- Name: storage_cids id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.storage_cids ALTER COLUMN id SET DEFAULT nextval('eth.storage_cids_id_seq'::regclass); - - --- --- Name: transaction_cids id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.transaction_cids ALTER COLUMN id SET DEFAULT nextval('eth.transaction_cids_id_seq'::regclass); - - --- --- Name: uncle_cids id; Type: DEFAULT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.uncle_cids ALTER COLUMN id SET DEFAULT nextval('eth.uncle_cids_id_seq'::regclass); - - -- -- Name: goose_db_version id; Type: DEFAULT; Schema: public; Owner: - -- @@ -724,23 +478,7 @@ ALTER TABLE ONLY public.nodes ALTER COLUMN id SET DEFAULT nextval('public.nodes_ -- ALTER TABLE ONLY eth.access_list_element - ADD CONSTRAINT access_list_element_pkey PRIMARY KEY (id); - - --- --- Name: access_list_element access_list_element_tx_id_index_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.access_list_element - ADD CONSTRAINT access_list_element_tx_id_index_key UNIQUE (tx_id, index); - - --- --- Name: header_cids header_cids_block_number_block_hash_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.header_cids - ADD CONSTRAINT header_cids_block_number_block_hash_key UNIQUE (block_number, block_hash); + ADD CONSTRAINT access_list_element_pkey PRIMARY KEY (tx_id, index); -- @@ -748,7 +486,7 @@ ALTER TABLE ONLY eth.header_cids -- ALTER TABLE ONLY eth.header_cids - ADD CONSTRAINT header_cids_pkey PRIMARY KEY (id); + ADD CONSTRAINT header_cids_pkey PRIMARY KEY (block_hash); -- @@ -756,15 +494,7 @@ ALTER TABLE ONLY eth.header_cids -- ALTER TABLE ONLY eth.log_cids - ADD CONSTRAINT log_cids_pkey PRIMARY KEY (id); - - --- --- Name: log_cids log_cids_receipt_id_index_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.log_cids - ADD CONSTRAINT log_cids_receipt_id_index_key UNIQUE (receipt_id, index); + ADD CONSTRAINT log_cids_pkey PRIMARY KEY (rct_id, index); -- @@ -772,15 +502,7 @@ ALTER TABLE ONLY eth.log_cids -- ALTER TABLE ONLY eth.receipt_cids - ADD CONSTRAINT receipt_cids_pkey PRIMARY KEY (id); - - --- --- Name: receipt_cids receipt_cids_tx_id_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.receipt_cids - ADD CONSTRAINT receipt_cids_tx_id_key UNIQUE (tx_id); + ADD CONSTRAINT receipt_cids_pkey PRIMARY KEY (tx_id); -- @@ -788,23 +510,7 @@ ALTER TABLE ONLY eth.receipt_cids -- ALTER TABLE ONLY eth.state_accounts - ADD CONSTRAINT state_accounts_pkey PRIMARY KEY (id); - - --- --- Name: state_accounts state_accounts_state_id_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.state_accounts - ADD CONSTRAINT state_accounts_state_id_key UNIQUE (state_id); - - --- --- Name: state_cids state_cids_header_id_state_path_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.state_cids - ADD CONSTRAINT state_cids_header_id_state_path_key UNIQUE (header_id, state_path); + ADD CONSTRAINT state_accounts_pkey PRIMARY KEY (header_id, state_path); -- @@ -812,7 +518,7 @@ ALTER TABLE ONLY eth.state_cids -- ALTER TABLE ONLY eth.state_cids - ADD CONSTRAINT state_cids_pkey PRIMARY KEY (id); + ADD CONSTRAINT state_cids_pkey PRIMARY KEY (header_id, state_path); -- @@ -820,23 +526,7 @@ ALTER TABLE ONLY eth.state_cids -- ALTER TABLE ONLY eth.storage_cids - ADD CONSTRAINT storage_cids_pkey PRIMARY KEY (id); - - --- --- Name: storage_cids storage_cids_state_id_storage_path_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.storage_cids - ADD CONSTRAINT storage_cids_state_id_storage_path_key UNIQUE (state_id, storage_path); - - --- --- Name: transaction_cids transaction_cids_header_id_tx_hash_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.transaction_cids - ADD CONSTRAINT transaction_cids_header_id_tx_hash_key UNIQUE (header_id, tx_hash); + ADD CONSTRAINT storage_cids_pkey PRIMARY KEY (header_id, state_path, storage_path); -- @@ -844,15 +534,7 @@ ALTER TABLE ONLY eth.transaction_cids -- ALTER TABLE ONLY eth.transaction_cids - ADD CONSTRAINT transaction_cids_pkey PRIMARY KEY (id); - - --- --- Name: uncle_cids uncle_cids_header_id_block_hash_key; Type: CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.uncle_cids - ADD CONSTRAINT uncle_cids_header_id_block_hash_key UNIQUE (header_id, block_hash); + ADD CONSTRAINT transaction_cids_pkey PRIMARY KEY (tx_hash); -- @@ -860,15 +542,15 @@ ALTER TABLE ONLY eth.uncle_cids -- ALTER TABLE ONLY eth.uncle_cids - ADD CONSTRAINT uncle_cids_pkey PRIMARY KEY (id); + ADD CONSTRAINT uncle_cids_pkey PRIMARY KEY (block_hash); -- --- Name: blocks blocks_key_key; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: blocks blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.blocks - ADD CONSTRAINT blocks_key_key UNIQUE (key); + ADD CONSTRAINT blocks_pkey PRIMARY KEY (key); -- @@ -896,24 +578,24 @@ ALTER TABLE ONLY public.nodes -- --- Name: accesss_list_element_address_index; Type: INDEX; Schema: eth; Owner: - +-- Name: access_list_element_address_index; Type: INDEX; Schema: eth; Owner: - -- -CREATE INDEX accesss_list_element_address_index ON eth.access_list_element USING btree (address); +CREATE INDEX access_list_element_address_index ON eth.access_list_element USING btree (address); -- --- Name: account_state_id_index; Type: INDEX; Schema: eth; Owner: - +-- Name: access_list_storage_keys_index; Type: INDEX; Schema: eth; Owner: - -- -CREATE INDEX account_state_id_index ON eth.state_accounts USING btree (state_id); +CREATE INDEX access_list_storage_keys_index ON eth.access_list_element USING gin (storage_keys); -- --- Name: block_hash_index; Type: INDEX; Schema: eth; Owner: - +-- Name: account_state_path_index; Type: INDEX; Schema: eth; Owner: - -- -CREATE INDEX block_hash_index ON eth.header_cids USING btree (block_hash); +CREATE INDEX account_state_path_index ON eth.state_accounts USING btree (state_path); -- @@ -937,6 +619,13 @@ CREATE INDEX header_cid_index ON eth.header_cids USING btree (cid); CREATE INDEX header_mh_index ON eth.header_cids USING btree (mh_key); +-- +-- Name: log_address_index; Type: INDEX; Schema: eth; Owner: - +-- + +CREATE INDEX log_address_index ON eth.log_cids USING btree (address); + + -- -- Name: log_cid_index; Type: INDEX; Schema: eth; Owner: - -- @@ -951,13 +640,6 @@ CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid); CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key); --- --- Name: log_rct_id_index; Type: INDEX; Schema: eth; Owner: - --- - -CREATE INDEX log_rct_id_index ON eth.log_cids USING btree (receipt_id); - - -- -- Name: log_topic0_index; Type: INDEX; Schema: eth; Owner: - -- @@ -1014,13 +696,6 @@ CREATE INDEX rct_leaf_cid_index ON eth.receipt_cids USING btree (leaf_cid); CREATE INDEX rct_leaf_mh_index ON eth.receipt_cids USING btree (leaf_mh_key); --- --- Name: rct_tx_id_index; Type: INDEX; Schema: eth; Owner: - --- - -CREATE INDEX rct_tx_id_index ON eth.receipt_cids USING btree (tx_id); - - -- -- Name: state_cid_index; Type: INDEX; Schema: eth; Owner: - -- @@ -1028,13 +703,6 @@ CREATE INDEX rct_tx_id_index ON eth.receipt_cids USING btree (tx_id); CREATE INDEX state_cid_index ON eth.state_cids USING btree (cid); --- --- Name: state_header_id_index; Type: INDEX; Schema: eth; Owner: - --- - -CREATE INDEX state_header_id_index ON eth.state_cids USING btree (header_id); - - -- -- Name: state_leaf_key_index; Type: INDEX; Schema: eth; Owner: - -- @@ -1113,10 +781,10 @@ CREATE INDEX storage_root_index ON eth.state_accounts USING btree (storage_root) -- --- Name: storage_state_id_index; Type: INDEX; Schema: eth; Owner: - +-- Name: storage_state_path_index; Type: INDEX; Schema: eth; Owner: - -- -CREATE INDEX storage_state_id_index ON eth.storage_cids USING btree (state_id); +CREATE INDEX storage_state_path_index ON eth.storage_cids USING btree (state_path); -- @@ -1140,13 +808,6 @@ CREATE INDEX tx_cid_index ON eth.transaction_cids USING btree (cid); CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst); --- --- Name: tx_hash_index; Type: INDEX; Schema: eth; Owner: - --- - -CREATE INDEX tx_hash_index ON eth.transaction_cids USING btree (tx_hash); - - -- -- Name: tx_header_id_index; Type: INDEX; Schema: eth; Owner: - -- @@ -1168,53 +829,60 @@ CREATE INDEX tx_mh_index ON eth.transaction_cids USING btree (mh_key); CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src); +-- +-- Name: uncle_header_id_index; Type: INDEX; Schema: eth; Owner: - +-- + +CREATE INDEX uncle_header_id_index ON eth.uncle_cids USING btree (header_id); + + -- -- Name: header_cids header_cids_ai; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER header_cids_ai AFTER INSERT ON eth.header_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription('header_cids', 'id'); +CREATE TRIGGER header_cids_ai AFTER INSERT ON eth.header_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription('header_cids', 'id'); -- -- Name: receipt_cids receipt_cids_ai; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER receipt_cids_ai AFTER INSERT ON eth.receipt_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription('receipt_cids', 'id'); +CREATE TRIGGER receipt_cids_ai AFTER INSERT ON eth.receipt_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription('receipt_cids', 'id'); -- -- Name: state_accounts state_accounts_ai; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER state_accounts_ai AFTER INSERT ON eth.state_accounts FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription('state_accounts', 'id'); +CREATE TRIGGER state_accounts_ai AFTER INSERT ON eth.state_accounts FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription('state_accounts', 'id'); -- -- Name: state_cids state_cids_ai; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER state_cids_ai AFTER INSERT ON eth.state_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription('state_cids', 'id'); +CREATE TRIGGER state_cids_ai AFTER INSERT ON eth.state_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription('state_cids', 'id'); -- -- Name: storage_cids storage_cids_ai; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER storage_cids_ai AFTER INSERT ON eth.storage_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription('storage_cids', 'id'); +CREATE TRIGGER storage_cids_ai AFTER INSERT ON eth.storage_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription('storage_cids', 'id'); -- -- Name: transaction_cids transaction_cids_ai; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER transaction_cids_ai AFTER INSERT ON eth.transaction_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription('transaction_cids', 'id'); +CREATE TRIGGER transaction_cids_ai AFTER INSERT ON eth.transaction_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription('transaction_cids', 'id'); -- -- Name: uncle_cids uncle_cids_ai; Type: TRIGGER; Schema: eth; Owner: - -- -CREATE TRIGGER uncle_cids_ai AFTER INSERT ON eth.uncle_cids FOR EACH ROW EXECUTE PROCEDURE eth.graphql_subscription('uncle_cids', 'id'); +CREATE TRIGGER uncle_cids_ai AFTER INSERT ON eth.uncle_cids FOR EACH ROW EXECUTE FUNCTION eth.graphql_subscription('uncle_cids', 'id'); -- @@ -1222,7 +890,7 @@ CREATE TRIGGER uncle_cids_ai AFTER INSERT ON eth.uncle_cids FOR EACH ROW EXECUTE -- ALTER TABLE ONLY eth.access_list_element - ADD CONSTRAINT access_list_element_tx_id_fkey FOREIGN KEY (tx_id) REFERENCES eth.transaction_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + ADD CONSTRAINT access_list_element_tx_id_fkey FOREIGN KEY (tx_id) REFERENCES eth.transaction_cids(tx_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -- @@ -1250,11 +918,11 @@ ALTER TABLE ONLY eth.log_cids -- --- Name: log_cids log_cids_receipt_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- Name: log_cids log_cids_rct_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- ALTER TABLE ONLY eth.log_cids - ADD CONSTRAINT log_cids_receipt_id_fkey FOREIGN KEY (receipt_id) REFERENCES eth.receipt_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + ADD CONSTRAINT log_cids_rct_id_fkey FOREIGN KEY (rct_id) REFERENCES eth.receipt_cids(tx_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -- @@ -1270,15 +938,15 @@ ALTER TABLE ONLY eth.receipt_cids -- ALTER TABLE ONLY eth.receipt_cids - ADD CONSTRAINT receipt_cids_tx_id_fkey FOREIGN KEY (tx_id) REFERENCES eth.transaction_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + ADD CONSTRAINT receipt_cids_tx_id_fkey FOREIGN KEY (tx_id) REFERENCES eth.transaction_cids(tx_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -- --- Name: state_accounts state_accounts_state_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- Name: state_accounts state_accounts_header_id_state_path_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- ALTER TABLE ONLY eth.state_accounts - ADD CONSTRAINT state_accounts_state_id_fkey FOREIGN KEY (state_id) REFERENCES eth.state_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + ADD CONSTRAINT state_accounts_header_id_state_path_fkey FOREIGN KEY (header_id, state_path) REFERENCES eth.state_cids(header_id, state_path) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -- @@ -1286,7 +954,7 @@ ALTER TABLE ONLY eth.state_accounts -- ALTER TABLE ONLY eth.state_cids - ADD CONSTRAINT state_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES eth.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + ADD CONSTRAINT state_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES eth.header_cids(block_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -- @@ -1297,6 +965,14 @@ ALTER TABLE ONLY eth.state_cids ADD CONSTRAINT state_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; +-- +-- Name: storage_cids storage_cids_header_id_state_path_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.storage_cids + ADD CONSTRAINT storage_cids_header_id_state_path_fkey FOREIGN KEY (header_id, state_path) REFERENCES eth.state_cids(header_id, state_path) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + + -- -- Name: storage_cids storage_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- @@ -1305,20 +981,12 @@ ALTER TABLE ONLY eth.storage_cids ADD CONSTRAINT storage_cids_mh_key_fkey FOREIGN KEY (mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; --- --- Name: storage_cids storage_cids_state_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - --- - -ALTER TABLE ONLY eth.storage_cids - ADD CONSTRAINT storage_cids_state_id_fkey FOREIGN KEY (state_id) REFERENCES eth.state_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; - - -- -- Name: transaction_cids transaction_cids_header_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - -- ALTER TABLE ONLY eth.transaction_cids - ADD CONSTRAINT transaction_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES eth.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + ADD CONSTRAINT transaction_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES eth.header_cids(block_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -- @@ -1334,7 +1002,7 @@ ALTER TABLE ONLY eth.transaction_cids -- ALTER TABLE ONLY eth.uncle_cids - ADD CONSTRAINT uncle_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES eth.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; + ADD CONSTRAINT uncle_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES eth.header_cids(block_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; -- diff --git a/vulcanize_db.png b/vulcanize_db.png index 13a6c49..a01a0a1 100644 Binary files a/vulcanize_db.png and b/vulcanize_db.png differ diff --git a/vulcanize_db.uml b/vulcanize_db.uml index 83e029b..61a3df5 100644 --- a/vulcanize_db.uml +++ b/vulcanize_db.uml @@ -1,150 +1,148 @@ DATABASE - 763cb2dc-728a-4fbd-a163-94dd564429aa + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.eth.receipt_cids - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.eth.log_cids - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.eth.state_accounts - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.eth.state_cids - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.public.blocks - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.eth.storage_cids - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.eth.uncle_cids - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.public.goose_db_version - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.public.nodes - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.eth.access_list_element - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.eth.header_cids - 763cb2dc-728a-4fbd-a163-94dd564429aa.TABLE:vulcanize_testing.eth.transaction_cids + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.public.blocks + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.eth.log_cids + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.eth.receipt_cids + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.eth.header_cids + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.eth.storage_cids + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.eth.state_cids + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.eth.access_list_element + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.eth.state_accounts + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.eth.transaction_cids + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.eth.uncle_cids + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.public.goose_db_version + 7d32edb9-2bc3-46e6-9f18-0d9158833b0d.TABLE:new_vulcanize_test.public.nodes - - - - - - + + + + + + + + + - - - - - + + + + + - - - - - - - - - + + + + + + + + + - + - - - + + + - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + Columns