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
141a480f
Unverified
Commit
141a480f
authored
Mar 17, 2022
by
Conner Fromknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: pass BatchType as argument to Write
parent
ec3857eb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
25 deletions
+17
-25
batch.go
go/batch-submitter/drivers/sequencer/batch.go
+0
-2
driver.go
go/batch-submitter/drivers/sequencer/driver.go
+2
-2
encoding.go
go/batch-submitter/drivers/sequencer/encoding.go
+13
-14
encoding_test.go
go/batch-submitter/drivers/sequencer/encoding_test.go
+2
-7
No files found.
go/batch-submitter/drivers/sequencer/batch.go
View file @
141a480f
...
...
@@ -78,7 +78,6 @@ func GenSequencerBatchParams(
shouldStartAtElement
uint64
,
blockOffset
uint64
,
batch
[]
BatchElement
,
batchType
BatchType
,
)
(
*
AppendSequencerBatchParams
,
error
)
{
var
(
...
...
@@ -189,6 +188,5 @@ func GenSequencerBatchParams(
TotalElementsToAppend
:
uint64
(
len
(
batch
)),
Contexts
:
contexts
,
Txs
:
txs
,
Type
:
batchType
,
},
nil
}
go/batch-submitter/drivers/sequencer/driver.go
View file @
141a480f
...
...
@@ -199,13 +199,13 @@ func (d *Driver) CraftBatchTx(
var
pruneCount
int
for
{
batchParams
,
err
:=
GenSequencerBatchParams
(
shouldStartAt
,
d
.
cfg
.
BlockOffset
,
batchElements
,
d
.
cfg
.
BatchType
,
shouldStartAt
,
d
.
cfg
.
BlockOffset
,
batchElements
,
)
if
err
!=
nil
{
return
nil
,
err
}
batchArguments
,
err
:=
batchParams
.
Serialize
()
batchArguments
,
err
:=
batchParams
.
Serialize
(
d
.
cfg
.
BatchType
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
go/batch-submitter/drivers/sequencer/encoding.go
View file @
141a480f
...
...
@@ -146,9 +146,6 @@ type AppendSequencerBatchParams struct {
// Txs contains all sequencer txs that will be recorded in the L1 CTC
// contract.
Txs
[]
*
CachedTx
// The type of the batch
Type
BatchType
}
// Write encodes the AppendSequencerBatchParams using the following format:
...
...
@@ -173,7 +170,11 @@ type AppendSequencerBatchParams struct {
//
// Note that writing to a bytes.Buffer cannot
// error, so errors are ignored here
func
(
p
*
AppendSequencerBatchParams
)
Write
(
w
*
bytes
.
Buffer
)
error
{
func
(
p
*
AppendSequencerBatchParams
)
Write
(
w
*
bytes
.
Buffer
,
batchType
BatchType
,
)
error
{
_
=
writeUint64
(
w
,
p
.
ShouldStartAtElement
,
5
)
_
=
writeUint64
(
w
,
p
.
TotalElementsToAppend
,
3
)
...
...
@@ -190,7 +191,7 @@ func (p *AppendSequencerBatchParams) Write(w *bytes.Buffer) error {
// copy the contexts as to not malleate the struct
// when it is a typed batch
contexts
:=
make
([]
BatchContext
,
0
,
len
(
p
.
Contexts
)
+
1
)
if
p
.
Type
==
BatchTypeZlib
{
if
batch
Type
==
BatchTypeZlib
{
// All zero values for the single batch context
// is desired here as blocknumber 0 means it is a zlib batch
contexts
=
append
(
contexts
,
BatchContext
{})
...
...
@@ -203,7 +204,7 @@ func (p *AppendSequencerBatchParams) Write(w *bytes.Buffer) error {
context
.
Write
(
w
)
}
switch
p
.
Type
{
switch
batch
Type
{
case
BatchTypeLegacy
:
// Write each length-prefixed tx.
for
_
,
tx
:=
range
p
.
Txs
{
...
...
@@ -225,7 +226,7 @@ func (p *AppendSequencerBatchParams) Write(w *bytes.Buffer) error {
}
default
:
return
fmt
.
Errorf
(
"Unknown batch type: %s"
,
p
.
Type
)
return
fmt
.
Errorf
(
"Unknown batch type: %s"
,
batch
Type
)
}
return
nil
...
...
@@ -233,9 +234,12 @@ func (p *AppendSequencerBatchParams) Write(w *bytes.Buffer) error {
// Serialize performs the same encoding as Write, but returns the resulting
// bytes slice.
func
(
p
*
AppendSequencerBatchParams
)
Serialize
()
([]
byte
,
error
)
{
func
(
p
*
AppendSequencerBatchParams
)
Serialize
(
batchType
BatchType
,
)
([]
byte
,
error
)
{
var
buf
bytes
.
Buffer
if
err
:=
p
.
Write
(
&
buf
);
err
!=
nil
{
if
err
:=
p
.
Write
(
&
buf
,
batchType
);
err
!=
nil
{
return
nil
,
err
}
return
buf
.
Bytes
(),
nil
...
...
@@ -277,15 +281,10 @@ func (p *AppendSequencerBatchParams) Read(r io.Reader) error {
p
.
Contexts
=
append
(
p
.
Contexts
,
batchContext
)
}
// Assume that it is a legacy batch at first
p
.
Type
=
BatchTypeLegacy
// Handle backwards compatible batch types
if
len
(
p
.
Contexts
)
>
0
&&
p
.
Contexts
[
0
]
.
Timestamp
==
0
{
switch
p
.
Contexts
[
0
]
.
BlockNumber
{
case
0
:
// zlib compressed transaction data
p
.
Type
=
BatchTypeZlib
// remove the first dummy context
p
.
Contexts
=
p
.
Contexts
[
1
:
]
numContexts
--
...
...
go/batch-submitter/drivers/sequencer/encoding_test.go
View file @
141a480f
...
...
@@ -119,7 +119,6 @@ func testAppendSequencerBatchParamsEncodeDecode(
TotalElementsToAppend
:
test
.
TotalElementsToAppend
,
Contexts
:
test
.
Contexts
,
Txs
:
nil
,
Type
:
sequencer
.
BatchTypeLegacy
,
}
// Decode the batch from the test string.
...
...
@@ -133,7 +132,6 @@ func testAppendSequencerBatchParamsEncodeDecode(
}
else
{
require
.
Nil
(
t
,
err
)
}
require
.
Equal
(
t
,
params
.
Type
,
sequencer
.
BatchTypeLegacy
)
// Assert that the decoded params match the expected params. The
// transactions are compared serparetly (via hash), since the internal
...
...
@@ -149,7 +147,7 @@ func testAppendSequencerBatchParamsEncodeDecode(
// Finally, encode the decoded object and assert it matches the original
// hex string.
paramsBytes
,
err
:=
params
.
Serialize
()
paramsBytes
,
err
:=
params
.
Serialize
(
sequencer
.
BatchTypeLegacy
)
// Return early when testing error cases, no need to reserialize again
if
test
.
Error
{
...
...
@@ -161,17 +159,14 @@ func testAppendSequencerBatchParamsEncodeDecode(
require
.
Equal
(
t
,
test
.
HexEncoding
,
hex
.
EncodeToString
(
paramsBytes
))
// Serialize the batches in compressed form
params
.
Type
=
sequencer
.
BatchTypeZlib
compressedParamsBytes
,
err
:=
params
.
Serialize
()
compressedParamsBytes
,
err
:=
params
.
Serialize
(
sequencer
.
BatchTypeZlib
)
require
.
Nil
(
t
,
err
)
// Deserialize the compressed batch
var
paramsCompressed
sequencer
.
AppendSequencerBatchParams
err
=
paramsCompressed
.
Read
(
bytes
.
NewReader
(
compressedParamsBytes
))
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
paramsCompressed
.
Type
,
sequencer
.
BatchTypeZlib
)
expParams
.
Type
=
sequencer
.
BatchTypeZlib
decompressedTxs
:=
paramsCompressed
.
Txs
paramsCompressed
.
Txs
=
nil
...
...
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