From 3a0e5c43e792b880b56e907c66c9cb29af2a1a07 Mon Sep 17 00:00:00 2001 From: Advaith Date: Mon, 16 Aug 2021 10:56:55 -0700 Subject: [PATCH 1/7] init v2 --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 233e80180..d5b6b6987 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -# Helios - -**Note**: working on v0.2, check back soon! +# Helios V2 Helios is a tool built on-top of [go-ethereum](https://github.com/ethereum/go-ethereum) and the [ELK stack](https://www.elastic.co/what-is/elk-stack) to query and monitor the mempool. From 4ac60f26934b939f24ba4d5709298a1a76f4c95f Mon Sep 17 00:00:00 2001 From: Advaith Date: Mon, 16 Aug 2021 11:33:08 -0700 Subject: [PATCH 2/7] minimal config for yaml files --- config/config.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ helios.yml | 10 +++++++ 4 files changed, 82 insertions(+) create mode 100644 config/config.go create mode 100644 helios.yml diff --git a/config/config.go b/config/config.go new file mode 100644 index 000000000..61cc6fc71 --- /dev/null +++ b/config/config.go @@ -0,0 +1,69 @@ +package config + +import ( + "os" + "gopkg.in/yaml.v2" +) + +type Config struct { + Helios struct { + NodeUrl string `yaml:"nodeUrl"`, // node ws url + Mode string `yaml:"mode"`, // quick or full + } `yaml:"helios"` + + Postgres struct { + PostgresHot string `yaml:"postgres_host"` + PostgresUser string `yaml:"postgres_user"` + PostgresPassword string `yaml:"postgres_password"` + } `yaml:"postgres"` + + Redis struct { + RedisHost string `yaml:"redis_host"` + RedisUser string `yaml:"redis_user"` + RedisPassword string `yaml:"redis_password"` + } `yaml:"redis"` +} + +func NewConfig(configPath string) (*Config, err) { + config := &Config{} + + file, err := os.Open(configPath) + + if err != nil { + return nil, err + } + + defer file.Close() + + decoder := yaml.NewDecoder(file) + + if err := decoder.Decode(&config); err != nil { + return nil, err + } + return config, nil +} + +func ValidatePath(path string) error { + s, err := os.Stat(path) + if err != nil { + return err + } + if s.IsDir() { + return fmt.Errorf("'%s' is a directory, please specify a file", path) + } + return nil +} + +func ParseFlags() (string, error) { + var configPath string + + flag.StringVar(&configPath, "ocnfig", "./helios.yml", "path to yaml config for helios") + + flag.Parse() + + if err := ValidatePath(configPath); err != nil { + return "", err + } + + return configPath, nil +} \ No newline at end of file diff --git a/go.mod b/go.mod index a63a892f7..0ec0fcea1 100644 --- a/go.mod +++ b/go.mod @@ -8,4 +8,5 @@ require ( github.com/joho/godotenv v1.3.0 github.com/logrusorgru/aurora v2.0.3+incompatible github.com/logrusorgru/aurora/v3 v3.0.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index e64d08888..3219ecefd 100644 --- a/go.sum +++ b/go.sum @@ -241,4 +241,6 @@ gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHO gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= diff --git a/helios.yml b/helios.yml new file mode 100644 index 000000000..4902dd023 --- /dev/null +++ b/helios.yml @@ -0,0 +1,10 @@ +helios: + nodeUrl: 'ws://xx.xx.xx:8547' +postgres: + postgres_host: '' + postgres_user: '' + postgres_password: '' +redis: + redis_host: '' + redis_user: '' + redis_password: '' \ No newline at end of file From 6dbd362e4db8ccbc2c5c1e1702810190f3696893 Mon Sep 17 00:00:00 2001 From: Advaith Date: Mon, 16 Aug 2021 13:23:17 -0700 Subject: [PATCH 3/7] docker compose --- docker-compose.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..f1b71b634 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.7' + +services: + postgres: + image: postgres:10.5 + restart: always + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + logging: + options: + max-size: 10m + max-file: "3" + ports: + - '5438:5432' + container_name: postgres + volumes: + - ./postgres-data:/var/lib/postgresql/data + # sql script to create tables + - ./sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql + redis: + image: 'redis:6' + ports: + - '6379:6379' + container_name: redis From 2dc994598c1e85ea5199967ec787d1e6c9c17513 Mon Sep 17 00:00:00 2001 From: Advaith Date: Mon, 16 Aug 2021 13:23:54 -0700 Subject: [PATCH 4/7] minor changes to ports --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index f1b71b634..13be79055 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: max-size: 10m max-file: "3" ports: - - '5438:5432' + - '5432:5432' container_name: postgres volumes: - ./postgres-data:/var/lib/postgresql/data From a07f4a3ba75c4c1aeb5f625cbeeeca7a6188c11a Mon Sep 17 00:00:00 2001 From: Advaith Date: Mon, 16 Aug 2021 15:24:52 -0700 Subject: [PATCH 5/7] first set of sql tables --- .gitignore | 1 + docker-compose.yml | 25 ++++++++++++++++++++++ sql/create_tables.sql | 48 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 docker-compose.yml create mode 100644 sql/create_tables.sql diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..7d8ae415a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/postgres-data diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..13be79055 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.7' + +services: + postgres: + image: postgres:10.5 + restart: always + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + logging: + options: + max-size: 10m + max-file: "3" + ports: + - '5432:5432' + container_name: postgres + volumes: + - ./postgres-data:/var/lib/postgresql/data + # sql script to create tables + - ./sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql + redis: + image: 'redis:6' + ports: + - '6379:6379' + container_name: redis diff --git a/sql/create_tables.sql b/sql/create_tables.sql new file mode 100644 index 000000000..aa7f2b1f3 --- /dev/null +++ b/sql/create_tables.sql @@ -0,0 +1,48 @@ +CREATE TABLE transactions IF NOT EXISTS +( + hash PRIMARY KEY varchar(66), + nonce bigint, + transaction_index bigint, + from_address varchar(42), + to_address varchar(42), + value numeric(38), + gas bigint, + gas_price bigint, + input text, + receipt_cumulative_gas_used bigint, + receipt_gas_used bigint, + receipt_contract_address varchar(42), + receipt_root varchar(66), + receipt_status bigint, + block_timestamp timestamp, + block_number bigint, + block_hash varchar(66), + max_fee_per_gas bigint, + max_priority_fee_per_gas bigint, + transaction_type bigint, + receipt_effective_gas_price bigint +); + +CREATE TABLE liquidation_attempts IF NOT EXISTS +( + hash PRIMARY KEY varchar(66) + liquidator varchar(42) + loan_owner varchar(42) + gas_price bigint, + repayAmount bigint, + time timestamp, + collateralAddress varchar(42) + debtAddress varchar(42) + block_number bigint + isMined boolean +) + +CREATE TABLE trade_attempts IF NOT EXISTS +( + hash PRIMARY KEY varchar(66) + from varchar(42) + to varchar(42) + fromAmount bigInt + toAmount bigInt + isMined boolean +) From 958a14cf271f4cdc67e0f5dc6e95eff4dd01ea89 Mon Sep 17 00:00:00 2001 From: Advaith Date: Wed, 18 Aug 2021 13:10:45 -0700 Subject: [PATCH 6/7] helios dockerfile --- .dockerignore | 1 + .gitignore | 2 +- Dockerfile | 26 ++++++++++++++++++++++++++ helios.go => main.go | 0 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile rename helios.go => main.go (100%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..0d36bc39d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/docker diff --git a/.gitignore b/.gitignore index 7d8ae415a..97e148ad0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/postgres-data +/docker/** diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..93f0ab3d7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM golang:alpine + +ENV GO111MODULE=on \ + CGO_ENABLED=0 \ + GOOS=linux \ + GOARCH=amd64 + +WORKDIR /build + +COPY go.mod . +COPY go.sum . +RUN go mod download + +COPY . . + +RUN go build -o main . + +WORKDIR /dist + +RUN cp /build/main . + +# Expose ports (when we have WS or REST endpoints) +# EXPOSE 3000 + +# start container +CMD ["/dist/main"] diff --git a/helios.go b/main.go similarity index 100% rename from helios.go rename to main.go From 7dc62f95297bc70ea3582ce6d3b57a0d384ff10e Mon Sep 17 00:00:00 2001 From: Advaith Date: Wed, 18 Aug 2021 13:51:50 -0700 Subject: [PATCH 7/7] ignore geth and sigs for faster builds --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.dockerignore b/.dockerignore index 0d36bc39d..f0047da74 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,3 @@ /docker +/geth+ +/data