Skip to content
Merged
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
24 changes: 21 additions & 3 deletions core/rawdb/chain_freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ const (
// storage.
freezerRecheckInterval = time.Minute

// freezerBatchLimit is the maximum number of blocks to freeze in one batch
// before doing an fsync and deleting it from the key-value store.
// TODO(galaio): For BSC, the 0.75 interval and freezing of 30,000 blocks will seriously affect performance.
// It is temporarily adjusted to 100, and improves the freezing performance later.
freezerBatchLimit = 100
SlowFreezerBatchLimit = 100
SlowdownFreezeWindow = 24 * time.Hour
)

var (
// freezerBatchLimit is the maximum number of blocks to freeze in one batch
// before doing an fsync and deleting it from the key-value store.
freezerBatchLimit uint64 = 30000
)

var (
Expand Down Expand Up @@ -268,6 +273,7 @@ func (f *chainFreezer) freeze(db ethdb.KeyValueStore, continueFreeze bool) {
backoff = true
continue
}
trySlowdownFreeze(head)

first = frozen
last = threshold
Expand Down Expand Up @@ -307,6 +313,7 @@ func (f *chainFreezer) freeze(db ethdb.KeyValueStore, continueFreeze bool) {
backoff = true
continue
}
trySlowdownFreeze(head)
first, _ = f.Ancients()
last = *number - threshold
if last-first > freezerBatchLimit {
Expand Down Expand Up @@ -735,3 +742,14 @@ func (f *chainFreezer) ResetTable(kind string, startAt uint64, onlyEmpty bool) e
func (f *chainFreezer) SyncAncient() error {
return f.ancients.SyncAncient()
}

func trySlowdownFreeze(head *types.Header) {
if time.Since(time.UnixMilli(int64(head.MilliTimestamp()))) > SlowdownFreezeWindow {
return
}
if freezerBatchLimit == SlowFreezerBatchLimit {
return
}
log.Info("Freezer need to slow down", "number", head.Number, "time", head.Time, "new", SlowFreezerBatchLimit)
freezerBatchLimit = SlowFreezerBatchLimit
}