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
7c60017f
Unverified
Commit
7c60017f
authored
Mar 22, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: handle duplicates in payloads-queue by hash, not by number
parent
a7c3e832
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
27 deletions
+31
-27
engine_queue.go
op-node/rollup/derive/engine_queue.go
+9
-13
payloads_queue.go
op-node/rollup/derive/payloads_queue.go
+21
-9
payloads_queue_test.go
op-node/rollup/derive/payloads_queue_test.go
+1
-5
No files found.
op-node/rollup/derive/engine_queue.go
View file @
7c60017f
...
@@ -107,7 +107,7 @@ type EngineQueue struct {
...
@@ -107,7 +107,7 @@ type EngineQueue struct {
// The queued-up attributes
// The queued-up attributes
safeAttributesParent
eth
.
L2BlockRef
safeAttributesParent
eth
.
L2BlockRef
safeAttributes
*
eth
.
PayloadAttributes
safeAttributes
*
eth
.
PayloadAttributes
unsafePayloads
PayloadsQueue
// queue of unsafe payloads, ordered by ascending block number, may have gap
s
unsafePayloads
*
PayloadsQueue
// queue of unsafe payloads, ordered by ascending block number, may have gaps and duplicate
s
// Tracks which L2 blocks where last derived from which L1 block. At most finalityLookback large.
// Tracks which L2 blocks where last derived from which L1 block. At most finalityLookback large.
finalityData
[]
FinalityData
finalityData
[]
FinalityData
...
@@ -127,18 +127,14 @@ var _ EngineControl = (*EngineQueue)(nil)
...
@@ -127,18 +127,14 @@ var _ EngineControl = (*EngineQueue)(nil)
// NewEngineQueue creates a new EngineQueue, which should be Reset(origin) before use.
// NewEngineQueue creates a new EngineQueue, which should be Reset(origin) before use.
func
NewEngineQueue
(
log
log
.
Logger
,
cfg
*
rollup
.
Config
,
engine
Engine
,
metrics
Metrics
,
prev
NextAttributesProvider
,
l1Fetcher
L1Fetcher
)
*
EngineQueue
{
func
NewEngineQueue
(
log
log
.
Logger
,
cfg
*
rollup
.
Config
,
engine
Engine
,
metrics
Metrics
,
prev
NextAttributesProvider
,
l1Fetcher
L1Fetcher
)
*
EngineQueue
{
return
&
EngineQueue
{
return
&
EngineQueue
{
log
:
log
,
log
:
log
,
cfg
:
cfg
,
cfg
:
cfg
,
engine
:
engine
,
engine
:
engine
,
metrics
:
metrics
,
metrics
:
metrics
,
finalityData
:
make
([]
FinalityData
,
0
,
finalityLookback
),
finalityData
:
make
([]
FinalityData
,
0
,
finalityLookback
),
unsafePayloads
:
PayloadsQueue
{
unsafePayloads
:
NewPayloadsQueue
(
maxUnsafePayloadsMemory
,
payloadMemSize
),
MaxSize
:
maxUnsafePayloadsMemory
,
prev
:
prev
,
SizeFn
:
payloadMemSize
,
l1Fetcher
:
l1Fetcher
,
blockNos
:
make
(
map
[
uint64
]
bool
),
},
prev
:
prev
,
l1Fetcher
:
l1Fetcher
,
}
}
}
}
...
...
op-node/rollup/derive/payloads_queue.go
View file @
7c60017f
...
@@ -5,6 +5,8 @@ import (
...
@@ -5,6 +5,8 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
)
)
...
@@ -48,8 +50,8 @@ func (pq *payloadsByNumber) Pop() any {
...
@@ -48,8 +50,8 @@ func (pq *payloadsByNumber) Pop() any {
}
}
const
(
const
(
// ~580 bytes per payload, with some margin for overhead
// ~580 bytes per payload, with some margin for overhead
like map data
payloadMemFixedCost
uint64
=
6
00
payloadMemFixedCost
uint64
=
8
00
// 24 bytes per tx overhead (size of slice header in memory)
// 24 bytes per tx overhead (size of slice header in memory)
payloadTxMemOverhead
uint64
=
24
payloadTxMemOverhead
uint64
=
24
)
)
...
@@ -72,15 +74,25 @@ func payloadMemSize(p *eth.ExecutionPayload) uint64 {
...
@@ -72,15 +74,25 @@ func payloadMemSize(p *eth.ExecutionPayload) uint64 {
// without the need to use heap.Push/heap.Pop as caller.
// without the need to use heap.Push/heap.Pop as caller.
// PayloadsQueue maintains a MaxSize by counting and tracking sizes of added eth.ExecutionPayload entries.
// PayloadsQueue maintains a MaxSize by counting and tracking sizes of added eth.ExecutionPayload entries.
// When the size grows too large, the first (lowest block-number) payload is removed from the queue.
// When the size grows too large, the first (lowest block-number) payload is removed from the queue.
// PayloadsQueue allows entries with same block number,
or even full duplicates.
// PayloadsQueue allows entries with same block number,
but does not allow duplicate blocks
type
PayloadsQueue
struct
{
type
PayloadsQueue
struct
{
pq
payloadsByNumber
pq
payloadsByNumber
currentSize
uint64
currentSize
uint64
MaxSize
uint64
MaxSize
uint64
block
Nos
map
[
uint64
]
bool
block
Hashes
map
[
common
.
Hash
]
struct
{}
SizeFn
func
(
p
*
eth
.
ExecutionPayload
)
uint64
SizeFn
func
(
p
*
eth
.
ExecutionPayload
)
uint64
}
}
func
NewPayloadsQueue
(
maxSize
uint64
,
sizeFn
func
(
p
*
eth
.
ExecutionPayload
)
uint64
)
*
PayloadsQueue
{
return
&
PayloadsQueue
{
pq
:
nil
,
currentSize
:
0
,
MaxSize
:
maxSize
,
blockHashes
:
make
(
map
[
common
.
Hash
]
struct
{}),
SizeFn
:
sizeFn
,
}
}
func
(
upq
*
PayloadsQueue
)
Len
()
int
{
func
(
upq
*
PayloadsQueue
)
Len
()
int
{
return
len
(
upq
.
pq
)
return
len
(
upq
.
pq
)
}
}
...
@@ -100,8 +112,8 @@ func (upq *PayloadsQueue) Push(p *eth.ExecutionPayload) error {
...
@@ -100,8 +112,8 @@ func (upq *PayloadsQueue) Push(p *eth.ExecutionPayload) error {
if
p
==
nil
{
if
p
==
nil
{
return
errors
.
New
(
"cannot add nil payload"
)
return
errors
.
New
(
"cannot add nil payload"
)
}
}
if
upq
.
blockNos
[
p
.
ID
()
.
Number
]
{
if
_
,
ok
:=
upq
.
blockHashes
[
p
.
BlockHash
];
ok
{
return
errors
.
New
(
"cannot add duplicate payload"
)
return
fmt
.
Errorf
(
"cannot add duplicate payload %s"
,
p
.
ID
()
)
}
}
size
:=
upq
.
SizeFn
(
p
)
size
:=
upq
.
SizeFn
(
p
)
if
size
>
upq
.
MaxSize
{
if
size
>
upq
.
MaxSize
{
...
@@ -115,7 +127,7 @@ func (upq *PayloadsQueue) Push(p *eth.ExecutionPayload) error {
...
@@ -115,7 +127,7 @@ func (upq *PayloadsQueue) Push(p *eth.ExecutionPayload) error {
for
upq
.
currentSize
>
upq
.
MaxSize
{
for
upq
.
currentSize
>
upq
.
MaxSize
{
upq
.
Pop
()
upq
.
Pop
()
}
}
upq
.
block
Nos
[
p
.
ID
()
.
Number
]
=
true
upq
.
block
Hashes
[
p
.
BlockHash
]
=
struct
{}{}
return
nil
return
nil
}
}
...
@@ -137,7 +149,7 @@ func (upq *PayloadsQueue) Pop() *eth.ExecutionPayload {
...
@@ -137,7 +149,7 @@ func (upq *PayloadsQueue) Pop() *eth.ExecutionPayload {
}
}
ps
:=
heap
.
Pop
(
&
upq
.
pq
)
.
(
payloadAndSize
)
// nosemgrep
ps
:=
heap
.
Pop
(
&
upq
.
pq
)
.
(
payloadAndSize
)
// nosemgrep
upq
.
currentSize
-=
ps
.
size
upq
.
currentSize
-=
ps
.
size
// remove the key from the block
No
s map
// remove the key from the block
hashe
s map
delete
(
upq
.
block
Nos
,
ps
.
payload
.
ID
()
.
Number
)
delete
(
upq
.
block
Hashes
,
ps
.
payload
.
BlockHash
)
return
ps
.
payload
return
ps
.
payload
}
}
op-node/rollup/derive/payloads_queue_test.go
View file @
7c60017f
...
@@ -74,11 +74,7 @@ func TestPayloadMemSize(t *testing.T) {
...
@@ -74,11 +74,7 @@ func TestPayloadMemSize(t *testing.T) {
}
}
func
TestPayloadsQueue
(
t
*
testing
.
T
)
{
func
TestPayloadsQueue
(
t
*
testing
.
T
)
{
pq
:=
PayloadsQueue
{
pq
:=
NewPayloadsQueue
(
payloadMemFixedCost
*
3
,
payloadMemSize
)
MaxSize
:
payloadMemFixedCost
*
3
,
SizeFn
:
payloadMemSize
,
blockNos
:
make
(
map
[
uint64
]
bool
),
}
require
.
Equal
(
t
,
0
,
pq
.
Len
())
require
.
Equal
(
t
,
0
,
pq
.
Len
())
require
.
Equal
(
t
,
(
*
eth
.
ExecutionPayload
)(
nil
),
pq
.
Peek
())
require
.
Equal
(
t
,
(
*
eth
.
ExecutionPayload
)(
nil
),
pq
.
Peek
())
require
.
Equal
(
t
,
(
*
eth
.
ExecutionPayload
)(
nil
),
pq
.
Pop
())
require
.
Equal
(
t
,
(
*
eth
.
ExecutionPayload
)(
nil
),
pq
.
Pop
())
...
...
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