@ -268,7 +268,6 @@ var (
StateSchemeFlag = & cli . StringFlag {
Name : "state.scheme" ,
Usage : "Scheme to use for storing ethereum state ('hash' or 'path')" ,
Value : rawdb . HashScheme ,
Category : flags . StateCategory ,
}
StateHistoryFlag = & cli . Uint64Flag {
@ -1721,15 +1720,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx . IsSet ( StateHistoryFlag . Name ) {
cfg . StateHistory = ctx . Uint64 ( StateHistoryFlag . Name )
}
// Parse state scheme, abort the process if it's not compatible.
chaindb := tryMakeReadOnlyDatabase ( ctx , stack )
scheme , err := ParseStateScheme ( ctx , chaindb )
chaindb . Close ( )
if err != nil {
Fatalf ( "%v" , err )
if ctx . IsSet ( StateSchemeFlag . Name ) {
cfg . StateScheme = ctx . String ( StateSchemeFlag . Name )
}
cfg . StateScheme = scheme
// Parse transaction history flag, if user is still using legacy config
// file with 'TxLookupLimit' configured, copy the value to 'TransactionHistory'.
if cfg . TransactionHistory == ethconfig . Defaults . TransactionHistory && cfg . TxLookupLimit != ethconfig . Defaults . TxLookupLimit {
@ -2165,7 +2158,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
if gcmode := ctx . String ( GCModeFlag . Name ) ; gcmode != "full" && gcmode != "archive" {
Fatalf ( "--%s must be either 'full' or 'archive'" , GCModeFlag . Name )
}
scheme , err := ParseStateScheme ( ctx , chainDb )
scheme , err := rawdb . ParseStateScheme ( ctx . String ( StateSchemeFlag . Name ) , chainDb )
if err != nil {
Fatalf ( "%v" , err )
}
@ -2224,47 +2217,12 @@ func MakeConsolePreloads(ctx *cli.Context) []string {
return preloads
}
// ParseStateScheme resolves scheme identifier from CLI flag. If the provided
// state scheme is not compatible with the one of persistent scheme, an error
// will be returned.
//
// - none: use the scheme consistent with persistent state, or fallback
// to hash-based scheme if state is empty.
// - hash: use hash-based scheme or error out if not compatible with
// persistent state scheme.
// - path: use path-based scheme or error out if not compatible with
// persistent state scheme.
func ParseStateScheme ( ctx * cli . Context , disk ethdb . Database ) ( string , error ) {
// If state scheme is not specified, use the scheme consistent
// with persistent state, or fallback to hash mode if database
// is empty.
stored := rawdb . ReadStateScheme ( disk )
if ! ctx . IsSet ( StateSchemeFlag . Name ) {
if stored == "" {
// use default scheme for empty database, flip it when
// path mode is chosen as default
log . Info ( "State schema set to default" , "scheme" , "hash" )
return rawdb . HashScheme , nil
}
log . Info ( "State scheme set to already existing" , "scheme" , stored )
return stored , nil // reuse scheme of persistent scheme
}
// If state scheme is specified, ensure it's compatible with
// persistent state.
scheme := ctx . String ( StateSchemeFlag . Name )
if stored == "" || scheme == stored {
log . Info ( "State scheme set by user" , "scheme" , scheme )
return scheme , nil
}
return "" , fmt . Errorf ( "incompatible state scheme, stored: %s, provided: %s" , stored , scheme )
}
// MakeTrieDatabase constructs a trie database based on the configured scheme.
func MakeTrieDatabase ( ctx * cli . Context , disk ethdb . Database , preimage bool , readOnly bool ) * trie . Database {
config := & trie . Config {
Preimages : preimage ,
}
scheme , err := ParseStateScheme ( ctx , disk )
scheme , err := rawdb . ParseStateScheme ( ctx . String ( StateSchemeFlag . Name ) , disk )
if err != nil {
Fatalf ( "%v" , err )
}