Skip to content

Commit 2787328

Browse files
committed
core/rawdb, eth, les: fix review concerns
1 parent 79a943f commit 2787328

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

core/rawdb/accessors_metadata.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
func ReadDatabaseVersion(db ethdb.KeyValueReader) *uint64 {
3232
var version uint64
3333

34-
enc, _ := db.Get(databaseVerisionKey)
34+
enc, _ := db.Get(databaseVersionKey)
3535
if len(enc) == 0 {
3636
return nil
3737
}
@@ -48,7 +48,7 @@ func WriteDatabaseVersion(db ethdb.KeyValueWriter, version uint64) {
4848
if err != nil {
4949
log.Crit("Failed to encode database version", "err", err)
5050
}
51-
if err = db.Put(databaseVerisionKey, enc); err != nil {
51+
if err = db.Put(databaseVersionKey, enc); err != nil {
5252
log.Crit("Failed to store the database version", "err", err)
5353
}
5454
}
@@ -81,22 +81,24 @@ func WriteChainConfig(db ethdb.KeyValueWriter, hash common.Hash, cfg *params.Cha
8181
}
8282
}
8383

84-
// ucmList is a list of unclean-shutdown-markers, for rlp-encoding to the
84+
// crashList is a list of unclean-shutdown-markers, for rlp-encoding to the
8585
// database
86-
type ucmList struct {
86+
type crashList struct {
8787
Discarded uint64 // how many ucs have we deleted
8888
Recent []uint64 // unix timestamps of 10 latest unclean shutdowns
8989
}
9090

91-
// UpdateUncleanShutdownMarker appends a new unclean shutdown marker and returns
91+
const crashesToKeep = 10
92+
93+
// PushUncleanShutdownMarker appends a new unclean shutdown marker and returns
9294
// the previous data
9395
// - a list of timestamps
9496
// - a count of how many old unclean-shutdowns have been discarded
95-
func UpdateUncleanShutdownMarker(db ethdb.KeyValueStore) ([]uint64, uint64, error) {
96-
var uncleanShutdowns ucmList
97+
func PushUncleanShutdownMarker(db ethdb.KeyValueStore) ([]uint64, uint64, error) {
98+
var uncleanShutdowns crashList
9799
// Read old data
98100
if data, err := db.Get(uncleanShutdownKey); err != nil {
99-
log.Warn("Error reading USM", "error", err)
101+
log.Warn("Error reading unclean shutdown markers", "error", err)
100102
} else if err := rlp.DecodeBytes(data, &uncleanShutdowns); err != nil {
101103
return nil, 0, err
102104
}
@@ -105,8 +107,8 @@ func UpdateUncleanShutdownMarker(db ethdb.KeyValueStore) ([]uint64, uint64, erro
105107
copy(previous, uncleanShutdowns.Recent)
106108
// Add a new (but cap it)
107109
uncleanShutdowns.Recent = append(uncleanShutdowns.Recent, uint64(time.Now().Unix()))
108-
if l := len(uncleanShutdowns.Recent); l > 11 {
109-
uncleanShutdowns.Recent = uncleanShutdowns.Recent[l-11:]
110+
if l := len(uncleanShutdowns.Recent); l > crashesToKeep+1 {
111+
uncleanShutdowns.Recent = uncleanShutdowns.Recent[l-crashesToKeep-1:]
110112
uncleanShutdowns.Discarded++
111113
}
112114
// And save it again
@@ -118,14 +120,14 @@ func UpdateUncleanShutdownMarker(db ethdb.KeyValueStore) ([]uint64, uint64, erro
118120
return previous, discarded, nil
119121
}
120122

121-
// ClearUncleanShutdowMarker removes the last unclean shutdown marker
122-
func ClearUncleanShutdowMarker(db ethdb.KeyValueStore) {
123-
var uncleanShutdowns ucmList
123+
// PopUncleanShutdownMarker removes the last unclean shutdown marker
124+
func PopUncleanShutdownMarker(db ethdb.KeyValueStore) {
125+
var uncleanShutdowns crashList
124126
// Read old data
125127
if data, err := db.Get(uncleanShutdownKey); err != nil {
126-
log.Warn("Error reading USM", "error", err)
128+
log.Warn("Error reading unclean shutdown markers", "error", err)
127129
} else if err := rlp.DecodeBytes(data, &uncleanShutdowns); err != nil {
128-
log.Error("Error reading USM", "error", err) // Should mos def _not_ happen
130+
log.Error("Error decoding unclean shutdown markers", "error", err) // Should mos def _not_ happen
129131
}
130132
if l := len(uncleanShutdowns.Recent); l > 0 {
131133
uncleanShutdowns.Recent = uncleanShutdowns.Recent[:l-1]

core/rawdb/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func InspectDatabase(db ethdb.Database) error {
355355
bloomTrieNodes.Add(size)
356356
default:
357357
var accounted bool
358-
for _, meta := range [][]byte{databaseVerisionKey, headHeaderKey, headBlockKey, headFastBlockKey, fastTrieProgressKey} {
358+
for _, meta := range [][]byte{databaseVersionKey, headHeaderKey, headBlockKey, headFastBlockKey, fastTrieProgressKey, uncleanShutdownKey} {
359359
if bytes.Equal(key, meta) {
360360
metadata.Add(size)
361361
accounted = true

core/rawdb/schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727

2828
// The fields below define the low level database schema prefixing.
2929
var (
30-
// databaseVerisionKey tracks the current database version.
31-
databaseVerisionKey = []byte("DatabaseVersion")
30+
// databaseVersionKey tracks the current database version.
31+
databaseVersionKey = []byte("DatabaseVersion")
3232

3333
// headHeaderKey tracks the latest known header's hash.
3434
headHeaderKey = []byte("LastHeader")

eth/backend.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ func New(stack *node.Node, config *Config) (*Ethereum, error) {
222222
stack.RegisterProtocols(eth.Protocols())
223223
stack.RegisterLifecycle(eth)
224224
// Check for unclean shutdown
225-
if uncleanShutdowns, discards, err := rawdb.UpdateUncleanShutdownMarker(chainDb); err != nil {
225+
if uncleanShutdowns, discards, err := rawdb.PushUncleanShutdownMarker(chainDb); err != nil {
226226
log.Error("Could not update unclean-shutdown-marker list", "error", err)
227227
} else {
228228
if discards > 0 {
229229
log.Warn("Old unclean shutdowns found", "count", discards)
230230
}
231231
for _, tstamp := range uncleanShutdowns {
232232
t := time.Unix(int64(tstamp), 0)
233-
log.Warn("Unclean shutdown detected", "time", t,
233+
log.Warn("Unclean shutdown detected", "booted", t,
234234
"age", common.PrettyAge(t))
235235
}
236236
}
@@ -557,7 +557,7 @@ func (s *Ethereum) Stop() error {
557557
s.miner.Stop()
558558
s.blockchain.Stop()
559559
s.engine.Close()
560-
rawdb.ClearUncleanShutdowMarker(s.chainDb)
560+
rawdb.PopUncleanShutdownMarker(s.chainDb)
561561
s.chainDb.Close()
562562
s.eventMux.Stop()
563563
return nil

les/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ func New(stack *node.Node, config *eth.Config) (*LightEthereum, error) {
179179
stack.RegisterLifecycle(leth)
180180

181181
// Check for unclean shutdown
182-
if uncleanShutdowns, discards, err := rawdb.UpdateUncleanShutdownMarker(chainDb); err != nil {
182+
if uncleanShutdowns, discards, err := rawdb.PushUncleanShutdownMarker(chainDb); err != nil {
183183
log.Error("Could not update unclean-shutdown-marker list", "error", err)
184184
} else {
185185
if discards > 0 {
186186
log.Warn("Old unclean shutdowns found", "count", discards)
187187
}
188188
for _, tstamp := range uncleanShutdowns {
189189
t := time.Unix(int64(tstamp), 0)
190-
log.Warn("Unclean shutdown detected", "time", t,
190+
log.Warn("Unclean shutdown detected", "booted", t,
191191
"age", common.PrettyAge(t))
192192
}
193193
}
@@ -326,7 +326,7 @@ func (s *LightEthereum) Stop() error {
326326
s.engine.Close()
327327
s.pruner.close()
328328
s.eventMux.Stop()
329-
rawdb.ClearUncleanShutdowMarker(s.chainDb)
329+
rawdb.PopUncleanShutdownMarker(s.chainDb)
330330
s.chainDb.Close()
331331
s.wg.Wait()
332332
log.Info("Light ethereum stopped")

0 commit comments

Comments
 (0)