@@ -68,27 +68,27 @@ func New(dataDir string) (*Database, error) {
68
68
return nil , fmt .Errorf ("failed to open PebbleDB: %w" , err )
69
69
}
70
70
71
- pruneHeight , err := getPruneHeight (db )
71
+ earliestVersion , err := getEarliestVersion (db )
72
72
if err != nil {
73
- return nil , fmt .Errorf ("failed to get prune height : %w" , err )
73
+ return nil , fmt .Errorf ("failed to get the earliest version : %w" , err )
74
74
}
75
75
76
76
return & Database {
77
77
storage : db ,
78
- earliestVersion : pruneHeight + 1 ,
78
+ earliestVersion : earliestVersion ,
79
79
sync : true ,
80
80
}, nil
81
81
}
82
82
83
83
func NewWithDB (storage * pebble.DB , sync bool ) * Database {
84
- pruneHeight , err := getPruneHeight (storage )
84
+ earliestVersion , err := getEarliestVersion (storage )
85
85
if err != nil {
86
- panic (fmt .Errorf ("failed to get prune height : %w" , err ))
86
+ panic (fmt .Errorf ("failed to get the earliest version : %w" , err ))
87
87
}
88
88
89
89
return & Database {
90
90
storage : storage ,
91
- earliestVersion : pruneHeight + 1 ,
91
+ earliestVersion : earliestVersion ,
92
92
sync : sync ,
93
93
}
94
94
}
@@ -362,7 +362,10 @@ func prependStoreKey(storeKey, key []byte) []byte {
362
362
return []byte (fmt .Sprintf ("%s%s" , storePrefix (storeKey ), key ))
363
363
}
364
364
365
- func getPruneHeight (storage * pebble.DB ) (uint64 , error ) {
365
+ // getEarliestVersion returns the earliest version set in the database.
366
+ // It is calculated by prune height + 1. If the prune height is not set, it
367
+ // returns 0.
368
+ func getEarliestVersion (storage * pebble.DB ) (uint64 , error ) {
366
369
bz , closer , err := storage .Get ([]byte (pruneHeightKey ))
367
370
if err != nil {
368
371
if errors .Is (err , pebble .ErrNotFound ) {
@@ -377,7 +380,7 @@ func getPruneHeight(storage *pebble.DB) (uint64, error) {
377
380
return 0 , closer .Close ()
378
381
}
379
382
380
- return binary .LittleEndian .Uint64 (bz ), closer .Close ()
383
+ return binary .LittleEndian .Uint64 (bz ) + 1 , closer .Close ()
381
384
}
382
385
383
386
func valTombstoned (value []byte ) bool {
0 commit comments