Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix database config and schema #32

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ parsing:
average_block_time: 1s

database:
url: postgresql://root:password@postgres:5432/root?sslmode=disable&search_path=public
name: root # This is the defaults, but might be updated
host: postgres
port: 5432
Expand Down Expand Up @@ -71,4 +72,4 @@ pricefeed:
units:
- denom: coreum
exponent: 6
price_id: coreum
price_id: coreum
108 changes: 4 additions & 104 deletions database/schema/02-bank.sql
Original file line number Diff line number Diff line change
@@ -1,110 +1,10 @@
/* ---- PARAMS ---- */
/* ---- SUPPLY ---- */

CREATE TABLE staking_params
CREATE TABLE supply
(
one_row_id BOOLEAN NOT NULL DEFAULT TRUE PRIMARY KEY,
params JSONB NOT NULL,
coins COIN[] NOT NULL,
height BIGINT NOT NULL,
CHECK (one_row_id)
);
CREATE INDEX staking_params_height_index ON staking_params (height);

/* ---- POOL ---- */

CREATE TABLE staking_pool
(
one_row_id BOOLEAN NOT NULL DEFAULT TRUE PRIMARY KEY,
bonded_tokens TEXT NOT NULL,
not_bonded_tokens TEXT NOT NULL,
unbonding_tokens TEXT NOT NULL,
staked_not_bonded_tokens TEXT NOT NULL,
height BIGINT NOT NULL,
CHECK (one_row_id)
);
CREATE INDEX staking_pool_height_index ON staking_pool (height);

/* ---- VALIDATORS INFO ---- */

CREATE TABLE validator_info
(
consensus_address TEXT NOT NULL UNIQUE PRIMARY KEY REFERENCES validator (consensus_address),
operator_address TEXT NOT NULL UNIQUE,
self_delegate_address TEXT REFERENCES account (address),
max_change_rate TEXT NOT NULL,
max_rate TEXT NOT NULL,
height BIGINT NOT NULL
);
CREATE INDEX validator_info_operator_address_index ON validator_info (operator_address);
CREATE INDEX validator_info_self_delegate_address_index ON validator_info (self_delegate_address);

CREATE TABLE validator_description
(
validator_address TEXT NOT NULL REFERENCES validator (consensus_address) PRIMARY KEY,
moniker TEXT,
identity TEXT,
avatar_url TEXT,
website TEXT,
security_contact TEXT,
details TEXT,
height BIGINT NOT NULL
);
CREATE INDEX validator_description_height_index ON validator_description (height);

CREATE TABLE validator_commission
(
validator_address TEXT NOT NULL REFERENCES validator (consensus_address) PRIMARY KEY,
commission DECIMAL NOT NULL,
min_self_delegation BIGINT NOT NULL,
height BIGINT NOT NULL
);
CREATE INDEX validator_commission_height_index ON validator_commission (height);

CREATE TABLE validator_voting_power
(
validator_address TEXT NOT NULL REFERENCES validator (consensus_address) PRIMARY KEY,
voting_power BIGINT NOT NULL,
height BIGINT NOT NULL REFERENCES block (height)
);
CREATE INDEX validator_voting_power_height_index ON validator_voting_power (height);

CREATE TABLE validator_status
(
validator_address TEXT NOT NULL REFERENCES validator (consensus_address) PRIMARY KEY,
status INT NOT NULL,
jailed BOOLEAN NOT NULL,
height BIGINT NOT NULL
);
CREATE INDEX validator_status_height_index ON validator_status (height);

/* ---- DOUBLE SIGN EVIDENCE ---- */

/*
* This holds the votes that is the evidence of a double sign.
* It should be updated on a BLOCK basis when a double sign occurs.
*/
CREATE TABLE double_sign_vote
(
id SERIAL PRIMARY KEY,
type SMALLINT NOT NULL,
height BIGINT NOT NULL,
round INT NOT NULL,
block_id TEXT NOT NULL,
validator_address TEXT NOT NULL REFERENCES validator (consensus_address),
validator_index INT NOT NULL,
signature TEXT NOT NULL,
UNIQUE (block_id, validator_address)
);
CREATE INDEX double_sign_vote_validator_address_index ON double_sign_vote (validator_address);
CREATE INDEX double_sign_vote_height_index ON double_sign_vote (height);

/*
* This holds the double sign evidences.
* It should be updated on a on BLOCK basis.
*/
CREATE TABLE double_sign_evidence
(
height BIGINT NOT NULL,
vote_a_id BIGINT NOT NULL REFERENCES double_sign_vote (id),
vote_b_id BIGINT NOT NULL REFERENCES double_sign_vote (id)
);
CREATE INDEX double_sign_evidence_height_index ON double_sign_evidence (height);
CREATE INDEX supply_height_index ON supply (height);