Skip to content

Commit 675d10f

Browse files
committed
Only considers finalized block in freeze threshold computation
1 parent ac98f8a commit 675d10f

File tree

1 file changed

+4
-32
lines changed

1 file changed

+4
-32
lines changed

core/rawdb/chain_freezer.go

+4-32
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/ethereum/go-ethereum/common"
2626
"github.com/ethereum/go-ethereum/ethdb"
2727
"github.com/ethereum/go-ethereum/log"
28-
"github.com/ethereum/go-ethereum/params"
2928
)
3029

3130
const (
@@ -87,22 +86,6 @@ func (f *chainFreezer) Close() error {
8786
return f.AncientStore.Close()
8887
}
8988

90-
// readHeadNumber returns the number of chain head block. 0 is returned if the
91-
// block is unknown or not available yet.
92-
func (f *chainFreezer) readHeadNumber(db ethdb.KeyValueReader) uint64 {
93-
hash := ReadHeadBlockHash(db)
94-
if hash == (common.Hash{}) {
95-
log.Error("Head block is not reachable")
96-
return 0
97-
}
98-
number := ReadHeaderNumber(db, hash)
99-
if number == nil {
100-
log.Error("Number of head block is missing")
101-
return 0
102-
}
103-
return *number
104-
}
105-
10689
// readFinalizedNumber returns the number of finalized block. 0 is returned
10790
// if the block is unknown or not available yet.
10891
func (f *chainFreezer) readFinalizedNumber(db ethdb.KeyValueReader) uint64 {
@@ -118,24 +101,13 @@ func (f *chainFreezer) readFinalizedNumber(db ethdb.KeyValueReader) uint64 {
118101
return *number
119102
}
120103

121-
// freezeThreshold returns the threshold for chain freezing. It's determined
122-
// by formula: max(finality, HEAD-params.FullImmutabilityThreshold).
104+
// freezeThreshold returns the threshold for chain freezing.
123105
func (f *chainFreezer) freezeThreshold(db ethdb.KeyValueReader) (uint64, error) {
124-
var (
125-
head = f.readHeadNumber(db)
126-
final = f.readFinalizedNumber(db)
127-
headLimit uint64
128-
)
129-
if head > params.FullImmutabilityThreshold {
130-
headLimit = head - params.FullImmutabilityThreshold
131-
}
132-
if final == 0 && headLimit == 0 {
106+
final := f.readFinalizedNumber(db)
107+
if final == 0 {
133108
return 0, errors.New("freezing threshold is not available")
134109
}
135-
if final > headLimit {
136-
return final, nil
137-
}
138-
return headLimit, nil
110+
return final, nil
139111
}
140112

141113
// freeze is a background thread that periodically checks the blockchain for any

0 commit comments

Comments
 (0)