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

Commit d52cb4f

Browse files
Define endorseTimeout value in fabric-sdk-node v1.4(Issue #552) (#565)
In fabric-sdk-node v1.4, as well as in v2.2, define "endorseTimeout" value and use it instead of "commitTimeout". Co-Authored-by: Shinsuke Hasegawa <[email protected]> Signed-off-by: takayuki-nagai <[email protected]>
1 parent 28fb45c commit d52cb4f

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

fabric-network/lib/gateway.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const logger = require('./logger').getLogger('Gateway');
3636
* @memberof module:fabric-network
3737
* @property {number} [commitTimeout = 300] The timeout period in seconds to wait for commit notification to
3838
* complete.
39+
* @property {number} [endorseTimeout = 45] The timeout period in seconds to wait
40+
* for the endorsement to complete.
3941
* @property {?module:fabric-network.Gateway~TxEventHandlerFactory} [strategy=MSPID_SCOPE_ALLFORTX] Event handling strategy to identify
4042
* successful transaction commits. A null value indicates that no event handling is desired. The default is
4143
* [MSPID_SCOPE_ALLFORTX]{@link module:fabric-network.DefaultEventHandlerStrategies}.
@@ -154,6 +156,7 @@ class Gateway {
154156
},
155157
eventHandlerOptions: {
156158
commitTimeout: 300, // 5 minutes
159+
endorseTimeout: 45, // Same as "request-timeout" default value in fabric-client/config/default.json
157160
strategy: EventStrategies.MSPID_SCOPE_ALLFORTX
158161
},
159162
discovery: {

fabric-network/lib/transaction.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,11 @@ class Transaction {
175175
}
176176
request.endorsement_hint = {chaincodes: this._contract.getDiscoveryInterests()};
177177

178-
const commitTimeout = options.commitTimeout * 1000; // in ms
179-
let timeout = this._contract.gateway.getClient().getConfigSetting('request-timeout', commitTimeout);
180-
if (timeout < commitTimeout) {
181-
timeout = commitTimeout;
182-
}
178+
// Same as v2.2, define the endorseTimeout property which is used as the timeout for endorsement of the proposal
179+
const endorseTimeout = options.endorseTimeout * 1000; // in ms
183180

184181
// node sdk will target all peers on the channel that are endorsingPeer or do something special for a discovery environment
185-
const results = await channel.sendTransactionProposal(request, timeout);
182+
const results = await channel.sendTransactionProposal(request, endorseTimeout);
186183
const proposalResponses = results[0];
187184
const proposal = results[1];
188185

fabric-network/test/network.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ describe('Network', () => {
9292
},
9393
eventHandlerOptions: {
9494
commitTimeout: 300,
95+
endorseTimeout: 45,
9596
strategy: EventStrategies.MSPID_SCOPE_ALLFORTX
9697
},
9798
queryHandlerOptions: {

fabric-network/test/transaction.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,18 +300,12 @@ describe('Transaction', () => {
300300
return expect(promise).to.be.rejectedWith('Transaction has already been invoked');
301301
});
302302

303-
it('sends proposal with long timeout', async () => {
304-
stubContract.getEventHandlerOptions.returns({commitTimeout: 999});
303+
it('uses endorseTimeout option as proposal timeout', async () => {
304+
stubContract.getEventHandlerOptions.returns({endorseTimeout: 999});
305305
await transaction.submit();
306306
sinon.assert.calledWith(channel.sendTransactionProposal, sinon.match(expectedProposal), 999000);
307307
});
308308

309-
it('sends proposal with short timeout', async () => {
310-
stubContract.getEventHandlerOptions.returns({commitTimeout: 3});
311-
await transaction.submit();
312-
sinon.assert.calledWith(channel.sendTransactionProposal, sinon.match(expectedProposal), 45000);
313-
});
314-
315309
it('sends proposal to specified peers', async () => {
316310
const peer = sinon.createStubInstance(ChannelPeer);
317311
const endorsingPeers = [peer];

0 commit comments

Comments
 (0)