createLocalNodes uses the cpu miner to mine node IDs for the local public key.
(diff int, num int)
| 117 | |
| 118 | // createLocalNodes uses the cpu miner to mine node IDs for the local public key. |
| 119 | func createLocalNodes(diff int, num int) (nodes []*proto.Node, err error) { |
| 120 | pub, err := kms.GetLocalPublicKey() |
| 121 | if err != nil { |
| 122 | return |
| 123 | } |
| 124 | nodes = make([]*proto.Node, num) |
| 125 | |
| 126 | miner := cpuminer.NewCPUMiner(nil) |
| 127 | nCh := make(chan cpuminer.NonceInfo) |
| 128 | defer close(nCh) |
| 129 | block := cpuminer.MiningBlock{ |
| 130 | Data: pub.Serialize(), |
| 131 | NonceChan: nCh, |
| 132 | } |
| 133 | next := cpuminer.Uint256{} |
| 134 | wg := &sync.WaitGroup{} |
| 135 | |
| 136 | for i := 0; i < num; i++ { |
| 137 | wg.Add(1) |
| 138 | go func() { |
| 139 | defer wg.Done() |
| 140 | _ = miner.ComputeBlockNonce(block, next, diff) |
| 141 | }() |
| 142 | |
| 143 | n := <-nCh |
| 144 | nodes[i] = &proto.Node{ |
| 145 | ID: proto.NodeID(n.Hash.String()), |
| 146 | PublicKey: pub, |
| 147 | Nonce: n.Nonce, |
| 148 | } |
| 149 | |
| 150 | next = n.Nonce |
| 151 | next.Inc() |
| 152 | wg.Wait() |
| 153 | } |
| 154 | return |
| 155 | } |
| 156 | |
| 157 | func setupServer(node *proto.Node) (server *Server, err error) { |
| 158 | if server, err = NewServerWithService( |
no test coverage detected