Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions op-batcher/batcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type Config struct {

// Channel builder parameters
Channel ChannelConfig

// SYSCOIN
ChainID uint64
}

// Check ensures that the [Config] is valid.
Expand Down Expand Up @@ -92,6 +95,9 @@ type CLIConfig struct {
MetricsConfig opmetrics.CLIConfig
PprofConfig oppprof.CLIConfig
CompressorConfig compressor.CLIConfig

// SYSCOIN
ChainID uint64
}

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

/* Optional Flags */

Expand Down
45 changes: 42 additions & 3 deletions op-batcher/batcher/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"golang.org/x/crypto/sha3"
"io"
"math/big"
_ "net/http/pprof"
Expand All @@ -23,6 +26,22 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
)

func testnetAppendSelector() []byte {
h := sha3.NewLegacyKeccak256()
h.Write([]byte("appendSequencerBatch()"))
sum := h.Sum(nil)
return sum[:4]
}

func buildTestnetRawCalldata(vhs [][32]byte) []byte {
data := make([]byte, 0, 4+32*len(vhs))
data = append(data, testnetAppendSelector()...)
for _, vh := range vhs {
data = append(data, vh[:]...)
}
return data
}

// BatchSubmitter encapsulates a service responsible for submitting L2 tx
// batches to L1 for availability.
type BatchSubmitter struct {
Expand Down Expand Up @@ -106,6 +125,7 @@ func NewBatchSubmitterFromCLIConfig(cfg CLIConfig, l log.Logger, m metrics.Metri
MaxFrameSize: cfg.MaxL1TxSize - 1, // subtract 1 byte for version
CompressorConfig: cfg.CompressorConfig.Config(),
},
ChainID: cfg.ChainID,
}

// Validate the batcher config
Expand Down Expand Up @@ -165,6 +185,24 @@ func (l *BatchSubmitter) StopIfRunning(ctx context.Context) {
_ = l.Stop(ctx)
}

func (l *BatchSubmitter) PickCalldataFormat(
ctx context.Context,
to common.Address,
arrayOfVHs [][32]byte,
parsedABI *abi.ABI,
) ([]byte, error) {
if l.Config.ChainID == 5700 { // sys testnet
return buildTestnetRawCalldata(arrayOfVHs), nil
}

// mainnet is default (57 and any other chain ID)
packed, err := parsedABI.Pack("appendSequencerBatch", arrayOfVHs)
if err != nil {
return nil, fmt.Errorf("failed to pack mainnet calldata: %w", err)
}
return packed, nil
}

func (l *BatchSubmitter) Stop(ctx context.Context) error {
l.log.Info("Stopping Batch Submitter")

Expand Down Expand Up @@ -403,13 +441,14 @@ func (l *BatchSubmitter) publishTxToL1(ctx context.Context, queue *txmgr.Queue[t
var array [32]byte
copy(array[:], receipt.TxHash.Bytes())
arrayOfVHs = append(arrayOfVHs, array)
packedData, err := parsedABI.Pack(appendSequencerBatchMethodName, arrayOfVHs)
calldata, err := l.PickCalldataFormat(ctx, l.Rollup.BatchInboxAddress, arrayOfVHs, parsedABI)
if err != nil {
l.log.Error("Failed to pack data for function call: %v", err)
l.log.Error("Failed to build calldata for BatchInbox", "err", err)
l.recordFailedTx(txdata.ID(), err)
return err
}
txdata.frame.data = packedData

txdata.frame.data = calldata
l.sendTransaction(txdata, queue, receiptsCh)
}
return nil
Expand Down
6 changes: 6 additions & 0 deletions op-batcher/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ var (
Usage: "HTTP provider URL for Rollup node",
EnvVars: prefixEnvVars("ROLLUP_RPC"),
}
ChainIDFlag = &cli.StringFlag{
Name: "rollup-rpc",
Usage: "HTTP provider URL for Rollup node",
EnvVars: prefixEnvVars("CHAIN_ID"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is op-batcher getting OP_BATCHER_CHAIN_ID (as set in docker-compose) or is the prefix "OP_BATCHER_" taken out somehow?

}
// Optional flags
SubSafetyMarginFlag = &cli.Uint64Flag{
Name: "sub-safety-margin",
Expand All @@ -48,6 +53,7 @@ var (
Value: 10,
EnvVars: prefixEnvVars("SUB_SAFETY_MARGIN"),
}

PollIntervalFlag = &cli.DurationFlag{
Name: "poll-interval",
Usage: "How frequently to poll L2 for new blocks",
Expand Down
1 change: 1 addition & 0 deletions ops-bedrock/docker-compose-rollux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ services:
OP_BATCHER_PPROF_ENABLED: "true"
OP_BATCHER_METRICS_ENABLED: "true"
OP_BATCHER_RPC_ENABLE_ADMIN: "true"
OP_BATCHER_CHAIN_ID: 57
dns:
- 8.8.8.8
- 8.8.4.4
Expand Down
1 change: 1 addition & 0 deletions ops-bedrock/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ services:
OP_BATCHER_PPROF_ENABLED: "true"
OP_BATCHER_METRICS_ENABLED: "true"
OP_BATCHER_RPC_ENABLE_ADMIN: "true"
OP_BATCHER_CHAIN_ID: 5700
dns:
- 8.8.8.8
- 8.8.4.4
Expand Down
Loading