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
6dcb3b35
Unverified
Commit
6dcb3b35
authored
Jan 31, 2022
by
Conner Fromknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: extract driver configuration outside of NewBatchSubmitter
parent
21928467
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
148 additions
and
165 deletions
+148
-165
batch_submitter.go
go/batch-submitter/batch_submitter.go
+148
-165
No files found.
go/batch-submitter/batch_submitter.go
View file @
6dcb3b35
...
...
@@ -5,7 +5,6 @@ import (
"crypto/ecdsa"
"crypto/tls"
"fmt"
"github.com/ethereum/go-ethereum/rpc"
"net/http"
"os"
"strconv"
...
...
@@ -21,6 +20,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/getsentry/sentry-go"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/urfave/cli"
...
...
@@ -37,8 +37,8 @@ const (
// use of a closure allows the parameters bound to the top-level main package,
// e.g. GitVersion, to be captured and used once the function is executed.
func
Main
(
gitVersion
string
)
func
(
ctx
*
cli
.
Context
)
error
{
return
func
(
ctx
*
cli
.
Context
)
error
{
cfg
,
err
:=
NewConfig
(
ctx
)
return
func
(
c
liC
tx
*
cli
.
Context
)
error
{
cfg
,
err
:=
NewConfig
(
c
liC
tx
)
if
err
!=
nil
{
return
err
}
...
...
@@ -51,52 +51,12 @@ func Main(gitVersion string) func(ctx *cli.Context) error {
log
.
Info
(
"Initializing batch submitter"
)
batchSubmitter
,
err
:=
NewBatchSubmitter
(
cfg
,
gitVersion
)
if
err
!=
nil
{
log
.
Error
(
"Unable to create batch submitter"
,
"error"
,
err
)
return
err
}
log
.
Info
(
"Starting batch submitter"
)
if
err
:=
batchSubmitter
.
Start
();
err
!=
nil
{
return
err
}
defer
batchSubmitter
.
Stop
()
log
.
Info
(
"Batch submitter started"
)
<-
(
chan
struct
{})(
nil
)
return
nil
}
}
// BatchSubmitter is a service that configures the necessary resources for
// running the TxBatchSubmitter and StateBatchSubmitter sub-services.
type
BatchSubmitter
struct
{
ctx
context
.
Context
cfg
Config
l1Client
*
ethclient
.
Client
l2Client
*
l2ethclient
.
Client
sequencerPrivKey
*
ecdsa
.
PrivateKey
proposerPrivKey
*
ecdsa
.
PrivateKey
ctcAddress
common
.
Address
sccAddress
common
.
Address
batchTxService
*
Service
batchStateService
*
Service
}
// NewBatchSubmitter initializes the BatchSubmitter, gathering any resources
// that will be needed by the TxBatchSubmitter and StateBatchSubmitter
// sub-services.
func
NewBatchSubmitter
(
cfg
Config
,
gitVersion
string
)
(
*
BatchSubmitter
,
error
)
{
ctx
:=
context
.
Background
()
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
// Set up our logging. If Sentry is enabled, we will use our custom
// log handler that logs to stdout and forwards any error messages to
// Sentry
for collection. Otherwise, logs will only be posted to stdout.
// Set up our logging. If Sentry is enabled, we will use our custom log
// handler that logs to stdout and forwards any error messages to Sentry
//
for collection. Otherwise, logs will only be posted to stdout.
var
logHandler
log
.
Handler
if
cfg
.
SentryEnable
{
err
:=
sentry
.
Init
(
sentry
.
ClientOptions
{
...
...
@@ -107,7 +67,7 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) {
Debug
:
false
,
})
if
err
!=
nil
{
return
nil
,
err
return
err
}
logHandler
=
SentryStreamHandler
(
os
.
Stdout
,
log
.
TerminalFormat
(
true
))
...
...
@@ -117,7 +77,7 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) {
logLevel
,
err
:=
log
.
LvlFromString
(
cfg
.
LogLevel
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
log
.
Root
()
.
SetHandler
(
log
.
LvlFilterHandler
(
logLevel
,
logHandler
))
...
...
@@ -128,7 +88,7 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) {
cfg
.
SequencerPrivateKey
,
cfg
.
CTCAddress
,
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
// Parse proposer private key and SCC contract address.
...
...
@@ -137,19 +97,19 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) {
cfg
.
ProposerPrivateKey
,
cfg
.
SCCAddress
,
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
// Connect to L1 and L2 providers. Perform these last since they are the
// most expensive.
l1Client
,
err
:=
dialL1EthClientWithTimeout
(
ctx
,
cfg
.
L1EthRpc
,
cfg
.
DisableHTTP2
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
l2Client
,
err
:=
dialL2EthClientWithTimeout
(
ctx
,
cfg
.
L2EthRpc
,
cfg
.
DisableHTTP2
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
if
cfg
.
MetricsServerEnable
{
...
...
@@ -158,7 +118,7 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) {
chainID
,
err
:=
l1Client
.
ChainID
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
txManagerConfig
:=
txmgr
.
Config
{
...
...
@@ -167,7 +127,7 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) {
NumConfirmations
:
cfg
.
NumConfirmations
,
}
var
batchTxService
*
Service
var
services
[]
*
Service
if
cfg
.
RunTxBatchSubmitter
{
batchTxDriver
,
err
:=
sequencer
.
NewDriver
(
sequencer
.
Config
{
Name
:
"Sequencer"
,
...
...
@@ -180,20 +140,19 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) {
PrivKey
:
sequencerPrivKey
,
})
if
err
!=
nil
{
return
nil
,
err
return
err
}
batchTxService
=
NewService
(
ServiceConfig
{
services
=
append
(
services
,
NewService
(
ServiceConfig
{
Context
:
ctx
,
Driver
:
batchTxDriver
,
PollInterval
:
cfg
.
PollInterval
,
ClearPendingTx
:
cfg
.
ClearPendingTxs
,
L1Client
:
l1Client
,
TxManagerConfig
:
txManagerConfig
,
}
)
})
)
}
var
batchStateService
*
Service
if
cfg
.
RunStateBatchSubmitter
{
batchStateDriver
,
err
:=
proposer
.
NewDriver
(
proposer
.
Config
{
Name
:
"Proposer"
,
...
...
@@ -207,41 +166,67 @@ func NewBatchSubmitter(cfg Config, gitVersion string) (*BatchSubmitter, error) {
PrivKey
:
proposerPrivKey
,
})
if
err
!=
nil
{
return
nil
,
err
return
err
}
batchStateService
=
NewService
(
ServiceConfig
{
services
=
append
(
services
,
NewService
(
ServiceConfig
{
Context
:
ctx
,
Driver
:
batchStateDriver
,
PollInterval
:
cfg
.
PollInterval
,
ClearPendingTx
:
cfg
.
ClearPendingTxs
,
L1Client
:
l1Client
,
TxManagerConfig
:
txManagerConfig
,
})
}))
}
batchSubmitter
,
err
:=
NewBatchSubmitter
(
ctx
,
cancel
,
services
)
if
err
!=
nil
{
log
.
Error
(
"Unable to create batch submitter"
,
"error"
,
err
)
return
err
}
log
.
Info
(
"Starting batch submitter"
)
if
err
:=
batchSubmitter
.
Start
();
err
!=
nil
{
return
err
}
defer
batchSubmitter
.
Stop
()
log
.
Info
(
"Batch submitter started"
)
<-
(
chan
struct
{})(
nil
)
return
nil
}
}
// BatchSubmitter is a service that configures the necessary resources for
// running the TxBatchSubmitter and StateBatchSubmitter sub-services.
type
BatchSubmitter
struct
{
ctx
context
.
Context
services
[]
*
Service
cancel
func
()
}
// NewBatchSubmitter initializes the BatchSubmitter, gathering any resources
// that will be needed by the TxBatchSubmitter and StateBatchSubmitter
// sub-services.
func
NewBatchSubmitter
(
ctx
context
.
Context
,
cancel
func
(),
services
[]
*
Service
,
)
(
*
BatchSubmitter
,
error
)
{
return
&
BatchSubmitter
{
ctx
:
ctx
,
cfg
:
cfg
,
l1Client
:
l1Client
,
l2Client
:
l2Client
,
sequencerPrivKey
:
sequencerPrivKey
,
proposerPrivKey
:
proposerPrivKey
,
ctcAddress
:
ctcAddress
,
sccAddress
:
sccAddress
,
batchTxService
:
batchTxService
,
batchStateService
:
batchStateService
,
services
:
services
,
cancel
:
cancel
,
},
nil
}
func
(
b
*
BatchSubmitter
)
Start
()
error
{
if
b
.
cfg
.
RunTxBatchSubmitter
{
if
err
:=
b
.
batchTxService
.
Start
();
err
!=
nil
{
return
err
}
}
if
b
.
cfg
.
RunStateBatchSubmitter
{
if
err
:=
b
.
batchStateService
.
Start
();
err
!=
nil
{
for
_
,
service
:=
range
b
.
services
{
if
err
:=
service
.
Start
();
err
!=
nil
{
return
err
}
}
...
...
@@ -249,11 +234,9 @@ func (b *BatchSubmitter) Start() error {
}
func
(
b
*
BatchSubmitter
)
Stop
()
{
if
b
.
cfg
.
RunTxBatchSubmitter
{
_
=
b
.
batchTxService
.
Stop
()
}
if
b
.
cfg
.
RunStateBatchSubmitter
{
_
=
b
.
batchStateService
.
Stop
()
b
.
cancel
()
for
_
,
service
:=
range
b
.
services
{
_
=
service
.
Stop
()
}
}
...
...
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