@@ -30,14 +30,17 @@ import (
30
30
31
31
"github.com/ethereum/go-ethereum/cmd/utils"
32
32
"github.com/ethereum/go-ethereum/common"
33
+ "github.com/ethereum/go-ethereum/core"
33
34
"github.com/ethereum/go-ethereum/core/rawdb"
34
35
"github.com/ethereum/go-ethereum/core/state"
35
36
"github.com/ethereum/go-ethereum/core/state/pruner"
36
37
"github.com/ethereum/go-ethereum/core/state/snapshot"
37
38
"github.com/ethereum/go-ethereum/core/types"
38
39
"github.com/ethereum/go-ethereum/crypto"
40
+ "github.com/ethereum/go-ethereum/eth/ethconfig"
39
41
"github.com/ethereum/go-ethereum/ethdb"
40
42
"github.com/ethereum/go-ethereum/log"
43
+ "github.com/ethereum/go-ethereum/metrics"
41
44
"github.com/ethereum/go-ethereum/node"
42
45
"github.com/ethereum/go-ethereum/rlp"
43
46
"github.com/ethereum/go-ethereum/trie"
@@ -133,6 +136,32 @@ geth snapshot verify-state <state-root>
133
136
will traverse the whole accounts and storages set based on the specified
134
137
snapshot and recalculate the root hash of state for verification.
135
138
In other words, this command does the snapshot to trie conversion.
139
+ ` ,
140
+ },
141
+ {
142
+ Name : "insecure-prune-all" ,
143
+ Usage : "Prune all trie state data except genesis block, it will break storage for fullnode, only suitable for fast node " +
144
+ "who do not need trie storage at all" ,
145
+ ArgsUsage : "<genesisPath>" ,
146
+ Action : utils .MigrateFlags (pruneAllState ),
147
+ Category : "MISCELLANEOUS COMMANDS" ,
148
+ Flags : []cli.Flag {
149
+ utils .DataDirFlag ,
150
+ utils .AncientFlag ,
151
+ utils .RopstenFlag ,
152
+ utils .RinkebyFlag ,
153
+ utils .GoerliFlag ,
154
+ },
155
+ Description : `
156
+ will prune all historical trie state data except genesis block.
157
+ All trie nodes will be deleted from the database.
158
+
159
+ It expects the genesis file as argument.
160
+
161
+ WARNING: It's necessary to delete the trie clean cache after the pruning.
162
+ If you specify another directory for the trie clean cache via "--cache.trie.journal"
163
+ during the use of Geth, please also specify it here for correct deletion. Otherwise
164
+ the trie clean cache with default directory will be deleted.
136
165
` ,
137
166
},
138
167
{
@@ -228,7 +257,7 @@ func accessDb(ctx *cli.Context, stack *node.Node) (ethdb.Database, error) {
228
257
}
229
258
headHeader := headBlock .Header ()
230
259
//Make sure the MPT and snapshot matches before pruning, otherwise the node can not start.
231
- snaptree , err := snapshot .New (chaindb , trie .NewDatabase (chaindb ), 256 , TriesInMemory , headBlock .Root (), false , false , false )
260
+ snaptree , err := snapshot .New (chaindb , trie .NewDatabase (chaindb ), 256 , TriesInMemory , headBlock .Root (), false , false , false , false )
232
261
if err != nil {
233
262
log .Error ("snaptree error" , "err" , err )
234
263
return nil , err // The relevant snapshot(s) might not exist
@@ -396,6 +425,48 @@ func pruneState(ctx *cli.Context) error {
396
425
return nil
397
426
}
398
427
428
+ func pruneAllState (ctx * cli.Context ) error {
429
+ stack , _ := makeConfigNode (ctx )
430
+ defer stack .Close ()
431
+
432
+ genesisPath := ctx .Args ().First ()
433
+ if len (genesisPath ) == 0 {
434
+ utils .Fatalf ("Must supply path to genesis JSON file" )
435
+ }
436
+ file , err := os .Open (genesisPath )
437
+ if err != nil {
438
+ utils .Fatalf ("Failed to read genesis file: %v" , err )
439
+ }
440
+ defer file .Close ()
441
+
442
+ g := new (core.Genesis )
443
+ if err := json .NewDecoder (file ).Decode (g ); err != nil {
444
+ cfg := gethConfig {
445
+ Eth : ethconfig .Defaults ,
446
+ Node : defaultNodeConfig (),
447
+ Metrics : metrics .DefaultConfig ,
448
+ }
449
+
450
+ // Load config file.
451
+ if err := loadConfig (genesisPath , & cfg ); err != nil {
452
+ utils .Fatalf ("%v" , err )
453
+ }
454
+ g = cfg .Eth .Genesis
455
+ }
456
+
457
+ chaindb := utils .MakeChainDatabase (ctx , stack , false , false )
458
+ pruner , err := pruner .NewAllPruner (chaindb )
459
+ if err != nil {
460
+ log .Error ("Failed to open snapshot tree" , "err" , err )
461
+ return err
462
+ }
463
+ if err = pruner .PruneAll (g ); err != nil {
464
+ log .Error ("Failed to prune state" , "err" , err )
465
+ return err
466
+ }
467
+ return nil
468
+ }
469
+
399
470
func verifyState (ctx * cli.Context ) error {
400
471
stack , _ := makeConfigNode (ctx )
401
472
defer stack .Close ()
@@ -406,7 +477,7 @@ func verifyState(ctx *cli.Context) error {
406
477
log .Error ("Failed to load head block" )
407
478
return errors .New ("no head block" )
408
479
}
409
- snaptree , err := snapshot .New (chaindb , trie .NewDatabase (chaindb ), 256 , 128 , headBlock .Root (), false , false , false )
480
+ snaptree , err := snapshot .New (chaindb , trie .NewDatabase (chaindb ), 256 , 128 , headBlock .Root (), false , false , false , false )
410
481
if err != nil {
411
482
log .Error ("Failed to open snapshot tree" , "err" , err )
412
483
return err
@@ -658,7 +729,7 @@ func dumpState(ctx *cli.Context) error {
658
729
return err
659
730
}
660
731
triesInMemory := ctx .GlobalUint64 (utils .TriesInMemoryFlag .Name )
661
- snaptree , err := snapshot .New (db , trie .NewDatabase (db ), int (triesInMemory ), 256 , root , false , false , false )
732
+ snaptree , err := snapshot .New (db , trie .NewDatabase (db ), int (triesInMemory ), 256 , root , false , false , false , false )
662
733
if err != nil {
663
734
return err
664
735
}
0 commit comments