caliper icon indicating copy to clipboard operation
caliper copied to clipboard

Allow the Ethereum connector to use an already deployed contract

Open mkrielza opened this issue 2 years ago • 2 comments
trafficstars

Please share the technical limitation of Caliper that you encountered.

Running benchmarks against an already deployed contract was not possible without changing the Ethereum connector.

Please detail your feature idea that could alleviate the limitation.

Allow for the case where no smart contracts need to be deployed by adding a contract address to the network configuration file.

Please share some details about your use case if possible, and how the new feature would make Caliper a better performance benchmarking framework.

It would allow the Ethereum connector to use an already deployed contract when running a benchmark.

Please share any suggestions about the new feature's code/configuration API (using formatted YAML segments or pseudo-code).

diff --git a/packages/caliper-ethereum/lib/ethereum-connector.js b/packages/caliper-ethereum/lib/ethereum-connector.js
--- a/packages/caliper-ethereum/lib/ethereum-connector.js	(revision 943ab2a22872639f39ccb36f8baf94b2863e21c6)
+++ b/packages/caliper-ethereum/lib/ethereum-connector.js	(date 1684132327195)
@@ -114,24 +114,30 @@
             }
             this.ethereumConfig.contracts[key].abi = contractData.abi;
-            promises.push(new Promise(async function(resolve, reject) {
-                let contractInstance;
-                try {
-                    if (privacy) {
-                        contractInstance = await self.deployPrivateContract(contractData, privacy);
-                        logger.info(`Deployed private contract ${contractData.name} at ${contractInstance.options.address}`);
-                    } else {
-                        contractInstance = await self.deployContract(contractData);
-                        logger.info(`Deployed contract ${contractData.name} at ${contractInstance.options.address}`);
-                    }
-                } catch (err) {
-                    reject(err);
-                }
-                self.ethereumConfig.contracts[key].address = contractInstance.options.address;
-                self.ethereumConfig.contracts[key].gas = contractGas;
-                self.ethereumConfig.contracts[key].estimateGas = estimateGas;
-                resolve(contractInstance);
-            }));
+            if (contract.address) {
+                self.ethereumConfig.contracts[key].address = contract.address;
+                self.ethereumConfig.contracts[key].gas = contractGas;
+                self.ethereumConfig.contracts[key].estimateGas = estimateGas;
+            } else {
+                promises.push(new Promise(async function (resolve, reject) {
+                    let contractInstance;
+                    try {
+                        if (privacy) {
+                            contractInstance = await self.deployPrivateContract(contractData, privacy);
+                            logger.info(`Deployed private contract ${contractData.name} at ${contractInstance.options.address}`);
+                        } else {
+                            contractInstance = await self.deployContract(contractData);
+                            logger.info(`Deployed contract ${contractData.name} at ${contractInstance.options.address}`);
+                        }
+                    } catch (err) {
+                        reject(err);
+                    }
+                    self.ethereumConfig.contracts[key].address = contractInstance.options.address;
+                    self.ethereumConfig.contracts[key].gas = contractGas;
+                    self.ethereumConfig.contracts[key].estimateGas = estimateGas;
+                    resolve(contractInstance);
+                }));
+            }
         }
         return Promise.all(promises);
     }

mkrielza avatar May 15 '23 13:05 mkrielza

The solution here is to run caliper but ensure it skips the install phase, you can do this by either skipping the phase or only running a specific phase (Caliper has 5 phases which admittedly are poorly documented). To skip the install phase and thus work with an already deployed contract use the --caliper-flow-skip-install option when launching caliper.

davidkel avatar Jun 01 '24 07:06 davidkel

see #1589 for more details on skipping install

davidkel avatar Jun 02 '24 09:06 davidkel

Closing as support for besu and ethereum have now been dropped

davidkel avatar Apr 24 '25 08:04 davidkel