From 050c1ae3dfd21bf4ad12cf24a62de233d74dd99b Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Tue, 18 Apr 2023 20:39:22 +0800 Subject: [PATCH 1/3] Startup script tweaks * forward goose command * don't idle migrations container --- scripts/startup_script.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/startup_script.sh b/scripts/startup_script.sh index 0535f5e..9e07753 100755 --- a/scripts/startup_script.sh +++ b/scripts/startup_script.sh @@ -1,6 +1,11 @@ #!/bin/sh # Runs the db migrations -set +x +set -e + +# Default command is "goose up" +if [[ $# -eq 0 ]]; then + set -- "up" +fi # Construct the connection string for postgres VDB_PG_CONNECT=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME:$DATABASE_PORT/$DATABASE_NAME?sslmode=disable @@ -8,12 +13,11 @@ VDB_PG_CONNECT=postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOSTNAME # Run the DB migrations echo "Connecting with: $VDB_PG_CONNECT" echo "Running database migrations" -./goose -dir migrations postgres "$VDB_PG_CONNECT" up +./goose -dir migrations postgres "$VDB_PG_CONNECT" "$@" # If the db migrations ran without err if [[ $? -eq 0 ]]; then echo "Migration process ran successfully" - tail -f /dev/null else echo "Could not run migrations. Are the database details correct?" exit 1 From e4e1b0ea1fbc00c61cec1f068282e8093fa3a5df Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Mon, 15 May 2023 00:32:50 +0800 Subject: [PATCH 2/3] Upgrade github action --- .github/workflows/publish.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 55a5693..39ae444 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -7,7 +7,7 @@ jobs: name: Run docker build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Get the version id: vars run: | From af9910d381d8acdb88ea1ce0ef4db3b95a8aa8d6 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Mon, 15 May 2023 14:17:32 +0800 Subject: [PATCH 3/3] Update schema dump --- schema.sql | 184 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 103 insertions(+), 81 deletions(-) diff --git a/schema.sql b/schema.sql index 3c14de7..fa247f9 100644 --- a/schema.sql +++ b/schema.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version 14.6 --- Dumped by pg_dump version 14.6 +-- Dumped by pg_dump version 14.7 (Homebrew) SET statement_timeout = 0; SET lock_timeout = 0; @@ -51,77 +51,59 @@ CREATE SCHEMA eth_meta; CREATE SCHEMA ipld; -SET default_tablespace = ''; - -SET default_table_access_method = heap; - -- --- Name: header_cids; Type: TABLE; Schema: eth; Owner: - +-- Name: header_result; Type: TYPE; Schema: public; Owner: - -- -CREATE TABLE eth.header_cids ( - block_number bigint NOT NULL, - block_hash character varying(66) NOT NULL, - parent_hash character varying(66) NOT NULL, - cid text NOT NULL, - td numeric NOT NULL, - node_ids character varying(128)[] NOT NULL, - reward numeric NOT NULL, - state_root character varying(66) NOT NULL, - tx_root character varying(66) NOT NULL, - receipt_root character varying(66) NOT NULL, - uncles_hash character varying(66) NOT NULL, - bloom bytea NOT NULL, - "timestamp" bigint NOT NULL, - coinbase character varying(66) NOT NULL +CREATE TYPE public.header_result AS ( + block_number bigint, + block_hash character varying(66), + parent_hash character varying(66), + cid text, + td numeric, + node_ids character varying(128)[], + reward numeric, + state_root character varying(66), + tx_root character varying(66), + receipt_root character varying(66), + uncles_hash character varying(66), + bloom bytea, + "timestamp" bigint, + coinbase character varying(66) ); --- --- Name: TABLE header_cids; Type: COMMENT; Schema: eth; Owner: - --- - -COMMENT ON TABLE eth.header_cids IS '@name EthHeaderCids'; - - --- --- Name: COLUMN header_cids.node_ids; Type: COMMENT; Schema: eth; Owner: - --- - -COMMENT ON COLUMN eth.header_cids.node_ids IS '@name EthNodeIDs'; - - -- -- Name: child_result; Type: TYPE; Schema: public; Owner: - -- CREATE TYPE public.child_result AS ( has_child boolean, - children eth.header_cids[] + children public.header_result[] ); -- --- Name: canonical_header_from_array(eth.header_cids[]); Type: FUNCTION; Schema: public; Owner: - +-- Name: canonical_header_from_array(public.header_result[]); Type: FUNCTION; Schema: public; Owner: - -- -CREATE FUNCTION public.canonical_header_from_array(headers eth.header_cids[]) RETURNS eth.header_cids +CREATE FUNCTION public.canonical_header_from_array(headers public.header_result[]) RETURNS public.header_result LANGUAGE plpgsql AS $$ DECLARE - canonical_header eth.header_cids; - canonical_child eth.header_cids; - header eth.header_cids; + canonical_header header_result; + canonical_child header_result; + header header_result; current_child_result child_result; - child_headers eth.header_cids[]; - current_header_with_child eth.header_cids; + child_headers header_result[]; + current_header_with_child header_result; has_children_count INT DEFAULT 0; BEGIN -- for each header in the provided set FOREACH header IN ARRAY headers LOOP -- check if it has any children - current_child_result = has_child(header.block_hash, header.block_number); + current_child_result = get_child(header.block_hash, header.block_number); IF current_child_result.has_child THEN -- if it does, take note has_children_count = has_children_count + 1; @@ -159,10 +141,10 @@ CREATE FUNCTION public.canonical_header_hash(height bigint) RETURNS character va LANGUAGE plpgsql AS $$ DECLARE - canonical_header eth.header_cids; - headers eth.header_cids[]; + canonical_header header_result; + headers header_result[]; header_count INT; - temp_header eth.header_cids; + temp_header header_result; BEGIN -- collect all headers at this height FOR temp_header IN @@ -187,6 +169,39 @@ END $$; +-- +-- Name: get_child(character varying, bigint); Type: FUNCTION; Schema: public; Owner: - +-- + +CREATE FUNCTION public.get_child(hash character varying, height bigint) RETURNS public.child_result + LANGUAGE plpgsql + AS $$ +DECLARE + child_height INT; + temp_child header_result; + new_child_result child_result; +BEGIN + child_height = height + 1; + -- short circuit if there are no children + SELECT exists(SELECT 1 + FROM eth.header_cids + WHERE parent_hash = hash + AND block_number = child_height + LIMIT 1) + INTO new_child_result.has_child; + -- collect all the children for this header + IF new_child_result.has_child THEN + FOR temp_child IN + SELECT * FROM eth.header_cids WHERE parent_hash = hash AND block_number = child_height + LOOP + new_child_result.children = array_append(new_child_result.children, temp_child); + END LOOP; + END IF; + RETURN new_child_result; +END +$$; + + -- -- Name: get_storage_at_by_hash(text, text, text); Type: FUNCTION; Schema: public; Owner: - -- @@ -277,39 +292,6 @@ END $$; --- --- Name: has_child(character varying, bigint); Type: FUNCTION; Schema: public; Owner: - --- - -CREATE FUNCTION public.has_child(hash character varying, height bigint) RETURNS public.child_result - LANGUAGE plpgsql - AS $$ -DECLARE - child_height INT; - temp_child eth.header_cids; - new_child_result child_result; -BEGIN - child_height = height + 1; - -- short circuit if there are no children - SELECT exists(SELECT 1 - FROM eth.header_cids - WHERE parent_hash = hash - AND block_number = child_height - LIMIT 1) - INTO new_child_result.has_child; - -- collect all the children for this header - IF new_child_result.has_child THEN - FOR temp_child IN - SELECT * FROM eth.header_cids WHERE parent_hash = hash AND block_number = child_height - LOOP - new_child_result.children = array_append(new_child_result.children, temp_child); - END LOOP; - END IF; - RETURN new_child_result; -END -$$; - - -- -- Name: was_state_leaf_removed(character varying, character varying); Type: FUNCTION; Schema: public; Owner: - -- @@ -344,6 +326,46 @@ CREATE FUNCTION public.was_state_leaf_removed_by_number(v_key character varying, $$; +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: header_cids; Type: TABLE; Schema: eth; Owner: - +-- + +CREATE TABLE eth.header_cids ( + block_number bigint NOT NULL, + block_hash character varying(66) NOT NULL, + parent_hash character varying(66) NOT NULL, + cid text NOT NULL, + td numeric NOT NULL, + node_ids character varying(128)[] NOT NULL, + reward numeric NOT NULL, + state_root character varying(66) NOT NULL, + tx_root character varying(66) NOT NULL, + receipt_root character varying(66) NOT NULL, + uncles_hash character varying(66) NOT NULL, + bloom bytea NOT NULL, + "timestamp" bigint NOT NULL, + coinbase character varying(66) NOT NULL +); + + +-- +-- Name: TABLE header_cids; Type: COMMENT; Schema: eth; Owner: - +-- + +COMMENT ON TABLE eth.header_cids IS '@name EthHeaderCids'; + + +-- +-- Name: COLUMN header_cids.node_ids; Type: COMMENT; Schema: eth; Owner: - +-- + +COMMENT ON COLUMN eth.header_cids.node_ids IS '@name EthNodeIDs'; + + -- -- Name: log_cids; Type: TABLE; Schema: eth; Owner: - -- @@ -889,7 +911,7 @@ CREATE INDEX uncle_block_number_index ON eth.uncle_cids USING btree (block_numbe -- Name: uncle_cid_block_number_index; Type: INDEX; Schema: eth; Owner: - -- -CREATE UNIQUE INDEX uncle_cid_block_number_index ON eth.uncle_cids USING btree (cid, block_number); +CREATE UNIQUE INDEX uncle_cid_block_number_index ON eth.uncle_cids USING btree (cid, block_number, index); --