Commit a756c1f3 authored by Ben Wilson's avatar Ben Wilson

Removed OVM string, added success in calling metric

parent 71bfa3fe
SHELL := /bin/bash SHELL := /bin/bash
GITCOMMIT := $(shell git rev-parse HEAD) VERSION := `git describe --abbrev=0`
GITDATE := $(shell git show -s --format='%ct') GITCOMMIT := `git rev-parse HEAD`
GITVERSION := $(shell cat package.json | jq .version) BUILDDATE := `date +%Y-%m-%d`
BUILDUSER := `whoami`
LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT) LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE) LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
LDFLAGSSTRING +=-X main.GitVersion=$(GITVERSION) LDFLAGSSTRING +=-X main.GitVersion=$(GITVERSION)
LDFLAGS :=-ldflags "$(LDFLAGSSTRING)" LDFLAGS :=-ldflags "$(LDFLAGSSTRING)"
l2geth-exporter: all: build
env GO111MODULE=on go build $(LDFLAGS)
build:
CGO_ENABLED=0 go build $(LDFLAGS)
clean: clean:
rm l2geth-exporter rm l2geth-exporter
...@@ -24,15 +27,15 @@ lint: ...@@ -24,15 +27,15 @@ lint:
binding: binding:
$(eval temp := $(shell mktemp)) $(eval temp := $(shell mktemp))
cat ../../packages/contracts/deployments/mainnet/OVM_CanonicalTransactionChain.json \ cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \
| jq -r .bytecode > $(temp) | jq -r .bytecode > $(temp)
cat ../../packages/contracts/deployments/mainnet/OVM_CanonicalTransactionChain.json \ cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \
| jq .abi \ | jq .abi \
| abigen --pkg bindings \ | abigen --pkg bindings \
--abi - \ --abi - \
--out bindings/OVM_CanonicalTransactionChain.go \ --out bindings/CanonicalTransactionChain.go \
--type OVMCanonicalTransactionChain \ --type CanonicalTransactionChain \
--bin $(temp) --bin $(temp)
rm $(temp) rm $(temp)
This diff is collapsed.
...@@ -6,15 +6,21 @@ import ( ...@@ -6,15 +6,21 @@ import (
//Define the metrics we wish to expose //Define the metrics we wish to expose
var ( var (
ovmctcTotalElements = prometheus.NewGaugeVec( ctcTotalElements = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Name: "ovmctc_total_elements", Name: "l2geth_ctc_total_elements",
Help: "OVM CTC GetTotalElements value."}, Help: "CTC GetTotalElements value."},
[]string{"state"}, []string{"state"},
) )
ctcTotalElementsCallSuccess = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "l2geth_ctc_total_elements_call_success",
Help: "CTC GetTotalElements call success."},
)
) )
func init() { func init() {
//Register metrics with prometheus //Register metrics with prometheus
prometheus.MustRegister(ovmctcTotalElements) prometheus.MustRegister(ctcTotalElements)
prometheus.MustRegister(ctcTotalElementsCallSuccess)
} }
module github.com/optimisticben/optimism/go/l2geth-exporter module github.com/ethereum-optimism/optimism/go/l2geth-exporter
go 1.16 go 1.16
require ( require (
github.com/ethereum/go-ethereum v1.10.8 github.com/ethereum/go-ethereum v1.10.8
github.com/prometheus/client_golang v1.11.0 // indirect github.com/prometheus/client_golang v1.11.0
) )
This diff is collapsed.
...@@ -4,28 +4,28 @@ import ( ...@@ -4,28 +4,28 @@ import (
"context" "context"
"math/big" "math/big"
"github.com/ethereum-optimism/optimism/go/l2geth-exporter/bindings"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/optimisticben/optimism/go/l2geth-exporter/bindings"
) )
// OVMCTC interacts with the OVM CTC contract // CTC interacts with the OVM CTC contract
type OVMCTC struct { type CTC struct {
Ctx context.Context Ctx context.Context
Address common.Address Address common.Address
Client *ethclient.Client Client *ethclient.Client
} }
func (ovmctc *OVMCTC) GetTotalElements() (*big.Int, error) { func (ctc *CTC) GetTotalElements() (*big.Int, error) {
contract, err := bindings.NewOVMCanonicalTransactionChainCaller(ovmctc.Address, ovmctc.Client) contract, err := bindings.NewCanonicalTransactionChainCaller(ctc.Address, ctc.Client)
if err != nil { if err != nil {
return nil, err return nil, err
} }
totalElements, err := contract.GetTotalElements(&bind.CallOpts{ totalElements, err := contract.GetTotalElements(&bind.CallOpts{
Context: ovmctc.Ctx, Context: ctc.Ctx,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -6,10 +6,10 @@ import ( ...@@ -6,10 +6,10 @@ import (
"os" "os"
"time" "time"
"github.com/ethereum-optimism/optimism/go/l2geth-exporter/l1contracts"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/optimisticben/optimism/go/l2geth-exporter/l1contracts"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )
...@@ -19,19 +19,21 @@ func main() { ...@@ -19,19 +19,21 @@ func main() {
listenAddress = ":9100" listenAddress = ":9100"
} }
gethUrl := os.Getenv("GETH_URL") log.Root().SetHandler(log.CallerFileHandler(log.StdoutHandler))
if gethUrl == "" {
log.Error("GETH_URL environmental variable is required") l1Url := os.Getenv("L1_URL")
if l1Url == "" {
log.Error("L1_URL environmental variable is required")
os.Exit(1) os.Exit(1)
} }
ovmCtcAddress := os.Getenv("OVM_CTC_ADDRESS") ctcAddress := os.Getenv("CTC_ADDRESS")
if ovmCtcAddress == "" { if ctcAddress == "" {
log.Error("OVM_CTC_ADDRESS environmental variable is required") log.Error("CTC_ADDRESS environmental variable is required")
os.Exit(1) os.Exit(1)
} }
client, err := ethclient.Dial(gethUrl) client, err := ethclient.Dial(l1Url)
if err != nil { if err != nil {
log.Error("Problem connecting to GETH: %s", err) log.Error("Problem connecting to L1: %s", err)
} }
http.Handle("/metrics", promhttp.Handler()) http.Handle("/metrics", promhttp.Handler())
...@@ -44,17 +46,17 @@ func main() { ...@@ -44,17 +46,17 @@ func main() {
</body> </body>
</html>`)) </html>`))
}) })
go getCTCTotalElements(ovmCtcAddress, client) go getCTCTotalElements(ctcAddress, client)
log.Info("Listening on", listenAddress) log.Info("Program starting", "listenAddress", listenAddress, "GETH_URL", l1Url, "CTC_ADDRESS", ctcAddress)
if err := http.ListenAndServe(listenAddress, nil); err != nil { if err := http.ListenAndServe(listenAddress, nil); err != nil {
log.Error("Can't start http server: %s", err) log.Error("Can't start http server", "error", err)
} }
} }
func getCTCTotalElements(address string, client *ethclient.Client) { func getCTCTotalElements(address string, client *ethclient.Client) {
ovmCTC := l1contracts.OVMCTC{ ctc := l1contracts.CTC{
Address: common.HexToAddress(address), Address: common.HexToAddress(address),
Client: client, Client: client,
} }
...@@ -62,16 +64,18 @@ func getCTCTotalElements(address string, client *ethclient.Client) { ...@@ -62,16 +64,18 @@ func getCTCTotalElements(address string, client *ethclient.Client) {
ticker := time.NewTicker(30 * time.Second) ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop() defer ticker.Stop()
for { for {
<-ticker.C totalElements, err := ctc.GetTotalElements()
totalElements, err := ovmCTC.GetTotalElements()
if err != nil { if err != nil {
log.Error("Error calling GetTotalElements: %s", err) ctcTotalElementsCallSuccess.Set(0)
log.Error("Error calling GetTotalElements", "error", err)
continue continue
} }
ctcTotalElementsCallSuccess.Set(1)
totalElementsFloat, _ := new(big.Float).SetInt(totalElements).Float64() totalElementsFloat, _ := new(big.Float).SetInt(totalElements).Float64()
ovmctcTotalElements.WithLabelValues( ctcTotalElements.WithLabelValues(
"latest").Set(totalElementsFloat) "latest").Set(totalElementsFloat)
<-ticker.C
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment