github.com/annchain/OG@v0.0.9/node/node.go (about)

     1  // Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  package node
    15  
    16  import (
    17  	"fmt"
    18  	"github.com/annchain/OG/account"
    19  	archive2 "github.com/annchain/OG/archive"
    20  	"github.com/annchain/OG/arefactor/common/io"
    21  	"github.com/annchain/OG/arefactor/og/types"
    22  	"github.com/annchain/OG/arefactor/og_interface"
    23  	"github.com/annchain/OG/common/encryption"
    24  	"github.com/annchain/OG/og/message_archive"
    25  	"github.com/annchain/OG/og/txmaker"
    26  	"github.com/annchain/OG/og/types/archive"
    27  	"github.com/annchain/OG/og/verifier"
    28  	"github.com/annchain/OG/ogcore/pool"
    29  	"github.com/annchain/OG/p2p/ioperformance"
    30  	"github.com/annchain/OG/protocol"
    31  	"github.com/annchain/OG/rpc"
    32  	"github.com/annchain/OG/status"
    33  	"time"
    34  
    35  	"github.com/annchain/OG/consensus/annsensus"
    36  	"github.com/annchain/OG/og"
    37  	"github.com/annchain/OG/og/syncer"
    38  	"github.com/annchain/OG/wserver"
    39  	"github.com/sirupsen/logrus"
    40  
    41  	"github.com/annchain/OG/common/crypto"
    42  
    43  	"strconv"
    44  
    45  	"github.com/annchain/OG/og/downloader"
    46  	"github.com/annchain/OG/og/fetcher"
    47  
    48  	"github.com/annchain/OG/arefactor/performance"
    49  	miner2 "github.com/annchain/OG/ogcore/miner"
    50  	"github.com/annchain/OG/p2p"
    51  	"github.com/spf13/viper"
    52  )
    53  
    54  // Node is the basic entrypoint for all modules to start.
    55  type Node struct {
    56  	Components []Component
    57  }
    58  
    59  func NewNode() *Node {
    60  	n := new(Node)
    61  	// Order matters.
    62  	// Start myself first and then provide service and do p2p
    63  	pm := &performance.PerformanceMonitor{}
    64  
    65  	// Crypto and signers
    66  	var cryptoType crypto.CryptoType
    67  	switch viper.GetString("ogcrypto.algorithm") {
    68  	case "ed25519":
    69  		cryptoType = crypto.CryptoTypeEd25519
    70  	case "secp256k1":
    71  		cryptoType = crypto.CryptoTypeSecp256k1
    72  	default:
    73  		logrus.Fatal("Unknown ogcrypto algorithm: " + viper.GetString("ogcrypto.algorithm"))
    74  	}
    75  	//set default signer
    76  	og_interface.Signer = crypto.NewSigner(cryptoType)
    77  	// Setup ogcrypto algorithm
    78  	if og_interface.Signer.CanRecoverPubFromSig() {
    79  		archive.CanRecoverPubFromSig = true
    80  	}
    81  	// network id is configured either in config.toml or env variable
    82  	networkId := viper.GetInt64("p2p.network_id")
    83  	if networkId == 0 {
    84  		networkId = defaultNetworkId
    85  	}
    86  
    87  	// OG init
    88  	org, err := og.NewOg(
    89  		og.OGConfig{
    90  			NetworkId:   uint64(networkId),
    91  			GenesisPath: viper.GetString("dag.genesis_path"),
    92  		},
    93  	)
    94  	if err != nil {
    95  		logrus.WithError(err).Warning("Error occurred while initializing OG")
    96  		logrus.WithError(err).Fatal(fmt.Sprintf("Error occurred while initializing OG %v", err))
    97  	}
    98  
    99  	// Hub
   100  	maxPeers := viper.GetInt("p2p.max_peers")
   101  	if maxPeers == 0 {
   102  		maxPeers = defaultMaxPeers
   103  	}
   104  
   105  	feedBack := og.FeedBackMode
   106  	if viper.GetBool("hub.disable_feedback") == true {
   107  		feedBack = og.NormalMode
   108  	}
   109  	hub := og.NewHub(&og.HubConfig{
   110  		OutgoingBufferSize:            viper.GetInt("hub.outgoing_buffer_size"),
   111  		IncomingBufferSize:            viper.GetInt("hub.incoming_buffer_size"),
   112  		MessageCacheExpirationSeconds: viper.GetInt("hub.message_cache_expiration_seconds"),
   113  		MessageCacheMaxSize:           viper.GetInt("hub.message_cache_max_size"),
   114  		MaxPeers:                      maxPeers,
   115  		BroadCastMode:                 feedBack,
   116  		DisableEncryptGossip:          viper.GetBool("hub.disable_encrypt_gossip"),
   117  	})
   118  
   119  	// let og be the status source of hub to provide chain info to other peers
   120  	hub.StatusDataProvider = org
   121  
   122  	n.Components = append(n.Components, org)
   123  	n.Components = append(n.Components, hub)
   124  
   125  	// my account
   126  	// init key vault from a file
   127  	privFilePath := io.FixPrefixPath(viper.GetString("datadir"), "privkey")
   128  	if !io.FileExists(privFilePath) {
   129  		if viper.GetBool("genkey") {
   130  			logrus.Info("We will generate a private key for you. Please store it carefully.")
   131  			priv, _ := account.GenAccount()
   132  			account.SavePrivateKey(privFilePath, priv.String())
   133  		} else {
   134  			logrus.Fatal("Please generate a private key under " + privFilePath + " , or specify --genkey to let us generate one for you")
   135  		}
   136  	}
   137  
   138  	decrpted, err := encryption.DecryptFileDummy(privFilePath, "")
   139  	if err != nil {
   140  		logrus.WithError(err).Fatal("failed to decrypt private key")
   141  	}
   142  	vault := encryption.NewVault(decrpted)
   143  
   144  	myAcount := account.NewAccount(string(vault.Fetch()))
   145  
   146  	// p2p server
   147  	privKey := getNodePrivKey()
   148  	// isBootNode must be set to false if you need a centralized server to collect and dispatch bootstrap
   149  	if viper.GetBool("p2p.enabled") && viper.GetString("p2p.bootstrap_nodes") == "" {
   150  
   151  		// get my url and then send to centralized bootstrap server if there is no bootstrap server specified
   152  		nodeURL := getOnodeURL(privKey)
   153  		buildBootstrap(networkId, nodeURL, &myAcount.PublicKey)
   154  	}
   155  
   156  	var p2pServer *p2p.Server
   157  	if viper.GetBool("p2p.enabled") {
   158  		isBootNode := viper.GetBool("p2p.bootstrap_node")
   159  		p2pServer = NewP2PServer(privKey, isBootNode)
   160  
   161  		p2pServer.Protocols = append(p2pServer.Protocols, hub.SubProtocols...)
   162  		hub.NodeInfo = p2pServer.NodeInfo
   163  
   164  		n.Components = append(n.Components, p2pServer)
   165  	}
   166  
   167  	// transaction verifiers
   168  	graphVerifier := &verifier.GraphVerifier{
   169  		Dag:    org.Dag,
   170  		TxPool: org.TxPool,
   171  		//Buffer: txBuffer,
   172  	}
   173  
   174  	txFormatVerifier := &verifier.TxFormatVerifier{
   175  		MaxTxHash:    types.HexToHash(viper.GetString("max_tx_hash")),
   176  		MaxMinedHash: types.HexToHash(viper.GetString("max_mined_hash")),
   177  	}
   178  	if txFormatVerifier.MaxMinedHash == types.HexToHash("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") {
   179  		txFormatVerifier.NoVerifyMineHash = true
   180  		logrus.Info("no verify mined hash")
   181  	}
   182  	if txFormatVerifier.MaxTxHash == types.HexToHash("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") {
   183  		txFormatVerifier.NoVerifyMaxTxHash = true
   184  		logrus.Info("no verify max tx hash")
   185  	}
   186  	txFormatVerifier.NoVerifySignatrue = viper.GetBool("tx_buffer.no_verify_signature")
   187  	//verify format first , set address and then verify graph
   188  	verifiers := []protocol.Verifier{txFormatVerifier, graphVerifier}
   189  
   190  	// txBuffer
   191  	txBuffer := pool.NewTxBuffer(pool.TxBufferConfig{
   192  		Verifiers:                        verifiers,
   193  		Dag:                              org.Dag,
   194  		TxPool:                           org.TxPool,
   195  		DependencyCacheExpirationSeconds: 1 * 60 * 60,
   196  		DependencyCacheMaxSize:           100000,
   197  		NewTxQueueSize:                   viper.GetInt("tx_buffer.new_tx_queue_size"),
   198  		KnownCacheMaxSize:                100000,
   199  		KnownCacheExpirationSeconds:      1 * 60 * 60,
   200  		AddedToPoolQueueSize:             10000,
   201  		TestNoVerify:                     viper.GetBool("tx_buffer.test_no_verify"),
   202  	})
   203  	// let txBuffer judge whether the tx is received previously
   204  	hub.IsReceivedHash = txBuffer.IsReceivedHash
   205  	org.TxBuffer = txBuffer
   206  	n.Components = append(n.Components, txBuffer)
   207  
   208  	// syncBuffer
   209  	syncBuffer := syncer.NewSyncBuffer(syncer.SyncBufferConfig{
   210  		TxPool:    org.TxPool,
   211  		Dag:       org.Dag,
   212  		Verifiers: verifiers,
   213  	})
   214  	n.Components = append(n.Components, syncBuffer)
   215  
   216  	isBootNode := viper.GetBool("p2p.bootstrap_node")
   217  	// syncManager
   218  	syncManager := syncer.NewSyncManager(syncer.SyncManagerConfig{
   219  		Mode:           downloader.FullSync,
   220  		ForceSyncCycle: uint(viper.GetInt("hub.sync_cycle_ms")),
   221  		BootstrapNode:  isBootNode,
   222  	}, hub, org)
   223  
   224  	downloaderInstance := downloader.New(downloader.FullSync, org.Dag, hub.RemovePeer, syncBuffer.AddTxs)
   225  	heighter := func() uint64 {
   226  		return org.Dag.LatestSequencer().Height
   227  	}
   228  	hub.Fetcher = fetcher.New(org.Dag.GetSequencerByHash, heighter, syncBuffer.AddTxs, hub.RemovePeer)
   229  	syncManager.CatchupSyncer = &syncer.CatchupSyncer{
   230  		PeerProvider:           hub,
   231  		NodeStatusDataProvider: org,
   232  		Hub:                    hub,
   233  		Downloader:             downloaderInstance,
   234  		SyncMode:               downloader.FullSync,
   235  		BootStrapNode:          isBootNode,
   236  	}
   237  	syncManager.CatchupSyncer.Init()
   238  	hub.Downloader = downloaderInstance
   239  
   240  	messageHandler := og.NewIncomingMessageHandler(org, hub, 10000, time.Millisecond*40)
   241  
   242  	m := &og.MessageRouter{
   243  		PongHandler:               messageHandler,
   244  		PingHandler:               messageHandler,
   245  		BodiesRequestHandler:      messageHandler,
   246  		BodiesResponseHandler:     messageHandler,
   247  		HeaderRequestHandler:      messageHandler,
   248  		SequencerHeaderHandler:    messageHandler,
   249  		TxsRequestHandler:         messageHandler,
   250  		TxsResponseHandler:        messageHandler,
   251  		HeaderResponseHandler:     messageHandler,
   252  		FetchByHashRequestHandler: messageHandler,
   253  		GetMsgHandler:             messageHandler,
   254  		ControlMsgHandler:         messageHandler,
   255  		Hub:                       hub,
   256  	}
   257  	n.Components = append(n.Components, messageHandler)
   258  	syncManager.IncrementalSyncer = syncer.NewIncrementalSyncer(
   259  		&syncer.SyncerConfig{
   260  			BatchTimeoutMilliSecond:                  20,
   261  			AcquireTxQueueSize:                       1000,
   262  			MaxBatchSize:                             5, //smaller
   263  			AcquireTxDedupCacheMaxSize:               10000,
   264  			AcquireTxDedupCacheExpirationSeconds:     600,
   265  			BufferedIncomingTxCacheExpirationSeconds: 3600,
   266  			BufferedIncomingTxCacheMaxSize:           100000,
   267  			FiredTxCacheExpirationSeconds:            3600,
   268  			FiredTxCacheMaxSize:                      30000,
   269  			NewTxsChannelSize:                        15,
   270  		}, m, org.TxPool.GetHashOrder, org.TxBuffer.IsKnownHash,
   271  		heighter, syncManager.CatchupSyncer.CacheNewTxEnabled)
   272  	org.TxPool.onNewLatestSequencer = append(org.TxPool.onNewLatestSequencer, org.NewLatestSequencerCh,
   273  		syncManager.IncrementalSyncer.NewLatestSequencerCh)
   274  	m.NewSequencerHandler = syncManager.IncrementalSyncer
   275  	m.NewTxsHandler = syncManager.IncrementalSyncer
   276  	m.NewTxHandler = syncManager.IncrementalSyncer
   277  	m.FetchByHashResponseHandler = syncManager.IncrementalSyncer
   278  	m.CampaignHandler = syncManager.IncrementalSyncer
   279  	m.TermChangeHandler = syncManager.IncrementalSyncer
   280  	m.ArchiveHandler = syncManager.IncrementalSyncer
   281  	m.ActionTxHandler = syncManager.IncrementalSyncer
   282  	messageHandler.TxEnable = syncManager.IncrementalSyncer.TxEnable
   283  	syncManager.IncrementalSyncer.RemoveContrlMsgFromCache = messageHandler.RemoveControlMsgFromCache
   284  	//syncManager.OnUpToDate = append(syncManager.OnUpToDate, syncer.UpToDateEventListener)
   285  	//org.OnNodeSyncStatusChanged = append(org.OnNodeSyncStatusChanged, syncer.UpToDateEventListener)
   286  
   287  	syncManager.IncrementalSyncer.OnNewTxiReceived = append(syncManager.IncrementalSyncer.OnNewTxiReceived, txBuffer.ReceivedNewTxsChan)
   288  
   289  	txBuffer.Syncer = syncManager.IncrementalSyncer
   290  	announcer := syncer.NewAnnouncer(m)
   291  	txBuffer.Announcer = announcer
   292  	n.Components = append(n.Components, syncManager)
   293  
   294  	messageHandler32 := &og.IncomingMessageHandlerOG02{
   295  		Hub: hub,
   296  		Og:  org,
   297  	}
   298  
   299  	mr32 := &og.MessageRouterOG02{
   300  		GetNodeDataMsgHandler: messageHandler32,
   301  		GetReceiptsMsgHandler: messageHandler32,
   302  		NodeDataMsgHandler:    messageHandler32,
   303  	}
   304  
   305  	// Setup Hub
   306  	SetupCallbacks(m, hub)
   307  	SetupCallbacksOG32(mr32, hub)
   308  
   309  	miner := &miner2.PoWMiner{}
   310  	txCreator := &txmaker.OGTxCreator{
   311  		Miner:              miner,
   312  		TipGenerator:       org.TxPool,
   313  		MaxConnectingTries: 100,
   314  		MaxTxHash:          txFormatVerifier.MaxTxHash,
   315  		MaxMinedHash:       txFormatVerifier.MaxMinedHash,
   316  		NoVerifyMineHash:   txFormatVerifier.NoVerifyMineHash,
   317  		NoVerifyMaxTxHash:  txFormatVerifier.NoVerifyMaxTxHash,
   318  		DebugNodeId:        viper.GetInt("debug.node_id"),
   319  		GraphVerifier:      graphVerifier,
   320  		StateRootProvider:  org.TxPool,
   321  	}
   322  
   323  	// TODO: move to (embeded) client. It is not part of OG
   324  	//var privateKey ogcrypto.PrivateKey
   325  	//if viper.IsSet("account.private_key") {
   326  	//	privateKey, err = ogcrypto.PrivateKeyFromString(viper.GetString("account.private_key"))
   327  	//	logrus.Info("Loaded private key from configuration")
   328  	//	if err != nil {
   329  	//		panic(err)
   330  	//	}
   331  	//} else {
   332  	//	_, privateKey, err = signer.RandomKeyPair()
   333  	//	logrus.Warnf("Generated public/private key pair")
   334  	//	if err != nil {
   335  	//		panic(err)
   336  	//	}
   337  	//}
   338  
   339  	delegate := &Delegate{
   340  		TxPool: org.TxPool,
   341  		//TxBuffer:  txBuffer,
   342  		Dag:              org.Dag,
   343  		TxCreator:        txCreator,
   344  		InsertSyncBuffer: syncBuffer.AddTxs,
   345  	}
   346  
   347  	delegate.OnNewTxiGenerated = append(delegate.OnNewTxiGenerated, txBuffer.SelfGeneratedNewTxChan)
   348  	delegate.ReceivedNewTxsChan = txBuffer.ReceivedNewTxsChan
   349  	genesisAccounts := parserGenesisAccounts(viper.GetString("annsensus.genesis_pk"))
   350  
   351  	mode := viper.GetString("mode")
   352  	if mode == "archive" {
   353  		status.ArchiveMode = true
   354  	}
   355  
   356  	disableConsensus := viper.GetBool("annsensus.disable")
   357  	//TODO temperary , delete this after demo
   358  	//if archiveMode {
   359  	//	disableConsensus = true
   360  	//}
   361  
   362  	var annSensus *annsensus.AnnSensus
   363  	if !disableConsensus {
   364  		campaign := viper.GetBool("annsensus.campaign")
   365  		disableTermChange := viper.GetBool("annsensus.disable_term_change")
   366  		partnerNum := viper.GetInt("annsensus.partner_number")
   367  		//threshold := viper.GetInt("annsensus.threshold")
   368  		sequencerTime := viper.GetInt("annsensus.sequencerTime")
   369  		if sequencerTime == 0 {
   370  			sequencerTime = 3000
   371  		}
   372  		consensFilePath := io.FixPrefixPath(viper.GetString("datadir"), viper.GetString("annsensus.consensus_path"))
   373  		if consensFilePath == "" {
   374  			logrus.Fatal("need path")
   375  		}
   376  		termChangeInterval := viper.GetInt("annsensus.term_change_interval")
   377  		annSensus = annsensus.NewAnnSensus(termChangeInterval, disableConsensus, cryptoType, campaign,
   378  			partnerNum, genesisAccounts, consensFilePath, disableTermChange)
   379  
   380  		// TODO
   381  		// set annsensus's private key to be coinbase.
   382  
   383  		consensusVerifier := &verifier.ConsensusVerifier{
   384  			VerifyTermChange: annSensus.VerifyTermChange,
   385  			VerifySequencer:  annSensus.VerifySequencer,
   386  			VerifyCampaign:   annSensus.VerifyCampaign,
   387  		}
   388  		txBuffer.Verifiers = append(txBuffer.Verifiers, consensusVerifier)
   389  
   390  		annSensus.InitAccount(myAcount, time.Millisecond*time.Duration(sequencerTime),
   391  			delegate.JudgeNonce, txCreator, org.Dag, txBuffer.SelfGeneratedNewTxChan,
   392  			syncManager.IncrementalSyncer.HandleNewTxi, hub)
   393  		logrus.Info("my pk ", annSensus.MyAccount.PublicKey.String())
   394  		hub.SetEncryptionKey(&annSensus.MyAccount.PrivateKey)
   395  
   396  		syncManager.OnUpToDate = append(syncManager.OnUpToDate, annSensus.UpdateEvent)
   397  		hub.OnNewPeerConnected = append(hub.OnNewPeerConnected, annSensus.NewPeerConnectedEventListener)
   398  		org.Dag.OnConsensusTXConfirmed = annSensus.ConsensusTXConfirmed
   399  
   400  		n.Components = append(n.Components, annSensus)
   401  		//m.ConsensusDkgDealHandler = annSensus
   402  		//m.ConsensusDkgDealResponseHandler = annSensus
   403  		//m.ConsensusDkgSigSetsHandler = annSensus
   404  		//m.ConsensusHandler = annSensus
   405  		//m.ConsensusPreCommitHandler = annSensus
   406  		//m.ConsensusPreVoteHandler = annSensus
   407  		//m.ConsensusDkgGenesisPublicKeyHandler = annSensus
   408  		m.TermChangeResponseHandler = annSensus
   409  		m.TermChangeRequestHandler = annSensus
   410  		txBuffer.OnProposalSeqCh = annSensus.ProposalSeqChan
   411  
   412  		org.TxPool.onNewLatestSequencer = append(org.TxPool.onNewLatestSequencer, annSensus.NewLatestSequencer)
   413  		pm.Register(annSensus)
   414  	}
   415  
   416  	hub.OnNewPeerConnected = append(hub.OnNewPeerConnected, syncManager.CatchupSyncer.NewPeerConnectedEventListener)
   417  
   418  	//init msg requst id
   419  	message_archive.MsgCountInit()
   420  
   421  	// DataLoader
   422  	dataLoader := &og.DataLoader{
   423  		Dag:    org.Dag,
   424  		TxPool: org.TxPool,
   425  	}
   426  	n.Components = append(n.Components, dataLoader)
   427  
   428  	n.Components = append(n.Components, m)
   429  	org.Manager = m
   430  
   431  	// rpc server
   432  	var rpcServer *rpc.RpcServer
   433  	if viper.GetBool("rpc.enabled") {
   434  		rpcServer = rpc.NewRpcServer(viper.GetString("rpc.port"))
   435  		n.Components = append(n.Components, rpcServer)
   436  	}
   437  
   438  	if rpcServer != nil {
   439  		rpcServer.C.P2pServer = p2pServer
   440  		rpcServer.C.Og = org
   441  		rpcServer.C.TxBuffer = txBuffer
   442  		rpcServer.C.TxCreator = txCreator
   443  
   444  		rpcServer.C.SyncerManager = syncManager
   445  
   446  		if !disableConsensus {
   447  			rpcServer.C.AnnSensus = annSensus
   448  		}
   449  
   450  		rpcServer.C.PerformanceMonitor = pm
   451  	}
   452  
   453  	// websocket server
   454  	if viper.GetBool("websocket.enabled") {
   455  		wsServer := wserver.NewServer(fmt.Sprintf(":%d", viper.GetInt("websocket.port")))
   456  		n.Components = append(n.Components, wsServer)
   457  		org.TxPool.RegisterOnNewTxReceived(wsServer.NewTxReceivedChan, "wsServer.NewTxReceivedChan", true)
   458  		org.TxPool.onBatchConfirmed = append(org.TxPool.onBatchConfirmed, wsServer.BatchConfirmedChan)
   459  		pm.Register(wsServer)
   460  	}
   461  
   462  	if status.ArchiveMode {
   463  		logrus.Info("archive mode")
   464  	}
   465  
   466  	//txMetrics
   467  	txCounter := archive2.NewTxCounter()
   468  
   469  	org.TxPool.RegisterOnNewTxReceived(txCounter.NewTxReceivedChan, "txCounter.NewTxReceivedChan", true)
   470  	org.TxPool.onBatchConfirmed = append(org.TxPool.onBatchConfirmed, txCounter.BatchConfirmedChan)
   471  	delegate.OnNewTxiGenerated = append(delegate.OnNewTxiGenerated, txCounter.NewTxGeneratedChan)
   472  	n.Components = append(n.Components, txCounter)
   473  
   474  	//annSensus.RegisterNewTxHandler(txBuffer.ReceivedNewTxChan)
   475  
   476  	pm.Register(org.TxPool)
   477  	pm.Register(syncManager)
   478  	pm.Register(syncManager.IncrementalSyncer)
   479  	pm.Register(txBuffer)
   480  	pm.Register(messageHandler)
   481  	pm.Register(hub)
   482  	pm.Register(txCounter)
   483  
   484  	n.Components = append(n.Components, pm)
   485  	ioPerformance := ioperformance.Init()
   486  	n.Components = append(n.Components, ioPerformance)
   487  	return n
   488  }
   489  
   490  func StringArrayToIntArray(arr []string) []int {
   491  	var a = make([]int, len(arr))
   492  	var err error
   493  	for i := 0; i < len(arr); i++ {
   494  		a[i], err = strconv.Atoi(arr[i])
   495  		if err != nil {
   496  			logrus.WithError(err).Fatal("bad config on string array")
   497  		}
   498  	}
   499  	return a
   500  }
   501  
   502  func (n *Node) Start() {
   503  	for _, component := range n.Components {
   504  		logrus.Infof("Starting %s", component.Name())
   505  		component.Start()
   506  		logrus.Infof("Started: %s", component.Name())
   507  
   508  	}
   509  	logrus.Info("Node Started")
   510  }
   511  func (n *Node) Stop() {
   512  	status.NodeStopped = true
   513  	for i := len(n.Components) - 1; i >= 0; i-- {
   514  		comp := n.Components[i]
   515  		logrus.Infof("Stopping %s", comp.Name())
   516  		comp.Stop()
   517  		logrus.Infof("Stopped: %s", comp.Name())
   518  	}
   519  	logrus.Info("Node Stopped")
   520  }
   521  
   522  // SetupCallbacks Regist callbacks to handle different messages
   523  func SetupCallbacks(m *og.MessageRouter, hub *og.Hub) {
   524  	hub.CallbackRegistry[message_archive.MessageTypePing] = m.RoutePing
   525  	hub.CallbackRegistry[message_archive.MessageTypePong] = m.RoutePong
   526  	hub.CallbackRegistry[message_archive.MessageTypeFetchByHashRequest] = m.RouteFetchByHashRequest
   527  	hub.CallbackRegistry[message_archive.MessageTypeFetchByHashResponse] = m.RouteFetchByHashResponse
   528  	hub.CallbackRegistry[message_archive.MessageTypeNewTx] = m.RouteNewTx
   529  	hub.CallbackRegistry[message_archive.MessageTypeNewTxs] = m.RouteNewTxs
   530  	hub.CallbackRegistry[message_archive.MessageTypeNewSequencer] = m.RouteNewSequencer
   531  	hub.CallbackRegistry[message_archive.MessageTypeGetMsg] = m.RouteGetMsg
   532  	hub.CallbackRegistry[message_archive.MessageTypeSequencerHeader] = m.RouteSequencerHeader
   533  	hub.CallbackRegistry[message_archive.MessageTypeBodiesRequest] = m.RouteBodiesRequest
   534  	hub.CallbackRegistry[message_archive.MessageTypeBodiesResponse] = m.RouteBodiesResponse
   535  	hub.CallbackRegistry[message_archive.MessageTypeTxsRequest] = m.RouteTxsRequest
   536  	hub.CallbackRegistry[message_archive.MessageTypeTxsResponse] = m.RouteTxsResponse
   537  	hub.CallbackRegistry[message_archive.MessageTypeHeaderRequest] = m.RouteHeaderRequest
   538  	hub.CallbackRegistry[message_archive.MessageTypeHeaderResponse] = m.RouteHeaderResponse
   539  	hub.CallbackRegistry[message_archive.MessageTypeControl] = m.RouteControlMsg
   540  	hub.CallbackRegistry[message_archive.MessageTypeCampaign] = m.RouteCampaign
   541  	hub.CallbackRegistry[message_archive.MessageTypeTermChange] = m.RouteTermChange
   542  	hub.CallbackRegistry[message_archive.MessageTypeArchive] = m.RouteArchive
   543  	hub.CallbackRegistry[message_archive.MessageTypeActionTX] = m.RouteActionTx
   544  	// Callbacks for DKG were moved to dkg package
   545  	//hub.CallbackRegistry[message.MessageTypeConsensusDkgDeal] = m.RouteConsensusDkgDeal
   546  	//hub.CallbackRegistry[message.MessageTypeConsensusDkgDealResponse] = m.RouteConsensusDkgDealResponse
   547  	//hub.CallbackRegistry[message.MessageTypeConsensusDkgSigSets] = m.RouteConsensusDkgSigSets
   548  	//hub.CallbackRegistry[message.MessageTypeConsensusDkgGenesisPublicKey] = m.RouteConsensusDkgGenesisPublicKey
   549  	// Callbacks fot BFT were moved to bft package
   550  	//hub.CallbackRegistry[p2p_message.MessageTypeProposal] = m.RouteConsensusProposal
   551  	//hub.CallbackRegistry[p2p_message.MessageTypePreVote] = m.RouteConsensusPreVote
   552  	//hub.CallbackRegistry[p2p_message.MessageTypePreCommit] = m.RouteConsensusPreCommit
   553  	// TODO: move dkg callbacks to consensus package
   554  
   555  	hub.CallbackRegistry[message_archive.MessageTypeTermChangeRequest] = m.RouteTermChangeRequest
   556  	hub.CallbackRegistry[message_archive.MessageTypeTermChangeResponse] = m.RouteTermChangeResponse
   557  }
   558  
   559  func SetupCallbacksOG32(m *og.MessageRouterOG02, hub *og.Hub) {
   560  	hub.CallbackRegistryOG02[message_archive.GetNodeDataMsg] = m.RouteGetNodeDataMsg
   561  	hub.CallbackRegistryOG02[message_archive.NodeDataMsg] = m.RouteNodeDataMsg
   562  	hub.CallbackRegistryOG02[message_archive.GetReceiptsMsg] = m.RouteGetReceiptsMsg
   563  }