Skip to content

Commit

Permalink
fix: add log
Browse files Browse the repository at this point in the history
  • Loading branch information
flywukong committed Dec 1, 2023
1 parent 1d445a8 commit c1b812c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func initGenesis(ctx *cli.Context) error {
// Open and initialise both full and light databases
stack, _ := makeConfigNode(ctx)
defer stack.Close()

stack.Config().TrieDir = ctx.String(utils.TrieDirFlag.Name)
for _, name := range []string{"chaindata", "lightchaindata"} {
chaindb, err := stack.OpenDatabaseWithFreezer(name, 0, 0, ctx.String(utils.AncientFlag.Name), "", false, false, false, false)
if err != nil {
Expand All @@ -232,7 +232,7 @@ func initGenesis(ctx *cli.Context) error {
if ctx.IsSet(utils.TrieDirFlag.Name) {
newChaindb, dbErr := stack.OpenDatabaseForTrie(name, 0, 0, "", "", false, false, false, false)
if dbErr != nil {
utils.Fatalf("Failed to open database: %v", err)
utils.Fatalf("Failed to open separate trie database: %v", dbErr)
}
defer newChaindb.Close()

Expand Down
1 change: 1 addition & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
v := ctx.Uint64(utils.OverrideVerkle.Name)
cfg.Eth.OverrideVerkle = &v
}
stack.Config().TrieDir = ctx.String(utils.TrieDirFlag.Name)
backend, _ := utils.RegisterEthService(stack, &cfg.Eth)

// Configure log filter RPC API.
Expand Down
2 changes: 2 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,7 @@ func SetDataDir(ctx *cli.Context, cfg *node.Config) {
case ctx.IsSet(DataDirFlag.Name):
cfg.DataDir = ctx.String(DataDirFlag.Name)
case ctx.IsSet(TrieDirFlag.Name):
fmt.Println("setting TrieDirFlag.Name")
cfg.TrieDir = ctx.String(TrieDirFlag.Name)
case ctx.Bool(DeveloperFlag.Name):
cfg.DataDir = "" // unless explicitly requested, use memory databases
Expand Down Expand Up @@ -2160,6 +2161,7 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend
stack.RegisterAPIs(tracers.APIs(backend.ApiBackend))
return backend.ApiBackend, nil
}

backend, err := eth.New(stack, cfg)
if err != nil {
Fatalf("Failed to register the Ethereum service: %v", err)
Expand Down
6 changes: 4 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
// Open trie database with provided config
var triedb *trie.Database
if bc.separateDB != nil {
fmt.Printf("the separate db of block chain has been setted")
log.Info("the separate db of block chain has been set")
triedb = trie.NewDatabase(bc.separateDB, cacheConfig.triedbConfig())
} else {
triedb = trie.NewDatabase(db, cacheConfig.triedbConfig())
Expand Down Expand Up @@ -2970,7 +2970,9 @@ func EnablePipelineCommit(bc *BlockChain) (*BlockChain, error) {

func EnableSeparateDB(separateDB ethdb.Database) BlockChainOption {
return func(chain *BlockChain) (*BlockChain, error) {
chain.separateDB = separateDB
if separateDB != nil {
chain.separateDB = separateDB
}
return chain, nil
}
}
Expand Down
1 change: 1 addition & 0 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func (s *stateObject) getOriginStorage(key common.Hash) (common.Hash, bool) {
if value, cached := s.originStorage[key]; cached {
return value, true
}

// if L1 cache miss, try to get it from shared pool
if s.sharedOriginStorage != nil {
val, ok := s.sharedOriginStorage.Load(key)
Expand Down
3 changes: 2 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,13 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if stack.Config().EnableDoubleSignMonitor {
bcOps = append(bcOps, core.EnableDoubleSignChecker)
}

log.Info("trie dir is :" + stack.Config().TrieDir)
if stack.Config().TrieDir != "" {
fmt.Println("trie data dir has setted to ", stack.Config().TrieDir)
newChainDb, err := stack.OpenDatabaseForTrie("chaindata", config.DatabaseCache, config.DatabaseHandles,
config.DatabaseFreezer, "eth/db/chaindata/", false, false, false, config.PruneAncientData)
if err != nil {
log.Info("open db err", err)
return nil, err
}
bcOps = append(bcOps, core.EnableSeparateDB(newChainDb))
Expand Down
2 changes: 1 addition & 1 deletion miner/stress/clique/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey, sealers []*ecdsa.PrivateKey) *core
func makeSealer(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
// Define the basic configurations for the Ethereum node
datadir, _ := os.MkdirTemp("", "")

log.Info("making sealer")
config := &node.Config{
Name: "geth",
Version: params.Version,
Expand Down
10 changes: 8 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func New(conf *Config) (*Node, error) {
}
conf.DataDir = absdatadir
}

if conf.LogConfig != nil {
if conf.LogConfig.TermTimeFormat != nil && *conf.LogConfig.TermTimeFormat != "" {
log.SetTermTimeFormat(*conf.LogConfig.TermTimeFormat)
Expand Down Expand Up @@ -830,18 +831,23 @@ func (n *Node) OpenDatabaseWithFreezer(name string, cache, handles int, ancient,
func (n *Node) OpenDatabaseForTrie(name string, cache, handles int, ancient, namespace string, readonly, disableFreeze, isLastOffset, pruneAncientData bool) (ethdb.Database, error) {
n.lock.Lock()
defer n.lock.Unlock()
fmt.Println(":q!"+
":qtrie database dir0:", n.config.TrieDir)
if n.state == closedState {
return nil, ErrNodeStopped
}
var db ethdb.Database
var err error
if n.config.DataDir == "" {
fmt.Println("trie database dir1:", n.config.TrieDir)
db = rawdb.NewMemoryDatabase()
} else {
direcrory := filepath.Join(n.config.trieDir(), name)
fmt.Println("trie database dir2c:", direcrory)
db, err = rawdb.Open(rawdb.OpenOptions{
Type: n.config.DBEngine,
Directory: n.config.TrieDir,
AncientsDirectory: filepath.Join(n.config.trieDir(), "ancient"),
Directory: direcrory,
AncientsDirectory: filepath.Join(direcrory, "ancient"),
Namespace: namespace,
Cache: cache,
Handles: handles,
Expand Down

0 comments on commit c1b812c

Please sign in to comment.