diff --git a/fabric-client/lib/Remote.js b/fabric-client/lib/Remote.js index 45598c7fb5..54880b4e4f 100644 --- a/fabric-client/lib/Remote.js +++ b/fabric-client/lib/Remote.js @@ -93,19 +93,23 @@ var Remote = class { } } - let grpc_receive_max = utils.getConfigSetting('grpc-max-receive-message-length'); - let grpc_send_max = utils.getConfigSetting('grpc-max-send-message-length'); - // if greater than 0, set to that specific limit - // if equal to -1, set to that to have no limit - // if 0, do not set anything to use the system default - if (grpc_receive_max > 0 || grpc_receive_max === -1) - this._options['grpc.max_receive_message_length'] = grpc_receive_max; - - // if greater than 0, set to that specific limit - // if equal to -1, set to that to have no limit - // if 0, do not set anything to use the system default - if (grpc_send_max > 0 || grpc_send_max === -1) - this._options['grpc.max_send_message_length'] = grpc_send_max; + if(!this._options['grpc.max_receive_message_length']) { + let grpc_receive_max = utils.getConfigSetting('grpc.max_receive_message_length'); + // if greater than 0, set to that specific limit + // if equal to -1, set to that to have no limit + // if 0, do not set anything to use the system default + if (grpc_receive_max > 0 || grpc_receive_max === -1) + this._options['grpc.max_receive_message_length'] = grpc_receive_max; + } + + if(!this._options['grpc.max_send_message_length']) { + let grpc_send_max = utils.getConfigSetting('grpc.max_send_message_length'); + // if greater than 0, set to that specific limit + // if equal to -1, set to that to have no limit + // if 0, do not set anything to use the system default + if (grpc_send_max > 0 || grpc_send_max === -1) + this._options['grpc.max_send_message_length'] = grpc_send_max; + } // service connection this._url = url; diff --git a/test/integration/e2e/create-channel.js b/test/integration/e2e/create-channel.js index ecf1a7df27..16d3b5444b 100644 --- a/test/integration/e2e/create-channel.js +++ b/test/integration/e2e/create-channel.js @@ -80,6 +80,19 @@ test('\n\n***** SDK Built config update create flow *****\n\n', function(t) { } ); + // set something to fail to test that the code picks up values from the config + let keep = Client.getConfigSetting('grpc.max_send_message_length'); + Client.setConfigSetting('grpc.max_send_message_length', 6800); + var orderer_bad2 = client.newOrderer( + ORGS.orderer.url, + { + 'pem': caroots, + 'ssl-target-name-override': ORGS.orderer['server-hostname'], + 'grpc.max_send_message_length': 6800 + } + ); + // put back the setting + Client.setConfigSetting('grpc.max_send_message_length',keep); var TWO_ORG_MEMBERS_AND_ADMIN = [{ role: { @@ -193,7 +206,8 @@ test('\n\n***** SDK Built config update create flow *****\n\n', function(t) { logger.debug('\n***\n done signing \n***\n'); // build up a create request to include - // an orderer that will fail + // an orderer that will fail because the + // orderer is defined with a bad options value let tx_id = client.newTransactionID(); var request = { config: config, @@ -219,6 +233,36 @@ test('\n\n***** SDK Built config update create flow *****\n\n', function(t) { t.fail('Failed to fail with max error on the create channel: ' + err.stack ? err.stack : err); } + return true; + }).then((nothing) => { + // build up a create request to + // an orderer that will fail + + let tx_id = client.newTransactionID(); + var request = { + config: config, + signatures : signatures, + name : channel_name, + orderer : orderer_bad2, + txId : tx_id + }; + + // send create request to bad orderer + return client.createChannel(request); + }).then((result) => { + logger.debug('\n***\n completed the create \n***\n'); + + logger.debug(' response ::%j',result); + t.fail('Failed when this Successfully created the channel.'); + t.end(); + throw new Error('Failed to get max send error'); + }, (err) => { + if(err.toString().indexOf('Sent message larger than max') > -1) { + t.pass('Successfully failed with max error on the create channel: ' + err.toString()); + } else { + t.fail('Failed to fail with max error on the create channel: ' + err.stack ? err.stack : err); + } + return true; }).then((nothing) => { // build up the create request diff --git a/test/integration/grpc.js b/test/integration/grpc.js index 09431dfb98..80e188a43d 100644 --- a/test/integration/grpc.js +++ b/test/integration/grpc.js @@ -68,7 +68,9 @@ test('\n\n*** GRPC communication tests ***\n\n', (t) => { testUtil.setupChaincodeDeploy(); // limit the send message size to 1M - utils.setConfigSetting('grpc-max-send-message-length', 1024 * 1024); + utils.setConfigSetting('grpc.max_send_message_length', 1024 * 1024); + // now that we have set the config setting, create a new peer so that it will + // pick up the settings which are only done when the peer is created. e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v2', 'golang', t, true) .then(() => { t.fail('Should have failed because the file size is too big for grpc send messages'); @@ -81,7 +83,8 @@ test('\n\n*** GRPC communication tests ***\n\n', (t) => { } // now dial the send limit up - utils.setConfigSetting('grpc-max-send-message-length', 1024 * 1024 * 2); + utils.setConfigSetting('grpc.max_send_message_length', 1024 * 1024 * 2); + // be sure to create a new peer to pick up the new settings return e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v2', 'golang', t, true); }).then(() => { @@ -89,41 +92,30 @@ test('\n\n*** GRPC communication tests ***\n\n', (t) => { Client.addConfigFile(path.join(__dirname, './e2e/config.json')); - return Client.newDefaultKeyValueStore({ - path: testUtil.storePathForOrg(orgName) - }); - }, (err) => { - t.fail('Failed to effectively use config setting to control grpc send message limit with error ::'+err); - t.end(); + return Client.newDefaultKeyValueStore({path: testUtil.storePathForOrg(orgName)}); }).then((store) => { - client.setStateStore(store); - return testUtil.getSubmitter(client, t, userOrg); + return testUtil.getSubmitter(client, t, userOrg, true); }).then((admin) => { submitter = admin; - // now dial the receive limit back down to reproduce the message size error - utils.setConfigSetting('grpc-max-receive-message-length', 1024 * 1024 * 1); - // for this test we only need to send to one of the peers in org1 let data = fs.readFileSync(path.join(__dirname, 'e2e', ORGS[userOrg].peer1['tls_cacerts'])); let peer = client.newPeer( ORGS[userOrg].peer1.requests, { pem: Buffer.from(data).toString(), - 'ssl-target-name-override': ORGS[userOrg].peer1['server-hostname'] + 'ssl-target-name-override': ORGS[userOrg].peer1['server-hostname'], + // now dial the receive limit back down to reproduce the message size error + // notice this is another way to set a grpc setting, this will override + // what is in the config setting. + 'grpc.max_receive_message_length': 10 } ); return channel.sendTransactionProposal(buildEchoRequest(client, peer)); - - }, (err) => { - - t.fail('Failed to enroll user \'admin\'. ' + err); - t.end(); - }).then((response) => { var err = (response[0] && response[0][0] && response[0][0] instanceof Error) ? response[0][0] : {}; @@ -132,10 +124,12 @@ test('\n\n*** GRPC communication tests ***\n\n', (t) => { } else { t.fail(util.format('Unexpected error: %s' + err.stack ? err.stack : err)); t.end(); + throw new Error('Test Failed'); } // now dial the send limit up by setting to -1 for unlimited - utils.setConfigSetting('grpc-max-receive-message-length', -1); + utils.setConfigSetting('grpc.max_receive_message_length', -1); + utils.setConfigSetting('grpc.max_send_message_length', -1); // must re-construct a new peer instance to pick up the new setting let data = fs.readFileSync(path.join(__dirname, 'e2e', ORGS[userOrg].peer1['tls_cacerts'])); @@ -173,4 +167,4 @@ function buildEchoRequest(client, peer) { txId: tx_id, nonce: nonce }; -} \ No newline at end of file +}