Commit 373d0e6f authored by Ben Wilson's avatar Ben Wilson Committed by GitHub

Added SCC TotalElement collection for metrics (#2353)

* Added SCC TotalElement collection for metrics

* Update addressTotalElementsCallStatus metric name
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent b4dcfdf3
---
'@eth-optimism/l2geth-exporter': patch
---
Added SCC collection
...@@ -25,10 +25,10 @@ lint: ...@@ -25,10 +25,10 @@ lint:
golangci-lint run ./... golangci-lint run ./...
binding: binding:
$(eval temp := $(shell mktemp)) $(eval tempCTC := $(shell mktemp))
cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \ cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \
| jq -r .bytecode > $(temp) | jq -r .bytecode > $(tempCTC)
cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \ cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \
| jq .abi \ | jq .abi \
...@@ -36,6 +36,21 @@ binding: ...@@ -36,6 +36,21 @@ binding:
--abi - \ --abi - \
--out bindings/CanonicalTransactionChain.go \ --out bindings/CanonicalTransactionChain.go \
--type CanonicalTransactionChain \ --type CanonicalTransactionChain \
--bin $(temp) --bin $(tempCTC)
rm $(temp) rm $(tempCTC)
$(eval tempSCC := $(shell mktemp))
cat ../../packages/contracts/deployments/mainnet/StateCommitmentChain.json \
| jq -r .bytecode > $(tempSCC)
cat ../../packages/contracts/deployments/mainnet/StateCommitmentChain.json \
| jq .abi \
| abigen --pkg bindings \
--abi - \
--out bindings/StateCommitmentChain.go \
--type StateCommitmentChain \
--bin $(tempSCC)
rm $(tempSCC)
\ No newline at end of file
This diff is collapsed.
...@@ -6,21 +6,22 @@ import ( ...@@ -6,21 +6,22 @@ import (
//Define the metrics we wish to expose //Define the metrics we wish to expose
var ( var (
ctcTotalElements = prometheus.NewGaugeVec( addressTotalElements = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Name: "l2geth_ctc_total_elements", Name: "l2geth_total_elements",
Help: "CTC GetTotalElements value."}, Help: "GetTotalElements value."},
[]string{"state"}, []string{"state", "address"},
) )
ctcTotalElementsCallSuccess = prometheus.NewGauge( addressTotalElementsCallStatus = prometheus.NewCounterVec(
prometheus.GaugeOpts{ prometheus.CounterOpts{
Name: "l2geth_ctc_total_elements_call_success", Name: "l2geth_total_elements_call_status",
Help: "CTC GetTotalElements call success."}, Help: "GetTotalElements call status."},
[]string{"status", "address"},
) )
) )
func init() { func init() {
//Register metrics with prometheus //Register metrics with prometheus
prometheus.MustRegister(ctcTotalElements) prometheus.MustRegister(addressTotalElements)
prometheus.MustRegister(ctcTotalElementsCallSuccess) prometheus.MustRegister(addressTotalElementsCallStatus)
} }
...@@ -10,12 +10,36 @@ import ( ...@@ -10,12 +10,36 @@ import (
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
) )
// CTC interacts with the OVM CTC contract // CTC interacts with the OVM Canonical Transaction Chain contract
type CTC struct { type CTC struct {
Address common.Address Address common.Address
Client *ethclient.Client Client *ethclient.Client
} }
// SCC interacts with the OVM State Commitment Chain contract
type SCC struct {
Address common.Address
Client *ethclient.Client
}
func (ctc *SCC) GetTotalElements(ctx context.Context) (*big.Int, error) {
contract, err := bindings.NewCanonicalTransactionChainCaller(ctc.Address, ctc.Client)
if err != nil {
return nil, err
}
totalElements, err := contract.GetTotalElements(&bind.CallOpts{
Context: ctx,
})
if err != nil {
return nil, err
}
return totalElements, nil
}
func (ctc *CTC) GetTotalElements(ctx context.Context) (*big.Int, error) { func (ctc *CTC) GetTotalElements(ctx context.Context) (*big.Int, error) {
contract, err := bindings.NewCanonicalTransactionChainCaller(ctc.Address, ctc.Client) contract, err := bindings.NewCanonicalTransactionChainCaller(ctc.Address, ctc.Client)
......
...@@ -31,11 +31,16 @@ func main() { ...@@ -31,11 +31,16 @@ func main() {
log.Error("L1_URL environmental variable is required") log.Error("L1_URL environmental variable is required")
os.Exit(1) os.Exit(1)
} }
ctcAddress := os.Getenv("CTC_ADDRESS") ctcAddress := os.Getenv("OVM_CTC_ADDRESS")
if ctcAddress == "" { if ctcAddress == "" {
log.Error("CTC_ADDRESS environmental variable is required") log.Error("CTC_ADDRESS environmental variable is required")
os.Exit(1) os.Exit(1)
} }
sccAddress := os.Getenv("OVM_SCC_ADDRESS")
if sccAddress == "" {
log.Error("OVM_SCC_ADDRESS environmental variable is required")
os.Exit(1)
}
client, err := ethclient.Dial(l1Url) client, err := ethclient.Dial(l1Url)
if err != nil { if err != nil {
log.Error("Problem connecting to L1: %s", err) log.Error("Problem connecting to L1: %s", err)
...@@ -51,7 +56,8 @@ func main() { ...@@ -51,7 +56,8 @@ func main() {
</body> </body>
</html>`)) </html>`))
}) })
go getCTCTotalElements(ctcAddress, client) go getCTCTotalElements(ctcAddress, "ctc", client)
go getSCCTotalElements(sccAddress, "scc", client)
log.Info("Program starting", "listenAddress", listenAddress, "GETH_URL", l1Url, "CTC_ADDRESS", ctcAddress) 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 {
...@@ -60,7 +66,35 @@ func main() { ...@@ -60,7 +66,35 @@ func main() {
} }
func getCTCTotalElements(address string, client *ethclient.Client) { func getSCCTotalElements(address string, addressLabel string, client *ethclient.Client) {
scc := l1contracts.SCC{
Address: common.HexToAddress(address),
Client: client,
}
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(l1TimeoutSeconds))
totalElements, err := scc.GetTotalElements(ctx)
if err != nil {
addressTotalElementsCallStatus.WithLabelValues("error", addressLabel).Inc()
log.Error("Error calling GetTotalElements", "address", addressLabel, "error", err)
cancel()
continue
}
addressTotalElementsCallStatus.WithLabelValues("success", addressLabel).Inc()
totalElementsFloat, _ := new(big.Float).SetInt(totalElements).Float64()
addressTotalElements.WithLabelValues("latest", addressLabel).Set(totalElementsFloat)
log.Info(addressLabel, "TotalElements", totalElementsFloat)
cancel()
<-ticker.C
}
}
func getCTCTotalElements(address string, addressLabel string, client *ethclient.Client) {
ctc := l1contracts.CTC{ ctc := l1contracts.CTC{
Address: common.HexToAddress(address), Address: common.HexToAddress(address),
Client: client, Client: client,
...@@ -72,16 +106,16 @@ func getCTCTotalElements(address string, client *ethclient.Client) { ...@@ -72,16 +106,16 @@ func getCTCTotalElements(address string, client *ethclient.Client) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(l1TimeoutSeconds)) ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(l1TimeoutSeconds))
totalElements, err := ctc.GetTotalElements(ctx) totalElements, err := ctc.GetTotalElements(ctx)
if err != nil { if err != nil {
ctcTotalElementsCallSuccess.Set(0) addressTotalElementsCallStatus.WithLabelValues("error", addressLabel).Inc()
log.Error("Error calling GetTotalElements", "error", err) log.Error("Error calling GetTotalElements", "address", addressLabel, "error", err)
cancel() cancel()
continue continue
} }
ctcTotalElementsCallSuccess.Set(1) addressTotalElementsCallStatus.WithLabelValues("success", addressLabel).Inc()
totalElementsFloat, _ := new(big.Float).SetInt(totalElements).Float64() totalElementsFloat, _ := new(big.Float).SetInt(totalElements).Float64()
ctcTotalElements.WithLabelValues( addressTotalElements.WithLabelValues("latest", addressLabel).Set(totalElementsFloat)
"latest").Set(totalElementsFloat)
log.Info("ctc updated", "ctcTotalElements", totalElementsFloat) log.Info(addressLabel, "TotalElements", totalElementsFloat)
cancel() cancel()
<-ticker.C <-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