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

core: separated databases for block data #2227

Merged
merged 10 commits into from
Apr 18, 2024
Prev Previous commit
Next Next commit
core: fix some code conflict
  • Loading branch information
jingjunLi committed Apr 16, 2024
commit 04e273b1e0bcbfb44987b89c82bee67c2af3e29e
4 changes: 2 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1717,9 +1717,9 @@ func (bc *BlockChain) writeBlockWithoutState(block *types.Block, td *big.Int) (e
rawdb.WriteBlock(blockBatch, block)
// if cancun is enabled, here need to write sidecars too
if bc.chainConfig.IsCancun(block.Number(), block.Time()) {
rawdb.WriteBlobSidecars(batch, block.Hash(), block.NumberU64(), block.Sidecars())
rawdb.WriteBlobSidecars(blockBatch, block.Hash(), block.NumberU64(), block.Sidecars())
}
if err := batch.Write(); err != nil {
if err := blockBatch.Write(); err != nil {
log.Crit("Failed to write block into disk", "err", err)
}
return nil
Expand Down
8 changes: 6 additions & 2 deletions core/rawdb/chain_freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"math/big"
"sync"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/rlp"
Expand Down Expand Up @@ -184,6 +185,9 @@ func (f *chainFreezer) freeze(db ethdb.KeyValueStore) {
continue
}

headNum := f.readHeadNumber(db)
hash := ReadHeadBlockHash(nfdb)
head := ReadHeader(nfdb, hash, headNum)
threshold, err := f.freezeThreshold(nfdb)
if err != nil {
backoff = true
Expand All @@ -208,7 +212,7 @@ func (f *chainFreezer) freeze(db ethdb.KeyValueStore) {
last = freezerBatchLimit + first - 1
}

ancients, err := f.freezeRangeWithBlobs(nfdb, first, limit)
ancients, err := f.freezeRangeWithBlobs(nfdb, first, last)
if err != nil {
log.Error("Error in block freeze operation", "err", err)
backoff = true
Expand Down Expand Up @@ -296,7 +300,7 @@ func (f *chainFreezer) freeze(db ethdb.KeyValueStore) {
env, _ := f.freezeEnv.Load().(*ethdb.FreezerEnv)
// try prune blob data after cancun fork
if isCancun(env, head.Number, head.Time) {
f.tryPruneBlobAncientTable(env, *number)
f.tryPruneBlobAncientTable(env, headNum)
}

// Avoid database thrashing with tiny writes
Expand Down