-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated proposal Monitor insert * trying to make assetHolders() faster * Fixed Smart Contract apis to actually return data * Added requested NFT apis * Updated existing NFT apis with additional data * Started using Kotlin coroutines * Started integrating with Kotlin protobuf supported functions * Added Missed Blocks apis for devops * Fixed tx_gas_fee_volume_* aggregations closes: #253 closes: #254 closes: #255 closes: #257 closes: #258
- Loading branch information
Carolyn Russell
authored
Nov 18, 2021
1 parent
dd6d58c
commit ff3f143
Showing
46 changed files
with
901 additions
and
341 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
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
65 changes: 65 additions & 0 deletions
65
database/src/main/resources/db/migration/V1_36__Update_gas_fee_volumes.sql
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,65 @@ | ||
SELECT 'Update update_gas_fee_volume() procedure' AS comment; | ||
-- Update gas stats with latest data | ||
CREATE OR REPLACE PROCEDURE update_gas_fee_volume() | ||
LANGUAGE plpgsql | ||
AS | ||
$$ | ||
DECLARE | ||
unprocessed_daily_times TIMESTAMP[]; | ||
unprocessed_hourly_times TIMESTAMP[]; | ||
unprocessed_ids INT[]; | ||
BEGIN | ||
-- Collect unprocessed message timestamps (grouped by day and hour) | ||
SELECT array_agg(DISTINCT date_trunc('DAY', tx_timestamp)) FROM tx_gas_cache WHERE processed = false INTO unprocessed_daily_times; | ||
SELECT array_agg(DISTINCT date_trunc('HOUR', tx_timestamp)) FROM tx_gas_cache WHERE processed = false INTO unprocessed_hourly_times; | ||
SELECT array_agg(id) FROM tx_gas_cache WHERE processed = false INTO unprocessed_ids; | ||
|
||
-- Update daily stats for unprocessed messages | ||
-- Reprocess daily stats for the day that unprocessed messages fall in | ||
INSERT | ||
INTO tx_gas_fee_volume_day | ||
SELECT date_trunc('DAY', tx_timestamp) AS tx_timestamp, | ||
sum(gas_wanted) AS gas_wanted, | ||
sum(gas_used) AS gas_used, | ||
sum((tx_v2 -> 'tx' -> 'auth_info' -> 'fee' -> 'amount' -> 0 ->> 'amount')::DOUBLE PRECISION) AS fee_amount | ||
FROM tx_cache | ||
WHERE date_trunc('DAY', tx_timestamp) = ANY (unprocessed_daily_times) | ||
GROUP BY date_trunc('DAY', tx_timestamp) | ||
ON CONFLICT (tx_timestamp) | ||
DO UPDATE | ||
SET gas_wanted = excluded.gas_wanted, | ||
gas_used = excluded.gas_used, | ||
fee_amount = excluded.fee_amount; | ||
|
||
-- Update hourly stats for unprocessed messages | ||
-- Reprocess hourly stats for the day that unprocessed messages fall in | ||
INSERT | ||
INTO tx_gas_fee_volume_hour | ||
SELECT date_trunc('HOUR', tx_timestamp) AS tx_timestamp, | ||
sum(gas_wanted) AS gas_wanted, | ||
sum(gas_used) AS gas_used, | ||
sum((tx_v2 -> 'tx' -> 'auth_info' -> 'fee' -> 'amount' -> 0 ->> 'amount')::DOUBLE PRECISION) AS fee_amount | ||
FROM tx_cache | ||
WHERE date_trunc('HOUR', tx_timestamp) = ANY (unprocessed_hourly_times) | ||
GROUP BY date_trunc('HOUR', tx_timestamp) | ||
ON CONFLICT (tx_timestamp) | ||
DO UPDATE | ||
SET gas_wanted = excluded.gas_wanted, | ||
gas_used = excluded.gas_used, | ||
fee_amount = excluded.fee_amount; | ||
|
||
-- Update complete. Now mark records as 'processed'. | ||
UPDATE tx_gas_cache | ||
SET processed = true | ||
WHERE id = ANY (unprocessed_ids); | ||
|
||
RAISE INFO 'UPDATED gas fee volume'; | ||
END; | ||
$$; | ||
|
||
SELECT 'Updating tx_gas_cache to reset' AS comment; | ||
UPDATE tx_gas_cache | ||
SET processed = false; | ||
|
||
SELECT 'Calling procedure to bring up to date' AS comment; | ||
CALL update_gas_fee_volume(); |
35 changes: 35 additions & 0 deletions
35
database/src/main/resources/db/migration/V1_37__Add_missed_blocks_period_function.sql
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,35 @@ | ||
CREATE OR REPLACE FUNCTION missed_block_periods(fromHeight int, toHeight int, address varchar(128) = NULL) | ||
RETURNS TABLE (val_cons_address varchar(128), blocks int[]) AS | ||
$func$ | ||
DECLARE | ||
r missed_blocks; -- use table type as row variable | ||
r0 missed_blocks; | ||
BEGIN | ||
|
||
FOR r IN | ||
SELECT | ||
* | ||
FROM missed_blocks t | ||
WHERE t.block_height between fromHeight and toHeight | ||
AND (address IS NULL OR t.val_cons_address = address) | ||
ORDER BY t.val_cons_address, t.block_height | ||
LOOP | ||
IF ( r.val_cons_address, r.block_height) | ||
<> (r0.val_cons_address, r0.block_height + 1) THEN -- not true for first row | ||
|
||
RETURN QUERY | ||
SELECT r0.val_cons_address, blocks; -- output row | ||
|
||
blocks := ARRAY[r.block_height]; -- start new array | ||
ELSE | ||
blocks := blocks || r.block_height; -- add to array - year can be NULL, too | ||
END IF; | ||
|
||
r0 := r; -- remember last row | ||
END LOOP; | ||
|
||
RETURN QUERY -- output last iteration | ||
SELECT r0.val_cons_address, blocks; | ||
|
||
END | ||
$func$ LANGUAGE plpgsql; |
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
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 @@ | ||
Track when a scope owner/value owner/data access is initiated or updated. |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
kotlin.code.style=official | ||
kapt.use.worker.api=false | ||
kapt.incremental.apt=false | ||
org.gradle.jvmargs=-Xmx4096M |
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
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
Oops, something went wrong.