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
1786f370
Unverified
Commit
1786f370
authored
Mar 07, 2023
by
Joshua Gutow
Committed by
GitHub
Mar 07, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5063 from ethereum-optimism/jg/batch_introspection
op-node/cmd/batch_decoder: Fetch batches
parents
c35b6e39
6f445b2f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
212 additions
and
0 deletions
+212
-0
fetch.go
op-node/cmd/batch_decoder/fetch/fetch.go
+117
-0
main.go
op-node/cmd/batch_decoder/main.go
+90
-0
params.go
op-node/rollup/derive/params.go
+5
-0
No files found.
op-node/cmd/batch_decoder/fetch/fetch.go
0 → 100644
View file @
1786f370
package
fetch
import
(
"context"
"encoding/json"
"fmt"
"log"
"math/big"
"os"
"path"
"time"
"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/ethclient"
)
type
TransactionWithMeta
struct
{
TxIndex
uint64
`json:"tx_index"`
InboxAddr
common
.
Address
`json:"inbox_address"`
BlockNumber
uint64
`json:"block_number"`
BlockHash
common
.
Hash
`json:"block_hash"`
ChainId
uint64
`json:"chain_id"`
Sender
common
.
Address
`json:"sender"`
ValidSender
bool
`json:"valid_sender"`
Frames
[]
derive
.
Frame
`json:"frames"`
FrameErr
string
`json:"frame_parse_error"`
ValidFrames
bool
`json:"valid_data"`
Tx
*
types
.
Transaction
`json:"tx"`
}
type
Config
struct
{
Start
,
End
uint64
ChainID
*
big
.
Int
BatchInbox
common
.
Address
BatchSenders
map
[
common
.
Address
]
struct
{}
OutDirectory
string
}
func
Batches
(
client
*
ethclient
.
Client
,
config
Config
)
(
totalValid
,
totalInvalid
int
)
{
if
err
:=
os
.
MkdirAll
(
config
.
OutDirectory
,
0750
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
number
:=
new
(
big
.
Int
)
.
SetUint64
(
config
.
Start
)
signer
:=
types
.
LatestSignerForChainID
(
config
.
ChainID
)
for
i
:=
config
.
Start
;
i
<
config
.
End
;
i
++
{
valid
,
invalid
:=
fetchBatchesPerBlock
(
client
,
number
,
signer
,
config
)
totalValid
+=
valid
totalInvalid
+=
invalid
number
=
number
.
Add
(
number
,
common
.
Big1
)
}
return
}
func
fetchBatchesPerBlock
(
client
*
ethclient
.
Client
,
number
*
big
.
Int
,
signer
types
.
Signer
,
config
Config
)
(
validBatchCount
,
invalidBatchCount
int
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
block
,
err
:=
client
.
BlockByNumber
(
ctx
,
number
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
for
i
,
tx
:=
range
block
.
Transactions
()
{
if
tx
.
To
()
!=
nil
&&
*
tx
.
To
()
==
config
.
BatchInbox
{
sender
,
err
:=
signer
.
Sender
(
tx
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
validSender
:=
true
if
_
,
ok
:=
config
.
BatchSenders
[
sender
];
!
ok
{
fmt
.
Printf
(
"Found a transaction (%s) from an invalid sender (%s)
\n
"
,
tx
.
Hash
()
.
String
(),
sender
.
String
())
invalidBatchCount
+=
1
validSender
=
false
}
validFrames
:=
true
frameError
:=
""
frames
,
err
:=
derive
.
ParseFrames
(
tx
.
Data
())
if
err
!=
nil
{
fmt
.
Printf
(
"Found a transaction (%s) with invalid data: %v
\n
"
,
tx
.
Hash
()
.
String
(),
err
)
validFrames
=
false
frameError
=
err
.
Error
()
}
if
validSender
&&
validFrames
{
validBatchCount
+=
1
}
else
{
invalidBatchCount
+=
1
}
txm
:=
&
TransactionWithMeta
{
Tx
:
tx
,
Sender
:
sender
,
ValidSender
:
validSender
,
TxIndex
:
uint64
(
i
),
BlockNumber
:
block
.
NumberU64
(),
BlockHash
:
block
.
Hash
(),
ChainId
:
config
.
ChainID
.
Uint64
(),
InboxAddr
:
config
.
BatchInbox
,
Frames
:
frames
,
FrameErr
:
frameError
,
ValidFrames
:
validFrames
,
}
filename
:=
path
.
Join
(
config
.
OutDirectory
,
fmt
.
Sprintf
(
"%s.json"
,
tx
.
Hash
()
.
String
()))
file
,
err
:=
os
.
Create
(
filename
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
defer
file
.
Close
()
enc
:=
json
.
NewEncoder
(
file
)
if
err
:=
enc
.
Encode
(
txm
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
}
return
}
op-node/cmd/batch_decoder/main.go
0 → 100644
View file @
1786f370
package
main
import
(
"context"
"fmt"
"log"
"os"
"time"
"github.com/ethereum-optimism/optimism/op-node/cmd/batch_decoder/fetch"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/urfave/cli"
)
func
main
()
{
app
:=
cli
.
NewApp
()
app
.
Name
=
"batch-decoder"
app
.
Usage
=
"Optimism Batch Decoding Utility"
app
.
Commands
=
[]
cli
.
Command
{
{
Name
:
"fetch"
,
Usage
:
"Fetches batches in the specified range"
,
Flags
:
[]
cli
.
Flag
{
cli
.
IntFlag
{
Name
:
"start"
,
Required
:
true
,
Usage
:
"First block (inclusive) to fetch"
,
},
cli
.
IntFlag
{
Name
:
"end"
,
Required
:
true
,
Usage
:
"Last block (exclusive) to fetch"
,
},
cli
.
StringFlag
{
Name
:
"inbox"
,
Required
:
true
,
Usage
:
"Batch Inbox Address"
,
},
cli
.
StringFlag
{
Name
:
"sender"
,
Required
:
true
,
Usage
:
"Batch Sender Address"
,
},
cli
.
StringFlag
{
Name
:
"out"
,
Value
:
"/tmp/batch_decoder/transactions_cache"
,
Usage
:
"Cache directory for the found transactions"
,
},
cli
.
StringFlag
{
Name
:
"l1"
,
Required
:
true
,
Usage
:
"L1 RPC URL"
,
EnvVar
:
"L1_RPC"
,
},
},
Action
:
func
(
cliCtx
*
cli
.
Context
)
error
{
client
,
err
:=
ethclient
.
Dial
(
cliCtx
.
String
(
"l1"
))
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
1
*
time
.
Second
)
defer
cancel
()
chainID
,
err
:=
client
.
ChainID
(
ctx
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
config
:=
fetch
.
Config
{
Start
:
uint64
(
cliCtx
.
Int
(
"start"
)),
End
:
uint64
(
cliCtx
.
Int
(
"end"
)),
ChainID
:
chainID
,
BatchSenders
:
map
[
common
.
Address
]
struct
{}{
common
.
HexToAddress
(
cliCtx
.
String
(
"sender"
))
:
struct
{}{},
},
BatchInbox
:
common
.
HexToAddress
(
cliCtx
.
String
(
"inbox"
)),
OutDirectory
:
cliCtx
.
String
(
"out"
),
}
totalValid
,
totalInvalid
:=
fetch
.
Batches
(
client
,
config
)
fmt
.
Printf
(
"Fetched batches in range [%v,%v). Found %v valid & %v invalid batches
\n
"
,
config
.
Start
,
config
.
End
,
totalValid
,
totalInvalid
)
fmt
.
Printf
(
"Fetch Config: Chain ID: %v. Inbox Address: %v. Valid Senders: %v.
\n
"
,
config
.
ChainID
,
config
.
BatchInbox
,
config
.
BatchSenders
)
fmt
.
Printf
(
"Wrote transactions with batches to %v
\n
"
,
config
.
OutDirectory
)
return
nil
},
},
}
if
err
:=
app
.
Run
(
os
.
Args
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
op-node/rollup/derive/params.go
View file @
1786f370
package
derive
package
derive
import
(
import
(
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
)
)
...
@@ -44,3 +45,7 @@ func (id ChannelID) String() string {
...
@@ -44,3 +45,7 @@ func (id ChannelID) String() string {
func
(
id
ChannelID
)
TerminalString
()
string
{
func
(
id
ChannelID
)
TerminalString
()
string
{
return
fmt
.
Sprintf
(
"%x..%x"
,
id
[
:
3
],
id
[
13
:
])
return
fmt
.
Sprintf
(
"%x..%x"
,
id
[
:
3
],
id
[
13
:
])
}
}
func
(
id
ChannelID
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
id
.
String
())
}
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