Skip to content

Commit fc1c1cb

Browse files
authored
Merge pull request #22739 from holiman/remove_code
core: remove old conversion to shuffle leveldb blocks into ancients
2 parents 8f94fc2 + 83375b0 commit fc1c1cb

File tree

1 file changed

+7
-56
lines changed

1 file changed

+7
-56
lines changed

core/blockchain.go

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,63 +1208,14 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
12081208
if !bc.HasHeader(block.Hash(), block.NumberU64()) {
12091209
return i, fmt.Errorf("containing header #%d [%x..] unknown", block.Number(), block.Hash().Bytes()[:4])
12101210
}
1211-
var (
1212-
start = time.Now()
1213-
logged = time.Now()
1214-
count int
1215-
)
1216-
// Migrate all ancient blocks. This can happen if someone upgrades from Geth
1217-
// 1.8.x to 1.9.x mid-fast-sync. Perhaps we can get rid of this path in the
1218-
// long term.
1219-
for {
1220-
// We can ignore the error here since light client won't hit this code path.
1221-
frozen, _ := bc.db.Ancients()
1222-
if frozen >= block.NumberU64() {
1223-
break
1224-
}
1225-
h := rawdb.ReadCanonicalHash(bc.db, frozen)
1226-
b := rawdb.ReadBlock(bc.db, h, frozen)
1227-
size += rawdb.WriteAncientBlock(bc.db, b, rawdb.ReadReceipts(bc.db, h, frozen, bc.chainConfig), rawdb.ReadTd(bc.db, h, frozen))
1228-
count += 1
1229-
1230-
// Always keep genesis block in active database.
1231-
if b.NumberU64() != 0 {
1232-
deleted = append(deleted, &numberHash{b.NumberU64(), b.Hash()})
1211+
if block.NumberU64() == 1 {
1212+
// Make sure to write the genesis into the freezer
1213+
if frozen, _ := bc.db.Ancients(); frozen == 0 {
1214+
h := rawdb.ReadCanonicalHash(bc.db, 0)
1215+
b := rawdb.ReadBlock(bc.db, h, 0)
1216+
size += rawdb.WriteAncientBlock(bc.db, b, rawdb.ReadReceipts(bc.db, h, 0, bc.chainConfig), rawdb.ReadTd(bc.db, h, 0))
1217+
log.Info("Wrote genesis to ancients")
12331218
}
1234-
if time.Since(logged) > 8*time.Second {
1235-
log.Info("Migrating ancient blocks", "count", count, "elapsed", common.PrettyDuration(time.Since(start)))
1236-
logged = time.Now()
1237-
}
1238-
// Don't collect too much in-memory, write it out every 100K blocks
1239-
if len(deleted) > 100000 {
1240-
// Sync the ancient store explicitly to ensure all data has been flushed to disk.
1241-
if err := bc.db.Sync(); err != nil {
1242-
return 0, err
1243-
}
1244-
// Wipe out canonical block data.
1245-
for _, nh := range deleted {
1246-
rawdb.DeleteBlockWithoutNumber(batch, nh.hash, nh.number)
1247-
rawdb.DeleteCanonicalHash(batch, nh.number)
1248-
}
1249-
if err := batch.Write(); err != nil {
1250-
return 0, err
1251-
}
1252-
batch.Reset()
1253-
// Wipe out side chain too.
1254-
for _, nh := range deleted {
1255-
for _, hash := range rawdb.ReadAllHashes(bc.db, nh.number) {
1256-
rawdb.DeleteBlock(batch, hash, nh.number)
1257-
}
1258-
}
1259-
if err := batch.Write(); err != nil {
1260-
return 0, err
1261-
}
1262-
batch.Reset()
1263-
deleted = deleted[0:]
1264-
}
1265-
}
1266-
if count > 0 {
1267-
log.Info("Migrated ancient blocks", "count", count, "elapsed", common.PrettyDuration(time.Since(start)))
12681219
}
12691220
// Flush data into ancient database.
12701221
size += rawdb.WriteAncientBlock(bc.db, block, receiptChain[i], bc.GetTd(block.Hash(), block.NumberU64()))

0 commit comments

Comments
 (0)