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
f37bb6e5
Commit
f37bb6e5
authored
May 05, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor duplicated service utilities.
parent
8053be9d
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
78 additions
and
115 deletions
+78
-115
batch_submitter.go
op-batcher/batcher/batch_submitter.go
+0
-7
driver.go
op-batcher/batcher/driver.go
+4
-3
challenger.go
op-challenger/challenger/challenger.go
+6
-4
utils.go
op-challenger/challenger/utils.go
+0
-49
l2_output_submitter.go
op-proposer/proposer/l2_output_submitter.go
+5
-3
utils.go
op-proposer/proposer/utils.go
+0
-49
ethclient.go
op-service/client/ethclient.go
+18
-0
rollup.go
op-service/client/rollup.go
+25
-0
timeout.go
op-service/client/timeout.go
+8
-0
util.go
op-service/util.go
+12
-0
No files found.
op-batcher/batcher/batch_submitter.go
View file @
f37bb6e5
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"os"
"os"
"os/signal"
"os/signal"
"syscall"
"syscall"
"time"
gethrpc
"github.com/ethereum/go-ethereum/rpc"
gethrpc
"github.com/ethereum/go-ethereum/rpc"
"github.com/urfave/cli"
"github.com/urfave/cli"
...
@@ -20,12 +19,6 @@ import (
...
@@ -20,12 +19,6 @@ import (
oprpc
"github.com/ethereum-optimism/optimism/op-service/rpc"
oprpc
"github.com/ethereum-optimism/optimism/op-service/rpc"
)
)
const
(
// defaultDialTimeout is default duration the service will wait on
// startup to make a connection to either the L1 or L2 backends.
defaultDialTimeout
=
5
*
time
.
Second
)
// Main is the entrypoint into the Batch Submitter. This method returns a
// Main is the entrypoint into the Batch Submitter. This method returns a
// closure that executes the service and blocks until the service exits. The use
// closure that executes the service and blocks until the service exits. The use
// of a closure allows the parameters bound to the top-level main package, e.g.
// of a closure allows the parameters bound to the top-level main package, e.g.
...
...
op-batcher/batcher/driver.go
View file @
f37bb6e5
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"github.com/ethereum-optimism/optimism/op-batcher/metrics"
"github.com/ethereum-optimism/optimism/op-batcher/metrics"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
opclient
"github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
...
@@ -49,17 +50,17 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metri
...
@@ -49,17 +50,17 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metri
// Connect to L1 and L2 providers. Perform these last since they are the
// Connect to L1 and L2 providers. Perform these last since they are the
// most expensive.
// most expensive.
l1Client
,
err
:=
dialEthClientWithTimeout
(
ctx
,
cfg
.
L1EthRpc
)
l1Client
,
err
:=
opclient
.
DialEthClientWithTimeout
(
ctx
,
cfg
.
L1EthRpc
,
opclient
.
DefaultDialTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
l2Client
,
err
:=
dialEthClientWithTimeout
(
ctx
,
cfg
.
L2EthRpc
)
l2Client
,
err
:=
opclient
.
DialEthClientWithTimeout
(
ctx
,
cfg
.
L2EthRpc
,
opclient
.
DefaultDialTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
rollupClient
,
err
:=
dialRollupClientWithTimeout
(
ctx
,
cfg
.
RollupRpc
)
rollupClient
,
err
:=
opclient
.
DialRollupClientWithTimeout
(
ctx
,
cfg
.
RollupRpc
,
opclient
.
DefaultDialTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
op-challenger/challenger/challenger.go
View file @
f37bb6e5
...
@@ -20,6 +20,8 @@ import (
...
@@ -20,6 +20,8 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/metrics"
"github.com/ethereum-optimism/optimism/op-challenger/metrics"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-node/sources"
opservice
"github.com/ethereum-optimism/optimism/op-service"
opclient
"github.com/ethereum-optimism/optimism/op-service/client"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
oppprof
"github.com/ethereum-optimism/optimism/op-service/pprof"
oppprof
"github.com/ethereum-optimism/optimism/op-service/pprof"
oprpc
"github.com/ethereum-optimism/optimism/op-service/rpc"
oprpc
"github.com/ethereum-optimism/optimism/op-service/rpc"
...
@@ -145,12 +147,12 @@ func NewChallengerFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metricer)
...
@@ -145,12 +147,12 @@ func NewChallengerFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metricer)
// NewChallengerConfigFromCLIConfig creates the challenger config from the CLI config.
// NewChallengerConfigFromCLIConfig creates the challenger config from the CLI config.
func
NewChallengerConfigFromCLIConfig
(
cfg
CLIConfig
,
l
log
.
Logger
,
m
metrics
.
Metricer
)
(
*
Config
,
error
)
{
func
NewChallengerConfigFromCLIConfig
(
cfg
CLIConfig
,
l
log
.
Logger
,
m
metrics
.
Metricer
)
(
*
Config
,
error
)
{
l2ooAddress
,
err
:=
p
arseAddress
(
cfg
.
L2OOAddress
)
l2ooAddress
,
err
:=
opservice
.
P
arseAddress
(
cfg
.
L2OOAddress
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
dgfAddress
,
err
:=
p
arseAddress
(
cfg
.
DGFAddress
)
dgfAddress
,
err
:=
opservice
.
P
arseAddress
(
cfg
.
DGFAddress
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -162,12 +164,12 @@ func NewChallengerConfigFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Met
...
@@ -162,12 +164,12 @@ func NewChallengerConfigFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Met
// Connect to L1 and L2 providers. Perform these last since they are the most expensive.
// Connect to L1 and L2 providers. Perform these last since they are the most expensive.
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
l1Client
,
err
:=
dialEthClientWithTimeout
(
ctx
,
cfg
.
L1EthRpc
)
l1Client
,
err
:=
opclient
.
DialEthClientWithTimeout
(
ctx
,
cfg
.
L1EthRpc
,
opclient
.
DefaultDialTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
rollupClient
,
err
:=
dialRollupClientWithTimeout
(
ctx
,
cfg
.
RollupRpc
)
rollupClient
,
err
:=
opclient
.
DialRollupClientWithTimeout
(
ctx
,
cfg
.
RollupRpc
,
opclient
.
DefaultDialTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
op-challenger/challenger/utils.go
deleted
100644 → 0
View file @
8053be9d
package
challenger
import
(
"context"
"fmt"
"time"
"github.com/ethereum-optimism/optimism/op-node/client"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
)
var
defaultDialTimeout
=
5
*
time
.
Second
// dialEthClientWithTimeout attempts to dial the L1 provider using the provided
// URL. If the dial doesn't complete within defaultDialTimeout seconds, this
// method will return an error.
func
dialEthClientWithTimeout
(
ctx
context
.
Context
,
url
string
)
(
*
ethclient
.
Client
,
error
)
{
ctxt
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultDialTimeout
)
defer
cancel
()
return
ethclient
.
DialContext
(
ctxt
,
url
)
}
// dialRollupClientWithTimeout attempts to dial the RPC provider using the provided
// URL. If the dial doesn't complete within defaultDialTimeout seconds, this
// method will return an error.
func
dialRollupClientWithTimeout
(
ctx
context
.
Context
,
url
string
)
(
*
sources
.
RollupClient
,
error
)
{
ctxt
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultDialTimeout
)
defer
cancel
()
rpcCl
,
err
:=
rpc
.
DialContext
(
ctxt
,
url
)
if
err
!=
nil
{
return
nil
,
err
}
return
sources
.
NewRollupClient
(
client
.
NewBaseRPCClient
(
rpcCl
)),
nil
}
// parseAddress parses an ETH address from a hex string. This method will fail if
// the address is not a valid hexadecimal address.
func
parseAddress
(
address
string
)
(
common
.
Address
,
error
)
{
if
common
.
IsHexAddress
(
address
)
{
return
common
.
HexToAddress
(
address
),
nil
}
return
common
.
Address
{},
fmt
.
Errorf
(
"invalid address: %v"
,
address
)
}
op-proposer/proposer/l2_output_submitter.go
View file @
f37bb6e5
...
@@ -23,6 +23,8 @@ import (
...
@@ -23,6 +23,8 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-proposer/metrics"
"github.com/ethereum-optimism/optimism/op-proposer/metrics"
opservice
"github.com/ethereum-optimism/optimism/op-service"
opclient
"github.com/ethereum-optimism/optimism/op-service/client"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
oplog
"github.com/ethereum-optimism/optimism/op-service/log"
oppprof
"github.com/ethereum-optimism/optimism/op-service/pprof"
oppprof
"github.com/ethereum-optimism/optimism/op-service/pprof"
oprpc
"github.com/ethereum-optimism/optimism/op-service/rpc"
oprpc
"github.com/ethereum-optimism/optimism/op-service/rpc"
...
@@ -148,7 +150,7 @@ func NewL2OutputSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Me
...
@@ -148,7 +150,7 @@ func NewL2OutputSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Me
// NewL2OutputSubmitterConfigFromCLIConfig creates the proposer config from the CLI config.
// NewL2OutputSubmitterConfigFromCLIConfig creates the proposer config from the CLI config.
func
NewL2OutputSubmitterConfigFromCLIConfig
(
cfg
CLIConfig
,
l
log
.
Logger
,
m
metrics
.
Metricer
)
(
*
Config
,
error
)
{
func
NewL2OutputSubmitterConfigFromCLIConfig
(
cfg
CLIConfig
,
l
log
.
Logger
,
m
metrics
.
Metricer
)
(
*
Config
,
error
)
{
l2ooAddress
,
err
:=
p
arseAddress
(
cfg
.
L2OOAddress
)
l2ooAddress
,
err
:=
opservice
.
P
arseAddress
(
cfg
.
L2OOAddress
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -160,12 +162,12 @@ func NewL2OutputSubmitterConfigFromCLIConfig(cfg CLIConfig, l log.Logger, m metr
...
@@ -160,12 +162,12 @@ func NewL2OutputSubmitterConfigFromCLIConfig(cfg CLIConfig, l log.Logger, m metr
// Connect to L1 and L2 providers. Perform these last since they are the most expensive.
// Connect to L1 and L2 providers. Perform these last since they are the most expensive.
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
l1Client
,
err
:=
dialEthClientWithTimeout
(
ctx
,
cfg
.
L1EthRpc
)
l1Client
,
err
:=
opclient
.
DialEthClientWithTimeout
(
ctx
,
cfg
.
L1EthRpc
,
opclient
.
DefaultDialTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
rollupClient
,
err
:=
dialRollupClientWithTimeout
(
ctx
,
cfg
.
RollupRpc
)
rollupClient
,
err
:=
opclient
.
DialRollupClientWithTimeout
(
ctx
,
cfg
.
RollupRpc
,
opclient
.
DefaultDialTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
op-proposer/proposer/utils.go
deleted
100644 → 0
View file @
8053be9d
package
proposer
import
(
"context"
"fmt"
"time"
"github.com/ethereum-optimism/optimism/op-node/client"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
)
var
defaultDialTimeout
=
5
*
time
.
Second
// dialEthClientWithTimeout attempts to dial the L1 provider using the provided
// URL. If the dial doesn't complete within defaultDialTimeout seconds, this
// method will return an error.
func
dialEthClientWithTimeout
(
ctx
context
.
Context
,
url
string
)
(
*
ethclient
.
Client
,
error
)
{
ctxt
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultDialTimeout
)
defer
cancel
()
return
ethclient
.
DialContext
(
ctxt
,
url
)
}
// dialRollupClientWithTimeout attempts to dial the RPC provider using the provided
// URL. If the dial doesn't complete within defaultDialTimeout seconds, this
// method will return an error.
func
dialRollupClientWithTimeout
(
ctx
context
.
Context
,
url
string
)
(
*
sources
.
RollupClient
,
error
)
{
ctxt
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultDialTimeout
)
defer
cancel
()
rpcCl
,
err
:=
rpc
.
DialContext
(
ctxt
,
url
)
if
err
!=
nil
{
return
nil
,
err
}
return
sources
.
NewRollupClient
(
client
.
NewBaseRPCClient
(
rpcCl
)),
nil
}
// parseAddress parses an ETH address from a hex string. This method will fail if
// the address is not a valid hexadecimal address.
func
parseAddress
(
address
string
)
(
common
.
Address
,
error
)
{
if
common
.
IsHexAddress
(
address
)
{
return
common
.
HexToAddress
(
address
),
nil
}
return
common
.
Address
{},
fmt
.
Errorf
(
"invalid address: %v"
,
address
)
}
op-service/client/ethclient.go
0 → 100644
View file @
f37bb6e5
package
client
import
(
"context"
"time"
"github.com/ethereum/go-ethereum/ethclient"
)
// DialEthClientWithTimeout attempts to dial the L1 provider using the provided
// URL. If the dial doesn't complete within defaultDialTimeout seconds, this
// method will return an error.
func
DialEthClientWithTimeout
(
ctx
context
.
Context
,
url
string
,
timeout
time
.
Duration
)
(
*
ethclient
.
Client
,
error
)
{
ctxt
,
cancel
:=
context
.
WithTimeout
(
ctx
,
timeout
)
defer
cancel
()
return
ethclient
.
DialContext
(
ctxt
,
url
)
}
op-
batcher/batcher/utils
.go
→
op-
service/client/rollup
.go
View file @
f37bb6e5
package
batcher
package
client
import
(
import
(
"context"
"context"
"time"
"github.com/ethereum-optimism/optimism/op-node/client"
"github.com/ethereum-optimism/optimism/op-node/client"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc"
)
)
//
dialEthClientWithTimeout attempts to dial the L1
provider using the provided
//
DialRollupClientWithTimeout attempts to dial the RPC
provider using the provided
// URL. If the dial doesn't complete within defaultDialTimeout seconds, this
// URL. If the dial doesn't complete within defaultDialTimeout seconds, this
// method will return an error.
// method will return an error.
func
dialEthClientWithTimeout
(
ctx
context
.
Context
,
url
string
)
(
*
ethclient
.
Client
,
error
)
{
func
DialRollupClientWithTimeout
(
ctx
context
.
Context
,
url
string
,
timeout
time
.
Duration
)
(
*
sources
.
RollupClient
,
error
)
{
ctxt
,
cancel
:=
context
.
WithTimeout
(
ctx
,
timeout
)
ctxt
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultDialTimeout
)
defer
cancel
()
return
ethclient
.
DialContext
(
ctxt
,
url
)
}
// dialRollupClientWithTimeout attempts to dial the RPC provider using the provided
// URL. If the dial doesn't complete within defaultDialTimeout seconds, this
// method will return an error.
func
dialRollupClientWithTimeout
(
ctx
context
.
Context
,
url
string
)
(
*
sources
.
RollupClient
,
error
)
{
ctxt
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultDialTimeout
)
defer
cancel
()
defer
cancel
()
rpcCl
,
err
:=
rpc
.
DialContext
(
ctxt
,
url
)
rpcCl
,
err
:=
rpc
.
DialContext
(
ctxt
,
url
)
...
...
op-service/client/timeout.go
0 → 100644
View file @
f37bb6e5
package
client
import
(
"time"
)
// DefaultDialTimeout is a default timeout for dialing a client.
const
DefaultDialTimeout
=
5
*
time
.
Second
op-service/util.go
View file @
f37bb6e5
...
@@ -3,16 +3,28 @@ package op_service
...
@@ -3,16 +3,28 @@ package op_service
import
(
import
(
"context"
"context"
"errors"
"errors"
"fmt"
"os"
"os"
"os/signal"
"os/signal"
"syscall"
"syscall"
"time"
"time"
"github.com/ethereum/go-ethereum/common"
)
)
func
PrefixEnvVar
(
prefix
,
suffix
string
)
string
{
func
PrefixEnvVar
(
prefix
,
suffix
string
)
string
{
return
prefix
+
"_"
+
suffix
return
prefix
+
"_"
+
suffix
}
}
// ParseAddress parses an ETH address from a hex string. This method will fail if
// the address is not a valid hexadecimal address.
func
ParseAddress
(
address
string
)
(
common
.
Address
,
error
)
{
if
common
.
IsHexAddress
(
address
)
{
return
common
.
HexToAddress
(
address
),
nil
}
return
common
.
Address
{},
fmt
.
Errorf
(
"invalid address: %v"
,
address
)
}
// CloseAction runs the function in the background, until it finishes or until it is closed by the user with an interrupt.
// CloseAction runs the function in the background, until it finishes or until it is closed by the user with an interrupt.
func
CloseAction
(
fn
func
(
ctx
context
.
Context
,
shutdown
<-
chan
struct
{})
error
)
error
{
func
CloseAction
(
fn
func
(
ctx
context
.
Context
,
shutdown
<-
chan
struct
{})
error
)
error
{
stopped
:=
make
(
chan
error
,
1
)
stopped
:=
make
(
chan
error
,
1
)
...
...
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