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
6780c473
Unverified
Commit
6780c473
authored
Dec 14, 2021
by
Conner Fromknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: cache go BSS txn serialization
parent
229fde5a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
19 deletions
+50
-19
batch.go
go/batch-submitter/drivers/sequencer/batch.go
+6
-5
batch_test.go
go/batch-submitter/drivers/sequencer/batch_test.go
+1
-1
cached_tx.go
go/batch-submitter/drivers/sequencer/cached_tx.go
+37
-0
encoding.go
go/batch-submitter/drivers/sequencer/encoding.go
+4
-11
encoding_test.go
go/batch-submitter/drivers/sequencer/encoding_test.go
+2
-2
No files found.
go/batch-submitter/drivers/sequencer/batch.go
View file @
6780c473
...
@@ -27,7 +27,7 @@ type BatchElement struct {
...
@@ -27,7 +27,7 @@ type BatchElement struct {
// Tx is the optional transaction that was applied in this batch.
// Tx is the optional transaction that was applied in this batch.
//
//
// NOTE: This field will only be populated for sequencer txs.
// NOTE: This field will only be populated for sequencer txs.
Tx
*
l2types
.
Transaction
Tx
*
CachedTx
}
}
// IsSequencerTx returns true if this batch contains a tx that needs to be
// IsSequencerTx returns true if this batch contains a tx that needs to be
...
@@ -54,14 +54,15 @@ func BatchElementFromBlock(block *l2types.Block) BatchElement {
...
@@ -54,14 +54,15 @@ func BatchElementFromBlock(block *l2types.Block) BatchElement {
isSequencerTx
:=
tx
.
QueueOrigin
()
==
l2types
.
QueueOriginSequencer
isSequencerTx
:=
tx
.
QueueOrigin
()
==
l2types
.
QueueOriginSequencer
// Only include sequencer txs in the returned BatchElement.
// Only include sequencer txs in the returned BatchElement.
if
!
isSequencerTx
{
var
cachedTx
*
CachedTx
tx
=
nil
if
isSequencerTx
{
cachedTx
=
NewCachedTx
(
tx
)
}
}
return
BatchElement
{
return
BatchElement
{
Timestamp
:
block
.
Time
(),
Timestamp
:
block
.
Time
(),
BlockNumber
:
l1BlockNumber
,
BlockNumber
:
l1BlockNumber
,
Tx
:
t
x
,
Tx
:
cachedT
x
,
}
}
}
}
...
@@ -82,7 +83,7 @@ func GenSequencerBatchParams(
...
@@ -82,7 +83,7 @@ func GenSequencerBatchParams(
var
(
var
(
contexts
[]
BatchContext
contexts
[]
BatchContext
groupedBlocks
[]
groupedBlock
groupedBlocks
[]
groupedBlock
txs
[]
*
l2types
.
Transaction
txs
[]
*
CachedTx
lastBlockIsSequencerTx
bool
lastBlockIsSequencerTx
bool
lastTimestamp
uint64
lastTimestamp
uint64
lastBlockNumber
uint64
lastBlockNumber
uint64
...
...
go/batch-submitter/drivers/sequencer/batch_test.go
View file @
6780c473
...
@@ -31,7 +31,7 @@ func TestBatchElementFromBlock(t *testing.T) {
...
@@ -31,7 +31,7 @@ func TestBatchElementFromBlock(t *testing.T) {
require
.
Equal
(
t
,
element
.
Timestamp
,
expTime
)
require
.
Equal
(
t
,
element
.
Timestamp
,
expTime
)
require
.
Equal
(
t
,
element
.
BlockNumber
,
expBlockNumber
)
require
.
Equal
(
t
,
element
.
BlockNumber
,
expBlockNumber
)
require
.
True
(
t
,
element
.
IsSequencerTx
())
require
.
True
(
t
,
element
.
IsSequencerTx
())
require
.
Equal
(
t
,
element
.
Tx
,
expTx
)
require
.
Equal
(
t
,
element
.
Tx
.
Tx
()
,
expTx
)
queueMeta
:=
l2types
.
NewTransactionMeta
(
queueMeta
:=
l2types
.
NewTransactionMeta
(
new
(
big
.
Int
)
.
SetUint64
(
expBlockNumber
),
0
,
nil
,
new
(
big
.
Int
)
.
SetUint64
(
expBlockNumber
),
0
,
nil
,
...
...
go/batch-submitter/drivers/sequencer/cached_tx.go
0 → 100644
View file @
6780c473
package
sequencer
import
(
"bytes"
"fmt"
l2types
"github.com/ethereum-optimism/optimism/l2geth/core/types"
)
type
CachedTx
struct
{
tx
*
l2types
.
Transaction
rawTx
[]
byte
}
func
NewCachedTx
(
tx
*
l2types
.
Transaction
)
*
CachedTx
{
var
txBuf
bytes
.
Buffer
if
err
:=
tx
.
EncodeRLP
(
&
txBuf
);
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"Unable to encode tx: %v"
,
err
))
}
return
&
CachedTx
{
tx
:
tx
,
rawTx
:
txBuf
.
Bytes
(),
}
}
func
(
t
*
CachedTx
)
Tx
()
*
l2types
.
Transaction
{
return
t
.
tx
}
func
(
t
*
CachedTx
)
Size
()
int
{
return
len
(
t
.
rawTx
)
}
func
(
t
*
CachedTx
)
RawTx
()
[]
byte
{
return
t
.
rawTx
}
go/batch-submitter/drivers/sequencer/encoding.go
View file @
6780c473
...
@@ -88,7 +88,7 @@ type AppendSequencerBatchParams struct {
...
@@ -88,7 +88,7 @@ type AppendSequencerBatchParams struct {
// Txs contains all sequencer txs that will be recorded in the L1 CTC
// Txs contains all sequencer txs that will be recorded in the L1 CTC
// contract.
// contract.
Txs
[]
*
l2types
.
Transaction
Txs
[]
*
CachedTx
}
}
// Write encodes the AppendSequencerBatchParams using the following format:
// Write encodes the AppendSequencerBatchParams using the following format:
...
@@ -110,16 +110,9 @@ func (p *AppendSequencerBatchParams) Write(w *bytes.Buffer) error {
...
@@ -110,16 +110,9 @@ func (p *AppendSequencerBatchParams) Write(w *bytes.Buffer) error {
}
}
// Write each length-prefixed tx.
// Write each length-prefixed tx.
var
txBuf
bytes
.
Buffer
for
_
,
tx
:=
range
p
.
Txs
{
for
_
,
tx
:=
range
p
.
Txs
{
txBuf
.
Reset
()
writeUint64
(
w
,
uint64
(
tx
.
Size
()),
3
)
_
,
_
=
w
.
Write
(
tx
.
RawTx
())
// can't fail for bytes.Buffer
if
err
:=
tx
.
EncodeRLP
(
&
txBuf
);
err
!=
nil
{
return
err
}
writeUint64
(
w
,
uint64
(
txBuf
.
Len
()),
3
)
_
,
_
=
w
.
Write
(
txBuf
.
Bytes
())
// can't fail for bytes.Buffer
}
}
return
nil
return
nil
...
@@ -187,7 +180,7 @@ func (p *AppendSequencerBatchParams) Read(r io.Reader) error {
...
@@ -187,7 +180,7 @@ func (p *AppendSequencerBatchParams) Read(r io.Reader) error {
return
err
return
err
}
}
p
.
Txs
=
append
(
p
.
Txs
,
tx
)
p
.
Txs
=
append
(
p
.
Txs
,
NewCachedTx
(
tx
)
)
}
}
}
}
...
...
go/batch-submitter/drivers/sequencer/encoding_test.go
View file @
6780c473
...
@@ -297,9 +297,9 @@ func testAppendSequencerBatchParamsEncodeDecode(
...
@@ -297,9 +297,9 @@ func testAppendSequencerBatchParamsEncodeDecode(
// compareTxs compares a list of two transactions, testing each pair by tx hash.
// compareTxs compares a list of two transactions, testing each pair by tx hash.
// This is used rather than require.Equal, since there `time` metadata on the
// This is used rather than require.Equal, since there `time` metadata on the
// decoded tx and the expected tx will differ, and can't be modified/ignored.
// decoded tx and the expected tx will differ, and can't be modified/ignored.
func
compareTxs
(
t
*
testing
.
T
,
a
,
b
[]
*
l2types
.
Transaction
)
{
func
compareTxs
(
t
*
testing
.
T
,
a
[]
*
l2types
.
Transaction
,
b
[]
*
sequencer
.
CachedTx
)
{
require
.
Equal
(
t
,
len
(
a
),
len
(
b
))
require
.
Equal
(
t
,
len
(
a
),
len
(
b
))
for
i
,
txA
:=
range
a
{
for
i
,
txA
:=
range
a
{
require
.
Equal
(
t
,
txA
.
Hash
(),
b
[
i
]
.
Hash
())
require
.
Equal
(
t
,
txA
.
Hash
(),
b
[
i
]
.
Tx
()
.
Hash
())
}
}
}
}
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