Skip to content

Commit 9201ce7

Browse files
committed
[FAB-16327] Discovery config query with org endpoints
This change set makes discovery config parsing honor configs that have the old endpoint location removed from config entirely. Change-Id: Ic93fd6e49764a03056f88abf23af56ad530979cc Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 7468cca commit 9201ce7

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

discovery/support/config/support.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,5 @@ func ValidateConfigEnvelope(ce *common.ConfigEnvelope) error {
264264
if ce.Config.ChannelGroup.Values == nil {
265265
return fmt.Errorf("field Config.ChannelGroup.Values is nil")
266266
}
267-
if _, exists := ce.Config.ChannelGroup.Values[channelconfig.OrdererAddressesKey]; !exists {
268-
return fmt.Errorf("field Config.ChannelGroup.Values is empty")
269-
}
270267
return nil
271268
}

discovery/support/config/support_test.go

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -291,25 +291,6 @@ func TestValidateConfigEnvelope(t *testing.T) {
291291
},
292292
containsError: "field Config.ChannelGroup.Values is nil",
293293
},
294-
{
295-
name: "no OrdererAddressesKey in ChannelGroup Values",
296-
ce: &common.ConfigEnvelope{
297-
Config: &common.Config{
298-
ChannelGroup: &common.ConfigGroup{
299-
Values: map[string]*common.ConfigValue{},
300-
Groups: map[string]*common.ConfigGroup{
301-
channelconfig.ApplicationGroupKey: {
302-
Groups: map[string]*common.ConfigGroup{},
303-
},
304-
channelconfig.OrdererGroupKey: {
305-
Groups: map[string]*common.ConfigGroup{},
306-
},
307-
},
308-
},
309-
},
310-
},
311-
containsError: "field Config.ChannelGroup.Values is empty",
312-
},
313294
}
314295

315296
for _, test := range tests {
@@ -341,7 +322,7 @@ func TestOrdererEndpoints(t *testing.T) {
341322
}, res.Orderers)
342323
})
343324

344-
t.Run("Per org endpoints", func(t *testing.T) {
325+
t.Run("Per org endpoints alongside global endpoints", func(t *testing.T) {
345326
block, err := test.MakeGenesisBlock("mychannel")
346327
assert.NoError(t, err)
347328

@@ -361,6 +342,42 @@ func TestOrdererEndpoints(t *testing.T) {
361342
"aBadOrg": {},
362343
}, res.Orderers)
363344
})
345+
346+
t.Run("Per org endpoints without global endpoints", func(t *testing.T) {
347+
block, err := test.MakeGenesisBlock("mychannel")
348+
assert.NoError(t, err)
349+
350+
fakeBlockGetter := &mocks.ConfigBlockGetter{}
351+
cs := config.NewDiscoverySupport(fakeBlockGetter)
352+
353+
fakeBlockGetter.GetCurrConfigBlockReturnsOnCall(0, block)
354+
355+
removeGlobalEndpoints(t, block)
356+
injectAdditionalEndpointPair(t, block, "perOrgEndpoint:7050", "SampleOrg")
357+
injectAdditionalEndpointPair(t, block, "endpointWithoutAPortName", "aBadOrg")
358+
359+
res, err := cs.Config("test")
360+
assert.NoError(t, err)
361+
assert.Equal(t, map[string]*discovery.Endpoints{
362+
"SampleOrg": {Endpoint: []*discovery.Endpoint{{Host: "perOrgEndpoint", Port: 7050}}},
363+
"aBadOrg": {},
364+
}, res.Orderers)
365+
})
366+
}
367+
368+
func removeGlobalEndpoints(t *testing.T, block *common.Block) {
369+
// Unwrap the layers until we reach the orderer addresses
370+
env, err := protoutil.ExtractEnvelope(block, 0)
371+
assert.NoError(t, err)
372+
payload := protoutil.UnmarshalPayloadOrPanic(env.Payload)
373+
confEnv, err := configtx.UnmarshalConfigEnvelope(payload.Data)
374+
assert.NoError(t, err)
375+
// Remove the orderer addresses
376+
delete(confEnv.Config.ChannelGroup.Values, channelconfig.OrdererAddressesKey)
377+
// And put it back into the block
378+
payload.Data = protoutil.MarshalOrPanic(confEnv)
379+
env.Payload = protoutil.MarshalOrPanic(payload)
380+
block.Data.Data[0] = protoutil.MarshalOrPanic(env)
364381
}
365382

366383
func injectGlobalOrdererEndpoint(t *testing.T, block *common.Block, endpoint string) {

0 commit comments

Comments
 (0)