Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
82f96927
Unverified
Commit
82f96927
authored
Dec 20, 2021
by
Ben Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added context to GetTotalElements
parent
a756c1f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
main.go
go/l2geth-exporter/l1contracts/main.go
+2
-3
main.go
go/l2geth-exporter/main.go
+10
-2
No files found.
go/l2geth-exporter/l1contracts/main.go
View file @
82f96927
...
...
@@ -12,12 +12,11 @@ import (
// CTC interacts with the OVM CTC contract
type
CTC
struct
{
Ctx
context
.
Context
Address
common
.
Address
Client
*
ethclient
.
Client
}
func
(
ctc
*
CTC
)
GetTotalElements
()
(
*
big
.
Int
,
error
)
{
func
(
ctc
*
CTC
)
GetTotalElements
(
ctx
context
.
Context
)
(
*
big
.
Int
,
error
)
{
contract
,
err
:=
bindings
.
NewCanonicalTransactionChainCaller
(
ctc
.
Address
,
ctc
.
Client
)
if
err
!=
nil
{
...
...
@@ -25,7 +24,7 @@ func (ctc *CTC) GetTotalElements() (*big.Int, error) {
}
totalElements
,
err
:=
contract
.
GetTotalElements
(
&
bind
.
CallOpts
{
Context
:
ct
c
.
Ct
x
,
Context
:
ctx
,
})
if
err
!=
nil
{
return
nil
,
err
...
...
go/l2geth-exporter/main.go
View file @
82f96927
package
main
import
(
"context"
"math/big"
"net/http"
"os"
...
...
@@ -13,6 +14,10 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var
(
l1TimeoutSeconds
=
5
)
func
main
()
{
listenAddress
:=
os
.
Getenv
(
"LISTEN_ADDRESS"
)
if
listenAddress
==
""
{
...
...
@@ -64,17 +69,20 @@ func getCTCTotalElements(address string, client *ethclient.Client) {
ticker
:=
time
.
NewTicker
(
30
*
time
.
Second
)
defer
ticker
.
Stop
()
for
{
totalElements
,
err
:=
ctc
.
GetTotalElements
()
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
)
cancel
()
continue
}
ctcTotalElementsCallSuccess
.
Set
(
1
)
totalElementsFloat
,
_
:=
new
(
big
.
Float
)
.
SetInt
(
totalElements
)
.
Float64
()
ctcTotalElements
.
WithLabelValues
(
"latest"
)
.
Set
(
totalElementsFloat
)
log
.
Info
(
"ctc updated"
,
"ctcTotalElements"
,
totalElementsFloat
)
ctx
.
Done
()
<-
ticker
.
C
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment