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
a013539c
Commit
a013539c
authored
Jan 25, 2023
by
Sebastian Stammler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-batcher: Track latest block hash for reorg detection
parent
bd860220
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
+8
-3
channel_manager.go
op-batcher/batcher/channel_manager.go
+8
-3
No files found.
op-batcher/batcher/channel_manager.go
View file @
a013539c
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
)
)
...
@@ -50,6 +51,8 @@ type channelManager struct {
...
@@ -50,6 +51,8 @@ type channelManager struct {
// All blocks since the last request for new tx data.
// All blocks since the last request for new tx data.
blocks
[]
*
types
.
Block
blocks
[]
*
types
.
Block
// last block hash - for reorg detection
tip
common
.
Hash
// Pending data returned by TxData waiting on Tx Confirmed/Failed
// Pending data returned by TxData waiting on Tx Confirmed/Failed
...
@@ -259,15 +262,17 @@ func (s *channelManager) addBlocks() error {
...
@@ -259,15 +262,17 @@ func (s *channelManager) addBlocks() error {
return
nil
return
nil
}
}
var
zeroHash
common
.
Hash
// AddL2Block saves an L2 block to the internal state. It returns ErrReorg
// AddL2Block saves an L2 block to the internal state. It returns ErrReorg
// if the block does not extend the last block loaded into the state.
// if the block does not extend the last block loaded into the state.
// If no block is already in the channel, the the parent hash check is skipped.
// If no blocks were added yet, the parent hash check is skipped.
// TODO: Phantom last block b/c if the local state is fully drained we can reorg without realizing it.
func
(
s
*
channelManager
)
AddL2Block
(
block
*
types
.
Block
)
error
{
func
(
s
*
channelManager
)
AddL2Block
(
block
*
types
.
Block
)
error
{
if
l
:=
len
(
s
.
blocks
);
l
>
0
&&
s
.
blocks
[
l
-
1
]
.
Hash
()
!=
block
.
ParentHash
()
{
if
s
.
tip
!=
zeroHash
&&
s
.
tip
!=
block
.
ParentHash
()
{
return
ErrReorg
return
ErrReorg
}
}
s
.
blocks
=
append
(
s
.
blocks
,
block
)
s
.
blocks
=
append
(
s
.
blocks
,
block
)
s
.
tip
=
block
.
Hash
()
return
nil
return
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