Skip to content

Commit

Permalink
cli args for chains not in registry
Browse files Browse the repository at this point in the history
  • Loading branch information
zobront committed Aug 13, 2024
1 parent 76dfd4a commit a34fa2f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 16 deletions.
13 changes: 13 additions & 0 deletions op-proposer/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ var (
Value: 10,
EnvVars: prefixEnvVars("BATCH_DECODER_CONCURRENT_REQS"),
}
BatchInboxFlag = &cli.StringFlag{
Name: "batch-inbox",
Usage: "Batch Inbox Address",
EnvVars: prefixEnvVars("BATCH_INBOX"),
}
BatcherAddressFlag = &cli.StringFlag{
Name: "batcher-address",
Usage: "Batch Sender Address",
EnvVars: prefixEnvVars("BATCHER_ADDRESS"),
}

// Legacy Flags
L2OutputHDPathFlag = txmgr.L2OutputHDPathFlag
)
Expand Down Expand Up @@ -173,6 +184,8 @@ var optionalFlags = []cli.Flag{
BatchDecoderConcurrentReqsFlag,
KonaServerUrlFlag,
MaxConcurrentProofRequestsFlag,
BatchInboxFlag,
BatcherAddressFlag,
}

func init() {
Expand Down
6 changes: 6 additions & 0 deletions op-proposer/proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ type CLIConfig struct {
KonaServerUrl string
// The maximum proofs that can be requested from the server concurrently.
MaxConcurrentProofRequests uint64
// The batch inbox on L1 to read batches from. Note that this is ignored if L2 Chain ID is in rollup config.
BatchInbox string
// The batcher address to include transactions from. Note that this is ignored if L2 Chain ID is in rollup config.
BatcherAddress string
}

func (c *CLIConfig) Check() error {
Expand Down Expand Up @@ -151,5 +155,7 @@ func NewConfig(ctx *cli.Context) *CLIConfig {
BatchDecoderConcurrentReqs: ctx.Uint64(flags.BatchDecoderConcurrentReqsFlag.Name),
KonaServerUrl: ctx.String(flags.KonaServerUrlFlag.Name),
MaxConcurrentProofRequests: ctx.Uint64(flags.MaxConcurrentProofRequestsFlag.Name),
BatchInbox: ctx.String(flags.BatchInboxFlag.Name),
BatcherAddress: ctx.String(flags.BatcherAddressFlag.Name),
}
}
4 changes: 4 additions & 0 deletions op-proposer/proposer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type L2OOContract interface {
NextBlockNumber(*bind.CallOpts) (*big.Int, error)
LatestOutputIndex(*bind.CallOpts) (*big.Int, error)
NextOutputIndex(*bind.CallOpts) (*big.Int, error)
StartingTimestamp(*bind.CallOpts) (*big.Int, error)
L2BLOCKTIME(*bind.CallOpts) (*big.Int, error)
}

type RollupClient interface {
Expand Down Expand Up @@ -86,6 +88,8 @@ type L2OutputSubmitter struct {
dgfABI *abi.ABI

db db.ProofDB

lastFetchedL1Block uint64
}

// NewL2OutputSubmitter creates a new L2 Output Submitter
Expand Down
4 changes: 4 additions & 0 deletions op-proposer/proposer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type ProposerConfig struct {
ProofTimeout uint64
KonaServerUrl string
MaxConcurrentProofRequests uint64
BatchInbox common.Address
BatcherAddress common.Address
}

type ProposerService struct {
Expand Down Expand Up @@ -120,6 +122,8 @@ func (ps *ProposerService) initFromCLIConfig(ctx context.Context, version string
ps.ProofTimeout = cfg.ProofTimeout
ps.L2ChainID = cfg.L2ChainID
ps.MaxConcurrentProofRequests = cfg.MaxConcurrentProofRequests
ps.BatchInbox = common.HexToAddress(cfg.BatchInbox)
ps.BatcherAddress = common.HexToAddress(cfg.BatcherAddress)

ps.initL2ooAddress(cfg)
ps.initDGF(cfg)
Expand Down
61 changes: 45 additions & 16 deletions op-proposer/proposer/span_batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (l *L2OutputSubmitter) DeriveNewSpanBatches(ctx context.Context) error {

for {
// use batch decoder to reassemble the batches from disk to determine the start and end of relevant span batch
start, end, err := l.GenerateSpanBatchRange(nextBlock, l.DriverSetup.Cfg.MaxSpanBatchDeviation)
start, end, err := l.GenerateSpanBatchRange(ctx, nextBlock, l.DriverSetup.Cfg.MaxSpanBatchDeviation)
if err == reassemble.NoSpanBatchFoundError {
l.Log.Info("no span batch found", "nextBlock", nextBlock)
break
Expand Down Expand Up @@ -120,13 +120,19 @@ func (l *L2OutputSubmitter) FetchBatchesFromChain(ctx context.Context, nextBlock
fmt.Println("L1 Beacon endpoint not set. Unable to fetch post-ecotone channel frames")
return err
}
// ZTODO: This won't work for untracked / new / test chains.
// How do we want to handle that? This is just for BatcherAddr / BatchInbox,
// so I think best is to allow CLI arg of either ChainID or those two.

batchInbox, batcherAddress := common.Address{}, common.Address{}
rollupCfg, err := rollup.LoadOPStackRollupConfig(l.Cfg.L2ChainID)
if err != nil {
log.Fatal(err)
return err
l.Log.Warn("failed to load rollup config, trying cli args: %w", err)
if (l.Cfg.BatcherAddress == common.Address{} || l.Cfg.BatchInbox == common.Address{}) {
return err
}
batchInbox = l.Cfg.BatchInbox
batcherAddress = l.Cfg.BatcherAddress
} else {
batchInbox = rollupCfg.BatchInboxAddress
batcherAddress = rollupCfg.Genesis.SystemConfig.BatcherAddr
}

l.Log.Info("Fetching batches from L1 Origin to Finalized L1", "l1 origin", l1Origin, "Finalized L1", finalizedL1)
Expand All @@ -135,33 +141,56 @@ func (l *L2OutputSubmitter) FetchBatchesFromChain(ctx context.Context, nextBlock
End: finalizedL1,
ChainID: chainID,
BatchSenders: map[common.Address]struct{}{
rollupCfg.Genesis.SystemConfig.BatcherAddr: {},
batcherAddress: {},
},
BatchInbox: rollupCfg.BatchInboxAddress,
BatchInbox: batchInbox,
OutDirectory: proposerConfig.TxCacheOutDir,
ConcurrentRequests: proposerConfig.BatchDecoderConcurrentReqs,
}

// ZTODO: How to avoid it refetching the same ones repeatedly?
// TODO: Optimization to avoid it refetching same batches.
totalValid, _ := fetch.Batches(l1Client, beacon, fetchConfig)
l.Log.Info("Fetched batches", "totalValid", totalValid)
l.Log.Info("Successfully fetched batches", "totalValid", totalValid)
return nil
}

func (l *L2OutputSubmitter) GenerateSpanBatchRange(nextBlock, maxSpanBatchDeviation uint64) (uint64, uint64, error) {
func (l *L2OutputSubmitter) GenerateSpanBatchRange(ctx context.Context, nextBlock, maxSpanBatchDeviation uint64) (uint64, uint64, error) {
batchInbox, l2BlockTime, genesisTimestamp := common.Address{}, uint64(0), uint64(0)
rollupCfg, err := rollup.LoadOPStackRollupConfig(l.Cfg.L2ChainID)
if err != nil {
log.Fatal(err)
return 0, 0, err
if (l.Cfg.BatchInbox == common.Address{}) {
return 0, 0, err
}
cCtx, cancel := context.WithTimeout(ctx, l.Cfg.NetworkTimeout)
defer cancel()
callOpts := &bind.CallOpts{
From: l.Txmgr.From(),
Context: cCtx,
}
l2BlockTimeU256, err := l.l2ooContract.L2BLOCKTIME(callOpts)
if err != nil {
return 0, 0, fmt.Errorf("error pulling l2 block time from L2OO contract: %w", err)
}
l2BlockTime = l2BlockTimeU256.Uint64()

genesisTimestampU256, err := l.l2ooContract.StartingTimestamp(callOpts)
if err != nil {
return 0, 0, fmt.Errorf("error pulling genesis timestamp from L2OO contract: %w", err)
}
genesisTimestamp = genesisTimestampU256.Uint64()
} else {
batchInbox = rollupCfg.BatchInboxAddress
l2BlockTime = rollupCfg.BlockTime
genesisTimestamp = rollupCfg.Genesis.L2Time
}

reassembleConfig := reassemble.Config{
BatchInbox: rollupCfg.BatchInboxAddress,
BatchInbox: batchInbox,
InDirectory: l.DriverSetup.Cfg.TxCacheOutDir,
OutDirectory: "",
L2ChainID: new(big.Int).SetUint64(l.Cfg.L2ChainID),
L2GenesisTime: rollupCfg.Genesis.L2Time,
L2BlockTime: rollupCfg.BlockTime,
L2GenesisTime: genesisTimestamp,
L2BlockTime: l2BlockTime,
}

return reassemble.GetSpanBatchRange(reassembleConfig, rollupCfg, nextBlock, maxSpanBatchDeviation)
Expand Down
Binary file modified proofs.db
Binary file not shown.

0 comments on commit a34fa2f

Please sign in to comment.