Skip to content

Commit

Permalink
more migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew7234 committed Sep 30, 2024
1 parent 1bcb7a1 commit b3ccd5f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 93 deletions.
43 changes: 29 additions & 14 deletions storage/migrations/00_consensus.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,25 @@ CREATE TYPE public.sourcify_level AS ENUM ('partial', 'full');
CREATE TABLE chain.blocks
(
height UINT63 PRIMARY KEY,
block_hash HEX64 NOT NULL, -- NULL in 32_block_meta.up.sql
time TIMESTAMP WITH TIME ZONE NOT NULL, -- NULL in 32_block_meta.up.sql
num_txs UINT31 NOT NULL -- NULL in 32_block_meta.up.sql,
block_hash HEX64 NOT NULL,
time TIMESTAMP WITH TIME ZONE NOT NULL,
num_txs UINT31 NOT NULL,
gas_limit UINT_NUMERIC NOT NULL DEFAULT 0, -- uint64 in go; because the value might conceivably be >2^63, we use UINT_NUMERIC over UINT63 here.
size_limit UINT_NUMERIC NOT NULL DEFAULT 0, -- uint64 in go; because the value might conceivably be >2^63, we use UINT_NUMERIC over UINT63 here.
epoch UINT63 NOT NULL DEFAULT 0,

-- State Root Info
namespace TEXT NOT NULL, -- NULL in 32_block_meta.up.sql
version UINT63 NOT NULL, -- NULL in 32_block_meta.up.sql
state_root HEX64 NOT NULL -- NULL in 32_block_meta.up.sql
namespace TEXT NOT NULL,
version UINT63 NOT NULL,
state_root HEX64 NOT NULL,

-- added in 32_block_meta.up.sql
-- proposer_entity_id base64_ed25519_pubkey,
-- signer_entity_ids base64_ed25519_pubkey[]
proposer_entity_id base64_ed25519_pubkey,
signer_entity_ids base64_ed25519_pubkey[]
);
CREATE INDEX ix_blocks_time ON chain.blocks (time);
CREATE INDEX ix_blocks_block_hash ON chain.blocks (block_hash); -- Needed to lookup blocks by hash.
CREATE INDEX ix_blocks_proposer_entity_id ON chain.blocks (proposer_entity_id);
CREATE INDEX ix_blocks_signer_entity_ids ON chain.blocks USING gin(signer_entity_ids);

CREATE TABLE chain.transactions
(
Expand Down Expand Up @@ -130,9 +131,9 @@ CREATE TABLE chain.epochs
start_height UINT63 NOT NULL,
-- Max known height that belongs to the epoch.
end_height UINT63 NOT NULL CHECK (end_height >= start_height),
UNIQUE (start_height, end_height)
UNIQUE (start_height, end_height),

validators base64_ed25519_pubkey[],
validators base64_ed25519_pubkey[]
);
CREATE INDEX ix_epochs_id ON chain.epochs (id);

Expand Down Expand Up @@ -353,7 +354,8 @@ CREATE TABLE chain.latest_node_heights
height UINT63 NOT NULL
);

-- Historical validator information
-- Historical State Tracking

CREATE TABLE history.validators
(
id base64_ed25519_pubkey NOT NULL,
Expand All @@ -363,7 +365,20 @@ CREATE TABLE history.validators
escrow_balance_debonding UINT_NUMERIC NOT NULL,
escrow_total_shares_active UINT_NUMERIC NOT NULL,
escrow_total_shares_debonding UINT_NUMERIC NOT NULL,
num_delegators UINT63
num_delegators UINT63,
staking_rewards UINT_NUMERIC -- Note: staking rewards are granted in the first block of the subsequent epoch
);

CREATE TABLE history.escrow_events
(
tx_block UINT63 NOT NULL,
epoch UINT63 NOT NULL,
type TEXT NOT NULL,
delegatee oasis_addr NOT NULL,
delegator oasis_addr NOT NULL,
shares UINT_NUMERIC,
amount UINT_NUMERIC,
debonding_amount UINT_NUMERIC -- for slashing events
);

-- Indexing Progress Management
Expand All @@ -385,7 +400,7 @@ GRANT SELECT ON ALL TABLES IN SCHEMA chain TO PUBLIC;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA chain TO PUBLIC;
GRANT SELECT ON ALL TABLES IN SCHEMA analysis TO PUBLIC;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA analysis TO PUBLIC;
GRANT SELECT ON ALL TABLES IN SCHEMA history TO PUBLIC
GRANT SELECT ON ALL TABLES IN SCHEMA history TO PUBLIC;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA history TO PUBLIC;

COMMIT;
31 changes: 28 additions & 3 deletions storage/migrations/01_runtimes.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ CREATE TABLE chain.runtime_transactions
-- NOTE: The signer(s) and their nonce(s) are stored separately in runtime_transaction_signers.

fee UINT_NUMERIC NOT NULL,
-- Added in 29_rofl_tx_fees.up.sql
-- fee_proxy_module TEXT
-- fee_proxy_id TEXT
fee_symbol TEXT NOT NULL DEFAULT '',
fee_proxy_module TEXT,
fee_proxy_id BYTEA,
gas_limit UINT63 NOT NULL,
gas_used UINT63 NOT NULL,
size UINT31 NOT NULL,
Expand Down Expand Up @@ -78,6 +77,14 @@ CREATE TABLE chain.runtime_transactions
evm_encrypted_result_nonce BYTEA,
evm_encrypted_result_data BYTEA,

-- Encrypted data in encrypted Oasis-format transactions.
oasis_encrypted_format call_format,
oasis_encrypted_public_key BYTEA,
oasis_encrypted_data_nonce BYTEA,
oasis_encrypted_data_data BYTEA,
oasis_encrypted_result_nonce BYTEA,
oasis_encrypted_result_data BYTEA,

-- Error information.
success BOOLEAN, -- NULL means success is unknown (can happen in confidential runtimes)
error_module TEXT,
Expand Down Expand Up @@ -361,6 +368,24 @@ CREATE TABLE chain.evm_nfts (
CREATE INDEX ix_evm_nfts_stale ON chain.evm_nfts (runtime, token_address, nft_id) WHERE last_download_round IS NULL OR last_want_download_round > last_download_round;
CREATE INDEX ix_evm_nfts_owner ON chain.evm_nfts (runtime, owner, token_address, nft_id);

CREATE TABLE chain.evm_swap_pair_creations (
runtime runtime NOT NULL,
factory_address oasis_addr NOT NULL,
token0_address oasis_addr NOT NULL,
token1_address oasis_addr NOT NULL,
pair_address oasis_addr NOT NULL,
create_round UINT63 NOT NULL,
PRIMARY KEY (runtime, factory_address, token0_address, token1_address)
);

CREATE TABLE chain.evm_swap_pairs (
runtime runtime NOT NULL,
pair_address oasis_addr NOT NULL,
PRIMARY KEY (runtime, pair_address),
reserve0 uint_numeric NOT NULL,
reserve1 uint_numeric NOT NULL,
last_sync_round UINT63 NOT NULL
);

-- -- -- -- -- -- -- -- -- -- -- -- -- Module accounts -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Expand Down
9 changes: 0 additions & 9 deletions storage/migrations/29_rofl_tx_fees.up.sql

This file was deleted.

27 changes: 0 additions & 27 deletions storage/migrations/30_evm_swap_pairs.up.sql

This file was deleted.

12 changes: 0 additions & 12 deletions storage/migrations/31_runtime_txs_oasis_encryption.up.sql

This file was deleted.

10 changes: 0 additions & 10 deletions storage/migrations/32_block_meta.up.sql

This file was deleted.

18 changes: 0 additions & 18 deletions storage/migrations/33_staking_rewards.up.sql

This file was deleted.

0 comments on commit b3ccd5f

Please sign in to comment.