44 "context"
55 "errors"
66 "fmt"
7+ "github.com/ethereum/go-ethereum/accounts/abi"
8+ "github.com/ethereum/go-ethereum/common"
9+ "golang.org/x/crypto/sha3"
710 "io"
811 "math/big"
912 _ "net/http/pprof"
@@ -23,6 +26,22 @@ import (
2326 "github.com/ethereum-optimism/optimism/op-bindings/bindings"
2427)
2528
29+ func testnetAppendSelector () []byte {
30+ h := sha3 .NewLegacyKeccak256 ()
31+ h .Write ([]byte ("appendSequencerBatch()" ))
32+ sum := h .Sum (nil )
33+ return sum [:4 ]
34+ }
35+
36+ func buildTestnetRawCalldata (vhs [][32 ]byte ) []byte {
37+ data := make ([]byte , 0 , 4 + 32 * len (vhs ))
38+ data = append (data , testnetAppendSelector ()... )
39+ for _ , vh := range vhs {
40+ data = append (data , vh [:]... )
41+ }
42+ return data
43+ }
44+
2645// BatchSubmitter encapsulates a service responsible for submitting L2 tx
2746// batches to L1 for availability.
2847type BatchSubmitter struct {
@@ -106,6 +125,7 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metri
106125 MaxFrameSize : cfg .MaxL1TxSize - 1 , // subtract 1 byte for version
107126 CompressorConfig : cfg .CompressorConfig .Config (),
108127 },
128+ ChainID : cfg .ChainID ,
109129 }
110130
111131 // Validate the batcher config
@@ -165,6 +185,24 @@ func (l *BatchSubmitter) StopIfRunning(ctx context.Context) {
165185 _ = l .Stop (ctx )
166186}
167187
188+ func (l * BatchSubmitter ) PickCalldataFormat (
189+ ctx context.Context ,
190+ to common.Address ,
191+ arrayOfVHs [][32 ]byte ,
192+ parsedABI * abi.ABI ,
193+ ) ([]byte , error ) {
194+ if l .Config .ChainID == 5700 { // sys testnet
195+ return buildTestnetRawCalldata (arrayOfVHs ), nil
196+ }
197+
198+ // mainnet is default (57 and any other chain ID)
199+ packed , err := parsedABI .Pack ("appendSequencerBatch" , arrayOfVHs )
200+ if err != nil {
201+ return nil , fmt .Errorf ("failed to pack mainnet calldata: %w" , err )
202+ }
203+ return packed , nil
204+ }
205+
168206func (l * BatchSubmitter ) Stop (ctx context.Context ) error {
169207 l .log .Info ("Stopping Batch Submitter" )
170208
@@ -403,13 +441,14 @@ func (l *BatchSubmitter) publishTxToL1(ctx context.Context, queue *txmgr.Queue[t
403441 var array [32 ]byte
404442 copy (array [:], receipt .TxHash .Bytes ())
405443 arrayOfVHs = append (arrayOfVHs , array )
406- packedData , err := parsedABI . Pack ( appendSequencerBatchMethodName , arrayOfVHs )
444+ calldata , err := l . PickCalldataFormat ( ctx , l . Rollup . BatchInboxAddress , arrayOfVHs , parsedABI )
407445 if err != nil {
408- l .log .Error ("Failed to pack data for function call: %v " , err )
446+ l .log .Error ("Failed to build calldata for BatchInbox" , "err " , err )
409447 l .recordFailedTx (txdata .ID (), err )
410448 return err
411449 }
412- txdata .frame .data = packedData
450+
451+ txdata .frame .data = calldata
413452 l .sendTransaction (txdata , queue , receiptsCh )
414453 }
415454 return nil
0 commit comments