@@ -787,7 +787,7 @@ func freezerMigrate(ctx *cli.Context) error {
787787 return nil
788788 }
789789
790- isFirstLegacy , firstIdx , err := dbHasLegacyReceipts (db )
790+ isFirstLegacy , firstIdx , err := dbHasLegacyReceipts (db , 0 )
791791 if err != nil {
792792 return err
793793 }
@@ -812,7 +812,7 @@ func freezerMigrate(ctx *cli.Context) error {
812812// dbHasLegacyReceipts checks freezer entries for legacy receipts. It stops at the first
813813// non-empty receipt and checks its format. The index of this first non-empty element is
814814// the second return parameter.
815- func dbHasLegacyReceipts (db ethdb.Database ) (bool , uint64 , error ) {
815+ func dbHasLegacyReceipts (db ethdb.Database , firstIdx uint64 ) (bool , uint64 , error ) {
816816 // Check first block for legacy receipt format
817817 numAncients , err := db .Ancients ()
818818 if err != nil {
@@ -821,24 +821,29 @@ func dbHasLegacyReceipts(db ethdb.Database) (bool, uint64, error) {
821821 if numAncients < 1 {
822822 return false , 0 , nil
823823 }
824+ if firstIdx >= numAncients {
825+ return false , firstIdx , nil
826+ }
824827 var (
825828 legacy bool
826- firstIdx uint64
827829 blob []byte
828830 emptyRLPList = []byte {192 }
829831 )
830- // Find first block with non-empty receipt
831- for i := uint64 (0 ); i < numAncients ; i ++ {
832- blob , err = db .Ancient ("receipts" , i )
833- if err != nil {
834- return false , 0 , err
835- }
836- if len (blob ) == 0 {
837- continue
838- }
839- if ! bytes .Equal (blob , emptyRLPList ) {
840- firstIdx = i
841- break
832+ // Find first block with non-empty receipt, only if
833+ // the index is not already provided.
834+ if firstIdx == 0 {
835+ for i := uint64 (0 ); i < numAncients ; i ++ {
836+ blob , err = db .Ancient ("receipts" , i )
837+ if err != nil {
838+ return false , 0 , err
839+ }
840+ if len (blob ) == 0 {
841+ continue
842+ }
843+ if ! bytes .Equal (blob , emptyRLPList ) {
844+ firstIdx = i
845+ break
846+ }
842847 }
843848 }
844849 // Is first non-empty receipt legacy?
0 commit comments