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
874fb900
Commit
874fb900
authored
Dec 04, 2023
by
pcw109550
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: batch_decoder: Support Span Batch
parent
06c495e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
24 deletions
+93
-24
main.go
op-node/cmd/batch_decoder/main.go
+55
-10
reassemble.go
op-node/cmd/batch_decoder/reassemble/reassemble.go
+38
-14
No files found.
op-node/cmd/batch_decoder/main.go
View file @
874fb900
...
...
@@ -4,11 +4,13 @@ import (
"context"
"fmt"
"log"
"math/big"
"os"
"time"
"github.com/ethereum-optimism/optimism/op-node/cmd/batch_decoder/fetch"
"github.com/ethereum-optimism/optimism/op-node/cmd/batch_decoder/reassemble"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
...
...
@@ -77,7 +79,7 @@ func main() {
End
:
uint64
(
cliCtx
.
Int
(
"end"
)),
ChainID
:
chainID
,
BatchSenders
:
map
[
common
.
Address
]
struct
{}{
common
.
HexToAddress
(
cliCtx
.
String
(
"sender"
))
:
struct
{}
{},
common
.
HexToAddress
(
cliCtx
.
String
(
"sender"
))
:
{},
},
BatchInbox
:
common
.
HexToAddress
(
cliCtx
.
String
(
"inbox"
)),
OutDirectory
:
cliCtx
.
String
(
"out"
),
...
...
@@ -92,13 +94,8 @@ func main() {
},
{
Name
:
"reassemble"
,
Usage
:
"Reassembles channels from fetched batches"
,
Usage
:
"Reassembles channels from fetched batch
transactions and decode batch
es"
,
Flags
:
[]
cli
.
Flag
{
&
cli
.
StringFlag
{
Name
:
"inbox"
,
Value
:
"0xff00000000000000000000000000000000000420"
,
Usage
:
"Batch Inbox Address"
,
},
&
cli
.
StringFlag
{
Name
:
"in"
,
Value
:
"/tmp/batch_decoder/transactions_cache"
,
...
...
@@ -109,12 +106,60 @@ func main() {
Value
:
"/tmp/batch_decoder/channel_cache"
,
Usage
:
"Cache directory for the found channels"
,
},
&
cli
.
Uint64Flag
{
Name
:
"l2-chain-id"
,
Value
:
10
,
Usage
:
"L2 chain id for span batch derivation. Default value from op-mainnet."
,
},
&
cli
.
Uint64Flag
{
Name
:
"l2-genesis-timestamp"
,
Value
:
1686068903
,
Usage
:
"L2 genesis time for span batch derivation. Default value from op-mainnet. "
+
"Superchain-registry prioritized when given value is inconsistent."
,
},
&
cli
.
Uint64Flag
{
Name
:
"l2-block-time"
,
Value
:
2
,
Usage
:
"L2 block time for span batch derivation. Default value from op-mainnet. "
+
"Superchain-registry prioritized when given value is inconsistent."
,
},
&
cli
.
StringFlag
{
Name
:
"inbox"
,
Value
:
"0xFF00000000000000000000000000000000000010"
,
Usage
:
"Batch Inbox Address. Default value from op-mainnet. "
+
"Superchain-registry prioritized when given value is inconsistent."
,
},
},
Action
:
func
(
cliCtx
*
cli
.
Context
)
error
{
var
(
L2GenesisTime
uint64
=
cliCtx
.
Uint64
(
"l2-genesis-timestamp"
)
L2BlockTime
uint64
=
cliCtx
.
Uint64
(
"l2-block-time"
)
BatchInboxAddress
common
.
Address
=
common
.
HexToAddress
(
cliCtx
.
String
(
"inbox"
))
)
L2ChainID
:=
new
(
big
.
Int
)
.
SetUint64
(
cliCtx
.
Uint64
(
"l2-chain-id"
))
rollupCfg
,
err
:=
rollup
.
LoadOPStackRollupConfig
(
L2ChainID
.
Uint64
())
if
err
==
nil
{
// prioritize superchain config
if
L2GenesisTime
!=
rollupCfg
.
Genesis
.
L2Time
{
L2GenesisTime
=
rollupCfg
.
Genesis
.
L2Time
fmt
.
Printf
(
"L2GenesisTime overridden: %v
\n
"
,
L2GenesisTime
)
}
if
L2BlockTime
!=
rollupCfg
.
BlockTime
{
L2BlockTime
=
rollupCfg
.
BlockTime
fmt
.
Printf
(
"L2BlockTime overridden: %v
\n
"
,
L2BlockTime
)
}
if
BatchInboxAddress
!=
rollupCfg
.
BatchInboxAddress
{
BatchInboxAddress
=
rollupCfg
.
BatchInboxAddress
fmt
.
Printf
(
"BatchInboxAddress overridden: %v
\n
"
,
BatchInboxAddress
)
}
}
config
:=
reassemble
.
Config
{
BatchInbox
:
common
.
HexToAddress
(
cliCtx
.
String
(
"inbox"
)),
InDirectory
:
cliCtx
.
String
(
"in"
),
OutDirectory
:
cliCtx
.
String
(
"out"
),
BatchInbox
:
BatchInboxAddress
,
InDirectory
:
cliCtx
.
String
(
"in"
),
OutDirectory
:
cliCtx
.
String
(
"out"
),
L2ChainID
:
L2ChainID
,
L2GenesisTime
:
L2GenesisTime
,
L2BlockTime
:
L2BlockTime
,
}
reassemble
.
Channels
(
config
)
return
nil
...
...
op-node/cmd/batch_decoder/reassemble/reassemble.go
View file @
874fb900
...
...
@@ -5,13 +5,11 @@ import (
"fmt"
"io"
"log"
"math/big"
"os"
"path"
"sort"
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/cmd/batch_decoder/fetch"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-service/eth"
...
...
@@ -24,7 +22,8 @@ type ChannelWithMetadata struct {
InvalidFrames
bool
`json:"invalid_frames"`
InvalidBatches
bool
`json:"invalid_batches"`
Frames
[]
FrameWithMetadata
`json:"frames"`
Batches
[]
derive
.
BatchData
`json:"batches"`
Batches
[]
derive
.
Batch
`json:"batches"`
BatchTypes
[]
int
`json:"batch_types"`
}
type
FrameWithMetadata
struct
{
...
...
@@ -36,9 +35,12 @@ type FrameWithMetadata struct {
}
type
Config
struct
{
BatchInbox
common
.
Address
InDirectory
string
OutDirectory
string
BatchInbox
common
.
Address
InDirectory
string
OutDirectory
string
L2ChainID
*
big
.
Int
L2GenesisTime
uint64
L2BlockTime
uint64
}
func
LoadFrames
(
directory
string
,
inbox
common
.
Address
)
[]
FrameWithMetadata
{
...
...
@@ -68,9 +70,8 @@ func Channels(config Config) {
for
_
,
frame
:=
range
frames
{
framesByChannel
[
frame
.
Frame
.
ID
]
=
append
(
framesByChannel
[
frame
.
Frame
.
ID
],
frame
)
}
cfg
:=
chaincfg
.
Mainnet
for
id
,
frames
:=
range
framesByChannel
{
ch
:=
processFrames
(
c
f
g
,
id
,
frames
)
ch
:=
processFrames
(
c
onfi
g
,
id
,
frames
)
filename
:=
path
.
Join
(
config
.
OutDirectory
,
fmt
.
Sprintf
(
"%s.json"
,
id
.
String
()))
if
err
:=
writeChannel
(
ch
,
filename
);
err
!=
nil
{
log
.
Fatal
(
err
)
...
...
@@ -88,7 +89,7 @@ func writeChannel(ch ChannelWithMetadata, filename string) error {
return
enc
.
Encode
(
ch
)
}
func
processFrames
(
cfg
*
rollup
.
Config
,
id
derive
.
ChannelID
,
frames
[]
FrameWithMetadata
)
ChannelWithMetadata
{
func
processFrames
(
cfg
Config
,
id
derive
.
ChannelID
,
frames
[]
FrameWithMetadata
)
ChannelWithMetadata
{
ch
:=
derive
.
NewChannel
(
id
,
eth
.
L1BlockRef
{
Number
:
frames
[
0
]
.
InclusionBlock
})
invalidFrame
:=
false
...
...
@@ -104,17 +105,39 @@ func processFrames(cfg *rollup.Config, id derive.ChannelID, frames []FrameWithMe
}
}
var
batches
[]
derive
.
BatchData
var
batches
[]
derive
.
Batch
var
batchTypes
[]
int
invalidBatches
:=
false
if
ch
.
IsReady
()
{
br
,
err
:=
derive
.
BatchReader
(
ch
.
Reader
())
if
err
==
nil
{
for
batch
,
err
:=
br
();
err
!=
io
.
EOF
;
batch
,
err
=
br
()
{
for
batch
Data
,
err
:=
br
();
err
!=
io
.
EOF
;
batchData
,
err
=
br
()
{
if
err
!=
nil
{
fmt
.
Printf
(
"Error reading batch for channel %v. Err: %v
\n
"
,
id
.
String
(),
err
)
fmt
.
Printf
(
"Error reading batch
Data
for channel %v. Err: %v
\n
"
,
id
.
String
(),
err
)
invalidBatches
=
true
}
else
{
batches
=
append
(
batches
,
*
batch
)
batchType
:=
batchData
.
GetBatchType
()
batchTypes
=
append
(
batchTypes
,
int
(
batchType
))
switch
batchType
{
case
derive
.
SingularBatchType
:
singularBatch
,
err
:=
derive
.
GetSingularBatch
(
batchData
)
if
err
!=
nil
{
invalidBatches
=
true
fmt
.
Printf
(
"Error converting singularBatch from batchData for channel %v. Err: %v
\n
"
,
id
.
String
(),
err
)
}
// singularBatch will be nil when errored
batches
=
append
(
batches
,
singularBatch
)
case
derive
.
SpanBatchType
:
spanBatch
,
err
:=
derive
.
DeriveSpanBatch
(
batchData
,
cfg
.
L2BlockTime
,
cfg
.
L2GenesisTime
,
cfg
.
L2ChainID
)
if
err
!=
nil
{
invalidBatches
=
true
fmt
.
Printf
(
"Error deriving spanBatch from batchData for channel %v. Err: %v
\n
"
,
id
.
String
(),
err
)
}
// spanBatch will be nil when errored
batches
=
append
(
batches
,
spanBatch
)
default
:
fmt
.
Printf
(
"unrecognized batch type: %d for channel %v.
\n
"
,
batchData
.
GetBatchType
(),
id
.
String
())
}
}
}
}
else
{
...
...
@@ -131,6 +154,7 @@ func processFrames(cfg *rollup.Config, id derive.ChannelID, frames []FrameWithMe
InvalidFrames
:
invalidFrame
,
InvalidBatches
:
invalidBatches
,
Batches
:
batches
,
BatchTypes
:
batchTypes
,
}
}
...
...
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