-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: headwatcher #13
Open
dputko
wants to merge
3
commits into
main
Choose a base branch
from
feat/headwatcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,7 @@ | |
path = ofchain/scripts | ||
url = [email protected]:lidofinance/scripts.git | ||
branch = feat/pectra-devnet | ||
[submodule "ofchain/headwatcher"] | ||
path = ofchain/headwatcher | ||
url = [email protected]:lidofinance/ethereum-head-watcher.git | ||
branch = feature/val-1404-eip-7251-head-watcher-alerts-for-new-el-requests |
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,27 @@ | ||
import {baseConfig, jsonDb} from "../../config/index.js"; | ||
import {getLidoLocatorAddress} from "../../lib/lido/index.js"; | ||
import fs from "node:fs"; | ||
|
||
export async function getEnv() { | ||
const state = await jsonDb.read(); | ||
const {network} = baseConfig; | ||
|
||
const el = state.network?.binding?.elNodesPrivate?.[0] ?? network.el.url; | ||
const cl = state.network?.binding?.clNodesPrivate?.[0] ?? network.cl.url; | ||
const name = state.network?.binding?.name ?? network.name; | ||
const locator = await getLidoLocatorAddress(); | ||
|
||
if (!fs.existsSync(baseConfig.headwatcher.alertsOutputPath)) { | ||
fs.mkdirSync(baseConfig.headwatcher.alertsOutputPath, {recursive: true}); | ||
} | ||
|
||
return { | ||
DOCKER_FILE_PATH: baseConfig.headwatcher.root, | ||
ALERTS_OUTPUT_DIR: baseConfig.headwatcher.alertsOutputPath, | ||
CONSENSUS_CLIENT_URI: cl, | ||
EXECUTION_CLIENT_URI: el, | ||
LIDO_LOCATOR_ADDRESS: locator, | ||
DOCKER_NETWORK_NAME: 'kt-' + name, | ||
KEYS_API_URI: 'http://localhost:9030', | ||
} | ||
} |
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,38 @@ | ||
networks: | ||
devnet: | ||
name: ${DOCKER_NETWORK_NAME} | ||
external: true | ||
|
||
services: | ||
stub_alertmanager: | ||
container_name: ethereum-head-watcher-stub-alertmanager | ||
build: ./stub_alertmanager | ||
networks: | ||
- devnet | ||
volumes: | ||
- ${ALERTS_OUTPUT_DIR:-../../../artifacts/headwatcher}:/opt/alerts:rw | ||
environment: | ||
- ALERTS_DIR=/opt/alerts | ||
expose: | ||
- 41288 | ||
|
||
app: | ||
container_name: ethereum-head-watcher | ||
build: ${DOCKER_FILE_PATH} | ||
restart: unless-stopped | ||
networks: | ||
- devnet | ||
deploy: | ||
resources: | ||
limits: | ||
memory: 2g | ||
depends_on: | ||
- stub_alertmanager | ||
environment: | ||
- CONSENSUS_CLIENT_URI=${CONSENSUS_CLIENT_URI} | ||
- EXECUTION_CLIENT_URI=${EXECUTION_CLIENT_URI} | ||
- LIDO_LOCATOR_ADDRESS=${LIDO_LOCATOR_ADDRESS} | ||
- KEYS_SOURCE=keys_api | ||
- KEYS_API_URI=${KEYS_API_URI} | ||
- ALERTMANAGER_URI="http://stub_alertmanager:41288" | ||
- LOG_LEVEL=INFO |
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,26 @@ | ||
import {Command} from "@oclif/core"; | ||
import {execa} from "execa"; | ||
import {getEnv} from "./common.js"; | ||
|
||
export default class HeadwatcherDown extends Command { | ||
static description = "Shutdown Ethereum Head Watcher"; | ||
|
||
async run() { | ||
this.log("Stopping Ethereum Head Watcher..."); | ||
|
||
try { | ||
await execa( | ||
"docker", | ||
["compose", "-f", "docker-compose.yml", "down", "-v"], | ||
{ | ||
stdio: "inherit", | ||
cwd: import.meta.dirname, | ||
env: await getEnv() | ||
} | ||
); | ||
this.log("Ethereum Head Watcher stopped successfully."); | ||
} catch (error: any) { | ||
this.error(`Failed to stop Ethereum Head Watcher: ${error.message}`); | ||
} | ||
} | ||
} |
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,19 @@ | ||
import {Command} from "@oclif/core"; | ||
import {execa} from "execa"; | ||
import {getEnv} from "./common.js"; | ||
|
||
export default class HeadwatcherLogs extends Command { | ||
static description = "Output logs of Ethereum Head Watcher"; | ||
|
||
async run() { | ||
await execa( | ||
"docker", | ||
["compose", "-f", "docker-compose.yml", "logs", "-f"], | ||
{ | ||
stdio: "inherit", | ||
cwd: import.meta.dirname, | ||
env: await getEnv() | ||
} | ||
); | ||
} | ||
} |
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,5 @@ | ||
FROM golang:1.23.4 | ||
WORKDIR /app | ||
COPY stub.go ./ | ||
EXPOSE 41288 | ||
CMD ["go", "run", "stub.go"] |
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,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
) | ||
|
||
func main() { | ||
dir := os.Getenv("ALERTS_DIR") | ||
if dir == "" { | ||
fmt.Println("Environment variable ALERTS_DIR is not set") | ||
os.Exit(1) | ||
} | ||
|
||
http.HandleFunc("/api/v1/alerts", func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodPost { | ||
http.Error(w, "Only POST method is allowed", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
body, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
http.Error(w, "Failed to read request body", http.StatusInternalServerError) | ||
return | ||
} | ||
defer r.Body.Close() | ||
|
||
filename := fmt.Sprintf("%s.json", time.Now().Format("20060102_150405")) | ||
filepath := filepath.Join(dir, filename) | ||
|
||
if err := os.WriteFile(filepath, body, 0644); err != nil { | ||
message := fmt.Sprintf("Failed to write file: %s", err.Error()) | ||
http.Error(w, message, http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
fmt.Fprintf(w, "Alert saved to %s\n", filepath) | ||
}) | ||
|
||
port := ":41288" | ||
fmt.Printf("Starting server on port %s\n", port) | ||
if err := http.ListenAndServe(port, nil); err != nil { | ||
fmt.Printf("Server failed: %s\n", err) | ||
} | ||
} |
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,26 @@ | ||
import {Command} from "@oclif/core"; | ||
import {execa} from "execa"; | ||
import {getEnv} from "./common.js"; | ||
|
||
export default class HeadwatcherUp extends Command { | ||
static description = "Start Ethereum Head Watcher"; | ||
|
||
async run() { | ||
this.log("Starting Ethereum Head Watcher..."); | ||
|
||
try { | ||
await execa( | ||
"docker", | ||
["compose", "-f", "docker-compose.yml", "up", "--build", "-d"], | ||
{ | ||
stdio: "inherit", | ||
cwd: import.meta.dirname, | ||
env: await getEnv() | ||
} | ||
); | ||
this.log("Ethereum Head Watcher started successfully."); | ||
} catch (error: any) { | ||
this.error(`Failed to start Ethereum Head Watcher: ${error.message}`); | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any errors when running commands because this file is in the
commands
directory? In the current settings, Oclif treats everything in thecli/commands
directory as commands. For this reason, I placed the commands separately and the helper code in thecli/lib
directoryThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thank you! Fixed.