Skip to content

Commit e08d82f

Browse files
committed
speed-up hack for mainnet
1 parent 0b14470 commit e08d82f

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

cmd/geth/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
164164
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
165165
// Warn users to migrate if they have a legacy freezer format.
166166
if eth != nil {
167-
isLegacy, _, err := dbHasLegacyReceipts(eth.ChainDb())
167+
firstIdx := uint64(0)
168+
// Hack to speed up check for mainnet because we know
169+
// the first non-empty block.
170+
if ctx.GlobalIsSet(utils.MainnetFlag.Name) {
171+
firstIdx = 46147
172+
}
173+
isLegacy, _, err := dbHasLegacyReceipts(eth.ChainDb(), firstIdx)
168174
if err != nil {
169175
utils.Fatalf("Failed to check db for legacy receipts: %v", err)
170176
}

cmd/geth/dbcmd.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)