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
d0922bff
Unverified
Commit
d0922bff
authored
Mar 17, 2023
by
Michael de Hoog
Committed by
Brian Bland
Mar 27, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow passing in ctx to Stop
Usa separate contexts for loading L2 blocks and tx submission
parent
ae230d21
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
16 deletions
+27
-16
driver.go
op-batcher/batcher/driver.go
+24
-13
api.go
op-batcher/rpc/api.go
+3
-3
No files found.
op-batcher/batcher/driver.go
View file @
d0922bff
...
...
@@ -29,8 +29,10 @@ type BatchSubmitter struct {
wg
sync
.
WaitGroup
done
chan
struct
{}
ctx
context
.
Context
cancel
context
.
CancelFunc
loadCtx
context
.
Context
cancelLoad
context
.
CancelFunc
txCtx
context
.
Context
cancelTx
context
.
CancelFunc
mutex
sync
.
Mutex
running
bool
...
...
@@ -145,7 +147,8 @@ func (l *BatchSubmitter) Start() error {
l
.
running
=
true
l
.
done
=
make
(
chan
struct
{})
l
.
ctx
,
l
.
cancel
=
context
.
WithCancel
(
context
.
Background
())
l
.
loadCtx
,
l
.
cancelLoad
=
context
.
WithCancel
(
context
.
Background
())
l
.
txCtx
,
l
.
cancelTx
=
context
.
WithCancel
(
context
.
Background
())
l
.
state
.
Clear
()
l
.
lastStoredBlock
=
eth
.
BlockID
{}
...
...
@@ -158,10 +161,10 @@ func (l *BatchSubmitter) Start() error {
}
func
(
l
*
BatchSubmitter
)
StopIfRunning
()
{
_
=
l
.
Stop
()
_
=
l
.
Stop
(
context
.
Background
()
)
}
func
(
l
*
BatchSubmitter
)
Stop
()
error
{
func
(
l
*
BatchSubmitter
)
Stop
(
ctx
context
.
Context
)
error
{
l
.
log
.
Info
(
"Stopping Batch Submitter"
)
l
.
mutex
.
Lock
()
...
...
@@ -172,7 +175,16 @@ func (l *BatchSubmitter) Stop() error {
}
l
.
running
=
false
l
.
cancel
()
// go routine will call cancelTx() if the passed in ctx is ever Done
cancelTx
:=
l
.
cancelTx
wrapped
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
go
func
()
{
<-
wrapped
.
Done
()
cancelTx
()
}()
l
.
cancelLoad
()
close
(
l
.
done
)
l
.
wg
.
Wait
()
...
...
@@ -285,9 +297,6 @@ func (l *BatchSubmitter) calculateL2BlockRangeToStore(ctx context.Context) (eth.
func
(
l
*
BatchSubmitter
)
loop
()
{
defer
l
.
wg
.
Done
()
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
ticker
:=
time
.
NewTicker
(
l
.
PollInterval
)
defer
ticker
.
Stop
()
for
{
...
...
@@ -296,15 +305,15 @@ func (l *BatchSubmitter) loop() {
// prioritize the `done` condition over the ticker, even though select ordering is randomized
select
{
case
<-
l
.
done
:
l
.
publishStateToL1
(
c
tx
)
l
.
publishStateToL1
(
l
.
txC
tx
)
return
default
:
}
l
.
loadBlocksIntoState
(
l
.
c
tx
)
l
.
publishStateToL1
(
c
tx
)
l
.
loadBlocksIntoState
(
l
.
loadC
tx
)
l
.
publishStateToL1
(
l
.
txC
tx
)
case
<-
l
.
done
:
l
.
publishStateToL1
(
c
tx
)
l
.
publishStateToL1
(
l
.
txC
tx
)
return
}
}
...
...
@@ -317,6 +326,8 @@ func (l *BatchSubmitter) publishStateToL1(ctx context.Context) {
// Attempt to gracefully terminate the current channel, ensuring that no new frames will be
// produced. Any remaining frames must still be published to the L1 to prevent stalling.
select
{
case
<-
ctx
.
Done
()
:
l
.
state
.
Close
()
case
<-
l
.
done
:
l
.
state
.
Close
()
default
:
...
...
op-batcher/rpc/api.go
View file @
d0922bff
...
...
@@ -6,7 +6,7 @@ import (
type
batcherClient
interface
{
Start
()
error
Stop
()
error
Stop
(
ctx
context
.
Context
)
error
}
type
adminAPI
struct
{
...
...
@@ -23,6 +23,6 @@ func (a *adminAPI) StartBatcher(_ context.Context) error {
return
a
.
b
.
Start
()
}
func
(
a
*
adminAPI
)
StopBatcher
(
_
context
.
Context
)
error
{
return
a
.
b
.
Stop
()
func
(
a
*
adminAPI
)
StopBatcher
(
ctx
context
.
Context
)
error
{
return
a
.
b
.
Stop
(
ctx
)
}
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