Skip to content

Commit

Permalink
feat(guardian-prover-health-check): Guardian prover rework (#15375)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Dec 12, 2023
1 parent 7dfc298 commit 975c882
Show file tree
Hide file tree
Showing 19 changed files with 590 additions and 264 deletions.
8 changes: 4 additions & 4 deletions packages/guardian-prover-health-check/.default.env
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
HTTP_PORT=4103
PROMETHEUS_HTTP_PORT=6062
METRICS_HTTP_PORT=6062
DATABASE_USER=root
DATABASE_PASSWORD=root
DATABASE_NAME=healthcheck
DATABASE_HOST=localhost:3306
DATABASE_MAX_IDLE_CONNS=50
DATABASE_MAX_OPEN_CONNS=3000
DATABASE_CONN_MAX_LIFETIME_IN_MS=100000
GUARDIAN_PROVER_CONTRACT_ADDRESS=0x0E801D84Fa97b50751Dbf25036d067dCf18858bF
GUARDIAN_PROVER_ENDPOINTS=https://guardian-prover-1.internal.taiko.xyz,https://guardian-prover-2.internal.taiko.xyz,https://guardian-prover-3.internal.taiko.xyz,https://guardian-prover-4.internal.taiko.xyz,https://guardian-prover-5.internal.taiko.xyz
RPC_URL=wss://l1ws.internal.taiko.xyz
GUARDIAN_PROVER_CONTRACT_ADDRESS=0xDf8038e9f4535040D7421A89ead398b3A38366EC
L1_RPC_URL=wss://l1ws.internal.taiko.xyz
L2_RPC_URL=wss://ws.internal.taiko.xyz
INTERVAL=12s
34 changes: 13 additions & 21 deletions packages/guardian-prover-health-check/cmd/flags/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import (

// required flags
var (
GuardianProverEndpoints = &cli.StringSliceFlag{
Name: "guardianProverEndpoints",
Usage: "List of guardian prover endpoints",
Category: healthCheckCategory,
EnvVars: []string{"GUARDIAN_PROVER_ENDPOINTS"},
Required: true,
}
GuardianProverContractAddress = &cli.StringFlag{
Name: "guardianProverContractAddress",
Usage: "Address of the GuardianProver contract",
Category: healthCheckCategory,
EnvVars: []string{"GUARDIAN_PROVER_CONTRACT_ADDRESS"},
Required: true,
}
RPCUrl = &cli.StringFlag{
Name: "rpcUrl",
Usage: "RPC Url",
L1RPCUrl = &cli.StringFlag{
Name: "l1RpcUrl",
Usage: "L1 RPC Url",
Category: healthCheckCategory,
EnvVars: []string{"L1_RPC_URL"},
Required: true,
}
L2RPCUrl = &cli.StringFlag{
Name: "l2RpcUrl",
Usage: "L2 RPC Url",
Category: healthCheckCategory,
EnvVars: []string{"RPC_URL"},
EnvVars: []string{"L2_RPC_URL"},
Required: true,
}
)
Expand All @@ -52,21 +52,13 @@ var (
Value: "*",
EnvVars: []string{"HTTP_CORS_ORIGINS"},
}
Interval = &cli.DurationFlag{
Name: "interval",
Usage: "Health check interval duration",
Category: healthCheckCategory,
Value: 12 * time.Second,
EnvVars: []string{"INTERVAL"},
}
)

var HealthCheckFlags = MergeFlags(CommonFlags, []cli.Flag{
HTTPPort,
CORSOrigins,
Backoff,
GuardianProverEndpoints,
GuardianProverContractAddress,
Interval,
RPCUrl,
L1RPCUrl,
L2RPCUrl,
})
38 changes: 34 additions & 4 deletions packages/guardian-prover-health-check/guardianprover.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
package guardianproverhealthcheck

import (
"encoding/base64"
"errors"
"math/big"
"net/url"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)

type GuardianProver struct {
Address common.Address
ID *big.Int
Endpoint *url.URL
Address common.Address
ID *big.Int
}

func SignatureToGuardianProver(
msg []byte,
b64EncodedSig string,
guardianProvers []GuardianProver,
) (*GuardianProver, error) {
b64DecodedSig, err := base64.StdEncoding.DecodeString(b64EncodedSig)
if err != nil {
return nil, err
}

// recover the public key from the signature
r, err := crypto.SigToPub(msg, b64DecodedSig)
if err != nil {
return nil, err
}

// convert it to address type
recoveredAddr := crypto.PubkeyToAddress(*r)

// see if any of our known guardian provers have that recovered address
for _, p := range guardianProvers {
if recoveredAddr.Cmp(p.Address) == 0 {
return &p, nil
}
}

return nil, errors.New("signature does not recover to known guardian prover")
}
11 changes: 4 additions & 7 deletions packages/guardian-prover-health-check/healthchecker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package healthchecker
import (
"database/sql"
"strings"
"time"

"github.com/taikoxyz/taiko-mono/packages/guardian-prover-health-check/cmd/flags"
"github.com/taikoxyz/taiko-mono/packages/guardian-prover-health-check/db"
Expand All @@ -30,10 +29,9 @@ type Config struct {
CORSOrigins []string
Backoff uint64
HTTPPort uint64
GuardianProverEndpoints []string
GuardianProverContractAddress string
RPCUrl string
Interval time.Duration
L1RPCUrl string
L2RPCUrl string
OpenDBFunc func() (DB, error)
}

Expand All @@ -48,11 +46,10 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
DatabaseMaxOpenConns: c.Uint64(flags.DatabaseMaxOpenConns.Name),
DatabaseMaxConnLifetime: c.Uint64(flags.DatabaseConnMaxLifetime.Name),
CORSOrigins: strings.Split(c.String(flags.CORSOrigins.Name), ","),
GuardianProverEndpoints: c.StringSlice(flags.GuardianProverEndpoints.Name),
GuardianProverContractAddress: c.String(flags.GuardianProverContractAddress.Name),
RPCUrl: c.String(flags.RPCUrl.Name),
L1RPCUrl: c.String(flags.L1RPCUrl.Name),
L2RPCUrl: c.String(flags.L2RPCUrl.Name),
HTTPPort: c.Uint64(flags.HTTPPort.Name),
Interval: c.Duration(flags.Interval.Name),
OpenDBFunc: func() (DB, error) {
return db.OpenDBConnection(db.DBConnectionOpts{
Name: c.String(flags.DatabaseUsername.Name),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package healthchecker

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -12,7 +11,6 @@ import (

var (
guardianProverAddress = "0x63FaC9201494f0bd17B9892B9fae4d52fe3BD377"
guardianProverEndpoints = "http://endpoint.com,http://endpoint2.com"
databaseMaxIdleConns = "10"
databaseMaxOpenConns = "10"
databaseMaxConnLifetime = "30"
Expand Down Expand Up @@ -40,8 +38,8 @@ func TestNewConfigFromCliContext(t *testing.T) {
assert.Equal(t, "dbpass", c.DatabasePassword)
assert.Equal(t, "dbname", c.DatabaseName)
assert.Equal(t, "dbhost", c.DatabaseHost)
assert.Equal(t, "rpcUrl", c.RPCUrl)
assert.Equal(t, strings.Split(guardianProverEndpoints, ","), c.GuardianProverEndpoints)
assert.Equal(t, "l1RpcUrl", c.L1RPCUrl)
assert.Equal(t, "l2RpcUrl", c.L2RPCUrl)
assert.Equal(t, guardianProverAddress, c.GuardianProverContractAddress)
assert.Equal(t, []string{"*"}, c.CORSOrigins)
assert.Equal(t, uint64(10), c.DatabaseMaxIdleConns)
Expand All @@ -64,13 +62,13 @@ func TestNewConfigFromCliContext(t *testing.T) {
"--" + flags.DatabasePassword.Name, "dbpass",
"--" + flags.DatabaseHost.Name, "dbhost",
"--" + flags.DatabaseName.Name, "dbname",
"--" + flags.RPCUrl.Name, "rpcUrl",
"--" + flags.L1RPCUrl.Name, "l1RpcUrl",
"--" + flags.L2RPCUrl.Name, "l2RpcUrl",
"--" + flags.CORSOrigins.Name, "*",
"--" + flags.DatabaseMaxOpenConns.Name, databaseMaxOpenConns,
"--" + flags.DatabaseMaxIdleConns.Name, databaseMaxIdleConns,
"--" + flags.DatabaseConnMaxLifetime.Name, databaseMaxConnLifetime,
"--" + flags.HTTPPort.Name, HTTPPort,
"--" + flags.GuardianProverContractAddress.Name, guardianProverAddress,
"--" + flags.GuardianProverEndpoints.Name, guardianProverEndpoints,
}))
}
Loading

0 comments on commit 975c882

Please sign in to comment.