From 9018e551baf00df44cab4a7d1b1a2efea040a69c Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Fri, 31 Jan 2020 13:25:15 -0600 Subject: [PATCH] move eth tables under eth schema --- db/migrations/00032_create_eth_schema.sql | 5 + ...=> 00033_create_eth_header_cids_table.sql} | 4 +- ... => 00034_create_eth_uncle_cids_table.sql} | 6 +- ...035_create_eth_transaction_cids_table.sql} | 6 +- ...> 00036_create_eth_receipt_cids_table.sql} | 6 +- ... => 00037_create_eth_state_cids_table.sql} | 6 +- ...> 00038_create_eth_storage_cids_table.sql} | 6 +- ...sql => 00039_create_ipfs_blocks_table.sql} | 0 db/schema.sql | 762 +++++++++--------- pkg/super_node/eth/indexer.go | 12 +- pkg/super_node/eth/indexer_test.go | 10 +- pkg/super_node/eth/retriever.go | 32 +- pkg/super_node/eth/test_helpers.go | 10 +- 13 files changed, 442 insertions(+), 423 deletions(-) create mode 100644 db/migrations/00032_create_eth_schema.sql rename db/migrations/{00032_create_header_cids_table.sql => 00033_create_eth_header_cids_table.sql} (83%) rename db/migrations/{00033_create_uncle_cids_table.sql => 00034_create_eth_uncle_cids_table.sql} (57%) rename db/migrations/{00034_create_transaction_cids_table.sql => 00035_create_eth_transaction_cids_table.sql} (62%) rename db/migrations/{00035_create_receipt_cids_table.sql => 00036_create_eth_receipt_cids_table.sql} (61%) rename db/migrations/{00036_create_state_cids_table.sql => 00037_create_eth_state_cids_table.sql} (56%) rename db/migrations/{00037_create_storage_cids_table.sql => 00038_create_eth_storage_cids_table.sql} (56%) rename db/migrations/{00038_create_ipfs_blocks_table.sql => 00039_create_ipfs_blocks_table.sql} (100%) diff --git a/db/migrations/00032_create_eth_schema.sql b/db/migrations/00032_create_eth_schema.sql new file mode 100644 index 00000000..84d6f4b6 --- /dev/null +++ b/db/migrations/00032_create_eth_schema.sql @@ -0,0 +1,5 @@ +-- +goose Up +CREATE SCHEMA eth; + +-- +goose Down +DROP SCHEMA eth; \ No newline at end of file diff --git a/db/migrations/00032_create_header_cids_table.sql b/db/migrations/00033_create_eth_header_cids_table.sql similarity index 83% rename from db/migrations/00032_create_header_cids_table.sql rename to db/migrations/00033_create_eth_header_cids_table.sql index 6f90cf50..cf7f42f9 100644 --- a/db/migrations/00032_create_header_cids_table.sql +++ b/db/migrations/00033_create_eth_header_cids_table.sql @@ -1,5 +1,5 @@ -- +goose Up -CREATE TABLE public.header_cids ( +CREATE TABLE eth.header_cids ( id SERIAL PRIMARY KEY, block_number BIGINT NOT NULL, block_hash VARCHAR(66) NOT NULL, @@ -10,4 +10,4 @@ CREATE TABLE public.header_cids ( ); -- +goose Down -DROP TABLE public.header_cids; \ No newline at end of file +DROP TABLE eth.header_cids; \ No newline at end of file diff --git a/db/migrations/00033_create_uncle_cids_table.sql b/db/migrations/00034_create_eth_uncle_cids_table.sql similarity index 57% rename from db/migrations/00033_create_uncle_cids_table.sql rename to db/migrations/00034_create_eth_uncle_cids_table.sql index 4ff9db19..d79976df 100644 --- a/db/migrations/00033_create_uncle_cids_table.sql +++ b/db/migrations/00034_create_eth_uncle_cids_table.sql @@ -1,7 +1,7 @@ -- +goose Up -CREATE TABLE public.uncle_cids ( +CREATE TABLE eth.uncle_cids ( id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + 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, @@ -9,4 +9,4 @@ CREATE TABLE public.uncle_cids ( ); -- +goose Down -DROP TABLE public.uncle_cids; \ No newline at end of file +DROP TABLE eth.uncle_cids; \ No newline at end of file diff --git a/db/migrations/00034_create_transaction_cids_table.sql b/db/migrations/00035_create_eth_transaction_cids_table.sql similarity index 62% rename from db/migrations/00034_create_transaction_cids_table.sql rename to db/migrations/00035_create_eth_transaction_cids_table.sql index 634a42ff..e3750ced 100644 --- a/db/migrations/00034_create_transaction_cids_table.sql +++ b/db/migrations/00035_create_eth_transaction_cids_table.sql @@ -1,7 +1,7 @@ -- +goose Up -CREATE TABLE public.transaction_cids ( +CREATE TABLE eth.transaction_cids ( id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + 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, @@ -11,4 +11,4 @@ CREATE TABLE public.transaction_cids ( ); -- +goose Down -DROP TABLE public.transaction_cids; +DROP TABLE eth.transaction_cids; diff --git a/db/migrations/00035_create_receipt_cids_table.sql b/db/migrations/00036_create_eth_receipt_cids_table.sql similarity index 61% rename from db/migrations/00035_create_receipt_cids_table.sql rename to db/migrations/00036_create_eth_receipt_cids_table.sql index 4015e3b0..a8f77de0 100644 --- a/db/migrations/00035_create_receipt_cids_table.sql +++ b/db/migrations/00036_create_eth_receipt_cids_table.sql @@ -1,7 +1,7 @@ -- +goose Up -CREATE TABLE public.receipt_cids ( +CREATE TABLE eth.receipt_cids ( id SERIAL PRIMARY KEY, - tx_id INTEGER NOT NULL REFERENCES transaction_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + tx_id INTEGER NOT NULL REFERENCES eth.transaction_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, cid TEXT NOT NULL, contract VARCHAR(66), topic0s VARCHAR(66)[], @@ -11,4 +11,4 @@ CREATE TABLE public.receipt_cids ( ); -- +goose Down -DROP TABLE public.receipt_cids; \ No newline at end of file +DROP TABLE eth.receipt_cids; \ No newline at end of file diff --git a/db/migrations/00036_create_state_cids_table.sql b/db/migrations/00037_create_eth_state_cids_table.sql similarity index 56% rename from db/migrations/00036_create_state_cids_table.sql rename to db/migrations/00037_create_eth_state_cids_table.sql index 6efce63d..6f0170a5 100644 --- a/db/migrations/00036_create_state_cids_table.sql +++ b/db/migrations/00037_create_eth_state_cids_table.sql @@ -1,7 +1,7 @@ -- +goose Up -CREATE TABLE public.state_cids ( +CREATE TABLE eth.state_cids ( id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + header_id INTEGER NOT NULL REFERENCES eth.header_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, state_key VARCHAR(66) NOT NULL, leaf BOOLEAN NOT NULL, cid TEXT NOT NULL, @@ -9,4 +9,4 @@ CREATE TABLE public.state_cids ( ); -- +goose Down -DROP TABLE public.state_cids; \ No newline at end of file +DROP TABLE eth.state_cids; \ No newline at end of file diff --git a/db/migrations/00037_create_storage_cids_table.sql b/db/migrations/00038_create_eth_storage_cids_table.sql similarity index 56% rename from db/migrations/00037_create_storage_cids_table.sql rename to db/migrations/00038_create_eth_storage_cids_table.sql index 2506be41..070eda45 100644 --- a/db/migrations/00037_create_storage_cids_table.sql +++ b/db/migrations/00038_create_eth_storage_cids_table.sql @@ -1,7 +1,7 @@ -- +goose Up -CREATE TABLE public.storage_cids ( +CREATE TABLE eth.storage_cids ( id SERIAL PRIMARY KEY, - state_id INTEGER NOT NULL REFERENCES state_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + state_id INTEGER NOT NULL REFERENCES eth.state_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, storage_key VARCHAR(66) NOT NULL, leaf BOOLEAN NOT NULL, cid TEXT NOT NULL, @@ -9,4 +9,4 @@ CREATE TABLE public.storage_cids ( ); -- +goose Down -DROP TABLE public.storage_cids; \ No newline at end of file +DROP TABLE eth.storage_cids; \ No newline at end of file diff --git a/db/migrations/00038_create_ipfs_blocks_table.sql b/db/migrations/00039_create_ipfs_blocks_table.sql similarity index 100% rename from db/migrations/00038_create_ipfs_blocks_table.sql rename to db/migrations/00039_create_ipfs_blocks_table.sql diff --git a/db/schema.sql b/db/schema.sql index 844d0368..92400f32 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -16,8 +16,226 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; +-- +-- Name: btc; Type: SCHEMA; Schema: -; Owner: - +-- + +CREATE SCHEMA btc; + + +-- +-- Name: eth; Type: SCHEMA; Schema: -; Owner: - +-- + +CREATE SCHEMA eth; + + SET default_tablespace = ''; +-- +-- 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, + parent_hash character varying(66) NOT NULL, + cid text NOT NULL, + td bigint +); + + +-- +-- 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: receipt_cids; Type: TABLE; Schema: eth; Owner: - +-- + +CREATE TABLE eth.receipt_cids ( + id integer NOT NULL, + tx_id integer NOT NULL, + cid text NOT NULL, + contract character varying(66), + topic0s character varying(66)[], + topic1s character varying(66)[], + topic2s character varying(66)[], + topic3s character varying(66)[] +); + + +-- +-- 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_cids; Type: TABLE; Schema: eth; Owner: - +-- + +CREATE TABLE eth.state_cids ( + id integer NOT NULL, + header_id integer NOT NULL, + state_key character varying(66) NOT NULL, + leaf boolean NOT NULL, + cid text NOT NULL +); + + +-- +-- Name: state_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: - +-- + +CREATE SEQUENCE eth.state_cids_id_seq + AS integer + 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 integer NOT NULL, + state_id integer NOT NULL, + storage_key character varying(66) NOT NULL, + leaf boolean NOT NULL, + cid text NOT NULL +); + + +-- +-- Name: storage_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: - +-- + +CREATE SEQUENCE eth.storage_cids_id_seq + AS integer + 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, + index integer NOT NULL, + cid text NOT NULL, + dst character varying(66) NOT NULL, + src character varying(66) NOT NULL +); + + +-- +-- 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, + parent_hash character varying(66) NOT NULL, + cid text NOT NULL +); + + +-- +-- 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: addresses; Type: TABLE; Schema: public; Owner: - -- @@ -305,40 +523,6 @@ CREATE SEQUENCE public.goose_db_version_id_seq ALTER SEQUENCE public.goose_db_version_id_seq OWNED BY public.goose_db_version.id; --- --- Name: header_cids; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.header_cids ( - id integer NOT NULL, - block_number bigint NOT NULL, - block_hash character varying(66) NOT NULL, - parent_hash character varying(66) NOT NULL, - cid text NOT NULL, - td bigint -); - - --- --- Name: header_cids_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.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: public; Owner: - --- - -ALTER SEQUENCE public.header_cids_id_seq OWNED BY public.header_cids.id; - - -- -- Name: header_sync_logs; Type: TABLE; Schema: public; Owner: - -- @@ -583,108 +767,6 @@ CREATE SEQUENCE public.queued_storage_id_seq ALTER SEQUENCE public.queued_storage_id_seq OWNED BY public.queued_storage.id; --- --- Name: receipt_cids; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.receipt_cids ( - id integer NOT NULL, - tx_id integer NOT NULL, - cid text NOT NULL, - contract character varying(66), - topic0s character varying(66)[], - topic1s character varying(66)[], - topic2s character varying(66)[], - topic3s character varying(66)[] -); - - --- --- Name: receipt_cids_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.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: public; Owner: - --- - -ALTER SEQUENCE public.receipt_cids_id_seq OWNED BY public.receipt_cids.id; - - --- --- Name: state_cids; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.state_cids ( - id integer NOT NULL, - header_id integer NOT NULL, - state_key character varying(66) NOT NULL, - leaf boolean NOT NULL, - cid text NOT NULL -); - - --- --- Name: state_cids_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.state_cids_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: state_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.state_cids_id_seq OWNED BY public.state_cids.id; - - --- --- Name: storage_cids; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.storage_cids ( - id integer NOT NULL, - state_id integer NOT NULL, - storage_key character varying(66) NOT NULL, - leaf boolean NOT NULL, - cid text NOT NULL -); - - --- --- Name: storage_cids_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.storage_cids_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: storage_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.storage_cids_id_seq OWNED BY public.storage_cids.id; - - -- -- Name: storage_diff; Type: TABLE; Schema: public; Owner: - -- @@ -719,74 +801,6 @@ CREATE SEQUENCE public.storage_diff_id_seq ALTER SEQUENCE public.storage_diff_id_seq OWNED BY public.storage_diff.id; --- --- Name: transaction_cids; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.transaction_cids ( - id integer NOT NULL, - header_id integer NOT NULL, - tx_hash character varying(66) NOT NULL, - index integer NOT NULL, - cid text NOT NULL, - dst character varying(66) NOT NULL, - src character varying(66) NOT NULL -); - - --- --- Name: transaction_cids_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.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: public; Owner: - --- - -ALTER SEQUENCE public.transaction_cids_id_seq OWNED BY public.transaction_cids.id; - - --- --- Name: uncle_cids; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.uncle_cids ( - id integer NOT NULL, - header_id integer NOT NULL, - block_hash character varying(66) NOT NULL, - parent_hash character varying(66) NOT NULL, - cid text NOT NULL -); - - --- --- Name: uncle_cids_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.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: public; Owner: - --- - -ALTER SEQUENCE public.uncle_cids_id_seq OWNED BY public.uncle_cids.id; - - -- -- Name: uncles; Type: TABLE; Schema: public; Owner: - -- @@ -909,6 +923,48 @@ CREATE SEQUENCE public.watched_logs_id_seq ALTER SEQUENCE public.watched_logs_id_seq OWNED BY public.watched_logs.id; +-- +-- 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: 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_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: addresses id; Type: DEFAULT; Schema: public; Owner: - -- @@ -965,13 +1021,6 @@ ALTER TABLE ONLY public.full_sync_transactions ALTER COLUMN id SET DEFAULT nextv ALTER TABLE ONLY public.goose_db_version ALTER COLUMN id SET DEFAULT nextval('public.goose_db_version_id_seq'::regclass); --- --- Name: header_cids id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.header_cids ALTER COLUMN id SET DEFAULT nextval('public.header_cids_id_seq'::regclass); - - -- -- Name: header_sync_logs id; Type: DEFAULT; Schema: public; Owner: - -- @@ -1014,27 +1063,6 @@ ALTER TABLE ONLY public.log_filters ALTER COLUMN id SET DEFAULT nextval('public. ALTER TABLE ONLY public.queued_storage ALTER COLUMN id SET DEFAULT nextval('public.queued_storage_id_seq'::regclass); --- --- Name: receipt_cids id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.receipt_cids ALTER COLUMN id SET DEFAULT nextval('public.receipt_cids_id_seq'::regclass); - - --- --- Name: state_cids id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.state_cids ALTER COLUMN id SET DEFAULT nextval('public.state_cids_id_seq'::regclass); - - --- --- Name: storage_cids id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.storage_cids ALTER COLUMN id SET DEFAULT nextval('public.storage_cids_id_seq'::regclass); - - -- -- Name: storage_diff id; Type: DEFAULT; Schema: public; Owner: - -- @@ -1042,20 +1070,6 @@ ALTER TABLE ONLY public.storage_cids ALTER COLUMN id SET DEFAULT nextval('public ALTER TABLE ONLY public.storage_diff ALTER COLUMN id SET DEFAULT nextval('public.storage_diff_id_seq'::regclass); --- --- Name: transaction_cids id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.transaction_cids ALTER COLUMN id SET DEFAULT nextval('public.transaction_cids_id_seq'::regclass); - - --- --- Name: uncle_cids id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.uncle_cids ALTER COLUMN id SET DEFAULT nextval('public.uncle_cids_id_seq'::regclass); - - -- -- Name: uncles id; Type: DEFAULT; Schema: public; Owner: - -- @@ -1077,6 +1091,94 @@ ALTER TABLE ONLY public.watched_contracts ALTER COLUMN contract_id SET DEFAULT n ALTER TABLE ONLY public.watched_logs ALTER COLUMN id SET DEFAULT nextval('public.watched_logs_id_seq'::regclass); +-- +-- 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); + + +-- +-- Name: header_cids header_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.header_cids + ADD CONSTRAINT header_cids_pkey PRIMARY KEY (id); + + +-- +-- Name: receipt_cids receipt_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.receipt_cids + ADD CONSTRAINT receipt_cids_pkey PRIMARY KEY (id); + + +-- +-- Name: state_cids state_cids_header_id_state_key_key; Type: CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.state_cids + ADD CONSTRAINT state_cids_header_id_state_key_key UNIQUE (header_id, state_key); + + +-- +-- Name: state_cids state_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.state_cids + ADD CONSTRAINT state_cids_pkey PRIMARY KEY (id); + + +-- +-- Name: storage_cids storage_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.storage_cids + ADD CONSTRAINT storage_cids_pkey PRIMARY KEY (id); + + +-- +-- Name: storage_cids storage_cids_state_id_storage_key_key; Type: CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.storage_cids + ADD CONSTRAINT storage_cids_state_id_storage_key_key UNIQUE (state_id, storage_key); + + +-- +-- 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); + + +-- +-- Name: transaction_cids transaction_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: - +-- + +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); + + +-- +-- Name: uncle_cids uncle_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: - +-- + +ALTER TABLE ONLY eth.uncle_cids + ADD CONSTRAINT uncle_cids_pkey PRIMARY KEY (id); + + -- -- Name: addresses addresses_address_key; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -1173,22 +1275,6 @@ ALTER TABLE ONLY public.goose_db_version ADD CONSTRAINT goose_db_version_pkey PRIMARY KEY (id); --- --- Name: header_cids header_cids_block_number_block_hash_key; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.header_cids - ADD CONSTRAINT header_cids_block_number_block_hash_key UNIQUE (block_number, block_hash); - - --- --- Name: header_cids header_cids_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.header_cids - ADD CONSTRAINT header_cids_pkey PRIMARY KEY (id); - - -- -- Name: header_sync_logs header_sync_logs_header_id_tx_index_log_index_key; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -1285,46 +1371,6 @@ ALTER TABLE ONLY public.queued_storage ADD CONSTRAINT queued_storage_pkey PRIMARY KEY (id); --- --- Name: receipt_cids receipt_cids_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.receipt_cids - ADD CONSTRAINT receipt_cids_pkey PRIMARY KEY (id); - - --- --- Name: state_cids state_cids_header_id_state_key_key; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.state_cids - ADD CONSTRAINT state_cids_header_id_state_key_key UNIQUE (header_id, state_key); - - --- --- Name: state_cids state_cids_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.state_cids - ADD CONSTRAINT state_cids_pkey PRIMARY KEY (id); - - --- --- Name: storage_cids storage_cids_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.storage_cids - ADD CONSTRAINT storage_cids_pkey PRIMARY KEY (id); - - --- --- Name: storage_cids storage_cids_state_id_storage_key_key; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.storage_cids - ADD CONSTRAINT storage_cids_state_id_storage_key_key UNIQUE (state_id, storage_key); - - -- -- Name: storage_diff storage_diff_block_height_block_hash_hashed_address_storage_key; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -1341,38 +1387,6 @@ ALTER TABLE ONLY public.storage_diff ADD CONSTRAINT storage_diff_pkey PRIMARY KEY (id); --- --- Name: transaction_cids transaction_cids_header_id_tx_hash_key; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.transaction_cids - ADD CONSTRAINT transaction_cids_header_id_tx_hash_key UNIQUE (header_id, tx_hash); - - --- --- Name: transaction_cids transaction_cids_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.transaction_cids - ADD CONSTRAINT transaction_cids_pkey PRIMARY KEY (id); - - --- --- Name: uncle_cids uncle_cids_header_id_block_hash_key; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.uncle_cids - ADD CONSTRAINT uncle_cids_header_id_block_hash_key UNIQUE (header_id, block_hash); - - --- --- Name: uncle_cids uncle_cids_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.uncle_cids - ADD CONSTRAINT uncle_cids_pkey PRIMARY KEY (id); - - -- -- Name: uncles uncles_block_id_hash_key; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -1490,6 +1504,46 @@ CREATE INDEX tx_from_index ON public.full_sync_transactions USING btree (tx_from CREATE INDEX tx_to_index ON public.full_sync_transactions USING btree (tx_to); +-- +-- Name: receipt_cids receipt_cids_tx_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +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; + + +-- +-- Name: state_cids state_cids_header_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +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; + + +-- +-- 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; + + +-- +-- Name: uncle_cids uncle_cids_header_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: - +-- + +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; + + -- -- Name: checked_headers checked_headers_header_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -1594,14 +1648,6 @@ ALTER TABLE ONLY public.queued_storage ADD CONSTRAINT queued_storage_diff_id_fkey FOREIGN KEY (diff_id) REFERENCES public.storage_diff(id); --- --- Name: receipt_cids receipt_cids_tx_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.receipt_cids - ADD CONSTRAINT receipt_cids_tx_id_fkey FOREIGN KEY (tx_id) REFERENCES public.transaction_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; - - -- -- Name: full_sync_logs receipts_fk; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -1610,38 +1656,6 @@ ALTER TABLE ONLY public.full_sync_logs ADD CONSTRAINT receipts_fk FOREIGN KEY (receipt_id) REFERENCES public.full_sync_receipts(id) ON DELETE CASCADE; --- --- Name: state_cids state_cids_header_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.state_cids - ADD CONSTRAINT state_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; - - --- --- Name: storage_cids storage_cids_state_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.storage_cids - ADD CONSTRAINT storage_cids_state_id_fkey FOREIGN KEY (state_id) REFERENCES public.state_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; - - --- --- Name: transaction_cids transaction_cids_header_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.transaction_cids - ADD CONSTRAINT transaction_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; - - --- --- Name: uncle_cids uncle_cids_header_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.uncle_cids - ADD CONSTRAINT uncle_cids_header_id_fkey FOREIGN KEY (header_id) REFERENCES public.header_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; - - -- -- Name: uncles uncles_block_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- diff --git a/pkg/super_node/eth/indexer.go b/pkg/super_node/eth/indexer.go index faadef9e..41c78ec3 100644 --- a/pkg/super_node/eth/indexer.go +++ b/pkg/super_node/eth/indexer.go @@ -83,7 +83,7 @@ func (in *CIDIndexer) Index(cids shared.CIDsForIndexing) error { func (repo *CIDIndexer) indexHeaderCID(tx *sqlx.Tx, header HeaderModel) (int64, error) { var headerID int64 - err := tx.QueryRowx(`INSERT INTO public.header_cids (block_number, block_hash, parent_hash, cid, td) VALUES ($1, $2, $3, $4, $5) + err := tx.QueryRowx(`INSERT INTO eth.header_cids (block_number, block_hash, parent_hash, cid, td) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (block_number, block_hash) DO UPDATE SET (parent_hash, cid, td) = ($3, $4, $5) RETURNING id`, header.BlockNumber, header.BlockHash, header.ParentHash, header.CID, header.TotalDifficulty).Scan(&headerID) @@ -91,7 +91,7 @@ func (repo *CIDIndexer) indexHeaderCID(tx *sqlx.Tx, header HeaderModel) (int64, } func (in *CIDIndexer) indexUncleCID(tx *sqlx.Tx, uncle UncleModel, headerID int64) error { - _, err := tx.Exec(`INSERT INTO public.uncle_cids (block_hash, header_id, parent_hash, cid) VALUES ($1, $2, $3, $4) + _, err := tx.Exec(`INSERT INTO eth.uncle_cids (block_hash, header_id, parent_hash, cid) VALUES ($1, $2, $3, $4) ON CONFLICT (header_id, block_hash) DO UPDATE SET (parent_hash, cid) = ($3, $4)`, uncle.BlockHash, headerID, uncle.ParentHash, uncle.CID) return err @@ -100,7 +100,7 @@ func (in *CIDIndexer) indexUncleCID(tx *sqlx.Tx, uncle UncleModel, headerID int6 func (in *CIDIndexer) indexTransactionAndReceiptCIDs(tx *sqlx.Tx, payload *CIDPayload, headerID int64) error { for _, trxCidMeta := range payload.TransactionCIDs { var txID int64 - err := tx.QueryRowx(`INSERT INTO public.transaction_cids (header_id, tx_hash, cid, dst, src, index) VALUES ($1, $2, $3, $4, $5, $6) + err := tx.QueryRowx(`INSERT INTO eth.transaction_cids (header_id, tx_hash, cid, dst, src, index) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (header_id, tx_hash) DO UPDATE SET (cid, dst, src, index) = ($3, $4, $5, $6) RETURNING id`, headerID, trxCidMeta.TxHash, trxCidMeta.CID, trxCidMeta.Dst, trxCidMeta.Src, trxCidMeta.Index).Scan(&txID) @@ -118,7 +118,7 @@ func (in *CIDIndexer) indexTransactionAndReceiptCIDs(tx *sqlx.Tx, payload *CIDPa } func (in *CIDIndexer) indexReceiptCID(tx *sqlx.Tx, cidMeta ReceiptModel, txID int64) error { - _, err := tx.Exec(`INSERT INTO public.receipt_cids (tx_id, cid, contract, topic0s, topic1s, topic2s, topic3s) VALUES ($1, $2, $3, $4, $5, $6, $7)`, + _, err := tx.Exec(`INSERT INTO eth.receipt_cids (tx_id, cid, contract, topic0s, topic1s, topic2s, topic3s) VALUES ($1, $2, $3, $4, $5, $6, $7)`, txID, cidMeta.CID, cidMeta.Contract, pq.Array(cidMeta.Topic0s), pq.Array(cidMeta.Topic1s), pq.Array(cidMeta.Topic2s), pq.Array(cidMeta.Topic3s)) return err } @@ -126,7 +126,7 @@ func (in *CIDIndexer) indexReceiptCID(tx *sqlx.Tx, cidMeta ReceiptModel, txID in func (in *CIDIndexer) indexStateAndStorageCIDs(tx *sqlx.Tx, payload *CIDPayload, headerID int64) error { for _, stateCID := range payload.StateNodeCIDs { var stateID int64 - err := tx.QueryRowx(`INSERT INTO public.state_cids (header_id, state_key, cid, leaf) VALUES ($1, $2, $3, $4) + err := tx.QueryRowx(`INSERT INTO eth.state_cids (header_id, state_key, cid, leaf) VALUES ($1, $2, $3, $4) ON CONFLICT (header_id, state_key) DO UPDATE SET (cid, leaf) = ($3, $4) RETURNING id`, headerID, stateCID.StateKey, stateCID.CID, stateCID.Leaf).Scan(&stateID) @@ -143,7 +143,7 @@ func (in *CIDIndexer) indexStateAndStorageCIDs(tx *sqlx.Tx, payload *CIDPayload, } func (in *CIDIndexer) indexStorageCID(tx *sqlx.Tx, storageCID StorageNodeModel, stateID int64) error { - _, err := tx.Exec(`INSERT INTO public.storage_cids (state_id, storage_key, cid, leaf) VALUES ($1, $2, $3, $4) + _, err := tx.Exec(`INSERT INTO eth.storage_cids (state_id, storage_key, cid, leaf) VALUES ($1, $2, $3, $4) ON CONFLICT (state_id, storage_key) DO UPDATE SET (cid, leaf) = ($3, $4)`, stateID, storageCID.StorageKey, storageCID.CID, storageCID.Leaf) return err diff --git a/pkg/super_node/eth/indexer_test.go b/pkg/super_node/eth/indexer_test.go index 804e4b7a..65853e1c 100644 --- a/pkg/super_node/eth/indexer_test.go +++ b/pkg/super_node/eth/indexer_test.go @@ -46,7 +46,7 @@ var _ = Describe("Indexer", func() { It("Indexes CIDs and related metadata into vulcanizedb", func() { err = repo.Index(mocks.MockCIDPayload) Expect(err).ToNot(HaveOccurred()) - pgStr := `SELECT cid, td FROM header_cids + pgStr := `SELECT cid, td FROM eth.header_cids WHERE block_number = $1` // check header was properly indexed type res struct { @@ -60,7 +60,7 @@ var _ = Describe("Indexer", func() { Expect(headers.TD).To(Equal("1337")) // check trxs were properly indexed trxs := make([]string, 0) - pgStr = `SELECT transaction_cids.cid FROM transaction_cids INNER JOIN header_cids ON (transaction_cids.header_id = header_cids.id) + pgStr = `SELECT transaction_cids.cid FROM eth.transaction_cids INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.id) WHERE header_cids.block_number = $1` err = db.Select(&trxs, pgStr, 1) Expect(err).ToNot(HaveOccurred()) @@ -69,7 +69,7 @@ var _ = Describe("Indexer", func() { Expect(shared.ListContainsString(trxs, "mockTrxCID2")).To(BeTrue()) // check receipts were properly indexed rcts := make([]string, 0) - pgStr = `SELECT receipt_cids.cid FROM receipt_cids, transaction_cids, header_cids + pgStr = `SELECT receipt_cids.cid FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids WHERE receipt_cids.tx_id = transaction_cids.id AND transaction_cids.header_id = header_cids.id AND header_cids.block_number = $1` @@ -80,7 +80,7 @@ var _ = Describe("Indexer", func() { Expect(shared.ListContainsString(rcts, "mockRctCID2")).To(BeTrue()) // check that state nodes were properly indexed stateNodes := make([]eth.StateNodeModel, 0) - pgStr = `SELECT state_cids.cid, state_cids.state_key, state_cids.leaf FROM state_cids INNER JOIN header_cids ON (state_cids.header_id = header_cids.id) + pgStr = `SELECT state_cids.cid, state_cids.state_key, state_cids.leaf FROM eth.state_cids INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id) WHERE header_cids.block_number = $1` err = db.Select(&stateNodes, pgStr, 1) Expect(err).ToNot(HaveOccurred()) @@ -97,7 +97,7 @@ var _ = Describe("Indexer", func() { } // check that storage nodes were properly indexed storageNodes := make([]eth.StorageNodeWithStateKeyModel, 0) - pgStr = `SELECT storage_cids.cid, state_cids.state_key, storage_cids.storage_key, storage_cids.leaf FROM storage_cids, state_cids, header_cids + pgStr = `SELECT storage_cids.cid, state_cids.state_key, storage_cids.storage_key, storage_cids.leaf FROM eth.storage_cids, eth.state_cids, eth.header_cids WHERE storage_cids.state_id = state_cids.id AND state_cids.header_id = header_cids.id AND header_cids.block_number = $1` diff --git a/pkg/super_node/eth/retriever.go b/pkg/super_node/eth/retriever.go index 3dff18af..8b4dc000 100644 --- a/pkg/super_node/eth/retriever.go +++ b/pkg/super_node/eth/retriever.go @@ -46,14 +46,14 @@ func NewCIDRetriever(db *postgres.DB) *CIDRetriever { // RetrieveFirstBlockNumber is used to retrieve the first block number in the db func (ecr *CIDRetriever) RetrieveFirstBlockNumber() (int64, error) { var blockNumber int64 - err := ecr.db.Get(&blockNumber, "SELECT block_number FROM header_cids ORDER BY block_number ASC LIMIT 1") + err := ecr.db.Get(&blockNumber, "SELECT block_number FROM eth.header_cids ORDER BY block_number ASC LIMIT 1") return blockNumber, err } // RetrieveLastBlockNumber is used to retrieve the latest block number in the db func (ecr *CIDRetriever) RetrieveLastBlockNumber() (int64, error) { var blockNumber int64 - err := ecr.db.Get(&blockNumber, "SELECT block_number FROM header_cids ORDER BY block_number DESC LIMIT 1 ") + err := ecr.db.Get(&blockNumber, "SELECT block_number FROM eth.header_cids ORDER BY block_number DESC LIMIT 1 ") return blockNumber, err } @@ -157,7 +157,7 @@ func empty(cidWrapper *CIDWrapper) bool { func (ecr *CIDRetriever) RetrieveHeaderCIDs(tx *sqlx.Tx, blockNumber int64) ([]HeaderModel, error) { log.Debug("retrieving header cids for block ", blockNumber) headers := make([]HeaderModel, 0) - pgStr := `SELECT * FROM header_cids + pgStr := `SELECT * FROM eth.header_cids WHERE block_number = $1` return headers, tx.Select(&headers, pgStr, blockNumber) } @@ -166,7 +166,7 @@ func (ecr *CIDRetriever) RetrieveHeaderCIDs(tx *sqlx.Tx, blockNumber int64) ([]H func (ecr *CIDRetriever) RetrieveUncleCIDsByHeaderID(tx *sqlx.Tx, headerID int64) ([]UncleModel, error) { log.Debug("retrieving uncle cids for block id ", headerID) headers := make([]UncleModel, 0) - pgStr := `SELECT * FROM uncle_cids + pgStr := `SELECT * FROM eth.uncle_cids WHERE header_id = $1` return headers, tx.Select(&headers, pgStr, headerID) } @@ -180,7 +180,7 @@ func (ecr *CIDRetriever) RetrieveTxCIDs(tx *sqlx.Tx, txFilter config.TxFilter, b pgStr := `SELECT transaction_cids.id, transaction_cids.header_id, transaction_cids.tx_hash, transaction_cids.cid, transaction_cids.dst, transaction_cids.src, transaction_cids.index - FROM transaction_cids INNER JOIN header_cids ON (transaction_cids.header_id = header_cids.id) + FROM eth.transaction_cids INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.id) WHERE header_cids.block_number = $1` args = append(args, blockNumber) if len(txFilter.Dst) > 0 { @@ -203,7 +203,7 @@ func (ecr *CIDRetriever) RetrieveRctCIDs(tx *sqlx.Tx, rctFilter config.ReceiptFi pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, receipt_cids.contract, receipt_cids.topic0s, receipt_cids.topic1s, receipt_cids.topic2s, receipt_cids.topic3s - FROM receipt_cids, transaction_cids, header_cids + FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids WHERE receipt_cids.tx_id = transaction_cids.id AND transaction_cids.header_id = header_cids.id` if blockNumber > 0 { @@ -287,7 +287,7 @@ func (ecr *CIDRetriever) RetrieveStateCIDs(tx *sqlx.Tx, stateFilter config.State args := make([]interface{}, 0, 2) pgStr := `SELECT state_cids.id, state_cids.header_id, state_cids.state_key, state_cids.leaf, state_cids.cid - FROM state_cids INNER JOIN header_cids ON (state_cids.header_id = header_cids.id) + FROM eth.state_cids INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id) WHERE header_cids.block_number = $1` args = append(args, blockNumber) addrLen := len(stateFilter.Addresses) @@ -311,7 +311,7 @@ func (ecr *CIDRetriever) RetrieveStorageCIDs(tx *sqlx.Tx, storageFilter config.S log.Debug("retrieving storage cids for block ", blockNumber) args := make([]interface{}, 0, 3) pgStr := `SELECT storage_cids.id, storage_cids.state_id, storage_cids.storage_key, - storage_cids.leaf, storage_cids.cid, state_cids.state_key FROM storage_cids, state_cids, header_cids + storage_cids.leaf, storage_cids.cid, state_cids.state_key FROM eth.storage_cids, eth.state_cids, eth.header_cids WHERE storage_cids.state_id = state_cids.id AND state_cids.header_id = header_cids.id AND header_cids.block_number = $1` @@ -341,9 +341,9 @@ func (ecr *CIDRetriever) RetrieveStorageCIDs(tx *sqlx.Tx, storageFilter config.S // RetrieveGapsInData is used to find the the block numbers at which we are missing data in the db func (ecr *CIDRetriever) RetrieveGapsInData() ([]shared.Gap, error) { - pgStr := `SELECT header_cids.block_number + 1 AS start, min(fr.block_number) - 1 AS stop FROM header_cids - LEFT JOIN header_cids r on header_cids.block_number = r.block_number - 1 - LEFT JOIN header_cids fr on header_cids.block_number < fr.block_number + pgStr := `SELECT header_cids.block_number + 1 AS start, min(fr.block_number) - 1 AS stop FROM eth.header_cids + LEFT JOIN eth.header_cids r on eth.header_cids.block_number = r.block_number - 1 + LEFT JOIN eth.header_cids fr on eth.header_cids.block_number < fr.block_number WHERE r.block_number is NULL and fr.block_number IS NOT NULL GROUP BY header_cids.block_number, r.block_number` results := make([]struct { @@ -462,7 +462,7 @@ func (ecr *CIDRetriever) RetrieveBlockByNumber(blockNumber int64) (HeaderModel, // RetrieveHeaderCIDByHash returns the header for the given block hash func (ecr *CIDRetriever) RetrieveHeaderCIDByHash(tx *sqlx.Tx, blockHash common.Hash) (HeaderModel, error) { log.Debug("retrieving header cids for block hash ", blockHash.String()) - pgStr := `SELECT * FROM header_cids + pgStr := `SELECT * FROM eth.header_cids WHERE block_hash = $1` var headerCID HeaderModel return headerCID, tx.Get(&headerCID, pgStr, blockHash.String()) @@ -471,8 +471,8 @@ func (ecr *CIDRetriever) RetrieveHeaderCIDByHash(tx *sqlx.Tx, blockHash common.H // RetrieveTxCIDsByHeaderID retrieves all tx CIDs for the given header id func (ecr *CIDRetriever) RetrieveTxCIDsByHeaderID(tx *sqlx.Tx, headerID int64) ([]TxModel, error) { log.Debug("retrieving tx cids for block id ", headerID) - pgStr := `SELECT * FROM transaction_cids - WHERE transaction_cids.header_id = $1` + pgStr := `SELECT * FROM eth.transaction_cids + WHERE eth.transaction_cids.header_id = $1` var txCIDs []TxModel return txCIDs, tx.Select(&txCIDs, pgStr, headerID) } @@ -480,8 +480,8 @@ func (ecr *CIDRetriever) RetrieveTxCIDsByHeaderID(tx *sqlx.Tx, headerID int64) ( // RetrieveReceiptCIDsByTxIDs retrieves receipt CIDs by their associated tx IDs func (ecr *CIDRetriever) RetrieveReceiptCIDsByTxIDs(tx *sqlx.Tx, txIDs []int64) ([]ReceiptModel, error) { log.Debugf("retrieving receipt cids for tx ids %v", txIDs) - pgStr := `SELECT * FROM receipt_cids - WHERE receipt_cids.tx_id = ANY($1::INTEGER[])` + pgStr := `SELECT * FROM eth.receipt_cids + WHERE eth.receipt_cids.tx_id = ANY($1::INTEGER[])` var rctCIDs []ReceiptModel return rctCIDs, tx.Select(&rctCIDs, pgStr, pq.Array(txIDs)) } diff --git a/pkg/super_node/eth/test_helpers.go b/pkg/super_node/eth/test_helpers.go index 2279ba87..58c65064 100644 --- a/pkg/super_node/eth/test_helpers.go +++ b/pkg/super_node/eth/test_helpers.go @@ -38,15 +38,15 @@ func TearDownDB(db *postgres.DB) { tx, err := db.Beginx() Expect(err).NotTo(HaveOccurred()) - _, err = tx.Exec(`DELETE FROM header_cids`) + _, err = tx.Exec(`DELETE FROM eth.header_cids`) Expect(err).NotTo(HaveOccurred()) - _, err = tx.Exec(`DELETE FROM transaction_cids`) + _, err = tx.Exec(`DELETE FROM eth.transaction_cids`) Expect(err).NotTo(HaveOccurred()) - _, err = tx.Exec(`DELETE FROM receipt_cids`) + _, err = tx.Exec(`DELETE FROM eth.receipt_cids`) Expect(err).NotTo(HaveOccurred()) - _, err = tx.Exec(`DELETE FROM state_cids`) + _, err = tx.Exec(`DELETE FROM eth.state_cids`) Expect(err).NotTo(HaveOccurred()) - _, err = tx.Exec(`DELETE FROM storage_cids`) + _, err = tx.Exec(`DELETE FROM eth.storage_cids`) Expect(err).NotTo(HaveOccurred()) _, err = tx.Exec(`DELETE FROM blocks`) Expect(err).NotTo(HaveOccurred())