github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/setup/setup.go (about) 1 package setup 2 3 import ( 4 "os" 5 "os/signal" 6 "syscall" 7 8 "github.com/urfave/cli" 9 "github.com/sixexorg/magnetic-ring/bactor/actorstart" 10 "github.com/sixexorg/magnetic-ring/config" 11 "github.com/sixexorg/magnetic-ring/log" 12 "github.com/sixexorg/magnetic-ring/mock" 13 p2pcommon "github.com/sixexorg/magnetic-ring/p2pserver/common" 14 "fmt" 15 ) 16 17 //before Start(),need init global config 18 //ordinary: 19 // 1: bootnode 20 // 2: log 21 // 3: node account 22 // 4: main store 23 // 5: main block genesis 24 // 6: p2p and p2p-actor 25 // 7: cycle-actor in order to transit orgblock 26 // 8: assign p2p-actor in the cycle-actor 27 // 9: txpool and txpool-actor 28 //star: 29 // 1: the store across the chain 30 // 2: main radar 31 // 3: assign mainRadar in the txpool 32 // 4: mainRadar-actor 33 // 5: consensus 34 //exposed api: 35 // 1:runRouter 36 //league: 37 // 1: containers just nitialize once 38 // 2: createContainers 39 func Start(ctx *cli.Context) { 40 //1 41 p2pcommon.InitBootNode(config.GlobalConfig.BootNode.IP) 42 //2 43 initLog(config.GlobalConfig.SysCfg.LogPath) 44 //3 45 acct := initNodeAccount(ctx) //The node public private key needs to be bound to the account public private key. If it is a request for a star node. 46 //4 47 ledger := initLedger(config.GlobalConfig.SysCfg.StoreDir) 48 //5 49 mainchainGenesis(&config.GlobalConfig.Genesis, ledger) 50 //6 51 fmt.Println("before &&&&&&------->>>>>>>>>>>RestoreVars") 52 p2pActor := initP2P() 53 fmt.Println("after &&&&&&------->>>>>>>>>>>RestoreVars") 54 //7 to pass league block to cross-chain validation, 55 cycle := actorstart.InitCycleActor(p2pActor) // Broadcasting a sub-chain block to a star node. Adding this ordinary node does not require starting the star node radar. 56 //8 to check mainchain tx's nonce,balance and more 57 mainPool := initTxPool() 58 if true {// If it is a star node 59 //1 Cross-chain radar storage 60 acrossLedger := initAcrossStore(config.GlobalConfig.SysCfg.StoreDir) 61 //2 the star need check leagues's block Main chain radar stellar node consumption A node block data 62 mainRadar := initMainRadar(acct, ledger, acrossLedger) 63 //3 decorate txpool with mainRadar,then it can execute the data from mainRadar. txpool need to register the radar of the public chain, the radar will generate unsigned transactions. 64 mainPool.SetMainRadar(mainRadar) 65 //4 the mainRadar has data source after that 66 mainActor := actorstart.InitMainRadarActor() 67 //5 turn on this switch,the cycelRadar can push orgBlock to cross-chain validation 68 cycle.SetMainRadarActor(mainActor) 69 ledger.RestoreVars() 70 71 //4 local can package blocks 72 initConsensus(p2pActor, acct) 73 } 74 //ledger.RestoreVars() 75 //for http 76 go runRouter(config.GlobalConfig.SysCfg.HttpPort) 77 78 //for org-chain 79 if true { 80 initContainers(p2pActor) 81 go func() { 82 if config.GlobalConfig.SysCfg.GenBlock { 83 CreateContainer(mock.AccountNormal_1, 1, config.GlobalConfig.SysCfg.StoreDir, &config.GlobalConfig.CliqueCfg) 84 } 85 }() 86 } 87 waitFor() 88 } 89 func waitFor() { 90 c := make(chan os.Signal, 1) 91 signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP) 92 <-c 93 log.Info("server shut down") 94 }