Commit a5ab73f9 authored by vicotor's avatar vicotor

fix bug

parent 13d9396e
...@@ -237,9 +237,9 @@ func (n *OpNode) initL1(ctx context.Context, cfg *Config) error { ...@@ -237,9 +237,9 @@ func (n *OpNode) initL1(ctx context.Context, cfg *Config) error {
// Poll for the safe L1 block and finalized block, // Poll for the safe L1 block and finalized block,
// which only change once per epoch at most and may be delayed. // which only change once per epoch at most and may be delayed.
n.l1SafeSub = eth.PollBlockChanges(n.log, n.l1Source, n.OnNewL1Safe, eth.Safe, n.l1SafeSub = eth.PollBlockChanges(n.log, n.l1Source, n.OnNewL1Safe, eth.Unsafe,
cfg.L1EpochPollInterval, time.Second*10) cfg.L1EpochPollInterval, time.Second*10)
n.l1FinalizedSub = eth.PollBlockChanges(n.log, n.l1Source, n.OnNewL1Finalized, eth.Finalized, n.l1FinalizedSub = eth.PollBlockChanges(n.log, n.l1Source, n.OnNewL1Finalized, eth.Unsafe,
cfg.L1EpochPollInterval, time.Second*10) cfg.L1EpochPollInterval, time.Second*10)
return nil return nil
} }
......
...@@ -233,12 +233,15 @@ func (l *L2OutputSubmitter) FetchL2OOOutput(ctx context.Context) (*eth.OutputRes ...@@ -233,12 +233,15 @@ func (l *L2OutputSubmitter) FetchL2OOOutput(ctx context.Context) (*eth.OutputRes
Context: cCtx, Context: cCtx,
} }
nextCheckpointBlockBig, err := l.l2ooContract.NextBlockNumber(callOpts) nextCheckpointBlockBig, err := l.l2ooContract.NextBlockNumber(callOpts)
l.Log.Info("Fetching next block number", "block", nextCheckpointBlockBig)
if err != nil { if err != nil {
return nil, false, fmt.Errorf("querying next block number: %w", err) return nil, false, fmt.Errorf("querying next block number: %w", err)
} }
nextCheckpointBlock := nextCheckpointBlockBig.Uint64() nextCheckpointBlock := nextCheckpointBlockBig.Uint64()
// Fetch the current L2 heads // Fetch the current L2 heads
currentBlockNumber, err := l.FetchCurrentBlockNumber(ctx) currentBlockNumber, err := l.FetchCurrentBlockNumber(ctx)
l.Log.Info("Fetching current block number", "block", currentBlockNumber, "err", err)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
} }
...@@ -322,11 +325,14 @@ func (l *L2OutputSubmitter) FetchCurrentBlockNumber(ctx context.Context) (uint64 ...@@ -322,11 +325,14 @@ func (l *L2OutputSubmitter) FetchCurrentBlockNumber(ctx context.Context) (uint64
return 0, fmt.Errorf("getting sync status: %w", err) return 0, fmt.Errorf("getting sync status: %w", err)
} }
//l.Log.Info("rollup sync status", "status", status)
return status.UnsafeL2.Number, nil
// Use either the finalized or safe head depending on the config. Finalized head is default & safer. // Use either the finalized or safe head depending on the config. Finalized head is default & safer.
if l.Cfg.AllowNonFinalized { //if l.Cfg.AllowNonFinalized {
return status.SafeL2.Number, nil // return status.SafeL2.Number, nil
} //}
return status.FinalizedL2.Number, nil //return status.FinalizedL2.Number, nil
} }
func (l *L2OutputSubmitter) FetchOutput(ctx context.Context, block uint64) (*eth.OutputResponse, error) { func (l *L2OutputSubmitter) FetchOutput(ctx context.Context, block uint64) (*eth.OutputResponse, error) {
......
...@@ -242,7 +242,7 @@ func (l *Operator) DoOperator(ctx context.Context) { ...@@ -242,7 +242,7 @@ func (l *Operator) DoOperator(ctx context.Context) {
l.Log.Error("failed to get latest block number from l2oo", "err", err) l.Log.Error("failed to get latest block number from l2oo", "err", err)
return return
} }
l.Log.Debug("latest block number from l2oo", "l2Latest", l2Latest) l.Log.Info("latest block number from l2oo", "l2Latest", l2Latest, "progress", progress)
currentFinished := false currentFinished := false
if progress.Total == 0 || progress.Index == (progress.Total-1) { if progress.Total == 0 || progress.Index == (progress.Total-1) {
currentFinished = true currentFinished = true
...@@ -415,6 +415,7 @@ func (l *Operator) sendTransaction(ctx context.Context, params []bindings.TypesB ...@@ -415,6 +415,7 @@ func (l *Operator) sendTransaction(ctx context.Context, params []bindings.TypesB
// loop is responsible for creating & submitting the next outputs // loop is responsible for creating & submitting the next outputs
// The loop regularly polls the L2 chain to infer whether to make the next proposal. // The loop regularly polls the L2 chain to infer whether to make the next proposal.
func (l *Operator) loop() { func (l *Operator) loop() {
l.Log.Info("Operator loop started")
defer l.wg.Done() defer l.wg.Done()
defer l.Log.Info("loop returning") defer l.Log.Info("loop returning")
ctx := l.ctx ctx := l.ctx
......
...@@ -64,6 +64,7 @@ type ProposerService struct { ...@@ -64,6 +64,7 @@ type ProposerService struct {
RollupProvider dial.RollupProvider RollupProvider dial.RollupProvider
driver *L2OutputSubmitter driver *L2OutputSubmitter
operator *Operator
Version string Version string
...@@ -118,6 +119,9 @@ func (ps *ProposerService) initFromCLIConfig(ctx context.Context, version string ...@@ -118,6 +119,9 @@ func (ps *ProposerService) initFromCLIConfig(ctx context.Context, version string
if err := ps.initDriver(); err != nil { if err := ps.initDriver(); err != nil {
return fmt.Errorf("failed to init Driver: %w", err) return fmt.Errorf("failed to init Driver: %w", err)
} }
if err := ps.initOperator(); err != nil {
return fmt.Errorf("failed to init Operator: %w", err)
}
if err := ps.initRPCServer(cfg); err != nil { if err := ps.initRPCServer(cfg); err != nil {
return fmt.Errorf("failed to start RPC server: %w", err) return fmt.Errorf("failed to start RPC server: %w", err)
} }
...@@ -253,6 +257,23 @@ func (ps *ProposerService) initDriver() error { ...@@ -253,6 +257,23 @@ func (ps *ProposerService) initDriver() error {
return nil return nil
} }
func (ps *ProposerService) initOperator() error {
operator, err := NewOperator(DriverSetup{
Log: ps.Log,
Metr: ps.Metrics,
Cfg: ps.ProposerConfig,
Txmgr: ps.TxManager,
L1Client: ps.L1Client,
Multicaller: batching.NewMultiCaller(ps.L1Client.Client(), batching.DefaultBatchSize),
RollupProvider: ps.RollupProvider,
}, ps.Database)
if err != nil {
return err
}
ps.operator = operator
return nil
}
func (ps *ProposerService) initRPCServer(cfg *CLIConfig) error { func (ps *ProposerService) initRPCServer(cfg *CLIConfig) error {
server := oprpc.NewServer( server := oprpc.NewServer(
cfg.RPCConfig.ListenAddr, cfg.RPCConfig.ListenAddr,
...@@ -278,7 +299,13 @@ func (ps *ProposerService) initRPCServer(cfg *CLIConfig) error { ...@@ -278,7 +299,13 @@ func (ps *ProposerService) initRPCServer(cfg *CLIConfig) error {
// and starts L2Output-submission work if the proposer is configured to start submit data on startup. // and starts L2Output-submission work if the proposer is configured to start submit data on startup.
func (ps *ProposerService) Start(_ context.Context) error { func (ps *ProposerService) Start(_ context.Context) error {
ps.Log.Info("Starting Proposer") ps.Log.Info("Starting Proposer")
return ps.driver.StartL2OutputSubmitting() if err := ps.driver.StartL2OutputSubmitting(); err != nil {
return err
}
if err := ps.operator.StartOperator(); err != nil {
return err
}
return nil
} }
func (ps *ProposerService) Stopped() bool { func (ps *ProposerService) Stopped() bool {
...@@ -307,6 +334,12 @@ func (ps *ProposerService) Stop(ctx context.Context) error { ...@@ -307,6 +334,12 @@ func (ps *ProposerService) Stop(ctx context.Context) error {
} }
} }
if ps.operator != nil {
if err := ps.operator.StopOperator(); err != nil {
result = errors.Join(result, fmt.Errorf("failed to stop operator: %w", err))
}
}
if ps.rpcServer != nil { if ps.rpcServer != nil {
// TODO(7685): the op-service RPC server is not built on top of op-service httputil Server, and has poor shutdown // TODO(7685): the op-service RPC server is not built on top of op-service httputil Server, and has poor shutdown
if err := ps.rpcServer.Stop(); err != nil { if err := ps.rpcServer.Stop(); err != nil {
......
#!/bin/bash
source .envrc
./bin/op-proposer \
--data-dir=./data/proposer \
--poll-interval=12s \
--rpc.port=8560 \
--rollup-rpc=http://127.0.0.1:9545 \
--l2oo-address=$(cat ./deployer/artifact.json | grep "L2OutputOracleProxy" | grep -Eo "0x[a-fA-F0-9]+") \
--portal-address=$(cat ./deployer/artifact.json | grep -w "OptimismPortal" | grep -Eo "0x[a-fA-F0-9]+") \
--private-key=$GS_PROPOSER_PRIVATE_KEY \
--l1-eth-rpc=$L1_RPC_URL
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