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
c2260ca0
Commit
c2260ca0
authored
Dec 01, 2023
by
pcw109550
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Refactor to expose span batch derivation
parent
918459c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
16 deletions
+23
-16
batch_test.go
op-node/rollup/derive/batch_test.go
+2
-6
channel_in_reader.go
op-node/rollup/derive/channel_in_reader.go
+1
-10
span_batch.go
op-node/rollup/derive/span_batch.go
+20
-0
No files found.
op-node/rollup/derive/batch_test.go
View file @
c2260ca0
...
...
@@ -172,9 +172,7 @@ func TestBatchRoundTrip(t *testing.T) {
err
=
dec
.
UnmarshalBinary
(
enc
)
require
.
NoError
(
t
,
err
)
if
dec
.
GetBatchType
()
==
SpanBatchType
{
rawSpanBatch
,
ok
:=
dec
.
inner
.
(
*
RawSpanBatch
)
require
.
True
(
t
,
ok
)
_
,
err
:=
rawSpanBatch
.
derive
(
blockTime
,
genesisTimestamp
,
chainID
)
_
,
err
:=
DeriveSpanBatch
(
&
dec
,
blockTime
,
genesisTimestamp
,
chainID
)
require
.
NoError
(
t
,
err
)
}
require
.
Equal
(
t
,
batch
,
&
dec
,
"Batch not equal test case %v"
,
i
)
...
...
@@ -222,9 +220,7 @@ func TestBatchRoundTripRLP(t *testing.T) {
err
=
dec
.
DecodeRLP
(
s
)
require
.
NoError
(
t
,
err
)
if
dec
.
GetBatchType
()
==
SpanBatchType
{
rawSpanBatch
,
ok
:=
dec
.
inner
.
(
*
RawSpanBatch
)
require
.
True
(
t
,
ok
)
_
,
err
:=
rawSpanBatch
.
derive
(
blockTime
,
genesisTimestamp
,
chainID
)
_
,
err
=
DeriveSpanBatch
(
&
dec
,
blockTime
,
genesisTimestamp
,
chainID
)
require
.
NoError
(
t
,
err
)
}
require
.
Equal
(
t
,
batch
,
&
dec
,
"Batch not equal test case %v"
,
i
)
...
...
op-node/rollup/derive/channel_in_reader.go
View file @
c2260ca0
...
...
@@ -104,16 +104,7 @@ func (cr *ChannelInReader) NextBatch(ctx context.Context) (Batch, error) {
// This is just for early dropping invalid batches as soon as possible.
return
nil
,
NewTemporaryError
(
fmt
.
Errorf
(
"cannot accept span batch in L1 block %s at time %d"
,
origin
,
origin
.
Time
))
}
rawSpanBatch
,
ok
:=
batchData
.
inner
.
(
*
RawSpanBatch
)
if
!
ok
{
return
nil
,
NewCriticalError
(
errors
.
New
(
"failed type assertion to SpanBatch"
))
}
// If the batch type is Span batch, derive block inputs from RawSpanBatch.
spanBatch
,
err
:=
rawSpanBatch
.
derive
(
cr
.
cfg
.
BlockTime
,
cr
.
cfg
.
Genesis
.
L2Time
,
cr
.
cfg
.
L2ChainID
)
if
err
!=
nil
{
return
nil
,
err
}
return
spanBatch
,
nil
return
DeriveSpanBatch
(
batchData
,
cr
.
cfg
.
BlockTime
,
cr
.
cfg
.
Genesis
.
L2Time
,
cr
.
cfg
.
L2ChainID
)
default
:
// error is bubbled up to user, but pipeline can skip the batch and continue after.
return
nil
,
NewTemporaryError
(
fmt
.
Errorf
(
"unrecognized batch type: %d"
,
batchData
.
GetBatchType
()))
...
...
op-node/rollup/derive/span_batch.go
View file @
c2260ca0
...
...
@@ -416,6 +416,16 @@ func (b *RawSpanBatch) derive(blockTime, genesisTimestamp uint64, chainID *big.I
return
&
spanBatch
,
nil
}
// ToSpanBatch converts RawSpanBatch to SpanBatch,
// which implements a wrapper of derive method of RawSpanBatch
func
(
b
*
RawSpanBatch
)
ToSpanBatch
(
blockTime
,
genesisTimestamp
uint64
,
chainID
*
big
.
Int
)
(
*
SpanBatch
,
error
)
{
spanBatch
,
err
:=
b
.
derive
(
blockTime
,
genesisTimestamp
,
chainID
)
if
err
!=
nil
{
return
nil
,
err
}
return
spanBatch
,
nil
}
// spanBatchElement is a derived form of input to build a L2 block.
// similar to SingularBatch, but does not have ParentHash and EpochHash
// because Span batch spec does not contain parent hash and epoch hash of every block in the span.
...
...
@@ -604,6 +614,16 @@ func NewSpanBatch(singularBatches []*SingularBatch) *SpanBatch {
return
spanBatch
}
// DeriveSpanBatch derives SpanBatch from BatchData.
func
DeriveSpanBatch
(
batchData
*
BatchData
,
blockTime
,
genesisTimestamp
uint64
,
chainID
*
big
.
Int
)
(
*
SpanBatch
,
error
)
{
rawSpanBatch
,
ok
:=
batchData
.
inner
.
(
*
RawSpanBatch
)
if
!
ok
{
return
nil
,
NewCriticalError
(
errors
.
New
(
"failed type assertion to SpanBatch"
))
}
// If the batch type is Span batch, derive block inputs from RawSpanBatch.
return
rawSpanBatch
.
ToSpanBatch
(
blockTime
,
genesisTimestamp
,
chainID
)
}
// SpanBatchBuilder is a utility type to build a SpanBatch by adding a SingularBatch one by one.
// makes easier to stack SingularBatches and convert to RawSpanBatch for encoding.
type
SpanBatchBuilder
struct
{
...
...
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