Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anomit committed Sep 4, 2024
0 parents commit 74706bd
Show file tree
Hide file tree
Showing 24 changed files with 4,980 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
*/settings.json
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:alpine3.17

ENV GO111MODULE=on

RUN rm -rf /var/cache/apk/* && \
rm -rf /tmp/*

RUN apk update && apk add --no-cache ethtool nodejs npm bash gcc musl-dev libc-dev curl libffi-dev vim nano ca-certificates protoc

RUN npm install pm2 -g
RUN pm2 install pm2-logrotate && pm2 set pm2-logrotate:compress true && pm2 set pm2-logrotate:retain 7

WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download

# EXPOSE 9000

COPY . .
RUN chmod +x build.sh
RUN ./build.sh

RUN chmod +x init_processes.sh
Empty file added README.md
Empty file.
1 change: 1 addition & 0 deletions build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -t powerloom-submission-validator .
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd cmd
go build .
23 changes: 23 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"sync"
"validator/config"
"validator/pkgs/helpers"
)

func main() {
var wg sync.WaitGroup

helpers.InitLogger()
config.LoadConfig()
helpers.ConfigureClient()
helpers.ConfigureContractInstance()
helpers.RedisClient = helpers.NewRedisClient()
helpers.ConnectIPFSNode()
helpers.PopulateStateVars()

wg.Add(1)
go helpers.StartFetchingBlocks()
wg.Wait()
}
11 changes: 11 additions & 0 deletions config/settings.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ClientUrl": "PROST_RPC_URL",
"ContractAddress": "PROTOCOL_STATE_CONTRACT",
"RedisHost": "REDIS_HOST",
"RedisPort": "REDIS_PORT",
"IPFSUrl": "IPFS_URL",
"SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS",
"PrivateKey": "SIGNER_ACCOUNT_PRIVATE_KEY",
"ChainID": "PROST_CHAIN_ID",
"BatchSubmissionLimit": "BATCH_SUBMISSION_LIMIT"
}
54 changes: 54 additions & 0 deletions config/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package config

import (
"crypto/ecdsa"
"encoding/json"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
log "github.com/sirupsen/logrus"
"os"
"strings"
)

var SettingsObj *Settings

type Settings struct {
ClientUrl string `json:"ClientUrl"`
ContractAddress string `json:"ContractAddress"`
RedisHost string `json:"RedisHost"`
RedisPort string `json:"RedisPort"`
IPFSUrl string `json:"IPFSUrl"`
SignerAccountAddressStr string `json:"SignerAccountAddress"`
SignerAccountAddress common.Address
PrivateKeyStr string `json:"PrivateKey"`
PrivateKey *ecdsa.PrivateKey
ChainID int `json:"ChainID"`
BlockTime int `json:"BlockTime"`
BatchSubmissionLimit int `json:"BatchSubmissionLimit"`
}

func LoadConfig() {
//file, err := os.Open("/Users/mukundrawat/power2/validator-alpha/config/settings.json")
file, err := os.Open(strings.TrimSuffix(os.Getenv("CONFIG_PATH"), "/") + "/config/settings.json")
if err != nil {
log.Fatalf("Failed to open config file: %v", err)
}
defer func(file *os.File) {
err = file.Close()
if err != nil {
log.Errorf("Unable to close file: %s", err.Error())
}
}(file)

decoder := json.NewDecoder(file)
config := Settings{}
err = decoder.Decode(&config)
if err != nil {
log.Fatalf("Failed to decode config file: %v", err)
}

config.SignerAccountAddress = common.HexToAddress(config.SignerAccountAddressStr)
config.PrivateKey, _ = crypto.HexToECDSA(config.PrivateKeyStr)

SettingsObj = &config
}
68 changes: 68 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module validator

go 1.20

require (
github.com/ethereum/go-ethereum v1.13.12
github.com/go-redis/redis/v8 v8.11.5
github.com/ipfs/go-ipfs-api v0.7.0
github.com/sergerad/incremental-merkle-tree v0.0.0-20230715063941-db79af0c6c68
github.com/sirupsen/logrus v1.9.3
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/ipfs/boxo v0.12.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.26.3 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.8.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum v1.13.12 => github.com/muku314115/go-ethereum v1.13.12
Loading

0 comments on commit 74706bd

Please sign in to comment.