From e81da697bc4c55f3b65bf3b6aad1024ade938968 Mon Sep 17 00:00:00 2001 From: Arijit Das Date: Mon, 27 Sep 2021 17:14:27 +0530 Subject: [PATCH] Fix query and add debug logs. --- .../00014_create_stored_functions.sql | 32 +++++++------------ docker-compose.yml | 1 + 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/db/migrations/00014_create_stored_functions.sql b/db/migrations/00014_create_stored_functions.sql index 778aeb3b..e0374636 100644 --- a/db/migrations/00014_create_stored_functions.sql +++ b/db/migrations/00014_create_stored_functions.sql @@ -1,26 +1,18 @@ -- +goose Up -- +goose StatementBegin -- returns if a state leaf node was removed within the provided block number -CREATE OR REPLACE FUNCTION was_state_leaf_removed(key character varying, hash character varying) RETURNS boolean - LANGUAGE plpgsql -AS $$ -DECLARE - rec RECORD; -BEGIN - FOR rec IN SELECT state_cids.node_type - FROM eth.state_cids - INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id) - WHERE state_leaf_key = key - AND block_number <= (SELECT block_number FROM eth.header_cids WHERE block_hash = hash) - ORDER BY state_cids.id DESC LIMIT 1 - LOOP - IF rec.node_type = 3 THEN - RETURN TRUE; - END IF; - END LOOP; - RETURN FALSE; -END; -$$; +CREATE OR REPLACE FUNCTION was_state_leaf_removed(key character varying, hash character varying) + RETURNS boolean AS $$ + SELECT state_cids.node_type = 3 + FROM eth.state_cids + INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id) + WHERE state_leaf_key = key + AND block_number <= (SELECT block_number + FROM eth.header_cids + WHERE block_hash = hash) + ORDER BY block_number DESC LIMIT 1; +$$ +language sql; -- +goose StatementEnd -- +goose StatementBegin diff --git a/docker-compose.yml b/docker-compose.yml index c24619bc..2ef02cfd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,6 +39,7 @@ services: - vdb_db_eth_server:/var/lib/postgresql/data ports: - "127.0.0.1:8077:5432" + command: ["postgres", "-c", "log_statement=all"] eth-server: restart: unless-stopped