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
f4f3054a
Unverified
Commit
f4f3054a
authored
Mar 03, 2022
by
Conner Fromknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add teleportr API server
parent
bced4fa9
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
822 additions
and
1 deletion
+822
-1
mighty-sloths-float.md
.changeset/mighty-sloths-float.md
+5
-0
Makefile
go/teleportr/Makefile
+5
-0
metrics.go
go/teleportr/api/metrics.go
+43
-0
server.go
go/teleportr/api/server.go
+626
-0
main.go
go/teleportr/cmd/teleportr-api/main.go
+42
-0
api_flags.go
go/teleportr/flags/api_flags.go
+97
-0
go.mod
go/teleportr/go.mod
+3
-1
go.sum
go/teleportr/go.sum
+1
-0
No files found.
.changeset/mighty-sloths-float.md
0 → 100644
View file @
f4f3054a
---
'
@eth-optimism/teleportr'
:
patch
---
Add teleportr API server
go/teleportr/Makefile
View file @
f4f3054a
...
...
@@ -13,8 +13,12 @@ DISBURSER_ARTIFACT := ../../packages/contracts/artifacts/contracts/L2/teleportr/
teleportr
:
env
GO111MODULE
=
on go build
-v
$(LDFLAGS)
./cmd/teleportr
teleportr-api
:
env
GO111MODULE
=
on go build
-v
$(LDFLAGS)
./cmd/teleportr-api
clean
:
rm
teleportr
rm
api
test
:
go
test
-v
./...
...
...
@@ -48,6 +52,7 @@ bindings-disburser:
.PHONY
:
\
teleportr
\
teleportr-api
\
bindings
\
bindings-deposit
\
bindings-disburser
\
...
...
go/teleportr/api/metrics.go
0 → 100644
View file @
f4f3054a
package
api
import
(
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const
TeleportrAPINamespace
=
"teleportr_api"
var
(
rpcRequestsTotal
=
promauto
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
TeleportrAPINamespace
,
Name
:
"rpc_requests_total"
,
Help
:
"Count of total client RPC requests."
,
})
httpResponseCodesTotal
=
promauto
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
TeleportrAPINamespace
,
Name
:
"http_response_codes_total"
,
Help
:
"Count of total HTTP response codes."
,
},
[]
string
{
"status_code"
,
})
httpRequestDurationSumm
=
promauto
.
NewSummary
(
prometheus
.
SummaryOpts
{
Namespace
:
TeleportrAPINamespace
,
Name
:
"http_request_duration_seconds"
,
Help
:
"Summary of HTTP request durations, in seconds."
,
Objectives
:
map
[
float64
]
float64
{
0.5
:
0.05
,
0.9
:
0.01
,
0.95
:
0.005
,
0.99
:
0.001
},
})
databaseErrorsTotal
=
promauto
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
TeleportrAPINamespace
,
Name
:
"database_errors_total"
,
Help
:
"Count of total database failures."
,
},
[]
string
{
"method"
,
})
rpcErrorsTotal
=
promauto
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
TeleportrAPINamespace
,
Name
:
"rpc_errors_total"
,
Help
:
"Count of total L1 rpc failures."
,
},
[]
string
{
"method"
,
})
)
go/teleportr/api/server.go
0 → 100644
View file @
f4f3054a
This diff is collapsed.
Click to expand it.
go/teleportr/cmd/teleportr-api/main.go
0 → 100644
View file @
f4f3054a
package
main
import
(
"fmt"
"os"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli"
"github.com/ethereum-optimism/optimism/go/teleportr/api"
"github.com/ethereum-optimism/optimism/go/teleportr/flags"
)
var
(
GitVersion
=
""
GitCommit
=
""
GitDate
=
""
)
func
main
()
{
// Set up logger with a default INFO level in case we fail to parse flags.
// Otherwise the final critical log won't show what the parsing error was.
log
.
Root
()
.
SetHandler
(
log
.
LvlFilterHandler
(
log
.
LvlInfo
,
log
.
StreamHandler
(
os
.
Stdout
,
log
.
TerminalFormat
(
true
)),
),
)
app
:=
cli
.
NewApp
()
app
.
Flags
=
flags
.
APIFlags
app
.
Version
=
fmt
.
Sprintf
(
"%s-%s-%s"
,
GitVersion
,
GitCommit
,
GitDate
)
app
.
Name
=
"teleportr-api"
app
.
Usage
=
"Teleportr API server"
app
.
Description
=
"API serving teleportr data"
app
.
Action
=
api
.
Main
(
GitVersion
)
err
:=
app
.
Run
(
os
.
Args
)
if
err
!=
nil
{
log
.
Crit
(
"Application failed"
,
"message"
,
err
)
}
}
go/teleportr/flags/api_flags.go
0 → 100644
View file @
f4f3054a
package
flags
import
(
"fmt"
"strings"
"github.com/urfave/cli"
)
func
prefixAPIEnvVar
(
name
string
)
string
{
return
fmt
.
Sprintf
(
"TELEPORTR_API_%s"
,
strings
.
ToUpper
(
name
))
}
var
(
APIHostnameFlag
=
cli
.
StringFlag
{
Name
:
"hostname"
,
Usage
:
"The hostname of the API server"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"HOSTNAME"
),
}
APIPortFlag
=
cli
.
StringFlag
{
Name
:
"port"
,
Usage
:
"The hostname of the API server"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"PORT"
),
}
APIL1EthRpcFlag
=
cli
.
StringFlag
{
Name
:
"l1-eth-rpc"
,
Usage
:
"The endpoint for the L1 ETH provider"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"L1_ETH_RPC"
),
}
APIDepositAddressFlag
=
cli
.
StringFlag
{
Name
:
"deposit-address"
,
Usage
:
"Address of the TeleportrDeposit contract"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"DEPOSIT_ADDRESS"
),
}
APINumConfirmationsFlag
=
cli
.
StringFlag
{
Name
:
"num-confirmations"
,
Usage
:
"Number of confirmations required until deposits are "
+
"considered confirmed"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"NUM_CONFIRMATIONS"
),
}
APIPostgresHostFlag
=
cli
.
StringFlag
{
Name
:
"postgres-host"
,
Usage
:
"Host of the teleportr postgres instance"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"POSTGRES_HOST"
),
}
APIPostgresPortFlag
=
cli
.
Uint64Flag
{
Name
:
"postgres-port"
,
Usage
:
"Port of the teleportr postgres instance"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"POSTGRES_PORT"
),
}
APIPostgresUserFlag
=
cli
.
StringFlag
{
Name
:
"postgres-user"
,
Usage
:
"Username of the teleportr postgres instance"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"POSTGRES_USER"
),
}
APIPostgresPasswordFlag
=
cli
.
StringFlag
{
Name
:
"postgres-password"
,
Usage
:
"Password of the teleportr postgres instance"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"POSTGRES_PASSWORD"
),
}
APIPostgresDBNameFlag
=
cli
.
StringFlag
{
Name
:
"postgres-db-name"
,
Usage
:
"Database name of the teleportr postgres instance"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"POSTGRES_DB_NAME"
),
}
APIPostgresEnableSSLFlag
=
cli
.
BoolFlag
{
Name
:
"postgres-enable-ssl"
,
Usage
:
"Whether or not to enable SSL on connections to "
+
"teleportr postgres instance"
,
Required
:
true
,
EnvVar
:
prefixAPIEnvVar
(
"POSTGRES_ENABLE_SSL"
),
}
)
var
APIFlags
=
[]
cli
.
Flag
{
APIHostnameFlag
,
APIPortFlag
,
APIL1EthRpcFlag
,
APIDepositAddressFlag
,
APINumConfirmationsFlag
,
APIPostgresHostFlag
,
APIPostgresPortFlag
,
APIPostgresUserFlag
,
APIPostgresPasswordFlag
,
APIPostgresDBNameFlag
,
APIPostgresEnableSSLFlag
,
}
go/teleportr/go.mod
View file @
f4f3054a
...
...
@@ -6,7 +6,10 @@ require (
github.com/ethereum-optimism/optimism/go/bss-core v0.0.0-20220218171106-67a0414d7606
github.com/ethereum/go-ethereum v1.10.15
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/lib/pq v1.10.4
github.com/prometheus/client_golang v1.11.0
github.com/rs/cors v1.7.0
github.com/stretchr/testify v1.7.0
github.com/urfave/cli v1.22.5
)
...
...
@@ -39,7 +42,6 @@ require (
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
...
...
go/teleportr/go.sum
View file @
f4f3054a
...
...
@@ -265,6 +265,7 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
...
...
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