Prechádzať zdrojové kódy

Merge pull request #186 from binance-chain/upgrade_tmp

[R4R] make prune tool available
zjubfd 4 rokov pred
rodič
commit
031607200a

+ 13 - 4
core/state/pruner/pruner.go

@@ -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
@@ -275,11 +277,11 @@ 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
@@ -287,6 +289,13 @@ func (p *Pruner) Prune(root common.Hash) error {
 				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")

+ 3 - 0
core/state/snapshot/snapshot.go

@@ -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
 }
 
@@ -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
 }
 
@@ -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
 }
 

+ 0 - 3
les/peer.go

@@ -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}