Skip to content

Commit

Permalink
Merge pull request #863 from nklincoln/v032-bugfix-release
Browse files Browse the repository at this point in the history
0.3.2 release candidate: web3 version change, mqtt fixes, fabric gateway fixes
  • Loading branch information
aklenik authored Jun 11, 2020
2 parents e10dc05 + c043b52 commit c9de977
Show file tree
Hide file tree
Showing 25 changed files with 363 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "8"
- "10"

services:
- docker
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"bootstrap": "lerna bootstrap",
"pretest": "npm run licchk",
"licchk": "license-check-and-add",
"test": "lerna run test"
"test": "lerna run test",
"version-fix": "node ./packages/caliper-publish/publish.js version fix"
},
"engines": {
"node": ">=8.10.0",
Expand Down
16 changes: 8 additions & 8 deletions packages/caliper-cli/lib/lib/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ sut:
# The name/key of the SDK binding
1.0.0:
# Specifies the packages and their versions to install
packages: ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']
packages: ['[email protected]', '[email protected]', '[email protected]', '[email protected]']
# The settings to apply during binding. The first setting whose versionRegexp matches the node version will be used
settings:
- *new-node-old-grpc
1.1.0:
packages: ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']
packages: ['[email protected]', '[email protected]', '[email protected]', '[email protected]']
settings:
- *new-node-old-grpc
1.2.0:
packages: ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']
packages: ['[email protected]', '[email protected]', '[email protected]', '[email protected]']
settings:
- *new-node-old-grpc
1.3.0:
packages: ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']
packages: ['[email protected]', '[email protected]', '[email protected]', '[email protected]']
1.4.0:
packages: ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']
1.4.1:
Expand Down Expand Up @@ -99,14 +99,14 @@ sut:

ethereum:
1.2.1: &ethereum-latest
packages: ['[email protected].0']
packages: ['[email protected].2']
latest: *ethereum-latest

besu:
1.3.2:
packages: ['[email protected].0']
packages: ['[email protected].2']
1.3:
packages: ['[email protected].0']
packages: ['[email protected].2']
1.4: &besu-latest
packages: ['[email protected].0']
packages: ['[email protected].2']
latest: *besu-latest
4 changes: 3 additions & 1 deletion packages/caliper-core/lib/common/messaging/mqtt-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,16 @@ class MqttMasterMessenger extends MessengerInterface {
* Clean up any resources associated with the messenger.
*/
async dispose() {
Logger.info('Disconnecting from MQTT service');
const messengerDisconnectedPromise = new Promise((resolve, reject) => {
this.messengerDisconnectedPromise = {
resolve: resolve,
reject: reject
};
});

this.mqttClient.end(false, undefined, () => {
this.mqttClient.end(false, {}, () => {
Logger.info('MQTT connection closed');
this.messengerDisconnectedPromise.resolve();
});

Expand Down
4 changes: 3 additions & 1 deletion packages/caliper-core/lib/common/messaging/mqtt-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ class MqttWorkerMessenger extends MessengerInterface {
* Clean up any resources associated with the messenger.
*/
async dispose() {
Logger.info('Disconnecting from MQTT service');
const messengerDisconnectedPromise = new Promise((resolve, reject) => {
this.messengerDisconnectedPromise = {
resolve: resolve,
reject: reject
};
});

this.mqttClient.end(true, undefined, () => {
this.mqttClient.end(false, {}, () => {
Logger.info('MQTT connection closed');
this.messengerDisconnectedPromise.resolve();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class PrometheusPushClient {
useGateway(method, body) {
Logger.debug(`Prometheus client sending body ${body} to target ${this.requestParams.href}`);
// Convert body to binary, the newline is important
body = new Buffer(body + '\n', 'binary');
body = Buffer.from(body + '\n', 'binary');

// Assign request options
const options = Object.assign(this.requestParams, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class MonitorOrchestrator {
* @async
*/
async stopAllMonitors() {
logger.info('Stopping all monitors');
if(this.started === true) {

for (let key of this.monitors.keys()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class WorkerOrchestrator {
this.workerArguments = workerArguments;

this.workers = {};
this.workerObjects = [];
this.workerObjects = []; // used in the process communications
this.updates = {id:0, data:[]}; // contains txUpdated messages
this.results = []; // cumulative results

Expand Down Expand Up @@ -486,16 +486,17 @@ class WorkerOrchestrator {
}

/**
* Stop all test workers (child processes)
* Stop all test workers and disconnect from messenger
*/
async stop() {
logger.info('Sending exit message to connected workers');
this.messenger.send(['all'], TYPES.EXIT, {});
await this.messenger.dispose();

for (let workerObject of this.workerObjects) {
workerObject.kill();
}
// Internally spawned workers are killed within the messenger handling of 'exit', but clean the array of processes here
this.workerObjects = [];

// dispose of master messenger
await this.messenger.dispose();
}

/**
Expand Down Expand Up @@ -538,13 +539,13 @@ class WorkerOrchestrator {
logger.info(`Launching worker ${index} of ${this.number}`);

// Spawn the worker. The index is assigned upon connection
let cliPath = process.argv[1];
let workerCommands = ['launch', 'worker'];
let remainingArgs = process.argv.slice(4);
const cliPath = process.argv[1];
const workerCommands = ['launch', 'worker'];
const remainingArgs = process.argv.slice(4);

let nodeArgs = workerCommands.concat(remainingArgs);
const nodeArgs = workerCommands.concat(remainingArgs);

let worker = childProcess.fork(cliPath, nodeArgs, {
const worker = childProcess.fork(cliPath, nodeArgs, {
env: process.env,
cwd: process.cwd()
});
Expand Down
2 changes: 1 addition & 1 deletion packages/caliper-core/lib/master/report/report-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

const Config = require('../../common/config/config-util');
const Utils = require('../../common/utils/caliper-utils');
const Logger = Utils.getLogger('caliper-flow');
const Logger = Utils.getLogger('report-builder');
const fs = require('fs');
const Mustache = require('mustache');
const path = require('path');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const bc = require('../../common/core/blockchain.js');
const RateControl = require('../rate-control/rateControl.js');
const PrometheusClient = require('../../common/prometheus/prometheus-push-client');

const Logger = CaliperUtils.getLogger('caliper-local-client.js');
const Logger = CaliperUtils.getLogger('caliper-local-client');

/**
* Class for Client Interaction
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/caliper-core/lib/worker/client/message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MessageHandler {
* @param {Messenger} messenger the Messenger to use for communication with the orchestrator
*/
constructor(handlers, messenger) {

if (!handlers.init) {
let msg = 'Handler for "init" is not specified';
logger.error(msg);
Expand Down Expand Up @@ -236,7 +237,7 @@ class MessageHandler {
case 'exit': {
logger.info('Handling "exit" message');
await context.messenger.dispose();
logger.info(`Handled "exit" message for worker ${context.workerId}`);
logger.info(`Handled "exit" message for worker ${context.workerId}, exiting process`);
process.exit(0);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
const FabricClient = require('fabric-client');
const { DefaultEventHandlerStrategies, DefaultQueryHandlerStrategies, FileSystemWallet, Gateway, InMemoryWallet, X509WalletMixin } = require('fabric-network');
const { google, common } = require('fabric-protos');
const { BlockchainInterface, CaliperUtils, TxStatus, Version, ConfigUtil } = require('@hyperledger/caliper-core');
const { BlockchainInterface, CaliperUtils, TxStatus, ConfigUtil } = require('@hyperledger/caliper-core');
const logger = CaliperUtils.getLogger('adapters/fabric');

const FabricNetwork = require('../../fabricNetwork.js');
const ConfigValidator = require('../../configValidator.js');
const fs = require('fs');
const semver = require('semver');

const EventStrategies = {
msp_all : DefaultEventHandlerStrategies.MSPID_SCOPE_ALLFORTX,
Expand Down Expand Up @@ -139,7 +140,7 @@ class Fabric extends BlockchainInterface {
super(networkConfig);
this.bcType = 'fabric';
this.workspaceRoot = workspace_root;
this.version = new Version(require('fabric-client/package').version);
this.version = require('fabric-client/package').version;

this.network = undefined;
if (typeof networkConfig === 'string') {
Expand All @@ -160,6 +161,7 @@ class Fabric extends BlockchainInterface {
this.wallet = undefined;
this.userContracts = new Map();
this.userGateways = new Map();
this.peerCache = new Map();

// this value is hardcoded, if it's used, that means that the provided timeouts are not sufficient
this.configSmallestTimeout = 1000;
Expand Down Expand Up @@ -189,11 +191,6 @@ class Fabric extends BlockchainInterface {
this.fileWalletPath = this.networkUtil.getFileWalletPath();
this.defaultInvoker = Array.from(this.networkUtil.getClients())[0];

// Network Wallet/Gateway is only available in SDK versions greater than v1.4.0
if (this.version.lessThan('1.4.0')) {
throw new Error(`Fabric SDK ${this.version.toString()} is not supported when using a Fabric Gateway object, use at least version 1.4.0`);
}

this._prepareWallet();
}

Expand Down Expand Up @@ -916,6 +913,7 @@ class Fabric extends BlockchainInterface {
strategy: EventStrategies[this.eventStrategy]
},
queryHandlerOptions: {
requestTimeout: this.configDefaultTimeout,
strategy: QueryStrategies[this.queryStrategy]
}
};
Expand Down Expand Up @@ -1388,6 +1386,27 @@ class Fabric extends BlockchainInterface {
return channelJoined;
}

/**
* Initialize channel objects for use in peer targeting. Requires user gateways to have been
* formed in advance.
*/
async _initializePeerCache() {

for (const userName of this.userGateways.keys()) {
const gateway = this.userGateways.get(userName);
// Loop over known channel names
const channelNames = this.networkUtil.getChannels();
for (const channelName of channelNames) {
const network = await gateway.getNetwork(channelName);
const channel = network.getChannel();
// Add all peers
for (const peerObject of channel.getChannelPeers()) {
this.peerCache.set(peerObject.getName(), peerObject);
}
}
}
}

/**
* Conditionally initializes a wallet depending on user provided options
* @private
Expand Down Expand Up @@ -1500,11 +1519,11 @@ class Fabric extends BlockchainInterface {

// Add transient data if present
// - passed as key value pairing such as {"hello":"world"}
if (invokeSettings.transientData) {
if (invokeSettings.transientMap) {
const transientData = {};
const keys = Array.from(Object.keys(invokeSettings.transientData));
const keys = Array.from(Object.keys(invokeSettings.transientMap));
keys.forEach((key) => {
transientData[key] = Buffer.from(invokeSettings.transientData[key]);
transientData[key] = Buffer.from(invokeSettings.transientMap[key]);
});
transaction.setTransient(transientData);
}
Expand All @@ -1515,10 +1534,14 @@ class Fabric extends BlockchainInterface {
const targetPeerObjects = [];
for (const name of invokeSettings.targetPeers) {
const peer = this.peerCache.get(name);
targetPeerObjects.push(peer);
if (peer) {
targetPeerObjects.push(peer);
}
}
// Set the peer objects in the transaction
transaction.setEndorsingPeers(targetPeerObjects);
if (targetPeerObjects.length > 0) {
transaction.setEndorsingPeers(targetPeerObjects);
}
}

try {
Expand Down Expand Up @@ -1615,6 +1638,13 @@ class Fabric extends BlockchainInterface {
// - within submit/evaluate, a contract will be used for a nominated user
await this._initializeContracts();

// - use gateways to build a peer cache if the version supports it
if (semver.satisfies(semver.coerce(this.version), '>=1.4.5')) {
await this._initializePeerCache();
} else {
logger.warn(`Bound SDK ${this.version} is unable to use target peers; to enable target peer nomination for a gateway transaction, bind Caliper to Fabric 1.4.5 and above`);
}

// We are done - return the networkUtil object
return {
networkInfo: this.networkUtil,
Expand Down Expand Up @@ -1763,6 +1793,9 @@ class Fabric extends BlockchainInterface {
logger.info(`disconnecting gateway for user ${userName}`);
gateway.disconnect();
}

// Clear peer cache
this.peerCache.clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

const { DefaultEventHandlerStrategies, DefaultQueryHandlerStrategies, Gateway, Wallets } = require('fabric-network');
const { BlockchainInterface, CaliperUtils, TxStatus, Version, ConfigUtil } = require('@hyperledger/caliper-core');
const logger = CaliperUtils.getLogger('adapters/fabric');

const FabricNetwork = require('../../fabricNetwork.js');
const ConfigValidator = require('../../configValidator.js');
const RegistrarHelper = require('./registrarHelper');

const logger = CaliperUtils.getLogger('adapters/fabric');

const EventStrategies = {
msp_all : DefaultEventHandlerStrategies.MSPID_SCOPE_ALLFORTX,
msp_any : DefaultEventHandlerStrategies.MSPID_SCOPE_ANYFORTX,
Expand Down Expand Up @@ -135,10 +136,6 @@ class Fabric extends BlockchainInterface {
throw new Error('[FabricNetwork.constructor] Parameter \'networkConfig\' is neither a file path nor an object');
}

// validate the network
ConfigValidator.validateNetwork(this.network, CaliperUtils.getFlowOptions(),
this.configDiscovery, true);

this.clientIndex = clientIndex;
this.txIndex = -1;
this.networkUtil = new FabricNetwork(this.network, workspace_root);
Expand All @@ -159,6 +156,9 @@ class Fabric extends BlockchainInterface {
this.configDiscovery = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.Discovery, false);
this.eventStrategy = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.EventStrategy, 'msp_all');
this.queryStrategy = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.QueryStrategy, 'msp_single');

// validate the network
ConfigValidator.validateNetwork(this.network, CaliperUtils.getFlowOptions(), this.configDiscovery, true);
}

////////////////////////////////
Expand Down Expand Up @@ -449,11 +449,11 @@ class Fabric extends BlockchainInterface {

// Add transient data if present
// - passed as key value pairing such as {"hello":"world"}
if (invokeSettings.transientData) {
if (invokeSettings.transientMap) {
const transientData = {};
const keys = Array.from(Object.keys(invokeSettings.transientData));
const keys = Array.from(Object.keys(invokeSettings.transientMap));
keys.forEach((key) => {
transientData[key] = Buffer.from(invokeSettings.transientData[key]);
transientData[key] = Buffer.from(invokeSettings.transientMap[key]);
});
transaction.setTransient(transientData);
}
Expand Down Expand Up @@ -690,6 +690,9 @@ class Fabric extends BlockchainInterface {
logger.info(`disconnecting gateway for user ${userName}`);
gateway.disconnect();
}

// Clear peer cache
this.peerCache.clear();
}}

module.exports = Fabric;
Loading

0 comments on commit c9de977

Please sign in to comment.