Skip to content

Commit

Permalink
Cold Sync Enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Sulejman committed Aug 2, 2024
0 parents commit a1e7469
Show file tree
Hide file tree
Showing 19 changed files with 9,854 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PROST_RPC_URL=http://127.0.0.1:8545
PROTOCOL_STATE_CONTRACT=0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
DATA_MARKET_ADDRESS=0xCafac3dD18aC6c6e92c921884f9E4176737C052c
SLACK_REPORTING_URL=
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use the official Golang image as the build environment
FROM golang:1.20 as builder

# Set the working directory inside the container
WORKDIR /app

# Copy go.mod and go.sum files to the working directory
COPY go.mod go.sum ./

# Download the dependencies
RUN go mod download

# Copy the rest of the application code to the working directory
COPY . .

# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux go build -o /contract-listener ./cmd/main.go

# Use a minimal base image
FROM scratch

# Copy the binary from the builder stage
COPY --from=builder /contract-listener /contract-listener

# Expose port 9000

# Command to run the application
CMD ["/contract-listener"]
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Libp2p-submission-sequencer-listener Deployment
Scripts to deploy Sequencer-listener

## Requirements

1. Latest version of `docker` (`>= 20.10.21`) and `docker-compose` (`>= v2.13.0`)
2. At least 4 core CPU, 8GB RAM and 50GB SSD - make sure to choose the correct spec when deploying to Github Codespaces.

## Running the Sequencer Node

Clone the repository against the testnet branch.

`git clone https://github.com/PowerLoom/libp2p-submission-sequencer-listener.git --single-branch powerloom_sequencer_listener && cd powerloom_sequencer_listener`


### Deployment steps

1. Copy `env.example` to `.env`.
- Ensure the following required variables are filled:
- `RENDEZVOUS_POINT`: The identifier for locating all relayer peers which are the only way to access the sequencer and submit snapshots.
- `PROTOCOL_STATE_CONTRACT`: The contract address for the protocol state.
- `PROST_RPC_URL`: The URL for the PROST RPC service.
- `DATA_MARKET_ADDRESS`: The contract address of data market this listener is for.

- Optionally, you may also set the following variables:
- `REDIS_HOST` & `REDIS_PORT`: The redis server connection url (if you wish to use a separate one).
- `SLACK_REPORTING_URL`: The reporting url for sending alert notifications.

2. Build the image

`./build-docker.sh`

3. Run the following command (ideally in a `screen`) and follow instructions

`./run.sh`

## Troubleshooting
### To be added
### Stopping and Resetting
1. To shutdown services, just press `Ctrl+C` (and again to force).# protocol-state-cacher
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 proto-snapshot-listener . --no-cache
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#bash scripts/generate.sh
cd cmd
go build .
#docker-compose -f docker-compose.yaml up
19 changes: 19 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"protocol-state-cacher/config"
"protocol-state-cacher/pkgs/prost"
"protocol-state-cacher/pkgs/redis"
"protocol-state-cacher/pkgs/utils"
)

func main() {
utils.InitLogger()
config.LoadConfig()

prost.ConfigureClient()
prost.ConfigureContractInstance()
redis.RedisClient = redis.NewRedisClient()

prost.ColdSync()
}
64 changes: 64 additions & 0 deletions config/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package config

import (
log "github.com/sirupsen/logrus"
"os"
)

var SettingsObj *Settings

type Settings struct {
ClientUrl string
ContractAddress string
RedisHost string
RedisPort string
SlackReportingUrl string
DataMarketAddress string
}

func LoadConfig() {
config := Settings{
ClientUrl: getEnv("PROST_RPC_URL", ""),
ContractAddress: getEnv("PROTOCOL_STATE_CONTRACT", ""),
RedisHost: getEnv("REDIS_HOST", ""),
RedisPort: getEnv("REDIS_PORT", ""),
SlackReportingUrl: getEnv("SLACK_REPORTING_URL", ""),
DataMarketAddress: getEnv("DATA_MARKET_ADDRESS", ""),
}

// Check for any missing required environment variables and log errors
missingEnvVars := []string{}
if config.ClientUrl == "" {
missingEnvVars = append(missingEnvVars, "PROST_RPC_URL")
}
if config.ContractAddress == "" {
missingEnvVars = append(missingEnvVars, "PROTOCOL_STATE_CONTRACT")
}
if config.DataMarketAddress == "" {
missingEnvVars = append(missingEnvVars, "DATA_MARKET_ADDRESS")
}

if len(missingEnvVars) > 0 {
log.Fatalf("Missing required environment variables: %v", missingEnvVars)
}

checkOptionalEnvVar(config.SlackReportingUrl, "SLACK_REPORTING_URL")
checkOptionalEnvVar(config.RedisHost, "REDIS_HOST")
checkOptionalEnvVar(config.RedisPort, "REDIS_PORT")

SettingsObj = &config
}

func getEnv(key, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}

func checkOptionalEnvVar(value, key string) {
if value == "" {
log.Warnf("Optional environment variable %s is not set", key)
}
}
40 changes: 40 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module protocol-state-cacher

go 1.22

require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/ethereum/go-ethereum v1.14.7
github.com/go-redis/redis/v8 v8.11.5
github.com/sirupsen/logrus v1.9.3
)

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/ethereum/c-kzg-4844 v1.0.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.3.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // 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.22.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading

0 comments on commit a1e7469

Please sign in to comment.