Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit bafd43a

Browse files
authored
FABN-1619 Fix requiredOrgs with Discovery (#308) (#309)
The requiredOrgs was not building the endorsement plan correctly. The peer groups did not contain the proper information. Signed-off-by: Bret Harrison <[email protected]>
1 parent dfdeb8d commit bafd43a

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

fabric-common/lib/DiscoveryHandler.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ class DiscoveryHandler extends ServiceHandler {
160160

161161
const results = await this.discovery.getDiscoveryResults(true);
162162

163-
if (results && request.requiredOrgs) {
163+
if (results && results.peers_by_org && request.requiredOrgs) {
164164
// special case when user knows which organizations to send the endorsement
165165
// let's build our own endorsement plan so that we can use the sorting and sending code
166-
const endorsement_plan = this._buildRequiredOrgPlan(results.peers_by_org);
166+
const endorsement_plan = this._buildRequiredOrgPlan(results.peers_by_org, request.requiredOrgs);
167167

168168
// remove all org and peer
169169
const orgs_request = {
@@ -320,17 +320,17 @@ class DiscoveryHandler extends ServiceHandler {
320320
return responses;
321321
}
322322

323-
_buildRequiredOrgPlan(peers_by_org) {
323+
_buildRequiredOrgPlan(peers_by_org, required_orgs) {
324324
const method = '_buildRequiredOrgPlan';
325325
logger.debug('%s - starting', method);
326326
const endorsement_plan = {plan_id: 'required organizations'};
327327
endorsement_plan.groups = {};
328328
endorsement_plan.layouts = [{}]; // only one layout which will have all organizations
329329

330-
for (const mspid in peers_by_org) {
330+
for (const mspid of required_orgs) {
331331
logger.debug(`${method} - found org:${mspid}`);
332332
endorsement_plan.groups[mspid] = {}; // make a group for each organization
333-
endorsement_plan.groups[mspid].peers = peers_by_org[mspid].peers; // now put in all peers from that organization
333+
endorsement_plan.groups[mspid].peers = JSON.parse(JSON.stringify(peers_by_org[mspid].peers)); // now put in all peers from that organization
334334
endorsement_plan.layouts[0][mspid] = 1; // add this org to the one layout and require one peer to endorse
335335
}
336336

fabric-common/test/DiscoveryHandler.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('DiscoveryHandler', () => {
152152
}
153153
};
154154

155-
const organization_plan = {
155+
const organization_plan = JSON.parse(JSON.stringify({
156156
plan_id: 'required organizations',
157157
groups: {
158158
Org1MSP: {
@@ -176,7 +176,7 @@ describe('DiscoveryHandler', () => {
176176
}
177177
},
178178
layouts: [{Org1MSP: 1, Org2MSP: 1, Org3MSP: 1}]
179-
};
179+
}));
180180

181181
const good = {response: {status: 200}};
182182
beforeEach(() => {
@@ -549,10 +549,10 @@ describe('DiscoveryHandler', () => {
549549
});
550550

551551
describe('#_buildRequiredOrgPlan', () => {
552-
it('should run ok', async () => {
552+
it('should run ok', () => {
553553

554554
// TEST CALL
555-
const results = await discoveryHandler._buildRequiredOrgPlan(config_results.peers_by_org);
555+
const results = discoveryHandler._buildRequiredOrgPlan(config_results.peers_by_org, ['Org1MSP', 'Org2MSP', 'Org3MSP']);
556556
results.should.deep.equal(organization_plan);
557557
});
558558
});

fabric-network/src/transaction.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ function newEndorsementError(proposalResponse: ProposalResponse): Error {
4141
const errorInfos: ErrorInfo[] = [];
4242

4343
for (const error of proposalResponse.errors) {
44-
const errorInfo = {
45-
peer: error.connection.name,
44+
const errorInfo: ErrorInfo = {
45+
peer: 'unknown',
4646
status: 'grpc',
4747
message: error.message
4848
};
49+
if (error.connection) {
50+
errorInfo.peer = error.connection.name;
51+
}
4952
errorInfos.push(errorInfo);
5053
}
5154

0 commit comments

Comments
 (0)