Skip to content

Commit 9043fd0

Browse files
Remove the legacy fabric connectors (#1235)
This is mainly a deletion exercise with the following code changes 1. simplication of which connector to load 2. only create a connector instance if required for example flow-only-start and flow-only-end don't need to have a connector created Signed-off-by: D <d_kelsey@uk.ibm.com> Co-authored-by: D <d_kelsey@uk.ibm.com>
1 parent 338212d commit 9043fd0

File tree

25 files changed

+244
-11280
lines changed

25 files changed

+244
-11280
lines changed

packages/caliper-core/lib/common/config/Config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ const keys = {
160160
CountQueryAsLoad: 'caliper-fabric-countqueryasload',
161161
SkipCreateChannelPrefix: 'caliper-fabric-skipcreatechannel-',
162162
Gateway: {
163-
Discovery: 'caliper-fabric-gateway-discovery',
164163
Enabled: 'caliper-fabric-gateway-enabled',
165164
EventStrategy: 'caliper-fabric-gateway-eventstrategy',
166165
LocalHost: 'caliper-fabric-gateway-localhost',

packages/caliper-core/lib/common/config/default.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ caliper:
226226
enabled: false
227227
# Indicates whether to use the localhost default within the Fabric Gateway API
228228
localhost: true
229-
# Indicates whether to use the Fabric discovery mechanism (via Gateway API)
230-
discovery: false
231229
# Which event strategy to use
232230
eventstrategy: msp_any
233231
# Which query strategy to use

packages/caliper-core/lib/manager/caliper-engine.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class CaliperEngine {
9090
BenchValidator.validateObject(this.benchmarkConfig);
9191

9292
logger.info('Starting benchmark flow');
93-
let connector = await this.adapterFactory(-1);
9493

9594
try {
9695

@@ -101,10 +100,13 @@ class CaliperEngine {
101100
await this._executeCommand('start', 0);
102101
}
103102

103+
let connector;
104+
104105
// Conditional network initialization
105106
if (!flowOpts.performInit) {
106107
logger.info('Skipping initialization phase due to benchmark flow conditioning');
107108
} else {
109+
connector = connector ? connector : await this.adapterFactory(-1);
108110
let initStartTime = Date.now();
109111
try {
110112
await connector.init();
@@ -123,6 +125,7 @@ class CaliperEngine {
123125
if (!flowOpts.performInstall) {
124126
logger.info('Skipping install smart contract phase due to benchmark flow conditioning');
125127
} else {
128+
connector = connector ? connector : await this.adapterFactory(-1);
126129
let installStartTime = Date.now();
127130
try {
128131
await connector.installSmartContract();
@@ -143,6 +146,7 @@ class CaliperEngine {
143146
} else {
144147
let numberSet = this.benchmarkConfig.test && this.benchmarkConfig.test.workers && this.benchmarkConfig.test.workers.number;
145148
let numberOfWorkers = numberSet ? this.benchmarkConfig.test.workers.number : 1;
149+
connector = connector ? connector : await this.adapterFactory(-1);
146150
let workerArguments = await connector.prepareWorkerArguments(numberOfWorkers);
147151

148152
const roundOrchestrator = new RoundOrchestrator(this.benchmarkConfig, this.networkConfig, workerArguments);

packages/caliper-fabric/lib/FabricConnectorFactory.js

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616

1717
const { CaliperUtils, ConfigUtil } = require('@hyperledger/caliper-core');
1818
const ConnectorConfigurationFactory = require('./connector-configuration/ConnectorConfigurationFactory');
19-
const ConfigValidator = require('./configValidator.js');
20-
const Logger = CaliperUtils.getLogger('fabric-connector');
19+
const Logger = CaliperUtils.getLogger('FabricConnectorFactory');
2120
const semver = require('semver');
2221

23-
const LEGACY_V1_NODE_CONNECTOR = './connector-versions/v1/fabric.js';
24-
const LEGACY_V1_GATEWAY_CONNECTOR = './connector-versions/v1/fabric-gateway.js';
25-
const LEGACY_V2_GATEWAY_CONNECTOR = './connector-versions/v2/fabric-gateway.js';
26-
2722
const NEW_V1_NODE_CONNECTOR = './connector-versions/v1/FabricNonGateway.js';
2823
const NEW_V1_GATEWAY_CONNECTOR = './connector-versions/v1/FabricGateway.js';
2924
const NEW_V1_WALLET_FACADE_FACTORY = './connector-versions/v1/WalletFacadeFactory.js';
@@ -35,41 +30,29 @@ const NEW_V2_WALLET_FACADE_FACTORY = './connector-versions/v2/WalletFacadeFactor
3530
* @returns {string} version
3631
*/
3732
const _determineInstalledNodeSDKVersion = () => {
38-
let version;
33+
34+
// Caliper can only work if you use bind and it will pull in fabric network even for non gateway 1.4
3935
if (CaliperUtils.moduleIsInstalled('fabric-network')) {
4036
const packageVersion = require('fabric-network/package').version;
41-
version = semver.coerce(packageVersion);
42-
} else if (CaliperUtils.moduleIsInstalled('fabric-client')) {
43-
const packageVersion = require('fabric-client/package').version;
44-
version = semver.coerce(packageVersion);
37+
return semver.coerce(packageVersion);
4538
} else {
46-
const msg = 'Unable to detect required Fabric binding packages';
47-
throw new Error(msg);
39+
throw new Error('Unable to detect required Fabric binding packages');
4840
}
49-
return version;
5041
};
5142

52-
const _loadAppropriateConnectorClass = (installedNodeSDKVersion, useGateway, useLegacyVersion) => {
43+
const _loadAppropriateConnectorClass = (installedNodeSDKVersion, useGateway) => {
5344
let connectorPath;
5445
let walletFacadeFactoryPath;
5546

5647
if (semver.satisfies(installedNodeSDKVersion, '=1.x')) {
5748
if (!useGateway) {
58-
if (useLegacyVersion) {
59-
connectorPath = LEGACY_V1_NODE_CONNECTOR;
60-
} else {
61-
connectorPath = NEW_V1_NODE_CONNECTOR;
62-
walletFacadeFactoryPath = NEW_V1_WALLET_FACADE_FACTORY;
63-
}
49+
connectorPath = NEW_V1_NODE_CONNECTOR;
50+
walletFacadeFactoryPath = NEW_V1_WALLET_FACADE_FACTORY;
6451
} else {
6552
// gateway with default event handlers appears in SDK > 1.4.2
6653
if (semver.satisfies(installedNodeSDKVersion, '>=1.4.2')) {
67-
if (useLegacyVersion) {
68-
connectorPath = LEGACY_V1_GATEWAY_CONNECTOR;
69-
} else {
70-
connectorPath = NEW_V1_GATEWAY_CONNECTOR;
71-
walletFacadeFactoryPath = NEW_V1_WALLET_FACADE_FACTORY;
72-
}
54+
connectorPath = NEW_V1_GATEWAY_CONNECTOR;
55+
walletFacadeFactoryPath = NEW_V1_WALLET_FACADE_FACTORY;
7356
} else {
7457
throw new Error('Caliper currently only supports Fabric gateway based operation using Fabric-SDK 1.4.2 and higher. Please retry with a different SDK binding');
7558
}
@@ -78,12 +61,8 @@ const _loadAppropriateConnectorClass = (installedNodeSDKVersion, useGateway, use
7861
if (!useGateway) {
7962
throw new Error(`Caliper currently only supports gateway based operation using the ${installedNodeSDKVersion} Fabric-SDK. Please retry with the gateway flag`);
8063
} else {
81-
if (useLegacyVersion) {
82-
connectorPath = LEGACY_V2_GATEWAY_CONNECTOR;
83-
} else {
84-
connectorPath = NEW_V2_GATEWAY_CONNECTOR;
85-
walletFacadeFactoryPath = NEW_V2_WALLET_FACADE_FACTORY;
86-
}
64+
connectorPath = NEW_V2_GATEWAY_CONNECTOR;
65+
walletFacadeFactoryPath = NEW_V2_WALLET_FACADE_FACTORY;
8766
}
8867
} else {
8968
throw new Error(`Installed SDK version ${installedNodeSDKVersion} did not match any compatible Fabric connectors`);
@@ -108,35 +87,21 @@ const connectorFactory = async (workerIndex) => {
10887

10988
const connectorConfigurationFile = CaliperUtils.resolvePath(ConfigUtil.get(ConfigUtil.keys.NetworkConfig));
11089
const loadedConnectorConfiguration = CaliperUtils.parseYaml(connectorConfigurationFile);
111-
const legacyVersion = loadedConnectorConfiguration.version === '1.0';
90+
if (loadedConnectorConfiguration.version === '1.0') {
91+
throw new Error('Network configuration version 1.0 is not supported anymore, please use version 2');
92+
}
11293

113-
if (!legacyVersion && !semver.satisfies(loadedConnectorConfiguration.version, '=2.0')) {
94+
if (!semver.satisfies(loadedConnectorConfiguration.version, '=2.0')) {
11495
throw new Error(`Unknown network configuration version ${loadedConnectorConfiguration.version} specified`);
11596
}
11697

11798
const installedNodeSDKVersion = _determineInstalledNodeSDKVersion();
11899
const useGateway = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.Enabled, false);
119-
const useDiscovery = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.Discovery, false);
120100

121101
Logger.info(`Initializing ${useGateway ? 'gateway' : 'standard' } connector compatible with installed SDK: ${installedNodeSDKVersion}`);
122-
const {fabricConnectorClass, walletFacadeFactoryClass} = _loadAppropriateConnectorClass(installedNodeSDKVersion, useGateway, legacyVersion);
123-
124-
let fabricConnector;
125-
126-
if (legacyVersion) {
127-
ConfigValidator.validateNetwork(loadedConnectorConfiguration, CaliperUtils.getFlowOptions(), useDiscovery, useGateway);
128-
129-
fabricConnector = new fabricConnectorClass(loadedConnectorConfiguration, workerIndex, 'fabric');
130-
if (workerIndex > -1) {
131-
// These connectors must have init called for both masters and workers
132-
// but for masters it will have already been called
133-
await fabricConnector.init(true);
134-
}
135-
} else {
136-
// use new connectors
137-
const connectorConfiguration = await new ConnectorConfigurationFactory().create(connectorConfigurationFile, new walletFacadeFactoryClass());
138-
fabricConnector = new fabricConnectorClass(connectorConfiguration, workerIndex, 'fabric');
139-
}
102+
const {fabricConnectorClass, walletFacadeFactoryClass} = _loadAppropriateConnectorClass(installedNodeSDKVersion, useGateway);
103+
const connectorConfiguration = await new ConnectorConfigurationFactory().create(connectorConfigurationFile, new walletFacadeFactoryClass());
104+
const fabricConnector = new fabricConnectorClass(connectorConfiguration, workerIndex, 'fabric');
140105

141106
return fabricConnector;
142107
};

0 commit comments

Comments
 (0)