Skip to content

Commit

Permalink
[FAB-5117] NodeSDK - grpc dflt send/receive size
Browse files Browse the repository at this point in the history
Setting the grpc settings for send and recieve size
to -1 for unlimited. The users may override this setting
but should not have a need.

Change-Id: I756886068f10fc619a9aa9ad348ac2f21ebfc785
Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob committed Nov 17, 2017
1 parent 4a42fc3 commit 1941ef8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 36 deletions.
30 changes: 17 additions & 13 deletions fabric-client/lib/Remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 45 additions & 1 deletion test/integration/e2e/create-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
38 changes: 16 additions & 22 deletions test/integration/grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -81,49 +83,39 @@ 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(() => {
t.pass('Successfully tested setting grpc send limit');

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] : {};

Expand All @@ -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']));
Expand Down Expand Up @@ -173,4 +167,4 @@ function buildEchoRequest(client, peer) {
txId: tx_id,
nonce: nonce
};
}
}

0 comments on commit 1941ef8

Please sign in to comment.