Skip to content

Commit 01f4ce7

Browse files
committed
WIP
1 parent 0a527a0 commit 01f4ce7

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

Diff for: cmd/geth/dbcmd.go

+5
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,11 @@ func hbss2pbss(ctx *cli.Context) error {
746746
log.Error("Prune Hash trie node in database failed", "error", err)
747747
return err
748748
}
749+
err = h2p.Compact()
750+
if err != nil {
751+
log.Error("Compact trie node failed", "error", err)
752+
return err
753+
}
749754

750755
return nil
751756
}

Diff for: core/rawdb/database.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ func PruneHashTrieNodeInDataBase(db ethdb.Database) error {
473473
it := db.NewIterator([]byte{}, []byte{})
474474
defer it.Release()
475475

476+
start := time.Now()
477+
logged := time.Now()
476478
total_num := 0
477479
for it.Next() {
478480
var key = it.Key()
@@ -481,12 +483,16 @@ func PruneHashTrieNodeInDataBase(db ethdb.Database) error {
481483
db.Delete(key)
482484
total_num++
483485
if total_num%100000 == 0 {
484-
log.Info("Pruning hash-base state trie nodes", "Complete progress: ", total_num)
486+
log.Info("Pruning hash-base state trie nodes", "Complete progress: ", total_num, "elapsed", common.PrettyDuration(time.Since(start)))
485487
}
486488
default:
489+
if time.Since(logged) > 8*time.Second {
490+
log.Info("Pruning hash-base state trie nodes", "Complete progress: ", total_num, "elapsed", common.PrettyDuration(time.Since(start)))
491+
logged = time.Now()
492+
}
487493
continue
488494
}
489495
}
490-
log.Info("Pruning hash-base state trie nodes", "Complete progress", total_num)
496+
log.Info("Pruning hash-base state trie nodes", "Complete progress", total_num, "elapsed", common.PrettyDuration(time.Since(start)))
491497
return nil
492498
}

Diff for: trie/database.go

-1
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,6 @@ func (db *Database) GetFrom(root, key []byte) ([]byte, error) {
11261126
return n, nil
11271127
}
11281128

1129-
log.Info("pathdb get node reader is nil", "root", r.Hex())
11301129
return nil, errors.New("reader is nil")
11311130
}
11321131
return nil, nil

Diff for: trie/hbss2pbss.go

+21
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ func (h2p *Hbss2Pbss) handleGenesis() error {
108108
return nil
109109
}
110110

111+
func (h2p *Hbss2Pbss) Compact() error {
112+
cstart := time.Now()
113+
for b := 0x00; b <= 0xf0; b += 0x10 {
114+
var (
115+
start = []byte{byte(b)}
116+
end = []byte{byte(b + 0x10)}
117+
)
118+
if b == 0xf0 {
119+
end = nil
120+
}
121+
log.Info("Compacting database", "range", fmt.Sprintf("%#x-%#x", start, end), "elapsed", common.PrettyDuration(time.Since(cstart)))
122+
if err := h2p.db.Compact(start, end); err != nil {
123+
log.Error("Database compaction failed", "error", err)
124+
return err
125+
}
126+
}
127+
log.Info("Database compaction finished", "elapsed", common.PrettyDuration(time.Since(cstart)))
128+
129+
return nil
130+
}
131+
111132
func (h2p *Hbss2Pbss) writeNode(pathKey []bool, n *zktrie.Node, owner common.Hash) {
112133
if owner == (common.Hash{}) {
113134
h, _ := n.NodeHash()

0 commit comments

Comments
 (0)