6
6
"fmt"
7
7
"math/big"
8
8
_ "net/http/pprof"
9
+ "sort"
9
10
"sync"
10
11
"time"
11
12
@@ -362,12 +363,20 @@ func (l *L2OutputSubmitter) SubmitAggProofs(ctx context.Context) error {
362
363
return nil
363
364
}
364
365
365
- for _ , aggProof := range completedAggProofs {
366
- output , err := l .FetchOutput (ctx , aggProof .EndBlock )
367
- if err != nil {
368
- return fmt .Errorf ("failed to fetch output at block %d: %w" , aggProof .EndBlock , err )
369
- }
370
- l .proposeOutput (ctx , output , aggProof .Proof , aggProof .L1BlockNumber )
366
+ // Select the agg proof with the highest L2 block number.
367
+ sort .Slice (completedAggProofs , func (i , j int ) bool {
368
+ return completedAggProofs [i ].EndBlock > completedAggProofs [j ].EndBlock
369
+ })
370
+
371
+ // Submit the agg proof with the highest L2 block number.
372
+ aggProof := completedAggProofs [0 ]
373
+ output , err := l .FetchOutput (ctx , aggProof .EndBlock )
374
+ if err != nil {
375
+ return fmt .Errorf ("failed to fetch output at block %d: %w" , aggProof .EndBlock , err )
376
+ }
377
+ err = l .proposeOutput (ctx , output , aggProof .Proof , aggProof .L1BlockNumber )
378
+ if err != nil {
379
+ return fmt .Errorf ("failed to propose output: %w" , err )
371
380
}
372
381
373
382
return nil
@@ -683,15 +692,15 @@ func (l *L2OutputSubmitter) loopL2OO(ctx context.Context) {
683
692
}
684
693
}
685
694
686
- func (l * L2OutputSubmitter ) proposeOutput (ctx context.Context , output * eth.OutputResponse , proof []byte , l1BlockNum uint64 ) {
695
+ func (l * L2OutputSubmitter ) proposeOutput (ctx context.Context , output * eth.OutputResponse , proof []byte , l1BlockNum uint64 ) error {
687
696
cCtx , cancel := context .WithTimeout (ctx , 10 * time .Minute )
688
697
defer cancel ()
689
698
690
699
// Get the current nextBlockNumber from the L2OO contract.
691
700
nextBlockNumber , err := l .l2ooContract .NextBlockNumber (& bind.CallOpts {Context : cCtx })
692
701
if err != nil {
693
702
l .Log .Error ("Failed to get nextBlockNumber" , "err" , err )
694
- return
703
+ return err
695
704
}
696
705
697
706
if err := l .sendTransaction (cCtx , output , proof , l1BlockNum ); err != nil {
@@ -702,10 +711,11 @@ func (l *L2OutputSubmitter) proposeOutput(ctx context.Context, output *eth.Outpu
702
711
"l1blocknum" , l1BlockNum ,
703
712
"l1head" , output .Status .HeadL1 .Number ,
704
713
"proof" , proof )
705
- return
714
+ return err
706
715
}
707
716
l .Log .Info ("AGG proof submitted on-chain" , "end" , output .BlockRef .Number )
708
717
l .Metr .RecordL2BlocksProposed (output .BlockRef )
718
+ return nil
709
719
}
710
720
711
721
// checkpointBlockHash gets the current L1 head, and then sends a transaction to checkpoint the blockhash on
0 commit comments