From 92f734a08adaad12dde5cb1afc15787967d4ccee Mon Sep 17 00:00:00 2001 From: Robert Martin-Legene <robert@martin-legene.dk> Date: Wed, 2 Sep 2020 06:28:00 -0300 Subject: [PATCH] Current status commit --- docker-compose.yml | 13 +-- postgres/10-postgres.sql | 175 +++++++++++++------------------------ postgres/90-add-db-user.sh | 6 ++ 3 files changed, 74 insertions(+), 120 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e250889..2682b9d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -37,7 +37,7 @@ services: driver: "json-file" options: max-file: "5" - max-size: "10m" + max-size: "50m" geth: #image: bfaar/nodo @@ -46,6 +46,7 @@ services: ports: - 8545:8545 - 8546:8546 + - 30303:30303 volumes: - geth:/home/bfa/bfa logging: @@ -55,11 +56,11 @@ services: max-size: "10m" stop_grace_period: 300s -# adminer: -# image: adminer -# restart: always -# ports: -# - 8080:8080 + adminer: + image: adminer + restart: always + ports: + - 8080:8080 volumes: pgdata: diff --git a/postgres/10-postgres.sql b/postgres/10-postgres.sql index a29279e..01f2ec6 100644 --- a/postgres/10-postgres.sql +++ b/postgres/10-postgres.sql @@ -12,17 +12,12 @@ CREATE SEQUENCE account_id_seq START 1000 CACHE 1; CREATE TABLE "public"."account" ( - "id" bigint - DEFAULT nextval('account_id_seq') - NOT NULL, - "address" character(42) - NOT NULL, - "shortname" character varying(16), - "name" character varying(255), - CONSTRAINT "account_id" - PRIMARY KEY ("id"), - CONSTRAINT "account_hash" - UNIQUE ("address") + "id" bigint NOT NULL DEFAULT nextval('account_id_seq'), + "address" character(42) NOT NULL, + "shortname" character varying(16), + "name" character varying(255), + CONSTRAINT "account_id" PRIMARY KEY ("id"), + CONSTRAINT "account_hash" UNIQUE ("address") ) WITH (oids = false); CREATE SEQUENCE blockhash_id_seq @@ -32,116 +27,68 @@ CREATE SEQUENCE blockhash_id_seq START 1000000 CACHE 1; CREATE TABLE "public"."blockhash" ( - "id" bigint - DEFAULT nextval('blockhash_id_seq') - NOT NULL, - "hash" character(66) - NOT NULL, - CONSTRAINT "blockhash_id" - PRIMARY KEY ("id"), - CONSTRAINT "blockhash_hash" - UNIQUE ("hash") + "id" bigint NOT NULL DEFAULT nextval('blockhash_id_seq'), + "hash" character(66) NOT NULL, + CONSTRAINT "blockhash_id" PRIMARY KEY ("id"), + CONSTRAINT "blockhash_hash" UNIQUE ("hash") ) WITH (oids = false); CREATE TABLE "public"."block" ( - "id" bigint NOT NULL, - "parentBlockhashId" bigint, - "number" bigint NOT NULL, - "sealerAccountId" bigint, - "timestamp" bigint NOT NULL, - "difficulty" smallint NOT NULL, - "gasUsed" numeric(79) NOT NULL, - "gasLimit" numeric(79) NOT NULL, - "size" bigint NOT NULL, - CONSTRAINT "block_id" - PRIMARY KEY ("id"), - CONSTRAINT "block_sealerAccountId_fkey" - FOREIGN KEY ("sealerAccountId") - REFERENCES account(id) - NOT DEFERRABLE, - CONSTRAINT "block_id_fkey" - FOREIGN KEY (id) - REFERENCES blockhash(id) - NOT DEFERRABLE, - CONSTRAINT "block_parentBlockhashId_fkey" - FOREIGN KEY ("parentBlockhashId") - REFERENCES blockhash(id) - NOT DEFERRABLE + "id" bigint NOT NULL, + "parentBlockhashId" bigint, + "number" bigint NOT NULL, + "sealerAccountId" bigint, + "timestamp" bigint NOT NULL, + "difficulty" smallint NOT NULL, + "gasUsed" numeric(79) NOT NULL, + "gasLimit" numeric(79) NOT NULL, + "size" bigint NOT NULL, + CONSTRAINT "block_id" PRIMARY KEY ("id"), + CONSTRAINT "block_sealerAccountId_fkey" FOREIGN KEY ("sealerAccountId") REFERENCES account(id) NOT DEFERRABLE, + CONSTRAINT "block_id_fkey" FOREIGN KEY ("id") REFERENCES blockhash(id) NOT DEFERRABLE, + CONSTRAINT "block_parentBlockhashId_fkey" FOREIGN KEY ("parentBlockhashId") REFERENCES blockhash(id) NOT DEFERRABLE ) WITH (oids = false); -CREATE INDEX "block_parentBlockHashId" - ON "public"."block" - USING btree ("parentBlockhashId"); -CREATE INDEX "block_sealerAccountId" - ON "public"."block" - USING btree ("sealerAccountId"); -CREATE INDEX "block_number" - ON "public"."block" - USING btree ("number"); -CREATE INDEX "block_timestamp" - ON "public"."block" - USING btree ("timestamp"); +CREATE INDEX "block_parentBlockHashId" ON "public"."block" ("parentBlockhashId"); +CREATE INDEX "block_sealerAccountId" ON "public"."block" ("sealerAccountId"); +CREATE INDEX "block_number" ON "public"."block" ("number"); +CREATE INDEX "block_timestamp" ON "public"."block" ("timestamp"); CREATE TABLE "public"."transaction" ( - "hash" character(66) - NOT NULL, - "blockId" bigint, - "type" transactiontype - DEFAULT 'unknown' - NOT NULL, - "nonce" bigint - NOT NULL, - "gas" numeric(79) - NOT NULL, - "gasPrice" numeric(79) - NOT NULL, - "value" numeric(79) - NOT NULL, - "fromAccountId" bigint - NOT NULL, - "toAccountId" bigint, - "contractaddressAccountId" - bigint, - "status" smallint, - "gasUsed" numeric(79), - "inputlen" integer - NOT NULL, - "input" text - NOT NULL, - CONSTRAINT "transaction_contractaddressAccountId_fkey" - FOREIGN KEY ("contractaddressAccountId") - REFERENCES account(id) - NOT DEFERRABLE, - CONSTRAINT "transaction_fromAccountId_fkey" - FOREIGN KEY ("fromAccountId") - REFERENCES account(id) - NOT DEFERRABLE, - CONSTRAINT "transaction_toAccountId_fkey" - FOREIGN KEY ("toAccountId") - REFERENCES account(id) - NOT DEFERRABLE, - CONSTRAINT "transaction_blockId_fkey" - FOREIGN KEY ("blockId") - REFERENCES block(id) - NOT DEFERRABLE + "hash" character(66) NOT NULL, + "blockId" bigint, + "type" transactiontype NOT NULL DEFAULT 'unknown', + "nonce" bigint NOT NULL, + "gas" numeric(79) NOT NULL, + "gasPrice" numeric(79) NOT NULL, + "value" numeric(79) NOT NULL, + "fromAccountId" bigint NOT NULL, + "toAccountId" bigint, + "contractaddressAccountId" bigint, + "status" smallint, + "gasUsed" numeric(79), + "inputlen" integer NOT NULL, + "input" text NOT NULL, + CONSTRAINT "tx_cntrctaddrAccntId_fkey" FOREIGN KEY ("contractaddressAccountId") REFERENCES account(id) NOT DEFERRABLE, + CONSTRAINT "tx_fromAccountId_fkey" FOREIGN KEY ("fromAccountId") REFERENCES account(id) NOT DEFERRABLE, + CONSTRAINT "tx_toAccountId_fkey" FOREIGN KEY ("toAccountId") REFERENCES account(id) NOT DEFERRABLE, + CONSTRAINT "tx_blockId_fkey" FOREIGN KEY ("blockId") REFERENCES block(id) NOT DEFERRABLE ) WITH (oids = false); -CREATE INDEX "transaction_hash" - ON "public"."transaction" - USING btree ("hash"); -CREATE INDEX "transaction_contractaddressAccountId" - ON "public"."transaction" - USING btree ("contractaddressAccountId"); -CREATE INDEX "transaction_fromAccountId" - ON "public"."transaction" - USING btree ("fromAccountId"); -CREATE INDEX "transaction_toAccountId" - ON "public"."transaction" - USING btree ("toAccountId"); -CREATE INDEX "transaction_blockId" - ON "public"."transaction" - USING btree ("blockId"); -CREATE INDEX "transaction_gasUsed" - ON "public"."transaction" - USING btree ("gasUsed"); +CREATE INDEX "transaction_hash" ON "public"."transaction" ("hash"); +CREATE INDEX "transaction_contractaddressAccountId" ON "public"."transaction" ("contractaddressAccountId"); +CREATE INDEX "transaction_fromAccountId" ON "public"."transaction" ("fromAccountId"); +CREATE INDEX "transaction_toAccountId" ON "public"."transaction" ("toAccountId"); +CREATE INDEX "transaction_blockId" ON "public"."transaction" ("blockId"); +CREATE INDEX "transaction_gasUsed" ON "public"."transaction" ("gasUsed"); + +CREATE TABLE "public"."accountsnapshots" ( + "accountId" bigint NOT NULL, + "when" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, + "wei_balance" numeric(79,0), + "wei_loadamount" numeric(79,0), + CONSTRAINT "accntsnapshots_accntId_fkey" FOREIGN KEY ("accountId") REFERENCES account(id) NOT DEFERRABLE +); +CREATE INDEX "accountsnapshots_when" ON "public"."accountsnapshots" ("when"); +CREATE INDEX "accountsnapshots_accountId" ON "public"."accountsnapshots" ("accountId"); CREATE VIEW b AS diff --git a/postgres/90-add-db-user.sh b/postgres/90-add-db-user.sh index 87657ed..5253073 100755 --- a/postgres/90-add-db-user.sh +++ b/postgres/90-add-db-user.sh @@ -5,4 +5,10 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E GRANT CONNECT ON DATABASE postgres TO dgsi; GRANT SELECT ON ALL TABLES IN SCHEMA public TO dgsi; GRANT UPDATE (shortname,name) ON TABLE public.account TO dgsi; + CREATE USER logparser WITH PASSWORD 'bfa'; + GRANT SELECT,INSERT,UPDATE,DELETE,TRUNCATE ON TABLE accountsnapshots TO logparser; + GRANT CONNECT ON DATABASE postgres TO logparser; + GRANT SELECT ON ALL TABLES IN SCHEMA public TO logparser; + GRANT USAGE ON account_id_seq TO logparser; EOSQL + -- GitLab