diff --git a/packages/guardian-prover-health-check/guardianprover.go b/packages/guardian-prover-health-check/guardianprover.go index fd9d29aee5c..df7e3bbc6a8 100644 --- a/packages/guardian-prover-health-check/guardianprover.go +++ b/packages/guardian-prover-health-check/guardianprover.go @@ -7,11 +7,14 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" + "github.com/prometheus/client_golang/prometheus" ) type GuardianProver struct { - Address common.Address - ID *big.Int + Address common.Address + ID *big.Int + HealthCheckCounter prometheus.Counter + SignedBlockCounter prometheus.Counter } func SignatureToGuardianProver( diff --git a/packages/guardian-prover-health-check/healthchecker/healthchecker.go b/packages/guardian-prover-health-check/healthchecker/healthchecker.go index 52da0277541..b67623a93c7 100644 --- a/packages/guardian-prover-health-check/healthchecker/healthchecker.go +++ b/packages/guardian-prover-health-check/healthchecker/healthchecker.go @@ -12,6 +12,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" "github.com/labstack/echo/v4" + "github.com/labstack/gommon/log" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" guardianproverhealthcheck "github.com/taikoxyz/taiko-mono/packages/guardian-prover-health-check" "github.com/taikoxyz/taiko-mono/packages/guardian-prover-health-check/bindings/guardianprover" hchttp "github.com/taikoxyz/taiko-mono/packages/guardian-prover-health-check/http" @@ -108,9 +111,19 @@ func InitFromConfig(ctx context.Context, h *HealthChecker, cfg *Config) (err err return err } + log.Info("setting guardian prover address", "address", guardianAddress.Hex(), "id", guardianId.Uint64()) + guardianProvers = append(guardianProvers, guardianproverhealthcheck.GuardianProver{ Address: guardianAddress, ID: guardianId, + HealthCheckCounter: promauto.NewCounter(prometheus.CounterOpts{ + Name: fmt.Sprintf("guardian_prover_%v_health_checks_ops_total", guardianId.Uint64()), + Help: "The total number of health checks", + }), + SignedBlockCounter: promauto.NewCounter(prometheus.CounterOpts{ + Name: fmt.Sprintf("guardian_prover_%v_signed_block_ops_total", guardianId.Uint64()), + Help: "The total number of signed blocks", + }), }) } diff --git a/packages/guardian-prover-health-check/http/post_health_check.go b/packages/guardian-prover-health-check/http/post_health_check.go index f3d49edbe38..fc8742d0856 100644 --- a/packages/guardian-prover-health-check/http/post_health_check.go +++ b/packages/guardian-prover-health-check/http/post_health_check.go @@ -1,6 +1,7 @@ package http import ( + "log/slog" "net/http" "github.com/ethereum/go-ethereum/crypto" @@ -61,5 +62,14 @@ func (srv *Server) PostHealthCheck(c echo.Context) error { return c.JSON(http.StatusBadRequest, err) } + // increment health check metric + for _, v := range srv.guardianProvers { + if v.Address.Hex() == recoveredGuardianProver.Address.Hex() { + v.HealthCheckCounter.Inc() + } + } + + slog.Info("successful health check", "guardianProver", recoveredGuardianProver.Address.Hex()) + return c.JSON(http.StatusOK, nil) } diff --git a/packages/guardian-prover-health-check/http/post_signed_block.go b/packages/guardian-prover-health-check/http/post_signed_block.go index 7e92145926d..421aadd3350 100644 --- a/packages/guardian-prover-health-check/http/post_signed_block.go +++ b/packages/guardian-prover-health-check/http/post_signed_block.go @@ -60,5 +60,14 @@ func (srv *Server) PostSignedBlock(c echo.Context) error { return c.JSON(http.StatusBadRequest, err) } + // increment signed block metric + for _, v := range srv.guardianProvers { + if v.Address.Hex() == recoveredGuardianProver.Address.Hex() { + v.SignedBlockCounter.Inc() + } + } + + slog.Info("successful signed block", "guardianProver", recoveredGuardianProver.Address.Hex()) + return c.JSON(http.StatusOK, nil) } diff --git a/packages/guardian-prover-health-check/migrations/1666651001_create_signed_blocks_table.sql b/packages/guardian-prover-health-check/migrations/1666651001_create_signed_blocks_table.sql index f62d84bc460..ac768258fc8 100644 --- a/packages/guardian-prover-health-check/migrations/1666651001_create_signed_blocks_table.sql +++ b/packages/guardian-prover-health-check/migrations/1666651001_create_signed_blocks_table.sql @@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS signed_blocks ( guardian_prover_id int NOT NULL, block_id int NOT NULL, signature varchar(5000) NOT NULL, - block_hash varchar (42) NOT NULL, + block_hash VARCHAR(255) NOT NULL, recovered_address varchar(42) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,