Skip to content

Commit

Permalink
speed-up hack for mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Mar 17, 2022
1 parent 0b14470 commit e08d82f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
8 changes: 7 additions & 1 deletion cmd/geth/config.go
Expand Up @@ -164,7 +164,13 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
// Warn users to migrate if they have a legacy freezer format.
if eth != nil {
isLegacy, _, err := dbHasLegacyReceipts(eth.ChainDb())
firstIdx := uint64(0)
// Hack to speed up check for mainnet because we know
// the first non-empty block.
if ctx.GlobalIsSet(utils.MainnetFlag.Name) {
firstIdx = 46147
}
isLegacy, _, err := dbHasLegacyReceipts(eth.ChainDb(), firstIdx)
if err != nil {
utils.Fatalf("Failed to check db for legacy receipts: %v", err)
}
Expand Down
35 changes: 20 additions & 15 deletions cmd/geth/dbcmd.go
Expand Up @@ -787,7 +787,7 @@ func freezerMigrate(ctx *cli.Context) error {
return nil
}

isFirstLegacy, firstIdx, err := dbHasLegacyReceipts(db)
isFirstLegacy, firstIdx, err := dbHasLegacyReceipts(db, 0)
if err != nil {
return err
}
Expand All @@ -812,7 +812,7 @@ func freezerMigrate(ctx *cli.Context) error {
// dbHasLegacyReceipts checks freezer entries for legacy receipts. It stops at the first
// non-empty receipt and checks its format. The index of this first non-empty element is
// the second return parameter.
func dbHasLegacyReceipts(db ethdb.Database) (bool, uint64, error) {
func dbHasLegacyReceipts(db ethdb.Database, firstIdx uint64) (bool, uint64, error) {
// Check first block for legacy receipt format
numAncients, err := db.Ancients()
if err != nil {
Expand All @@ -821,24 +821,29 @@ func dbHasLegacyReceipts(db ethdb.Database) (bool, uint64, error) {
if numAncients < 1 {
return false, 0, nil
}
if firstIdx >= numAncients {
return false, firstIdx, nil
}
var (
legacy bool
firstIdx uint64
blob []byte
emptyRLPList = []byte{192}
)
// Find first block with non-empty receipt
for i := uint64(0); i < numAncients; i++ {
blob, err = db.Ancient("receipts", i)
if err != nil {
return false, 0, err
}
if len(blob) == 0 {
continue
}
if !bytes.Equal(blob, emptyRLPList) {
firstIdx = i
break
// Find first block with non-empty receipt, only if
// the index is not already provided.
if firstIdx == 0 {
for i := uint64(0); i < numAncients; i++ {
blob, err = db.Ancient("receipts", i)
if err != nil {
return false, 0, err
}
if len(blob) == 0 {
continue
}
if !bytes.Equal(blob, emptyRLPList) {
firstIdx = i
break
}
}
}
// Is first non-empty receipt legacy?
Expand Down

0 comments on commit e08d82f

Please sign in to comment.