MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / createLocalNodes

Function createLocalNodes

rpc/xxx_test.go:119–155  ·  view source on GitHub ↗

createLocalNodes uses the cpu miner to mine node IDs for the local public key.

(diff int, num int)

Source from the content-addressed store, hash-verified

117
118// createLocalNodes uses the cpu miner to mine node IDs for the local public key.
119func 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
157func setupServer(node *proto.Node) (server *Server, err error) {
158 if server, err = NewServerWithService(

Callers 1

setupEnvironmentFunction · 0.85

Calls 9

ComputeBlockNonceMethod · 0.95
IncMethod · 0.95
GetLocalPublicKeyFunction · 0.92
NewCPUMinerFunction · 0.92
NodeIDTypeAlias · 0.92
WaitMethod · 0.80
SerializeMethod · 0.45
AddMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected