@@ -488,6 +488,45 @@ describe('sequencer', () => {
488
488
expectPublisherProposeL2Block ( postFlushTxHashes ) ;
489
489
} ) ;
490
490
491
+ it ( 'settles on the chain tip before it starts building a block' , async ( ) => {
492
+ // this test simulates a synch happening right after the sequencer starts building a bloxk
493
+ // simulate every component being synched
494
+ const firstBlock = await L2Block . random ( 1 ) ;
495
+ const currentTip = firstBlock ;
496
+ let syncedToL2Block = { number : currentTip . number , hash : ( await currentTip . hash ( ) ) . toString ( ) } ;
497
+ worldState . status . mockImplementation ( ( ) =>
498
+ Promise . resolve ( { state : WorldStateRunningState . IDLE , syncedToL2Block } ) ,
499
+ ) ;
500
+ p2p . getStatus . mockImplementation ( ( ) => Promise . resolve ( { state : P2PClientState . IDLE , syncedToL2Block } ) ) ;
501
+ l2BlockSource . getL2Tips . mockImplementation ( ( ) =>
502
+ Promise . resolve ( {
503
+ latest : syncedToL2Block ,
504
+ proven : { number : 0 , hash : undefined } ,
505
+ finalized : { number : 0 , hash : undefined } ,
506
+ } ) ,
507
+ ) ;
508
+ l1ToL2MessageSource . getBlockNumber . mockImplementation ( ( ) => Promise . resolve ( currentTip . number ) ) ;
509
+
510
+ // simulate a synch happening right after
511
+ l2BlockSource . getBlockNumber . mockResolvedValueOnce ( currentTip . number ) ;
512
+ l2BlockSource . getBlockNumber . mockResolvedValueOnce ( currentTip . number + 1 ) ;
513
+ // now the new tip is actually block 2
514
+ l2BlockSource . getBlock . mockImplementation ( n =>
515
+ n === - 1
516
+ ? L2Block . random ( currentTip . number + 1 )
517
+ : n === currentTip . number
518
+ ? Promise . resolve ( currentTip )
519
+ : Promise . resolve ( undefined ) ,
520
+ ) ;
521
+
522
+ publisher . canProposeAtNextEthBlock . mockResolvedValueOnce ( undefined ) ;
523
+ await sequencer . doRealWork ( ) ;
524
+ expect ( publisher . enqueueProposeL2Block ) . not . toHaveBeenCalled ( ) ;
525
+ // even though the chain tip moved, the sequencer should still have tried to build a block against the old archive
526
+ // this should get caught by the rollup
527
+ expect ( publisher . canProposeAtNextEthBlock ) . toHaveBeenCalledWith ( currentTip . archive . root . toBuffer ( ) ) ;
528
+ } ) ;
529
+
491
530
it ( 'aborts building a block if the chain moves underneath it' , async ( ) => {
492
531
const tx = await makeTx ( ) ;
493
532
mockPendingTxs ( [ tx ] ) ;
0 commit comments