Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R]fix: tools broken because of writting metadata when open a readyonly db #1013

Merged
merged 3 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/rawdb/accessors_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func ReadOffSetOfCurrentAncientFreezer(db ethdb.KeyValueReader) uint64 {
// WriteOffSetOfCurrentAncientFreezer write prune block start
func WriteOffSetOfCurrentAncientFreezer(db ethdb.KeyValueWriter, offset uint64) {
if err := db.Put(offSetOfCurrentAncientFreezer, new(big.Int).SetUint64(offset).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store the current offset of ancient", "err", err)
}
}

Expand All @@ -209,7 +209,7 @@ func ReadOffSetOfLastAncientFreezer(db ethdb.KeyValueReader) uint64 {
// WriteOffSetOfLastAncientFreezer wirte before prune block start
func WriteOffSetOfLastAncientFreezer(db ethdb.KeyValueWriter, offset uint64) {
if err := db.Put(offSetOfLastAncientFreezer, new(big.Int).SetUint64(offset).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store the old offset of ancient", "err", err)
}
}

Expand All @@ -225,7 +225,7 @@ func ReadFrozenOfAncientFreezer(db ethdb.KeyValueReader) uint64 {
// WriteFrozenOfAncientFreezer write freezer block number
func WriteFrozenOfAncientFreezer(db ethdb.KeyValueWriter, frozen uint64) {
if err := db.Put(frozenOfAncientDBKey, new(big.Int).SetUint64(frozen).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store the ancient frozen number", "err", err)
}
}

Expand All @@ -241,7 +241,7 @@ func ReadSafePointBlockNumber(db ethdb.KeyValueReader) uint64 {
// WriteSafePointBlockNumber write the number of block that roothash save to disk
func WriteSafePointBlockNumber(db ethdb.KeyValueWriter, number uint64) {
if err := db.Put(LastSafePointBlockKey, new(big.Int).SetUint64(number).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store safe point of block number", "err", err)
}
}

Expand All @@ -257,6 +257,6 @@ func ReadAncientType(db ethdb.KeyValueReader) uint64 {
// WriteAncientType write freezer type
func WriteAncientType(db ethdb.KeyValueWriter, flag uint64) {
if err := db.Put(pruneAncientKey, new(big.Int).SetUint64(flag).Bytes()); err != nil {
log.Crit("Failed to store offSetOfAncientFreezer", "err", err)
log.Crit("Failed to store prune ancient type", "err", err)
}
}
8 changes: 6 additions & 2 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace st
}

go frdb.freeze()
WriteAncientType(db, PruneFreezerType)
if !readonly {
WriteAncientType(db, PruneFreezerType)
}
return &freezerdb{
KeyValueStore: db,
AncientStore: frdb,
Expand Down Expand Up @@ -296,7 +298,9 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace st
}
}
// no prune ancinet start success
WriteAncientType(db, EntireFreezerType)
if !readonly {
WriteAncientType(db, EntireFreezerType)
}
// Freezer is consistent with the key-value database, permit combining the two
if !disableFreeze && !frdb.readonly {
frdb.wg.Add(1)
Expand Down