-
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.
- Loading branch information
1 parent
da6d23a
commit 98ad2a3
Showing
27 changed files
with
209 additions
and
601 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 was deleted.
Oops, something went wrong.
190 changes: 82 additions & 108 deletions
190
storage/migrations/02_runtimes.up.sql → storage/migrations/01_runtimes.up.sql
Large diffs are not rendered by default.
Oops, something went wrong.
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,48 @@ | ||
-- Initialization of materialized views and tables for aggregate statistics on the consensus layer. | ||
|
||
BEGIN; | ||
|
||
-- Schema for aggregate statistics. | ||
CREATE SCHEMA IF NOT EXISTS stats; | ||
GRANT USAGE ON SCHEMA stats TO PUBLIC; | ||
|
||
-- min5_tx_volume stores the 5-minute tx volumes in 5-minute windows, per layer. | ||
CREATE TABLE stats.min5_tx_volume | ||
( | ||
layer TEXT NOT NULL, | ||
window_end TIMESTAMP WITH TIME ZONE NOT NULL, | ||
tx_volume UINT63 NOT NULL, | ||
|
||
PRIMARY KEY (layer, window_end) | ||
); | ||
|
||
-- daily_tx_volume stores the sliding window for the number of transactions per day per layer. | ||
CREATE TABLE stats.daily_tx_volume | ||
( | ||
layer TEXT NOT NULL, | ||
window_end TIMESTAMP WITH TIME ZONE NOT NULL, | ||
tx_volume UINT63 NOT NULL, | ||
|
||
PRIMARY KEY (layer, window_end) | ||
); | ||
-- Index for efficient query of the daily samples. | ||
CREATE INDEX ix_stats_daily_tx_volume_daily_windows ON stats.daily_tx_volume (layer, window_end) WHERE ((window_end AT TIME ZONE 'UTC')::time = '00:00:00'); | ||
|
||
-- daily_active_accounts stores the sliding window for the number of unique accounts per day | ||
-- that were involved in transactions. | ||
CREATE TABLE stats.daily_active_accounts | ||
( | ||
layer TEXT NOT NULL, | ||
window_end TIMESTAMP WITH TIME ZONE NOT NULL, | ||
active_accounts UINT63 NOT NULL, | ||
|
||
PRIMARY KEY (layer, window_end) | ||
); | ||
-- Index for efficient query of the daily samples. | ||
CREATE INDEX ix_stats_daily_active_accounts_daily_windows ON stats.daily_active_accounts (layer, window_end) WHERE ((window_end AT TIME ZONE 'UTC')::time = '00:00:00'); | ||
|
||
-- Grant others read-only use. This does NOT apply to future tables in the schema. | ||
GRANT SELECT ON ALL TABLES IN SCHEMA stats TO PUBLIC; | ||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA stats TO PUBLIC; | ||
|
||
COMMIT; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,59 @@ | ||
-- Helper functions for manipulating oasis data types. | ||
BEGIN; | ||
|
||
------------------------------------- | ||
-- Convenience functions for converting between eth-style and oasis-style addresses | ||
-- via lookups in the address_preimages table. | ||
|
||
-- Convenience function for retrieving the ethereum address associated with a given oasis address. | ||
CREATE OR REPLACE FUNCTION eth_preimage(addr oasis_addr) | ||
RETURNS BYTEA | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
DECLARE | ||
result BYTEA; | ||
BEGIN | ||
SELECT pre.address_data | ||
INTO result | ||
FROM chain.address_preimages pre | ||
WHERE pre.address = addr | ||
AND pre.context_identifier = 'oasis-runtime-sdk/address: secp256k1eth' | ||
AND pre.context_version = 0; | ||
RETURN result; | ||
END; | ||
END; | ||
$$; | ||
|
||
CREATE OR REPLACE FUNCTION derive_oasis_addr(eth_addr bytea) | ||
RETURNS TEXT | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
DECLARE | ||
result TEXT; | ||
BEGIN | ||
-- Check if the bytea data is exactly 20 bytes in length; this prevents accidentally accepting strings that are hex-encodings of the actual address, or similar. | ||
IF length(eth_addr) <> 20 THEN | ||
RAISE EXCEPTION 'Input address must be a bytea and exactly 20 bytes in length'; | ||
END IF; | ||
|
||
-- Look up the oasis-style address derived from evs.body.address. | ||
-- The derivation is just a keccak hash and we could theoretically compute it instead of looking it up, | ||
-- but the right hash function will only be easily available in postgres once openssl 3.2 is released | ||
-- (see https://github.com/openssl/openssl/issues/19304) and bundled into a postgres docker image, probably | ||
-- in early 2024. | ||
SELECT pre.address | ||
INTO result | ||
FROM chain.address_preimages pre | ||
WHERE pre.address_data = eth_addr | ||
AND pre.context_identifier = 'oasis-runtime-sdk/address: secp256k1eth' | ||
AND pre.context_version = 0; | ||
RETURN result; | ||
END; | ||
END; | ||
$$; | ||
|
||
|
||
------------------------------------- | ||
COMMIT; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.