From 713f6a92086db6546b5d7d953a4bde58de79011d Mon Sep 17 00:00:00 2001 From: i-norden Date: Mon, 23 Jan 2023 17:12:50 -0600 Subject: [PATCH] add removed flag; embed value in storage_cids --- db/migrations/00008_create_eth_state_cids_table.sql | 9 +++++---- db/migrations/00009_create_eth_storage_cids_table.sql | 2 ++ db/migrations/00014_create_cid_indexes.sql | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/db/migrations/00008_create_eth_state_cids_table.sql b/db/migrations/00008_create_eth_state_cids_table.sql index f7fa60a..35a50fc 100644 --- a/db/migrations/00008_create_eth_state_cids_table.sql +++ b/db/migrations/00008_create_eth_state_cids_table.sql @@ -7,10 +7,11 @@ CREATE TABLE IF NOT EXISTS eth.state_cids ( state_path BYTEA NOT NULL, diff BOOLEAN NOT NULL DEFAULT FALSE, mh_key TEXT NOT NULL, - balance NUMERIC NOT NULL, - nonce BIGINT NOT NULL, - code_hash VARCHAR(66) NOT NULL, - storage_root VARCHAR(66) NOT NULL, + balance NUMERIC, -- NULL if "removed" + nonce BIGINT, -- NULL if "removed" + code_hash VARCHAR(66), -- NULL if "removed" + storage_root VARCHAR(66), -- NULL if "removed" + removed BOOLEAN NOT NULL, PRIMARY KEY (state_leaf_key, header_id, block_number) ); diff --git a/db/migrations/00009_create_eth_storage_cids_table.sql b/db/migrations/00009_create_eth_storage_cids_table.sql index e195e2c..1df408e 100644 --- a/db/migrations/00009_create_eth_storage_cids_table.sql +++ b/db/migrations/00009_create_eth_storage_cids_table.sql @@ -8,6 +8,8 @@ CREATE TABLE IF NOT EXISTS eth.storage_cids ( storage_path BYTEA NOT NULL, diff BOOLEAN NOT NULL DEFAULT FALSE, mh_key TEXT NOT NULL, + val BYTEA, -- NULL if "removed" + removed BOOLEAN NOT NULL, PRIMARY KEY (storage_leaf_key, state_leaf_key, header_id, block_number) ); diff --git a/db/migrations/00014_create_cid_indexes.sql b/db/migrations/00014_create_cid_indexes.sql index 4566c92..16b3829 100644 --- a/db/migrations/00014_create_cid_indexes.sql +++ b/db/migrations/00014_create_cid_indexes.sql @@ -34,6 +34,8 @@ CREATE INDEX state_cid_index ON eth.state_cids USING btree (cid); CREATE INDEX state_mh_block_number_index ON eth.state_cids USING btree (mh_key, block_number); CREATE INDEX state_header_id_index ON eth.state_cids USING btree (header_id); CREATE INDEX state_path_index ON eth.state_cids USING btree (state_path); +CREATE INDEX state_removed_index ON eth.state_cids USING btree (removed); +CREATE INDEX state_code_hash_index ON eth.state_cids USING btree (code_hash); -- could be useful for e.g. selecting all the state accounts with the same contract bytecode deployed -- storage node indexes CREATE INDEX storage_block_number_index ON eth.storage_cids USING brin (block_number); @@ -42,6 +44,7 @@ CREATE INDEX storage_cid_index ON eth.storage_cids USING btree (cid); CREATE INDEX storage_mh_block_number_index ON eth.storage_cids USING btree (mh_key, block_number); CREATE INDEX storage_header_id_index ON eth.storage_cids USING btree (header_id); CREATE INDEX storage_path_index ON eth.storage_cids USING btree (state_path); +CREATE INDEX storage_removed_index ON eth.storage_cids USING btree (removed); -- access list indexes CREATE INDEX access_list_block_number_index ON eth.access_list_elements USING brin (block_number); @@ -79,6 +82,7 @@ DROP INDEX eth.access_list_element_address_index; DROP INDEX eth.access_list_block_number_index; -- storage node indexes +DROP INDEX eth.storage_removed_index; DROP INDEX eth.storage_path_index; DROP INDEX eth.storage_header_id_index; DROP INDEX eth.storage_mh_block_number_index; @@ -88,6 +92,8 @@ DROP INDEX eth.storage_state_leaf_key_index; DROP INDEX eth.storage_block_number_index; -- state node indexes +DROP INDEX eth.state_code_hash_index; +DROP INDEX eth.state_removed_index; DROP INDEX eth.state_path_index; DROP INDEX eth.state_header_id_index; DROP INDEX eth.state_mh_block_number_index;