generated from ethereum-optimism/.github
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: open-source pms Signed-off-by: Yashvardhan Kukreja <[email protected]>
- Loading branch information
1 parent
880391f
commit f5e8317
Showing
26 changed files
with
2,561 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
SERVICES = [ | ||
'proxyd', | ||
'peer-mgmt-service', | ||
'op-ufm', | ||
'op-signer', | ||
'op-conductor-mon', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bin/ | ||
mocks/ | ||
mock_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @eth-optimism/peer-mgmt-service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.