Skip to content

Commit

Permalink
fly: put tunables into .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Dec 13, 2023
1 parent 56597c2 commit ff8c664
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
59 changes: 35 additions & 24 deletions fly/cmd/fly/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"encoding/hex"
"flag"
"fmt"
"os"
"strconv"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/certusone/wormhole/node/pkg/supervisor"
eth_common "github.com/ethereum/go-ethereum/common"
ipfslog "github.com/ipfs/go-log/v2"
"github.com/joho/godotenv"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/wormhole-foundation/wormhole-monitor/fly/utils"
"github.com/wormhole-foundation/wormhole/sdk/vaa"
Expand Down Expand Up @@ -46,6 +46,9 @@ var (
gcpProjectID string
bigtableInstanceID string
signedVAATopicName string
rpcUrl string
coreBridgeAddr string
credentialsFile string
)

// Make a bigtable row key from a VAA
Expand Down Expand Up @@ -107,30 +110,38 @@ func incrementPythNetMsgCount(ctx context.Context, client *firestore.Client, cou
}
}

func main() {
// TODO: pass in config instead of hard-coding it
p2pNetworkID = "/wormhole/mainnet/2"
p2pBootstrap = "/dns4/wormhole-mainnet-v2-bootstrap.certus.one/udp/8999/quic/p2p/12D3KooWQp644DK27fd3d4Km3jr7gHiuJJ5ZGmy8hH4py7fP4FP7,/dns4/wormhole-v2-mainnet-bootstrap.xlabs.xyz/udp/8999/quic/p2p/12D3KooWNQ9tVrcb64tw6bNs2CaNrUGPM7yRrKvBBheQ5yCyPHKC"
p2pPort = 8999
nodeKeyPath = "/tmp/node.key"
logLevel = "warn"
gcpProjectID = "wormhole-message-db-mainnet"
bigtableInstanceID = "wormhole-mainnet"
signedVAATopicName = "signed-vaa"

rpcUrl := flag.String("rpcUrl", "https://rpc.ankr.com/eth", "RPC URL for fetching current guardian set")
coreBridgeAddr := flag.String("coreBridgeAddr", "0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B", "Core bridge address for fetching guardian set")
credentialsFile := flag.String("credentialsFile", "", "GCP service account or refresh token JSON credentials file")
flag.Parse()
if *credentialsFile == "" {
log.Fatalf("gcpCredentialsFile must be specified")
func loadEnvVars() {
err := godotenv.Load() // By default loads .env
if err != nil {
log.Fatal("Error loading .env file")
}
if *rpcUrl == "" {
log.Fatalf("rpcUrl must be specified")
p2pNetworkID = verifyEnvVar("P2P_NETWORK_ID")
p2pBootstrap = verifyEnvVar("P2P_BOOTSTRAP")
port, err := strconv.ParseUint(verifyEnvVar("P2P_PORT"), 10, 32)
if err != nil {
log.Fatal("Error parsing P2P_PORT")
}
if *coreBridgeAddr == "" {
log.Fatalf("coreBridgeAddr must be specified")
p2pPort = uint(port)
nodeKeyPath = verifyEnvVar("NODE_KEY_PATH")
logLevel = verifyEnvVar("LOG_LEVEL")
gcpProjectID = verifyEnvVar("GCP_PROJECT_ID")
bigtableInstanceID = verifyEnvVar("BIGTABLE_INSTANCE_ID")
signedVAATopicName = verifyEnvVar("SIGNED_VAA_TOPIC_NAME")
rpcUrl = verifyEnvVar("RPC_URL")
coreBridgeAddr = verifyEnvVar("CORE_BRIDGE_ADDR")
credentialsFile = verifyEnvVar("CREDENTIALS_FILE")
}

func verifyEnvVar(key string) string {
value := os.Getenv(key)
if value == "" {
log.Fatalf("%s must be specified", key)
}
return value
}

func main() {
loadEnvVars()

lvl, err := ipfslog.LevelFromString(logLevel)
if err != nil {
Expand All @@ -143,7 +154,7 @@ func main() {
ipfslog.SetAllLoggers(lvl)

ctx := context.Background()
sa := option.WithCredentialsFile(*credentialsFile)
sa := option.WithCredentialsFile(credentialsFile)
app, err := firebase.NewApp(ctx, nil, sa)
if err != nil {
log.Fatalln(err)
Expand Down Expand Up @@ -196,7 +207,7 @@ func main() {
// Governor status
govStatusC := make(chan *gossipv1.SignedChainGovernorStatus, 50)
// Bootstrap guardian set, otherwise heartbeats would be skipped
idx, sgs, err := utils.FetchCurrentGuardianSet(*rpcUrl, *coreBridgeAddr)
idx, sgs, err := utils.FetchCurrentGuardianSet(rpcUrl, coreBridgeAddr)
if err != nil {
logger.Fatal("Failed to fetch guardian set", zap.Error(err))
}
Expand Down
1 change: 1 addition & 0 deletions fly/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ require (
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions fly/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af/go.mod
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down

0 comments on commit ff8c664

Please sign in to comment.