2019-11-25 13:46:36 +00:00
package commands
import (
"github.com/ledgerwatch/turbo-geth/cmd/state/stateless"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/spf13/cobra"
)
var (
2020-01-24 10:58:01 +00:00
statefile string
triesize uint32
preroot bool
snapshotInterval uint64
snapshotFrom uint64
witnessInterval uint64
noverify bool
bintries bool
starkBlocksFile string
starkStatsBase string
statelessResolver bool
witnessDatabase string
2020-03-25 20:18:46 +00:00
writeHistory bool
2020-04-12 15:41:06 +00:00
blockSource string
2019-11-25 13:46:36 +00:00
)
2020-04-14 12:49:25 +00:00
func withBlocksource ( cmd * cobra . Command ) {
cmd . Flags ( ) . StringVar ( & blockSource , "blockSource" , "" , "Path to the block source: `db:///path/to/chaindata` or `exportfile:///path/to/my/exportfile`" )
if err := cmd . MarkFlagRequired ( "blockSource" ) ; err != nil {
panic ( err )
}
}
2019-11-25 13:46:36 +00:00
func init ( ) {
withStatsfile ( statelessCmd )
withBlock ( statelessCmd )
2020-04-14 12:49:25 +00:00
withBlocksource ( statelessCmd )
2019-11-25 13:46:36 +00:00
statelessCmd . Flags ( ) . StringVar ( & statefile , "statefile" , "state" , "path to the file where the state will be periodically written during the analysis" )
2020-04-08 05:00:31 +00:00
statelessCmd . Flags ( ) . Uint32Var ( & triesize , "triesize" , 4 * 1024 * 1024 , "maximum size of a trie in bytes" )
2019-11-25 13:46:36 +00:00
statelessCmd . Flags ( ) . BoolVar ( & preroot , "preroot" , false , "Attempt to compute hash of the trie without modifying it" )
statelessCmd . Flags ( ) . Uint64Var ( & snapshotInterval , "snapshotInterval" , 0 , "how often to take snapshots (0 - never, 1 - every block, 1000 - every 1000th block, etc)" )
statelessCmd . Flags ( ) . Uint64Var ( & snapshotFrom , "snapshotFrom" , 0 , "from which block to start snapshots" )
statelessCmd . Flags ( ) . Uint64Var ( & witnessInterval , "witnessInterval" , 1 , "after which block to extract witness (put a large number like 10000000 to disable)" )
2019-11-27 13:52:22 +00:00
statelessCmd . Flags ( ) . BoolVar ( & noverify , "noVerify" , false , "skip snapshot verification on loading" )
2019-12-04 12:48:38 +00:00
statelessCmd . Flags ( ) . BoolVar ( & bintries , "bintries" , false , "use binary tries instead of hexary to generate/load block witnesses" )
2020-01-15 17:33:36 +00:00
statelessCmd . Flags ( ) . StringVar ( & starkBlocksFile , "starkBlocksFile" , "" , "file with the list of blocks for which to produce stark data" )
statelessCmd . Flags ( ) . StringVar ( & starkStatsBase , "starkStatsBase" , "stark_stats" , "template for names of the files to write stark stats in" )
2020-01-24 10:58:01 +00:00
statelessCmd . Flags ( ) . BoolVar ( & statelessResolver , "statelessResolver" , false , "use a witness DB instead of the state when resolving tries" )
statelessCmd . Flags ( ) . StringVar ( & witnessDatabase , "witnessDbFile" , "" , "optional path to a database where to store witnesses (empty string -- do not store witnesses" )
2020-03-25 20:18:46 +00:00
statelessCmd . Flags ( ) . BoolVar ( & writeHistory , "writeHistory" , false , "write history buckets and changeset buckets into the statefile" )
2020-01-24 10:58:01 +00:00
if err := statelessCmd . MarkFlagFilename ( "witnessDbFile" , "" ) ; err != nil {
panic ( err )
}
2019-11-25 13:46:36 +00:00
rootCmd . AddCommand ( statelessCmd )
}
var statelessCmd = & cobra . Command {
Use : "stateless" ,
Short : "Stateless Ethereum prototype" ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2020-07-19 08:11:53 +00:00
createDb := func ( path string ) ( * ethdb . ObjectDatabase , error ) {
2020-06-16 13:36:16 +00:00
return ethdb . Open ( path )
2019-11-25 13:46:36 +00:00
}
2020-04-04 07:18:10 +00:00
ctx := rootContext ( )
2019-11-25 13:46:36 +00:00
2019-11-27 13:52:22 +00:00
stateless . Stateless (
2020-03-25 15:40:30 +00:00
ctx ,
2019-11-27 13:52:22 +00:00
block ,
2020-04-12 15:41:06 +00:00
blockSource ,
2019-11-27 13:52:22 +00:00
statefile ,
triesize ,
preroot ,
snapshotInterval ,
snapshotFrom ,
witnessInterval ,
statsfile ,
! noverify ,
2019-12-04 12:48:38 +00:00
bintries ,
2019-11-27 13:52:22 +00:00
createDb ,
2020-01-15 17:33:36 +00:00
starkBlocksFile ,
starkStatsBase ,
2020-01-24 10:58:01 +00:00
statelessResolver ,
witnessDatabase ,
2020-03-25 20:18:46 +00:00
writeHistory ,
2019-11-27 13:52:22 +00:00
)
2019-11-25 13:46:36 +00:00
return nil
} ,
}