Skip to content

Commit 08df4e3

Browse files
committed
[FAB-3520] Eventer doesn't trigger subsequent updates
The eventer applies the config on an object that is returned from an invocation of config.Organizations(), which returns the same reference of map in each config update. The config.Organizations() is a map from org name to config.ApplicationOrg which has the anchor peers. Due to the fact that the references are the same, the ce.lastConfig.orgMap is the same as the new orgMap of a new config update, and this makes the logic think that there has not been any update of anchor peers at every real update (of anchor peers). I fixed the bug by cloning the map, and also fixed the test in eventer_test.go(line 98) to fail when the code of the eventer.go is before the fix. Change-Id: Iede772975216a88d00badfc9d7092f92580737a8 Signed-off-by: Yacov Manevich <[email protected]>
1 parent c69a25e commit 08df4e3

File tree

3 files changed

+57
-49
lines changed

3 files changed

+57
-49
lines changed

gossip/service/eventer.go

+33-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func newConfigEventer(receiver configEventReceiver) *configEventer {
6868
// Note, that a changing sequence number is ignored as changing configuration
6969
func (ce *configEventer) ProcessConfigUpdate(config Config) {
7070
logger.Debugf("Processing new config for channel %s", config.ChainID())
71-
72-
if ce.lastConfig != nil && reflect.DeepEqual(ce.lastConfig.orgMap, config.Organizations()) {
71+
orgMap := cloneOrgConfig(config.Organizations())
72+
if ce.lastConfig != nil && reflect.DeepEqual(ce.lastConfig.orgMap, orgMap) {
7373
logger.Debugf("Ignoring new config for channel %s because it contained no anchor peer updates", config.ChainID())
7474
return
7575
}
@@ -80,11 +80,41 @@ func (ce *configEventer) ProcessConfigUpdate(config Config) {
8080
}
8181

8282
newConfig := &configStore{
83-
orgMap: config.Organizations(),
83+
orgMap: orgMap,
8484
anchorPeers: newAnchorPeers,
8585
}
8686
ce.lastConfig = newConfig
8787

8888
logger.Debugf("Calling out because config was updated for channel %s", config.ChainID())
8989
ce.receiver.configUpdated(config)
9090
}
91+
92+
func cloneOrgConfig(src map[string]config.ApplicationOrg) map[string]config.ApplicationOrg {
93+
clone := make(map[string]config.ApplicationOrg)
94+
for k, v := range src {
95+
clone[k] = &appGrp{
96+
name: v.Name(),
97+
mspID: v.MSPID(),
98+
anchorPeers: v.AnchorPeers(),
99+
}
100+
}
101+
return clone
102+
}
103+
104+
type appGrp struct {
105+
name string
106+
mspID string
107+
anchorPeers []*peer.AnchorPeer
108+
}
109+
110+
func (ag *appGrp) Name() string {
111+
return ag.name
112+
}
113+
114+
func (ag *appGrp) MSPID() string {
115+
return ag.mspID
116+
}
117+
118+
func (ag *appGrp) AnchorPeers() []*peer.AnchorPeer {
119+
return ag.anchorPeers
120+
}

gossip/service/eventer_test.go

+20-45
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,10 @@ import (
2727

2828
const testChainID = "foo"
2929

30-
type applicationOrgs []*peer.AnchorPeer
31-
3230
func init() {
3331
util.SetupTestLogging()
3432
}
3533

36-
func (ao applicationOrgs) AnchorPeers() []*peer.AnchorPeer {
37-
return ao
38-
}
39-
40-
func (ao applicationOrgs) MSPID() string {
41-
return "ORG1"
42-
}
43-
44-
func (ao applicationOrgs) Name() string {
45-
panic("Unimplimented")
46-
}
47-
4834
type mockReceiver struct {
4935
orgs map[string]config.ApplicationOrg
5036
sequence uint64
@@ -76,11 +62,9 @@ func TestInitialUpdate(t *testing.T) {
7662
mc := &mockConfig{
7763
sequence: 7,
7864
orgs: map[string]config.ApplicationOrg{
79-
testOrgID: applicationOrgs([]*peer.AnchorPeer{
80-
&peer.AnchorPeer{
81-
Port: 9,
82-
},
83-
}),
65+
testOrgID: &appGrp{
66+
anchorPeers: []*peer.AnchorPeer{{Port: 9}},
67+
},
8468
},
8569
}
8670

@@ -95,15 +79,14 @@ func TestInitialUpdate(t *testing.T) {
9579
}
9680

9781
func TestSecondUpdate(t *testing.T) {
82+
appGrps := map[string]config.ApplicationOrg{
83+
testOrgID: &appGrp{
84+
anchorPeers: []*peer.AnchorPeer{{Port: 9}},
85+
},
86+
}
9887
mc := &mockConfig{
9988
sequence: 7,
100-
orgs: map[string]config.ApplicationOrg{
101-
testOrgID: applicationOrgs([]*peer.AnchorPeer{
102-
&peer.AnchorPeer{
103-
Port: 9,
104-
},
105-
}),
106-
},
89+
orgs: appGrps,
10790
}
10891

10992
mr := &mockReceiver{}
@@ -112,30 +95,24 @@ func TestSecondUpdate(t *testing.T) {
11295
ce.ProcessConfigUpdate(mc)
11396

11497
mc.sequence = 8
115-
mc.orgs = map[string]config.ApplicationOrg{
116-
testOrgID: applicationOrgs([]*peer.AnchorPeer{
117-
&peer.AnchorPeer{
118-
Port: 10,
119-
},
120-
}),
98+
appGrps[testOrgID] = &appGrp{
99+
anchorPeers: []*peer.AnchorPeer{{Port: 10}},
121100
}
122101

123102
ce.ProcessConfigUpdate(mc)
124103

125104
if !reflect.DeepEqual(mc, (*mockConfig)(mr)) {
126-
t.Fatalf("Should have updated config on initial update but did not")
105+
t.Fatal("Should have updated config on initial update but did not")
127106
}
128107
}
129108

130109
func TestSecondSameUpdate(t *testing.T) {
131110
mc := &mockConfig{
132111
sequence: 7,
133112
orgs: map[string]config.ApplicationOrg{
134-
testOrgID: applicationOrgs([]*peer.AnchorPeer{
135-
&peer.AnchorPeer{
136-
Port: 9,
137-
},
138-
}),
113+
testOrgID: &appGrp{
114+
anchorPeers: []*peer.AnchorPeer{{Port: 9}},
115+
},
139116
},
140117
}
141118

@@ -148,23 +125,21 @@ func TestSecondSameUpdate(t *testing.T) {
148125
ce.ProcessConfigUpdate(mc)
149126

150127
if mr.sequence != 0 {
151-
t.Errorf("Should not have updated sequence when reprocessing same config")
128+
t.Error("Should not have updated sequence when reprocessing same config")
152129
}
153130

154131
if mr.orgs != nil {
155-
t.Errorf("Should not have updated anchor peers when reprocessing same config")
132+
t.Error("Should not have updated anchor peers when reprocessing same config")
156133
}
157134
}
158135

159136
func TestUpdatedSeqOnly(t *testing.T) {
160137
mc := &mockConfig{
161138
sequence: 7,
162139
orgs: map[string]config.ApplicationOrg{
163-
testOrgID: applicationOrgs([]*peer.AnchorPeer{
164-
&peer.AnchorPeer{
165-
Port: 9,
166-
},
167-
}),
140+
testOrgID: &appGrp{
141+
anchorPeers: []*peer.AnchorPeer{{Port: 9}},
142+
},
168143
},
169144
}
170145

gossip/service/gossip_service_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,10 @@ func TestChannelConfig(t *testing.T) {
740740
mc := &mockConfig{
741741
sequence: 1,
742742
orgs: map[string]config.ApplicationOrg{
743-
testOrgID: applicationOrgs([]*peer.AnchorPeer{}),
743+
string(orgInChannelA): &appGrp{
744+
mspID: string(orgInChannelA),
745+
anchorPeers: []*peer.AnchorPeer{},
746+
},
744747
},
745748
}
746749
gService.JoinChan(jcm, gossipCommon.ChainID("A"))

0 commit comments

Comments
 (0)