Skip to content

Commit ee63dfd

Browse files
committed
Add SQL Format updates as per SQLFluff guidelines (#226)
1. Fix Asset Info Cache (include mint/burn tx rather than sum for meta consideration) 2. Update SQLs as per SQLFluff linting guidelines: - [x] 00_blockchain - [x] 01_cached_tables - [x] 02_indexes - [x] account - [x] address - [x] assets - [x] blocks - [x] epoch - [x] pool - [x] script - [x] transactions - [x] views 3. Fix `_last_active_stake_validated_epoch` in active_stake_cache (#222) 4. Typo for `pool_history_cache.sql` as well as add a check to ensure epoch_info_cache has run at least once prior to pool_history_cache (#223) 5. Move control_table entry in cache tables to the end (instead of start). ## Where should the reviewer start? Not really sure, too big to drill down 🙁 , we shouldnt have added any functional changes as part of linting. I expect us to cover review as part of tests itself ## Motivation and context Across months, different folks added SQL updates using different patterns, making it difficult to align/scan/automate linting ## How has this been tested? Was tested on guildnet as per below: - [x] Run `./setup-grest.sh -r -b lint` - [x] Wait for cache to be re-populated - [x] Run schemathesis tests
1 parent 6d8a8be commit ee63dfd

File tree

72 files changed

+2982
-3156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2982
-3156
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
tests/**/__pycache__
22
tests/**/.*
33
.vscode
4+
.swp

files/grest/.sqlfluff

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[sqlfluff]
2+
dialect = postgres
3+
exclude_rules = structure.column_order, references.keywords
4+
max_line_length=260
5+
recurse = 0
6+
capitalisation_policy = upper
7+
extended_capitalisation_policy = upper
8+
idented_joins = True
9+
indented_using_on = False
10+
tab_space_size = 2
11+
large_file_skip_byte_limit=35000
12+
13+
[sqlfluff:indentation]
14+
tab_space_size = 2
15+
allow_implicit_indents = True
16+
17+
[sqlfluff:rules:convention.count_rows]
18+
prefer_count_1 = True
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
CREATE FUNCTION grest.genesis ()
2-
RETURNS TABLE (
3-
NETWORKMAGIC varchar,
4-
NETWORKID varchar,
5-
ACTIVESLOTCOEFF varchar,
6-
UPDATEQUORUM varchar,
7-
MAXLOVELACESUPPLY varchar,
8-
EPOCHLENGTH varchar,
9-
SYSTEMSTART integer,
10-
SLOTSPERKESPERIOD varchar,
11-
SLOTLENGTH varchar,
12-
MAXKESREVOLUTIONS varchar,
13-
SECURITYPARAM varchar,
14-
ALONZOGENESIS varchar
15-
)
16-
LANGUAGE PLPGSQL
17-
AS $$
1+
CREATE OR REPLACE FUNCTION grest.genesis()
2+
RETURNS TABLE (
3+
networkmagic varchar,
4+
networkid varchar,
5+
activeslotcoeff varchar,
6+
updatequorum varchar,
7+
maxlovelacesupply varchar,
8+
epochlength varchar,
9+
systemstart integer,
10+
slotsperkesperiod varchar,
11+
slotlength varchar,
12+
maxkesrevolutions varchar,
13+
securityparam varchar,
14+
alonzogenesis varchar
15+
)
16+
LANGUAGE plpgsql
17+
AS $$
1818
BEGIN
1919
RETURN QUERY
2020
SELECT
21-
g.NETWORKMAGIC,
22-
g.NETWORKID,
23-
g.ACTIVESLOTCOEFF,
24-
g.UPDATEQUORUM,
25-
g.MAXLOVELACESUPPLY,
26-
g.EPOCHLENGTH,
27-
EXTRACT(epoch from g.SYSTEMSTART::timestamp)::integer,
28-
g.SLOTSPERKESPERIOD,
29-
g.SLOTLENGTH,
30-
g.MAXKESREVOLUTIONS,
31-
g.SECURITYPARAM,
32-
g.ALONZOGENESIS
21+
g.networkmagic,
22+
g.networkid,
23+
g.activeslotcoeff,
24+
g.updatequorum,
25+
g.maxlovelacesupply,
26+
g.epochlength,
27+
EXTRACT(EPOCH FROM g.systemstart::timestamp)::integer,
28+
g.slotsperkesperiod,
29+
g.slotlength,
30+
g.maxkesrevolutions,
31+
g.securityparam,
32+
g.alonzogenesis
3333
FROM
34-
grest.genesis g;
34+
grest.genesis AS g;
3535
END;
3636
$$;

files/grest/rpc/00_blockchain/param_updates.sql

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
CREATE OR REPLACE FUNCTION grest.param_updates ()
2-
RETURNS TABLE (
3-
tx_hash text,
4-
block_height word31type,
5-
block_time integer,
6-
epoch_no word31type,
7-
data jsonb
8-
)
9-
LANGUAGE PLPGSQL
10-
AS $$
11-
1+
CREATE OR REPLACE FUNCTION grest.param_updates()
2+
RETURNS TABLE (
3+
tx_hash text,
4+
block_height word31type,
5+
block_time integer,
6+
epoch_no word31type,
7+
data jsonb
8+
)
9+
LANGUAGE plpgsql
10+
AS $$
1211
BEGIN
1312
RETURN QUERY
1413
SELECT DISTINCT ON (pp.registered_tx_id)
15-
ENCODE(t.hash,'hex') as tx_hash,
14+
ENCODE(t.hash,'hex') AS tx_hash,
1615
b.block_no AS block_height,
17-
EXTRACT(epoch from b.time)::integer as block_time,
16+
EXTRACT(EPOCH FROM b.time)::integer AS block_time,
1817
b.epoch_no,
1918
JSONB_STRIP_NULLS(JSONB_BUILD_OBJECT(
2019
'min_fee_a', pp.min_fee_a,
@@ -47,13 +46,12 @@ BEGIN
4746
'max_collateral_inputs', pp.max_collateral_inputs,
4847
'coins_per_utxo_size', pp.coins_per_utxo_size
4948
)) AS data
50-
FROM
51-
public.param_proposal pp
52-
INNER JOIN tx t ON t.id = pp.registered_tx_id
53-
INNER JOIN block b ON t.block_id = b.id
54-
LEFT JOIN cost_model CM ON CM.id = pp.cost_model_id
55-
;
49+
FROM
50+
public.param_proposal pp
51+
INNER JOIN tx t ON t.id = pp.registered_tx_id
52+
INNER JOIN block b ON t.block_id = b.id
53+
LEFT JOIN cost_model CM ON CM.id = pp.cost_model_id;
5654
END;
5755
$$;
5856

59-
COMMENT ON FUNCTION grest.param_updates IS 'Parameter updates applied to the network';
57+
COMMENT ON FUNCTION grest.param_updates IS 'Parameter updates applied to the network'; -- noqa: LT01
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
CREATE FUNCTION grest.tip ()
2-
RETURNS TABLE (
3-
hash text,
4-
epoch_no word31type,
5-
abs_slot word63type,
6-
epoch_slot word31type,
7-
block_no word31type,
8-
block_time integer
9-
)
10-
LANGUAGE PLPGSQL
11-
AS $$
1+
CREATE OR REPLACE FUNCTION grest.tip()
2+
RETURNS TABLE (
3+
hash text,
4+
epoch_no word31type,
5+
abs_slot word63type,
6+
epoch_slot word31type,
7+
block_no word31type,
8+
block_time integer
9+
)
10+
LANGUAGE plpgsql
11+
AS $$
1212
BEGIN
1313
RETURN QUERY
1414
SELECT
15-
ENCODE(B.HASH::bytea, 'hex') AS BLOCK_HASH,
16-
b.EPOCH_NO AS EPOCH_NO,
17-
b.SLOT_NO AS ABS_SLOT,
18-
b.EPOCH_SLOT_NO AS EPOCH_SLOT,
19-
b.BLOCK_NO,
20-
EXTRACT(EPOCH from b.TIME)::integer
15+
ENCODE(b.hash::bytea, 'hex') AS block_hash,
16+
b.epoch_no AS epoch_no,
17+
b.slot_no AS abs_slot,
18+
b.epoch_slot_no AS epoch_slot,
19+
b.block_no,
20+
EXTRACT(EPOCH FROM b.time)::integer
2121
FROM
22-
BLOCK B
22+
block b
2323
ORDER BY
24-
B.ID DESC
24+
b.id DESC
2525
LIMIT 1;
2626
END;
2727
$$;
2828

29-
COMMENT ON FUNCTION grest.tip IS 'Get the tip info about the latest block seen by chain';
30-
29+
COMMENT ON FUNCTION grest.tip IS 'Get the tip info about the latest block seen by chain'; -- noqa: LT01
Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
1-
CREATE FUNCTION grest.totals (_epoch_no numeric DEFAULT NULL)
2-
RETURNS TABLE (
3-
epoch_no word31type,
4-
circulation text,
5-
treasury text,
6-
reward text,
7-
supply text,
8-
reserves text
9-
)
10-
LANGUAGE PLPGSQL
11-
AS $$
1+
CREATE OR REPLACE FUNCTION grest.totals(_epoch_no numeric DEFAULT NULL)
2+
RETURNS TABLE (
3+
epoch_no word31type,
4+
circulation text,
5+
treasury text,
6+
reward text,
7+
supply text,
8+
reserves text
9+
)
10+
LANGUAGE plpgsql
11+
AS $$
1212
BEGIN
1313
IF _epoch_no IS NULL THEN
1414
RETURN QUERY (
1515
SELECT
16-
ap.epoch_no, ap.utxo::text, ap.treasury::text, ap.rewards::text, (ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text as supply, ap.reserves::text
17-
FROM
18-
public.ada_pots as ap
19-
ORDER BY
20-
ap.epoch_no DESC) ;
16+
ap.epoch_no,
17+
ap.utxo::text,
18+
ap.treasury::text,
19+
ap.rewards::text,
20+
(ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text AS supply,
21+
ap.reserves::text
22+
FROM
23+
public.ada_pots AS ap
24+
ORDER BY
25+
ap.epoch_no DESC);
2126
ELSE
2227
RETURN QUERY (
2328
SELECT
24-
ap.epoch_no, ap.utxo::text, ap.treasury::text, ap.rewards::text, (ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text as supply, ap.reserves::text
25-
FROM
26-
public.ada_pots as ap
27-
WHERE
28-
ap.epoch_no = _epoch_no
29-
ORDER BY
30-
ap.epoch_no DESC);
29+
ap.epoch_no, ap.utxo::text,
30+
ap.treasury::text,
31+
ap.rewards::text,
32+
(ap.treasury + ap.rewards + ap.utxo + ap.deposits + ap.fees)::text AS supply,
33+
ap.reserves::text
34+
FROM
35+
public.ada_pots AS ap
36+
WHERE
37+
ap.epoch_no = _epoch_no
38+
ORDER BY
39+
ap.epoch_no DESC);
3140
END IF;
3241
END;
3342
$$;
3443

35-
COMMENT ON FUNCTION grest.totals IS 'Get the circulating utxo, treasury, rewards, supply and reserves in lovelace for specified epoch, all epochs if empty';
36-
44+
COMMENT ON FUNCTION grest.totals IS 'Get the circulating utxo, treasury, rewards, supply and reserves in lovelace for specified epoch, all epochs if empty'; -- noqa: LT01

0 commit comments

Comments
 (0)