Commit 6f445b2f authored by Joshua Gutow's avatar Joshua Gutow

batch_decoder: Attempt to parse frames

parent ff947801
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"path" "path"
"time" "time"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum/common" "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/ethclient" "github.com/ethereum/go-ethereum/ethclient"
...@@ -23,6 +24,9 @@ type TransactionWithMeta struct { ...@@ -23,6 +24,9 @@ type TransactionWithMeta struct {
ChainId uint64 `json:"chain_id"` ChainId uint64 `json:"chain_id"`
Sender common.Address `json:"sender"` Sender common.Address `json:"sender"`
ValidSender bool `json:"valid_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"` Tx *types.Transaction `json:"tx"`
} }
...@@ -62,14 +66,26 @@ func fetchBatchesPerBlock(client *ethclient.Client, number *big.Int, signer type ...@@ -62,14 +66,26 @@ func fetchBatchesPerBlock(client *ethclient.Client, number *big.Int, signer type
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
var validSender bool validSender := true
if _, ok := config.BatchSenders[sender]; !ok { if _, ok := config.BatchSenders[sender]; !ok {
fmt.Printf("Found a transaction (%s) from an invalid sender (%s)\n", tx.Hash().String(), sender.String()) fmt.Printf("Found a transaction (%s) from an invalid sender (%s)\n", tx.Hash().String(), sender.String())
invalidBatchCount += 1 invalidBatchCount += 1
validSender = false validSender = false
} else { }
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 validBatchCount += 1
validSender = true } else {
invalidBatchCount += 1
} }
txm := &TransactionWithMeta{ txm := &TransactionWithMeta{
...@@ -81,6 +97,9 @@ func fetchBatchesPerBlock(client *ethclient.Client, number *big.Int, signer type ...@@ -81,6 +97,9 @@ func fetchBatchesPerBlock(client *ethclient.Client, number *big.Int, signer type
BlockHash: block.Hash(), BlockHash: block.Hash(),
ChainId: config.ChainID.Uint64(), ChainId: config.ChainID.Uint64(),
InboxAddr: config.BatchInbox, InboxAddr: config.BatchInbox,
Frames: frames,
FrameErr: frameError,
ValidFrames: validFrames,
} }
filename := path.Join(config.OutDirectory, fmt.Sprintf("%s.json", tx.Hash().String())) filename := path.Join(config.OutDirectory, fmt.Sprintf("%s.json", tx.Hash().String()))
file, err := os.Create(filename) file, err := os.Create(filename)
......
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())
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment