This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
quorum-config
executable file
·166 lines (139 loc) · 5.56 KB
/
quorum-config
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env ruby
require "yaml"
require "erb"
require 'optparse'
# set up flag options
options = {action: 'ask'}
OptionParser.new do |opts|
opts.banner = "Usage: ./quorum-config [options]"
opts.on("-a", "--action [ACTION]", String,
"create: generate all new resources.
update: do not regenerate the genesis.json.") do |a|
options[:action] = a
end
opts.on("-h", "--help", "prints this help.") do
puts opts
exit
end
end.parse!
def set_node_template_vars(values)
@Node_UserIdent = values["Node_UserIdent"]
@Node_Key_Dir = values["Key_Dir"]
@Consensus = values["quorum"]["quorum"]["consensus"]
@Tm_Version = values["quorum"]["tm"]["Tm_Version"]
@Tm_Name = values["quorum"]["tm"]["Name"]
@Quorum_Version = values["quorum"]["quorum"]["Quorum_Version"]
@Geth_Network_Id = @Chain_Id
if values["geth"] and values["geth"]["network"] and values["geth"]["network"]["id"]
@Geth_Network_Id = values["geth"]["network"]["id"]
end
return
end
# generic variables
@config_file = "qubernetes.yaml"
@optional_config_file=ARGV[0]
ARGV.clear
if @optional_config_file != nil
@config_file = @optional_config_file
end
puts "using config file: " + @config_file
# decide to create new resources
action = options[:action]
generateGenesis=true
if (action == 'update')
generateGenesis=false
end
@config = YAML.load_file(@config_file)
@nodes = @config["nodes"] #YAML.load_file("nodes.yaml")["nodes"]
@external_nodes = @config["external_nodes"]
## set defaults for config if not set, else use the values from the config.
@Genesis_Consensus = @config["genesis"]["consensus"]
# used by quorum-shared-config.yaml.erb and quorum-keystore.yaml.erb to load keys.
@Key_Dir_Base = "out/config"
if @config.dig("config","Key_Dir_Base")
@Key_Dir_Base = @config["config"]["Key_Dir_Base"]
end
# used by quorum-shared-config.yaml.erb to load the permissioned-nodes.json in configmaps
@Permissioned_Nodes_File = "out/config/permissioned-nodes.json"
if @config.dig("config","Permissioned_Nodes_File")
@Permissioned_Nodes_File = @config["config"]["Permissioned_Nodes_File"]
end
# used by quorum-genesis-config.yaml.erb and quorum-shared-config.yaml.erb
@Genesis_File = "out/config/genesis.json"
if @config.dig("config","Genesis_File")
@Genesis_File = @config["config"]["Genesis_File"]
end
@Chain_Id=1101
if @config.dig("config","Chain_Id")
@Chain_Id = @config["config"]["Chain_Id"]
end
# used in quorum-shared-config.yaml.erb to make tessera config available to deployments.
@Tessera_Config_Dir = "out/config"
if @config.dig("config","Tessera_Config_Dir")
@Tessera_Config_Dir = @config["config"]["Tessera_Config_Dir"]
end
# used in tessera-config-*.json.erb(s)
@Node_DataDir = "/etc/quorum/qdata"
# if @config["quorum"]["Node_DataDir"]
# @Node_DataDir = @config["quorum"]["Node_DataDir"]
# end
## set ports needed for the quorum templates
# Tm_Port used in tessera config templates
@Tm_Port = 9001
# if @config["quorum"]["tm"]["Port"]
# @Tm_Port = @config["quorum"]["tm"]["Port"]
# end
# Tm_3Party_Port used in tessera config templates
@Tm_3Party_Port = 9080
# if @config["quorum"]["tm"]["3Party_Port"]
# @Tm_3Party_Port = @config["quorum"]["tm"]["3Party_Port"]
# end
# used by permissioned-nodes.json.erb to set enode URLs
@Raft_Port = 50401
# if @config["quorum"]["quorum"]["Raft_Port"]
# @Raft_Port = @config["quorum"]["quorum"]["Raft_Port"]
# end
@NodeP2P_ListenAddr = 30303
# if @config["geth"] and @config["geth"]["NodeP2P_ListenAddr"]
# @NodeP2P_ListenAddr = @config["geth"]["NodeP2P_ListenAddr"]
# end
#####################################################
# Generate genesis.json and permissioned-nodes.json
#####################################################
@base_template_path = "templates/quorum"
`mkdir -p out/config`
# if the consensus is an ibft variant, set up the istanbul-validator-config.toml
# this is used by the genesis template to initial extra data with necessary validator data.
if @Genesis_Consensus == "istanbul" || @Genesis_Consensus == "qbft"
@Istanbul_Validator_Config = @Key_Dir_Base + "/istanbul-validator-config.toml"
puts(@Istanbul_Validator_Config)
File.open(@Istanbul_Validator_Config , "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/istanbul-validator.toml.erb"), nil, "-").result)
end
end
# create genesis files with all discovered keystore accounts pre alloc with funds.
if generateGenesis
puts(@Genesis_File)
File.open(@Genesis_File, "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/genesis.json.erb"), nil, "-").result)
end
end
# create permission nodes file containing all the nodes.
puts(@Permissioned_Nodes_File)
File.open(@Permissioned_Nodes_File , "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/permissioned-nodes.json.erb"), nil, "-").result)
end
# create tessera config.
puts(@Tessera_Config_Dir + "/tessera-config.json")
File.open(@Tessera_Config_Dir + "/tessera-config.json" , "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/tessera-config.json.erb"), nil, "-").result)
end
puts(@Tessera_Config_Dir + "/tessera-config-enhanced.json")
File.open(@Tessera_Config_Dir + "/tessera-config-enhanced.json" , "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/tessera-config-enhanced.json.erb"), nil, "-").result)
end
# Add support for tessera 9.0+ configs
puts(@Tessera_Config_Dir + "/tessera-config-9.0.json")
File.open(@Tessera_Config_Dir + "/tessera-config-9.0.json" , "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/tessera-config-9.0.json.erb"), nil, "-").result)
end