Skip to content

Commit

Permalink
core/rawdb: return a better err for bad freezer.repair, add comments …
Browse files Browse the repository at this point in the history
…and newlines

Signed-off-by: meows <b5c6@protonmail.com>
  • Loading branch information
meowsbits committed Mar 4, 2020
1 parent 63eea3d commit 96185cf
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezerStr string, namespace
if reperr := frdb.repair(); reperr != nil {
log.Warn("Freezer repair errored", "error", reperr)

// Repair did error, and that's bad, but return the initial error.
return nil, validateErr
// Repair did error, AND the validation errored, so return both together because that's double bad.
return nil, fmt.Errorf("freezer/kv error=%v freezer repair error=%v", validateErr, reperr)
}

log.Warn("Freezer repair OK")
Expand Down Expand Up @@ -359,7 +359,6 @@ func validateFreezerVsKV(freezerdb *freezer, db ethdb.KeyValueStore) error {
// Key-value store and freezer belong to the same network. Ensure that they
// are contiguous, otherwise we might end up with a non-functional freezer.
if kvhash, _ := db.Get(headerHashKey(frozen)); len(kvhash) == 0 {

// Subsequent header after the freezer limit is missing from the database.
// Reject startup is the database has a more recent head.
if headHeaderN := *ReadHeaderNumber(db, ReadHeadHeaderHash(db)); headHeaderN > frozen-1 {
Expand All @@ -382,10 +381,10 @@ func validateFreezerVsKV(freezerdb *freezer, db ethdb.KeyValueStore) error {
if kvblob, _ := db.Get(headerHashKey(1)); len(kvblob) == 0 {
return errors.New("ancient chain segments already extracted, please set --datadir.ancient to the correct path")
}
// Block #1 is still in the database, we're allowed to init a new feezer
// Block #1 is still in the database, we're allowed to init a new freezer.
}
// Otherwise, the head header is still the genesis, we're allowed to init a new
// feezer.
// freezer.
}
}
return nil
Expand Down Expand Up @@ -432,10 +431,16 @@ func truncateKVtoFreezer(freezerdb *freezer, db ethdb.KeyValueStore) {
data, _ := freezerdb.Ancient(freezerHashTable, n)
h := common.BytesToHash(data)

// If h is the empty common hash, then when the headHeaderHash gets read, whoever's reading it isn't going to like that.
// This logic doesn't check for that because there's really nothing that can be sensibly done in this scope,
// and it seems reasonable to think that when a higher level function like `loadLastState` finds an empty hash in the
// headHeaderHash value, it's going to bark pretty loudly and probably just roll the whole thing (database(s)) back since the
// ancient database would appear to be screwy beyond repair since it lied about what frozen headers it had.
// So we're just gonna write this sucker.
log.Warn("Writing KV head header", "hash", h.String())
WriteHeadHeaderHash(db, h)

// If we had nonzero values for full and/or fast blocks, infer that preceding states will still be valid.
WriteHeadHeaderHash(db, h)
if headFast != 0 {
WriteHeadFastBlockHash(db, h)
}
Expand Down

0 comments on commit 96185cf

Please sign in to comment.