Skip to content

Commit

Permalink
feat: open-source pms (#74)
Browse files Browse the repository at this point in the history
* feat: open-source pms

Signed-off-by: Yashvardhan Kukreja <[email protected]>
  • Loading branch information
yashvardhan-kukreja authored Nov 6, 2024
1 parent 880391f commit f5e8317
Show file tree
Hide file tree
Showing 26 changed files with 2,561 additions and 3 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ workflows:
op-conductor-mon/.* run-build-op-conductor-mon true
op-signer/.* run-build-op-signer true
op-txproxy/.* run-build-op-txproxy true
peer-mgmt-service/.* run-build-pms true
op-ufm/.* run-build-op-ufm true
proxyd/.* run-build-proxyd true
.circleci/.* run-all true
Expand Down
113 changes: 111 additions & 2 deletions .circleci/continue_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ parameters:
run-build-op-txproxy:
type: boolean
default: false
run-build-pms:
type: boolean
default: false
run-build-op-ufm:
type: boolean
default: false
Expand Down Expand Up @@ -84,6 +87,7 @@ jobs:
echo "run-build-op-conductor-mon: << pipeline.parameters.run-build-op-conductor-mon >>"
echo "run-build-op-signer: << pipeline.parameters.run-build-op-signer >>"
echo "run-build-op-txproxy: << pipeline.parameters.run-build-op-txproxy >>"
echo "run-build-pms: << pipeline.parameters.run-build-pms >>"
echo "run-build-op-ufm: << pipeline.parameters.run-build-op-ufm >>"
echo "run-build-proxyd: << pipeline.parameters.run-build-proxyd >>"
echo "run-all: << pipeline.parameters.run-all >>"
Expand Down Expand Up @@ -120,6 +124,12 @@ jobs:
echo "op-txproxy tag regex match: false"
fi
if [[ $CURRENT_TAG =~ ^peer-mgmt-service/v.* ]]; then
echo "peer-mgmt-service tag regex match: true"
else
echo "peer-mgmt-service tag regex match: false"
fi
if [[ $CURRENT_TAG =~ ^op-ufm/v.* ]]; then
echo "op-ufm tag regex match: true"
else
Expand Down Expand Up @@ -444,6 +454,29 @@ workflows:
docker_name: op-signer
docker_tags: <<pipeline.git.revision>>,<<pipeline.git.branch>>
docker_context: .
peer-mgmt-service:
when:
or: [<< pipeline.parameters.run-build-pms >>, << pipeline.parameters.run-all >>]
jobs:
- go-lint:
name: pms-lint
module: peer-mgmt-service
- go-test:
name: pms-tests
module: peer-mgmt-service
- docker-build:
name: pms-docker-build
docker_file: peer-mgmt-service/Dockerfile
docker_name: peer-mgmt-service
docker_tags: <<pipeline.git.revision>>,<<pipeline.git.branch>>
docker_context: .
- docker-build:
name: pms-docker-build-backwards-compatible
docker_file: peer-mgmt-service/Dockerfile
docker_name: peer-mgmt-service
docker_tags: <<pipeline.git.revision>>,<<pipeline.git.branch>>
repo: oplabs-tools-artifacts/internal-images ## introduces backwards compatibility
docker_context: .
op-txproxy:
when:
or: [<< pipeline.parameters.run-build-op-txproxy >>, << pipeline.parameters.run-all >>]
Expand Down Expand Up @@ -497,14 +530,14 @@ workflows:
- log-config-results:
filters:
tags:
only: /^(proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)\/v.*/
only: /^(peer-mgmt-service|proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)\/v.*/
branches:
ignore: /.*/
- hold:
type: approval
filters:
tags:
only: /^(proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)\/v.*/
only: /^(peer-mgmt-service|proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)\/v.*/
branches:
ignore: /.*/
- docker-build:
Expand Down Expand Up @@ -647,6 +680,82 @@ workflows:
- oplabs-gcr-release
requires:
- proxyd-docker-publish
#region backwards-compatibility of PMS
## The following region-ed section builds, pushes and tags the peer-mgmt-service exactly at the destination where it was pushed when it was closed source for accomplishing backwards-compatibility with any clients mistakenly still relying on it.
- docker-build:
name: pms-docker-build-backwards-compatible
filters:
tags:
only: /^peer-mgmt-service\/v.*/
docker_name: peer-mgmt-service
docker_tags: <<pipeline.git.revision>>
docker_context: .
docker_file: peer-mgmt-service/Dockerfile
repo: oplabs-tools-artifacts/internal-images ## introduces backwards compatibility
context:
- oplabs-gcr-release
requires:
- hold
- docker-publish:
name: pms-docker-publish-backwards-compatible
filters:
tags:
only: /^peer-mgmt-service\/v.*/
docker_name: peer-mgmt-service
docker_tags: <<pipeline.git.revision>>
repo: oplabs-tools-artifacts/internal-images ## introduces backwards compatibility
context:
- oplabs-gcr-release
requires:
- pms-docker-build-backwards-compatible
- docker-tag-op-stack-release:
name: pms-docker-tag-backwards-compatible
filters:
tags:
only: /^peer-mgmt-service\/v.*/
branches:
ignore: /.*/
context:
- oplabs-gcr-release
repo: oplabs-tools-artifacts/internal-images ## introduces backwards compatibility
requires:
- pms-docker-publish-backwards-compatible
#endregion
- docker-build:
name: pms-docker-build
filters:
tags:
only: /^peer-mgmt-service\/v.*/
docker_name: peer-mgmt-service
docker_tags: <<pipeline.git.revision>>
docker_context: .
docker_file: peer-mgmt-service/Dockerfile
context:
- oplabs-gcr-release
requires:
- hold
- docker-publish:
name: pms-docker-publish
filters:
tags:
only: /^peer-mgmt-service\/v.*/
docker_name: peer-mgmt-service
docker_tags: <<pipeline.git.revision>>
context:
- oplabs-gcr-release
requires:
- pms-docker-build
- docker-tag-op-stack-release:
name: pms-docker-tag
filters:
tags:
only: /^peer-mgmt-service\/v.*/
branches:
ignore: /.*/
context:
- oplabs-gcr-release
requires:
- pms-docker-publish
- docker-build:
name: op-conductor-mon-docker-build
filters:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tag-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ on:
- op-ufm
- op-txproxy
- proxyd
- peer-mgmt-service
prerelease:
description: Increment major/minor/patch as prerelease?
required: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DOCKER_REPO=$1
GIT_TAG=$2
GIT_SHA=$3

IMAGE_NAME=$(echo "$GIT_TAG" | grep -Eow '^(proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)' || true)
IMAGE_NAME=$(echo "$GIT_TAG" | grep -Eow '^(peer-mgmt-service|proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)' || true)
if [ -z "$IMAGE_NAME" ]; then
echo "image name could not be parsed from git tag '$GIT_TAG'"
exit 1
Expand Down
1 change: 1 addition & 0 deletions ops/tag-service/tag-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'proxyd': '4.6.1',
'op-signer': '0.0.1',
'op-txproxy': '0.0.0',
'peer-mgmt-service': '0.0.0'
}

VALID_BUMPS = ('major', 'minor', 'patch', 'prerelease', 'finalize-prerelease')
Expand Down
1 change: 1 addition & 0 deletions ops/tag-service/tag-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

SERVICES = [
'proxyd',
'peer-mgmt-service',
'op-ufm',
'op-signer',
'op-conductor-mon',
Expand Down
3 changes: 3 additions & 0 deletions peer-mgmt-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/
mocks/
mock_*
1 change: 1 addition & 0 deletions peer-mgmt-service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @eth-optimism/peer-mgmt-service
18 changes: 18 additions & 0 deletions peer-mgmt-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.21.3-alpine3.18 as builder

COPY ./peer-mgmt-service /app

WORKDIR /app
RUN apk add --no-cache make jq bash git alpine-sdk
RUN make build

FROM alpine:3.18
RUN apk --no-cache add make jq bash git alpine-sdk redis

RUN addgroup -S app && adduser -S app -G app
USER app
WORKDIR /app

COPY --from=builder /app/bin/pms /app

ENTRYPOINT ["/app/pms"]
37 changes: 37 additions & 0 deletions peer-mgmt-service/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
VERSION := v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
LDFLAGSSTRING +=-X main.Version=$(VERSION)
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"

all: build

docker:
docker build ../ -f Dockerfile -t peer-mgmt-service:latest

build:
env GO111MODULE=on go build -v $(LDFLAGS) -o ./bin/pms ./cmd/pms

clean:
rm ./bin/peer-mgmt-service

generate:
[ '$(shell mockgen --version)' = 'v1.6.0' ] || go install github.com/golang/mock/[email protected]
go generate ./...

test: generate
go test -v ./...

lint:
golangci-lint run ./...

.PHONY: \
build \
clean \
test \
generate \
lint \
docker
14 changes: 14 additions & 0 deletions peer-mgmt-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @eth-optimism/peer-mgmt-service

Peer Management Service

## Setup

Install go1.21

```bash
make build

source .env.example # (or copy to .envrc if using direnv)
./bin/pms
```
84 changes: 84 additions & 0 deletions peer-mgmt-service/cmd/pms/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package main

import (
"context"
"encoding/json"
"fmt"
"os"
"os/signal"
"syscall"

"golang.org/x/exp/slog"

"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/infra/peer-mgmt-service/pkg/config"
"github.com/ethereum-optimism/infra/peer-mgmt-service/pkg/service"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
)

var (
GitVersion = ""
GitCommit = ""
GitDate = ""
)

func main() {
oplog.SetGlobalLogHandler(slog.NewJSONHandler(
os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))

log.Info("initializing",
"version", GitVersion,
"commit", GitCommit,
"date", GitDate)

if len(os.Args) < 2 {
log.Crit("must specify a config file on the command line")
}
cfg := initConfig(os.Args[1])

ctx := context.Background()
svc := service.New(cfg)
svc.Start(ctx)

sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
recvSig := <-sig
log.Info("caught signal, shutting down",
"signal", recvSig)

svc.Shutdown()
}

func initConfig(cfgFile string) *config.Config {
cfg, err := config.New(cfgFile)
if err != nil {
log.Crit("error reading config file",
"file", cfgFile,
"err", err)
}

// update log level from config
logLevel, err := oplog.LevelFromString(cfg.LogLevel)
if err != nil {
logLevel = log.LevelInfo
if cfg.LogLevel != "" {
log.Warn("invalid log_level",
"log_level", cfg.LogLevel)
}
}
oplog.SetGlobalLogHandler(slog.NewJSONHandler(
os.Stdout, &slog.HandlerOptions{Level: logLevel}))

// readable parsed config
jsonCfg, _ := json.MarshalIndent(cfg, "", " ")
fmt.Printf("%s", string(jsonCfg))

err = cfg.Validate()
if err != nil {
log.Crit("invalid config",
"err", err)
}

return cfg
}
28 changes: 28 additions & 0 deletions peer-mgmt-service/config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
log_level: info
dry_run: false

metrics:
enabled: true
host: 0.0.0.0
port: 7300

healthz:
enabled: true
host: 0.0.0.0
port: 8080

poll_interval: 30s
node_state_expiration: 1h
rpc_timeout: 15s

nodes:
op-node-0:
rpc_address: http://op-node-0:9545
op-node-1:
rpc_address: http://op-node-1:9545

networks:
network_name:
members:
- op-node-0
- op-node-1
Loading

0 comments on commit f5e8317

Please sign in to comment.