@@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
7
7
package nwo
8
8
9
9
import (
10
- "bytes"
11
10
"io/ioutil"
12
11
"os"
13
12
"path/filepath"
@@ -16,7 +15,6 @@ import (
16
15
"github.com/golang/protobuf/proto"
17
16
"github.com/hyperledger/fabric-protos-go/common"
18
17
protosorderer "github.com/hyperledger/fabric-protos-go/orderer"
19
- ectdraft_protos "github.com/hyperledger/fabric-protos-go/orderer/etcdraft"
20
18
"github.com/hyperledger/fabric/integration/nwo/commands"
21
19
"github.com/hyperledger/fabric/internal/configtxlator/update"
22
20
"github.com/hyperledger/fabric/protoutil"
@@ -25,7 +23,7 @@ import (
25
23
"github.com/onsi/gomega/gexec"
26
24
)
27
25
28
- // GetConfigBlock retrieves the current config block for a channel
26
+ // GetConfigBlock retrieves the current config block for a channel.
29
27
func GetConfigBlock (n * Network , peer * Peer , orderer * Orderer , channel string ) * common.Block {
30
28
tempDir , err := ioutil .TempDir (n .RootDir , "getConfigBlock" )
31
29
Expect (err ).NotTo (HaveOccurred ())
@@ -49,7 +47,7 @@ func GetConfigBlock(n *Network, peer *Peer, orderer *Orderer, channel string) *c
49
47
return configBlock
50
48
}
51
49
52
- // GetConfig retrieves the last config of the given channel
50
+ // GetConfig retrieves the last config of the given channel.
53
51
func GetConfig (n * Network , peer * Peer , orderer * Orderer , channel string ) * common.Config {
54
52
configBlock := GetConfigBlock (n , peer , orderer , channel )
55
53
// unmarshal the envelope bytes
@@ -197,8 +195,8 @@ func FetchConfigBlock(n *Network, peer *Peer, orderer *Orderer, channel string,
197
195
Eventually (fetch , n .EventuallyTimeout ).Should (Equal (0 ))
198
196
}
199
197
200
- // UpdateOrdererConfig computes, signs, and submits a configuration update which requires orderers signature and waits
201
- // for the update to complete.
198
+ // UpdateOrdererConfig computes, signs, and submits a configuration update
199
+ // which requires orderers signature and waits for the update to complete.
202
200
func UpdateOrdererConfig (n * Network , orderer * Orderer , channel string , current , updated * common.Config , submitter * Peer , additionalSigners ... * Orderer ) {
203
201
tempDir , err := ioutil .TempDir (n .RootDir , "updateConfig" )
204
202
Expect (err ).NotTo (HaveOccurred ())
@@ -240,7 +238,7 @@ func UpdateOrdererConfigSession(n *Network, orderer *Orderer, channel string, cu
240
238
241
239
ComputeUpdateOrdererConfig (updateFile , n , channel , current , updated , submitter , additionalSigners ... )
242
240
243
- //session should not return with a zero exit code nor with a success response
241
+ // session should not return with a zero exit code nor with a success response
244
242
sess , err := n .OrdererAdminSession (orderer , submitter , commands.ChannelUpdate {
245
243
ChannelID : channel ,
246
244
Orderer : n .OrdererAddress (orderer , ListenPort ),
@@ -289,93 +287,11 @@ func UnmarshalBlockFromFile(blockFile string) *common.Block {
289
287
return block
290
288
}
291
289
292
- // AddConsenter adds a new consenter to the given channel
293
- func AddConsenter (n * Network , peer * Peer , orderer * Orderer , channel string , consenter ectdraft_protos.Consenter ) {
294
- UpdateEtcdRaftMetadata (n , peer , orderer , channel , func (metadata * ectdraft_protos.ConfigMetadata ) {
295
- metadata .Consenters = append (metadata .Consenters , & consenter )
296
- })
297
- }
298
-
299
- // RemoveConsenter removes a consenter with the given certificate in PEM format from the given channel
300
- func RemoveConsenter (n * Network , peer * Peer , orderer * Orderer , channel string , certificate []byte ) {
301
- UpdateEtcdRaftMetadata (n , peer , orderer , channel , func (metadata * ectdraft_protos.ConfigMetadata ) {
302
- var newConsenters []* ectdraft_protos.Consenter
303
- for _ , consenter := range metadata .Consenters {
304
- if bytes .Equal (consenter .ClientTlsCert , certificate ) || bytes .Equal (consenter .ServerTlsCert , certificate ) {
305
- continue
306
- }
307
- newConsenters = append (newConsenters , consenter )
308
- }
309
-
310
- metadata .Consenters = newConsenters
311
- })
312
- }
313
-
314
- // ConsenterRemover constructs configs that can be used by `UpdateOrdererConfig` to remove a consenter
315
- func ConsenterRemover (n * Network , peer * Peer , orderer * Orderer , channel string , certificate []byte ) (current , updated * common.Config ) {
316
- config := GetConfig (n , peer , orderer , channel )
317
- updatedConfig := proto .Clone (config ).(* common.Config )
318
-
319
- consensusTypeConfigValue := updatedConfig .ChannelGroup .Groups ["Orderer" ].Values ["ConsensusType" ]
320
- consensusTypeValue := & protosorderer.ConsensusType {}
321
- err := proto .Unmarshal (consensusTypeConfigValue .Value , consensusTypeValue )
322
- Expect (err ).NotTo (HaveOccurred ())
323
-
324
- metadata := & ectdraft_protos.ConfigMetadata {}
325
- err = proto .Unmarshal (consensusTypeValue .Metadata , metadata )
326
- Expect (err ).NotTo (HaveOccurred ())
327
-
328
- var newConsenters []* ectdraft_protos.Consenter
329
- for _ , consenter := range metadata .Consenters {
330
- if bytes .Equal (consenter .ClientTlsCert , certificate ) || bytes .Equal (consenter .ServerTlsCert , certificate ) {
331
- continue
332
- }
333
- newConsenters = append (newConsenters , consenter )
334
- }
335
-
336
- metadata .Consenters = newConsenters
337
- consensusTypeValue .Metadata , err = proto .Marshal (metadata )
338
- Expect (err ).NotTo (HaveOccurred ())
339
-
340
- updatedConfig .ChannelGroup .Groups ["Orderer" ].Values ["ConsensusType" ] = & common.ConfigValue {
341
- ModPolicy : "Admins" ,
342
- Value : protoutil .MarshalOrPanic (consensusTypeValue ),
343
- }
344
-
345
- return config , updatedConfig
346
- }
347
-
348
- // ConsenterAdder constructs configs that can be used by `UpdateOrdererConfig` to add a consenter
349
- func ConsenterAdder (n * Network , peer * Peer , orderer * Orderer , channel string , consenter ectdraft_protos.Consenter ) (current , updated * common.Config ) {
350
- config := GetConfig (n , peer , orderer , channel )
351
- updatedConfig := proto .Clone (config ).(* common.Config )
352
-
353
- consensusTypeConfigValue := updatedConfig .ChannelGroup .Groups ["Orderer" ].Values ["ConsensusType" ]
354
- consensusTypeValue := & protosorderer.ConsensusType {}
355
- err := proto .Unmarshal (consensusTypeConfigValue .Value , consensusTypeValue )
356
- Expect (err ).NotTo (HaveOccurred ())
357
-
358
- metadata := & ectdraft_protos.ConfigMetadata {}
359
- err = proto .Unmarshal (consensusTypeValue .Metadata , metadata )
360
- Expect (err ).NotTo (HaveOccurred ())
361
-
362
- metadata .Consenters = append (metadata .Consenters , & consenter )
363
-
364
- consensusTypeValue .Metadata , err = proto .Marshal (metadata )
365
- Expect (err ).NotTo (HaveOccurred ())
366
-
367
- updatedConfig .ChannelGroup .Groups ["Orderer" ].Values ["ConsensusType" ] = & common.ConfigValue {
368
- ModPolicy : "Admins" ,
369
- Value : protoutil .MarshalOrPanic (consensusTypeValue ),
370
- }
371
-
372
- return config , updatedConfig
373
- }
374
-
375
- // ConsensusMetadataMutator receives ConsensusType.Metadata and mutates it
290
+ // ConsensusMetadataMutator receives ConsensusType.Metadata and mutates it.
376
291
type ConsensusMetadataMutator func ([]byte ) []byte
377
292
378
- // UpdateConsensusMetadata executes a config update that updates the consensus metadata according to the given ConsensusMetadataMutator
293
+ // UpdateConsensusMetadata executes a config update that updates the consensus
294
+ // metadata according to the given ConsensusMetadataMutator.
379
295
func UpdateConsensusMetadata (network * Network , peer * Peer , orderer * Orderer , channel string , mutateMetadata ConsensusMetadataMutator ) {
380
296
config := GetConfig (network , peer , orderer , channel )
381
297
updatedConfig := proto .Clone (config ).(* common.Config )
@@ -394,18 +310,3 @@ func UpdateConsensusMetadata(network *Network, peer *Peer, orderer *Orderer, cha
394
310
395
311
UpdateOrdererConfig (network , orderer , channel , config , updatedConfig , peer , orderer )
396
312
}
397
-
398
- // UpdateEtcdRaftMetadata executes a config update that updates the etcdraft metadata according to the given function f
399
- func UpdateEtcdRaftMetadata (network * Network , peer * Peer , orderer * Orderer , channel string , f func (md * ectdraft_protos.ConfigMetadata )) {
400
- UpdateConsensusMetadata (network , peer , orderer , channel , func (originalMetadata []byte ) []byte {
401
- metadata := & ectdraft_protos.ConfigMetadata {}
402
- err := proto .Unmarshal (originalMetadata , metadata )
403
- Expect (err ).NotTo (HaveOccurred ())
404
-
405
- f (metadata )
406
-
407
- newMetadata , err := proto .Marshal (metadata )
408
- Expect (err ).NotTo (HaveOccurred ())
409
- return newMetadata
410
- })
411
- }
0 commit comments