-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathbuild.go
69 lines (60 loc) · 1.97 KB
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package build
import (
"blockEmulator/consensus_shard/pbft_all"
"blockEmulator/networks"
"blockEmulator/params"
"blockEmulator/supervisor"
"log"
"time"
)
func initConfig(nid, nnm, sid, snm uint64) *params.ChainConfig {
// Read the contents of ipTable.json
ipMap := readIpTable("./ipTable.json")
params.IPmap_nodeTable = ipMap
params.SupervisorAddr = params.IPmap_nodeTable[params.SupervisorShard][0]
// check the correctness of params
if len(ipMap)-1 < int(snm) {
log.Panicf("Input ShardNumber = %d, but only %d shards in ipTable.json.\n", snm, len(ipMap)-1)
}
for shardID := 0; shardID < len(ipMap)-1; shardID++ {
if len(ipMap[uint64(shardID)]) < int(nnm) {
log.Panicf("Input NodeNumber = %d, but only %d nodes in Shard %d.\n", nnm, len(ipMap[uint64(shardID)]), shardID)
}
}
params.NodesInShard = int(nnm)
params.ShardNum = int(snm)
// init the network layer
networks.InitNetworkTools()
pcc := ¶ms.ChainConfig{
ChainID: sid,
NodeID: nid,
ShardID: sid,
Nodes_perShard: uint64(params.NodesInShard),
ShardNums: snm,
BlockSize: uint64(params.MaxBlockSize_global),
BlockInterval: uint64(params.Block_Interval),
InjectSpeed: uint64(params.InjectSpeed),
}
return pcc
}
func BuildSupervisor(nnm, snm uint64) {
methodID := params.ConsensusMethod
var measureMod []string
if methodID == 0 || methodID == 2 {
measureMod = params.MeasureBrokerMod
} else {
measureMod = params.MeasureRelayMod
}
measureMod = append(measureMod, "Tx_Details")
lsn := new(supervisor.Supervisor)
lsn.NewSupervisor(params.SupervisorAddr, initConfig(123, nnm, 123, snm), params.CommitteeMethod[methodID], measureMod...)
go lsn.TcpListen()
time.Sleep(5000 * time.Millisecond)
lsn.SupervisorTxHandling()
}
func BuildNewPbftNode(nid, nnm, sid, snm uint64) {
methodID := params.ConsensusMethod
worker := pbft_all.NewPbftNode(sid, nid, initConfig(nid, nnm, sid, snm), params.CommitteeMethod[methodID])
go worker.TcpListen()
worker.Propose()
}