Skip to content

Commit 7c27ce6

Browse files
Merge pull request #6 from SYS-Labs/fix_testnet_1
Make calldata dynamic
2 parents 9bf2f09 + ec5eb08 commit 7c27ce6

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

op-batcher/batcher/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type Config struct {
3535

3636
// Channel builder parameters
3737
Channel ChannelConfig
38+
39+
// SYSCOIN
40+
ChainID uint64
3841
}
3942

4043
// Check ensures that the [Config] is valid.
@@ -92,6 +95,9 @@ type CLIConfig struct {
9295
MetricsConfig opmetrics.CLIConfig
9396
PprofConfig oppprof.CLIConfig
9497
CompressorConfig compressor.CLIConfig
98+
99+
// SYSCOIN
100+
ChainID uint64
95101
}
96102

97103
func (c CLIConfig) Check() error {
@@ -122,6 +128,7 @@ func NewConfig(ctx *cli.Context) CLIConfig {
122128
RollupRpc: ctx.String(flags.RollupRpcFlag.Name),
123129
SubSafetyMargin: ctx.Uint64(flags.SubSafetyMarginFlag.Name),
124130
PollInterval: ctx.Duration(flags.PollIntervalFlag.Name),
131+
ChainID: ctx.Uint64(flags.ChainIDFlag.Name),
125132

126133
/* Optional Flags */
127134

op-batcher/batcher/driver.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
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.
2847
type 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+
168206
func (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

op-batcher/flags/flags.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ var (
3939
Usage: "HTTP provider URL for Rollup node",
4040
EnvVars: prefixEnvVars("ROLLUP_RPC"),
4141
}
42+
ChainIDFlag = &cli.StringFlag{
43+
Name: "rollup-rpc",
44+
Usage: "HTTP provider URL for Rollup node",
45+
EnvVars: prefixEnvVars("CHAIN_ID"),
46+
}
4247
// Optional flags
4348
SubSafetyMarginFlag = &cli.Uint64Flag{
4449
Name: "sub-safety-margin",
@@ -48,6 +53,7 @@ var (
4853
Value: 10,
4954
EnvVars: prefixEnvVars("SUB_SAFETY_MARGIN"),
5055
}
56+
5157
PollIntervalFlag = &cli.DurationFlag{
5258
Name: "poll-interval",
5359
Usage: "How frequently to poll L2 for new blocks",

ops-bedrock/docker-compose-rollux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ services:
167167
OP_BATCHER_PPROF_ENABLED: "true"
168168
OP_BATCHER_METRICS_ENABLED: "true"
169169
OP_BATCHER_RPC_ENABLE_ADMIN: "true"
170+
OP_BATCHER_CHAIN_ID: 57
170171
dns:
171172
- 8.8.8.8
172173
- 8.8.4.4

ops-bedrock/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ services:
167167
OP_BATCHER_PPROF_ENABLED: "true"
168168
OP_BATCHER_METRICS_ENABLED: "true"
169169
OP_BATCHER_RPC_ENABLE_ADMIN: "true"
170+
OP_BATCHER_CHAIN_ID: 5700
170171
dns:
171172
- 8.8.8.8
172173
- 8.8.4.4

0 commit comments

Comments
 (0)