<commit_before>package commands

import (
	"fmt"
	"io/ioutil"
	"time"

	"github.com/spf13/cobra"

	"github.com/bytom/node"
	"github.com/bytom/types"
	cmn "github.com/tendermint/tmlibs/common"
)

var runNodeCmd = &cobra.Command{
	Use:   "node",
	Short: "Run the p2p node",
	RunE:  runNode,
}

func init() {
	// p2p flags
	runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
	runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
	runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
	runNodeCmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange (dev feature)")

	RootCmd.AddCommand(runNodeCmd)
}

func runNode(cmd *cobra.Command, args []string) error {
	genDocFile := config.GenesisFile()
	if !cmn.FileExists(genDocFile) {
		logger.Info(cmn.Fmt("Waiting for genesis file %v...", genDocFile))
		for {
			time.Sleep(time.Second)
			if !cmn.FileExists(genDocFile) {
				continue
			}
			jsonBlob, err := ioutil.ReadFile(genDocFile)
			if err != nil {
				return fmt.Errorf("Couldn't read GenesisDoc file: %v", err)
			}
			genDoc, err := types.GenesisDocFromJSON(jsonBlob)
			if err != nil {
				return fmt.Errorf("Error reading GenesisDoc: %v", err)
			}
			if genDoc.ChainID == "" {
				return fmt.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile)
			}
			config.ChainID = genDoc.ChainID
			config.PrivateKey = genDoc.PrivateKey
			config.Time = genDoc.GenesisTime
		}
	}

	// Create & start node
	n := node.NewNodeDefault(config, logger.With("module", "node_p2p"))
	if _, err := n.Start(); err != nil {
		return fmt.Errorf("Failed to start node: %v", err)
	} else {
		logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo())
	}

	// Trap signal, run forever.
	n.RunForever()

	return nil
}<commit_msg>Fixed a bug about genesis.json defect.<commit_after>package commands

import (
	"fmt"
	"io/ioutil"

	"github.com/spf13/cobra"

	"github.com/bytom/node"
	"github.com/bytom/types"
	cmn "github.com/tendermint/tmlibs/common"
)

var runNodeCmd = &cobra.Command{
	Use:   "node",
	Short: "Run the p2p node",
	RunE:  runNode,
}

func init() {
	// p2p flags
	runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
	runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
	runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
	runNodeCmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange (dev feature)")

	RootCmd.AddCommand(runNodeCmd)
}

func runNode(cmd *cobra.Command, args []string) error {
	genDocFile := config.GenesisFile()
	if cmn.FileExists(genDocFile) {
		jsonBlob, err := ioutil.ReadFile(genDocFile)
		if err != nil {
			return fmt.Errorf("Couldn't read GenesisDoc file: %v", err)
		}
		genDoc, err := types.GenesisDocFromJSON(jsonBlob)
		if err != nil {
			return fmt.Errorf("Error reading GenesisDoc: %v", err)
		}
		if genDoc.ChainID == "" {
			return fmt.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile)
		}
		config.ChainID = genDoc.ChainID
		config.PrivateKey = genDoc.PrivateKey
		config.Time = genDoc.GenesisTime
	} else {
		return fmt.Errorf("not find genesis.json")
	}

	// Create & start node
	n := node.NewNodeDefault(config, logger.With("module", "node_p2p"))
	if _, err := n.Start(); err != nil {
		return fmt.Errorf("Failed to start node: %v", err)
	} else {
		logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo())
	}

	// Trap signal, run forever.
	n.RunForever()

	return nil
}
{'fraction_non_alphanumeric': 0.15463638821303055, 'fraction_numerical': 0.009732360097323601, 'mean_word_length': 4.124653739612189, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2988532', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1400, 'n_words': 300}