Skip to content

Commit

Permalink
Merge pull request #186 from binance-chain/upgrade_tmp
Browse files Browse the repository at this point in the history
[R4R] make prune tool available
  • Loading branch information
unclezoro authored May 6, 2021
2 parents 2605189 + b37e445 commit 0316072
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta
// Pruning is done, now drop the "useless" layers from the snapshot.
// Firstly, flushing the target layer into the disk. After that all
// diff layers below the target will all be merged into the disk.
if err := snaptree.Cap(root, 0); err != nil {
return err
if root != snaptree.DiskRoot() {
if err := snaptree.Cap(root, 0); err != nil {
return err
}
}
// Secondly, flushing the snapshot journal into the disk. All diff
// layers upon are dropped silently. Eventually the entire snapshot
Expand Down Expand Up @@ -275,18 +277,25 @@ func (p *Pruner) Prune(root common.Hash) error {
// bottom-most diff layer. Try to find the bottom-most snapshot
// layer with state available.
//
// Note HEAD and HEAD-1 is ignored. Usually there is the associated
// Note HEAD is ignored. Usually there is the associated
// state available, but we don't want to use the topmost state
// as the pruning target.
var found bool
for i := len(layers) - 2; i >= 2; i-- {
for i := len(layers) - 2; i >= 1; i-- {
if blob := rawdb.ReadTrieNode(p.db, layers[i].Root()); len(blob) != 0 {
root = layers[i].Root()
found = true
log.Info("Selecting middle-layer as the pruning target", "root", root, "depth", i)
break
}
}
if !found {
if blob := rawdb.ReadTrieNode(p.db, p.snaptree.DiskRoot()); len(blob) != 0 {
root = p.snaptree.DiskRoot()
found = true
log.Info("Selecting disk-layer as the pruning target", "root", root)
}
}
if !found {
if len(layers) > 0 {
return errors.New("no snapshot paired state")
Expand Down
3 changes: 3 additions & 0 deletions core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func New(diskdb ethdb.KeyValueStore, triedb *trie.Database, cache int, root comm
snap.layers[head.Root()] = head
head = head.Parent()
}
log.Info("Snapshot loaded", "diskRoot", snap.diskRoot(), "root", root)
return snap, nil
}

Expand Down Expand Up @@ -343,6 +344,7 @@ func (t *Tree) Update(blockRoot common.Hash, parentRoot common.Hash, destructs m
defer t.lock.Unlock()

t.layers[snap.root] = snap
log.Info("Snapshot updated", "blockRoot", blockRoot)
return nil
}

Expand Down Expand Up @@ -425,6 +427,7 @@ func (t *Tree) Cap(root common.Hash, layers int) error {
}
rebloom(persisted.root)
}
log.Debug("Snapshot capped", "root", root)
return nil
}

Expand Down
3 changes: 0 additions & 3 deletions les/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,6 @@ func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, ge
if server.config.UltraLightOnlyAnnounce {
recentTx = txIndexDisabled
}
if recentTx != txIndexUnlimited && p.version < lpv4 {
return errors.New("Cannot serve old clients without a complete tx index")
}
// Note: clientPeer.headInfo should contain the last head announced to the client by us.
// The values announced in the handshake are dummy values for compatibility reasons and should be ignored.
p.headInfo = blockInfo{Hash: head, Number: headNum, Td: td}
Expand Down

0 comments on commit 0316072

Please sign in to comment.