@@ -29,6 +29,7 @@ import (
29
29
30
30
"github.com/algorand/go-algorand/config"
31
31
"github.com/algorand/go-algorand/crypto"
32
+ kmdconfig "github.com/algorand/go-algorand/daemon/kmd/config"
32
33
"github.com/algorand/go-algorand/data/bookkeeping"
33
34
"github.com/algorand/go-algorand/gen"
34
35
"github.com/algorand/go-algorand/libgoal"
@@ -42,6 +43,20 @@ type NetworkTemplate struct {
42
43
Genesis gen.GenesisData
43
44
Nodes []remote.NodeConfigGoal
44
45
Consensus config.ConsensusProtocols
46
+ kmdConfig TemplateKMDConfig // set by OverrideKmdConfig
47
+ }
48
+
49
+ // TemplateKMDConfig is a subset of the kmd configuration that can be overridden in the network template
50
+ // by using OverrideKmdConfig TemplateOverride opts.
51
+ // The reason why config.KMDConfig cannot be used directly is that it contains DataDir field which is
52
+ // is not known until the template instantiation.
53
+ type TemplateKMDConfig struct {
54
+ SessionLifetimeSecs uint64
55
+ }
56
+
57
+ func (c TemplateKMDConfig ) apply (cfg kmdconfig.KMDConfig ) kmdconfig.KMDConfig {
58
+ cfg .SessionLifetimeSecs = c .SessionLifetimeSecs
59
+ return cfg
45
60
}
46
61
47
62
var defaultNetworkTemplate = NetworkTemplate {
@@ -131,10 +146,27 @@ func (t NetworkTemplate) createNodeDirectories(targetFolder string, binDir strin
131
146
}
132
147
}
133
148
149
+ var kmdDir string
150
+ if (t .kmdConfig != TemplateKMDConfig {}) {
151
+ kmdDir = filepath .Join (nodeDir , libgoal .DefaultKMDDataDir )
152
+ err = os .MkdirAll (kmdDir , 0700 ) // kmd requires 700 permissions
153
+ if err != nil {
154
+ return
155
+ }
156
+ err = createKMDConfigFile (t .kmdConfig , kmdDir )
157
+ if err != nil {
158
+ return
159
+ }
160
+ }
161
+
134
162
if importKeys && hasWallet {
135
163
var client libgoal.Client
136
- client , err = libgoal .MakeClientWithBinDir (binDir , nodeDir , "" , libgoal .KmdClient )
137
- if err != nil {
164
+ if client , err = libgoal .MakeClientFromConfig (libgoal.ClientConfig {
165
+ AlgodDataDir : nodeDir ,
166
+ KMDDataDir : kmdDir ,
167
+ CacheDir : "" ,
168
+ BinDir : binDir ,
169
+ }, libgoal .KmdClient ); err != nil {
138
170
return
139
171
}
140
172
_ , err = client .CreateWallet (libgoal .UnencryptedWalletName , nil , crypto.MasterDerivationKey {})
@@ -241,12 +273,12 @@ func (t NetworkTemplate) Validate() error {
241
273
return fmt .Errorf ("invalid template: at least one relay is required when more than a single node presents" )
242
274
}
243
275
244
- // Validate JSONOverride decoding
276
+ // Validate ConfigJSONOverride decoding
245
277
for _ , cfg := range t .Nodes {
246
278
local := config .GetDefaultLocal ()
247
279
err := decodeJSONOverride (cfg .ConfigJSONOverride , & local )
248
280
if err != nil {
249
- return fmt .Errorf ("invalid template: unable to decode JSONOverride : %w" , err )
281
+ return fmt .Errorf ("invalid template: unable to decode ConfigJSONOverride : %w" , err )
250
282
}
251
283
}
252
284
@@ -293,7 +325,7 @@ func countRelayNodes(nodeCfgs []remote.NodeConfigGoal) (relayCount int) {
293
325
return
294
326
}
295
327
296
- func decodeJSONOverride (override string , cfg * config. Local ) error {
328
+ func decodeJSONOverride [ T any ] (override string , cfg * T ) error {
297
329
if override != "" {
298
330
reader := strings .NewReader (override )
299
331
dec := json .NewDecoder (reader )
@@ -340,3 +372,8 @@ func createConfigFile(node remote.NodeConfigGoal, configFile string, numNodes in
340
372
341
373
return cfg , cfg .SaveToFile (configFile )
342
374
}
375
+
376
+ func createKMDConfigFile (kmdConfig TemplateKMDConfig , kmdDir string ) error {
377
+ cfg := kmdConfig .apply (kmdconfig .DefaultConfig (kmdDir ))
378
+ return kmdconfig .SaveKMDConfig (kmdDir , cfg )
379
+ }
0 commit comments