-
Notifications
You must be signed in to change notification settings - Fork 7
/
schema.sql
900 lines (618 loc) · 22.9 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
--
-- PostgreSQL database dump
--
-- Dumped from database version 14.12
-- Dumped by pg_dump version 14.12
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: timescaledb; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS timescaledb WITH SCHEMA public;
--
-- Name: EXTENSION timescaledb; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION timescaledb IS 'Enables scalable inserts and complex queries for time-series data (Community Edition)';
--
-- Name: eth; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA eth;
--
-- Name: eth_meta; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA eth_meta;
--
-- Name: ipld; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA ipld;
--
-- Name: canonical_header_hash(bigint); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.canonical_header_hash(height bigint) RETURNS character varying
LANGUAGE sql
AS $$
SELECT block_hash from eth.header_cids WHERE block_number = height AND canonical = true LIMIT 1;
$$;
--
-- Name: get_storage_at_by_hash(text, text, text); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.get_storage_at_by_hash(v_state_leaf_key text, v_storage_leaf_key text, v_block_hash text) RETURNS TABLE(cid text, val bytea, block_number bigint, removed boolean, state_leaf_removed boolean)
LANGUAGE plpgsql
AS $$
DECLARE
v_block_no BIGINT;
BEGIN
SELECT h.block_number INTO v_block_no FROM eth.header_cids AS h WHERE block_hash = v_block_hash LIMIT 1;
IF v_block_no IS NULL THEN
RETURN;
END IF;
RETURN QUERY SELECT * FROM get_storage_at_by_number(v_state_leaf_key, v_storage_leaf_key, v_block_no);
END
$$;
--
-- Name: get_storage_at_by_number(text, text, bigint); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.get_storage_at_by_number(v_state_leaf_key text, v_storage_leaf_key text, v_block_no bigint) RETURNS TABLE(cid text, val bytea, block_number bigint, removed boolean, state_leaf_removed boolean)
LANGUAGE plpgsql
AS $$
DECLARE
v_state_path BYTEA;
v_header TEXT;
v_canonical_header TEXT;
BEGIN
CREATE TEMP TABLE tmp_tt_stg2
(
header_id TEXT,
cid TEXT,
val BYTEA,
block_number BIGINT,
removed BOOL,
state_leaf_removed BOOL
) ON COMMIT DROP;
-- in best case scenario, the latest record we find for the provided keys is for a canonical block
INSERT INTO tmp_tt_stg2
SELECT storage_cids.header_id,
storage_cids.cid,
storage_cids.val,
storage_cids.block_number,
storage_cids.removed,
was_state_leaf_removed_by_number(v_state_leaf_key, v_block_no) AS state_leaf_removed
FROM eth.storage_cids
WHERE storage_leaf_key = v_storage_leaf_key
AND storage_cids.state_leaf_key = v_state_leaf_key -- can lookup directly on the leaf key in v5
AND storage_cids.block_number <= v_block_no
ORDER BY storage_cids.block_number DESC LIMIT 1;
-- check if result is from canonical state
SELECT header_id, canonical_header_hash(tmp_tt_stg2.block_number)
INTO v_header, v_canonical_header
FROM tmp_tt_stg2 LIMIT 1;
IF v_header IS NULL OR v_header != v_canonical_header THEN
RAISE NOTICE 'get_storage_at_by_number: chosen header NULL OR % != canonical header % for block number %, trying again.', v_header, v_canonical_header, v_block_no;
TRUNCATE tmp_tt_stg2;
-- If we hit on a non-canonical block, we need to go back and do a comprehensive check.
-- We try to avoid this to avoid joining between storage_cids and header_cids
INSERT INTO tmp_tt_stg2
SELECT storage_cids.header_id,
storage_cids.cid,
storage_cids.val,
storage_cids.block_number,
storage_cids.removed,
was_state_leaf_removed_by_number(
v_state_leaf_key,
v_block_no
) AS state_leaf_removed
FROM eth.storage_cids
INNER JOIN eth.header_cids ON (
storage_cids.header_id = header_cids.block_hash
AND storage_cids.block_number = header_cids.block_number
)
WHERE state_leaf_key = v_state_leaf_key
AND storage_leaf_key = v_storage_leaf_key
AND storage_cids.block_number <= v_block_no
AND header_cids.block_number <= v_block_no
AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number))
ORDER BY header_cids.block_number DESC LIMIT 1;
END IF;
RETURN QUERY SELECT t.cid, t.val, t.block_number, t.removed, t.state_leaf_removed
FROM tmp_tt_stg2 AS t LIMIT 1;
END
$$;
--
-- Name: was_state_leaf_removed(character varying, character varying); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.was_state_leaf_removed(v_key character varying, v_hash character varying) RETURNS boolean
LANGUAGE sql
AS $$
SELECT state_cids.removed = true
FROM eth.state_cids
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.block_hash)
WHERE state_leaf_key = v_key
AND state_cids.block_number <= (SELECT block_number
FROM eth.header_cids
WHERE block_hash = v_hash)
ORDER BY state_cids.block_number DESC LIMIT 1;
$$;
--
-- Name: was_state_leaf_removed_by_number(character varying, bigint); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.was_state_leaf_removed_by_number(v_key character varying, v_block_no bigint) RETURNS boolean
LANGUAGE sql
AS $$
SELECT state_cids.removed = true
FROM eth.state_cids
INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.block_hash)
WHERE state_leaf_key = v_key
AND state_cids.block_number <= v_block_no
ORDER BY state_cids.block_number DESC LIMIT 1;
$$;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: blob_hashes; Type: TABLE; Schema: eth; Owner: -
--
CREATE TABLE eth.blob_hashes (
tx_hash character varying(66) NOT NULL,
index integer NOT NULL,
blob_hash bytea NOT NULL
);
--
-- Name: header_cids; Type: TABLE; Schema: eth; Owner: -
--
CREATE TABLE eth.header_cids (
block_number bigint NOT NULL,
block_hash character varying(66) NOT NULL,
parent_hash character varying(66) NOT NULL,
cid text NOT NULL,
td numeric NOT NULL,
node_ids character varying(128)[] NOT NULL,
reward numeric NOT NULL,
state_root character varying(66) NOT NULL,
tx_root character varying(66) NOT NULL,
receipt_root character varying(66) NOT NULL,
uncles_hash character varying(66) NOT NULL,
bloom bytea NOT NULL,
"timestamp" bigint NOT NULL,
coinbase character varying(66) NOT NULL,
canonical boolean DEFAULT true NOT NULL,
withdrawals_root character varying(66) NOT NULL
);
--
-- Name: TABLE header_cids; Type: COMMENT; Schema: eth; Owner: -
--
COMMENT ON TABLE eth.header_cids IS '@name EthHeaderCids';
--
-- Name: COLUMN header_cids.node_ids; Type: COMMENT; Schema: eth; Owner: -
--
COMMENT ON COLUMN eth.header_cids.node_ids IS '@name EthNodeIDs';
--
-- Name: log_cids; Type: TABLE; Schema: eth; Owner: -
--
CREATE TABLE eth.log_cids (
block_number bigint NOT NULL,
header_id character varying(66) NOT NULL,
cid text NOT NULL,
rct_id character varying(66) NOT NULL,
address character varying(66) NOT NULL,
index integer NOT NULL,
topic0 character varying(66),
topic1 character varying(66),
topic2 character varying(66),
topic3 character varying(66)
);
--
-- Name: receipt_cids; Type: TABLE; Schema: eth; Owner: -
--
CREATE TABLE eth.receipt_cids (
block_number bigint NOT NULL,
header_id character varying(66) NOT NULL,
tx_id character varying(66) NOT NULL,
cid text NOT NULL,
contract character varying(66),
post_state character varying(66),
post_status smallint
);
--
-- Name: state_cids; Type: TABLE; Schema: eth; Owner: -
--
CREATE TABLE eth.state_cids (
block_number bigint NOT NULL,
header_id character varying(66) NOT NULL,
state_leaf_key character varying(66) NOT NULL,
cid text NOT NULL,
diff boolean DEFAULT false NOT NULL,
balance numeric,
nonce bigint,
code_hash character varying(66),
storage_root character varying(66),
removed boolean NOT NULL
);
--
-- Name: storage_cids; Type: TABLE; Schema: eth; Owner: -
--
CREATE TABLE eth.storage_cids (
block_number bigint NOT NULL,
header_id character varying(66) NOT NULL,
state_leaf_key character varying(66) NOT NULL,
storage_leaf_key character varying(66) NOT NULL,
cid text NOT NULL,
diff boolean DEFAULT false NOT NULL,
val bytea,
removed boolean NOT NULL
);
--
-- Name: transaction_cids; Type: TABLE; Schema: eth; Owner: -
--
CREATE TABLE eth.transaction_cids (
block_number bigint NOT NULL,
header_id character varying(66) NOT NULL,
tx_hash character varying(66) NOT NULL,
cid text NOT NULL,
dst character varying(66),
src character varying(66) NOT NULL,
index integer NOT NULL,
tx_type integer,
value numeric
);
--
-- Name: TABLE transaction_cids; Type: COMMENT; Schema: eth; Owner: -
--
COMMENT ON TABLE eth.transaction_cids IS '@name EthTransactionCids';
--
-- Name: uncle_cids; Type: TABLE; Schema: eth; Owner: -
--
CREATE TABLE eth.uncle_cids (
block_number bigint 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,
reward numeric NOT NULL,
index integer NOT NULL
);
--
-- Name: withdrawal_cids; Type: TABLE; Schema: eth; Owner: -
--
CREATE TABLE eth.withdrawal_cids (
block_number bigint NOT NULL,
header_id character varying(66) NOT NULL,
cid text NOT NULL,
index integer NOT NULL,
validator integer NOT NULL,
address character varying(66) NOT NULL,
amount numeric NOT NULL
);
--
-- Name: watched_addresses; Type: TABLE; Schema: eth_meta; Owner: -
--
CREATE TABLE eth_meta.watched_addresses (
address character varying(66) NOT NULL,
created_at bigint NOT NULL,
watched_at bigint NOT NULL,
last_filled_at bigint DEFAULT 0 NOT NULL
);
--
-- Name: blocks; Type: TABLE; Schema: ipld; Owner: -
--
CREATE TABLE ipld.blocks (
block_number bigint NOT NULL,
key text NOT NULL,
data bytea NOT NULL
);
--
-- Name: db_version; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.db_version (
singleton boolean DEFAULT true NOT NULL,
version text NOT NULL,
tstamp timestamp without time zone DEFAULT now(),
CONSTRAINT db_version_singleton_check CHECK (singleton)
);
--
-- Name: goose_db_version; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.goose_db_version (
id integer NOT NULL,
version_id bigint NOT NULL,
is_applied boolean NOT NULL,
tstamp timestamp without time zone DEFAULT now()
);
--
-- Name: goose_db_version_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.goose_db_version_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: goose_db_version_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.goose_db_version_id_seq OWNED BY public.goose_db_version.id;
--
-- Name: nodes; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.nodes (
genesis_block character varying(66),
network_id character varying,
node_id character varying(128) NOT NULL,
client_name character varying,
chain_id integer DEFAULT 1
);
--
-- Name: TABLE nodes; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE public.nodes IS '@name NodeInfo';
--
-- Name: COLUMN nodes.node_id; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON COLUMN public.nodes.node_id IS '@name ChainNodeID';
--
-- Name: goose_db_version id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.goose_db_version ALTER COLUMN id SET DEFAULT nextval('public.goose_db_version_id_seq'::regclass);
--
-- Name: header_cids header_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.header_cids
ADD CONSTRAINT header_cids_pkey PRIMARY KEY (block_hash, block_number);
--
-- Name: log_cids log_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.log_cids
ADD CONSTRAINT log_cids_pkey PRIMARY KEY (rct_id, index, header_id, block_number);
--
-- Name: receipt_cids receipt_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.receipt_cids
ADD CONSTRAINT receipt_cids_pkey PRIMARY KEY (tx_id, header_id, block_number);
--
-- Name: state_cids state_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.state_cids
ADD CONSTRAINT state_cids_pkey PRIMARY KEY (state_leaf_key, header_id, block_number);
--
-- Name: storage_cids storage_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.storage_cids
ADD CONSTRAINT storage_cids_pkey PRIMARY KEY (storage_leaf_key, state_leaf_key, header_id, block_number);
--
-- Name: transaction_cids transaction_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.transaction_cids
ADD CONSTRAINT transaction_cids_pkey PRIMARY KEY (tx_hash, header_id, block_number);
--
-- Name: uncle_cids uncle_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.uncle_cids
ADD CONSTRAINT uncle_cids_pkey PRIMARY KEY (block_hash, block_number);
--
-- Name: withdrawal_cids withdrawal_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
--
ALTER TABLE ONLY eth.withdrawal_cids
ADD CONSTRAINT withdrawal_cids_pkey PRIMARY KEY (index, header_id, block_number);
--
-- Name: watched_addresses watched_addresses_pkey; Type: CONSTRAINT; Schema: eth_meta; Owner: -
--
ALTER TABLE ONLY eth_meta.watched_addresses
ADD CONSTRAINT watched_addresses_pkey PRIMARY KEY (address);
--
-- Name: blocks blocks_pkey; Type: CONSTRAINT; Schema: ipld; Owner: -
--
ALTER TABLE ONLY ipld.blocks
ADD CONSTRAINT blocks_pkey PRIMARY KEY (key, block_number);
--
-- Name: db_version db_version_singleton_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.db_version
ADD CONSTRAINT db_version_singleton_key UNIQUE (singleton);
--
-- Name: goose_db_version goose_db_version_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.goose_db_version
ADD CONSTRAINT goose_db_version_pkey PRIMARY KEY (id);
--
-- Name: nodes nodes_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.nodes
ADD CONSTRAINT nodes_pkey PRIMARY KEY (node_id);
--
-- Name: blob_hashes_tx_hash_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE UNIQUE INDEX blob_hashes_tx_hash_index ON eth.blob_hashes USING btree (tx_hash, index);
--
-- Name: header_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX header_block_number_index ON eth.header_cids USING btree (block_number);
--
-- Name: header_cid_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE UNIQUE INDEX header_cid_block_number_index ON eth.header_cids USING btree (cid, block_number);
--
-- Name: log_address_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX log_address_index ON eth.log_cids USING btree (address);
--
-- Name: log_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX log_block_number_index ON eth.log_cids USING btree (block_number);
--
-- Name: log_cid_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX log_cid_block_number_index ON eth.log_cids USING btree (cid, block_number);
--
-- Name: log_header_id_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX log_header_id_index ON eth.log_cids USING btree (header_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);
--
-- Name: rct_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX rct_block_number_index ON eth.receipt_cids USING btree (block_number);
--
-- Name: rct_cid_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX rct_cid_block_number_index ON eth.receipt_cids USING btree (cid, block_number);
--
-- Name: rct_contract_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract);
--
-- Name: rct_header_id_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX rct_header_id_index ON eth.receipt_cids USING btree (header_id);
--
-- Name: state_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX state_block_number_index ON eth.state_cids USING btree (block_number);
--
-- Name: state_cid_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX state_cid_block_number_index ON eth.state_cids USING btree (cid, block_number);
--
-- Name: state_code_hash_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX state_code_hash_index ON eth.state_cids USING btree (code_hash);
--
-- 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_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX state_leaf_key_block_number_index ON eth.state_cids USING btree (state_leaf_key, block_number DESC);
--
-- Name: state_removed_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX state_removed_index ON eth.state_cids USING btree (removed);
--
-- Name: state_root_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX state_root_index ON eth.header_cids USING btree (state_root);
--
-- Name: storage_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX storage_block_number_index ON eth.storage_cids USING btree (block_number);
--
-- Name: storage_cid_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX storage_cid_block_number_index ON eth.storage_cids USING btree (cid, block_number);
--
-- Name: storage_header_id_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX storage_header_id_index ON eth.storage_cids USING btree (header_id);
--
-- Name: storage_leaf_key_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX storage_leaf_key_block_number_index ON eth.storage_cids USING btree (storage_leaf_key, block_number DESC);
--
-- Name: storage_removed_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX storage_removed_index ON eth.storage_cids USING btree (removed);
--
-- Name: storage_state_leaf_key_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX storage_state_leaf_key_index ON eth.storage_cids USING btree (state_leaf_key);
--
-- Name: timestamp_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX timestamp_index ON eth.header_cids USING btree ("timestamp");
--
-- Name: tx_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX tx_block_number_index ON eth.transaction_cids USING btree (block_number);
--
-- Name: tx_cid_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX tx_cid_block_number_index ON eth.transaction_cids USING btree (cid, block_number);
--
-- Name: tx_dst_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX tx_dst_index ON eth.transaction_cids USING btree (dst);
--
-- Name: tx_header_id_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX tx_header_id_index ON eth.transaction_cids USING btree (header_id);
--
-- Name: tx_src_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX tx_src_index ON eth.transaction_cids USING btree (src);
--
-- Name: uncle_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX uncle_block_number_index ON eth.uncle_cids USING btree (block_number);
--
-- Name: uncle_cid_block_number_index; Type: INDEX; Schema: eth; Owner: -
--
CREATE UNIQUE INDEX uncle_cid_block_number_index ON eth.uncle_cids USING btree (cid, block_number, index);
--
-- 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: withdrawal_cids_block_number_idx; Type: INDEX; Schema: eth; Owner: -
--
CREATE INDEX withdrawal_cids_block_number_idx ON eth.withdrawal_cids USING btree (block_number DESC);
--
-- Name: blocks_block_number_idx; Type: INDEX; Schema: ipld; Owner: -
--
CREATE INDEX blocks_block_number_idx ON ipld.blocks USING btree (block_number DESC);
--
-- Name: log_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.log_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_functions.insert_blocker();
--
-- Name: receipt_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.receipt_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_functions.insert_blocker();
--
-- Name: state_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.state_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_functions.insert_blocker();
--
-- Name: storage_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.storage_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_functions.insert_blocker();
--
-- Name: transaction_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.transaction_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_functions.insert_blocker();
--
-- Name: uncle_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.uncle_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_functions.insert_blocker();
--
-- Name: withdrawal_cids ts_insert_blocker; Type: TRIGGER; Schema: eth; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON eth.withdrawal_cids FOR EACH ROW EXECUTE FUNCTION _timescaledb_functions.insert_blocker();
--
-- Name: blocks ts_insert_blocker; Type: TRIGGER; Schema: ipld; Owner: -
--
CREATE TRIGGER ts_insert_blocker BEFORE INSERT ON ipld.blocks FOR EACH ROW EXECUTE FUNCTION _timescaledb_functions.insert_blocker();
--
-- PostgreSQL database dump complete
--