forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from vulcanize/v1.10.1-statediff-0.0.17
V1.10.1 statediff 0.0.17
- Loading branch information
Showing
18 changed files
with
1,912 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- +goose Up | ||
CREATE TABLE IF NOT EXISTS public.blocks ( | ||
key TEXT UNIQUE NOT NULL, | ||
data BYTEA NOT NULL | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE public.blocks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- +goose Up | ||
CREATE TABLE nodes ( | ||
id SERIAL PRIMARY KEY, | ||
client_name VARCHAR, | ||
genesis_block VARCHAR(66), | ||
network_id VARCHAR, | ||
node_id VARCHAR(128), | ||
chain_id INTEGER DEFAULT 1, | ||
CONSTRAINT node_uc UNIQUE (genesis_block, network_id, node_id, chain_id) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE nodes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- +goose Up | ||
CREATE SCHEMA eth; | ||
|
||
-- +goose Down | ||
DROP SCHEMA eth; |
23 changes: 23 additions & 0 deletions
23
statediff/db/migrations/00004_create_eth_header_cids_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- +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, | ||
UNIQUE (block_number, block_hash) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.header_cids; |
14 changes: 14 additions & 0 deletions
14
statediff/db/migrations/00005_create_eth_uncle_cids_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- +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) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.uncle_cids; |
16 changes: 16 additions & 0 deletions
16
statediff/db/migrations/00006_create_eth_transaction_cids_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- +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, | ||
UNIQUE (header_id, tx_hash) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.transaction_cids; |
20 changes: 20 additions & 0 deletions
20
statediff/db/migrations/00007_create_eth_receipt_cids_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- +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, | ||
cid TEXT NOT NULL, | ||
mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
contract VARCHAR(66), | ||
contract_hash VARCHAR(66), | ||
topic0s VARCHAR(66)[], | ||
topic1s VARCHAR(66)[], | ||
topic2s VARCHAR(66)[], | ||
topic3s VARCHAR(66)[], | ||
log_contracts VARCHAR(66)[], | ||
post_state VARCHAR(66), | ||
post_status INTEGER, | ||
UNIQUE (tx_id) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.receipt_cids; |
15 changes: 15 additions & 0 deletions
15
statediff/db/migrations/00008_create_eth_state_cids_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- +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) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.state_cids; |
15 changes: 15 additions & 0 deletions
15
statediff/db/migrations/00009_create_eth_storage_cids_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- +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) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.storage_cids; |
13 changes: 13 additions & 0 deletions
13
statediff/db/migrations/00010_create_eth_state_accouts_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- +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) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE eth.state_accounts; |
6 changes: 6 additions & 0 deletions
6
statediff/db/migrations/00011_create_postgraphile_comments.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- +goose Up | ||
COMMENT ON TABLE public.nodes IS E'@name NodeInfo'; | ||
COMMENT ON TABLE eth.transaction_cids IS E'@name EthTransactionCids'; | ||
COMMENT ON TABLE eth.header_cids IS E'@name EthHeaderCids'; | ||
COMMENT ON COLUMN public.nodes.node_id IS E'@name ChainNodeID'; | ||
COMMENT ON COLUMN eth.header_cids.node_id IS E'@name EthNodeID'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
CREATE FUNCTION eth.graphql_subscription() returns TRIGGER as $$ | ||
declare | ||
table_name text = TG_ARGV[0]; | ||
attribute text = TG_ARGV[1]; | ||
id text; | ||
begin | ||
execute 'select $1.' || quote_ident(attribute) | ||
using new | ||
into id; | ||
perform pg_notify('postgraphile:' || table_name, | ||
json_build_object( | ||
'__node__', json_build_array( | ||
table_name, | ||
id | ||
) | ||
)::text | ||
); | ||
return new; | ||
end; | ||
$$ language plpgsql; | ||
-- +goose StatementEnd | ||
|
||
CREATE TRIGGER header_cids_ai | ||
after INSERT ON eth.header_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('header_cids', 'id'); | ||
|
||
CREATE TRIGGER receipt_cids_ai | ||
after INSERT ON eth.receipt_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('receipt_cids', 'id'); | ||
|
||
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_cids_ai | ||
after INSERT ON eth.state_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('state_cids', 'id'); | ||
|
||
CREATE TRIGGER storage_cids_ai | ||
after INSERT ON eth.storage_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('storage_cids', 'id'); | ||
|
||
CREATE TRIGGER transaction_cids_ai | ||
after INSERT ON eth.transaction_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('transaction_cids', 'id'); | ||
|
||
CREATE TRIGGER uncle_cids_ai | ||
after INSERT ON eth.uncle_cids | ||
for each row | ||
execute procedure eth.graphql_subscription('uncle_cids', 'id'); | ||
|
||
-- +goose Down | ||
DROP TRIGGER uncle_cids_ai ON eth.uncle_cids; | ||
DROP TRIGGER transaction_cids_ai ON eth.transaction_cids; | ||
DROP TRIGGER storage_cids_ai ON eth.storage_cids; | ||
DROP TRIGGER state_cids_ai ON eth.state_cids; | ||
DROP TRIGGER state_accounts_ai ON eth.state_accounts; | ||
DROP TRIGGER receipt_cids_ai ON eth.receipt_cids; | ||
DROP TRIGGER header_cids_ai ON eth.header_cids; | ||
|
||
DROP FUNCTION eth.graphql_subscription(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
-- +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); | ||
|
||
-- 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_cid_index ON eth.receipt_cids USING btree (cid); | ||
|
||
CREATE INDEX rct_mh_index ON eth.receipt_cids USING btree (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); | ||
|
||
CREATE INDEX rct_topic0_index ON eth.receipt_cids USING gin (topic0s); | ||
|
||
CREATE INDEX rct_topic1_index ON eth.receipt_cids USING gin (topic1s); | ||
|
||
CREATE INDEX rct_topic2_index ON eth.receipt_cids USING gin (topic2s); | ||
|
||
CREATE INDEX rct_topic3_index ON eth.receipt_cids USING gin (topic3s); | ||
|
||
CREATE INDEX rct_log_contract_index ON eth.receipt_cids USING gin (log_contracts); | ||
|
||
-- 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); | ||
|
||
-- storage node indexes | ||
CREATE INDEX storage_state_id_index ON eth.storage_cids USING btree (state_id); | ||
|
||
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); | ||
|
||
-- state accounts indexes | ||
CREATE INDEX account_state_id_index ON eth.state_accounts USING btree (state_id); | ||
|
||
CREATE INDEX storage_root_index ON eth.state_accounts USING btree (storage_root); | ||
|
||
-- +goose Down | ||
-- state account indexes | ||
DROP INDEX eth.storage_root_index; | ||
DROP INDEX eth.account_state_id_index; | ||
|
||
-- storage node indexes | ||
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; | ||
|
||
-- state node indexes | ||
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_log_contract_index; | ||
DROP INDEX eth.rct_topic3_index; | ||
DROP INDEX eth.rct_topic2_index; | ||
DROP INDEX eth.rct_topic1_index; | ||
DROP INDEX eth.rct_topic0_index; | ||
DROP INDEX eth.rct_contract_hash_index; | ||
DROP INDEX eth.rct_contract_index; | ||
DROP INDEX eth.rct_mh_index; | ||
DROP INDEX eth.rct_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; | ||
|
||
-- 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; |
Oops, something went wrong.