Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/long-ties-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/l2geth-exporter': patch
---

Added SCC collection
23 changes: 19 additions & 4 deletions go/l2geth-exporter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,32 @@ lint:
golangci-lint run ./...

binding:
$(eval temp := $(shell mktemp))
$(eval tempCTC := $(shell mktemp))

cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \
| jq -r .bytecode > $(temp)
| jq -r .bytecode > $(tempCTC)

cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \
| jq .abi \
| abigen --pkg bindings \
--abi - \
--out bindings/CanonicalTransactionChain.go \
--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)
862 changes: 862 additions & 0 deletions go/l2geth-exporter/bindings/StateCommitmentChain.go

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions go/l2geth-exporter/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import (

//Define the metrics we wish to expose
var (
ctcTotalElements = prometheus.NewGaugeVec(
addressTotalElements = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "l2geth_ctc_total_elements",
Help: "CTC GetTotalElements value."},
[]string{"state"},
Name: "l2geth_total_elements",
Help: "GetTotalElements value."},
[]string{"state", "address"},
)
ctcTotalElementsCallSuccess = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "l2geth_ctc_total_elements_call_success",
Help: "CTC GetTotalElements call success."},
addressTotalElementsCallStatus = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "l2geth_total_elements_call_success",
Comment thread
optimisticben marked this conversation as resolved.
Outdated
Help: "GetTotalElements call status."},
[]string{"status", "address"},
)
)

func init() {
//Register metrics with prometheus
prometheus.MustRegister(ctcTotalElements)
prometheus.MustRegister(ctcTotalElementsCallSuccess)
prometheus.MustRegister(addressTotalElements)
prometheus.MustRegister(addressTotalElementsCallStatus)
}
26 changes: 25 additions & 1 deletion go/l2geth-exporter/l1contracts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,36 @@ import (
"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 {
Address common.Address
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) {

contract, err := bindings.NewCanonicalTransactionChainCaller(ctc.Address, ctc.Client)
Expand Down
52 changes: 43 additions & 9 deletions go/l2geth-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ func main() {
log.Error("L1_URL environmental variable is required")
os.Exit(1)
}
ctcAddress := os.Getenv("CTC_ADDRESS")
ctcAddress := os.Getenv("OVM_CTC_ADDRESS")
if ctcAddress == "" {
log.Error("CTC_ADDRESS environmental variable is required")
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)
if err != nil {
log.Error("Problem connecting to L1: %s", err)
Expand All @@ -51,7 +56,8 @@ func main() {
</body>
</html>`))
})
go getCTCTotalElements(ctcAddress, client)
go getCTCTotalElements(ctcAddress, "ctc", client)
go getSCCTotalElements(sccAddress, "scc", client)
Comment thread
optimisticben marked this conversation as resolved.

log.Info("Program starting", "listenAddress", listenAddress, "GETH_URL", l1Url, "CTC_ADDRESS", ctcAddress)
if err := http.ListenAndServe(listenAddress, nil); err != nil {
Expand All @@ -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{
Comment thread
optimisticben marked this conversation as resolved.
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{
Address: common.HexToAddress(address),
Client: client,
Expand All @@ -72,16 +106,16 @@ func getCTCTotalElements(address string, client *ethclient.Client) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(l1TimeoutSeconds))
totalElements, err := ctc.GetTotalElements(ctx)
if err != nil {
ctcTotalElementsCallSuccess.Set(0)
log.Error("Error calling GetTotalElements", "error", err)
addressTotalElementsCallStatus.WithLabelValues("error", addressLabel).Inc()
log.Error("Error calling GetTotalElements", "address", addressLabel, "error", err)
cancel()
continue
}
ctcTotalElementsCallSuccess.Set(1)
addressTotalElementsCallStatus.WithLabelValues("success", addressLabel).Inc()
totalElementsFloat, _ := new(big.Float).SetInt(totalElements).Float64()
ctcTotalElements.WithLabelValues(
"latest").Set(totalElementsFloat)
log.Info("ctc updated", "ctcTotalElements", totalElementsFloat)
addressTotalElements.WithLabelValues("latest", addressLabel).Set(totalElementsFloat)

log.Info(addressLabel, "TotalElements", totalElementsFloat)
cancel()
<-ticker.C

Expand Down