@@ -252,65 +252,6 @@ func upgradeSequentialBlockData(db ethdb.Database, hash []byte) error {
252252 return nil
253253}
254254
255- // upgradeChainDatabase ensures that the chain database stores block split into
256- // separate header and body entries.
257- func upgradeChainDatabase (db ethdb.Database ) error {
258- // Short circuit if the head block is stored already as separate header and body
259- data , err := db .Get ([]byte ("LastBlock" ))
260- if err != nil {
261- return nil
262- }
263- head := common .BytesToHash (data )
264-
265- if block := core .GetBlockByHashOld (db , head ); block == nil {
266- return nil
267- }
268- // At least some of the database is still the old format, upgrade (skip the head block!)
269- log .Info (fmt .Sprint ("Old database detected, upgrading..." ))
270-
271- if db , ok := db .(* ethdb.LDBDatabase ); ok {
272- blockPrefix := []byte ("block-hash-" )
273- for it := db .NewIterator (); it .Next (); {
274- // Skip anything other than a combined block
275- if ! bytes .HasPrefix (it .Key (), blockPrefix ) {
276- continue
277- }
278- // Skip the head block (merge last to signal upgrade completion)
279- if bytes .HasSuffix (it .Key (), head .Bytes ()) {
280- continue
281- }
282- // Load the block, split and serialize (order!)
283- block := core .GetBlockByHashOld (db , common .BytesToHash (bytes .TrimPrefix (it .Key (), blockPrefix )))
284-
285- if err := core .WriteTd (db , block .Hash (), block .NumberU64 (), block .DeprecatedTd ()); err != nil {
286- return err
287- }
288- if err := core .WriteBody (db , block .Hash (), block .NumberU64 (), block .Body ()); err != nil {
289- return err
290- }
291- if err := core .WriteHeader (db , block .Header ()); err != nil {
292- return err
293- }
294- if err := db .Delete (it .Key ()); err != nil {
295- return err
296- }
297- }
298- // Lastly, upgrade the head block, disabling the upgrade mechanism
299- current := core .GetBlockByHashOld (db , head )
300-
301- if err := core .WriteTd (db , current .Hash (), current .NumberU64 (), current .DeprecatedTd ()); err != nil {
302- return err
303- }
304- if err := core .WriteBody (db , current .Hash (), current .NumberU64 (), current .Body ()); err != nil {
305- return err
306- }
307- if err := core .WriteHeader (db , current .Header ()); err != nil {
308- return err
309- }
310- }
311- return nil
312- }
313-
314255func addMipmapBloomBins (db ethdb.Database ) (err error ) {
315256 const mipmapVersion uint = 2
316257
0 commit comments