add removed flag; embed value in storage_cids

This commit is contained in:
i-norden 2023-01-23 17:12:50 -06:00
parent 241bb281eb
commit 713f6a9208
3 changed files with 13 additions and 4 deletions

View File

@ -7,10 +7,11 @@ CREATE TABLE IF NOT EXISTS eth.state_cids (
state_path BYTEA NOT NULL, state_path BYTEA NOT NULL,
diff BOOLEAN NOT NULL DEFAULT FALSE, diff BOOLEAN NOT NULL DEFAULT FALSE,
mh_key TEXT NOT NULL, mh_key TEXT NOT NULL,
balance NUMERIC NOT NULL, balance NUMERIC, -- NULL if "removed"
nonce BIGINT NOT NULL, nonce BIGINT, -- NULL if "removed"
code_hash VARCHAR(66) NOT NULL, code_hash VARCHAR(66), -- NULL if "removed"
storage_root VARCHAR(66) NOT NULL, storage_root VARCHAR(66), -- NULL if "removed"
removed BOOLEAN NOT NULL,
PRIMARY KEY (state_leaf_key, header_id, block_number) PRIMARY KEY (state_leaf_key, header_id, block_number)
); );

View File

@ -8,6 +8,8 @@ CREATE TABLE IF NOT EXISTS eth.storage_cids (
storage_path BYTEA NOT NULL, storage_path BYTEA NOT NULL,
diff BOOLEAN NOT NULL DEFAULT FALSE, diff BOOLEAN NOT NULL DEFAULT FALSE,
mh_key TEXT NOT NULL, 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) PRIMARY KEY (storage_leaf_key, state_leaf_key, header_id, block_number)
); );

View File

@ -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_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_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_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 -- storage node indexes
CREATE INDEX storage_block_number_index ON eth.storage_cids USING brin (block_number); 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_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_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_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 -- access list indexes
CREATE INDEX access_list_block_number_index ON eth.access_list_elements USING brin (block_number); 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; DROP INDEX eth.access_list_block_number_index;
-- storage node indexes -- storage node indexes
DROP INDEX eth.storage_removed_index;
DROP INDEX eth.storage_path_index; DROP INDEX eth.storage_path_index;
DROP INDEX eth.storage_header_id_index; DROP INDEX eth.storage_header_id_index;
DROP INDEX eth.storage_mh_block_number_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; DROP INDEX eth.storage_block_number_index;
-- state node indexes -- 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_path_index;
DROP INDEX eth.state_header_id_index; DROP INDEX eth.state_header_id_index;
DROP INDEX eth.state_mh_block_number_index; DROP INDEX eth.state_mh_block_number_index;