-
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 #728 from EspressoSystems/ab/sqlite-support
ab/sqlite-support
- Loading branch information
Showing
23 changed files
with
762 additions
and
376 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 |
---|---|---|
|
@@ -8,4 +8,7 @@ lcov.info | |
|
||
/vsc | ||
|
||
/.vscode | ||
/.vscode | ||
|
||
# for sqlite databases created during the tests | ||
/tmp |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
ALTER TABLE transaction | ||
RENAME TO transactions; | ||
|
||
ALTER TABLE transactions | ||
RENAME COLUMN index TO idx; |
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,76 @@ | ||
CREATE TABLE header | ||
( | ||
height BIGINT PRIMARY KEY, | ||
hash TEXT NOT NULL UNIQUE, | ||
payload_hash TEXT NOT NULL, | ||
timestamp BIGINT NOT NULL, | ||
|
||
-- For convenience, we store the entire application-specific header type as JSON. Just like | ||
-- `leaf.leaf` and `leaf.qc`, this allows us to easily reconstruct the entire header using | ||
-- `serde_json`, and to run queries and create indexes on application-specific header fields | ||
-- without having a specific column for those fields. In many cases, this will enable new | ||
-- application-specific API endpoints to be implemented without altering the schema (beyond | ||
-- possibly adding an index for performance reasons). | ||
data JSONB NOT NULL | ||
); | ||
|
||
CREATE INDEX header_timestamp_idx ON header (timestamp); | ||
|
||
CREATE TABLE payload | ||
( | ||
height BIGINT PRIMARY KEY REFERENCES header (height) ON DELETE CASCADE, | ||
size INTEGER, | ||
data BLOB, | ||
num_transactions INTEGER | ||
); | ||
|
||
CREATE TABLE vid | ||
( | ||
height BIGINT PRIMARY KEY REFERENCES header (height) ON DELETE CASCADE, | ||
common BLOB NOT NULL, | ||
share BLOB | ||
); | ||
|
||
CREATE TABLE leaf | ||
( | ||
height BIGINT PRIMARY KEY REFERENCES header (height) ON DELETE CASCADE, | ||
hash TEXT NOT NULL UNIQUE, | ||
block_hash TEXT NOT NULL, | ||
|
||
-- For convenience, we store the entire leaf and justifying QC as JSON blobs. There is a bit of | ||
-- redundancy here with the indexed fields above, but it makes it easy to reconstruct the entire | ||
-- leaf without depending on the specific fields of the application-specific leaf type. We | ||
-- choose JSON over a binary format, even though it has a larger storage footprint, because | ||
-- Postgres actually has decent JSON support: we don't have to worry about escaping non-ASCII | ||
-- characters in inputs, and we can even do queries on the JSON and add indices over sub-objects | ||
-- of the JSON blobs. | ||
leaf JSONB NOT NULL, | ||
qc JSONB NOT NULL | ||
); | ||
|
||
CREATE TABLE transactions | ||
( | ||
hash TEXT NOT NULL, | ||
-- Block containing this transaction. | ||
block_height BIGINT NOT NULL REFERENCES header(height) ON DELETE CASCADE, | ||
-- Position within the block. Transaction indices are an application-specific type, so we store | ||
-- it as a serialized blob. We use JSON instead of a binary format so that the application can | ||
-- make use of the transaction index in its own SQL queries. | ||
idx JSONB NOT NULL, | ||
PRIMARY KEY (block_height, idx) | ||
); | ||
-- This index is not unique, because nothing stops HotShot from sequencing duplicate transactions. | ||
CREATE INDEX transaction_hash ON transactions (hash); | ||
|
||
CREATE TABLE pruned_height ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
-- The height of the last pruned block. | ||
last_height BIGINT NOT NULL | ||
); | ||
|
||
CREATE TABLE last_merklized_state_height ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
height BIGINT NOT NULL | ||
); | ||
|
||
CREATE INDEX header_payload_hash_idx ON header (payload_hash); |
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 @@ | ||
CREATE TABLE aggregate ( | ||
height BIGINT PRIMARY KEY REFERENCES header (height) ON DELETE CASCADE, | ||
num_transactions BIGINT NOT NULL, | ||
payload_size BIGINT NOT NULL | ||
); |
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
Oops, something went wrong.