@@ -50,7 +50,7 @@ func (s *fakeSpanner) CommitSpan(ctx context.Context, _ borTypes.Span, _ []stake
5050}
5151
5252// newChainAndBorForTest centralizes common Bor + HeaderChain initialization for tests
53- func newChainAndBorForTest (t * testing.T , sp Spanner , borCfg * params.BorConfig , devFake bool , signerAddr common.Address , genesisTime uint64 ) (* core.BlockChain , * Bor ) {
53+ func newChainAndBorForTest (t * testing.T , sp Spanner , borCfg * params.BorConfig , devFake bool , signerAddr common.Address ) (* core.BlockChain , * Bor ) {
5454 cfg := & params.ChainConfig {ChainID : big .NewInt (1 ), Bor : borCfg }
5555
5656 b := & Bor {chainConfig : cfg , config : cfg .Bor , DevFakeAuthor : devFake }
@@ -76,9 +76,8 @@ func newChainAndBorForTest(t *testing.T, sp Spanner, borCfg *params.BorConfig, d
7676 if devFake && signerAddr != (common.Address {}) {
7777 b .authorizedSigner .Store (& signer {signer : signerAddr })
7878 }
79- b .parentActualTimeCache , _ = lru .New (10 )
8079
81- genspec := & core.Genesis {Config : cfg , Timestamp : genesisTime }
80+ genspec := & core.Genesis {Config : cfg }
8281 db := rawdb .NewMemoryDatabase ()
8382 _ = genspec .MustCommit (db , triedb .NewDatabase (db , triedb .HashDefaults ))
8483 chain , err := core .NewBlockChain (rawdb .NewMemoryDatabase (), genspec , b , core .DefaultConfig ())
@@ -393,7 +392,7 @@ func TestPerformSpanCheck(t *testing.T) {
393392 t .Run (c .name , func (t * testing.T ) {
394393 sp := & fakeSpanner {vals : []* valset.Validator {{Address : addr2 , VotingPower : 1 }}}
395394 borCfg := & params.BorConfig {Sprint : map [string ]uint64 {"0" : 64 }, Period : map [string ]uint64 {"0" : 2 }}
396- chain , b := newChainAndBorForTest (t , sp , borCfg , false , common.Address {}, uint64 ( time . Now (). Unix ()) )
395+ chain , b := newChainAndBorForTest (t , sp , borCfg , false , common.Address {})
397396
398397 var parents []* types.Header
399398 var parentHash common.Hash
@@ -470,7 +469,7 @@ func TestGetVeBlopSnapshot(t *testing.T) {
470469 t .Run (c .name , func (t * testing.T ) {
471470 sp := & fakeSpanner {vals : c .spVals }
472471 borCfg := & params.BorConfig {Sprint : map [string ]uint64 {"0" : 64 }, Period : map [string ]uint64 {"0" : 2 }, RioBlock : big .NewInt (0 )}
473- chain , b := newChainAndBorForTest (t , sp , borCfg , false , common.Address {}, uint64 ( time . Now (). Unix ()) )
472+ chain , b := newChainAndBorForTest (t , sp , borCfg , false , common.Address {})
474473 h := & types.Header {Number : big .NewInt (int64 (c .targetNum ))}
475474 snap , err := b .getVeBlopSnapshot (chain .HeaderChain (), h , nil , c .checkNewSpan )
476475 require .NoError (t , err )
@@ -517,7 +516,7 @@ func TestSnapshot(t *testing.T) {
517516 sp := & fakeSpanner {vals : c .spVals }
518517 // Configure RioBlock far in the future so IsRio(header.Number) == false
519518 borCfg := & params.BorConfig {Sprint : map [string ]uint64 {"0" : 64 }, Period : map [string ]uint64 {"0" : 2 }, RioBlock : big .NewInt (1_000_000 )}
520- chain , b := newChainAndBorForTest (t , sp , borCfg , false , common.Address {}, uint64 ( time . Now (). Unix ()) )
519+ chain , b := newChainAndBorForTest (t , sp , borCfg , false , common.Address {})
521520 gen := chain .HeaderChain ().GetHeaderByNumber (0 )
522521 require .NotNil (t , gen )
523522 target := & types.Header {Number : big .NewInt (1 ), ParentHash : gen .Hash ()}
@@ -591,7 +590,7 @@ func TestCustomBlockTimeValidation(t *testing.T) {
591590 Period : map [string ]uint64 {"0" : tc .consensusPeriod },
592591 RioBlock : big .NewInt (0 ), // Enable Rio from genesis
593592 }
594- chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 , uint64 ( time . Now (). Unix ()) )
593+ chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 )
595594 b .blockTime = tc .blockTime
596595
597596 // Get genesis block as parent
@@ -627,7 +626,7 @@ func TestCustomBlockTimeCalculation(t *testing.T) {
627626 Period : map [string ]uint64 {"0" : 2 },
628627 RioBlock : big .NewInt (0 ),
629628 }
630- chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 , uint64 ( time . Now (). Unix ()) )
629+ chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 )
631630 b .blockTime = 5 * time .Second
632631
633632 genesis := chain .HeaderChain ().GetHeaderByNumber (0 )
@@ -653,7 +652,7 @@ func TestCustomBlockTimeCalculation(t *testing.T) {
653652 Period : map [string ]uint64 {"0" : 2 },
654653 RioBlock : big .NewInt (0 ),
655654 }
656- chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 , uint64 ( time . Now (). Unix ()) )
655+ chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 )
657656 b .blockTime = 3 * time .Second
658657
659658 genesis := chain .HeaderChain ().GetHeaderByNumber (0 )
@@ -679,23 +678,22 @@ func TestCustomBlockTimeCalculation(t *testing.T) {
679678 Period : map [string ]uint64 {"0" : 2 },
680679 RioBlock : big .NewInt (0 ),
681680 }
682- chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 , uint64 ( time . Now (). Unix ()) )
681+ chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 )
683682 b .blockTime = 4 * time .Second
684683
685684 genesis := chain .HeaderChain ().GetHeaderByNumber (0 )
686685 require .NotNil (t , genesis )
687686 baseTime := genesis .Time
688- parentHash := genesis .Hash ()
689687
690688 if baseTime > 10 {
691- b .parentActualTimeCache . Add ( parentHash , time .Unix (int64 (baseTime - 10 ), 0 ) )
689+ b .lastMinedBlockTime = time .Unix (int64 (baseTime - 10 ), 0 )
692690 } else {
693- b .parentActualTimeCache . Add ( parentHash , time .Unix (0 , 0 ) )
691+ b .lastMinedBlockTime = time .Unix (0 , 0 )
694692 }
695693
696694 header := & types.Header {
697695 Number : big .NewInt (1 ),
698- ParentHash : parentHash ,
696+ ParentHash : genesis . Hash () ,
699697 }
700698
701699 err := b .Prepare (chain .HeaderChain (), header )
@@ -720,7 +718,7 @@ func TestCustomBlockTimeBackwardCompatibility(t *testing.T) {
720718 BackupMultiplier : map [string ]uint64 {"0" : 2 },
721719 RioBlock : big .NewInt (0 ),
722720 }
723- chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 , uint64 ( time . Now (). Unix ()) )
721+ chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 )
724722 b .blockTime = 0
725723
726724 genesis := chain .HeaderChain ().GetHeaderByNumber (0 )
@@ -738,53 +736,6 @@ func TestCustomBlockTimeBackwardCompatibility(t *testing.T) {
738736 })
739737}
740738
741- func TestCustomBlockTimeClampsToNowAlsoUpdatesActualTime (t * testing.T ) {
742- t .Parallel ()
743-
744- addr1 := common .HexToAddress ("0x1" )
745- // Force parent time far in the past so that after adding blockTime, header.Time is still < now
746- // and the "clamp to now" block triggers.
747- pastParentTime := time .Now ().Add (- 10 * time .Minute ).Unix ()
748-
749- sp := & fakeSpanner {vals : []* valset.Validator {{Address : addr1 , VotingPower : 1 }}}
750- borCfg := & params.BorConfig {
751- Sprint : map [string ]uint64 {"0" : 64 },
752- Period : map [string ]uint64 {"0" : 2 },
753- RioBlock : big .NewInt (0 ), // Rio enabled from genesis
754- }
755- chain , b := newChainAndBorForTest (t , sp , borCfg , true , addr1 , uint64 (pastParentTime ))
756-
757- // Enable custom block time (must be >= Period to avoid validation error)
758- b .blockTime = 5 * time .Second
759-
760- genesis := chain .HeaderChain ().GetHeaderByNumber (0 )
761- require .NotNil (t , genesis )
762-
763- header := & types.Header {
764- Number : big .NewInt (1 ),
765- ParentHash : genesis .Hash (),
766- }
767-
768- before := time .Now ()
769- err := b .Prepare (chain .HeaderChain (), header )
770- after := time .Now ()
771-
772- require .NoError (t , err )
773-
774- // Validate the clamp happened: header.Time should be "now-ish", not the past-derived time.
775- require .GreaterOrEqual (t , int64 (header .Time ), before .Unix (), "header.Time should be clamped up to now" )
776- require .LessOrEqual (t , int64 (header .Time ), after .Unix ()+ 1 , "header.Time should be close to now" )
777-
778- // Critical regression assertion:
779- // When custom blockTime is enabled for Rio, clamping header.Time to now must also set ActualTime = now.
780- require .False (t , header .ActualTime .IsZero (), "ActualTime should be set when blockTime > 0 and Rio is enabled" )
781- require .GreaterOrEqual (t , header .ActualTime .Unix (), before .Unix (), "ActualTime should be updated to now when clamping occurs" )
782- require .LessOrEqual (t , header .ActualTime .Unix (), after .Unix ()+ 1 , "ActualTime should be close to now when clamping occurs" )
783-
784- // Optional: since clamping sets both from the same `now`, they should match on Unix seconds.
785- require .Equal (t , int64 (header .Time ), header .ActualTime .Unix (), "header.Time and ActualTime should align after clamping" )
786- }
787-
788739func TestVerifySealRejectsOversizedDifficulty (t * testing.T ) {
789740 t .Parallel ()
790741
@@ -806,7 +757,7 @@ func TestVerifySealRejectsOversizedDifficulty(t *testing.T) {
806757 }
807758
808759 // devFake=false, we need real signatures for the sake of this test
809- chain , b := newChainAndBorForTest (t , sp , borCfg , false , common.Address {}, uint64 ( time . Now (). Unix ()) )
760+ chain , b := newChainAndBorForTest (t , sp , borCfg , false , common.Address {})
810761
811762 parent := chain .HeaderChain ().GetHeaderByNumber (0 )
812763 require .NotNil (t , parent )
0 commit comments